4 * Driver for M32R serial ports
6 * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
7 * Based on drivers/serial/8250.c.
9 * Copyright (C) 2001 Russell King.
10 * Copyright (C) 2004 Hirokazu Takata <takata at linux-m32r.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
19 * A note about mapbase / membase
21 * mapbase is the physical address of the IO port. Currently, we don't
22 * support this very well, and it may well be dropped from this driver
23 * in future. As such, mapbase should be NULL.
25 * membase is an 'ioremapped' cookie. This is compatible with the old
26 * serial.c driver, and is currently the preferred form.
29 #if defined(CONFIG_SERIAL_M32R_SIO_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/ioport.h>
36 #include <linux/init.h>
37 #include <linux/console.h>
38 #include <linux/sysrq.h>
39 #include <linux/serial.h>
40 #include <linux/delay.h>
46 #define BAUD_RATE 115200
48 #include <linux/serial_core.h>
49 #include "m32r_sio_reg.h"
51 #define PASS_LIMIT 256
56 } old_serial_port[] = {
57 #if defined(CONFIG_PLAT_USRV)
59 { 0x3F8, PLD_IRQ_UART0 }, /* ttyS0 */
60 { 0x2F8, PLD_IRQ_UART1 }, /* ttyS1 */
61 #elif defined(CONFIG_SERIAL_M32R_PLDSIO)
62 { ((unsigned long)PLD_ESIO0CR), PLD_IRQ_SIO0_RCV }, /* ttyS0 */
64 { M32R_SIO_OFFSET, M32R_IRQ_SIO0_R }, /* ttyS0 */
68 #define UART_NR ARRAY_SIZE(old_serial_port)
70 struct uart_sio_port {
71 struct uart_port port;
72 struct timer_list timer; /* "no irq" timer */
73 struct list_head list; /* ports on this IRQ */
79 struct list_head *head;
82 static struct irq_info irq_lists[NR_IRQS];
84 #ifdef CONFIG_SERIAL_M32R_PLDSIO
86 #define __sio_in(x) inw((unsigned long)(x))
87 #define __sio_out(v,x) outw((v),(unsigned long)(x))
89 static inline void sio_set_baud_rate(unsigned long baud)
92 sbaud = (boot_cpu_data.bus_clock / (baud * 4))-1;
93 __sio_out(sbaud, PLD_ESIO0BAUR);
96 static void sio_reset(void)
100 tmp = __sio_in(PLD_ESIO0RXB);
101 tmp = __sio_in(PLD_ESIO0RXB);
102 tmp = __sio_in(PLD_ESIO0CR);
103 sio_set_baud_rate(BAUD_RATE);
104 __sio_out(0x0300, PLD_ESIO0CR);
105 __sio_out(0x0003, PLD_ESIO0CR);
108 static void sio_init(void)
112 tmp = __sio_in(PLD_ESIO0RXB);
113 tmp = __sio_in(PLD_ESIO0RXB);
114 tmp = __sio_in(PLD_ESIO0CR);
115 __sio_out(0x0300, PLD_ESIO0CR);
116 __sio_out(0x0003, PLD_ESIO0CR);
119 static void sio_error(int *status)
121 printk("SIO0 error[%04x]\n", *status);
124 } while ((*status = __sio_in(PLD_ESIO0CR)) != 3);
127 #else /* not CONFIG_SERIAL_M32R_PLDSIO */
129 #define __sio_in(x) inl(x)
130 #define __sio_out(v,x) outl((v),(x))
132 static inline void sio_set_baud_rate(unsigned long baud)
136 i = boot_cpu_data.bus_clock / (baud * 16);
137 j = (boot_cpu_data.bus_clock - (i * baud * 16)) / baud;
141 __sio_out(i, M32R_SIO0_BAUR_PORTL);
142 __sio_out(j, M32R_SIO0_RBAUR_PORTL);
145 static void sio_reset(void)
147 __sio_out(0x00000300, M32R_SIO0_CR_PORTL); /* init status */
148 __sio_out(0x00000800, M32R_SIO0_MOD1_PORTL); /* 8bit */
149 __sio_out(0x00000080, M32R_SIO0_MOD0_PORTL); /* 1stop non */
150 sio_set_baud_rate(BAUD_RATE);
151 __sio_out(0x00000000, M32R_SIO0_TRCR_PORTL);
152 __sio_out(0x00000003, M32R_SIO0_CR_PORTL); /* RXCEN */
155 static void sio_init(void)
159 tmp = __sio_in(M32R_SIO0_RXB_PORTL);
160 tmp = __sio_in(M32R_SIO0_RXB_PORTL);
161 tmp = __sio_in(M32R_SIO0_STS_PORTL);
162 __sio_out(0x00000003, M32R_SIO0_CR_PORTL);
165 static void sio_error(int *status)
167 printk("SIO0 error[%04x]\n", *status);
170 } while ((*status = __sio_in(M32R_SIO0_CR_PORTL)) != 3);
173 #endif /* CONFIG_SERIAL_M32R_PLDSIO */
175 static unsigned int sio_in(struct uart_sio_port *up, int offset)
177 return __sio_in(up->port.iobase + offset);
180 static void sio_out(struct uart_sio_port *up, int offset, int value)
182 __sio_out(value, up->port.iobase + offset);
185 static unsigned int serial_in(struct uart_sio_port *up, int offset)
190 return __sio_in(offset);
193 static void serial_out(struct uart_sio_port *up, int offset, int value)
198 __sio_out(value, offset);
201 static void m32r_sio_stop_tx(struct uart_port *port)
203 struct uart_sio_port *up =
204 container_of(port, struct uart_sio_port, port);
206 if (up->ier & UART_IER_THRI) {
207 up->ier &= ~UART_IER_THRI;
208 serial_out(up, UART_IER, up->ier);
212 static void m32r_sio_start_tx(struct uart_port *port)
214 #ifdef CONFIG_SERIAL_M32R_PLDSIO
215 struct uart_sio_port *up =
216 container_of(port, struct uart_sio_port, port);
217 struct circ_buf *xmit = &up->port.state->xmit;
219 if (!(up->ier & UART_IER_THRI)) {
220 up->ier |= UART_IER_THRI;
221 serial_out(up, UART_IER, up->ier);
222 if (!uart_circ_empty(xmit)) {
223 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
224 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
225 up->port.icount.tx++;
228 while((serial_in(up, UART_LSR) & UART_EMPTY) != UART_EMPTY);
230 struct uart_sio_port *up =
231 container_of(port, struct uart_sio_port, port);
233 if (!(up->ier & UART_IER_THRI)) {
234 up->ier |= UART_IER_THRI;
235 serial_out(up, UART_IER, up->ier);
240 static void m32r_sio_stop_rx(struct uart_port *port)
242 struct uart_sio_port *up =
243 container_of(port, struct uart_sio_port, port);
245 up->ier &= ~UART_IER_RLSI;
246 up->port.read_status_mask &= ~UART_LSR_DR;
247 serial_out(up, UART_IER, up->ier);
250 static void m32r_sio_enable_ms(struct uart_port *port)
252 struct uart_sio_port *up =
253 container_of(port, struct uart_sio_port, port);
255 up->ier |= UART_IER_MSI;
256 serial_out(up, UART_IER, up->ier);
259 static void receive_chars(struct uart_sio_port *up, int *status)
261 struct tty_port *port = &up->port.state->port;
267 ch = sio_in(up, SIORXB);
269 up->port.icount.rx++;
271 if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
272 UART_LSR_FE | UART_LSR_OE))) {
274 * For statistics only
276 if (*status & UART_LSR_BI) {
277 *status &= ~(UART_LSR_FE | UART_LSR_PE);
278 up->port.icount.brk++;
280 * We do the SysRQ and SAK checking
281 * here because otherwise the break
282 * may get masked by ignore_status_mask
283 * or read_status_mask.
285 if (uart_handle_break(&up->port))
287 } else if (*status & UART_LSR_PE)
288 up->port.icount.parity++;
289 else if (*status & UART_LSR_FE)
290 up->port.icount.frame++;
291 if (*status & UART_LSR_OE)
292 up->port.icount.overrun++;
295 * Mask off conditions which should be ingored.
297 *status &= up->port.read_status_mask;
299 if (*status & UART_LSR_BI) {
300 pr_debug("handling break....\n");
302 } else if (*status & UART_LSR_PE)
304 else if (*status & UART_LSR_FE)
307 if (uart_handle_sysrq_char(&up->port, ch))
309 if ((*status & up->port.ignore_status_mask) == 0)
310 tty_insert_flip_char(port, ch, flag);
312 if (*status & UART_LSR_OE) {
314 * Overrun is special, since it's reported
315 * immediately, and doesn't affect the current
318 tty_insert_flip_char(port, 0, TTY_OVERRUN);
321 *status = serial_in(up, UART_LSR);
322 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
324 spin_unlock(&up->port.lock);
325 tty_flip_buffer_push(port);
326 spin_lock(&up->port.lock);
329 static void transmit_chars(struct uart_sio_port *up)
331 struct circ_buf *xmit = &up->port.state->xmit;
334 if (up->port.x_char) {
335 #ifndef CONFIG_SERIAL_M32R_PLDSIO /* XXX */
336 serial_out(up, UART_TX, up->port.x_char);
338 up->port.icount.tx++;
342 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
343 m32r_sio_stop_tx(&up->port);
347 count = up->port.fifosize;
349 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
350 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
351 up->port.icount.tx++;
352 if (uart_circ_empty(xmit))
354 while (!(serial_in(up, UART_LSR) & UART_LSR_THRE));
356 } while (--count > 0);
358 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
359 uart_write_wakeup(&up->port);
361 pr_debug("THRE...\n");
363 if (uart_circ_empty(xmit))
364 m32r_sio_stop_tx(&up->port);
368 * This handles the interrupt from one port.
370 static inline void m32r_sio_handle_port(struct uart_sio_port *up,
373 pr_debug("status = %x...\n", status);
376 receive_chars(up, &status);
382 * This is the serial driver's interrupt routine.
384 * Arjan thinks the old way was overly complex, so it got simplified.
385 * Alan disagrees, saying that need the complexity to handle the weird
386 * nature of ISA shared interrupts. (This is a special exception.)
388 * In order to handle ISA shared interrupts properly, we need to check
389 * that all ports have been serviced, and therefore the ISA interrupt
390 * line has been de-asserted.
392 * This means we need to loop through all ports. checking that they
393 * don't have an interrupt pending.
395 static irqreturn_t m32r_sio_interrupt(int irq, void *dev_id)
397 struct irq_info *i = dev_id;
398 struct list_head *l, *end = NULL;
399 int pass_counter = 0;
401 pr_debug("m32r_sio_interrupt(%d)...\n", irq);
403 #ifdef CONFIG_SERIAL_M32R_PLDSIO
404 // if (irq == PLD_IRQ_SIO0_SND)
405 // irq = PLD_IRQ_SIO0_RCV;
407 if (irq == M32R_IRQ_SIO0_S)
408 irq = M32R_IRQ_SIO0_R;
415 struct uart_sio_port *up;
418 up = list_entry(l, struct uart_sio_port, list);
420 sts = sio_in(up, SIOSTS);
422 spin_lock(&up->port.lock);
423 m32r_sio_handle_port(up, sts);
424 spin_unlock(&up->port.lock);
427 } else if (end == NULL)
432 if (l == i->head && pass_counter++ > PASS_LIMIT) {
439 spin_unlock(&i->lock);
447 * To support ISA shared interrupts, we need to have one interrupt
448 * handler that ensures that the IRQ line has been deasserted
449 * before returning. Failing to do this will result in the IRQ
450 * line being stuck active, and, since ISA irqs are edge triggered,
451 * no more IRQs will be seen.
453 static void serial_do_unlink(struct irq_info *i, struct uart_sio_port *up)
455 spin_lock_irq(&i->lock);
457 if (!list_empty(i->head)) {
458 if (i->head == &up->list)
459 i->head = i->head->next;
462 BUG_ON(i->head != &up->list);
466 spin_unlock_irq(&i->lock);
469 static int serial_link_irq_chain(struct uart_sio_port *up)
471 struct irq_info *i = irq_lists + up->port.irq;
472 int ret, irq_flags = 0;
474 spin_lock_irq(&i->lock);
477 list_add(&up->list, i->head);
478 spin_unlock_irq(&i->lock);
482 INIT_LIST_HEAD(&up->list);
484 spin_unlock_irq(&i->lock);
486 ret = request_irq(up->port.irq, m32r_sio_interrupt,
487 irq_flags, "SIO0-RX", i);
488 ret |= request_irq(up->port.irq + 1, m32r_sio_interrupt,
489 irq_flags, "SIO0-TX", i);
491 serial_do_unlink(i, up);
497 static void serial_unlink_irq_chain(struct uart_sio_port *up)
499 struct irq_info *i = irq_lists + up->port.irq;
501 BUG_ON(i->head == NULL);
503 if (list_empty(i->head)) {
504 free_irq(up->port.irq, i);
505 free_irq(up->port.irq + 1, i);
508 serial_do_unlink(i, up);
512 * This function is used to handle ports that do not have an interrupt.
514 static void m32r_sio_timeout(unsigned long data)
516 struct uart_sio_port *up = (struct uart_sio_port *)data;
517 unsigned int timeout;
520 sts = sio_in(up, SIOSTS);
522 spin_lock(&up->port.lock);
523 m32r_sio_handle_port(up, sts);
524 spin_unlock(&up->port.lock);
527 timeout = up->port.timeout;
528 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
529 mod_timer(&up->timer, jiffies + timeout);
532 static unsigned int m32r_sio_tx_empty(struct uart_port *port)
534 struct uart_sio_port *up =
535 container_of(port, struct uart_sio_port, port);
539 spin_lock_irqsave(&up->port.lock, flags);
540 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
541 spin_unlock_irqrestore(&up->port.lock, flags);
546 static unsigned int m32r_sio_get_mctrl(struct uart_port *port)
551 static void m32r_sio_set_mctrl(struct uart_port *port, unsigned int mctrl)
556 static void m32r_sio_break_ctl(struct uart_port *port, int break_state)
561 static int m32r_sio_startup(struct uart_port *port)
563 struct uart_sio_port *up =
564 container_of(port, struct uart_sio_port, port);
570 * If the "interrupt" for this port doesn't correspond with any
571 * hardware interrupt, we use a timer-based system. The original
572 * driver used to do this with IRQ0.
575 unsigned int timeout = up->port.timeout;
577 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
579 up->timer.data = (unsigned long)up;
580 mod_timer(&up->timer, jiffies + timeout);
582 retval = serial_link_irq_chain(up);
588 * Finally, enable interrupts. Note: Modem status interrupts
589 * are set via set_termios(), which will be occurring imminently
590 * anyway, so we don't enable them here.
592 * - M32R_PLDSIO: 0x04
594 up->ier = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
595 sio_out(up, SIOTRCR, up->ier);
598 * And clear the interrupt registers again for luck.
605 static void m32r_sio_shutdown(struct uart_port *port)
607 struct uart_sio_port *up =
608 container_of(port, struct uart_sio_port, port);
611 * Disable interrupts from this port
614 sio_out(up, SIOTRCR, 0);
617 * Disable break condition and FIFOs
623 del_timer_sync(&up->timer);
625 serial_unlink_irq_chain(up);
628 static unsigned int m32r_sio_get_divisor(struct uart_port *port,
631 return uart_get_divisor(port, baud);
634 static void m32r_sio_set_termios(struct uart_port *port,
635 struct ktermios *termios, struct ktermios *old)
637 struct uart_sio_port *up =
638 container_of(port, struct uart_sio_port, port);
639 unsigned char cval = 0;
641 unsigned int baud, quot;
643 switch (termios->c_cflag & CSIZE) {
645 cval = UART_LCR_WLEN5;
648 cval = UART_LCR_WLEN6;
651 cval = UART_LCR_WLEN7;
655 cval = UART_LCR_WLEN8;
659 if (termios->c_cflag & CSTOPB)
660 cval |= UART_LCR_STOP;
661 if (termios->c_cflag & PARENB)
662 cval |= UART_LCR_PARITY;
663 if (!(termios->c_cflag & PARODD))
664 cval |= UART_LCR_EPAR;
666 if (termios->c_cflag & CMSPAR)
667 cval |= UART_LCR_SPAR;
671 * Ask the core to calculate the divisor for us.
673 #ifdef CONFIG_SERIAL_M32R_PLDSIO
674 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/4);
676 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
678 quot = m32r_sio_get_divisor(port, baud);
681 * Ok, we're now changing the port state. Do it with
682 * interrupts disabled.
684 spin_lock_irqsave(&up->port.lock, flags);
686 sio_set_baud_rate(baud);
689 * Update the per-port timeout.
691 uart_update_timeout(port, termios->c_cflag, baud);
693 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
694 if (termios->c_iflag & INPCK)
695 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
696 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
697 up->port.read_status_mask |= UART_LSR_BI;
700 * Characteres to ignore
702 up->port.ignore_status_mask = 0;
703 if (termios->c_iflag & IGNPAR)
704 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
705 if (termios->c_iflag & IGNBRK) {
706 up->port.ignore_status_mask |= UART_LSR_BI;
708 * If we're ignoring parity and break indicators,
709 * ignore overruns too (for real raw support).
711 if (termios->c_iflag & IGNPAR)
712 up->port.ignore_status_mask |= UART_LSR_OE;
716 * ignore all characters if CREAD is not set
718 if ((termios->c_cflag & CREAD) == 0)
719 up->port.ignore_status_mask |= UART_LSR_DR;
722 * CTS flow control flag and modem status interrupts
724 up->ier &= ~UART_IER_MSI;
725 if (UART_ENABLE_MS(&up->port, termios->c_cflag))
726 up->ier |= UART_IER_MSI;
728 serial_out(up, UART_IER, up->ier);
730 spin_unlock_irqrestore(&up->port.lock, flags);
734 * Resource handling. This is complicated by the fact that resources
735 * depend on the port type. Maybe we should be claiming the standard
736 * 8250 ports, and then trying to get other resources as necessary?
739 m32r_sio_request_std_resource(struct uart_sio_port *up, struct resource **res)
741 unsigned int size = 8 << up->port.regshift;
742 #ifndef CONFIG_SERIAL_M32R_PLDSIO
747 switch (up->port.iotype) {
749 if (up->port.mapbase) {
750 #ifdef CONFIG_SERIAL_M32R_PLDSIO
751 *res = request_mem_region(up->port.mapbase, size, "serial");
753 start = up->port.mapbase;
754 *res = request_mem_region(start, size, "serial");
762 *res = request_region(up->port.iobase, size, "serial");
770 static void m32r_sio_release_port(struct uart_port *port)
772 struct uart_sio_port *up =
773 container_of(port, struct uart_sio_port, port);
774 unsigned long start, offset = 0, size = 0;
776 size <<= up->port.regshift;
778 switch (up->port.iotype) {
780 if (up->port.mapbase) {
784 iounmap(up->port.membase);
785 up->port.membase = NULL;
787 start = up->port.mapbase;
790 release_mem_region(start + offset, size);
791 release_mem_region(start, 8 << up->port.regshift);
796 start = up->port.iobase;
799 release_region(start + offset, size);
800 release_region(start + offset, 8 << up->port.regshift);
808 static int m32r_sio_request_port(struct uart_port *port)
810 struct uart_sio_port *up =
811 container_of(port, struct uart_sio_port, port);
812 struct resource *res = NULL;
815 ret = m32r_sio_request_std_resource(up, &res);
818 * If we have a mapbase, then request that as well.
820 if (ret == 0 && up->port.flags & UPF_IOREMAP) {
821 int size = resource_size(res);
823 up->port.membase = ioremap(up->port.mapbase, size);
824 if (!up->port.membase)
830 release_resource(res);
836 static void m32r_sio_config_port(struct uart_port *port, int unused)
838 struct uart_sio_port *up =
839 container_of(port, struct uart_sio_port, port);
842 spin_lock_irqsave(&up->port.lock, flags);
844 up->port.fifosize = 1;
846 spin_unlock_irqrestore(&up->port.lock, flags);
850 m32r_sio_verify_port(struct uart_port *port, struct serial_struct *ser)
852 if (ser->irq >= nr_irqs || ser->irq < 0 || ser->baud_base < 9600)
857 static struct uart_ops m32r_sio_pops = {
858 .tx_empty = m32r_sio_tx_empty,
859 .set_mctrl = m32r_sio_set_mctrl,
860 .get_mctrl = m32r_sio_get_mctrl,
861 .stop_tx = m32r_sio_stop_tx,
862 .start_tx = m32r_sio_start_tx,
863 .stop_rx = m32r_sio_stop_rx,
864 .enable_ms = m32r_sio_enable_ms,
865 .break_ctl = m32r_sio_break_ctl,
866 .startup = m32r_sio_startup,
867 .shutdown = m32r_sio_shutdown,
868 .set_termios = m32r_sio_set_termios,
869 .release_port = m32r_sio_release_port,
870 .request_port = m32r_sio_request_port,
871 .config_port = m32r_sio_config_port,
872 .verify_port = m32r_sio_verify_port,
875 static struct uart_sio_port m32r_sio_ports[UART_NR];
877 static void __init m32r_sio_init_ports(void)
879 struct uart_sio_port *up;
880 static int first = 1;
887 for (i = 0, up = m32r_sio_ports; i < UART_NR; i++, up++) {
888 up->port.iobase = old_serial_port[i].port;
889 up->port.irq = irq_canonicalize(old_serial_port[i].irq);
890 up->port.uartclk = BAUD_RATE * 16;
891 up->port.flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
892 up->port.membase = 0;
894 up->port.regshift = 0;
895 up->port.ops = &m32r_sio_pops;
899 static void __init m32r_sio_register_ports(struct uart_driver *drv)
903 m32r_sio_init_ports();
905 for (i = 0; i < UART_NR; i++) {
906 struct uart_sio_port *up = &m32r_sio_ports[i];
909 up->port.ops = &m32r_sio_pops;
910 init_timer(&up->timer);
911 up->timer.function = m32r_sio_timeout;
913 uart_add_one_port(drv, &up->port);
917 #ifdef CONFIG_SERIAL_M32R_SIO_CONSOLE
920 * Wait for transmitter & holding register to empty
922 static void wait_for_xmitr(struct uart_sio_port *up)
924 unsigned int status, tmout = 10000;
926 /* Wait up to 10ms for the character(s) to be sent. */
928 status = sio_in(up, SIOSTS);
933 } while ((status & UART_EMPTY) != UART_EMPTY);
935 /* Wait up to 1s for flow control if necessary */
936 if (up->port.flags & UPF_CONS_FLOW) {
943 static void m32r_sio_console_putchar(struct uart_port *port, int ch)
945 struct uart_sio_port *up =
946 container_of(port, struct uart_sio_port, port);
949 sio_out(up, SIOTXB, ch);
953 * Print a string to the serial port trying not to disturb
954 * any possible real use of the port...
956 * The console_lock must be held when we get here.
958 static void m32r_sio_console_write(struct console *co, const char *s,
961 struct uart_sio_port *up = &m32r_sio_ports[co->index];
965 * First save the UER then disable the interrupts
967 ier = sio_in(up, SIOTRCR);
968 sio_out(up, SIOTRCR, 0);
970 uart_console_write(&up->port, s, count, m32r_sio_console_putchar);
973 * Finally, wait for transmitter to become empty
974 * and restore the IER
977 sio_out(up, SIOTRCR, ier);
980 static int __init m32r_sio_console_setup(struct console *co, char *options)
982 struct uart_port *port;
989 * Check whether an invalid uart number has been specified, and
990 * if so, search for the first available port that does have
993 if (co->index >= UART_NR)
995 port = &m32r_sio_ports[co->index].port;
1000 spin_lock_init(&port->lock);
1003 uart_parse_options(options, &baud, &parity, &bits, &flow);
1005 return uart_set_options(port, co, baud, parity, bits, flow);
1008 static struct uart_driver m32r_sio_reg;
1009 static struct console m32r_sio_console = {
1011 .write = m32r_sio_console_write,
1012 .device = uart_console_device,
1013 .setup = m32r_sio_console_setup,
1014 .flags = CON_PRINTBUFFER,
1016 .data = &m32r_sio_reg,
1019 static int __init m32r_sio_console_init(void)
1023 m32r_sio_init_ports();
1024 register_console(&m32r_sio_console);
1027 console_initcall(m32r_sio_console_init);
1029 #define M32R_SIO_CONSOLE &m32r_sio_console
1031 #define M32R_SIO_CONSOLE NULL
1034 static struct uart_driver m32r_sio_reg = {
1035 .owner = THIS_MODULE,
1036 .driver_name = "sio",
1041 .cons = M32R_SIO_CONSOLE,
1044 static int __init m32r_sio_init(void)
1048 printk(KERN_INFO "Serial: M32R SIO driver\n");
1050 for (i = 0; i < nr_irqs; i++)
1051 spin_lock_init(&irq_lists[i].lock);
1053 ret = uart_register_driver(&m32r_sio_reg);
1055 m32r_sio_register_ports(&m32r_sio_reg);
1059 device_initcall(m32r_sio_init);