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.
15 * (C) 2005 MontaVista Software, Inc. by Vitaly Bordug <vbordug@ru.mvista.com>
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/tty.h>
36 #include <linux/ioport.h>
37 #include <linux/init.h>
38 #include <linux/serial.h>
39 #include <linux/console.h>
40 #include <linux/sysrq.h>
41 #include <linux/device.h>
42 #include <linux/bootmem.h>
43 #include <linux/dma-mapping.h>
47 #include <asm/delay.h>
49 #if defined(CONFIG_SERIAL_CPM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
53 #include <linux/serial_core.h>
54 #include <linux/kernel.h>
58 /***********************************************************************/
60 /* Track which ports are configured as uarts */
61 int cpm_uart_port_map[UART_NR];
62 /* How many ports did we config as uarts */
65 /**************************************************************/
67 static int cpm_uart_tx_pump(struct uart_port *port);
68 static void cpm_uart_init_smc(struct uart_cpm_port *pinfo);
69 static void cpm_uart_init_scc(struct uart_cpm_port *pinfo);
70 static void cpm_uart_initbd(struct uart_cpm_port *pinfo);
72 /**************************************************************/
74 static inline unsigned long cpu2cpm_addr(void *addr)
76 if ((unsigned long)addr >= CPM_ADDR)
77 return (unsigned long)addr;
78 return virt_to_bus(addr);
81 static inline void *cpm2cpu_addr(unsigned long addr)
85 return bus_to_virt(addr);
89 * Check, if transmit buffers are processed
91 static unsigned int cpm_uart_tx_empty(struct uart_port *port)
93 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
94 volatile cbd_t *bdp = pinfo->tx_bd_base;
98 if (bdp->cbd_sc & BD_SC_READY)
101 if (bdp->cbd_sc & BD_SC_WRAP) {
108 pr_debug("CPM uart[%d]:tx_empty: %d\n", port->line, ret);
113 static void cpm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
115 /* Whee. Do nothing. */
118 static unsigned int cpm_uart_get_mctrl(struct uart_port *port)
120 /* Whee. Do nothing. */
121 return TIOCM_CAR | TIOCM_DSR | TIOCM_CTS;
127 static void cpm_uart_stop_tx(struct uart_port *port, unsigned int tty_stop)
129 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
130 volatile smc_t *smcp = pinfo->smcp;
131 volatile scc_t *sccp = pinfo->sccp;
133 pr_debug("CPM uart[%d]:stop tx\n", port->line);
136 smcp->smc_smcm &= ~SMCM_TX;
138 sccp->scc_sccm &= ~UART_SCCM_TX;
144 static void cpm_uart_start_tx(struct uart_port *port, unsigned int tty_start)
146 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
147 volatile smc_t *smcp = pinfo->smcp;
148 volatile scc_t *sccp = pinfo->sccp;
150 pr_debug("CPM uart[%d]:start tx\n", port->line);
153 if (smcp->smc_smcm & SMCM_TX)
156 if (sccp->scc_sccm & UART_SCCM_TX)
160 if (cpm_uart_tx_pump(port) != 0) {
162 smcp->smc_smcm |= SMCM_TX;
163 smcp->smc_smcmr |= SMCMR_TEN;
165 sccp->scc_sccm |= UART_SCCM_TX;
166 pinfo->sccp->scc_gsmrl |= SCC_GSMRL_ENT;
174 static void cpm_uart_stop_rx(struct uart_port *port)
176 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
177 volatile smc_t *smcp = pinfo->smcp;
178 volatile scc_t *sccp = pinfo->sccp;
180 pr_debug("CPM uart[%d]:stop rx\n", port->line);
183 smcp->smc_smcm &= ~SMCM_RX;
185 sccp->scc_sccm &= ~UART_SCCM_RX;
189 * Enable Modem status interrupts
191 static void cpm_uart_enable_ms(struct uart_port *port)
193 pr_debug("CPM uart[%d]:enable ms\n", port->line);
199 static void cpm_uart_break_ctl(struct uart_port *port, int break_state)
201 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
202 int line = pinfo - cpm_uart_ports;
204 pr_debug("CPM uart[%d]:break ctrl, break_state: %d\n", port->line,
208 cpm_line_cr_cmd(line, CPM_CR_STOP_TX);
210 cpm_line_cr_cmd(line, CPM_CR_RESTART_TX);
214 * Transmit characters, refill buffer descriptor, if possible
216 static void cpm_uart_int_tx(struct uart_port *port, struct pt_regs *regs)
218 pr_debug("CPM uart[%d]:TX INT\n", port->line);
220 cpm_uart_tx_pump(port);
226 static void cpm_uart_int_rx(struct uart_port *port, struct pt_regs *regs)
229 unsigned char ch, *cp;
230 struct tty_struct *tty = port->info->tty;
231 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
236 pr_debug("CPM uart[%d]:RX INT\n", port->line);
238 /* Just loop through the closed BDs and copy the characters into
244 status = bdp->cbd_sc;
245 /* If this one is empty, return happy */
246 if (status & BD_SC_EMPTY)
249 /* get number of characters, and check spce in flip-buffer */
252 /* If we have not enough room in tty flip buffer, then we try
253 * later, which will be the next rx-interrupt or a timeout
255 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE) {
256 tty->flip.work.func((void *)tty);
257 if ((tty->flip.count + i) >= TTY_FLIPBUF_SIZE) {
258 printk(KERN_WARNING "TTY_DONT_FLIP set\n");
264 cp = cpm2cpu_addr(bdp->cbd_bufaddr);
266 /* loop through the buffer */
273 (BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV))
275 if (uart_handle_sysrq_char(port, ch, regs))
279 *tty->flip.char_buf_ptr++ = ch;
280 *tty->flip.flag_buf_ptr++ = flg;
283 } /* End while (i--) */
285 /* This BD is ready to be used again. Clear status. get next */
286 bdp->cbd_sc &= ~(BD_SC_BR | BD_SC_FR | BD_SC_PR | BD_SC_OV | BD_SC_ID);
287 bdp->cbd_sc |= BD_SC_EMPTY;
289 if (bdp->cbd_sc & BD_SC_WRAP)
290 bdp = pinfo->rx_bd_base;
296 /* Write back buffer pointer */
297 pinfo->rx_cur = (volatile cbd_t *) bdp;
299 /* activate BH processing */
300 tty_flip_buffer_push(tty);
304 /* Error processing */
308 if (status & BD_SC_BR)
310 if (status & BD_SC_PR)
311 port->icount.parity++;
312 if (status & BD_SC_FR)
313 port->icount.frame++;
314 if (status & BD_SC_OV)
315 port->icount.overrun++;
317 /* Mask out ignored conditions */
318 status &= port->read_status_mask;
320 /* Handle the remaining ones */
321 if (status & BD_SC_BR)
323 else if (status & BD_SC_PR)
325 else if (status & BD_SC_FR)
328 /* overrun does not affect the current character ! */
329 if (status & BD_SC_OV) {
332 /* We skip this buffer */
333 /* CHECK: Is really nothing senseful there */
334 /* ASSUMPTION: it contains nothing valid */
344 * Asynchron mode interrupt handler
346 static irqreturn_t cpm_uart_int(int irq, void *data, struct pt_regs *regs)
349 struct uart_port *port = (struct uart_port *)data;
350 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
351 volatile smc_t *smcp = pinfo->smcp;
352 volatile scc_t *sccp = pinfo->sccp;
354 pr_debug("CPM uart[%d]:IRQ\n", port->line);
357 events = smcp->smc_smce;
358 smcp->smc_smce = events;
359 if (events & SMCM_BRKE)
360 uart_handle_break(port);
361 if (events & SMCM_RX)
362 cpm_uart_int_rx(port, regs);
363 if (events & SMCM_TX)
364 cpm_uart_int_tx(port, regs);
366 events = sccp->scc_scce;
367 sccp->scc_scce = events;
368 if (events & UART_SCCM_BRKE)
369 uart_handle_break(port);
370 if (events & UART_SCCM_RX)
371 cpm_uart_int_rx(port, regs);
372 if (events & UART_SCCM_TX)
373 cpm_uart_int_tx(port, regs);
375 return (events) ? IRQ_HANDLED : IRQ_NONE;
378 static int cpm_uart_startup(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]:startup\n", port->line);
386 /* Install interrupt handler. */
387 retval = request_irq(port->irq, cpm_uart_int, 0, "cpm_uart", port);
393 pinfo->smcp->smc_smcm |= SMCM_RX;
394 pinfo->smcp->smc_smcmr |= SMCMR_REN;
396 pinfo->sccp->scc_sccm |= UART_SCCM_RX;
399 if (!(pinfo->flags & FLAG_CONSOLE))
400 cpm_line_cr_cmd(line,CPM_CR_INIT_TRX);
404 inline void cpm_uart_wait_until_send(struct uart_cpm_port *pinfo)
406 unsigned long target_jiffies = jiffies + pinfo->wait_closing;
408 while (!time_after(jiffies, target_jiffies))
415 static void cpm_uart_shutdown(struct uart_port *port)
417 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
418 int line = pinfo - cpm_uart_ports;
420 pr_debug("CPM uart[%d]:shutdown\n", port->line);
422 /* free interrupt handler */
423 free_irq(port->irq, port);
425 /* If the port is not the console, disable Rx and Tx. */
426 if (!(pinfo->flags & FLAG_CONSOLE)) {
427 /* Wait for all the BDs marked sent */
428 while(!cpm_uart_tx_empty(port))
430 if(pinfo->wait_closing)
431 cpm_uart_wait_until_send(pinfo);
435 volatile smc_t *smcp = pinfo->smcp;
436 smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
437 smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
439 volatile scc_t *sccp = pinfo->sccp;
440 sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
441 sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
444 /* Shut them really down and reinit buffer descriptors */
445 cpm_line_cr_cmd(line, CPM_CR_STOP_TX);
446 cpm_uart_initbd(pinfo);
450 static void cpm_uart_set_termios(struct uart_port *port,
451 struct termios *termios, struct termios *old)
455 u16 cval, scval, prev_mode;
457 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
458 volatile smc_t *smcp = pinfo->smcp;
459 volatile scc_t *sccp = pinfo->sccp;
461 pr_debug("CPM uart[%d]:set_termios\n", port->line);
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 /* Start bit has not been added (so don't, because we would just
545 * subtract it later), and we need to add one for the number of
546 * stops bits (there is always at least one).
550 /* Set the mode register. We want to keep a copy of the
551 * enables, because we want to put them back if they were
554 prev_mode = smcp->smc_smcmr;
555 smcp->smc_smcmr = smcr_mk_clen(bits) | cval | SMCMR_SM_UART;
556 smcp->smc_smcmr |= (prev_mode & (SMCMR_REN | SMCMR_TEN));
558 sccp->scc_psmr = (sbits << 12) | scval;
561 cpm_set_brg(pinfo->brg - 1, baud);
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 = cpm2cpu_addr(bdp->cbd_bufaddr);
610 *p++ = xmit->buf[xmit->tail];
612 bdp->cbd_sc |= BD_SC_READY;
614 if (bdp->cbd_sc & BD_SC_WRAP)
615 bdp = pinfo->tx_bd_base;
625 if (uart_circ_empty(xmit) || uart_tx_stopped(port)) {
626 cpm_uart_stop_tx(port, 0);
630 /* Pick next descriptor and fill from buffer */
633 while (!(bdp->cbd_sc & BD_SC_READY) && (xmit->tail != xmit->head)) {
635 p = cpm2cpu_addr(bdp->cbd_bufaddr);
636 while (count < pinfo->tx_fifosize) {
637 *p++ = xmit->buf[xmit->tail];
638 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
641 if (xmit->head == xmit->tail)
644 bdp->cbd_datlen = count;
645 bdp->cbd_sc |= BD_SC_READY;
648 if (bdp->cbd_sc & BD_SC_WRAP)
649 bdp = pinfo->tx_bd_base;
655 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
656 uart_write_wakeup(port);
658 if (uart_circ_empty(xmit)) {
659 cpm_uart_stop_tx(port, 0);
667 * init buffer descriptors
669 static void cpm_uart_initbd(struct uart_cpm_port *pinfo)
675 pr_debug("CPM uart[%d]:initbd\n", pinfo->port.line);
677 /* Set the physical address of the host memory
678 * buffers in the buffer descriptors, and the
679 * virtual address for us to work with.
681 mem_addr = pinfo->mem_addr;
682 bdp = pinfo->rx_cur = pinfo->rx_bd_base;
683 for (i = 0; i < (pinfo->rx_nrfifos - 1); i++, bdp++) {
684 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr);
685 bdp->cbd_sc = BD_SC_EMPTY | BD_SC_INTRPT;
686 mem_addr += pinfo->rx_fifosize;
689 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr);
690 bdp->cbd_sc = BD_SC_WRAP | BD_SC_EMPTY | BD_SC_INTRPT;
692 /* Set the physical address of the host memory
693 * buffers in the buffer descriptors, and the
694 * virtual address for us to work with.
696 mem_addr = pinfo->mem_addr + L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize);
697 bdp = pinfo->tx_cur = pinfo->tx_bd_base;
698 for (i = 0; i < (pinfo->tx_nrfifos - 1); i++, bdp++) {
699 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr);
700 bdp->cbd_sc = BD_SC_INTRPT;
701 mem_addr += pinfo->tx_fifosize;
704 bdp->cbd_bufaddr = cpu2cpm_addr(mem_addr);
705 bdp->cbd_sc = BD_SC_WRAP | BD_SC_INTRPT;
708 static void cpm_uart_init_scc(struct uart_cpm_port *pinfo)
710 int line = pinfo - cpm_uart_ports;
712 volatile scc_uart_t *sup;
714 pr_debug("CPM uart[%d]:init_scc\n", pinfo->port.line);
720 pinfo->sccup->scc_genscc.scc_rbase = (unsigned char *)pinfo->rx_bd_base - DPRAM_BASE;
721 pinfo->sccup->scc_genscc.scc_tbase = (unsigned char *)pinfo->tx_bd_base - DPRAM_BASE;
723 /* Set up the uart parameters in the
727 cpm_set_scc_fcr(sup);
729 sup->scc_genscc.scc_mrblr = pinfo->rx_fifosize;
730 sup->scc_maxidl = pinfo->rx_fifosize;
739 sup->scc_char1 = 0x8000;
740 sup->scc_char2 = 0x8000;
741 sup->scc_char3 = 0x8000;
742 sup->scc_char4 = 0x8000;
743 sup->scc_char5 = 0x8000;
744 sup->scc_char6 = 0x8000;
745 sup->scc_char7 = 0x8000;
746 sup->scc_char8 = 0x8000;
747 sup->scc_rccm = 0xc0ff;
749 /* Send the CPM an initialize command.
751 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
753 /* Set UART mode, 8 bit, no parity, one stop.
754 * Enable receive and transmit.
758 (SCC_GSMRL_MODE_UART | SCC_GSMRL_TDCR_16 | SCC_GSMRL_RDCR_16);
760 /* Enable rx interrupts and clear all pending events. */
762 scp->scc_scce = 0xffff;
763 scp->scc_dsr = 0x7e7e;
764 scp->scc_psmr = 0x3000;
766 scp->scc_gsmrl |= (SCC_GSMRL_ENR | SCC_GSMRL_ENT);
769 static void cpm_uart_init_smc(struct uart_cpm_port *pinfo)
771 int line = pinfo - cpm_uart_ports;
773 volatile smc_uart_t *up;
775 pr_debug("CPM uart[%d]:init_smc\n", pinfo->port.line);
781 pinfo->smcup->smc_rbase = (u_char *)pinfo->rx_bd_base - DPRAM_BASE;
782 pinfo->smcup->smc_tbase = (u_char *)pinfo->tx_bd_base - DPRAM_BASE;
785 * In case SMC1 is being relocated...
787 #if defined (CONFIG_I2C_SPI_SMC1_UCODE_PATCH)
788 up->smc_rbptr = pinfo->smcup->smc_rbase;
789 up->smc_tbptr = pinfo->smcup->smc_tbase;
792 up->smc_brkcr = 1; /* number of break chars */
796 /* Set up the uart parameters in the
801 /* Using idle charater time requires some additional tuning. */
802 up->smc_mrblr = pinfo->rx_fifosize;
803 up->smc_maxidl = pinfo->rx_fifosize;
808 cpm_line_cr_cmd(line, CPM_CR_INIT_TRX);
810 /* Set UART mode, 8 bit, no parity, one stop.
811 * Enable receive and transmit.
813 sp->smc_smcmr = smcr_mk_clen(9) | SMCMR_SM_UART;
815 /* Enable only rx interrupts clear all pending events. */
819 sp->smc_smcmr |= (SMCMR_REN | SMCMR_TEN);
823 * Initialize port. This is called from early_console stuff
824 * so we have to be careful here !
826 static int cpm_uart_request_port(struct uart_port *port)
828 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
831 pr_debug("CPM uart[%d]:request port\n", port->line);
833 if (pinfo->flags & FLAG_CONSOLE)
837 * Setup any port IO, connect any baud rate generators,
838 * etc. This is expected to be handled by board
841 if (pinfo->set_lineif)
842 pinfo->set_lineif(pinfo);
845 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
846 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
848 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
849 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
852 ret = cpm_uart_allocbuf(pinfo, 0);
857 cpm_uart_initbd(pinfo);
859 cpm_uart_init_smc(pinfo);
861 cpm_uart_init_scc(pinfo);
866 static void cpm_uart_release_port(struct uart_port *port)
868 struct uart_cpm_port *pinfo = (struct uart_cpm_port *)port;
870 if (!(pinfo->flags & FLAG_CONSOLE))
871 cpm_uart_freebuf(pinfo);
875 * Configure/autoconfigure the port.
877 static void cpm_uart_config_port(struct uart_port *port, int flags)
879 pr_debug("CPM uart[%d]:config_port\n", port->line);
881 if (flags & UART_CONFIG_TYPE) {
882 port->type = PORT_CPM;
883 cpm_uart_request_port(port);
886 static struct uart_ops cpm_uart_pops = {
887 .tx_empty = cpm_uart_tx_empty,
888 .set_mctrl = cpm_uart_set_mctrl,
889 .get_mctrl = cpm_uart_get_mctrl,
890 .stop_tx = cpm_uart_stop_tx,
891 .start_tx = cpm_uart_start_tx,
892 .stop_rx = cpm_uart_stop_rx,
893 .enable_ms = cpm_uart_enable_ms,
894 .break_ctl = cpm_uart_break_ctl,
895 .startup = cpm_uart_startup,
896 .shutdown = cpm_uart_shutdown,
897 .set_termios = cpm_uart_set_termios,
898 .type = cpm_uart_type,
899 .release_port = cpm_uart_release_port,
900 .request_port = cpm_uart_request_port,
901 .config_port = cpm_uart_config_port,
902 .verify_port = cpm_uart_verify_port,
905 struct uart_cpm_port cpm_uart_ports[UART_NR] = {
909 .ops = &cpm_uart_pops,
910 .iotype = SERIAL_IO_MEM,
911 .lock = SPIN_LOCK_UNLOCKED,
914 .tx_nrfifos = TX_NUM_FIFO,
915 .tx_fifosize = TX_BUF_SIZE,
916 .rx_nrfifos = RX_NUM_FIFO,
917 .rx_fifosize = RX_BUF_SIZE,
918 .set_lineif = smc1_lineif,
923 .ops = &cpm_uart_pops,
924 .iotype = SERIAL_IO_MEM,
925 .lock = SPIN_LOCK_UNLOCKED,
928 .tx_nrfifos = TX_NUM_FIFO,
929 .tx_fifosize = TX_BUF_SIZE,
930 .rx_nrfifos = RX_NUM_FIFO,
931 .rx_fifosize = RX_BUF_SIZE,
932 .set_lineif = smc2_lineif,
933 #ifdef CONFIG_SERIAL_CPM_ALT_SMC2
940 .ops = &cpm_uart_pops,
941 .iotype = SERIAL_IO_MEM,
942 .lock = SPIN_LOCK_UNLOCKED,
944 .tx_nrfifos = TX_NUM_FIFO,
945 .tx_fifosize = TX_BUF_SIZE,
946 .rx_nrfifos = RX_NUM_FIFO,
947 .rx_fifosize = RX_BUF_SIZE,
948 .set_lineif = scc1_lineif,
949 .wait_closing = SCC_WAIT_CLOSING,
954 .ops = &cpm_uart_pops,
955 .iotype = SERIAL_IO_MEM,
956 .lock = SPIN_LOCK_UNLOCKED,
958 .tx_nrfifos = TX_NUM_FIFO,
959 .tx_fifosize = TX_BUF_SIZE,
960 .rx_nrfifos = RX_NUM_FIFO,
961 .rx_fifosize = RX_BUF_SIZE,
962 .set_lineif = scc2_lineif,
963 .wait_closing = SCC_WAIT_CLOSING,
968 .ops = &cpm_uart_pops,
969 .iotype = SERIAL_IO_MEM,
970 .lock = SPIN_LOCK_UNLOCKED,
972 .tx_nrfifos = TX_NUM_FIFO,
973 .tx_fifosize = TX_BUF_SIZE,
974 .rx_nrfifos = RX_NUM_FIFO,
975 .rx_fifosize = RX_BUF_SIZE,
976 .set_lineif = scc3_lineif,
977 .wait_closing = SCC_WAIT_CLOSING,
982 .ops = &cpm_uart_pops,
983 .iotype = SERIAL_IO_MEM,
984 .lock = SPIN_LOCK_UNLOCKED,
986 .tx_nrfifos = TX_NUM_FIFO,
987 .tx_fifosize = TX_BUF_SIZE,
988 .rx_nrfifos = RX_NUM_FIFO,
989 .rx_fifosize = RX_BUF_SIZE,
990 .set_lineif = scc4_lineif,
991 .wait_closing = SCC_WAIT_CLOSING,
995 #ifdef CONFIG_SERIAL_CPM_CONSOLE
997 * Print a string to the serial port trying not to disturb
998 * any possible real use of the port...
1000 * Note that this is called with interrupts already disabled
1002 static void cpm_uart_console_write(struct console *co, const char *s,
1005 struct uart_cpm_port *pinfo =
1006 &cpm_uart_ports[cpm_uart_port_map[co->index]];
1008 volatile cbd_t *bdp, *bdbase;
1009 volatile unsigned char *cp;
1011 /* Get the address of the host memory buffer.
1013 bdp = pinfo->tx_cur;
1014 bdbase = pinfo->tx_bd_base;
1017 * Now, do each character. This is not as bad as it looks
1018 * since this is a holding FIFO and not a transmitting FIFO.
1019 * We could add the complexity of filling the entire transmit
1020 * buffer, but we would just wait longer between accesses......
1022 for (i = 0; i < count; i++, s++) {
1023 /* Wait for transmitter fifo to empty.
1024 * Ready indicates output is ready, and xmt is doing
1025 * that, not that it is ready for us to send.
1027 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1030 /* Send the character out.
1031 * If the buffer address is in the CPM DPRAM, don't
1034 cp = cpm2cpu_addr(bdp->cbd_bufaddr);
1038 bdp->cbd_datlen = 1;
1039 bdp->cbd_sc |= BD_SC_READY;
1041 if (bdp->cbd_sc & BD_SC_WRAP)
1046 /* if a LF, also do CR... */
1048 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1051 cp = cpm2cpu_addr(bdp->cbd_bufaddr);
1054 bdp->cbd_datlen = 1;
1055 bdp->cbd_sc |= BD_SC_READY;
1057 if (bdp->cbd_sc & BD_SC_WRAP)
1065 * Finally, Wait for transmitter & holding register to empty
1066 * and restore the IER
1068 while ((bdp->cbd_sc & BD_SC_READY) != 0)
1071 pinfo->tx_cur = (volatile cbd_t *) bdp;
1075 * Setup console. Be careful is called early !
1077 static int __init cpm_uart_console_setup(struct console *co, char *options)
1079 struct uart_port *port;
1080 struct uart_cpm_port *pinfo;
1088 (struct uart_port *)&cpm_uart_ports[cpm_uart_port_map[co->index]];
1089 pinfo = (struct uart_cpm_port *)port;
1091 pinfo->flags |= FLAG_CONSOLE;
1094 uart_parse_options(options, &baud, &parity, &bits, &flow);
1096 bd_t *bd = (bd_t *) __res;
1098 if (bd->bi_baudrate)
1099 baud = bd->bi_baudrate;
1105 * Setup any port IO, connect any baud rate generators,
1106 * etc. This is expected to be handled by board
1109 if (pinfo->set_lineif)
1110 pinfo->set_lineif(pinfo);
1112 if (IS_SMC(pinfo)) {
1113 pinfo->smcp->smc_smcm &= ~(SMCM_RX | SMCM_TX);
1114 pinfo->smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
1116 pinfo->sccp->scc_sccm &= ~(UART_SCCM_TX | UART_SCCM_RX);
1117 pinfo->sccp->scc_gsmrl &= ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
1120 ret = cpm_uart_allocbuf(pinfo, 1);
1125 cpm_uart_initbd(pinfo);
1128 cpm_uart_init_smc(pinfo);
1130 cpm_uart_init_scc(pinfo);
1132 uart_set_options(port, co, baud, parity, bits, flow);
1137 static struct uart_driver cpm_reg;
1138 static struct console cpm_scc_uart_console = {
1140 .write = cpm_uart_console_write,
1141 .device = uart_console_device,
1142 .setup = cpm_uart_console_setup,
1143 .flags = CON_PRINTBUFFER,
1148 int __init cpm_uart_console_init(void)
1150 int ret = cpm_uart_init_portdesc();
1153 register_console(&cpm_scc_uart_console);
1157 console_initcall(cpm_uart_console_init);
1159 #define CPM_UART_CONSOLE &cpm_scc_uart_console
1161 #define CPM_UART_CONSOLE NULL
1164 static struct uart_driver cpm_reg = {
1165 .owner = THIS_MODULE,
1166 .driver_name = "ttyCPM",
1167 .dev_name = "ttyCPM",
1168 .major = SERIAL_CPM_MAJOR,
1169 .minor = SERIAL_CPM_MINOR,
1170 .cons = CPM_UART_CONSOLE,
1173 static int __init cpm_uart_init(void)
1177 printk(KERN_INFO "Serial: CPM driver $Revision: 0.01 $\n");
1179 #ifndef CONFIG_SERIAL_CPM_CONSOLE
1180 ret = cpm_uart_init_portdesc();
1185 cpm_reg.nr = cpm_uart_nr;
1186 ret = uart_register_driver(&cpm_reg);
1191 for (i = 0; i < cpm_uart_nr; i++) {
1192 int con = cpm_uart_port_map[i];
1193 cpm_uart_ports[con].port.line = i;
1194 cpm_uart_ports[con].port.flags = UPF_BOOT_AUTOCONF;
1195 uart_add_one_port(&cpm_reg, &cpm_uart_ports[con].port);
1201 static void __exit cpm_uart_exit(void)
1205 for (i = 0; i < cpm_uart_nr; i++) {
1206 int con = cpm_uart_port_map[i];
1207 uart_remove_one_port(&cpm_reg, &cpm_uart_ports[con].port);
1210 uart_unregister_driver(&cpm_reg);
1213 module_init(cpm_uart_init);
1214 module_exit(cpm_uart_exit);
1216 MODULE_AUTHOR("Kumar Gala/Antoniou Pantelis");
1217 MODULE_DESCRIPTION("CPM SCC/SMC port driver $Revision: 0.01 $");
1218 MODULE_LICENSE("GPL");
1219 MODULE_ALIAS_CHARDEV(SERIAL_CPM_MAJOR, SERIAL_CPM_MINOR);