1 /* MN10300 On-chip serial port UART driver
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
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>
41 #include <asm/bitops.h>
42 #include <asm/serial-regs.h>
43 #include <unit/timex.h>
44 #include "mn10300-serial.h"
48 #define GxICR(X) CROSS_GxICR(X, 0)
49 #endif /* CONFIG_SMP */
51 #define kenter(FMT, ...) \
52 printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
53 #define _enter(FMT, ...) \
54 no_printk(KERN_DEBUG "-->%s(" FMT ")\n", __func__, ##__VA_ARGS__)
55 #define kdebug(FMT, ...) \
56 printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
57 #define _debug(FMT, ...) \
58 no_printk(KERN_DEBUG "--- " FMT "\n", ##__VA_ARGS__)
59 #define kproto(FMT, ...) \
60 printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
61 #define _proto(FMT, ...) \
62 no_printk(KERN_DEBUG "### MNSERIAL " FMT " ###\n", ##__VA_ARGS__)
65 /* c_cflag bit meaning */
66 #define CODMSB 004000000000 /* change Transfer bit-order */
71 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
72 static void mn10300_serial_console_write(struct console *co,
73 const char *s, unsigned count);
74 static int __init mn10300_serial_console_setup(struct console *co,
77 static struct uart_driver mn10300_serial_driver;
78 static struct console mn10300_serial_console = {
80 .write = mn10300_serial_console_write,
81 .device = uart_console_device,
82 .setup = mn10300_serial_console_setup,
83 .flags = CON_PRINTBUFFER,
85 .data = &mn10300_serial_driver,
89 static struct uart_driver mn10300_serial_driver = {
91 .driver_name = "mn10300-serial",
96 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
97 .cons = &mn10300_serial_console,
101 static unsigned int mn10300_serial_tx_empty(struct uart_port *);
102 static void mn10300_serial_set_mctrl(struct uart_port *, unsigned int mctrl);
103 static unsigned int mn10300_serial_get_mctrl(struct uart_port *);
104 static void mn10300_serial_stop_tx(struct uart_port *);
105 static void mn10300_serial_start_tx(struct uart_port *);
106 static void mn10300_serial_send_xchar(struct uart_port *, char ch);
107 static void mn10300_serial_stop_rx(struct uart_port *);
108 static void mn10300_serial_enable_ms(struct uart_port *);
109 static void mn10300_serial_break_ctl(struct uart_port *, int ctl);
110 static int mn10300_serial_startup(struct uart_port *);
111 static void mn10300_serial_shutdown(struct uart_port *);
112 static void mn10300_serial_set_termios(struct uart_port *,
113 struct ktermios *new,
114 struct ktermios *old);
115 static const char *mn10300_serial_type(struct uart_port *);
116 static void mn10300_serial_release_port(struct uart_port *);
117 static int mn10300_serial_request_port(struct uart_port *);
118 static void mn10300_serial_config_port(struct uart_port *, int);
119 static int mn10300_serial_verify_port(struct uart_port *,
120 struct serial_struct *);
121 #ifdef CONFIG_CONSOLE_POLL
122 static void mn10300_serial_poll_put_char(struct uart_port *, unsigned char);
123 static int mn10300_serial_poll_get_char(struct uart_port *);
126 static const struct uart_ops mn10300_serial_ops = {
127 .tx_empty = mn10300_serial_tx_empty,
128 .set_mctrl = mn10300_serial_set_mctrl,
129 .get_mctrl = mn10300_serial_get_mctrl,
130 .stop_tx = mn10300_serial_stop_tx,
131 .start_tx = mn10300_serial_start_tx,
132 .send_xchar = mn10300_serial_send_xchar,
133 .stop_rx = mn10300_serial_stop_rx,
134 .enable_ms = mn10300_serial_enable_ms,
135 .break_ctl = mn10300_serial_break_ctl,
136 .startup = mn10300_serial_startup,
137 .shutdown = mn10300_serial_shutdown,
138 .set_termios = mn10300_serial_set_termios,
139 .type = mn10300_serial_type,
140 .release_port = mn10300_serial_release_port,
141 .request_port = mn10300_serial_request_port,
142 .config_port = mn10300_serial_config_port,
143 .verify_port = mn10300_serial_verify_port,
144 #ifdef CONFIG_CONSOLE_POLL
145 .poll_put_char = mn10300_serial_poll_put_char,
146 .poll_get_char = mn10300_serial_poll_get_char,
150 static irqreturn_t mn10300_serial_interrupt(int irq, void *dev_id);
153 * the first on-chip serial port: ttySM0 (aka SIF0)
155 #ifdef CONFIG_MN10300_TTYSM0
156 struct mn10300_serial_port mn10300_serial_port_sif0 = {
157 .uart.ops = &mn10300_serial_ops,
158 .uart.membase = (void __iomem *) &SC0CTR,
159 .uart.mapbase = (unsigned long) &SC0CTR,
160 .uart.iotype = UPIO_MEM,
162 .uart.uartclk = 0, /* MN10300_IOCLK, */
164 .uart.flags = UPF_BOOT_AUTOCONF,
166 .uart.type = PORT_MN10300,
168 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif0.uart.lock),
172 ._status = (volatile u8 *)&SC0STR,
176 .rx_name = "ttySM0:Rx",
177 .tx_name = "ttySM0:Tx",
178 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
179 .tm_name = "ttySM0:Timer8",
184 .div_timer = MNSCx_DIV_TIMER_16BIT,
185 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
186 .tm_name = "ttySM0:Timer0",
188 ._tmxbr = (volatile u16 *)&TM0BR,
191 .div_timer = MNSCx_DIV_TIMER_8BIT,
192 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
193 .tm_name = "ttySM0:Timer2",
195 ._tmxbr = (volatile u16 *)&TM2BR,
198 .div_timer = MNSCx_DIV_TIMER_8BIT,
200 #error "Unknown config for ttySM0"
204 .rx_icr = &GxICR(SC0RXIRQ),
205 .tx_icr = &GxICR(SC0TXIRQ),
206 .clock_src = MNSCx_CLOCK_SRC_IOCLK,
208 #ifdef CONFIG_GDBSTUB_ON_TTYSM0
212 #endif /* CONFIG_MN10300_TTYSM0 */
215 * the second on-chip serial port: ttySM1 (aka SIF1)
217 #ifdef CONFIG_MN10300_TTYSM1
218 struct mn10300_serial_port mn10300_serial_port_sif1 = {
219 .uart.ops = &mn10300_serial_ops,
220 .uart.membase = (void __iomem *) &SC1CTR,
221 .uart.mapbase = (unsigned long) &SC1CTR,
222 .uart.iotype = UPIO_MEM,
224 .uart.uartclk = 0, /* MN10300_IOCLK, */
226 .uart.flags = UPF_BOOT_AUTOCONF,
228 .uart.type = PORT_MN10300,
230 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif1.uart.lock),
234 ._status = (volatile u8 *)&SC1STR,
238 .rx_name = "ttySM1:Rx",
239 .tx_name = "ttySM1:Tx",
240 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
241 .tm_name = "ttySM1:Timer9",
246 .div_timer = MNSCx_DIV_TIMER_16BIT,
247 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
248 .tm_name = "ttySM1:Timer3",
250 ._tmxbr = (volatile u16 *)&TM3BR,
253 .div_timer = MNSCx_DIV_TIMER_8BIT,
254 #elif defined(CONFIG_MN10300_TTYSM1_TIMER12)
255 .tm_name = "ttySM1/Timer12",
260 .div_timer = MNSCx_DIV_TIMER_16BIT,
262 #error "Unknown config for ttySM1"
266 .rx_icr = &GxICR(SC1RXIRQ),
267 .tx_icr = &GxICR(SC1TXIRQ),
268 .clock_src = MNSCx_CLOCK_SRC_IOCLK,
270 #ifdef CONFIG_GDBSTUB_ON_TTYSM1
274 #endif /* CONFIG_MN10300_TTYSM1 */
277 * the third on-chip serial port: ttySM2 (aka SIF2)
279 #ifdef CONFIG_MN10300_TTYSM2
280 struct mn10300_serial_port mn10300_serial_port_sif2 = {
281 .uart.ops = &mn10300_serial_ops,
282 .uart.membase = (void __iomem *) &SC2CTR,
283 .uart.mapbase = (unsigned long) &SC2CTR,
284 .uart.iotype = UPIO_MEM,
286 .uart.uartclk = 0, /* MN10300_IOCLK, */
288 .uart.flags = UPF_BOOT_AUTOCONF,
290 #ifdef CONFIG_MN10300_TTYSM2_CTS
291 .uart.type = PORT_MN10300_CTS,
293 .uart.type = PORT_MN10300,
296 __SPIN_LOCK_UNLOCKED(mn10300_serial_port_sif2.uart.lock),
300 ._status = (volatile u8 *)&SC2STR,
304 .rx_name = "ttySM2:Rx",
305 .tx_name = "ttySM2:Tx",
306 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
307 .tm_name = "ttySM2/Timer10",
312 .div_timer = MNSCx_DIV_TIMER_16BIT,
313 #elif defined(CONFIG_MN10300_TTYSM2_TIMER9)
314 .tm_name = "ttySM2/Timer9",
319 .div_timer = MNSCx_DIV_TIMER_16BIT,
320 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
321 .tm_name = "ttySM2/Timer1",
323 ._tmxbr = (volatile u16 *)&TM1BR,
326 .div_timer = MNSCx_DIV_TIMER_8BIT,
327 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
328 .tm_name = "ttySM2/Timer3",
330 ._tmxbr = (volatile u16 *)&TM3BR,
333 .div_timer = MNSCx_DIV_TIMER_8BIT,
335 #error "Unknown config for ttySM2"
339 .rx_icr = &GxICR(SC2RXIRQ),
340 .tx_icr = &GxICR(SC2TXIRQ),
341 .clock_src = MNSCx_CLOCK_SRC_IOCLK,
342 #ifdef CONFIG_MN10300_TTYSM2_CTS
343 .options = MNSCx_OPT_CTS,
347 #ifdef CONFIG_GDBSTUB_ON_TTYSM2
351 #endif /* CONFIG_MN10300_TTYSM2 */
355 * list of available serial ports
357 struct mn10300_serial_port *mn10300_serial_ports[NR_UARTS + 1] = {
358 #ifdef CONFIG_MN10300_TTYSM0
359 [0] = &mn10300_serial_port_sif0,
361 #ifdef CONFIG_MN10300_TTYSM1
362 [1] = &mn10300_serial_port_sif1,
364 #ifdef CONFIG_MN10300_TTYSM2
365 [2] = &mn10300_serial_port_sif2,
372 * we abuse the serial ports' baud timers' interrupt lines to get the ability
373 * to deliver interrupts to userspace as we use the ports' interrupt lines to
374 * do virtual DMA on account of the ports having no hardware FIFOs
376 * we can generate an interrupt manually in the assembly stubs by writing to
377 * the enable and detect bits in the interrupt control register, so all we need
378 * to do here is disable the interrupt line
380 * note that we can't just leave the line enabled as the baud rate timer *also*
381 * generates interrupts
383 static void mn10300_serial_mask_ack(unsigned int irq)
388 flags = arch_local_cli_save();
389 GxICR(irq) = GxICR_LEVEL_6;
390 tmp = GxICR(irq); /* flush write buffer */
391 arch_local_irq_restore(flags);
394 static void mn10300_serial_chip_mask_ack(struct irq_data *d)
396 mn10300_serial_mask_ack(d->irq);
399 static void mn10300_serial_nop(struct irq_data *d)
403 static struct irq_chip mn10300_serial_pic = {
405 .irq_ack = mn10300_serial_chip_mask_ack,
406 .irq_mask = mn10300_serial_chip_mask_ack,
407 .irq_mask_ack = mn10300_serial_chip_mask_ack,
408 .irq_unmask = mn10300_serial_nop,
411 static void mn10300_serial_low_mask(struct irq_data *d)
416 flags = arch_local_cli_save();
417 GxICR(d->irq) = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
418 tmp = GxICR(d->irq); /* flush write buffer */
419 arch_local_irq_restore(flags);
422 static void mn10300_serial_low_unmask(struct irq_data *d)
427 flags = arch_local_cli_save();
429 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL) | GxICR_ENABLE;
430 tmp = GxICR(d->irq); /* flush write buffer */
431 arch_local_irq_restore(flags);
434 static struct irq_chip mn10300_serial_low_pic = {
435 .name = "mnserial-low",
436 .irq_mask = mn10300_serial_low_mask,
437 .irq_unmask = mn10300_serial_low_unmask,
441 * serial virtual DMA interrupt jump table
443 struct mn10300_serial_int mn10300_serial_int_tbl[NR_IRQS];
445 static void mn10300_serial_dis_tx_intr(struct mn10300_serial_port *port)
450 /* nothing to do if irq isn't set up */
451 if (!mn10300_serial_int_tbl[port->tx_irq].port)
454 port->tx_flags |= MNSCx_TX_STOP;
458 * Here we wait for the irq to be disabled. Either it already is
459 * disabled or we wait some number of retries for the VDMA handler
460 * to disable it. The retries give the VDMA handler enough time to
461 * run to completion if it was already in progress. If the VDMA IRQ
462 * is enabled but the handler is not yet running when arrive here,
463 * the STOP flag will prevent the handler from conflicting with the
464 * driver code following this loop.
466 while ((*port->tx_icr & GxICR_ENABLE) && retries-- > 0)
470 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
475 static void mn10300_serial_en_tx_intr(struct mn10300_serial_port *port)
479 /* nothing to do if irq isn't set up */
480 if (!mn10300_serial_int_tbl[port->tx_irq].port)
483 /* stop vdma irq if not already stopped */
484 if (!(port->tx_flags & MNSCx_TX_STOP))
485 mn10300_serial_dis_tx_intr(port);
487 port->tx_flags &= ~MNSCx_TX_STOP;
491 NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL) |
492 GxICR_ENABLE | GxICR_REQUEST | GxICR_DETECT;
496 static void mn10300_serial_dis_rx_intr(struct mn10300_serial_port *port)
501 flags = arch_local_cli_save();
502 *port->rx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
504 arch_local_irq_restore(flags);
508 * multi-bit equivalent of test_and_clear_bit()
510 static int mask_test_and_clear(volatile u8 *ptr, u8 mask)
513 asm volatile(" bclr %1,(%2) \n"
515 : "=d"(epsw) : "d"(mask), "a"(ptr)
517 return !(epsw & EPSW_FLAG_Z);
521 * receive chars from the ring buffer for this serial port
522 * - must do break detection here (not done in the UART)
524 static void mn10300_serial_receive_interrupt(struct mn10300_serial_port *port)
526 struct uart_icount *icount = &port->uart.icount;
527 struct tty_port *port = &port->uart.state->port;
528 struct tty_struct *tty = port->tty;
531 u8 st, ch, push, status, overrun;
533 _enter("%s", port->name);
537 count = CIRC_CNT(port->rx_inp, port->rx_outp, MNSC_BUFFER_SIZE);
538 count = tty_buffer_request_room(port, count);
540 if (!tty->low_latency)
541 tty_flip_buffer_push(tty);
546 /* pull chars out of the hat */
547 ix = ACCESS_ONCE(port->rx_outp);
548 if (CIRC_CNT(port->rx_inp, ix, MNSC_BUFFER_SIZE) == 0) {
549 if (push && !tty->low_latency)
550 tty_flip_buffer_push(tty);
554 smp_read_barrier_depends();
555 ch = port->rx_buffer[ix++];
556 st = port->rx_buffer[ix++];
558 port->rx_outp = ix & (MNSC_BUFFER_SIZE - 1);
559 port->uart.icount.rx++;
561 st &= SC01STR_FEF | SC01STR_PEF | SC01STR_OEF;
565 /* the UART doesn't detect BREAK, so we have to do that ourselves
566 * - it starts as a framing error on a NUL character
567 * - then we count another two NUL characters before issuing TTY_BREAK
568 * - then we end on a normal char or one that has all the bottom bits
569 * zero and the top bits set
571 switch (port->rx_brk) {
573 /* not breaking at the moment */
577 if (st & SC01STR_FEF && ch == 0) {
584 if (st & SC01STR_FEF && ch == 0) {
586 _proto("Rx Break Detected");
588 if (uart_handle_break(&port->uart))
590 status |= 1 << TTY_BREAK;
596 if (st & (SC01STR_FEF | SC01STR_PEF | SC01STR_OEF))
597 goto try_again; /* still breaking */
599 port->rx_brk = 0; /* end of the break */
611 /* discard char at probable break end */
618 /* handle framing error */
619 if (st & SC01STR_FEF) {
621 /* framing error with NUL char is probably a BREAK */
626 _proto("Rx Framing Error");
628 status |= 1 << TTY_FRAME;
631 /* handle parity error */
632 if (st & SC01STR_PEF) {
633 _proto("Rx Parity Error");
638 /* handle normal char */
640 if (uart_handle_sysrq_char(&port->uart, ch))
642 status = (1 << TTY_NORMAL);
645 /* handle overrun error */
646 if (st & SC01STR_OEF) {
650 _proto("Rx Overrun Error");
656 status &= port->uart.read_status_mask;
658 if (!overrun && !(status & port->uart.ignore_status_mask)) {
661 if (status & (1 << TTY_BREAK))
663 else if (status & (1 << TTY_PARITY))
665 else if (status & (1 << TTY_FRAME))
670 tty_insert_flip_char(port, ch, flag);
673 /* overrun is special, since it's reported immediately, and doesn't
674 * affect the current character
677 tty_insert_flip_char(port, 0, TTY_OVERRUN);
681 if (!tty->low_latency)
682 tty_flip_buffer_push(tty);
696 * handle an interrupt from the serial transmission "virtual DMA" driver
697 * - note: the interrupt routine will disable its own interrupts when the Tx
700 static void mn10300_serial_transmit_interrupt(struct mn10300_serial_port *port)
702 _enter("%s", port->name);
704 if (!port->uart.state || !port->uart.state->port.tty) {
705 mn10300_serial_dis_tx_intr(port);
709 if (uart_tx_stopped(&port->uart) ||
710 uart_circ_empty(&port->uart.state->xmit))
711 mn10300_serial_dis_tx_intr(port);
713 if (uart_circ_chars_pending(&port->uart.state->xmit) < WAKEUP_CHARS)
714 uart_write_wakeup(&port->uart);
718 * deal with a change in the status of the CTS line
720 static void mn10300_serial_cts_changed(struct mn10300_serial_port *port, u8 st)
725 port->uart.icount.cts++;
727 /* flip the CTS state selector flag to interrupt when it changes
729 ctr = *port->_control;
731 *port->_control = ctr;
733 uart_handle_cts_change(&port->uart, st & SC2STR_CTS);
734 wake_up_interruptible(&port->uart.state->port.delta_msr_wait);
738 * handle a virtual interrupt generated by the lower level "virtual DMA"
739 * routines (irq is the baud timer interrupt)
741 static irqreturn_t mn10300_serial_interrupt(int irq, void *dev_id)
743 struct mn10300_serial_port *port = dev_id;
746 spin_lock(&port->uart.lock);
748 if (port->intr_flags) {
749 _debug("INT %s: %x", port->name, port->intr_flags);
751 if (mask_test_and_clear(&port->intr_flags, MNSCx_RX_AVAIL))
752 mn10300_serial_receive_interrupt(port);
754 if (mask_test_and_clear(&port->intr_flags,
755 MNSCx_TX_SPACE | MNSCx_TX_EMPTY))
756 mn10300_serial_transmit_interrupt(port);
759 /* the only modem control line amongst the whole lot is CTS on
761 if (port->type == PORT_MN10300_CTS) {
763 if ((port->tx_cts ^ st) & SC2STR_CTS)
764 mn10300_serial_cts_changed(port, st);
767 spin_unlock(&port->uart.lock);
773 * return indication of whether the hardware transmit buffer is empty
775 static unsigned int mn10300_serial_tx_empty(struct uart_port *_port)
777 struct mn10300_serial_port *port =
778 container_of(_port, struct mn10300_serial_port, uart);
780 _enter("%s", port->name);
782 return (*port->_status & (SC01STR_TXF | SC01STR_TBF)) ?
787 * set the modem control lines (we don't have any)
789 static void mn10300_serial_set_mctrl(struct uart_port *_port,
792 struct mn10300_serial_port *port __attribute__ ((unused)) =
793 container_of(_port, struct mn10300_serial_port, uart);
795 _enter("%s,%x", port->name, mctrl);
799 * get the modem control line statuses
801 static unsigned int mn10300_serial_get_mctrl(struct uart_port *_port)
803 struct mn10300_serial_port *port =
804 container_of(_port, struct mn10300_serial_port, uart);
806 _enter("%s", port->name);
808 if (port->type == PORT_MN10300_CTS && !(*port->_status & SC2STR_CTS))
809 return TIOCM_CAR | TIOCM_DSR;
811 return TIOCM_CAR | TIOCM_CTS | TIOCM_DSR;
815 * stop transmitting characters
817 static void mn10300_serial_stop_tx(struct uart_port *_port)
819 struct mn10300_serial_port *port =
820 container_of(_port, struct mn10300_serial_port, uart);
822 _enter("%s", port->name);
824 /* disable the virtual DMA */
825 mn10300_serial_dis_tx_intr(port);
829 * start transmitting characters
830 * - jump-start transmission if it has stalled
831 * - enable the serial Tx interrupt (used by the virtual DMA controller)
832 * - force an interrupt to happen if necessary
834 static void mn10300_serial_start_tx(struct uart_port *_port)
836 struct mn10300_serial_port *port =
837 container_of(_port, struct mn10300_serial_port, uart);
841 CIRC_CNT(&port->uart.state->xmit.head,
842 &port->uart.state->xmit.tail,
845 /* kick the virtual DMA controller */
846 mn10300_serial_en_tx_intr(port);
848 _debug("CTR=%04hx ICR=%02hx STR=%04x TMD=%02hx TBR=%04hx ICR=%04hx",
849 *port->_control, *port->_intr, *port->_status,
851 (port->div_timer == MNSCx_DIV_TIMER_8BIT) ?
852 *(volatile u8 *)port->_tmxbr : *port->_tmxbr,
857 * transmit a high-priority XON/XOFF character
859 static void mn10300_serial_send_xchar(struct uart_port *_port, char ch)
861 struct mn10300_serial_port *port =
862 container_of(_port, struct mn10300_serial_port, uart);
865 _enter("%s,%02x", port->name, ch);
867 if (likely(port->gdbstub)) {
870 spin_lock_irqsave(&port->uart.lock, flags);
871 mn10300_serial_en_tx_intr(port);
872 spin_unlock_irqrestore(&port->uart.lock, flags);
878 * stop receiving characters
879 * - called whilst the port is being closed
881 static void mn10300_serial_stop_rx(struct uart_port *_port)
883 struct mn10300_serial_port *port =
884 container_of(_port, struct mn10300_serial_port, uart);
888 _enter("%s", port->name);
890 ctr = *port->_control;
892 *port->_control = ctr;
894 mn10300_serial_dis_rx_intr(port);
898 * enable modem status interrupts
900 static void mn10300_serial_enable_ms(struct uart_port *_port)
902 struct mn10300_serial_port *port =
903 container_of(_port, struct mn10300_serial_port, uart);
907 _enter("%s", port->name);
909 if (port->type == PORT_MN10300_CTS) {
910 /* want to interrupt when CTS goes low if CTS is now high and
913 port->tx_cts = *port->_status;
915 cts = (port->tx_cts & SC2STR_CTS) ?
916 SC2CTR_TWE : SC2CTR_TWE | SC2CTR_TWS;
918 ctr = *port->_control;
921 *port->_control = ctr;
923 mn10300_serial_en_tx_intr(port);
928 * transmit or cease transmitting a break signal
930 static void mn10300_serial_break_ctl(struct uart_port *_port, int ctl)
932 struct mn10300_serial_port *port =
933 container_of(_port, struct mn10300_serial_port, uart);
936 _enter("%s,%d", port->name, ctl);
938 spin_lock_irqsave(&port->uart.lock, flags);
940 /* tell the virtual DMA handler to assert BREAK */
941 port->tx_flags |= MNSCx_TX_BREAK;
942 mn10300_serial_en_tx_intr(port);
944 port->tx_flags &= ~MNSCx_TX_BREAK;
945 *port->_control &= ~SC01CTR_BKE;
946 mn10300_serial_en_tx_intr(port);
948 spin_unlock_irqrestore(&port->uart.lock, flags);
952 * grab the interrupts and enable the port for reception
954 static int mn10300_serial_startup(struct uart_port *_port)
956 struct mn10300_serial_port *port =
957 container_of(_port, struct mn10300_serial_port, uart);
958 struct mn10300_serial_int *pint;
960 _enter("%s{%d}", port->name, port->gdbstub);
962 if (unlikely(port->gdbstub))
965 /* allocate an Rx buffer for the virtual DMA handler */
966 port->rx_buffer = kmalloc(MNSC_BUFFER_SIZE, GFP_KERNEL);
967 if (!port->rx_buffer)
970 port->rx_inp = port->rx_outp = 0;
973 /* finally, enable the device */
974 *port->_intr = SC01ICR_TI;
975 *port->_control |= SC01CTR_TXE | SC01CTR_RXE;
977 pint = &mn10300_serial_int_tbl[port->rx_irq];
979 pint->vdma = mn10300_serial_vdma_rx_handler;
980 pint = &mn10300_serial_int_tbl[port->tx_irq];
982 pint->vdma = mn10300_serial_vdma_tx_handler;
984 irq_set_chip(port->rx_irq, &mn10300_serial_low_pic);
985 irq_set_chip(port->tx_irq, &mn10300_serial_low_pic);
986 irq_set_chip(port->tm_irq, &mn10300_serial_pic);
988 if (request_irq(port->rx_irq, mn10300_serial_interrupt,
989 IRQF_DISABLED | IRQF_NOBALANCING,
990 port->rx_name, port) < 0)
993 if (request_irq(port->tx_irq, mn10300_serial_interrupt,
994 IRQF_DISABLED | IRQF_NOBALANCING,
995 port->tx_name, port) < 0)
998 if (request_irq(port->tm_irq, mn10300_serial_interrupt,
999 IRQF_DISABLED | IRQF_NOBALANCING,
1000 port->tm_name, port) < 0)
1002 mn10300_serial_mask_ack(port->tm_irq);
1007 free_irq(port->tx_irq, port);
1009 free_irq(port->rx_irq, port);
1011 kfree(port->rx_buffer);
1012 port->rx_buffer = NULL;
1017 * shutdown the port and release interrupts
1019 static void mn10300_serial_shutdown(struct uart_port *_port)
1021 unsigned long flags;
1023 struct mn10300_serial_port *port =
1024 container_of(_port, struct mn10300_serial_port, uart);
1026 _enter("%s", port->name);
1028 spin_lock_irqsave(&_port->lock, flags);
1029 mn10300_serial_dis_tx_intr(port);
1031 *port->rx_icr = NUM2GxICR_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL);
1034 spin_unlock_irqrestore(&_port->lock, flags);
1036 /* disable the serial port and its baud rate timer */
1037 *port->_control &= ~(SC01CTR_TXE | SC01CTR_RXE | SC01CTR_BKE);
1040 if (port->rx_buffer) {
1041 void *buf = port->rx_buffer;
1042 port->rx_buffer = NULL;
1046 /* disable all intrs */
1047 free_irq(port->tm_irq, port);
1048 free_irq(port->rx_irq, port);
1049 free_irq(port->tx_irq, port);
1051 mn10300_serial_int_tbl[port->tx_irq].port = NULL;
1052 mn10300_serial_int_tbl[port->rx_irq].port = NULL;
1056 * this routine is called to set the UART divisor registers to match the
1057 * specified baud rate for a serial port.
1059 static void mn10300_serial_change_speed(struct mn10300_serial_port *port,
1060 struct ktermios *new,
1061 struct ktermios *old)
1063 unsigned long flags;
1064 unsigned long ioclk = port->ioclk;
1066 int baud, bits, xdiv, tmp;
1069 u8 div_timer = port->div_timer;
1071 _enter("%s{%lu}", port->name, ioclk);
1073 /* byte size and parity */
1074 cflag = new->c_cflag;
1075 switch (cflag & CSIZE) {
1076 case CS7: scxctr = SC01CTR_CLN_7BIT; bits = 9; break;
1077 case CS8: scxctr = SC01CTR_CLN_8BIT; bits = 10; break;
1078 default: scxctr = SC01CTR_CLN_8BIT; bits = 10; break;
1081 if (cflag & CSTOPB) {
1082 scxctr |= SC01CTR_STB_2BIT;
1086 if (cflag & PARENB) {
1089 scxctr |= SC01CTR_PB_ODD;
1091 else if (cflag & CMSPAR)
1092 scxctr |= SC01CTR_PB_FIXED0;
1095 scxctr |= SC01CTR_PB_EVEN;
1098 /* Determine divisor based on baud rate */
1101 switch (port->uart.line) {
1102 #ifdef CONFIG_MN10300_TTYSM0
1103 case 0: /* ttySM0 */
1104 #if defined(CONFIG_MN10300_TTYSM0_TIMER8)
1105 scxctr |= SC0CTR_CK_TM8UFLOW_8;
1106 #elif defined(CONFIG_MN10300_TTYSM0_TIMER0)
1107 scxctr |= SC0CTR_CK_TM0UFLOW_8;
1108 #elif defined(CONFIG_MN10300_TTYSM0_TIMER2)
1109 scxctr |= SC0CTR_CK_TM2UFLOW_8;
1111 #error "Unknown config for ttySM0"
1114 #endif /* CONFIG_MN10300_TTYSM0 */
1116 #ifdef CONFIG_MN10300_TTYSM1
1117 case 1: /* ttySM1 */
1118 #if defined(CONFIG_AM33_2) || defined(CONFIG_AM33_3)
1119 #if defined(CONFIG_MN10300_TTYSM1_TIMER9)
1120 scxctr |= SC1CTR_CK_TM9UFLOW_8;
1121 #elif defined(CONFIG_MN10300_TTYSM1_TIMER3)
1122 scxctr |= SC1CTR_CK_TM3UFLOW_8;
1124 #error "Unknown config for ttySM1"
1126 #else /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1127 #if defined(CONFIG_MN10300_TTYSM1_TIMER12)
1128 scxctr |= SC1CTR_CK_TM12UFLOW_8;
1130 #error "Unknown config for ttySM1"
1132 #endif /* CONFIG_AM33_2 || CONFIG_AM33_3 */
1134 #endif /* CONFIG_MN10300_TTYSM1 */
1136 #ifdef CONFIG_MN10300_TTYSM2
1137 case 2: /* ttySM2 */
1138 #if defined(CONFIG_AM33_2)
1139 #if defined(CONFIG_MN10300_TTYSM2_TIMER10)
1140 scxctr |= SC2CTR_CK_TM10UFLOW;
1142 #error "Unknown config for ttySM2"
1144 #else /* CONFIG_AM33_2 */
1145 #if defined(CONFIG_MN10300_TTYSM2_TIMER9)
1146 scxctr |= SC2CTR_CK_TM9UFLOW_8;
1147 #elif defined(CONFIG_MN10300_TTYSM2_TIMER1)
1148 scxctr |= SC2CTR_CK_TM1UFLOW_8;
1149 #elif defined(CONFIG_MN10300_TTYSM2_TIMER3)
1150 scxctr |= SC2CTR_CK_TM3UFLOW_8;
1152 #error "Unknown config for ttySM2"
1154 #endif /* CONFIG_AM33_2 */
1156 #endif /* CONFIG_MN10300_TTYSM2 */
1163 baud = uart_get_baud_rate(&port->uart, new, old, 0,
1166 _debug("ALT %d [baud %d]", battempt, baud);
1169 baud = 9600; /* B0 transition handled in rs_set_termios */
1172 baud = 269; /* 134 is really 134.5 */
1176 if (baud == 38400 &&
1177 (port->uart.flags & UPF_SPD_MASK) == UPF_SPD_CUST
1179 _debug("CUSTOM %u", port->uart.custom_divisor);
1181 if (div_timer == MNSCx_DIV_TIMER_16BIT) {
1182 if (port->uart.custom_divisor <= 65535) {
1183 tmxmd = TM8MD_SRC_IOCLK;
1184 tmxbr = port->uart.custom_divisor;
1185 port->uart.uartclk = ioclk;
1188 if (port->uart.custom_divisor / 8 <= 65535) {
1189 tmxmd = TM8MD_SRC_IOCLK_8;
1190 tmxbr = port->uart.custom_divisor / 8;
1191 port->uart.custom_divisor = tmxbr * 8;
1192 port->uart.uartclk = ioclk / 8;
1195 if (port->uart.custom_divisor / 32 <= 65535) {
1196 tmxmd = TM8MD_SRC_IOCLK_32;
1197 tmxbr = port->uart.custom_divisor / 32;
1198 port->uart.custom_divisor = tmxbr * 32;
1199 port->uart.uartclk = ioclk / 32;
1203 } else if (div_timer == MNSCx_DIV_TIMER_8BIT) {
1204 if (port->uart.custom_divisor <= 255) {
1205 tmxmd = TM2MD_SRC_IOCLK;
1206 tmxbr = port->uart.custom_divisor;
1207 port->uart.uartclk = ioclk;
1210 if (port->uart.custom_divisor / 8 <= 255) {
1211 tmxmd = TM2MD_SRC_IOCLK_8;
1212 tmxbr = port->uart.custom_divisor / 8;
1213 port->uart.custom_divisor = tmxbr * 8;
1214 port->uart.uartclk = ioclk / 8;
1217 if (port->uart.custom_divisor / 32 <= 255) {
1218 tmxmd = TM2MD_SRC_IOCLK_32;
1219 tmxbr = port->uart.custom_divisor / 32;
1220 port->uart.custom_divisor = tmxbr * 32;
1221 port->uart.uartclk = ioclk / 32;
1227 switch (div_timer) {
1228 case MNSCx_DIV_TIMER_16BIT:
1229 port->uart.uartclk = ioclk;
1230 tmxmd = TM8MD_SRC_IOCLK;
1231 tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
1232 if (tmp > 0 && tmp <= 65535)
1235 port->uart.uartclk = ioclk / 8;
1236 tmxmd = TM8MD_SRC_IOCLK_8;
1237 tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
1238 if (tmp > 0 && tmp <= 65535)
1241 port->uart.uartclk = ioclk / 32;
1242 tmxmd = TM8MD_SRC_IOCLK_32;
1243 tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
1244 if (tmp > 0 && tmp <= 65535)
1248 case MNSCx_DIV_TIMER_8BIT:
1249 port->uart.uartclk = ioclk;
1250 tmxmd = TM2MD_SRC_IOCLK;
1251 tmxbr = tmp = (ioclk / (baud * xdiv) + 4) / 8 - 1;
1252 if (tmp > 0 && tmp <= 255)
1255 port->uart.uartclk = ioclk / 8;
1256 tmxmd = TM2MD_SRC_IOCLK_8;
1257 tmxbr = tmp = (ioclk / (baud * 8 * xdiv) + 4) / 8 - 1;
1258 if (tmp > 0 && tmp <= 255)
1261 port->uart.uartclk = ioclk / 32;
1262 tmxmd = TM2MD_SRC_IOCLK_32;
1263 tmxbr = tmp = (ioclk / (baud * 32 * xdiv) + 4) / 8 - 1;
1264 if (tmp > 0 && tmp <= 255)
1273 /* refuse to change to a baud rate we can't support */
1274 _debug("CAN'T SUPPORT");
1279 new->c_cflag &= ~CBAUD;
1280 new->c_cflag |= (old->c_cflag & CBAUD);
1282 goto try_alternative;
1286 /* as a last resort, if the quotient is zero, default to 9600
1288 new->c_cflag &= ~CBAUD;
1289 new->c_cflag |= B9600;
1291 goto try_alternative;
1294 /* hmmm... can't seem to support 9600 either
1295 * - we could try iterating through the speeds we know about to
1298 new->c_cflag &= ~CBAUD;
1301 if (div_timer == MNSCx_DIV_TIMER_16BIT)
1302 tmxmd = TM8MD_SRC_IOCLK_32;
1303 else if (div_timer == MNSCx_DIV_TIMER_8BIT)
1304 tmxmd = TM2MD_SRC_IOCLK_32;
1307 port->uart.uartclk = ioclk / 32;
1312 _debug("UARTCLK: %u / %hu", port->uart.uartclk, tmxbr);
1314 /* make the changes */
1315 spin_lock_irqsave(&port->uart.lock, flags);
1317 uart_update_timeout(&port->uart, new->c_cflag, baud);
1319 /* set the timer to produce the required baud rate */
1320 switch (div_timer) {
1321 case MNSCx_DIV_TIMER_16BIT:
1323 *port->_tmxbr = tmxbr;
1324 *port->_tmxmd = TM8MD_INIT_COUNTER;
1325 *port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
1328 case MNSCx_DIV_TIMER_8BIT:
1330 *(volatile u8 *) port->_tmxbr = (u8) tmxbr;
1331 *port->_tmxmd = TM2MD_INIT_COUNTER;
1332 *port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
1336 /* CTS flow control flag and modem status interrupts */
1337 scxctr &= ~(SC2CTR_TWE | SC2CTR_TWS);
1339 if (port->type == PORT_MN10300_CTS && cflag & CRTSCTS) {
1340 /* want to interrupt when CTS goes low if CTS is now
1341 * high and vice versa
1343 port->tx_cts = *port->_status;
1345 if (port->tx_cts & SC2STR_CTS)
1346 scxctr |= SC2CTR_TWE;
1348 scxctr |= SC2CTR_TWE | SC2CTR_TWS;
1351 /* set up parity check flag */
1352 port->uart.read_status_mask = (1 << TTY_NORMAL) | (1 << TTY_OVERRUN);
1353 if (new->c_iflag & INPCK)
1354 port->uart.read_status_mask |=
1355 (1 << TTY_PARITY) | (1 << TTY_FRAME);
1356 if (new->c_iflag & (BRKINT | PARMRK))
1357 port->uart.read_status_mask |= (1 << TTY_BREAK);
1359 /* characters to ignore */
1360 port->uart.ignore_status_mask = 0;
1361 if (new->c_iflag & IGNPAR)
1362 port->uart.ignore_status_mask |=
1363 (1 << TTY_PARITY) | (1 << TTY_FRAME);
1364 if (new->c_iflag & IGNBRK) {
1365 port->uart.ignore_status_mask |= (1 << TTY_BREAK);
1367 * If we're ignoring parity and break indicators,
1368 * ignore overruns to (for real raw support).
1370 if (new->c_iflag & IGNPAR)
1371 port->uart.ignore_status_mask |= (1 << TTY_OVERRUN);
1374 /* Ignore all characters if CREAD is not set */
1375 if ((new->c_cflag & CREAD) == 0)
1376 port->uart.ignore_status_mask |= (1 << TTY_NORMAL);
1378 scxctr |= SC01CTR_TXE | SC01CTR_RXE;
1379 scxctr |= *port->_control & SC01CTR_BKE;
1380 *port->_control = scxctr;
1382 spin_unlock_irqrestore(&port->uart.lock, flags);
1386 * set the terminal I/O parameters
1388 static void mn10300_serial_set_termios(struct uart_port *_port,
1389 struct ktermios *new,
1390 struct ktermios *old)
1392 struct mn10300_serial_port *port =
1393 container_of(_port, struct mn10300_serial_port, uart);
1395 _enter("%s,%p,%p", port->name, new, old);
1397 mn10300_serial_change_speed(port, new, old);
1399 /* handle turning off CRTSCTS */
1400 if (!(new->c_cflag & CRTSCTS)) {
1401 u16 ctr = *port->_control;
1403 *port->_control = ctr;
1406 /* change Transfer bit-order (LSB/MSB) */
1407 if (new->c_cflag & CODMSB)
1408 *port->_control |= SC01CTR_OD_MSBFIRST; /* MSB MODE */
1410 *port->_control &= ~SC01CTR_OD_MSBFIRST; /* LSB MODE */
1414 * return description of port type
1416 static const char *mn10300_serial_type(struct uart_port *_port)
1418 struct mn10300_serial_port *port =
1419 container_of(_port, struct mn10300_serial_port, uart);
1421 if (port->uart.type == PORT_MN10300_CTS)
1422 return "MN10300 SIF_CTS";
1424 return "MN10300 SIF";
1428 * release I/O and memory regions in use by port
1430 static void mn10300_serial_release_port(struct uart_port *_port)
1432 struct mn10300_serial_port *port =
1433 container_of(_port, struct mn10300_serial_port, uart);
1435 _enter("%s", port->name);
1437 release_mem_region((unsigned long) port->_iobase, 16);
1441 * request I/O and memory regions for port
1443 static int mn10300_serial_request_port(struct uart_port *_port)
1445 struct mn10300_serial_port *port =
1446 container_of(_port, struct mn10300_serial_port, uart);
1448 _enter("%s", port->name);
1450 request_mem_region((unsigned long) port->_iobase, 16, port->name);
1455 * configure the type and reserve the ports
1457 static void mn10300_serial_config_port(struct uart_port *_port, int type)
1459 struct mn10300_serial_port *port =
1460 container_of(_port, struct mn10300_serial_port, uart);
1462 _enter("%s", port->name);
1464 port->uart.type = PORT_MN10300;
1466 if (port->options & MNSCx_OPT_CTS)
1467 port->uart.type = PORT_MN10300_CTS;
1469 mn10300_serial_request_port(_port);
1473 * verify serial parameters are suitable for this port type
1475 static int mn10300_serial_verify_port(struct uart_port *_port,
1476 struct serial_struct *ss)
1478 struct mn10300_serial_port *port =
1479 container_of(_port, struct mn10300_serial_port, uart);
1480 void *mapbase = (void *) (unsigned long) port->uart.mapbase;
1482 _enter("%s", port->name);
1484 /* these things may not be changed */
1485 if (ss->irq != port->uart.irq ||
1486 ss->port != port->uart.iobase ||
1487 ss->io_type != port->uart.iotype ||
1488 ss->iomem_base != mapbase ||
1489 ss->iomem_reg_shift != port->uart.regshift ||
1490 ss->hub6 != port->uart.hub6 ||
1491 ss->xmit_fifo_size != port->uart.fifosize)
1494 /* type may be changed on a port that supports CTS */
1495 if (ss->type != port->uart.type) {
1496 if (!(port->options & MNSCx_OPT_CTS))
1499 if (ss->type != PORT_MN10300 &&
1500 ss->type != PORT_MN10300_CTS)
1508 * initialise the MN10300 on-chip UARTs
1510 static int __init mn10300_serial_init(void)
1512 struct mn10300_serial_port *port;
1515 printk(KERN_INFO "%s version %s (%s)\n",
1516 serial_name, serial_version, serial_revdate);
1518 #if defined(CONFIG_MN10300_TTYSM2) && defined(CONFIG_AM33_2)
1521 SC2TIM = 8; /* make the baud base of timer 2 IOCLK/8 */
1526 set_intr_stub(NUM2EXCEP_IRQ_LEVEL(CONFIG_MN10300_SERIAL_IRQ_LEVEL),
1527 mn10300_serial_vdma_interrupt);
1529 ret = uart_register_driver(&mn10300_serial_driver);
1531 for (i = 0 ; i < NR_PORTS ; i++) {
1532 port = mn10300_serial_ports[i];
1533 if (!port || port->gdbstub)
1536 switch (port->clock_src) {
1537 case MNSCx_CLOCK_SRC_IOCLK:
1538 port->ioclk = MN10300_IOCLK;
1541 #ifdef MN10300_IOBCLK
1542 case MNSCx_CLOCK_SRC_IOBCLK:
1543 port->ioclk = MN10300_IOBCLK;
1550 ret = uart_add_one_port(&mn10300_serial_driver,
1554 _debug("ERROR %d", -ret);
1560 uart_unregister_driver(&mn10300_serial_driver);
1566 __initcall(mn10300_serial_init);
1569 #ifdef CONFIG_MN10300_TTYSM_CONSOLE
1572 * print a string to the serial port without disturbing the real user of the
1574 * - the console must be locked by the caller
1576 static void mn10300_serial_console_write(struct console *co,
1577 const char *s, unsigned count)
1579 struct mn10300_serial_port *port;
1583 unsigned long flags;
1586 port = mn10300_serial_ports[co->index];
1588 local_irq_save(flags);
1589 if (port->uart.sysrq) {
1590 /* mn10300_serial_interrupt() already took the lock */
1592 } else if (oops_in_progress) {
1593 locked = spin_trylock(&port->uart.lock);
1595 spin_lock(&port->uart.lock);
1597 /* firstly hijack the serial port from the "virtual DMA" controller */
1598 mn10300_serial_dis_tx_intr(port);
1600 /* the transmitter may be disabled */
1601 scxctr = *port->_control;
1602 if (!(scxctr & SC01CTR_TXE)) {
1603 /* restart the UART clock */
1604 tmxmd = *port->_tmxmd;
1606 switch (port->div_timer) {
1607 case MNSCx_DIV_TIMER_16BIT:
1609 *port->_tmxmd = TM8MD_INIT_COUNTER;
1610 *port->_tmxmd = tmxmd | TM8MD_COUNT_ENABLE;
1613 case MNSCx_DIV_TIMER_8BIT:
1615 *port->_tmxmd = TM2MD_INIT_COUNTER;
1616 *port->_tmxmd = tmxmd | TM2MD_COUNT_ENABLE;
1620 /* enable the transmitter */
1621 *port->_control = (scxctr & ~SC01CTR_BKE) | SC01CTR_TXE;
1623 } else if (scxctr & SC01CTR_BKE) {
1624 /* stop transmitting BREAK */
1625 *port->_control = (scxctr & ~SC01CTR_BKE);
1628 /* send the chars into the serial port (with LF -> LFCR conversion) */
1629 for (i = 0; i < count; i++) {
1632 while (*port->_status & SC01STR_TBF)
1637 while (*port->_status & SC01STR_TBF)
1643 /* can't let the transmitter be turned off if it's actually
1645 while (*port->_status & (SC01STR_TXF | SC01STR_TBF))
1648 /* disable the transmitter if we re-enabled it */
1649 if (!(scxctr & SC01CTR_TXE))
1650 *port->_control = scxctr;
1652 mn10300_serial_en_tx_intr(port);
1655 spin_unlock(&port->uart.lock);
1656 local_irq_restore(flags);
1660 * set up a serial port as a console
1661 * - construct a cflag setting for the first rs_open()
1662 * - initialize the serial port
1663 * - return non-zero if we didn't find a serial port.
1665 static int __init mn10300_serial_console_setup(struct console *co,
1668 struct mn10300_serial_port *port;
1669 int i, parity = 'n', baud = 9600, bits = 8, flow = 0;
1671 for (i = 0 ; i < NR_PORTS ; i++) {
1672 port = mn10300_serial_ports[i];
1673 if (port && !port->gdbstub && port->uart.line == co->index)
1680 switch (port->clock_src) {
1681 case MNSCx_CLOCK_SRC_IOCLK:
1682 port->ioclk = MN10300_IOCLK;
1685 #ifdef MN10300_IOBCLK
1686 case MNSCx_CLOCK_SRC_IOBCLK:
1687 port->ioclk = MN10300_IOBCLK;
1695 uart_parse_options(options, &baud, &parity, &bits, &flow);
1697 return uart_set_options(&port->uart, co, baud, parity, bits, flow);
1703 static int __init mn10300_serial_console_init(void)
1705 register_console(&mn10300_serial_console);
1709 console_initcall(mn10300_serial_console_init);
1712 #ifdef CONFIG_CONSOLE_POLL
1714 * Polled character reception for the kernel debugger
1716 static int mn10300_serial_poll_get_char(struct uart_port *_port)
1718 struct mn10300_serial_port *port =
1719 container_of(_port, struct mn10300_serial_port, uart);
1723 _enter("%s", port->name);
1725 if (mn10300_serial_int_tbl[port->rx_irq].port != NULL) {
1727 /* pull chars out of the hat */
1728 ix = ACCESS_ONCE(port->rx_outp);
1729 if (CIRC_CNT(port->rx_inp, ix, MNSC_BUFFER_SIZE) == 0)
1730 return NO_POLL_CHAR;
1732 smp_read_barrier_depends();
1733 ch = port->rx_buffer[ix++];
1734 st = port->rx_buffer[ix++];
1736 port->rx_outp = ix & (MNSC_BUFFER_SIZE - 1);
1738 } while (st & (SC01STR_FEF | SC01STR_PEF | SC01STR_OEF));
1741 st = *port->_status;
1742 if (st & (SC01STR_FEF | SC01STR_PEF | SC01STR_OEF))
1744 } while (!(st & SC01STR_RBF));
1754 * Polled character transmission for the kernel debugger
1756 static void mn10300_serial_poll_put_char(struct uart_port *_port,
1759 struct mn10300_serial_port *port =
1760 container_of(_port, struct mn10300_serial_port, uart);
1763 /* wait for the transmitter to finish anything it might be doing (and
1764 * this includes the virtual DMA handler, so it might take a while) */
1765 while (*port->_status & (SC01STR_TBF | SC01STR_TXF))
1768 /* disable the Tx ready interrupt */
1769 intr = *port->_intr;
1770 *port->_intr = intr & ~SC01ICR_TI;
1775 while (*port->_status & SC01STR_TBF)
1780 while (*port->_status & SC01STR_TBF)
1783 /* restore the Tx interrupt flag */
1784 *port->_intr = intr;
1788 #endif /* CONFIG_CONSOLE_POLL */