0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/module.h>
0015 #include <linux/tty.h>
0016 #include <linux/ioport.h>
0017 #include <linux/slab.h>
0018 #include <linux/serial.h>
0019 #include <linux/console.h>
0020 #include <linux/sysrq.h>
0021 #include <linux/device.h>
0022 #include <linux/memblock.h>
0023 #include <linux/dma-mapping.h>
0024
0025 #include <asm/io.h>
0026 #include <asm/irq.h>
0027 #include <asm/fs_pd.h>
0028
0029 #include <linux/serial_core.h>
0030 #include <linux/kernel.h>
0031
0032 #include "cpm_uart.h"
0033
0034
0035
0036 void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
0037 {
0038 cpm_command(port->command, cmd);
0039 }
0040
0041 void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
0042 struct device_node *np)
0043 {
0044 void __iomem *pram;
0045 unsigned long offset;
0046 struct resource res;
0047 resource_size_t len;
0048
0049
0050
0051
0052 if (IS_SMC(port) && port->smcup)
0053 return port->smcup;
0054 else if (!IS_SMC(port) && port->sccup)
0055 return port->sccup;
0056
0057 if (of_address_to_resource(np, 1, &res))
0058 return NULL;
0059
0060 len = resource_size(&res);
0061 pram = ioremap(res.start, len);
0062 if (!pram)
0063 return NULL;
0064
0065 if (!IS_SMC(port))
0066 return pram;
0067
0068 if (len != 2) {
0069 printk(KERN_WARNING "cpm_uart[%d]: device tree references "
0070 "SMC pram, using boot loader/wrapper pram mapping. "
0071 "Please fix your device tree to reference the pram "
0072 "base register instead.\n",
0073 port->port.line);
0074 return pram;
0075 }
0076
0077 offset = cpm_dpalloc(PROFF_SMC_SIZE, 64);
0078 out_be16(pram, offset);
0079 iounmap(pram);
0080 return cpm_muram_addr(offset);
0081 }
0082
0083 void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
0084 {
0085 if (!IS_SMC(port))
0086 iounmap(pram);
0087 }
0088
0089
0090
0091
0092
0093
0094
0095 int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
0096 {
0097 int dpmemsz, memsz;
0098 u8 __iomem *dp_mem;
0099 unsigned long dp_offset;
0100 u8 *mem_addr;
0101 dma_addr_t dma_addr = 0;
0102
0103 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
0104
0105 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
0106 dp_offset = cpm_dpalloc(dpmemsz, 8);
0107 if (IS_ERR_VALUE(dp_offset)) {
0108 printk(KERN_ERR
0109 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
0110 return -ENOMEM;
0111 }
0112
0113 dp_mem = cpm_dpram_addr(dp_offset);
0114
0115 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
0116 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
0117 if (is_con) {
0118 mem_addr = kzalloc(memsz, GFP_NOWAIT);
0119 dma_addr = virt_to_bus(mem_addr);
0120 }
0121 else
0122 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
0123 GFP_KERNEL);
0124
0125 if (mem_addr == NULL) {
0126 cpm_dpfree(dp_offset);
0127 printk(KERN_ERR
0128 "cpm_uart_cpm.c: could not allocate coherent memory\n");
0129 return -ENOMEM;
0130 }
0131
0132 pinfo->dp_addr = dp_offset;
0133 pinfo->mem_addr = mem_addr;
0134 pinfo->dma_addr = dma_addr;
0135 pinfo->mem_size = memsz;
0136
0137 pinfo->rx_buf = mem_addr;
0138 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
0139 * pinfo->rx_fifosize);
0140
0141 pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem;
0142 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
0143
0144 return 0;
0145 }
0146
0147 void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
0148 {
0149 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
0150 pinfo->rx_fifosize) +
0151 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
0152 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
0153 pinfo->dma_addr);
0154
0155 cpm_dpfree(pinfo->dp_addr);
0156 }