[XFRM]: skb_cow_data() does not set proper owner for new skbs.
[linux-2.6/verdex.git] / drivers / serial / cpm_uart / cpm_uart_cpm2.c
blobb422c3abfba612830df57630e7cbb3c4682279ce
1 /*
2 * linux/drivers/serial/cpm_uart_cpm2.c
4 * Driver for CPM (SCC/SMC) serial ports; CPM2 definitions
6 * Maintainer: Kumar Gala (kumar.gala@freescale.com) (CPM2)
7 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
8 *
9 * Copyright (C) 2004 Freescale Semiconductor, Inc.
10 * (C) 2004 Intracom, S.A.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include <linux/config.h>
29 #include <linux/module.h>
30 #include <linux/tty.h>
31 #include <linux/ioport.h>
32 #include <linux/init.h>
33 #include <linux/serial.h>
34 #include <linux/console.h>
35 #include <linux/sysrq.h>
36 #include <linux/device.h>
37 #include <linux/bootmem.h>
38 #include <linux/dma-mapping.h>
40 #include <asm/io.h>
41 #include <asm/irq.h>
43 #include <linux/serial_core.h>
44 #include <linux/kernel.h>
46 #include "cpm_uart.h"
48 /**************************************************************/
50 void cpm_line_cr_cmd(int line, int cmd)
52 volatile cpm_cpm2_t *cp = cpmp;
53 ulong val;
55 switch (line) {
56 case UART_SMC1:
57 val = mk_cr_cmd(CPM_CR_SMC1_PAGE, CPM_CR_SMC1_SBLOCK, 0,
58 cmd) | CPM_CR_FLG;
59 break;
60 case UART_SMC2:
61 val = mk_cr_cmd(CPM_CR_SMC2_PAGE, CPM_CR_SMC2_SBLOCK, 0,
62 cmd) | CPM_CR_FLG;
63 break;
64 case UART_SCC1:
65 val = mk_cr_cmd(CPM_CR_SCC1_PAGE, CPM_CR_SCC1_SBLOCK, 0,
66 cmd) | CPM_CR_FLG;
67 break;
68 case UART_SCC2:
69 val = mk_cr_cmd(CPM_CR_SCC2_PAGE, CPM_CR_SCC2_SBLOCK, 0,
70 cmd) | CPM_CR_FLG;
71 break;
72 case UART_SCC3:
73 val = mk_cr_cmd(CPM_CR_SCC3_PAGE, CPM_CR_SCC3_SBLOCK, 0,
74 cmd) | CPM_CR_FLG;
75 break;
76 case UART_SCC4:
77 val = mk_cr_cmd(CPM_CR_SCC4_PAGE, CPM_CR_SCC4_SBLOCK, 0,
78 cmd) | CPM_CR_FLG;
79 break;
80 default:
81 return;
84 cp->cp_cpcr = val;
85 while (cp->cp_cpcr & CPM_CR_FLG) ;
88 void smc1_lineif(struct uart_cpm_port *pinfo)
90 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
92 /* SMC1 is only on port D */
93 io->iop_ppard |= 0x00c00000;
94 io->iop_pdird |= 0x00400000;
95 io->iop_pdird &= ~0x00800000;
96 io->iop_psord &= ~0x00c00000;
98 /* Wire BRG1 to SMC1 */
99 cpm2_immr->im_cpmux.cmx_smr &= 0x0f;
100 pinfo->brg = 1;
103 void smc2_lineif(struct uart_cpm_port *pinfo)
105 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
107 /* SMC2 is only on port A */
108 io->iop_ppara |= 0x00c00000;
109 io->iop_pdira |= 0x00400000;
110 io->iop_pdira &= ~0x00800000;
111 io->iop_psora &= ~0x00c00000;
113 /* Wire BRG2 to SMC2 */
114 cpm2_immr->im_cpmux.cmx_smr &= 0xf0;
115 pinfo->brg = 2;
118 void scc1_lineif(struct uart_cpm_port *pinfo)
120 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
122 /* Use Port D for SCC1 instead of other functions. */
123 io->iop_ppard |= 0x00000003;
124 io->iop_psord &= ~0x00000001; /* Rx */
125 io->iop_psord |= 0x00000002; /* Tx */
126 io->iop_pdird &= ~0x00000001; /* Rx */
127 io->iop_pdird |= 0x00000002; /* Tx */
129 /* Wire BRG1 to SCC1 */
130 cpm2_immr->im_cpmux.cmx_scr &= 0x00ffffff;
131 cpm2_immr->im_cpmux.cmx_scr |= 0x00000000;
132 pinfo->brg = 1;
135 void scc2_lineif(struct uart_cpm_port *pinfo)
137 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
138 io->iop_pparb |= 0x008b0000;
139 io->iop_pdirb |= 0x00880000;
140 io->iop_psorb |= 0x00880000;
141 io->iop_pdirb &= ~0x00030000;
142 io->iop_psorb &= ~0x00030000;
143 cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff;
144 cpm2_immr->im_cpmux.cmx_scr |= 0x00090000;
145 pinfo->brg = 2;
148 void scc3_lineif(struct uart_cpm_port *pinfo)
150 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
151 io->iop_pparb |= 0x008b0000;
152 io->iop_pdirb |= 0x00880000;
153 io->iop_psorb |= 0x00880000;
154 io->iop_pdirb &= ~0x00030000;
155 io->iop_psorb &= ~0x00030000;
156 cpm2_immr->im_cpmux.cmx_scr &= 0xffff00ff;
157 cpm2_immr->im_cpmux.cmx_scr |= 0x00001200;
158 pinfo->brg = 3;
161 void scc4_lineif(struct uart_cpm_port *pinfo)
163 volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
165 io->iop_ppard |= 0x00000600;
166 io->iop_psord &= ~0x00000600; /* Tx/Rx */
167 io->iop_pdird &= ~0x00000200; /* Rx */
168 io->iop_pdird |= 0x00000400; /* Tx */
170 cpm2_immr->im_cpmux.cmx_scr &= 0xffffff00;
171 cpm2_immr->im_cpmux.cmx_scr |= 0x0000001b;
172 pinfo->brg = 4;
176 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
177 * receive buffer descriptors from dual port ram, and a character
178 * buffer area from host mem. If we are allocating for the console we need
179 * to do it from bootmem
181 int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
183 int dpmemsz, memsz;
184 u8 *dp_mem;
185 uint dp_offset;
186 u8 *mem_addr;
187 dma_addr_t dma_addr = 0;
189 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
191 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
192 dp_offset = cpm_dpalloc(dpmemsz, 8);
193 if (IS_DPERR(dp_offset)) {
194 printk(KERN_ERR
195 "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
196 return -ENOMEM;
199 dp_mem = cpm_dpram_addr(dp_offset);
201 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
202 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
203 if (is_con)
204 mem_addr = alloc_bootmem(memsz);
205 else
206 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
207 GFP_KERNEL);
209 if (mem_addr == NULL) {
210 cpm_dpfree(dp_offset);
211 printk(KERN_ERR
212 "cpm_uart_cpm.c: could not allocate coherent memory\n");
213 return -ENOMEM;
216 pinfo->dp_addr = dp_offset;
217 pinfo->mem_addr = mem_addr;
218 pinfo->dma_addr = dma_addr;
220 pinfo->rx_buf = mem_addr;
221 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
222 * pinfo->rx_fifosize);
224 pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
225 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
227 return 0;
230 void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
232 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
233 pinfo->rx_fifosize) +
234 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
235 pinfo->tx_fifosize), pinfo->mem_addr,
236 pinfo->dma_addr);
238 cpm_dpfree(pinfo->dp_addr);
241 /* Setup any dynamic params in the uart desc */
242 int cpm_uart_init_portdesc(void)
244 pr_debug("CPM uart[-]:init portdesc\n");
246 cpm_uart_nr = 0;
247 #ifdef CONFIG_SERIAL_CPM_SMC1
248 cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
249 cpm_uart_ports[UART_SMC1].smcup =
250 (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1];
251 cpm_uart_ports[UART_SMC1].port.mapbase =
252 (unsigned long)&cpm2_immr->im_smc[0];
253 cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
254 cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
255 cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
256 cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
257 #endif
259 #ifdef CONFIG_SERIAL_CPM_SMC2
260 cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1];
261 cpm_uart_ports[UART_SMC2].smcup =
262 (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2];
263 cpm_uart_ports[UART_SMC2].port.mapbase =
264 (unsigned long)&cpm2_immr->im_smc[1];
265 cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
266 cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
267 cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
268 cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
269 #endif
271 #ifdef CONFIG_SERIAL_CPM_SCC1
272 cpm_uart_ports[UART_SCC1].sccp = (scc_t *) & cpm2_immr->im_scc[0];
273 cpm_uart_ports[UART_SCC1].sccup =
274 (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC1];
275 cpm_uart_ports[UART_SCC1].port.mapbase =
276 (unsigned long)&cpm2_immr->im_scc[0];
277 cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
278 ~(UART_SCCM_TX | UART_SCCM_RX);
279 cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
280 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
281 cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
282 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
283 #endif
285 #ifdef CONFIG_SERIAL_CPM_SCC2
286 cpm_uart_ports[UART_SCC2].sccp = (scc_t *) & cpm2_immr->im_scc[1];
287 cpm_uart_ports[UART_SCC2].sccup =
288 (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC2];
289 cpm_uart_ports[UART_SCC2].port.mapbase =
290 (unsigned long)&cpm2_immr->im_scc[1];
291 cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
292 ~(UART_SCCM_TX | UART_SCCM_RX);
293 cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
294 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
295 cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
296 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
297 #endif
299 #ifdef CONFIG_SERIAL_CPM_SCC3
300 cpm_uart_ports[UART_SCC3].sccp = (scc_t *) & cpm2_immr->im_scc[2];
301 cpm_uart_ports[UART_SCC3].sccup =
302 (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC3];
303 cpm_uart_ports[UART_SCC3].port.mapbase =
304 (unsigned long)&cpm2_immr->im_scc[2];
305 cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
306 ~(UART_SCCM_TX | UART_SCCM_RX);
307 cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
308 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
309 cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
310 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
311 #endif
313 #ifdef CONFIG_SERIAL_CPM_SCC4
314 cpm_uart_ports[UART_SCC4].sccp = (scc_t *) & cpm2_immr->im_scc[3];
315 cpm_uart_ports[UART_SCC4].sccup =
316 (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC4];
317 cpm_uart_ports[UART_SCC4].port.mapbase =
318 (unsigned long)&cpm2_immr->im_scc[3];
319 cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
320 ~(UART_SCCM_TX | UART_SCCM_RX);
321 cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
322 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
323 cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
324 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
325 #endif
327 return 0;