2 * linux/drivers/serial/cpm_uart.c
4 * Driver for CPM (SCC/SMC) serial ports; core driver
6 * Based on arch/ppc/cpm2_io/uart.c by Dan Malek
7 * Based on ppc8xx.c by Thomas Gleixner
8 * Based on drivers/serial/amba.c by Russell King
10 * Maintainer: Kumar Gala (kumar.gala@freescale.com) (CPM2)
11 * Pantelis Antoniou (panto@intracom.gr) (CPM1)
13 * Copyright (C) 2004 Freescale Semiconductor, Inc.
14 * (C) 2004 Intracom, S.A.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <linux/config.h>
33 #include <linux/module.h>
34 #include <linux/tty.h>
35 #include <linux/ioport.h>
36 #include <linux/init.h>
37 #include <linux/serial.h>
38 #include <linux/console.h>
39 #include <linux/sysrq.h>
40 #include <linux/device.h>
41 #include <linux/bootmem.h>
42 #include <linux/dma-mapping.h>
46 #include <asm/delay.h>
48 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
52 #include <linux/serial_core.h>
53 #include <linux/kernel.h>
57 /***********************************************************************/
59 /* Track which ports are configured as uarts */
60 int cpm_uart_port_map[UART_NR];
61 /* How many ports did we config as uarts */
64 /**************************************************************/
66 static int cpm_uart_tx_pump(struct uart_port *port);
67 static void cpm_uart_init_smc(struct uart_cpm_port *pinfo);
68 static void cpm_uart_init_scc(struct uart_cpm_port *pinfo);
69 static void cpm_uart_initbd(struct uart_cpm_port *pinfo);
71 /**************************************************************/
74 * Check, if transmit buffers are processed
76 static unsigned int cpm_uart_tx_empty(struct uart_port *port)
78 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
79 volatile cbd_t *bdp = pinfo->tx_bd_base;
83 if (bdp->cbd_sc & BD_SC_READY)
86 if (bdp->cbd_sc & BD_SC_WRAP) {
93 pr_debug("CPM uart[%d]:tx_empty: %d\n", port->line, ret);
98 static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
100 /* Whee. Do nothing. */
103 static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
105 /* Whee. Do nothing. */
106 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
112 static void cpm_uart_stop_tx(struct uart_port *port, unsigned int tty_stop)
114 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
115 volatile smc_t *smcp = pinfo->smcp;
116 volatile scc_t *sccp = pinfo->sccp;
118 pr_debug("CPM uart[%d]:stop tx\n", port->line);
121 smcp->smc_smcm &= ~SMCM_TX;
123 sccp->scc_sccm &= ~UART_SCCM_TX;
129 static void cpm_uart_start_tx(struct uart_port *port, unsigned int tty_start)
131 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
132 volatile smc_t *smcp = pinfo->smcp;
133 volatile scc_t *sccp = pinfo->sccp;
135 pr_debug("CPM uart[%d]:start tx\n", port->line);
138 if (smcp->smc_smcm & SMCM_TX)
141 if (sccp->scc_sccm & UART_SCCM_TX)
145 if (cpm_uart_tx_pump(port) != 0) {
147 smcp->smc_smcm |= SMCM_TX;
149 sccp->scc_sccm |= UART_SCCM_TX;
156 static void cpm_uart_stop_rx(struct uart_port *port)
158 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
159 volatile smc_t *smcp = pinfo->smcp;
160 volatile scc_t *sccp = pinfo->sccp;
162 pr_debug("CPM uart[%d]:stop rx\n", port->line);
165 smcp->smc_smcm &= ~SMCM_RX;
167 sccp->scc_sccm &= ~UART_SCCM_RX;
171 * Enable Modem status interrupts
173 static void cpm_uart_enable_ms(struct uart_port *port)
175 pr_debug("CPM uart[%d]:enable ms\n", port->line);
181 static void cpm_uart_break_ctl(struct uart_port *port, int break_state)
183 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
184 int line = pinfo - cpm_uart_ports;
186 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line,
190 cpm_line_cr_cmd(line, CPM_CR_STOP_TX);
192 cpm_line_cr_cmd(line, CPM_CR_RESTART_TX);
196 * Transmit characters, refill buffer descriptor, if possible
198 static void cpm_uart_int_tx(struct uart_port *port, struct pt_regs *regs)
200 pr_debug("CPM uart[%d]:TX INT\n", port->line);
202 cpm_uart_tx_pump(port);
208 static void cpm_uart_int_rx(struct uart_port *port, struct pt_regs *regs)
211 unsigned char ch, *cp;
212 struct tty_struct *tty = port->info->tty;
213 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
218 pr_debug("CPM uart[%d]:RX INT\n", port->line);
220 /* Just loop through the closed BDs and copy the characters into
226 status = bdp->cbd_sc;
227 /* If this one is empty, return happy */
228 if (status & BD_SC_EMPTY)
231 /* get number of characters, and check spce in flip-buffer */
234 /* If we have not enough room in tty flip buffer, then we try
235 * later, which will be the next rx-interrupt or a timeout
237 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE) {
238 tty->flip.work.func((void *)tty);
239 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE) {
240 printk(KERN_WARNING "TTY_DONT_FLIP set\n");
246 cp = (unsigned char *)bus_to_virt(bdp->cbd_bufaddr);
248 /* loop through the buffer */
255 (BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV))
257 if (uart_handle_sysrq_char(port, ch, regs))
261 *tty->flip.char_buf_ptr++ = ch;
262 *tty->flip.flag_buf_ptr++ = flg;
265 } /* End while (i--) */
267 /* This BD is ready to be used again. Clear status. get next */
268 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
269 bdp->cbd_sc |= BD_SC_EMPTY;
271 if (bdp->cbd_sc & BD_SC_WRAP)
272 bdp = pinfo->rx_bd_base;
277 /* Write back buffer pointer */
278 pinfo->rx_cur = (volatile cbd_t *) bdp;
280 /* activate BH processing */
281 tty_flip_buffer_push(tty);
285 /* Error processing */
289 if (status & BD_SC_BR)
291 if (status & BD_SC_PR)
292 port->icount.parity++;
293 if (status & BD_SC_FR)
294 port->icount.frame++;
295 if (status & BD_SC_OV)
296 port->icount.overrun++;
298 /* Mask out ignored conditions */
299 status &= port->read_status_mask;
301 /* Handle the remaining ones */
302 if (status & BD_SC_BR)
304 else if (status & BD_SC_PR)
306 else if (status & BD_SC_FR)
309 /* overrun does not affect the current character ! */
310 if (status & BD_SC_OV) {
313 /* We skip this buffer */
314 /* CHECK: Is really nothing senseful there */
315 /* ASSUMPTION: it contains nothing valid */
325 * Asynchron mode interrupt handler
327 static irqreturn_t cpm_uart_int(int irq, void *data, struct pt_regs *regs)
330 struct uart_port *port = (struct uart_port *)data;
331 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
332 volatile smc_t *smcp = pinfo->smcp;
333 volatile scc_t *sccp = pinfo->sccp;
335 pr_debug("CPM uart[%d]:IRQ\n", port->line);
338 events = smcp->smc_smce;
339 if (events & SMCM_BRKE)
340 uart_handle_break(port);
341 if (events & SMCM_RX)
342 cpm_uart_int_rx(port, regs);
343 if (events & SMCM_TX)
344 cpm_uart_int_tx(port, regs);
345 smcp->smc_smce = events;
347 events = sccp->scc_scce;
348 if (events & UART_SCCM_BRKE)
349 uart_handle_break(port);
350 if (events & UART_SCCM_RX)
351 cpm_uart_int_rx(port, regs);
352 if (events & UART_SCCM_TX)
353 cpm_uart_int_tx(port, regs);
354 sccp->scc_scce = events;
356 return (events) ? IRQ_HANDLED : IRQ_NONE;
359 static int cpm_uart_startup(struct uart_port *port)
362 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
364 pr_debug("CPM uart[%d]:startup\n", port->line);
366 /* Install interrupt handler. */
367 retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port);
373 pinfo->smcp->smc_smcm |= SMCM_RX;
374 pinfo->smcp->smc_smcmr |= SMCMR_REN;
376 pinfo->sccp->scc_sccm |= UART_SCCM_RX;
385 static void cpm_uart_shutdown(struct uart_port *port)
387 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
388 int line = pinfo - cpm_uart_ports;
390 pr_debug("CPM uart[%d]:shutdown\n", port->line);
392 /* free interrupt handler */
393 free_irq(port->irq, port);
395 /* If the port is not the console, disable Rx and Tx. */
396 if (!(pinfo->flags & FLAG_CONSOLE)) {
399 volatile smc_t *smcp = pinfo->smcp;
400 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
401 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
403 volatile scc_t *sccp = pinfo->sccp;
404 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
405 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
408 /* Shut them really down and reinit buffer descriptors */
409 cpm_line_cr_cmd(line, CPM_CR_STOP_TX);
410 cpm_uart_initbd(pinfo);
414 static void cpm_uart_set_termios(struct uart_port *port,
415 struct termios *termios, struct termios *old)
419 u16 cval, scval, prev_mode;
421 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
422 volatile smc_t *smcp = pinfo->smcp;
423 volatile scc_t *sccp = pinfo->sccp;
425 pr_debug("CPM uart[%d]:set_termios\n", port->line);
427 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
429 /* Character length programmed into the mode register is the
430 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
431 * 1 or 2 stop bits, minus 1.
432 * The value 'bits' counts this for us.
438 switch (termios->c_cflag & CSIZE) {
451 /* Never happens, but GCC is too dumb to figure it out */
458 if (termios->c_cflag & CSTOPB) {
459 cval |= SMCMR_SL; /* Two stops */
460 scval |= SCU_PSMR_SL;
464 if (termios->c_cflag & PARENB) {
466 scval |= SCU_PSMR_PEN;
468 if (!(termios->c_cflag & PARODD)) {
469 cval |= SMCMR_PM_EVEN;
470 scval |= (SCU_PSMR_REVP | SCU_PSMR_TEVP);
475 * Set up parity check flag
477 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
479 port->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
480 if (termios->c_iflag & INPCK)
481 port->read_status_mask |= BD_SC_FR | BD_SC_PR;
482 if ((termios->c_iflag & BRKINT) || (termios->c_iflag & PARMRK))
483 port->read_status_mask |= BD_SC_BR;
486 * Characters to ignore
488 port->ignore_status_mask = 0;
489 if (termios->c_iflag & IGNPAR)
490 port->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
491 if (termios->c_iflag & IGNBRK) {
492 port->ignore_status_mask |= BD_SC_BR;
494 * If we're ignore parity and break indicators, ignore
495 * overruns too. (For real raw support).
497 if (termios->c_iflag & IGNPAR)
498 port->ignore_status_mask |= BD_SC_OV;
501 * !!! ignore all characters if CREAD is not set
503 if ((termios->c_cflag & CREAD) == 0)
504 port->read_status_mask &= ~BD_SC_EMPTY;
506 spin_lock_irqsave(&port->lock, flags);
508 /* Start bit has not been added (so don't, because we would just
509 * subtract it later), and we need to add one for the number of
510 * stops bits (there is always at least one).
514 /* Set the mode register. We want to keep a copy of the
515 * enables, because we want to put them back if they were
518 prev_mode = smcp->smc_smcmr;
519 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
520 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
522 sccp->scc_psmr = (sbits << 12) | scval;
525 cpm_set_brg(pinfo->brg - 1, baud);
526 spin_unlock_irqrestore(&port->lock, flags);
530 static const char *cpm_uart_type(struct uart_port *port)
532 pr_debug("CPM uart[%d]:uart_type\n", port->line);
534 return port->type == PORT_CPM ? "CPM UART" : NULL;
538 * verify the new serial_struct (for TIOCSSERIAL).
540 static int cpm_uart_verify_port(struct uart_port *port,
541 struct serial_struct *ser)
545 pr_debug("CPM uart[%d]:verify_port\n", port->line);
547 if (ser->type != PORT_UNKNOWN && ser->type != PORT_CPM)
549 if (ser->irq < 0 || ser->irq >= NR_IRQS)
551 if (ser->baud_base < 9600)
557 * Transmit characters, refill buffer descriptor, if possible
559 static int cpm_uart_tx_pump(struct uart_port *port)
564 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
565 struct circ_buf *xmit = &port->info->xmit;
567 /* Handle xon/xoff */
569 /* Pick next descriptor and fill from buffer */
572 p = bus_to_virt(bdp->cbd_bufaddr);
573 *p++ = xmit->buf[xmit->tail];
575 bdp->cbd_sc |= BD_SC_READY;
577 if (bdp->cbd_sc & BD_SC_WRAP)
578 bdp = pinfo->tx_bd_base;
588 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
589 cpm_uart_stop_tx(port, 0);
593 /* Pick next descriptor and fill from buffer */
596 while (!(bdp->cbd_sc & BD_SC_READY) && (xmit->tail != xmit->head)) {
598 p = bus_to_virt(bdp->cbd_bufaddr);
599 while (count < pinfo->tx_fifosize) {
600 *p++ = xmit->buf[xmit->tail];
601 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
604 if (xmit->head == xmit->tail)
607 bdp->cbd_datlen = count;
608 bdp->cbd_sc |= BD_SC_READY;
610 if (bdp->cbd_sc & BD_SC_WRAP)
611 bdp = pinfo->tx_bd_base;
617 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
618 uart_write_wakeup(port);
620 if (uart_circ_empty(xmit)) {
621 cpm_uart_stop_tx(port, 0);
629 * init buffer descriptors
631 static void cpm_uart_initbd(struct uart_cpm_port *pinfo)
637 pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line);
639 /* Set the physical address of the host memory
640 * buffers in the buffer descriptors, and the
641 * virtual address for us to work with.
643 mem_addr = pinfo->mem_addr;
644 bdp = pinfo->rx_cur = pinfo->rx_bd_base;
645 for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) {
646 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
647 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT;
648 mem_addr += pinfo->rx_fifosize;
651 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
652 bdp->cbd_sc = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
654 /* Set the physical address of the host memory
655 * buffers in the buffer descriptors, and the
656 * virtual address for us to work with.
658 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize);
659 bdp = pinfo->tx_cur = pinfo->tx_bd_base;
660 for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) {
661 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
662 bdp->cbd_sc = BD_SC_INTRPT;
663 mem_addr += pinfo->tx_fifosize;
666 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
667 bdp->cbd_sc = BD_SC_WRAP | BD_SC_INTRPT;
670 static void cpm_uart_init_scc(struct uart_cpm_port *pinfo)
672 int line = pinfo - cpm_uart_ports;
674 volatile scc_uart_t *sup;
676 pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line);
682 pinfo->sccup->scc_genscc.scc_rbase = (unsigned char *)pinfo->rx_bd_base - DPRAM_BASE;
683 pinfo->sccup->scc_genscc.scc_tbase = (unsigned char *)pinfo->tx_bd_base - DPRAM_BASE;
685 /* Set up the uart parameters in the
689 cpm_set_scc_fcr(sup);
691 sup->scc_genscc.scc_mrblr = pinfo->rx_fifosize;
692 sup->scc_maxidl = pinfo->rx_fifosize;
701 sup->scc_char1 = 0x8000;
702 sup->scc_char2 = 0x8000;
703 sup->scc_char3 = 0x8000;
704 sup->scc_char4 = 0x8000;
705 sup->scc_char5 = 0x8000;
706 sup->scc_char6 = 0x8000;
707 sup->scc_char7 = 0x8000;
708 sup->scc_char8 = 0x8000;
709 sup->scc_rccm = 0xc0ff;
711 /* Send the CPM an initialize command.
713 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
715 /* Set UART mode, 8 bit, no parity, one stop.
716 * Enable receive and transmit.
720 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
722 /* Enable rx interrupts and clear all pending events. */
724 scp->scc_scce = 0xffff;
725 scp->scc_dsr = 0x7e7e;
726 scp->scc_psmr = 0x3000;
728 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
731 static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
733 int line = pinfo - cpm_uart_ports;
735 volatile smc_uart_t *up;
737 pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line);
743 pinfo->smcup->smc_rbase = (u_char *)pinfo->rx_bd_base - DPRAM_BASE;
744 pinfo->smcup->smc_tbase = (u_char *)pinfo->tx_bd_base - DPRAM_BASE;
747 * In case SMC1 is being relocated...
749 #if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
750 up->smc_rbptr = pinfo->smcup->smc_rbase;
751 up->smc_tbptr = pinfo->smcup->smc_tbase;
754 up->smc_brkcr = 1; /* number of break chars */
758 /* Set up the uart parameters in the
763 /* Using idle charater time requires some additional tuning. */
764 up->smc_mrblr = pinfo->rx_fifosize;
765 up->smc_maxidl = pinfo->rx_fifosize;
768 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
770 /* Set UART mode, 8 bit, no parity, one stop.
771 * Enable receive and transmit.
773 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
775 /* Enable only rx interrupts clear all pending events. */
779 sp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
783 * Initialize port. This is called from early_console stuff
784 * so we have to be careful here !
786 static int cpm_uart_request_port(struct uart_port *port)
788 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
791 pr_debug("CPM uart[%d]:request port\n", port->line);
793 if (pinfo->flags & FLAG_CONSOLE)
797 * Setup any port IO, connect any baud rate generators,
798 * etc. This is expected to be handled by board
801 if (pinfo->set_lineif)
802 pinfo->set_lineif(pinfo);
805 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
806 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
808 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
809 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
812 ret = cpm_uart_allocbuf(pinfo, 0);
817 cpm_uart_initbd(pinfo);
822 static void cpm_uart_release_port(struct uart_port *port)
824 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
826 if (!(pinfo->flags & FLAG_CONSOLE))
827 cpm_uart_freebuf(pinfo);
831 * Configure/autoconfigure the port.
833 static void cpm_uart_config_port(struct uart_port *port, int flags)
835 pr_debug("CPM uart[%d]:config_port\n", port->line);
837 if (flags & UART_CONFIG_TYPE) {
838 port->type = PORT_CPM;
839 cpm_uart_request_port(port);
842 static struct uart_ops cpm_uart_pops = {
843 .tx_empty = cpm_uart_tx_empty,
844 .set_mctrl = cpm_uart_set_mctrl,
845 .get_mctrl = cpm_uart_get_mctrl,
846 .stop_tx = cpm_uart_stop_tx,
847 .start_tx = cpm_uart_start_tx,
848 .stop_rx = cpm_uart_stop_rx,
849 .enable_ms = cpm_uart_enable_ms,
850 .break_ctl = cpm_uart_break_ctl,
851 .startup = cpm_uart_startup,
852 .shutdown = cpm_uart_shutdown,
853 .set_termios = cpm_uart_set_termios,
854 .type = cpm_uart_type,
855 .release_port = cpm_uart_release_port,
856 .request_port = cpm_uart_request_port,
857 .config_port = cpm_uart_config_port,
858 .verify_port = cpm_uart_verify_port,
861 struct uart_cpm_port cpm_uart_ports[UART_NR] = {
865 .ops = &cpm_uart_pops,
866 .iotype = SERIAL_IO_MEM,
867 .lock = SPIN_LOCK_UNLOCKED,
870 .tx_nrfifos = TX_NUM_FIFO,
871 .tx_fifosize = TX_BUF_SIZE,
872 .rx_nrfifos = RX_NUM_FIFO,
873 .rx_fifosize = RX_BUF_SIZE,
874 .set_lineif = smc1_lineif,
879 .ops = &cpm_uart_pops,
880 .iotype = SERIAL_IO_MEM,
881 .lock = SPIN_LOCK_UNLOCKED,
884 .tx_nrfifos = TX_NUM_FIFO,
885 .tx_fifosize = TX_BUF_SIZE,
886 .rx_nrfifos = RX_NUM_FIFO,
887 .rx_fifosize = RX_BUF_SIZE,
888 .set_lineif = smc2_lineif,
889 #ifdef CONFIG_SERIAL_CPM_ALT_SMC2
896 .ops = &cpm_uart_pops,
897 .iotype = SERIAL_IO_MEM,
898 .lock = SPIN_LOCK_UNLOCKED,
900 .tx_nrfifos = TX_NUM_FIFO,
901 .tx_fifosize = TX_BUF_SIZE,
902 .rx_nrfifos = RX_NUM_FIFO,
903 .rx_fifosize = RX_BUF_SIZE,
904 .set_lineif = scc1_lineif,
909 .ops = &cpm_uart_pops,
910 .iotype = SERIAL_IO_MEM,
911 .lock = SPIN_LOCK_UNLOCKED,
913 .tx_nrfifos = TX_NUM_FIFO,
914 .tx_fifosize = TX_BUF_SIZE,
915 .rx_nrfifos = RX_NUM_FIFO,
916 .rx_fifosize = RX_BUF_SIZE,
917 .set_lineif = scc2_lineif,
922 .ops = &cpm_uart_pops,
923 .iotype = SERIAL_IO_MEM,
924 .lock = SPIN_LOCK_UNLOCKED,
926 .tx_nrfifos = TX_NUM_FIFO,
927 .tx_fifosize = TX_BUF_SIZE,
928 .rx_nrfifos = RX_NUM_FIFO,
929 .rx_fifosize = RX_BUF_SIZE,
930 .set_lineif = scc3_lineif,
935 .ops = &cpm_uart_pops,
936 .iotype = SERIAL_IO_MEM,
937 .lock = SPIN_LOCK_UNLOCKED,
939 .tx_nrfifos = TX_NUM_FIFO,
940 .tx_fifosize = TX_BUF_SIZE,
941 .rx_nrfifos = RX_NUM_FIFO,
942 .rx_fifosize = RX_BUF_SIZE,
943 .set_lineif = scc4_lineif,
947 #ifdef CONFIG_SERIAL_CPM_CONSOLE
949 * Print a string to the serial port trying not to disturb
950 * any possible real use of the port...
952 * Note that this is called with interrupts already disabled
954 static void cpm_uart_console_write(struct console *co, const char *s,
957 struct uart_cpm_port *pinfo =
958 &cpm_uart_ports[cpm_uart_port_map[co->index]];
960 volatile cbd_t *bdp, *bdbase;
961 volatile unsigned char *cp;
963 /* Get the address of the host memory buffer.
966 bdbase = pinfo->tx_bd_base;
969 * Now, do each character. This is not as bad as it looks
970 * since this is a holding FIFO and not a transmitting FIFO.
971 * We could add the complexity of filling the entire transmit
972 * buffer, but we would just wait longer between accesses......
974 for (i = 0; i < count; i++, s++) {
975 /* Wait for transmitter fifo to empty.
976 * Ready indicates output is ready, and xmt is doing
977 * that, not that it is ready for us to send.
979 while ((bdp->cbd_sc & BD_SC_READY) != 0)
982 /* Send the character out.
983 * If the buffer address is in the CPM DPRAM, don't
986 if ((uint) (bdp->cbd_bufaddr) > (uint) CPM_ADDR)
987 cp = (unsigned char *) (bdp->cbd_bufaddr);
989 cp = bus_to_virt(bdp->cbd_bufaddr);
994 bdp->cbd_sc |= BD_SC_READY;
996 if (bdp->cbd_sc & BD_SC_WRAP)
1001 /* if a LF, also do CR... */
1003 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1006 if ((uint) (bdp->cbd_bufaddr) > (uint) CPM_ADDR)
1007 cp = (unsigned char *) (bdp->cbd_bufaddr);
1009 cp = bus_to_virt(bdp->cbd_bufaddr);
1012 bdp->cbd_datlen = 1;
1013 bdp->cbd_sc |= BD_SC_READY;
1015 if (bdp->cbd_sc & BD_SC_WRAP)
1023 * Finally, Wait for transmitter & holding register to empty
1024 * and restore the IER
1026 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1029 pinfo->tx_cur = (volatile cbd_t *) bdp;
1033 * Setup console. Be careful is called early !
1035 static int __init cpm_uart_console_setup(struct console *co, char *options)
1037 struct uart_port *port;
1038 struct uart_cpm_port *pinfo;
1046 (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
1047 pinfo = (struct uart_cpm_port *)port;
1049 pinfo->flags |= FLAG_CONSOLE;
1052 uart_parse_options(options, &baud, &parity, &bits, &flow);
1054 bd_t *bd = (bd_t *) __res;
1056 if (bd->bi_baudrate)
1057 baud = bd->bi_baudrate;
1063 * Setup any port IO, connect any baud rate generators,
1064 * etc. This is expected to be handled by board
1067 if (pinfo->set_lineif)
1068 pinfo->set_lineif(pinfo);
1070 if (IS_SMC(pinfo)) {
1071 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
1072 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
1074 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
1075 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
1078 ret = cpm_uart_allocbuf(pinfo, 1);
1083 cpm_uart_initbd(pinfo);
1086 cpm_uart_init_smc(pinfo);
1088 cpm_uart_init_scc(pinfo);
1090 uart_set_options(port, co, baud, parity, bits, flow);
1095 extern struct uart_driver cpm_reg;
1096 static struct console cpm_scc_uart_console = {
1098 .write cpm_uart_console_write,
1099 .device uart_console_device,
1100 .setup cpm_uart_console_setup,
1101 .flags CON_PRINTBUFFER,
1106 int __init cpm_uart_console_init(void)
1108 int ret = cpm_uart_init_portdesc();
1111 register_console(&cpm_scc_uart_console);
1115 console_initcall(cpm_uart_console_init);
1117 #define CPM_UART_CONSOLE &cpm_scc_uart_console
1119 #define CPM_UART_CONSOLE NULL
1122 static struct uart_driver cpm_reg = {
1123 .owner = THIS_MODULE,
1124 .driver_name = "ttyCPM",
1125 .dev_name = "ttyCPM",
1126 .major = SERIAL_CPM_MAJOR,
1127 .minor = SERIAL_CPM_MINOR,
1128 .cons = CPM_UART_CONSOLE,
1131 static int __init cpm_uart_init(void)
1135 printk(KERN_INFO "Serial: CPM driver $Revision: 0.01 $\n");
1137 #ifndef CONFIG_SERIAL_CPM_CONSOLE
1138 ret = cpm_uart_init_portdesc();
1143 cpm_reg.nr = cpm_uart_nr;
1144 ret = uart_register_driver(&cpm_reg);
1149 for (i = 0; i < cpm_uart_nr; i++) {
1150 int con = cpm_uart_port_map[i];
1151 cpm_uart_ports[con].port.line = i;
1152 cpm_uart_ports[con].port.flags = UPF_BOOT_AUTOCONF;
1153 uart_add_one_port(&cpm_reg, &cpm_uart_ports[con].port);
1159 static void __exit cpm_uart_exit(void)
1163 for (i = 0; i < cpm_uart_nr; i++) {
1164 int con = cpm_uart_port_map[i];
1165 uart_remove_one_port(&cpm_reg, &cpm_uart_ports[con].port);
1168 uart_unregister_driver(&cpm_reg);
1171 module_init(cpm_uart_init);
1172 module_exit(cpm_uart_exit);
1174 MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis");
1175 MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $");
1176 MODULE_LICENSE("GPL");
1177 MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR, SERIAL_CPM_MINOR);