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 */
83 struct list_head
*head
;
86 static struct irq_info irq_lists
[NR_IRQS
];
88 #ifdef CONFIG_SERIAL_M32R_PLDSIO
90 #define __sio_in(x) inw((unsigned long)(x))
91 #define __sio_out(v,x) outw((v),(unsigned long)(x))
93 static inline void sio_set_baud_rate(unsigned long baud
)
96 sbaud
= (boot_cpu_data
.bus_clock
/ (baud
* 4))-1;
97 __sio_out(sbaud
, PLD_ESIO0BAUR
);
100 static void sio_reset(void)
104 tmp
= __sio_in(PLD_ESIO0RXB
);
105 tmp
= __sio_in(PLD_ESIO0RXB
);
106 tmp
= __sio_in(PLD_ESIO0CR
);
107 sio_set_baud_rate(BAUD_RATE
);
108 __sio_out(0x0300, PLD_ESIO0CR
);
109 __sio_out(0x0003, PLD_ESIO0CR
);
112 static void sio_init(void)
116 tmp
= __sio_in(PLD_ESIO0RXB
);
117 tmp
= __sio_in(PLD_ESIO0RXB
);
118 tmp
= __sio_in(PLD_ESIO0CR
);
119 __sio_out(0x0300, PLD_ESIO0CR
);
120 __sio_out(0x0003, PLD_ESIO0CR
);
123 static void sio_error(int *status
)
125 printk("SIO0 error[%04x]\n", *status
);
128 } while ((*status
= __sio_in(PLD_ESIO0CR
)) != 3);
131 #else /* not CONFIG_SERIAL_M32R_PLDSIO */
133 #define __sio_in(x) inl(x)
134 #define __sio_out(v,x) outl((v),(x))
136 static inline void sio_set_baud_rate(unsigned long baud
)
140 i
= boot_cpu_data
.bus_clock
/ (baud
* 16);
141 j
= (boot_cpu_data
.bus_clock
- (i
* baud
* 16)) / baud
;
145 __sio_out(i
, M32R_SIO0_BAUR_PORTL
);
146 __sio_out(j
, M32R_SIO0_RBAUR_PORTL
);
149 static void sio_reset(void)
151 __sio_out(0x00000300, M32R_SIO0_CR_PORTL
); /* init status */
152 __sio_out(0x00000800, M32R_SIO0_MOD1_PORTL
); /* 8bit */
153 __sio_out(0x00000080, M32R_SIO0_MOD0_PORTL
); /* 1stop non */
154 sio_set_baud_rate(BAUD_RATE
);
155 __sio_out(0x00000000, M32R_SIO0_TRCR_PORTL
);
156 __sio_out(0x00000003, M32R_SIO0_CR_PORTL
); /* RXCEN */
159 static void sio_init(void)
163 tmp
= __sio_in(M32R_SIO0_RXB_PORTL
);
164 tmp
= __sio_in(M32R_SIO0_RXB_PORTL
);
165 tmp
= __sio_in(M32R_SIO0_STS_PORTL
);
166 __sio_out(0x00000003, M32R_SIO0_CR_PORTL
);
169 static void sio_error(int *status
)
171 printk("SIO0 error[%04x]\n", *status
);
174 } while ((*status
= __sio_in(M32R_SIO0_CR_PORTL
)) != 3);
177 #endif /* CONFIG_SERIAL_M32R_PLDSIO */
179 static unsigned int sio_in(struct uart_sio_port
*up
, int offset
)
181 return __sio_in(up
->port
.iobase
+ offset
);
184 static void sio_out(struct uart_sio_port
*up
, int offset
, int value
)
186 __sio_out(value
, up
->port
.iobase
+ offset
);
189 static unsigned int serial_in(struct uart_sio_port
*up
, int offset
)
194 return __sio_in(offset
);
197 static void serial_out(struct uart_sio_port
*up
, int offset
, int value
)
202 __sio_out(value
, offset
);
205 static void m32r_sio_stop_tx(struct uart_port
*port
)
207 struct uart_sio_port
*up
=
208 container_of(port
, struct uart_sio_port
, port
);
210 if (up
->ier
& UART_IER_THRI
) {
211 up
->ier
&= ~UART_IER_THRI
;
212 serial_out(up
, UART_IER
, up
->ier
);
216 static void m32r_sio_start_tx(struct uart_port
*port
)
218 #ifdef CONFIG_SERIAL_M32R_PLDSIO
219 struct uart_sio_port
*up
=
220 container_of(port
, struct uart_sio_port
, port
);
221 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
223 if (!(up
->ier
& UART_IER_THRI
)) {
224 up
->ier
|= UART_IER_THRI
;
225 serial_out(up
, UART_IER
, up
->ier
);
226 if (!uart_circ_empty(xmit
)) {
227 serial_out(up
, UART_TX
, xmit
->buf
[xmit
->tail
]);
228 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
229 up
->port
.icount
.tx
++;
232 while((serial_in(up
, UART_LSR
) & UART_EMPTY
) != UART_EMPTY
);
234 struct uart_sio_port
*up
=
235 container_of(port
, struct uart_sio_port
, port
);
237 if (!(up
->ier
& UART_IER_THRI
)) {
238 up
->ier
|= UART_IER_THRI
;
239 serial_out(up
, UART_IER
, up
->ier
);
244 static void m32r_sio_stop_rx(struct uart_port
*port
)
246 struct uart_sio_port
*up
=
247 container_of(port
, struct uart_sio_port
, port
);
249 up
->ier
&= ~UART_IER_RLSI
;
250 up
->port
.read_status_mask
&= ~UART_LSR_DR
;
251 serial_out(up
, UART_IER
, up
->ier
);
254 static void m32r_sio_enable_ms(struct uart_port
*port
)
256 struct uart_sio_port
*up
=
257 container_of(port
, struct uart_sio_port
, port
);
259 up
->ier
|= UART_IER_MSI
;
260 serial_out(up
, UART_IER
, up
->ier
);
263 static void receive_chars(struct uart_sio_port
*up
, int *status
)
265 struct tty_port
*port
= &up
->port
.state
->port
;
271 ch
= sio_in(up
, SIORXB
);
273 up
->port
.icount
.rx
++;
275 if (unlikely(*status
& (UART_LSR_BI
| UART_LSR_PE
|
276 UART_LSR_FE
| UART_LSR_OE
))) {
278 * For statistics only
280 if (*status
& UART_LSR_BI
) {
281 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
282 up
->port
.icount
.brk
++;
284 * We do the SysRQ and SAK checking
285 * here because otherwise the break
286 * may get masked by ignore_status_mask
287 * or read_status_mask.
289 if (uart_handle_break(&up
->port
))
291 } else if (*status
& UART_LSR_PE
)
292 up
->port
.icount
.parity
++;
293 else if (*status
& UART_LSR_FE
)
294 up
->port
.icount
.frame
++;
295 if (*status
& UART_LSR_OE
)
296 up
->port
.icount
.overrun
++;
299 * Mask off conditions which should be ingored.
301 *status
&= up
->port
.read_status_mask
;
303 if (*status
& UART_LSR_BI
) {
304 pr_debug("handling break....\n");
306 } else if (*status
& UART_LSR_PE
)
308 else if (*status
& UART_LSR_FE
)
311 if (uart_handle_sysrq_char(&up
->port
, ch
))
313 if ((*status
& up
->port
.ignore_status_mask
) == 0)
314 tty_insert_flip_char(port
, ch
, flag
);
316 if (*status
& UART_LSR_OE
) {
318 * Overrun is special, since it's reported
319 * immediately, and doesn't affect the current
322 tty_insert_flip_char(port
, 0, TTY_OVERRUN
);
325 *status
= serial_in(up
, UART_LSR
);
326 } while ((*status
& UART_LSR_DR
) && (max_count
-- > 0));
328 spin_unlock(&up
->port
.lock
);
329 tty_flip_buffer_push(port
);
330 spin_lock(&up
->port
.lock
);
333 static void transmit_chars(struct uart_sio_port
*up
)
335 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
338 if (up
->port
.x_char
) {
339 #ifndef CONFIG_SERIAL_M32R_PLDSIO /* XXX */
340 serial_out(up
, UART_TX
, up
->port
.x_char
);
342 up
->port
.icount
.tx
++;
346 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
347 m32r_sio_stop_tx(&up
->port
);
351 count
= up
->port
.fifosize
;
353 serial_out(up
, UART_TX
, xmit
->buf
[xmit
->tail
]);
354 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
355 up
->port
.icount
.tx
++;
356 if (uart_circ_empty(xmit
))
358 while (!(serial_in(up
, UART_LSR
) & UART_LSR_THRE
));
360 } while (--count
> 0);
362 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
363 uart_write_wakeup(&up
->port
);
365 pr_debug("THRE...\n");
367 if (uart_circ_empty(xmit
))
368 m32r_sio_stop_tx(&up
->port
);
372 * This handles the interrupt from one port.
374 static inline void m32r_sio_handle_port(struct uart_sio_port
*up
,
377 pr_debug("status = %x...\n", status
);
380 receive_chars(up
, &status
);
386 * This is the serial driver's interrupt routine.
388 * Arjan thinks the old way was overly complex, so it got simplified.
389 * Alan disagrees, saying that need the complexity to handle the weird
390 * nature of ISA shared interrupts. (This is a special exception.)
392 * In order to handle ISA shared interrupts properly, we need to check
393 * that all ports have been serviced, and therefore the ISA interrupt
394 * line has been de-asserted.
396 * This means we need to loop through all ports. checking that they
397 * don't have an interrupt pending.
399 static irqreturn_t
m32r_sio_interrupt(int irq
, void *dev_id
)
401 struct irq_info
*i
= dev_id
;
402 struct list_head
*l
, *end
= NULL
;
403 int pass_counter
= 0;
405 pr_debug("m32r_sio_interrupt(%d)...\n", irq
);
407 #ifdef CONFIG_SERIAL_M32R_PLDSIO
408 // if (irq == PLD_IRQ_SIO0_SND)
409 // irq = PLD_IRQ_SIO0_RCV;
411 if (irq
== M32R_IRQ_SIO0_S
)
412 irq
= M32R_IRQ_SIO0_R
;
419 struct uart_sio_port
*up
;
422 up
= list_entry(l
, struct uart_sio_port
, list
);
424 sts
= sio_in(up
, SIOSTS
);
426 spin_lock(&up
->port
.lock
);
427 m32r_sio_handle_port(up
, sts
);
428 spin_unlock(&up
->port
.lock
);
431 } else if (end
== NULL
)
436 if (l
== i
->head
&& pass_counter
++ > PASS_LIMIT
) {
443 spin_unlock(&i
->lock
);
451 * To support ISA shared interrupts, we need to have one interrupt
452 * handler that ensures that the IRQ line has been deasserted
453 * before returning. Failing to do this will result in the IRQ
454 * line being stuck active, and, since ISA irqs are edge triggered,
455 * no more IRQs will be seen.
457 static void serial_do_unlink(struct irq_info
*i
, struct uart_sio_port
*up
)
459 spin_lock_irq(&i
->lock
);
461 if (!list_empty(i
->head
)) {
462 if (i
->head
== &up
->list
)
463 i
->head
= i
->head
->next
;
466 BUG_ON(i
->head
!= &up
->list
);
470 spin_unlock_irq(&i
->lock
);
473 static int serial_link_irq_chain(struct uart_sio_port
*up
)
475 struct irq_info
*i
= irq_lists
+ up
->port
.irq
;
476 int ret
, irq_flags
= 0;
478 spin_lock_irq(&i
->lock
);
481 list_add(&up
->list
, i
->head
);
482 spin_unlock_irq(&i
->lock
);
486 INIT_LIST_HEAD(&up
->list
);
488 spin_unlock_irq(&i
->lock
);
490 ret
= request_irq(up
->port
.irq
, m32r_sio_interrupt
,
491 irq_flags
, "SIO0-RX", i
);
492 ret
|= request_irq(up
->port
.irq
+ 1, m32r_sio_interrupt
,
493 irq_flags
, "SIO0-TX", i
);
495 serial_do_unlink(i
, up
);
501 static void serial_unlink_irq_chain(struct uart_sio_port
*up
)
503 struct irq_info
*i
= irq_lists
+ up
->port
.irq
;
505 BUG_ON(i
->head
== NULL
);
507 if (list_empty(i
->head
)) {
508 free_irq(up
->port
.irq
, i
);
509 free_irq(up
->port
.irq
+ 1, i
);
512 serial_do_unlink(i
, up
);
516 * This function is used to handle ports that do not have an interrupt.
518 static void m32r_sio_timeout(unsigned long data
)
520 struct uart_sio_port
*up
= (struct uart_sio_port
*)data
;
521 unsigned int timeout
;
524 sts
= sio_in(up
, SIOSTS
);
526 spin_lock(&up
->port
.lock
);
527 m32r_sio_handle_port(up
, sts
);
528 spin_unlock(&up
->port
.lock
);
531 timeout
= up
->port
.timeout
;
532 timeout
= timeout
> 6 ? (timeout
/ 2 - 2) : 1;
533 mod_timer(&up
->timer
, jiffies
+ timeout
);
536 static unsigned int m32r_sio_tx_empty(struct uart_port
*port
)
538 struct uart_sio_port
*up
=
539 container_of(port
, struct uart_sio_port
, port
);
543 spin_lock_irqsave(&up
->port
.lock
, flags
);
544 ret
= serial_in(up
, UART_LSR
) & UART_LSR_TEMT
? TIOCSER_TEMT
: 0;
545 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
550 static unsigned int m32r_sio_get_mctrl(struct uart_port
*port
)
555 static void m32r_sio_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
560 static void m32r_sio_break_ctl(struct uart_port
*port
, int break_state
)
565 static int m32r_sio_startup(struct uart_port
*port
)
567 struct uart_sio_port
*up
=
568 container_of(port
, struct uart_sio_port
, port
);
574 * If the "interrupt" for this port doesn't correspond with any
575 * hardware interrupt, we use a timer-based system. The original
576 * driver used to do this with IRQ0.
579 unsigned int timeout
= up
->port
.timeout
;
581 timeout
= timeout
> 6 ? (timeout
/ 2 - 2) : 1;
583 up
->timer
.data
= (unsigned long)up
;
584 mod_timer(&up
->timer
, jiffies
+ timeout
);
586 retval
= serial_link_irq_chain(up
);
592 * Finally, enable interrupts. Note: Modem status interrupts
593 * are set via set_termios(), which will be occurring imminently
594 * anyway, so we don't enable them here.
596 * - M32R_PLDSIO: 0x04
598 up
->ier
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
599 sio_out(up
, SIOTRCR
, up
->ier
);
602 * And clear the interrupt registers again for luck.
609 static void m32r_sio_shutdown(struct uart_port
*port
)
611 struct uart_sio_port
*up
=
612 container_of(port
, struct uart_sio_port
, port
);
615 * Disable interrupts from this port
618 sio_out(up
, SIOTRCR
, 0);
621 * Disable break condition and FIFOs
627 del_timer_sync(&up
->timer
);
629 serial_unlink_irq_chain(up
);
632 static unsigned int m32r_sio_get_divisor(struct uart_port
*port
,
635 return uart_get_divisor(port
, baud
);
638 static void m32r_sio_set_termios(struct uart_port
*port
,
639 struct ktermios
*termios
, struct ktermios
*old
)
641 struct uart_sio_port
*up
=
642 container_of(port
, struct uart_sio_port
, port
);
643 unsigned char cval
= 0;
645 unsigned int baud
, quot
;
647 switch (termios
->c_cflag
& CSIZE
) {
649 cval
= UART_LCR_WLEN5
;
652 cval
= UART_LCR_WLEN6
;
655 cval
= UART_LCR_WLEN7
;
659 cval
= UART_LCR_WLEN8
;
663 if (termios
->c_cflag
& CSTOPB
)
664 cval
|= UART_LCR_STOP
;
665 if (termios
->c_cflag
& PARENB
)
666 cval
|= UART_LCR_PARITY
;
667 if (!(termios
->c_cflag
& PARODD
))
668 cval
|= UART_LCR_EPAR
;
670 if (termios
->c_cflag
& CMSPAR
)
671 cval
|= UART_LCR_SPAR
;
675 * Ask the core to calculate the divisor for us.
677 #ifdef CONFIG_SERIAL_M32R_PLDSIO
678 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/4);
680 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
682 quot
= m32r_sio_get_divisor(port
, baud
);
685 * Ok, we're now changing the port state. Do it with
686 * interrupts disabled.
688 spin_lock_irqsave(&up
->port
.lock
, flags
);
690 sio_set_baud_rate(baud
);
693 * Update the per-port timeout.
695 uart_update_timeout(port
, termios
->c_cflag
, baud
);
697 up
->port
.read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
698 if (termios
->c_iflag
& INPCK
)
699 up
->port
.read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
700 if (termios
->c_iflag
& (IGNBRK
| BRKINT
| PARMRK
))
701 up
->port
.read_status_mask
|= UART_LSR_BI
;
704 * Characteres to ignore
706 up
->port
.ignore_status_mask
= 0;
707 if (termios
->c_iflag
& IGNPAR
)
708 up
->port
.ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
709 if (termios
->c_iflag
& IGNBRK
) {
710 up
->port
.ignore_status_mask
|= UART_LSR_BI
;
712 * If we're ignoring parity and break indicators,
713 * ignore overruns too (for real raw support).
715 if (termios
->c_iflag
& IGNPAR
)
716 up
->port
.ignore_status_mask
|= UART_LSR_OE
;
720 * ignore all characters if CREAD is not set
722 if ((termios
->c_cflag
& CREAD
) == 0)
723 up
->port
.ignore_status_mask
|= UART_LSR_DR
;
726 * CTS flow control flag and modem status interrupts
728 up
->ier
&= ~UART_IER_MSI
;
729 if (UART_ENABLE_MS(&up
->port
, termios
->c_cflag
))
730 up
->ier
|= UART_IER_MSI
;
732 serial_out(up
, UART_IER
, up
->ier
);
734 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
738 * Resource handling. This is complicated by the fact that resources
739 * depend on the port type. Maybe we should be claiming the standard
740 * 8250 ports, and then trying to get other resources as necessary?
743 m32r_sio_request_std_resource(struct uart_sio_port
*up
, struct resource
**res
)
745 unsigned int size
= 8 << up
->port
.regshift
;
746 #ifndef CONFIG_SERIAL_M32R_PLDSIO
751 switch (up
->port
.iotype
) {
753 if (up
->port
.mapbase
) {
754 #ifdef CONFIG_SERIAL_M32R_PLDSIO
755 *res
= request_mem_region(up
->port
.mapbase
, size
, "serial");
757 start
= up
->port
.mapbase
;
758 *res
= request_mem_region(start
, size
, "serial");
766 *res
= request_region(up
->port
.iobase
, size
, "serial");
774 static void m32r_sio_release_port(struct uart_port
*port
)
776 struct uart_sio_port
*up
=
777 container_of(port
, struct uart_sio_port
, port
);
778 unsigned long start
, offset
= 0, size
= 0;
780 size
<<= up
->port
.regshift
;
782 switch (up
->port
.iotype
) {
784 if (up
->port
.mapbase
) {
788 iounmap(up
->port
.membase
);
789 up
->port
.membase
= NULL
;
791 start
= up
->port
.mapbase
;
794 release_mem_region(start
+ offset
, size
);
795 release_mem_region(start
, 8 << up
->port
.regshift
);
800 start
= up
->port
.iobase
;
803 release_region(start
+ offset
, size
);
804 release_region(start
+ offset
, 8 << up
->port
.regshift
);
812 static int m32r_sio_request_port(struct uart_port
*port
)
814 struct uart_sio_port
*up
=
815 container_of(port
, struct uart_sio_port
, port
);
816 struct resource
*res
= NULL
;
819 ret
= m32r_sio_request_std_resource(up
, &res
);
822 * If we have a mapbase, then request that as well.
824 if (ret
== 0 && up
->port
.flags
& UPF_IOREMAP
) {
825 int size
= resource_size(res
);
827 up
->port
.membase
= ioremap(up
->port
.mapbase
, size
);
828 if (!up
->port
.membase
)
834 release_resource(res
);
840 static void m32r_sio_config_port(struct uart_port
*port
, int unused
)
842 struct uart_sio_port
*up
=
843 container_of(port
, struct uart_sio_port
, port
);
846 spin_lock_irqsave(&up
->port
.lock
, flags
);
848 up
->port
.fifosize
= 1;
850 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
854 m32r_sio_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
856 if (ser
->irq
>= nr_irqs
|| ser
->irq
< 0 || ser
->baud_base
< 9600)
861 static struct uart_ops m32r_sio_pops
= {
862 .tx_empty
= m32r_sio_tx_empty
,
863 .set_mctrl
= m32r_sio_set_mctrl
,
864 .get_mctrl
= m32r_sio_get_mctrl
,
865 .stop_tx
= m32r_sio_stop_tx
,
866 .start_tx
= m32r_sio_start_tx
,
867 .stop_rx
= m32r_sio_stop_rx
,
868 .enable_ms
= m32r_sio_enable_ms
,
869 .break_ctl
= m32r_sio_break_ctl
,
870 .startup
= m32r_sio_startup
,
871 .shutdown
= m32r_sio_shutdown
,
872 .set_termios
= m32r_sio_set_termios
,
873 .release_port
= m32r_sio_release_port
,
874 .request_port
= m32r_sio_request_port
,
875 .config_port
= m32r_sio_config_port
,
876 .verify_port
= m32r_sio_verify_port
,
879 static struct uart_sio_port m32r_sio_ports
[UART_NR
];
881 static void __init
m32r_sio_init_ports(void)
883 struct uart_sio_port
*up
;
884 static int first
= 1;
891 for (i
= 0, up
= m32r_sio_ports
; i
< UART_NR
; i
++, up
++) {
892 up
->port
.iobase
= old_serial_port
[i
].port
;
893 up
->port
.irq
= irq_canonicalize(old_serial_port
[i
].irq
);
894 up
->port
.uartclk
= BAUD_RATE
* 16;
895 up
->port
.flags
= STD_COM_FLAGS
;
896 up
->port
.membase
= 0;
898 up
->port
.regshift
= 0;
899 up
->port
.ops
= &m32r_sio_pops
;
903 static void __init
m32r_sio_register_ports(struct uart_driver
*drv
)
907 m32r_sio_init_ports();
909 for (i
= 0; i
< UART_NR
; i
++) {
910 struct uart_sio_port
*up
= &m32r_sio_ports
[i
];
913 up
->port
.ops
= &m32r_sio_pops
;
914 init_timer(&up
->timer
);
915 up
->timer
.function
= m32r_sio_timeout
;
917 uart_add_one_port(drv
, &up
->port
);
921 #ifdef CONFIG_SERIAL_M32R_SIO_CONSOLE
924 * Wait for transmitter & holding register to empty
926 static void wait_for_xmitr(struct uart_sio_port
*up
)
928 unsigned int status
, tmout
= 10000;
930 /* Wait up to 10ms for the character(s) to be sent. */
932 status
= sio_in(up
, SIOSTS
);
937 } while ((status
& UART_EMPTY
) != UART_EMPTY
);
939 /* Wait up to 1s for flow control if necessary */
940 if (up
->port
.flags
& UPF_CONS_FLOW
) {
947 static void m32r_sio_console_putchar(struct uart_port
*port
, int ch
)
949 struct uart_sio_port
*up
=
950 container_of(port
, struct uart_sio_port
, port
);
953 sio_out(up
, SIOTXB
, ch
);
957 * Print a string to the serial port trying not to disturb
958 * any possible real use of the port...
960 * The console_lock must be held when we get here.
962 static void m32r_sio_console_write(struct console
*co
, const char *s
,
965 struct uart_sio_port
*up
= &m32r_sio_ports
[co
->index
];
969 * First save the UER then disable the interrupts
971 ier
= sio_in(up
, SIOTRCR
);
972 sio_out(up
, SIOTRCR
, 0);
974 uart_console_write(&up
->port
, s
, count
, m32r_sio_console_putchar
);
977 * Finally, wait for transmitter to become empty
978 * and restore the IER
981 sio_out(up
, SIOTRCR
, ier
);
984 static int __init
m32r_sio_console_setup(struct console
*co
, char *options
)
986 struct uart_port
*port
;
993 * Check whether an invalid uart number has been specified, and
994 * if so, search for the first available port that does have
997 if (co
->index
>= UART_NR
)
999 port
= &m32r_sio_ports
[co
->index
].port
;
1004 spin_lock_init(&port
->lock
);
1007 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1009 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1012 static struct uart_driver m32r_sio_reg
;
1013 static struct console m32r_sio_console
= {
1015 .write
= m32r_sio_console_write
,
1016 .device
= uart_console_device
,
1017 .setup
= m32r_sio_console_setup
,
1018 .flags
= CON_PRINTBUFFER
,
1020 .data
= &m32r_sio_reg
,
1023 static int __init
m32r_sio_console_init(void)
1027 m32r_sio_init_ports();
1028 register_console(&m32r_sio_console
);
1031 console_initcall(m32r_sio_console_init
);
1033 #define M32R_SIO_CONSOLE &m32r_sio_console
1035 #define M32R_SIO_CONSOLE NULL
1038 static struct uart_driver m32r_sio_reg
= {
1039 .owner
= THIS_MODULE
,
1040 .driver_name
= "sio",
1045 .cons
= M32R_SIO_CONSOLE
,
1048 static int __init
m32r_sio_init(void)
1052 printk(KERN_INFO
"Serial: M32R SIO driver\n");
1054 for (i
= 0; i
< nr_irqs
; i
++)
1055 spin_lock_init(&irq_lists
[i
].lock
);
1057 ret
= uart_register_driver(&m32r_sio_reg
);
1059 m32r_sio_register_ports(&m32r_sio_reg
);
1064 static void __exit
m32r_sio_exit(void)
1068 for (i
= 0; i
< UART_NR
; i
++)
1069 uart_remove_one_port(&m32r_sio_reg
, &m32r_sio_ports
[i
].port
);
1071 uart_unregister_driver(&m32r_sio_reg
);
1074 module_init(m32r_sio_init
);
1075 module_exit(m32r_sio_exit
);
1077 MODULE_LICENSE("GPL");
1078 MODULE_DESCRIPTION("Generic M32R SIO serial driver");