1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30#include <linux/module.h>
31#include <linux/tty.h>
32#include <linux/ioport.h>
33#include <linux/slab.h>
34#include <linux/init.h>
35#include <linux/serial.h>
36#include <linux/console.h>
37#include <linux/sysrq.h>
38#include <linux/device.h>
39#include <linux/bootmem.h>
40#include <linux/dma-mapping.h>
41
42#include <asm/io.h>
43#include <asm/irq.h>
44#include <asm/fs_pd.h>
45#include <asm/prom.h>
46
47#include <linux/serial_core.h>
48#include <linux/kernel.h>
49
50#include "cpm_uart.h"
51
52
53
54void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd)
55{
56 cpm_command(port->command, cmd);
57}
58
59void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
60 struct device_node *np)
61{
62 void __iomem *pram;
63 unsigned long offset;
64 struct resource res;
65 resource_size_t len;
66
67
68
69
70 if (IS_SMC(port) && port->smcup)
71 return port->smcup;
72 else if (!IS_SMC(port) && port->sccup)
73 return port->sccup;
74
75 if (of_address_to_resource(np, 1, &res))
76 return NULL;
77
78 len = resource_size(&res);
79 pram = ioremap(res.start, len);
80 if (!pram)
81 return NULL;
82
83 if (!IS_SMC(port))
84 return pram;
85
86 if (len != 2) {
87 printk(KERN_WARNING "cpm_uart[%d]: device tree references "
88 "SMC pram, using boot loader/wrapper pram mapping. "
89 "Please fix your device tree to reference the pram "
90 "base register instead.\n",
91 port->port.line);
92 return pram;
93 }
94
95 offset = cpm_dpalloc(PROFF_SMC_SIZE, 64);
96 out_be16(pram, offset);
97 iounmap(pram);
98 return cpm_muram_addr(offset);
99}
100
101void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram)
102{
103 if (!IS_SMC(port))
104 iounmap(pram);
105}
106
107
108
109
110
111
112
113int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
114{
115 int dpmemsz, memsz;
116 u8 __iomem *dp_mem;
117 unsigned long dp_offset;
118 u8 *mem_addr;
119 dma_addr_t dma_addr = 0;
120
121 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
122
123 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
124 dp_offset = cpm_dpalloc(dpmemsz, 8);
125 if (IS_ERR_VALUE(dp_offset)) {
126 printk(KERN_ERR
127 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
128 return -ENOMEM;
129 }
130
131 dp_mem = cpm_dpram_addr(dp_offset);
132
133 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
134 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
135 if (is_con) {
136 mem_addr = kzalloc(memsz, GFP_NOWAIT);
137 dma_addr = virt_to_bus(mem_addr);
138 }
139 else
140 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
141 GFP_KERNEL);
142
143 if (mem_addr == NULL) {
144 cpm_dpfree(dp_offset);
145 printk(KERN_ERR
146 "cpm_uart_cpm.c: could not allocate coherent memory\n");
147 return -ENOMEM;
148 }
149
150 pinfo->dp_addr = dp_offset;
151 pinfo->mem_addr = mem_addr;
152 pinfo->dma_addr = dma_addr;
153 pinfo->mem_size = memsz;
154
155 pinfo->rx_buf = mem_addr;
156 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
157 * pinfo->rx_fifosize);
158
159 pinfo->rx_bd_base = (cbd_t __iomem *)dp_mem;
160 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
161
162 return 0;
163}
164
165void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
166{
167 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
168 pinfo->rx_fifosize) +
169 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
170 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
171 pinfo->dma_addr);
172
173 cpm_dpfree(pinfo->dp_addr);
174}
175