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, int bits, u16 cval);
68 static void cpm_uart_init_scc(struct uart_cpm_port *pinfo, int sbits, u16 sval);
70 /**************************************************************/
73 * Check, if transmit buffers are processed
75 static unsigned int cpm_uart_tx_empty(struct uart_port *port)
77 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
78 volatile cbd_t *bdp = pinfo->tx_bd_base;
82 if (bdp->cbd_sc & BD_SC_READY)
85 if (bdp->cbd_sc & BD_SC_WRAP) {
92 pr_debug("CPM uart[%d]:tx_empty: %d\n", port->line, ret);
97 static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
99 /* Whee. Do nothing. */
102 static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
104 /* Whee. Do nothing. */
105 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
111 static void cpm_uart_stop_tx(struct uart_port *port, unsigned int tty_stop)
113 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
114 volatile smc_t *smcp = pinfo->smcp;
115 volatile scc_t *sccp = pinfo->sccp;
117 pr_debug("CPM uart[%d]:stop tx\n", port->line);
120 smcp->smc_smcm &= ~SMCM_TX;
122 sccp->scc_sccm &= ~UART_SCCM_TX;
128 static void cpm_uart_start_tx(struct uart_port *port, unsigned int tty_start)
130 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
131 volatile smc_t *smcp = pinfo->smcp;
132 volatile scc_t *sccp = pinfo->sccp;
134 pr_debug("CPM uart[%d]:start tx\n", port->line);
136 /* if in the middle of discarding return */
137 if (IS_DISCARDING(pinfo))
141 if (smcp->smc_smcm & SMCM_TX)
144 if (sccp->scc_sccm & UART_SCCM_TX)
148 if (cpm_uart_tx_pump(port) != 0) {
150 smcp->smc_smcm |= SMCM_TX;
152 sccp->scc_sccm |= UART_SCCM_TX;
159 static void cpm_uart_stop_rx(struct uart_port *port)
161 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
162 volatile smc_t *smcp = pinfo->smcp;
163 volatile scc_t *sccp = pinfo->sccp;
165 pr_debug("CPM uart[%d]:stop rx\n", port->line);
168 smcp->smc_smcm &= ~SMCM_RX;
170 sccp->scc_sccm &= ~UART_SCCM_RX;
174 * Enable Modem status interrupts
176 static void cpm_uart_enable_ms(struct uart_port *port)
178 pr_debug("CPM uart[%d]:enable ms\n", port->line);
184 static void cpm_uart_break_ctl(struct uart_port *port, int break_state)
186 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
187 int line = pinfo - cpm_uart_ports;
189 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line,
193 cpm_line_cr_cmd(line, CPM_CR_STOP_TX);
195 cpm_line_cr_cmd(line, CPM_CR_RESTART_TX);
199 * Transmit characters, refill buffer descriptor, if possible
201 static void cpm_uart_int_tx(struct uart_port *port, struct pt_regs *regs)
203 pr_debug("CPM uart[%d]:TX INT\n", port->line);
205 cpm_uart_tx_pump(port);
211 static void cpm_uart_int_rx(struct uart_port *port, struct pt_regs *regs)
214 unsigned char ch, *cp;
215 struct tty_struct *tty = port->info->tty;
216 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
221 pr_debug("CPM uart[%d]:RX INT\n", port->line);
223 /* Just loop through the closed BDs and copy the characters into
229 status = bdp->cbd_sc;
230 /* If this one is empty, return happy */
231 if (status & BD_SC_EMPTY)
234 /* get number of characters, and check spce in flip-buffer */
237 /* If we have not enough room in tty flip buffer, then we try
238 * later, which will be the next rx-interrupt or a timeout
240 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE) {
241 tty->flip.work.func((void *)tty);
242 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE) {
243 printk(KERN_WARNING "TTY_DONT_FLIP set\n");
249 cp = (unsigned char *)bus_to_virt(bdp->cbd_bufaddr);
251 /* loop through the buffer */
258 (BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV))
260 if (uart_handle_sysrq_char(port, ch, regs))
264 *tty->flip.char_buf_ptr++ = ch;
265 *tty->flip.flag_buf_ptr++ = flg;
268 } /* End while (i--) */
270 /* This BD is ready to be used again. Clear status. get next */
271 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV);
272 bdp->cbd_sc |= BD_SC_EMPTY;
274 if (bdp->cbd_sc & BD_SC_WRAP)
275 bdp = pinfo->rx_bd_base;
280 /* Write back buffer pointer */
281 pinfo->rx_cur = (volatile cbd_t *) bdp;
283 /* activate BH processing */
284 tty_flip_buffer_push(tty);
288 /* Error processing */
292 if (status & BD_SC_BR)
294 if (status & BD_SC_PR)
295 port->icount.parity++;
296 if (status & BD_SC_FR)
297 port->icount.frame++;
298 if (status & BD_SC_OV)
299 port->icount.overrun++;
301 /* Mask out ignored conditions */
302 status &= port->read_status_mask;
304 /* Handle the remaining ones */
305 if (status & BD_SC_BR)
307 else if (status & BD_SC_PR)
309 else if (status & BD_SC_FR)
312 /* overrun does not affect the current character ! */
313 if (status & BD_SC_OV) {
316 /* We skip this buffer */
317 /* CHECK: Is really nothing senseful there */
318 /* ASSUMPTION: it contains nothing valid */
328 * Asynchron mode interrupt handler
330 static irqreturn_t cpm_uart_int(int irq, void *data, struct pt_regs *regs)
333 struct uart_port *port = (struct uart_port *)data;
334 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
335 volatile smc_t *smcp = pinfo->smcp;
336 volatile scc_t *sccp = pinfo->sccp;
338 pr_debug("CPM uart[%d]:IRQ\n", port->line);
341 events = smcp->smc_smce;
342 if (events & SMCM_BRKE)
343 uart_handle_break(port);
344 if (events & SMCM_RX)
345 cpm_uart_int_rx(port, regs);
346 if (events & SMCM_TX)
347 cpm_uart_int_tx(port, regs);
348 smcp->smc_smce = events;
350 events = sccp->scc_scce;
351 if (events & UART_SCCM_BRKE)
352 uart_handle_break(port);
353 if (events & UART_SCCM_RX)
354 cpm_uart_int_rx(port, regs);
355 if (events & UART_SCCM_TX)
356 cpm_uart_int_tx(port, regs);
357 sccp->scc_scce = events;
359 return (events) ? IRQ_HANDLED : IRQ_NONE;
362 static int cpm_uart_startup(struct uart_port *port)
366 pr_debug("CPM uart[%d]:startup\n", port->line);
368 /* Install interrupt handler. */
369 retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port);
379 static void cpm_uart_shutdown(struct uart_port *port)
381 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
382 int line = pinfo - cpm_uart_ports;
384 pr_debug("CPM uart[%d]:shutdown\n", port->line);
386 /* free interrupt handler */
387 free_irq(port->irq, port);
389 /* If the port is not the console, disable Rx and Tx. */
390 if (!(pinfo->flags & FLAG_CONSOLE)) {
393 volatile smc_t *smcp = pinfo->smcp;
394 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
395 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
397 volatile scc_t *sccp = pinfo->sccp;
398 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
399 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
402 /* Shut them really down and reinit buffer descriptors */
403 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
407 static void cpm_uart_set_termios(struct uart_port *port,
408 struct termios *termios, struct termios *old)
414 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
415 int line = pinfo - cpm_uart_ports;
418 pr_debug("CPM uart[%d]:set_termios\n", port->line);
420 spin_lock_irqsave(&port->lock, flags);
421 /* disable uart interrupts */
423 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
425 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
426 pinfo->flags |= FLAG_DISCARDING;
427 spin_unlock_irqrestore(&port->lock, flags);
429 /* if previous configuration exists wait for tx to finish */
430 if (pinfo->baud != 0 && pinfo->bits != 0) {
432 /* point to the last txed bd */
434 if (bdp == pinfo->tx_bd_base)
435 bdp = pinfo->tx_bd_base + (pinfo->tx_nrfifos - 1);
439 /* wait for it to be transmitted */
440 while ((bdp->cbd_sc & BD_SC_READY) != 0)
443 /* and delay for the hw fifo to drain */
444 udelay((3 * 1000000 * pinfo->bits) / pinfo->baud);
447 spin_lock_irqsave(&port->lock, flags);
449 /* Send the CPM an initialize command. */
450 cpm_line_cr_cmd(line, CPM_CR_STOP_TX);
454 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
456 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
458 /* Send the CPM an initialize command. */
459 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
461 spin_unlock_irqrestore(&port->lock, flags);
463 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk / 16);
465 /* Character length programmed into the mode register is the
466 * sum of: 1 start bit, number of data bits, 0 or 1 parity bit,
467 * 1 or 2 stop bits, minus 1.
468 * The value 'bits' counts this for us.
474 switch (termios->c_cflag & CSIZE) {
487 /* Never happens, but GCC is too dumb to figure it out */
494 if (termios->c_cflag & CSTOPB) {
495 cval |= SMCMR_SL; /* Two stops */
496 scval |= SCU_PSMR_SL;
500 if (termios->c_cflag & PARENB) {
502 scval |= SCU_PSMR_PEN;
504 if (!(termios->c_cflag & PARODD)) {
505 cval |= SMCMR_PM_EVEN;
506 scval |= (SCU_PSMR_REVP | SCU_PSMR_TEVP);
511 * Set up parity check flag
513 #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
515 port->read_status_mask = (BD_SC_EMPTY | BD_SC_OV);
516 if (termios->c_iflag & INPCK)
517 port->read_status_mask |= BD_SC_FR | BD_SC_PR;
518 if ((termios->c_iflag & BRKINT) || (termios->c_iflag & PARMRK))
519 port->read_status_mask |= BD_SC_BR;
522 * Characters to ignore
524 port->ignore_status_mask = 0;
525 if (termios->c_iflag & IGNPAR)
526 port->ignore_status_mask |= BD_SC_PR | BD_SC_FR;
527 if (termios->c_iflag & IGNBRK) {
528 port->ignore_status_mask |= BD_SC_BR;
530 * If we're ignore parity and break indicators, ignore
531 * overruns too. (For real raw support).
533 if (termios->c_iflag & IGNPAR)
534 port->ignore_status_mask |= BD_SC_OV;
537 * !!! ignore all characters if CREAD is not set
539 if ((termios->c_cflag & CREAD) == 0)
540 port->read_status_mask &= ~BD_SC_EMPTY;
542 spin_lock_irqsave(&port->lock, flags);
544 cpm_set_brg(pinfo->brg - 1, baud);
546 /* Start bit has not been added (so don't, because we would just
547 * subtract it later), and we need to add one for the number of
548 * stops bits (there is always at least one).
554 cpm_uart_init_smc(pinfo, bits, cval);
556 cpm_uart_init_scc(pinfo, sbits, scval);
561 pinfo->flags &= ~FLAG_DISCARDING;
562 spin_unlock_irqrestore(&port->lock, flags);
566 static const char *cpm_uart_type(struct uart_port *port)
568 pr_debug("CPM uart[%d]:uart_type\n", port->line);
570 return port->type == PORT_CPM ? "CPM UART" : NULL;
574 * verify the new serial_struct (for TIOCSSERIAL).
576 static int cpm_uart_verify_port(struct uart_port *port,
577 struct serial_struct *ser)
581 pr_debug("CPM uart[%d]:verify_port\n", port->line);
583 if (ser->type != PORT_UNKNOWN && ser->type != PORT_CPM)
585 if (ser->irq < 0 || ser->irq >= NR_IRQS)
587 if (ser->baud_base < 9600)
593 * Transmit characters, refill buffer descriptor, if possible
595 static int cpm_uart_tx_pump(struct uart_port *port)
600 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
601 struct circ_buf *xmit = &port->info->xmit;
603 /* Handle xon/xoff */
605 /* Pick next descriptor and fill from buffer */
608 p = bus_to_virt(bdp->cbd_bufaddr);
609 *p++ = xmit->buf[xmit->tail];
611 bdp->cbd_sc |= BD_SC_READY;
613 if (bdp->cbd_sc & BD_SC_WRAP)
614 bdp = pinfo->tx_bd_base;
624 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
625 cpm_uart_stop_tx(port, 0);
629 /* Pick next descriptor and fill from buffer */
632 while (!(bdp->cbd_sc & BD_SC_READY) && (xmit->tail != xmit->head)) {
634 p = bus_to_virt(bdp->cbd_bufaddr);
635 while (count < pinfo->tx_fifosize) {
636 *p++ = xmit->buf[xmit->tail];
637 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
640 if (xmit->head == xmit->tail)
643 bdp->cbd_datlen = count;
644 bdp->cbd_sc |= BD_SC_READY;
646 if (bdp->cbd_sc & BD_SC_WRAP)
647 bdp = pinfo->tx_bd_base;
653 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
654 uart_write_wakeup(port);
656 if (uart_circ_empty(xmit)) {
657 cpm_uart_stop_tx(port, 0);
664 static void cpm_uart_init_scc(struct uart_cpm_port *pinfo, int bits, u16 scval)
666 int line = pinfo - cpm_uart_ports;
668 volatile scc_uart_t *sup;
673 pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line);
678 /* Set the physical address of the host memory
679 * buffers in the buffer descriptors, and the
680 * virtual address for us to work with.
682 pinfo->rx_cur = pinfo->rx_bd_base;
683 mem_addr = pinfo->mem_addr;
684 for (bdp = pinfo->rx_bd_base, i = 0; i < pinfo->rx_nrfifos; i++, bdp++) {
685 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
686 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT | (i < (pinfo->rx_nrfifos - 1) ? 0 : BD_SC_WRAP);
687 mem_addr += pinfo->rx_fifosize;
690 /* Set the physical address of the host memory
691 * buffers in the buffer descriptors, and the
692 * virtual address for us to work with.
694 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize);
695 pinfo->tx_cur = pinfo->tx_bd_base;
696 for (bdp = pinfo->tx_bd_base, i = 0; i < pinfo->tx_nrfifos; i++, bdp++) {
697 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
698 bdp->cbd_sc = BD_SC_INTRPT | (i < (pinfo->tx_nrfifos - 1) ? 0 : BD_SC_WRAP);
699 mem_addr += pinfo->tx_fifosize;
704 pinfo->sccup->scc_genscc.scc_rbase = (unsigned char *)pinfo->rx_bd_base - DPRAM_BASE;
705 pinfo->sccup->scc_genscc.scc_tbase = (unsigned char *)pinfo->tx_bd_base - DPRAM_BASE;
707 /* Set up the uart parameters in the
711 cpm_set_scc_fcr(sup);
713 sup->scc_genscc.scc_mrblr = pinfo->rx_fifosize;
714 sup->scc_maxidl = pinfo->rx_fifosize;
723 sup->scc_char1 = 0x8000;
724 sup->scc_char2 = 0x8000;
725 sup->scc_char3 = 0x8000;
726 sup->scc_char4 = 0x8000;
727 sup->scc_char5 = 0x8000;
728 sup->scc_char6 = 0x8000;
729 sup->scc_char7 = 0x8000;
730 sup->scc_char8 = 0x8000;
731 sup->scc_rccm = 0xc0ff;
733 /* Send the CPM an initialize command.
735 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
737 /* Set UART mode, 8 bit, no parity, one stop.
738 * Enable receive and transmit.
742 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
744 /* Enable rx interrupts and clear all pending events. */
745 scp->scc_sccm = UART_SCCM_RX;
746 scp->scc_scce = 0xffff;
747 scp->scc_dsr = 0x7e7e;
748 scp->scc_psmr = (bits << 12) | scval;
750 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
753 static void cpm_uart_init_smc(struct uart_cpm_port *pinfo, int bits, u16 cval)
755 int line = pinfo - cpm_uart_ports;
757 volatile smc_uart_t *up;
758 volatile u8 *mem_addr;
762 pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line);
767 /* Set the physical address of the host memory
768 * buffers in the buffer descriptors, and the
769 * virtual address for us to work with.
771 mem_addr = pinfo->mem_addr;
772 pinfo->rx_cur = pinfo->rx_bd_base;
773 for (bdp = pinfo->rx_bd_base, i = 0; i < pinfo->rx_nrfifos; i++, bdp++) {
774 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
775 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT | (i < (pinfo->rx_nrfifos - 1) ? 0 : BD_SC_WRAP);
776 mem_addr += pinfo->rx_fifosize;
779 /* Set the physical address of the host memory
780 * buffers in the buffer descriptors, and the
781 * virtual address for us to work with.
783 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize);
784 pinfo->tx_cur = pinfo->tx_bd_base;
785 for (bdp = pinfo->tx_bd_base, i = 0; i < pinfo->tx_nrfifos; i++, bdp++) {
786 bdp->cbd_bufaddr = virt_to_bus(mem_addr);
787 bdp->cbd_sc = BD_SC_INTRPT | (i < (pinfo->tx_nrfifos - 1) ? 0 : BD_SC_WRAP);
788 mem_addr += pinfo->tx_fifosize;
792 pinfo->smcup->smc_rbase = (u_char *)pinfo->rx_bd_base - DPRAM_BASE;
793 pinfo->smcup->smc_tbase = (u_char *)pinfo->tx_bd_base - DPRAM_BASE;
795 /* Set up the uart parameters in the
800 /* Using idle charater time requires some additional tuning. */
801 up->smc_mrblr = pinfo->rx_fifosize;
802 up->smc_maxidl = pinfo->rx_fifosize;
805 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
807 /* Set UART mode, according to the parameters */
808 sp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
810 /* Enable only rx interrupts clear all pending events. */
811 sp->smc_smcm = SMCM_RX;
814 sp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
818 * Initialize port. This is called from early_console stuff
819 * so we have to be careful here !
821 static int cpm_uart_request_port(struct uart_port *port)
823 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
826 pr_debug("CPM uart[%d]:request port\n", port->line);
828 if (pinfo->flags & FLAG_CONSOLE)
832 * Setup any port IO, connect any baud rate generators,
833 * etc. This is expected to be handled by board
836 if (pinfo->set_lineif)
837 pinfo->set_lineif(pinfo);
839 ret = cpm_uart_allocbuf(pinfo, 0);
846 static void cpm_uart_release_port(struct uart_port *port)
848 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
850 if (!(pinfo->flags & FLAG_CONSOLE))
851 cpm_uart_freebuf(pinfo);
855 * Configure/autoconfigure the port.
857 static void cpm_uart_config_port(struct uart_port *port, int flags)
859 pr_debug("CPM uart[%d]:config_port\n", port->line);
861 if (flags & UART_CONFIG_TYPE) {
862 port->type = PORT_CPM;
863 cpm_uart_request_port(port);
866 static struct uart_ops cpm_uart_pops = {
867 .tx_empty = cpm_uart_tx_empty,
868 .set_mctrl = cpm_uart_set_mctrl,
869 .get_mctrl = cpm_uart_get_mctrl,
870 .stop_tx = cpm_uart_stop_tx,
871 .start_tx = cpm_uart_start_tx,
872 .stop_rx = cpm_uart_stop_rx,
873 .enable_ms = cpm_uart_enable_ms,
874 .break_ctl = cpm_uart_break_ctl,
875 .startup = cpm_uart_startup,
876 .shutdown = cpm_uart_shutdown,
877 .set_termios = cpm_uart_set_termios,
878 .type = cpm_uart_type,
879 .release_port = cpm_uart_release_port,
880 .request_port = cpm_uart_request_port,
881 .config_port = cpm_uart_config_port,
882 .verify_port = cpm_uart_verify_port,
885 struct uart_cpm_port cpm_uart_ports[UART_NR] = {
889 .ops = &cpm_uart_pops,
890 .iotype = SERIAL_IO_MEM,
893 .tx_nrfifos = TX_NUM_FIFO,
894 .tx_fifosize = TX_BUF_SIZE,
895 .rx_nrfifos = RX_NUM_FIFO,
896 .rx_fifosize = RX_BUF_SIZE,
897 .set_lineif = smc1_lineif,
902 .ops = &cpm_uart_pops,
903 .iotype = SERIAL_IO_MEM,
906 .tx_nrfifos = TX_NUM_FIFO,
907 .tx_fifosize = TX_BUF_SIZE,
908 .rx_nrfifos = RX_NUM_FIFO,
909 .rx_fifosize = RX_BUF_SIZE,
910 .set_lineif = smc2_lineif,
915 .ops = &cpm_uart_pops,
916 .iotype = SERIAL_IO_MEM,
918 .tx_nrfifos = TX_NUM_FIFO,
919 .tx_fifosize = TX_BUF_SIZE,
920 .rx_nrfifos = RX_NUM_FIFO,
921 .rx_fifosize = RX_BUF_SIZE,
922 .set_lineif = scc1_lineif,
927 .ops = &cpm_uart_pops,
928 .iotype = SERIAL_IO_MEM,
930 .tx_nrfifos = TX_NUM_FIFO,
931 .tx_fifosize = TX_BUF_SIZE,
932 .rx_nrfifos = RX_NUM_FIFO,
933 .rx_fifosize = RX_BUF_SIZE,
934 .set_lineif = scc2_lineif,
939 .ops = &cpm_uart_pops,
940 .iotype = SERIAL_IO_MEM,
942 .tx_nrfifos = TX_NUM_FIFO,
943 .tx_fifosize = TX_BUF_SIZE,
944 .rx_nrfifos = RX_NUM_FIFO,
945 .rx_fifosize = RX_BUF_SIZE,
946 .set_lineif = scc3_lineif,
951 .ops = &cpm_uart_pops,
952 .iotype = SERIAL_IO_MEM,
954 .tx_nrfifos = TX_NUM_FIFO,
955 .tx_fifosize = TX_BUF_SIZE,
956 .rx_nrfifos = RX_NUM_FIFO,
957 .rx_fifosize = RX_BUF_SIZE,
958 .set_lineif = scc4_lineif,
962 #ifdef CONFIG_SERIAL_CPM_CONSOLE
964 * Print a string to the serial port trying not to disturb
965 * any possible real use of the port...
967 * Note that this is called with interrupts already disabled
969 static void cpm_uart_console_write(struct console *co, const char *s,
972 struct uart_cpm_port *pinfo =
973 &cpm_uart_ports[cpm_uart_port_map[co->index]];
975 volatile cbd_t *bdp, *bdbase;
976 volatile unsigned char *cp;
978 if (IS_DISCARDING(pinfo))
981 /* Get the address of the host memory buffer.
984 bdbase = pinfo->tx_bd_base;
987 * Now, do each character. This is not as bad as it looks
988 * since this is a holding FIFO and not a transmitting FIFO.
989 * We could add the complexity of filling the entire transmit
990 * buffer, but we would just wait longer between accesses......
992 for (i = 0; i < count; i++, s++) {
993 /* Wait for transmitter fifo to empty.
994 * Ready indicates output is ready, and xmt is doing
995 * that, not that it is ready for us to send.
997 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1000 /* Send the character out.
1001 * If the buffer address is in the CPM DPRAM, don't
1004 if ((uint) (bdp->cbd_bufaddr) > (uint) CPM_ADDR)
1005 cp = (unsigned char *) (bdp->cbd_bufaddr);
1007 cp = bus_to_virt(bdp->cbd_bufaddr);
1011 bdp->cbd_datlen = 1;
1012 bdp->cbd_sc |= BD_SC_READY;
1014 if (bdp->cbd_sc & BD_SC_WRAP)
1019 /* if a LF, also do CR... */
1021 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1024 if ((uint) (bdp->cbd_bufaddr) > (uint) CPM_ADDR)
1025 cp = (unsigned char *) (bdp->cbd_bufaddr);
1027 cp = bus_to_virt(bdp->cbd_bufaddr);
1030 bdp->cbd_datlen = 1;
1031 bdp->cbd_sc |= BD_SC_READY;
1033 if (bdp->cbd_sc & BD_SC_WRAP)
1041 * Finally, Wait for transmitter & holding register to empty
1042 * and restore the IER
1044 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1047 pinfo->tx_cur = (volatile cbd_t *) bdp;
1051 * Setup console. Be careful is called early !
1053 static int __init cpm_uart_console_setup(struct console *co, char *options)
1055 struct uart_port *port;
1056 struct uart_cpm_port *pinfo;
1064 (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
1065 pinfo = (struct uart_cpm_port *)port;
1067 pinfo->flags |= FLAG_CONSOLE;
1070 uart_parse_options(options, &baud, &parity, &bits, &flow);
1072 bd_t *bd = (bd_t *) __res;
1074 if (bd->bi_baudrate)
1075 baud = bd->bi_baudrate;
1081 * Setup any port IO, connect any baud rate generators,
1082 * etc. This is expected to be handled by board
1085 if (pinfo->set_lineif)
1086 pinfo->set_lineif(pinfo);
1088 ret = cpm_uart_allocbuf(pinfo, 1);
1092 uart_set_options(port, co, baud, parity, bits, flow);
1097 extern struct uart_driver cpm_reg;
1098 static struct console cpm_scc_uart_console = {
1100 .write cpm_uart_console_write,
1101 .device uart_console_device,
1102 .setup cpm_uart_console_setup,
1103 .flags CON_PRINTBUFFER,
1108 int __init cpm_uart_console_init(void)
1110 int ret = cpm_uart_init_portdesc();
1113 register_console(&cpm_scc_uart_console);
1117 console_initcall(cpm_uart_console_init);
1119 #define CPM_UART_CONSOLE &cpm_scc_uart_console
1121 #define CPM_UART_CONSOLE NULL
1124 static struct uart_driver cpm_reg = {
1125 .owner = THIS_MODULE,
1126 .driver_name = "ttyCPM",
1127 .dev_name = "ttyCPM",
1128 .major = SERIAL_CPM_MAJOR,
1129 .minor = SERIAL_CPM_MINOR,
1130 .cons = CPM_UART_CONSOLE,
1133 static int __init cpm_uart_init(void)
1137 printk(KERN_INFO "Serial: CPM driver $Revision: 0.01 $\n");
1139 #ifndef CONFIG_SERIAL_CPM_CONSOLE
1140 ret = cpm_uart_init_portdesc();
1145 cpm_reg.nr = cpm_uart_nr;
1146 ret = uart_register_driver(&cpm_reg);
1151 for (i = 0; i < cpm_uart_nr; i++) {
1152 int con = cpm_uart_port_map[i];
1153 cpm_uart_ports[con].port.line = i;
1154 cpm_uart_ports[con].port.flags = UPF_BOOT_AUTOCONF;
1155 uart_add_one_port(&cpm_reg, &cpm_uart_ports[con].port);
1161 static void __exit cpm_uart_exit(void)
1165 for (i = 0; i < cpm_uart_nr; i++) {
1166 int con = cpm_uart_port_map[i];
1167 uart_remove_one_port(&cpm_reg, &cpm_uart_ports[con].port);
1170 uart_unregister_driver(&cpm_reg);
1173 module_init(cpm_uart_init);
1174 module_exit(cpm_uart_exit);
1176 MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis");
1177 MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $");
1178 MODULE_LICENSE("GPL");
1179 MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR, SERIAL_CPM_MINOR);