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/module.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/ioport.h>
37 #include <linux/init.h>
38 #include <linux/console.h>
39 #include <linux/sysrq.h>
40 #include <linux/serial.h>
41 #include <linux/delay.h>
47 #define BAUD_RATE 115200
49 #include <linux/serial_core.h>
50 #include "m32r_sio_reg.h"
52 #define PASS_LIMIT 256
54 /* Standard COM flags */
55 #define STD_COM_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST)
60 } old_serial_port[] = {
61 #if defined(CONFIG_PLAT_USRV)
63 { 0x3F8, PLD_IRQ_UART0 }, /* ttyS0 */
64 { 0x2F8, PLD_IRQ_UART1 }, /* ttyS1 */
65 #elif defined(CONFIG_SERIAL_M32R_PLDSIO)
66 { ((unsigned long)PLD_ESIO0CR), PLD_IRQ_SIO0_RCV }, /* ttyS0 */
68 { M32R_SIO_OFFSET, M32R_IRQ_SIO0_R }, /* ttyS0 */
72 #define UART_NR ARRAY_SIZE(old_serial_port)
74 struct uart_sio_port {
75 struct uart_port port;
76 struct timer_list timer; /* "no irq" timer */
77 struct list_head list; /* ports on this IRQ */
82 unsigned char mcr_mask; /* mask of user bits */
83 unsigned char mcr_force; /* mask of forced bits */
84 unsigned char lsr_break_flag;
87 * We provide a per-port pm hook.
89 void (*pm)(struct uart_port *port,
90 unsigned int state, unsigned int old);
95 struct list_head *head;
98 static struct irq_info irq_lists[NR_IRQS];
100 #ifdef CONFIG_SERIAL_M32R_PLDSIO
102 #define __sio_in(x) inw((unsigned long)(x))
103 #define __sio_out(v,x) outw((v),(unsigned long)(x))
105 static inline void sio_set_baud_rate(unsigned long baud)
107 unsigned short sbaud;
108 sbaud = (boot_cpu_data.bus_clock / (baud * 4))-1;
109 __sio_out(sbaud, PLD_ESIO0BAUR);
112 static void sio_reset(void)
116 tmp = __sio_in(PLD_ESIO0RXB);
117 tmp = __sio_in(PLD_ESIO0RXB);
118 tmp = __sio_in(PLD_ESIO0CR);
119 sio_set_baud_rate(BAUD_RATE);
120 __sio_out(0x0300, PLD_ESIO0CR);
121 __sio_out(0x0003, PLD_ESIO0CR);
124 static void sio_init(void)
128 tmp = __sio_in(PLD_ESIO0RXB);
129 tmp = __sio_in(PLD_ESIO0RXB);
130 tmp = __sio_in(PLD_ESIO0CR);
131 __sio_out(0x0300, PLD_ESIO0CR);
132 __sio_out(0x0003, PLD_ESIO0CR);
135 static void sio_error(int *status)
137 printk("SIO0 error[%04x]\n", *status);
140 } while ((*status = __sio_in(PLD_ESIO0CR)) != 3);
143 #else /* not CONFIG_SERIAL_M32R_PLDSIO */
145 #define __sio_in(x) inl(x)
146 #define __sio_out(v,x) outl((v),(x))
148 static inline void sio_set_baud_rate(unsigned long baud)
152 i = boot_cpu_data.bus_clock / (baud * 16);
153 j = (boot_cpu_data.bus_clock - (i * baud * 16)) / baud;
157 __sio_out(i, M32R_SIO0_BAUR_PORTL);
158 __sio_out(j, M32R_SIO0_RBAUR_PORTL);
161 static void sio_reset(void)
163 __sio_out(0x00000300, M32R_SIO0_CR_PORTL); /* init status */
164 __sio_out(0x00000800, M32R_SIO0_MOD1_PORTL); /* 8bit */
165 __sio_out(0x00000080, M32R_SIO0_MOD0_PORTL); /* 1stop non */
166 sio_set_baud_rate(BAUD_RATE);
167 __sio_out(0x00000000, M32R_SIO0_TRCR_PORTL);
168 __sio_out(0x00000003, M32R_SIO0_CR_PORTL); /* RXCEN */
171 static void sio_init(void)
175 tmp = __sio_in(M32R_SIO0_RXB_PORTL);
176 tmp = __sio_in(M32R_SIO0_RXB_PORTL);
177 tmp = __sio_in(M32R_SIO0_STS_PORTL);
178 __sio_out(0x00000003, M32R_SIO0_CR_PORTL);
181 static void sio_error(int *status)
183 printk("SIO0 error[%04x]\n", *status);
186 } while ((*status = __sio_in(M32R_SIO0_CR_PORTL)) != 3);
189 #endif /* CONFIG_SERIAL_M32R_PLDSIO */
191 static unsigned int sio_in(struct uart_sio_port *up, int offset)
193 return __sio_in(up->port.iobase + offset);
196 static void sio_out(struct uart_sio_port *up, int offset, int value)
198 __sio_out(value, up->port.iobase + offset);
201 static unsigned int serial_in(struct uart_sio_port *up, int offset)
206 return __sio_in(offset);
209 static void serial_out(struct uart_sio_port *up, int offset, int value)
214 __sio_out(value, offset);
217 static void m32r_sio_stop_tx(struct uart_port *port)
219 struct uart_sio_port *up =
220 container_of(port, struct uart_sio_port, port);
222 if (up->ier & UART_IER_THRI) {
223 up->ier &= ~UART_IER_THRI;
224 serial_out(up, UART_IER, up->ier);
228 static void m32r_sio_start_tx(struct uart_port *port)
230 #ifdef CONFIG_SERIAL_M32R_PLDSIO
231 struct uart_sio_port *up =
232 container_of(port, struct uart_sio_port, port);
233 struct circ_buf *xmit = &up->port.state->xmit;
235 if (!(up->ier & UART_IER_THRI)) {
236 up->ier |= UART_IER_THRI;
237 serial_out(up, UART_IER, up->ier);
238 if (!uart_circ_empty(xmit)) {
239 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
240 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
241 up->port.icount.tx++;
244 while((serial_in(up, UART_LSR) & UART_EMPTY) != UART_EMPTY);
246 struct uart_sio_port *up =
247 container_of(port, struct uart_sio_port, port);
249 if (!(up->ier & UART_IER_THRI)) {
250 up->ier |= UART_IER_THRI;
251 serial_out(up, UART_IER, up->ier);
256 static void m32r_sio_stop_rx(struct uart_port *port)
258 struct uart_sio_port *up =
259 container_of(port, struct uart_sio_port, port);
261 up->ier &= ~UART_IER_RLSI;
262 up->port.read_status_mask &= ~UART_LSR_DR;
263 serial_out(up, UART_IER, up->ier);
266 static void m32r_sio_enable_ms(struct uart_port *port)
268 struct uart_sio_port *up =
269 container_of(port, struct uart_sio_port, port);
271 up->ier |= UART_IER_MSI;
272 serial_out(up, UART_IER, up->ier);
275 static void receive_chars(struct uart_sio_port *up, int *status)
277 struct tty_port *port = &up->port.state->port;
283 ch = sio_in(up, SIORXB);
285 up->port.icount.rx++;
287 if (unlikely(*status & (UART_LSR_BI | UART_LSR_PE |
288 UART_LSR_FE | UART_LSR_OE))) {
290 * For statistics only
292 if (*status & UART_LSR_BI) {
293 *status &= ~(UART_LSR_FE | UART_LSR_PE);
294 up->port.icount.brk++;
296 * We do the SysRQ and SAK checking
297 * here because otherwise the break
298 * may get masked by ignore_status_mask
299 * or read_status_mask.
301 if (uart_handle_break(&up->port))
303 } else if (*status & UART_LSR_PE)
304 up->port.icount.parity++;
305 else if (*status & UART_LSR_FE)
306 up->port.icount.frame++;
307 if (*status & UART_LSR_OE)
308 up->port.icount.overrun++;
311 * Mask off conditions which should be ingored.
313 *status &= up->port.read_status_mask;
315 if (up->port.line == up->port.cons->index) {
316 /* Recover the break flag from console xmit */
317 *status |= up->lsr_break_flag;
318 up->lsr_break_flag = 0;
321 if (*status & UART_LSR_BI) {
322 pr_debug("handling break....\n");
324 } else if (*status & UART_LSR_PE)
326 else if (*status & UART_LSR_FE)
329 if (uart_handle_sysrq_char(&up->port, ch))
331 if ((*status & up->port.ignore_status_mask) == 0)
332 tty_insert_flip_char(port, ch, flag);
334 if (*status & UART_LSR_OE) {
336 * Overrun is special, since it's reported
337 * immediately, and doesn't affect the current
340 tty_insert_flip_char(port, 0, TTY_OVERRUN);
343 *status = serial_in(up, UART_LSR);
344 } while ((*status & UART_LSR_DR) && (max_count-- > 0));
346 spin_unlock(&up->port.lock);
347 tty_flip_buffer_push(port);
348 spin_lock(&up->port.lock);
351 static void transmit_chars(struct uart_sio_port *up)
353 struct circ_buf *xmit = &up->port.state->xmit;
356 if (up->port.x_char) {
357 #ifndef CONFIG_SERIAL_M32R_PLDSIO /* XXX */
358 serial_out(up, UART_TX, up->port.x_char);
360 up->port.icount.tx++;
364 if (uart_circ_empty(xmit) || uart_tx_stopped(&up->port)) {
365 m32r_sio_stop_tx(&up->port);
369 count = up->port.fifosize;
371 serial_out(up, UART_TX, xmit->buf[xmit->tail]);
372 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
373 up->port.icount.tx++;
374 if (uart_circ_empty(xmit))
376 while (!(serial_in(up, UART_LSR) & UART_LSR_THRE));
378 } while (--count > 0);
380 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
381 uart_write_wakeup(&up->port);
383 pr_debug("THRE...\n");
385 if (uart_circ_empty(xmit))
386 m32r_sio_stop_tx(&up->port);
390 * This handles the interrupt from one port.
392 static inline void m32r_sio_handle_port(struct uart_sio_port *up,
395 pr_debug("status = %x...\n", status);
398 receive_chars(up, &status);
404 * This is the serial driver's interrupt routine.
406 * Arjan thinks the old way was overly complex, so it got simplified.
407 * Alan disagrees, saying that need the complexity to handle the weird
408 * nature of ISA shared interrupts. (This is a special exception.)
410 * In order to handle ISA shared interrupts properly, we need to check
411 * that all ports have been serviced, and therefore the ISA interrupt
412 * line has been de-asserted.
414 * This means we need to loop through all ports. checking that they
415 * don't have an interrupt pending.
417 static irqreturn_t m32r_sio_interrupt(int irq, void *dev_id)
419 struct irq_info *i = dev_id;
420 struct list_head *l, *end = NULL;
421 int pass_counter = 0;
423 pr_debug("m32r_sio_interrupt(%d)...\n", irq);
425 #ifdef CONFIG_SERIAL_M32R_PLDSIO
426 // if (irq == PLD_IRQ_SIO0_SND)
427 // irq = PLD_IRQ_SIO0_RCV;
429 if (irq == M32R_IRQ_SIO0_S)
430 irq = M32R_IRQ_SIO0_R;
437 struct uart_sio_port *up;
440 up = list_entry(l, struct uart_sio_port, list);
442 sts = sio_in(up, SIOSTS);
444 spin_lock(&up->port.lock);
445 m32r_sio_handle_port(up, sts);
446 spin_unlock(&up->port.lock);
449 } else if (end == NULL)
454 if (l == i->head && pass_counter++ > PASS_LIMIT) {
461 spin_unlock(&i->lock);
469 * To support ISA shared interrupts, we need to have one interrupt
470 * handler that ensures that the IRQ line has been deasserted
471 * before returning. Failing to do this will result in the IRQ
472 * line being stuck active, and, since ISA irqs are edge triggered,
473 * no more IRQs will be seen.
475 static void serial_do_unlink(struct irq_info *i, struct uart_sio_port *up)
477 spin_lock_irq(&i->lock);
479 if (!list_empty(i->head)) {
480 if (i->head == &up->list)
481 i->head = i->head->next;
484 BUG_ON(i->head != &up->list);
488 spin_unlock_irq(&i->lock);
491 static int serial_link_irq_chain(struct uart_sio_port *up)
493 struct irq_info *i = irq_lists + up->port.irq;
494 int ret, irq_flags = 0;
496 spin_lock_irq(&i->lock);
499 list_add(&up->list, i->head);
500 spin_unlock_irq(&i->lock);
504 INIT_LIST_HEAD(&up->list);
506 spin_unlock_irq(&i->lock);
508 ret = request_irq(up->port.irq, m32r_sio_interrupt,
509 irq_flags, "SIO0-RX", i);
510 ret |= request_irq(up->port.irq + 1, m32r_sio_interrupt,
511 irq_flags, "SIO0-TX", i);
513 serial_do_unlink(i, up);
519 static void serial_unlink_irq_chain(struct uart_sio_port *up)
521 struct irq_info *i = irq_lists + up->port.irq;
523 BUG_ON(i->head == NULL);
525 if (list_empty(i->head)) {
526 free_irq(up->port.irq, i);
527 free_irq(up->port.irq + 1, i);
530 serial_do_unlink(i, up);
534 * This function is used to handle ports that do not have an interrupt.
536 static void m32r_sio_timeout(unsigned long data)
538 struct uart_sio_port *up = (struct uart_sio_port *)data;
539 unsigned int timeout;
542 sts = sio_in(up, SIOSTS);
544 spin_lock(&up->port.lock);
545 m32r_sio_handle_port(up, sts);
546 spin_unlock(&up->port.lock);
549 timeout = up->port.timeout;
550 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
551 mod_timer(&up->timer, jiffies + timeout);
554 static unsigned int m32r_sio_tx_empty(struct uart_port *port)
556 struct uart_sio_port *up =
557 container_of(port, struct uart_sio_port, port);
561 spin_lock_irqsave(&up->port.lock, flags);
562 ret = serial_in(up, UART_LSR) & UART_LSR_TEMT ? TIOCSER_TEMT : 0;
563 spin_unlock_irqrestore(&up->port.lock, flags);
568 static unsigned int m32r_sio_get_mctrl(struct uart_port *port)
573 static void m32r_sio_set_mctrl(struct uart_port *port, unsigned int mctrl)
578 static void m32r_sio_break_ctl(struct uart_port *port, int break_state)
583 static int m32r_sio_startup(struct uart_port *port)
585 struct uart_sio_port *up =
586 container_of(port, struct uart_sio_port, port);
592 * If the "interrupt" for this port doesn't correspond with any
593 * hardware interrupt, we use a timer-based system. The original
594 * driver used to do this with IRQ0.
597 unsigned int timeout = up->port.timeout;
599 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
601 up->timer.data = (unsigned long)up;
602 mod_timer(&up->timer, jiffies + timeout);
604 retval = serial_link_irq_chain(up);
610 * Finally, enable interrupts. Note: Modem status interrupts
611 * are set via set_termios(), which will be occurring imminently
612 * anyway, so we don't enable them here.
614 * - M32R_PLDSIO: 0x04
616 up->ier = UART_IER_MSI | UART_IER_RLSI | UART_IER_RDI;
617 sio_out(up, SIOTRCR, up->ier);
620 * And clear the interrupt registers again for luck.
627 static void m32r_sio_shutdown(struct uart_port *port)
629 struct uart_sio_port *up =
630 container_of(port, struct uart_sio_port, port);
633 * Disable interrupts from this port
636 sio_out(up, SIOTRCR, 0);
639 * Disable break condition and FIFOs
645 del_timer_sync(&up->timer);
647 serial_unlink_irq_chain(up);
650 static unsigned int m32r_sio_get_divisor(struct uart_port *port,
653 return uart_get_divisor(port, baud);
656 static void m32r_sio_set_termios(struct uart_port *port,
657 struct ktermios *termios, struct ktermios *old)
659 struct uart_sio_port *up =
660 container_of(port, struct uart_sio_port, port);
661 unsigned char cval = 0;
663 unsigned int baud, quot;
665 switch (termios->c_cflag & CSIZE) {
667 cval = UART_LCR_WLEN5;
670 cval = UART_LCR_WLEN6;
673 cval = UART_LCR_WLEN7;
677 cval = UART_LCR_WLEN8;
681 if (termios->c_cflag & CSTOPB)
682 cval |= UART_LCR_STOP;
683 if (termios->c_cflag & PARENB)
684 cval |= UART_LCR_PARITY;
685 if (!(termios->c_cflag & PARODD))
686 cval |= UART_LCR_EPAR;
688 if (termios->c_cflag & CMSPAR)
689 cval |= UART_LCR_SPAR;
693 * Ask the core to calculate the divisor for us.
695 #ifdef CONFIG_SERIAL_M32R_PLDSIO
696 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/4);
698 baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
700 quot = m32r_sio_get_divisor(port, baud);
703 * Ok, we're now changing the port state. Do it with
704 * interrupts disabled.
706 spin_lock_irqsave(&up->port.lock, flags);
708 sio_set_baud_rate(baud);
711 * Update the per-port timeout.
713 uart_update_timeout(port, termios->c_cflag, baud);
715 up->port.read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
716 if (termios->c_iflag & INPCK)
717 up->port.read_status_mask |= UART_LSR_FE | UART_LSR_PE;
718 if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
719 up->port.read_status_mask |= UART_LSR_BI;
722 * Characteres to ignore
724 up->port.ignore_status_mask = 0;
725 if (termios->c_iflag & IGNPAR)
726 up->port.ignore_status_mask |= UART_LSR_PE | UART_LSR_FE;
727 if (termios->c_iflag & IGNBRK) {
728 up->port.ignore_status_mask |= UART_LSR_BI;
730 * If we're ignoring parity and break indicators,
731 * ignore overruns too (for real raw support).
733 if (termios->c_iflag & IGNPAR)
734 up->port.ignore_status_mask |= UART_LSR_OE;
738 * ignore all characters if CREAD is not set
740 if ((termios->c_cflag & CREAD) == 0)
741 up->port.ignore_status_mask |= UART_LSR_DR;
744 * CTS flow control flag and modem status interrupts
746 up->ier &= ~UART_IER_MSI;
747 if (UART_ENABLE_MS(&up->port, termios->c_cflag))
748 up->ier |= UART_IER_MSI;
750 serial_out(up, UART_IER, up->ier);
752 up->lcr = cval; /* Save LCR */
753 spin_unlock_irqrestore(&up->port.lock, flags);
756 static void m32r_sio_pm(struct uart_port *port, unsigned int state,
757 unsigned int oldstate)
759 struct uart_sio_port *up =
760 container_of(port, struct uart_sio_port, port);
763 up->pm(port, state, oldstate);
767 * Resource handling. This is complicated by the fact that resources
768 * depend on the port type. Maybe we should be claiming the standard
769 * 8250 ports, and then trying to get other resources as necessary?
772 m32r_sio_request_std_resource(struct uart_sio_port *up, struct resource **res)
774 unsigned int size = 8 << up->port.regshift;
775 #ifndef CONFIG_SERIAL_M32R_PLDSIO
780 switch (up->port.iotype) {
782 if (up->port.mapbase) {
783 #ifdef CONFIG_SERIAL_M32R_PLDSIO
784 *res = request_mem_region(up->port.mapbase, size, "serial");
786 start = up->port.mapbase;
787 *res = request_mem_region(start, size, "serial");
795 *res = request_region(up->port.iobase, size, "serial");
803 static void m32r_sio_release_port(struct uart_port *port)
805 struct uart_sio_port *up =
806 container_of(port, struct uart_sio_port, port);
807 unsigned long start, offset = 0, size = 0;
809 size <<= up->port.regshift;
811 switch (up->port.iotype) {
813 if (up->port.mapbase) {
817 iounmap(up->port.membase);
818 up->port.membase = NULL;
820 start = up->port.mapbase;
823 release_mem_region(start + offset, size);
824 release_mem_region(start, 8 << up->port.regshift);
829 start = up->port.iobase;
832 release_region(start + offset, size);
833 release_region(start + offset, 8 << up->port.regshift);
841 static int m32r_sio_request_port(struct uart_port *port)
843 struct uart_sio_port *up =
844 container_of(port, struct uart_sio_port, port);
845 struct resource *res = NULL;
848 ret = m32r_sio_request_std_resource(up, &res);
851 * If we have a mapbase, then request that as well.
853 if (ret == 0 && up->port.flags & UPF_IOREMAP) {
854 int size = resource_size(res);
856 up->port.membase = ioremap(up->port.mapbase, size);
857 if (!up->port.membase)
863 release_resource(res);
869 static void m32r_sio_config_port(struct uart_port *port, int unused)
871 struct uart_sio_port *up =
872 container_of(port, struct uart_sio_port, port);
875 spin_lock_irqsave(&up->port.lock, flags);
877 up->port.fifosize = 1;
879 spin_unlock_irqrestore(&up->port.lock, flags);
883 m32r_sio_verify_port(struct uart_port *port, struct serial_struct *ser)
885 if (ser->irq >= nr_irqs || ser->irq < 0 || ser->baud_base < 9600)
890 static struct uart_ops m32r_sio_pops = {
891 .tx_empty = m32r_sio_tx_empty,
892 .set_mctrl = m32r_sio_set_mctrl,
893 .get_mctrl = m32r_sio_get_mctrl,
894 .stop_tx = m32r_sio_stop_tx,
895 .start_tx = m32r_sio_start_tx,
896 .stop_rx = m32r_sio_stop_rx,
897 .enable_ms = m32r_sio_enable_ms,
898 .break_ctl = m32r_sio_break_ctl,
899 .startup = m32r_sio_startup,
900 .shutdown = m32r_sio_shutdown,
901 .set_termios = m32r_sio_set_termios,
903 .release_port = m32r_sio_release_port,
904 .request_port = m32r_sio_request_port,
905 .config_port = m32r_sio_config_port,
906 .verify_port = m32r_sio_verify_port,
909 static struct uart_sio_port m32r_sio_ports[UART_NR];
911 static void __init m32r_sio_init_ports(void)
913 struct uart_sio_port *up;
914 static int first = 1;
921 for (i = 0, up = m32r_sio_ports; i < UART_NR; i++, up++) {
922 up->port.iobase = old_serial_port[i].port;
923 up->port.irq = irq_canonicalize(old_serial_port[i].irq);
924 up->port.uartclk = BAUD_RATE * 16;
925 up->port.flags = STD_COM_FLAGS;
926 up->port.membase = 0;
928 up->port.regshift = 0;
929 up->port.ops = &m32r_sio_pops;
933 static void __init m32r_sio_register_ports(struct uart_driver *drv)
937 m32r_sio_init_ports();
939 for (i = 0; i < UART_NR; i++) {
940 struct uart_sio_port *up = &m32r_sio_ports[i];
943 up->port.ops = &m32r_sio_pops;
944 init_timer(&up->timer);
945 up->timer.function = m32r_sio_timeout;
950 uart_add_one_port(drv, &up->port);
954 #ifdef CONFIG_SERIAL_M32R_SIO_CONSOLE
957 * Wait for transmitter & holding register to empty
959 static void wait_for_xmitr(struct uart_sio_port *up)
961 unsigned int status, tmout = 10000;
963 /* Wait up to 10ms for the character(s) to be sent. */
965 status = sio_in(up, SIOSTS);
970 } while ((status & UART_EMPTY) != UART_EMPTY);
972 /* Wait up to 1s for flow control if necessary */
973 if (up->port.flags & UPF_CONS_FLOW) {
980 static void m32r_sio_console_putchar(struct uart_port *port, int ch)
982 struct uart_sio_port *up =
983 container_of(port, struct uart_sio_port, port);
986 sio_out(up, SIOTXB, ch);
990 * Print a string to the serial port trying not to disturb
991 * any possible real use of the port...
993 * The console_lock must be held when we get here.
995 static void m32r_sio_console_write(struct console *co, const char *s,
998 struct uart_sio_port *up = &m32r_sio_ports[co->index];
1002 * First save the UER then disable the interrupts
1004 ier = sio_in(up, SIOTRCR);
1005 sio_out(up, SIOTRCR, 0);
1007 uart_console_write(&up->port, s, count, m32r_sio_console_putchar);
1010 * Finally, wait for transmitter to become empty
1011 * and restore the IER
1014 sio_out(up, SIOTRCR, ier);
1017 static int __init m32r_sio_console_setup(struct console *co, char *options)
1019 struct uart_port *port;
1026 * Check whether an invalid uart number has been specified, and
1027 * if so, search for the first available port that does have
1030 if (co->index >= UART_NR)
1032 port = &m32r_sio_ports[co->index].port;
1037 spin_lock_init(&port->lock);
1040 uart_parse_options(options, &baud, &parity, &bits, &flow);
1042 return uart_set_options(port, co, baud, parity, bits, flow);
1045 static struct uart_driver m32r_sio_reg;
1046 static struct console m32r_sio_console = {
1048 .write = m32r_sio_console_write,
1049 .device = uart_console_device,
1050 .setup = m32r_sio_console_setup,
1051 .flags = CON_PRINTBUFFER,
1053 .data = &m32r_sio_reg,
1056 static int __init m32r_sio_console_init(void)
1060 m32r_sio_init_ports();
1061 register_console(&m32r_sio_console);
1064 console_initcall(m32r_sio_console_init);
1066 #define M32R_SIO_CONSOLE &m32r_sio_console
1068 #define M32R_SIO_CONSOLE NULL
1071 static struct uart_driver m32r_sio_reg = {
1072 .owner = THIS_MODULE,
1073 .driver_name = "sio",
1078 .cons = M32R_SIO_CONSOLE,
1081 static int __init m32r_sio_init(void)
1085 printk(KERN_INFO "Serial: M32R SIO driver\n");
1087 for (i = 0; i < nr_irqs; i++)
1088 spin_lock_init(&irq_lists[i].lock);
1090 ret = uart_register_driver(&m32r_sio_reg);
1092 m32r_sio_register_ports(&m32r_sio_reg);
1097 static void __exit m32r_sio_exit(void)
1101 for (i = 0; i < UART_NR; i++)
1102 uart_remove_one_port(&m32r_sio_reg, &m32r_sio_ports[i].port);
1104 uart_unregister_driver(&m32r_sio_reg);
1107 module_init(m32r_sio_init);
1108 module_exit(m32r_sio_exit);
1110 MODULE_LICENSE("GPL");
1111 MODULE_DESCRIPTION("Generic M32R SIO serial driver");