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