2 * linux/drivers/serial/cpm_uart.c
4 * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
6 * Maintainer: Kumar Gala (kumar.gala@freescale.com) (CPM2)
7 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
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>
43 #include <linux/serial_core.h>
44 #include <linux/kernel.h>
48 /**************************************************************/
50 void cpm_line_cr_cmd(int line, int cmd)
53 volatile cpm8xx_t *cp = cpmp;
57 val = mk_cr_cmd(CPM_CR_CH_SMC1, cmd) | CPM_CR_FLG;
60 val = mk_cr_cmd(CPM_CR_CH_SMC2, cmd) | CPM_CR_FLG;
63 val = mk_cr_cmd(CPM_CR_CH_SCC1, cmd) | CPM_CR_FLG;
66 val = mk_cr_cmd(CPM_CR_CH_SCC2, cmd) | CPM_CR_FLG;
69 val = mk_cr_cmd(CPM_CR_CH_SCC3, cmd) | CPM_CR_FLG;
72 val = mk_cr_cmd(CPM_CR_CH_SCC4, cmd) | CPM_CR_FLG;
79 while (cp->cp_cpcr & CPM_CR_FLG) ;
82 void smc1_lineif(struct uart_cpm_port *pinfo)
84 volatile cpm8xx_t *cp = cpmp;
86 (void)cp; /* fix warning */
87 #if defined (CONFIG_MPC885ADS)
88 /* Enable SMC1 transceivers */
90 cp->cp_pepar |= 0x000000c0;
91 cp->cp_pedir &= ~0x000000c0;
92 cp->cp_peso &= ~0x00000040;
93 cp->cp_peso |= 0x00000080;
95 #elif defined (CONFIG_MPC86XADS)
96 unsigned int iobits = 0x000000c0;
98 if (!pinfo->is_portb) {
99 cp->cp_pbpar |= iobits;
100 cp->cp_pbdir &= ~iobits;
101 cp->cp_pbodr &= ~iobits;
103 ((immap_t *)IMAP_ADDR)->im_ioport.iop_papar |= iobits;
104 ((immap_t *)IMAP_ADDR)->im_ioport.iop_padir &= ~iobits;
105 ((immap_t *)IMAP_ADDR)->im_ioport.iop_paodr &= ~iobits;
111 void smc2_lineif(struct uart_cpm_port *pinfo)
113 volatile cpm8xx_t *cp = cpmp;
115 (void)cp; /* fix warning */
116 #if defined (CONFIG_MPC885ADS)
117 cp->cp_pepar |= 0x00000c00;
118 cp->cp_pedir &= ~0x00000c00;
119 cp->cp_peso &= ~0x00000400;
120 cp->cp_peso |= 0x00000800;
121 #elif defined (CONFIG_MPC86XADS)
122 unsigned int iobits = 0x00000c00;
124 if (!pinfo->is_portb) {
125 cp->cp_pbpar |= iobits;
126 cp->cp_pbdir &= ~iobits;
127 cp->cp_pbodr &= ~iobits;
129 ((immap_t *)IMAP_ADDR)->im_ioport.iop_papar |= iobits;
130 ((immap_t *)IMAP_ADDR)->im_ioport.iop_padir &= ~iobits;
131 ((immap_t *)IMAP_ADDR)->im_ioport.iop_paodr &= ~iobits;
139 void scc1_lineif(struct uart_cpm_port *pinfo)
141 /* XXX SCC1: insert port configuration here */
145 void scc2_lineif(struct uart_cpm_port *pinfo)
147 /* XXX SCC2: insert port configuration here */
151 void scc3_lineif(struct uart_cpm_port *pinfo)
153 /* XXX SCC3: insert port configuration here */
157 void scc4_lineif(struct uart_cpm_port *pinfo)
159 /* XXX SCC4: insert port configuration here */
164 * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
165 * receive buffer descriptors from dual port ram, and a character
166 * buffer area from host mem. If we are allocating for the console we need
167 * to do it from bootmem
169 int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
175 dma_addr_t dma_addr = 0;
177 pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
179 dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
180 dp_offset = cpm_dpalloc(dpmemsz, 8);
181 if (IS_DPERR(dp_offset)) {
183 "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
186 dp_mem = cpm_dpram_addr(dp_offset);
188 memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
189 L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
191 /* was hostalloc but changed cause it blows away the */
192 /* large tlb mapping when pinning the kernel area */
193 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
196 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
199 if (mem_addr == NULL) {
200 cpm_dpfree(dp_offset);
202 "cpm_uart_cpm1.c: could not allocate coherent memory\n");
206 pinfo->dp_addr = dp_offset;
207 pinfo->mem_addr = mem_addr;
208 pinfo->dma_addr = dma_addr;
210 pinfo->rx_buf = mem_addr;
211 pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
212 * pinfo->rx_fifosize);
214 pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
215 pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
220 void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
222 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
223 pinfo->rx_fifosize) +
224 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
225 pinfo->tx_fifosize), pinfo->mem_addr,
228 cpm_dpfree(pinfo->dp_addr);
231 /* Setup any dynamic params in the uart desc */
232 int cpm_uart_init_portdesc(void)
234 pr_debug("CPM uart[-]:init portdesc\n");
237 #ifdef CONFIG_SERIAL_CPM_SMC1
238 cpm_uart_ports[UART_SMC1].smcp = &cpmp->cp_smc[0];
240 * Is SMC1 being relocated?
242 # ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
243 cpm_uart_ports[UART_SMC1].smcup =
244 (smc_uart_t *) & cpmp->cp_dparam[0x3C0];
246 cpm_uart_ports[UART_SMC1].smcup =
247 (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC1];
249 cpm_uart_ports[UART_SMC1].port.mapbase =
250 (unsigned long)&cpmp->cp_smc[0];
251 cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
252 cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
253 cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
254 cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
257 #ifdef CONFIG_SERIAL_CPM_SMC2
258 cpm_uart_ports[UART_SMC2].smcp = &cpmp->cp_smc[1];
259 cpm_uart_ports[UART_SMC2].smcup =
260 (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC2];
261 cpm_uart_ports[UART_SMC2].port.mapbase =
262 (unsigned long)&cpmp->cp_smc[1];
263 cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
264 cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
265 cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
266 cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
269 #ifdef CONFIG_SERIAL_CPM_SCC1
270 cpm_uart_ports[UART_SCC1].sccp = &cpmp->cp_scc[0];
271 cpm_uart_ports[UART_SCC1].sccup =
272 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC1];
273 cpm_uart_ports[UART_SCC1].port.mapbase =
274 (unsigned long)&cpmp->cp_scc[0];
275 cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
276 ~(UART_SCCM_TX | UART_SCCM_RX);
277 cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
278 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
279 cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
280 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
283 #ifdef CONFIG_SERIAL_CPM_SCC2
284 cpm_uart_ports[UART_SCC2].sccp = &cpmp->cp_scc[1];
285 cpm_uart_ports[UART_SCC2].sccup =
286 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC2];
287 cpm_uart_ports[UART_SCC2].port.mapbase =
288 (unsigned long)&cpmp->cp_scc[1];
289 cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
290 ~(UART_SCCM_TX | UART_SCCM_RX);
291 cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
292 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
293 cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
294 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
297 #ifdef CONFIG_SERIAL_CPM_SCC3
298 cpm_uart_ports[UART_SCC3].sccp = &cpmp->cp_scc[2];
299 cpm_uart_ports[UART_SCC3].sccup =
300 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC3];
301 cpm_uart_ports[UART_SCC3].port.mapbase =
302 (unsigned long)&cpmp->cp_scc[2];
303 cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
304 ~(UART_SCCM_TX | UART_SCCM_RX);
305 cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
306 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
307 cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
308 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
311 #ifdef CONFIG_SERIAL_CPM_SCC4
312 cpm_uart_ports[UART_SCC4].sccp = &cpmp->cp_scc[3];
313 cpm_uart_ports[UART_SCC4].sccup =
314 (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC4];
315 cpm_uart_ports[UART_SCC4].port.mapbase =
316 (unsigned long)&cpmp->cp_scc[3];
317 cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
318 ~(UART_SCCM_TX | UART_SCCM_RX);
319 cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
320 ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
321 cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
322 cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;