1 /* MN10300 On-chip serial port UART driver
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 static const char serial_name[] = "MN10300 Serial driver";
13 static const char serial_version[] = "mn10300_serial-1.0";
14 static const char serial_revdate[] = "2007-11-06";
16 #if defined(CONFIG_MN10300_TTYSM_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
20 #include <linux/module.h>
21 #include <linux/serial.h>
22 #include <linux/circ_buf.h>
23 #include <linux/errno.h>
24 #include <linux/signal.h>
25 #include <linux/sched.h>
26 #include <linux/timer.h>
27 #include <linux/interrupt.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
30 #include <linux/major.h>
31 #include <linux/string.h>
32 #include <linux/ioport.h>
34 #include <linux/slab.h>
35 #include <linux/init.h>
36 #include <linux/console.h>
37 #include <linux/sysrq.h>
39 #include <asm/system.h>
42 #include <asm/bitops.h>
43 #include <asm/serial-regs.h>
44 #include <unit/timex.h>
45 #include "mn10300-serial.h"
49 #define GxICR(X) CROSS_GxICR(X, 0)
50 #endif /* CONFIG_SMP */
52 #define kenter(FMT, ...) \
53 printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
54 #define _enter(FMT, ...) \
55 no_printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
56 #define kdebug(FMT, ...) \
57 printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
58 #define _debug(FMT, ...) \
59 no_printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
60 #define kproto(FMT, ...) \
61 printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
62 #define _proto(FMT, ...) \
63 no_printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
66 /* c_cflag bit meaning */
67 #define CODMSB 004000000000 /* change Transfer bit-order */
72 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
73 static void mn10300_serial_console_write(struct console *co,
74 const char *s, unsigned count);
75 static int __init mn10300_serial_console_setup(struct console *co,
78 static struct uart_driver mn10300_serial_driver;
79 static struct console mn10300_serial_console = {
81 .write = mn10300_serial_console_write,
82 .device = uart_console_device,
83 .setup = mn10300_serial_console_setup,
84 .flags = CON_PRINTBUFFER,
86 .data = &mn10300_serial_driver,
90 static struct uart_driver mn10300_serial_driver = {
92 .driver_name = "mn10300-serial",
97 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
98 .cons = &mn10300_serial_console,
102 static unsigned int mn10300_serial_tx_empty(struct uart_port *);
103 static void mn10300_serial_set_mctrl(struct uart_port *, unsigned int mctrl);
104 static unsigned int mn10300_serial_get_mctrl(struct uart_port *);
105 static void mn10300_serial_stop_tx(struct uart_port *);
106 static void mn10300_serial_start_tx(struct uart_port *);
107 static void mn10300_serial_send_xchar(struct uart_port *, char ch);
108 static void mn10300_serial_stop_rx(struct uart_port *);
109 static void mn10300_serial_enable_ms(struct uart_port *);
110 static void mn10300_serial_break_ctl(struct uart_port *, int ctl);
111 static int mn10300_serial_startup(struct uart_port *);
112 static void mn10300_serial_shutdown(struct uart_port *);
113 static void mn10300_serial_set_termios(struct uart_port *,
114 struct ktermios *new,
115 struct ktermios *old);
116 static const char *mn10300_serial_type(struct uart_port *);
117 static void mn10300_serial_release_port(struct uart_port *);
118 static int mn10300_serial_request_port(struct uart_port *);
119 static void mn10300_serial_config_port(struct uart_port *, int);
120 static int mn10300_serial_verify_port(struct uart_port *,
121 struct serial_struct *);
122 #ifdef CONFIG_CONSOLE_POLL
123 static void mn10300_serial_poll_put_char(struct uart_port *, unsigned char);
124 static int mn10300_serial_poll_get_char(struct uart_port *);
127 static const struct uart_ops mn10300_serial_ops = {
128 .tx_empty = mn10300_serial_tx_empty,
129 .set_mctrl = mn10300_serial_set_mctrl,
130 .get_mctrl = mn10300_serial_get_mctrl,
131 .stop_tx = mn10300_serial_stop_tx,
132 .start_tx = mn10300_serial_start_tx,
133 .send_xchar = mn10300_serial_send_xchar,
134 .stop_rx = mn10300_serial_stop_rx,
135 .enable_ms = mn10300_serial_enable_ms,
136 .break_ctl = mn10300_serial_break_ctl,
137 .startup = mn10300_serial_startup,
138 .shutdown = mn10300_serial_shutdown,
139 .set_termios = mn10300_serial_set_termios,
140 .type = mn10300_serial_type,
141 .release_port = mn10300_serial_release_port,
142 .request_port = mn10300_serial_request_port,
143 .config_port = mn10300_serial_config_port,
144 .verify_port = mn10300_serial_verify_port,
145 #ifdef CONFIG_CONSOLE_POLL
146 .poll_put_char = mn10300_serial_poll_put_char,
147 .poll_get_char = mn10300_serial_poll_get_char,
151 static irqreturn_t mn10300_serial_interrupt(int irq, void *dev_id);
154 * the first on-chip serial port: ttySM0 (aka SIF0)
156 #ifdef CONFIG_MN10300_TTYSM0
157 struct mn10300_serial_port mn10300_serial_port_sif0 = {
158 .uart.ops = &mn10300_serial_ops,
159 .uart.membase = (void __iomem *) &SC0CTR,
160 .uart.mapbase = (unsigned long) &SC0CTR,
161 .uart.iotype = UPIO_MEM,
163 .uart.uartclk = 0, /* MN10300_IOCLK, */
165 .uart.flags = UPF_BOOT_AUTOCONF,
167 .uart.type = PORT_MN10300,
169 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif0.uart.lock),
173 ._status = (volatile u8 *)&SC0STR,
177 .rx_name = "ttySM0:Rx",
178 .tx_name = "ttySM0:Tx",
179 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
180 .tm_name = "ttySM0:Timer8",
185 .div_timer = MNSCx_DIV_TIMER_16BIT,
186 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
187 .tm_name = "ttySM0:Timer0",
189 ._tmxbr = (volatile u16 *)&TM0BR,
192 .div_timer = MNSCx_DIV_TIMER_8BIT,
193 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
194 .tm_name = "ttySM0:Timer2",
196 ._tmxbr = (volatile u16 *)&TM2BR,
199 .div_timer = MNSCx_DIV_TIMER_8BIT,
201 #error "Unknown config for ttySM0"
205 .rx_icr = &GxICR(SC0RXIRQ),
206 .tx_icr = &GxICR(SC0TXIRQ),
207 .clock_src = MNSCx_CLOCK_SRC_IOCLK,
209 #ifdef CONFIG_GDBSTUB_ON_TTYSM0
213 #endif /* CONFIG_MN10300_TTYSM0 */
216 * the second on-chip serial port: ttySM1 (aka SIF1)
218 #ifdef CONFIG_MN10300_TTYSM1
219 struct mn10300_serial_port mn10300_serial_port_sif1 = {
220 .uart.ops = &mn10300_serial_ops,
221 .uart.membase = (void __iomem *) &SC1CTR,
222 .uart.mapbase = (unsigned long) &SC1CTR,
223 .uart.iotype = UPIO_MEM,
225 .uart.uartclk = 0, /* MN10300_IOCLK, */
227 .uart.flags = UPF_BOOT_AUTOCONF,
229 .uart.type = PORT_MN10300,
231 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif1.uart.lock),
235 ._status = (volatile u8 *)&SC1STR,
239 .rx_name = "ttySM1:Rx",
240 .tx_name = "ttySM1:Tx",
241 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
242 .tm_name = "ttySM1:Timer9",
247 .div_timer = MNSCx_DIV_TIMER_16BIT,
248 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
249 .tm_name = "ttySM1:Timer3",
251 ._tmxbr = (volatile u16 *)&TM3BR,
254 .div_timer = MNSCx_DIV_TIMER_8BIT,
255 #elif defined(CONFIG_MN10300_TTYSM1_TIMER12)
256 .tm_name = "ttySM1/Timer12",
261 .div_timer = MNSCx_DIV_TIMER_16BIT,
263 #error "Unknown config for ttySM1"
267 .rx_icr = &GxICR(SC1RXIRQ),
268 .tx_icr = &GxICR(SC1TXIRQ),
269 .clock_src = MNSCx_CLOCK_SRC_IOCLK,
271 #ifdef CONFIG_GDBSTUB_ON_TTYSM1
275 #endif /* CONFIG_MN10300_TTYSM1 */
278 * the third on-chip serial port: ttySM2 (aka SIF2)
280 #ifdef CONFIG_MN10300_TTYSM2
281 struct mn10300_serial_port mn10300_serial_port_sif2 = {
282 .uart.ops = &mn10300_serial_ops,
283 .uart.membase = (void __iomem *) &SC2CTR,
284 .uart.mapbase = (unsigned long) &SC2CTR,
285 .uart.iotype = UPIO_MEM,
287 .uart.uartclk = 0, /* MN10300_IOCLK, */
289 .uart.flags = UPF_BOOT_AUTOCONF,
291 #ifdef CONFIG_MN10300_TTYSM2_CTS
292 .uart.type = PORT_MN10300_CTS,
294 .uart.type = PORT_MN10300,
297 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif2.uart.lock),
301 ._status = (volatile u8 *)&SC2STR,
305 .rx_name = "ttySM2:Rx",
306 .tx_name = "ttySM2:Tx",
307 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
308 .tm_name = "ttySM2/Timer10",
313 .div_timer = MNSCx_DIV_TIMER_16BIT,
314 #elif defined(CONFIG_MN10300_TTYSM2_TIMER9)
315 .tm_name = "ttySM2/Timer9",
320 .div_timer = MNSCx_DIV_TIMER_16BIT,
321 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
322 .tm_name = "ttySM2/Timer1",
324 ._tmxbr = (volatile u16 *)&TM1BR,
327 .div_timer = MNSCx_DIV_TIMER_8BIT,
328 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
329 .tm_name = "ttySM2/Timer3",
331 ._tmxbr = (volatile u16 *)&TM3BR,
334 .div_timer = MNSCx_DIV_TIMER_8BIT,
336 #error "Unknown config for ttySM2"
340 .rx_icr = &GxICR(SC2RXIRQ),
341 .tx_icr = &GxICR(SC2TXIRQ),
342 .clock_src = MNSCx_CLOCK_SRC_IOCLK,
343 #ifdef CONFIG_MN10300_TTYSM2_CTS
344 .options = MNSCx_OPT_CTS,
348 #ifdef CONFIG_GDBSTUB_ON_TTYSM2
352 #endif /* CONFIG_MN10300_TTYSM2 */
356 * list of available serial ports
358 struct mn10300_serial_port *mn10300_serial_ports[NR_UARTS + 1] = {
359 #ifdef CONFIG_MN10300_TTYSM0
360 [0] = &mn10300_serial_port_sif0,
362 #ifdef CONFIG_MN10300_TTYSM1
363 [1] = &mn10300_serial_port_sif1,
365 #ifdef CONFIG_MN10300_TTYSM2
366 [2] = &mn10300_serial_port_sif2,
373 * we abuse the serial ports' baud timers' interrupt lines to get the ability
374 * to deliver interrupts to userspace as we use the ports' interrupt lines to
375 * do virtual DMA on account of the ports having no hardware FIFOs
377 * we can generate an interrupt manually in the assembly stubs by writing to
378 * the enable and detect bits in the interrupt control register, so all we need
379 * to do here is disable the interrupt line
381 * note that we can't just leave the line enabled as the baud rate timer *also*
382 * generates interrupts
384 static void mn10300_serial_mask_ack(unsigned int irq)
389 flags = arch_local_cli_save();
390 GxICR(irq) = GxICR_LEVEL_6;
391 tmp = GxICR(irq); /* flush write buffer */
392 arch_local_irq_restore(flags);
395 static void mn10300_serial_chip_mask_ack(struct irq_data *d)
397 mn10300_serial_mask_ack(d->irq);
400 static void mn10300_serial_nop(struct irq_data *d)
404 static struct irq_chip mn10300_serial_pic = {
406 .irq_ack = mn10300_serial_chip_mask_ack,
407 .irq_mask = mn10300_serial_chip_mask_ack,
408 .irq_mask_ack = mn10300_serial_chip_mask_ack,
409 .irq_unmask = mn10300_serial_nop,
414 * serial virtual DMA interrupt jump table
416 struct mn10300_serial_int mn10300_serial_int_tbl[NR_IRQS];
418 static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port *port)
423 flags = arch_local_cli_save();
424 *port->tx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
426 arch_local_irq_restore(flags);
429 static void mn10300_serial_en_tx_intr(struct mn10300_serial_port *port)
434 flags = arch_local_cli_save();
436 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL) | GxICR_ENABLE;
438 arch_local_irq_restore(flags);
441 static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port *port)
446 flags = arch_local_cli_save();
447 *port->rx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
449 arch_local_irq_restore(flags);
453 * multi-bit equivalent of test_and_clear_bit()
455 static int mask_test_and_clear(volatile u8 *ptr, u8 mask)
458 asm volatile(" bclr %1,(%2) \n"
460 : "=d"(epsw) : "d"(mask), "a"(ptr)
462 return !(epsw & EPSW_FLAG_Z);
466 * receive chars from the ring buffer for this serial port
467 * - must do break detection here (not done in the UART)
469 static void mn10300_serial_receive_interrupt(struct mn10300_serial_port *port)
471 struct uart_icount *icount = &port->uart.icount;
472 struct tty_struct *tty = port->uart.state->port.tty;
475 u8 st, ch, push, status, overrun;
477 _enter("%s", port->name);
481 count = CIRC_CNT(port->rx_inp, port->rx_outp, MNSC_BUFFER_SIZE);
482 count = tty_buffer_request_room(tty, count);
484 if (!tty->low_latency)
485 tty_flip_buffer_push(tty);
490 /* pull chars out of the hat */
492 if (ix == port->rx_inp) {
493 if (push && !tty->low_latency)
494 tty_flip_buffer_push(tty);
498 ch = port->rx_buffer[ix++];
499 st = port->rx_buffer[ix++];
501 port->rx_outp = ix & (MNSC_BUFFER_SIZE - 1);
502 port->uart.icount.rx++;
504 st &= SC01STR_FEF | SC01STR_PEF | SC01STR_OEF;
508 /* the UART doesn't detect BREAK, so we have to do that ourselves
509 * - it starts as a framing error on a NUL character
510 * - then we count another two NUL characters before issuing TTY_BREAK
511 * - then we end on a normal char or one that has all the bottom bits
512 * zero and the top bits set
514 switch (port->rx_brk) {
516 /* not breaking at the moment */
520 if (st & SC01STR_FEF && ch == 0) {
527 if (st & SC01STR_FEF && ch == 0) {
529 _proto("Rx Break Detected");
531 if (uart_handle_break(&port->uart))
533 status |= 1 << TTY_BREAK;
539 if (st & (SC01STR_FEF | SC01STR_PEF | SC01STR_OEF))
540 goto try_again; /* still breaking */
542 port->rx_brk = 0; /* end of the break */
554 /* discard char at probable break end */
561 /* handle framing error */
562 if (st & SC01STR_FEF) {
564 /* framing error with NUL char is probably a BREAK */
569 _proto("Rx Framing Error");
571 status |= 1 << TTY_FRAME;
574 /* handle parity error */
575 if (st & SC01STR_PEF) {
576 _proto("Rx Parity Error");
581 /* handle normal char */
583 if (uart_handle_sysrq_char(&port->uart, ch))
585 status = (1 << TTY_NORMAL);
588 /* handle overrun error */
589 if (st & SC01STR_OEF) {
593 _proto("Rx Overrun Error");
599 status &= port->uart.read_status_mask;
601 if (!overrun && !(status & port->uart.ignore_status_mask)) {
604 if (status & (1 << TTY_BREAK))
606 else if (status & (1 << TTY_PARITY))
608 else if (status & (1 << TTY_FRAME))
613 tty_insert_flip_char(tty, ch, flag);
616 /* overrun is special, since it's reported immediately, and doesn't
617 * affect the current character
620 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
624 if (!tty->low_latency)
625 tty_flip_buffer_push(tty);
639 * handle an interrupt from the serial transmission "virtual DMA" driver
640 * - note: the interrupt routine will disable its own interrupts when the Tx
643 static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port *port)
645 _enter("%s", port->name);
647 if (!port->uart.state || !port->uart.state->port.tty) {
648 mn10300_serial_dis_tx_intr(port);
652 if (uart_tx_stopped(&port->uart) ||
653 uart_circ_empty(&port->uart.state->xmit))
654 mn10300_serial_dis_tx_intr(port);
656 if (uart_circ_chars_pending(&port->uart.state->xmit) < WAKEUP_CHARS)
657 uart_write_wakeup(&port->uart);
661 * deal with a change in the status of the CTS line
663 static void mn10300_serial_cts_changed(struct mn10300_serial_port *port, u8 st)
668 port->uart.icount.cts++;
670 /* flip the CTS state selector flag to interrupt when it changes
672 ctr = *port->_control;
674 *port->_control = ctr;
676 uart_handle_cts_change(&port->uart, st & SC2STR_CTS);
677 wake_up_interruptible(&port->uart.state->port.delta_msr_wait);
681 * handle a virtual interrupt generated by the lower level "virtual DMA"
682 * routines (irq is the baud timer interrupt)
684 static irqreturn_t mn10300_serial_interrupt(int irq, void *dev_id)
686 struct mn10300_serial_port *port = dev_id;
689 spin_lock(&port->uart.lock);
691 if (port->intr_flags) {
692 _debug("INT %s: %x", port->name, port->intr_flags);
694 if (mask_test_and_clear(&port->intr_flags, MNSCx_RX_AVAIL))
695 mn10300_serial_receive_interrupt(port);
697 if (mask_test_and_clear(&port->intr_flags,
698 MNSCx_TX_SPACE | MNSCx_TX_EMPTY))
699 mn10300_serial_transmit_interrupt(port);
702 /* the only modem control line amongst the whole lot is CTS on
704 if (port->type == PORT_MN10300_CTS) {
706 if ((port->tx_cts ^ st) & SC2STR_CTS)
707 mn10300_serial_cts_changed(port, st);
710 spin_unlock(&port->uart.lock);
716 * return indication of whether the hardware transmit buffer is empty
718 static unsigned int mn10300_serial_tx_empty(struct uart_port *_port)
720 struct mn10300_serial_port *port =
721 container_of(_port, struct mn10300_serial_port, uart);
723 _enter("%s", port->name);
725 return (*port->_status & (SC01STR_TXF | SC01STR_TBF)) ?
730 * set the modem control lines (we don't have any)
732 static void mn10300_serial_set_mctrl(struct uart_port *_port,
735 struct mn10300_serial_port *port __attribute__ ((unused)) =
736 container_of(_port, struct mn10300_serial_port, uart);
738 _enter("%s,%x", port->name, mctrl);
742 * get the modem control line statuses
744 static unsigned int mn10300_serial_get_mctrl(struct uart_port *_port)
746 struct mn10300_serial_port *port =
747 container_of(_port, struct mn10300_serial_port, uart);
749 _enter("%s", port->name);
751 if (port->type == PORT_MN10300_CTS && !(*port->_status & SC2STR_CTS))
752 return TIOCM_CAR | TIOCM_DSR;
754 return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR;
758 * stop transmitting characters
760 static void mn10300_serial_stop_tx(struct uart_port *_port)
762 struct mn10300_serial_port *port =
763 container_of(_port, struct mn10300_serial_port, uart);
765 _enter("%s", port->name);
767 /* disable the virtual DMA */
768 mn10300_serial_dis_tx_intr(port);
772 * start transmitting characters
773 * - jump-start transmission if it has stalled
774 * - enable the serial Tx interrupt (used by the virtual DMA controller)
775 * - force an interrupt to happen if necessary
777 static void mn10300_serial_start_tx(struct uart_port *_port)
779 struct mn10300_serial_port *port =
780 container_of(_port, struct mn10300_serial_port, uart);
786 CIRC_CNT(&port->uart.state->xmit.head,
787 &port->uart.state->xmit.tail,
790 /* kick the virtual DMA controller */
795 if (*port->_status & SC01STR_TBF)
796 x &= ~(GxICR_REQUEST | GxICR_DETECT);
798 x |= GxICR_REQUEST | GxICR_DETECT;
800 _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
801 *port->_control, *port->_intr, *port->_status,
803 (port->div_timer == MNSCx_DIV_TIMER_8BIT) ?
804 *(volatile u8 *)port->_tmxbr : *port->_tmxbr,
813 * transmit a high-priority XON/XOFF character
815 static void mn10300_serial_send_xchar(struct uart_port *_port, char ch)
817 struct mn10300_serial_port *port =
818 container_of(_port, struct mn10300_serial_port, uart);
820 _enter("%s,%02x", port->name, ch);
822 if (likely(port->gdbstub)) {
825 mn10300_serial_en_tx_intr(port);
830 * stop receiving characters
831 * - called whilst the port is being closed
833 static void mn10300_serial_stop_rx(struct uart_port *_port)
835 struct mn10300_serial_port *port =
836 container_of(_port, struct mn10300_serial_port, uart);
840 _enter("%s", port->name);
842 ctr = *port->_control;
844 *port->_control = ctr;
846 mn10300_serial_dis_rx_intr(port);
850 * enable modem status interrupts
852 static void mn10300_serial_enable_ms(struct uart_port *_port)
854 struct mn10300_serial_port *port =
855 container_of(_port, struct mn10300_serial_port, uart);
859 _enter("%s", port->name);
861 if (port->type == PORT_MN10300_CTS) {
862 /* want to interrupt when CTS goes low if CTS is now high and
865 port->tx_cts = *port->_status;
867 cts = (port->tx_cts & SC2STR_CTS) ?
868 SC2CTR_TWE : SC2CTR_TWE | SC2CTR_TWS;
870 ctr = *port->_control;
873 *port->_control = ctr;
875 mn10300_serial_en_tx_intr(port);
880 * transmit or cease transmitting a break signal
882 static void mn10300_serial_break_ctl(struct uart_port *_port, int ctl)
884 struct mn10300_serial_port *port =
885 container_of(_port, struct mn10300_serial_port, uart);
887 _enter("%s,%d", port->name, ctl);
890 /* tell the virtual DMA handler to assert BREAK */
892 mn10300_serial_en_tx_intr(port);
895 *port->_control &= ~SC01CTR_BKE;
896 mn10300_serial_en_tx_intr(port);
901 * grab the interrupts and enable the port for reception
903 static int mn10300_serial_startup(struct uart_port *_port)
905 struct mn10300_serial_port *port =
906 container_of(_port, struct mn10300_serial_port, uart);
907 struct mn10300_serial_int *pint;
909 _enter("%s{%d}", port->name, port->gdbstub);
911 if (unlikely(port->gdbstub))
914 /* allocate an Rx buffer for the virtual DMA handler */
915 port->rx_buffer = kmalloc(MNSC_BUFFER_SIZE, GFP_KERNEL);
916 if (!port->rx_buffer)
919 port->rx_inp = port->rx_outp = 0;
921 /* finally, enable the device */
922 *port->_intr = SC01ICR_TI;
923 *port->_control |= SC01CTR_TXE | SC01CTR_RXE;
925 pint = &mn10300_serial_int_tbl[port->rx_irq];
927 pint->vdma = mn10300_serial_vdma_rx_handler;
928 pint = &mn10300_serial_int_tbl[port->tx_irq];
930 pint->vdma = mn10300_serial_vdma_tx_handler;
932 set_intr_level(port->rx_irq,
933 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL));
934 set_intr_level(port->tx_irq,
935 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL));
936 set_irq_chip(port->tm_irq, &mn10300_serial_pic);
938 if (request_irq(port->rx_irq, mn10300_serial_interrupt,
939 IRQF_DISABLED, port->rx_name, port) < 0)
942 if (request_irq(port->tx_irq, mn10300_serial_interrupt,
943 IRQF_DISABLED, port->tx_name, port) < 0)
946 if (request_irq(port->tm_irq, mn10300_serial_interrupt,
947 IRQF_DISABLED, port->tm_name, port) < 0)
949 mn10300_serial_mask_ack(port->tm_irq);
954 free_irq(port->tx_irq, port);
956 free_irq(port->rx_irq, port);
958 kfree(port->rx_buffer);
959 port->rx_buffer = NULL;
964 * shutdown the port and release interrupts
966 static void mn10300_serial_shutdown(struct uart_port *_port)
969 struct mn10300_serial_port *port =
970 container_of(_port, struct mn10300_serial_port, uart);
972 _enter("%s", port->name);
974 /* disable the serial port and its baud rate timer */
976 *port->_control &= ~(SC01CTR_TXE | SC01CTR_RXE | SC01CTR_BKE);
979 if (port->rx_buffer) {
980 void *buf = port->rx_buffer;
981 port->rx_buffer = NULL;
985 /* disable all intrs */
986 free_irq(port->tm_irq, port);
987 free_irq(port->rx_irq, port);
988 free_irq(port->tx_irq, port);
991 *port->rx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
993 *port->tx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
999 * this routine is called to set the UART divisor registers to match the
1000 * specified baud rate for a serial port.
1002 static void mn10300_serial_change_speed(struct mn10300_serial_port *port,
1003 struct ktermios *new,
1004 struct ktermios *old)
1006 unsigned long flags;
1007 unsigned long ioclk = port->ioclk;
1009 int baud, bits, xdiv, tmp;
1012 u8 div_timer = port->div_timer;
1014 _enter("%s{%lu}", port->name, ioclk);
1016 /* byte size and parity */
1017 cflag = new->c_cflag;
1018 switch (cflag & CSIZE) {
1019 case CS7: scxctr = SC01CTR_CLN_7BIT; bits = 9; break;
1020 case CS8: scxctr = SC01CTR_CLN_8BIT; bits = 10; break;
1021 default: scxctr = SC01CTR_CLN_8BIT; bits = 10; break;
1024 if (cflag & CSTOPB) {
1025 scxctr |= SC01CTR_STB_2BIT;
1029 if (cflag & PARENB) {
1032 scxctr |= SC01CTR_PB_ODD;
1034 else if (cflag & CMSPAR)
1035 scxctr |= SC01CTR_PB_FIXED0;
1038 scxctr |= SC01CTR_PB_EVEN;
1041 /* Determine divisor based on baud rate */
1044 switch (port->uart.line) {
1045 #ifdef CONFIG_MN10300_TTYSM0
1046 case 0: /* ttySM0 */
1047 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
1048 scxctr |= SC0CTR_CK_TM8UFLOW_8;
1049 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
1050 scxctr |= SC0CTR_CK_TM0UFLOW_8;
1051 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
1052 scxctr |= SC0CTR_CK_TM2UFLOW_8;
1054 #error "Unknown config for ttySM0"
1057 #endif /* CONFIG_MN10300_TTYSM0 */
1059 #ifdef CONFIG_MN10300_TTYSM1
1060 case 1: /* ttySM1 */
1061 #if defined(CONFIG_AM33_2) || defined(CONFIG_AM33_3)
1062 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
1063 scxctr |= SC1CTR_CK_TM9UFLOW_8;
1064 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
1065 scxctr |= SC1CTR_CK_TM3UFLOW_8;
1067 #error "Unknown config for ttySM1"
1069 #else /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1070 #if defined(CONFIG_MN10300_TTYSM1_TIMER12)
1071 scxctr |= SC1CTR_CK_TM12UFLOW_8;
1073 #error "Unknown config for ttySM1"
1075 #endif /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1077 #endif /* CONFIG_MN10300_TTYSM1 */
1079 #ifdef CONFIG_MN10300_TTYSM2
1080 case 2: /* ttySM2 */
1081 #if defined(CONFIG_AM33_2)
1082 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
1083 scxctr |= SC2CTR_CK_TM10UFLOW;
1085 #error "Unknown config for ttySM2"
1087 #else /* CONFIG_AM33_2 */
1088 #if defined(CONFIG_MN10300_TTYSM2_TIMER9)
1089 scxctr |= SC2CTR_CK_TM9UFLOW_8;
1090 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
1091 scxctr |= SC2CTR_CK_TM1UFLOW_8;
1092 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
1093 scxctr |= SC2CTR_CK_TM3UFLOW_8;
1095 #error "Unknown config for ttySM2"
1097 #endif /* CONFIG_AM33_2 */
1099 #endif /* CONFIG_MN10300_TTYSM2 */
1106 baud = uart_get_baud_rate(&port->uart, new, old, 0,
1109 _debug("ALT %d [baud %d]", battempt, baud);
1112 baud = 9600; /* B0 transition handled in rs_set_termios */
1115 baud = 269; /* 134 is really 134.5 */
1119 if (baud == 38400 &&
1120 (port->uart.flags & UPF_SPD_MASK) == UPF_SPD_CUST
1122 _debug("CUSTOM %u", port->uart.custom_divisor);
1124 if (div_timer == MNSCx_DIV_TIMER_16BIT) {
1125 if (port->uart.custom_divisor <= 65535) {
1126 tmxmd = TM8MD_SRC_IOCLK;
1127 tmxbr = port->uart.custom_divisor;
1128 port->uart.uartclk = ioclk;
1131 if (port->uart.custom_divisor / 8 <= 65535) {
1132 tmxmd = TM8MD_SRC_IOCLK_8;
1133 tmxbr = port->uart.custom_divisor / 8;
1134 port->uart.custom_divisor = tmxbr * 8;
1135 port->uart.uartclk = ioclk / 8;
1138 if (port->uart.custom_divisor / 32 <= 65535) {
1139 tmxmd = TM8MD_SRC_IOCLK_32;
1140 tmxbr = port->uart.custom_divisor / 32;
1141 port->uart.custom_divisor = tmxbr * 32;
1142 port->uart.uartclk = ioclk / 32;
1146 } else if (div_timer == MNSCx_DIV_TIMER_8BIT) {
1147 if (port->uart.custom_divisor <= 255) {
1148 tmxmd = TM2MD_SRC_IOCLK;
1149 tmxbr = port->uart.custom_divisor;
1150 port->uart.uartclk = ioclk;
1153 if (port->uart.custom_divisor / 8 <= 255) {
1154 tmxmd = TM2MD_SRC_IOCLK_8;
1155 tmxbr = port->uart.custom_divisor / 8;
1156 port->uart.custom_divisor = tmxbr * 8;
1157 port->uart.uartclk = ioclk / 8;
1160 if (port->uart.custom_divisor / 32 <= 255) {
1161 tmxmd = TM2MD_SRC_IOCLK_32;
1162 tmxbr = port->uart.custom_divisor / 32;
1163 port->uart.custom_divisor = tmxbr * 32;
1164 port->uart.uartclk = ioclk / 32;
1170 switch (div_timer) {
1171 case MNSCx_DIV_TIMER_16BIT:
1172 port->uart.uartclk = ioclk;
1173 tmxmd = TM8MD_SRC_IOCLK;
1174 tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
1175 if (tmp > 0 && tmp <= 65535)
1178 port->uart.uartclk = ioclk / 8;
1179 tmxmd = TM8MD_SRC_IOCLK_8;
1180 tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
1181 if (tmp > 0 && tmp <= 65535)
1184 port->uart.uartclk = ioclk / 32;
1185 tmxmd = TM8MD_SRC_IOCLK_32;
1186 tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
1187 if (tmp > 0 && tmp <= 65535)
1191 case MNSCx_DIV_TIMER_8BIT:
1192 port->uart.uartclk = ioclk;
1193 tmxmd = TM2MD_SRC_IOCLK;
1194 tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
1195 if (tmp > 0 && tmp <= 255)
1198 port->uart.uartclk = ioclk / 8;
1199 tmxmd = TM2MD_SRC_IOCLK_8;
1200 tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
1201 if (tmp > 0 && tmp <= 255)
1204 port->uart.uartclk = ioclk / 32;
1205 tmxmd = TM2MD_SRC_IOCLK_32;
1206 tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
1207 if (tmp > 0 && tmp <= 255)
1216 /* refuse to change to a baud rate we can't support */
1217 _debug("CAN'T SUPPORT");
1222 new->c_cflag &= ~CBAUD;
1223 new->c_cflag |= (old->c_cflag & CBAUD);
1225 goto try_alternative;
1229 /* as a last resort, if the quotient is zero, default to 9600
1231 new->c_cflag &= ~CBAUD;
1232 new->c_cflag |= B9600;
1234 goto try_alternative;
1237 /* hmmm... can't seem to support 9600 either
1238 * - we could try iterating through the speeds we know about to
1241 new->c_cflag &= ~CBAUD;
1244 if (div_timer == MNSCx_DIV_TIMER_16BIT)
1245 tmxmd = TM8MD_SRC_IOCLK_32;
1246 else if (div_timer == MNSCx_DIV_TIMER_8BIT)
1247 tmxmd = TM2MD_SRC_IOCLK_32;
1250 port->uart.uartclk = ioclk / 32;
1255 _debug("UARTCLK: %u / %hu", port->uart.uartclk, tmxbr);
1257 /* make the changes */
1258 spin_lock_irqsave(&port->uart.lock, flags);
1260 uart_update_timeout(&port->uart, new->c_cflag, baud);
1262 /* set the timer to produce the required baud rate */
1263 switch (div_timer) {
1264 case MNSCx_DIV_TIMER_16BIT:
1266 *port->_tmxbr = tmxbr;
1267 *port->_tmxmd = TM8MD_INIT_COUNTER;
1268 *port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
1271 case MNSCx_DIV_TIMER_8BIT:
1273 *(volatile u8 *) port->_tmxbr = (u8) tmxbr;
1274 *port->_tmxmd = TM2MD_INIT_COUNTER;
1275 *port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
1279 /* CTS flow control flag and modem status interrupts */
1280 scxctr &= ~(SC2CTR_TWE | SC2CTR_TWS);
1282 if (port->type == PORT_MN10300_CTS && cflag & CRTSCTS) {
1283 /* want to interrupt when CTS goes low if CTS is now
1284 * high and vice versa
1286 port->tx_cts = *port->_status;
1288 if (port->tx_cts & SC2STR_CTS)
1289 scxctr |= SC2CTR_TWE;
1291 scxctr |= SC2CTR_TWE | SC2CTR_TWS;
1294 /* set up parity check flag */
1295 port->uart.read_status_mask = (1 << TTY_NORMAL) | (1 << TTY_OVERRUN);
1296 if (new->c_iflag & INPCK)
1297 port->uart.read_status_mask |=
1298 (1 << TTY_PARITY) | (1 << TTY_FRAME);
1299 if (new->c_iflag & (BRKINT | PARMRK))
1300 port->uart.read_status_mask |= (1 << TTY_BREAK);
1302 /* characters to ignore */
1303 port->uart.ignore_status_mask = 0;
1304 if (new->c_iflag & IGNPAR)
1305 port->uart.ignore_status_mask |=
1306 (1 << TTY_PARITY) | (1 << TTY_FRAME);
1307 if (new->c_iflag & IGNBRK) {
1308 port->uart.ignore_status_mask |= (1 << TTY_BREAK);
1310 * If we're ignoring parity and break indicators,
1311 * ignore overruns to (for real raw support).
1313 if (new->c_iflag & IGNPAR)
1314 port->uart.ignore_status_mask |= (1 << TTY_OVERRUN);
1317 /* Ignore all characters if CREAD is not set */
1318 if ((new->c_cflag & CREAD) == 0)
1319 port->uart.ignore_status_mask |= (1 << TTY_NORMAL);
1321 scxctr |= *port->_control & (SC01CTR_TXE | SC01CTR_RXE | SC01CTR_BKE);
1322 *port->_control = scxctr;
1324 spin_unlock_irqrestore(&port->uart.lock, flags);
1328 * set the terminal I/O parameters
1330 static void mn10300_serial_set_termios(struct uart_port *_port,
1331 struct ktermios *new,
1332 struct ktermios *old)
1334 struct mn10300_serial_port *port =
1335 container_of(_port, struct mn10300_serial_port, uart);
1337 _enter("%s,%p,%p", port->name, new, old);
1339 mn10300_serial_change_speed(port, new, old);
1341 /* handle turning off CRTSCTS */
1342 if (!(new->c_cflag & CRTSCTS)) {
1343 u16 ctr = *port->_control;
1345 *port->_control = ctr;
1348 /* change Transfer bit-order (LSB/MSB) */
1349 if (new->c_cflag & CODMSB)
1350 *port->_control |= SC01CTR_OD_MSBFIRST; /* MSB MODE */
1352 *port->_control &= ~SC01CTR_OD_MSBFIRST; /* LSB MODE */
1356 * return description of port type
1358 static const char *mn10300_serial_type(struct uart_port *_port)
1360 struct mn10300_serial_port *port =
1361 container_of(_port, struct mn10300_serial_port, uart);
1363 if (port->uart.type == PORT_MN10300_CTS)
1364 return "MN10300 SIF_CTS";
1366 return "MN10300 SIF";
1370 * release I/O and memory regions in use by port
1372 static void mn10300_serial_release_port(struct uart_port *_port)
1374 struct mn10300_serial_port *port =
1375 container_of(_port, struct mn10300_serial_port, uart);
1377 _enter("%s", port->name);
1379 release_mem_region((unsigned long) port->_iobase, 16);
1383 * request I/O and memory regions for port
1385 static int mn10300_serial_request_port(struct uart_port *_port)
1387 struct mn10300_serial_port *port =
1388 container_of(_port, struct mn10300_serial_port, uart);
1390 _enter("%s", port->name);
1392 request_mem_region((unsigned long) port->_iobase, 16, port->name);
1397 * configure the type and reserve the ports
1399 static void mn10300_serial_config_port(struct uart_port *_port, int type)
1401 struct mn10300_serial_port *port =
1402 container_of(_port, struct mn10300_serial_port, uart);
1404 _enter("%s", port->name);
1406 port->uart.type = PORT_MN10300;
1408 if (port->options & MNSCx_OPT_CTS)
1409 port->uart.type = PORT_MN10300_CTS;
1411 mn10300_serial_request_port(_port);
1415 * verify serial parameters are suitable for this port type
1417 static int mn10300_serial_verify_port(struct uart_port *_port,
1418 struct serial_struct *ss)
1420 struct mn10300_serial_port *port =
1421 container_of(_port, struct mn10300_serial_port, uart);
1422 void *mapbase = (void *) (unsigned long) port->uart.mapbase;
1424 _enter("%s", port->name);
1426 /* these things may not be changed */
1427 if (ss->irq != port->uart.irq ||
1428 ss->port != port->uart.iobase ||
1429 ss->io_type != port->uart.iotype ||
1430 ss->iomem_base != mapbase ||
1431 ss->iomem_reg_shift != port->uart.regshift ||
1432 ss->hub6 != port->uart.hub6 ||
1433 ss->xmit_fifo_size != port->uart.fifosize)
1436 /* type may be changed on a port that supports CTS */
1437 if (ss->type != port->uart.type) {
1438 if (!(port->options & MNSCx_OPT_CTS))
1441 if (ss->type != PORT_MN10300 &&
1442 ss->type != PORT_MN10300_CTS)
1450 * initialise the MN10300 on-chip UARTs
1452 static int __init mn10300_serial_init(void)
1454 struct mn10300_serial_port *port;
1457 printk(KERN_INFO "%s version %s (%s)\n",
1458 serial_name, serial_version, serial_revdate);
1460 #if defined(CONFIG_MN10300_TTYSM2) && defined(CONFIG_AM33_2)
1463 SC2TIM = 8; /* make the baud base of timer 2 IOCLK/8 */
1468 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL),
1469 mn10300_serial_vdma_interrupt);
1471 ret = uart_register_driver(&mn10300_serial_driver);
1473 for (i = 0 ; i < NR_PORTS ; i++) {
1474 port = mn10300_serial_ports[i];
1475 if (!port || port->gdbstub)
1478 switch (port->clock_src) {
1479 case MNSCx_CLOCK_SRC_IOCLK:
1480 port->ioclk = MN10300_IOCLK;
1483 #ifdef MN10300_IOBCLK
1484 case MNSCx_CLOCK_SRC_IOBCLK:
1485 port->ioclk = MN10300_IOBCLK;
1492 ret = uart_add_one_port(&mn10300_serial_driver,
1496 _debug("ERROR %d", -ret);
1502 uart_unregister_driver(&mn10300_serial_driver);
1508 __initcall(mn10300_serial_init);
1511 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
1514 * print a string to the serial port without disturbing the real user of the
1516 * - the console must be locked by the caller
1518 static void mn10300_serial_console_write(struct console *co,
1519 const char *s, unsigned count)
1521 struct mn10300_serial_port *port;
1523 u16 scxctr, txicr, tmp;
1526 port = mn10300_serial_ports[co->index];
1528 /* firstly hijack the serial port from the "virtual DMA" controller */
1530 txicr = *port->tx_icr;
1531 *port->tx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
1532 tmp = *port->tx_icr;
1535 /* the transmitter may be disabled */
1536 scxctr = *port->_control;
1537 if (!(scxctr & SC01CTR_TXE)) {
1538 /* restart the UART clock */
1539 tmxmd = *port->_tmxmd;
1541 switch (port->div_timer) {
1542 case MNSCx_DIV_TIMER_16BIT:
1544 *port->_tmxmd = TM8MD_INIT_COUNTER;
1545 *port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
1548 case MNSCx_DIV_TIMER_8BIT:
1550 *port->_tmxmd = TM2MD_INIT_COUNTER;
1551 *port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
1555 /* enable the transmitter */
1556 *port->_control = (scxctr & ~SC01CTR_BKE) | SC01CTR_TXE;
1558 } else if (scxctr & SC01CTR_BKE) {
1559 /* stop transmitting BREAK */
1560 *port->_control = (scxctr & ~SC01CTR_BKE);
1563 /* send the chars into the serial port (with LF -> LFCR conversion) */
1564 for (i = 0; i < count; i++) {
1567 while (*port->_status & SC01STR_TBF)
1569 *(u8 *) port->_txb = ch;
1572 while (*port->_status & SC01STR_TBF)
1574 *(u8 *) port->_txb = 0xd;
1578 /* can't let the transmitter be turned off if it's actually
1580 while (*port->_status & (SC01STR_TXF | SC01STR_TBF))
1583 /* disable the transmitter if we re-enabled it */
1584 if (!(scxctr & SC01CTR_TXE))
1585 *port->_control = scxctr;
1588 *port->tx_icr = txicr;
1589 tmp = *port->tx_icr;
1594 * set up a serial port as a console
1595 * - construct a cflag setting for the first rs_open()
1596 * - initialize the serial port
1597 * - return non-zero if we didn't find a serial port.
1599 static int __init mn10300_serial_console_setup(struct console *co,
1602 struct mn10300_serial_port *port;
1603 int i, parity = 'n', baud = 9600, bits = 8, flow = 0;
1605 for (i = 0 ; i < NR_PORTS ; i++) {
1606 port = mn10300_serial_ports[i];
1607 if (port && !port->gdbstub && port->uart.line == co->index)
1614 switch (port->clock_src) {
1615 case MNSCx_CLOCK_SRC_IOCLK:
1616 port->ioclk = MN10300_IOCLK;
1619 #ifdef MN10300_IOBCLK
1620 case MNSCx_CLOCK_SRC_IOBCLK:
1621 port->ioclk = MN10300_IOBCLK;
1629 uart_parse_options(options, &baud, &parity, &bits, &flow);
1631 return uart_set_options(&port->uart, co, baud, parity, bits, flow);
1637 static int __init mn10300_serial_console_init(void)
1639 register_console(&mn10300_serial_console);
1643 console_initcall(mn10300_serial_console_init);
1646 #ifdef CONFIG_CONSOLE_POLL
1648 * Polled character reception for the kernel debugger
1650 static int mn10300_serial_poll_get_char(struct uart_port *_port)
1652 struct mn10300_serial_port *port =
1653 container_of(_port, struct mn10300_serial_port, uart);
1657 _enter("%s", port->name);
1660 /* pull chars out of the hat */
1662 if (ix == port->rx_inp)
1663 return NO_POLL_CHAR;
1665 ch = port->rx_buffer[ix++];
1666 st = port->rx_buffer[ix++];
1668 port->rx_outp = ix & (MNSC_BUFFER_SIZE - 1);
1670 } while (st & (SC01STR_FEF | SC01STR_PEF | SC01STR_OEF));
1677 * Polled character transmission for the kernel debugger
1679 static void mn10300_serial_poll_put_char(struct uart_port *_port,
1682 struct mn10300_serial_port *port =
1683 container_of(_port, struct mn10300_serial_port, uart);
1686 /* wait for the transmitter to finish anything it might be doing (and
1687 * this includes the virtual DMA handler, so it might take a while) */
1688 while (*port->_status & (SC01STR_TBF | SC01STR_TXF))
1691 /* disable the Tx ready interrupt */
1692 intr = *port->_intr;
1693 *port->_intr = intr & ~SC01ICR_TI;
1697 *(u8 *) port->_txb = 0x0d;
1698 while (*port->_status & SC01STR_TBF)
1702 *(u8 *) port->_txb = ch;
1703 while (*port->_status & SC01STR_TBF)
1706 /* restore the Tx interrupt flag */
1707 *port->_intr = intr;
1711 #endif /* CONFIG_CONSOLE_POLL */