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 PORT_M32R_BASE PORT_M32R_SIO
48 #define PORT_INDEX(x) (x - PORT_M32R_BASE + 1)
49 #define BAUD_RATE 115200
51 #include <linux/serial_core.h>
53 #include "m32r_sio_reg.h"
59 #define DEBUG_AUTOCONF(fmt...) printk(fmt)
61 #define DEBUG_AUTOCONF(fmt...) do { } while (0)
65 #define DEBUG_INTR(fmt...) printk(fmt)
67 #define DEBUG_INTR(fmt...) do { } while (0)
70 #define PASS_LIMIT 256
72 #define BASE_BAUD 115200
74 /* Standard COM flags */
75 #define STD_COM_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST)
78 * SERIAL_PORT_DFNS tells us about built-in ports that have no
79 * standard enumeration mechanism. Platforms that can find all
80 * serial ports via mechanisms like ACPI or PCI need not supply it.
82 #if defined(CONFIG_PLAT_USRV)
84 #define SERIAL_PORT_DFNS \
85 /* UART CLK PORT IRQ FLAGS */ \
86 { 0, BASE_BAUD, 0x3F8, PLD_IRQ_UART0, STD_COM_FLAGS }, /* ttyS0 */ \
87 { 0, BASE_BAUD, 0x2F8, PLD_IRQ_UART1, STD_COM_FLAGS }, /* ttyS1 */
89 #else /* !CONFIG_PLAT_USRV */
91 #if defined(CONFIG_SERIAL_M32R_PLDSIO)
92 #define SERIAL_PORT_DFNS \
93 { 0, BASE_BAUD, ((unsigned long)PLD_ESIO0CR), PLD_IRQ_SIO0_RCV, \
94 STD_COM_FLAGS }, /* ttyS0 */
96 #define SERIAL_PORT_DFNS \
97 { 0, BASE_BAUD, M32R_SIO_OFFSET, M32R_IRQ_SIO0_R, \
98 STD_COM_FLAGS }, /* ttyS0 */
101 #endif /* !CONFIG_PLAT_USRV */
103 static struct old_serial_port old_serial_port
[] = {
107 #define UART_NR ARRAY_SIZE(old_serial_port)
109 struct uart_sio_port
{
110 struct uart_port port
;
111 struct timer_list timer
; /* "no irq" timer */
112 struct list_head list
; /* ports on this IRQ */
117 unsigned char mcr_mask
; /* mask of user bits */
118 unsigned char mcr_force
; /* mask of forced bits */
119 unsigned char lsr_break_flag
;
122 * We provide a per-port pm hook.
124 void (*pm
)(struct uart_port
*port
,
125 unsigned int state
, unsigned int old
);
130 struct list_head
*head
;
133 static struct irq_info irq_lists
[NR_IRQS
];
136 * Here we define the default xmit fifo size used for each type of UART.
138 static const struct serial_uart_config uart_config
[] = {
141 .dfl_xmit_fifo_size
= 1,
144 [PORT_INDEX(PORT_M32R_SIO
)] = {
146 .dfl_xmit_fifo_size
= 1,
151 #ifdef CONFIG_SERIAL_M32R_PLDSIO
153 #define __sio_in(x) inw((unsigned long)(x))
154 #define __sio_out(v,x) outw((v),(unsigned long)(x))
156 static inline void sio_set_baud_rate(unsigned long baud
)
158 unsigned short sbaud
;
159 sbaud
= (boot_cpu_data
.bus_clock
/ (baud
* 4))-1;
160 __sio_out(sbaud
, PLD_ESIO0BAUR
);
163 static void sio_reset(void)
167 tmp
= __sio_in(PLD_ESIO0RXB
);
168 tmp
= __sio_in(PLD_ESIO0RXB
);
169 tmp
= __sio_in(PLD_ESIO0CR
);
170 sio_set_baud_rate(BAUD_RATE
);
171 __sio_out(0x0300, PLD_ESIO0CR
);
172 __sio_out(0x0003, PLD_ESIO0CR
);
175 static void sio_init(void)
179 tmp
= __sio_in(PLD_ESIO0RXB
);
180 tmp
= __sio_in(PLD_ESIO0RXB
);
181 tmp
= __sio_in(PLD_ESIO0CR
);
182 __sio_out(0x0300, PLD_ESIO0CR
);
183 __sio_out(0x0003, PLD_ESIO0CR
);
186 static void sio_error(int *status
)
188 printk("SIO0 error[%04x]\n", *status
);
191 } while ((*status
= __sio_in(PLD_ESIO0CR
)) != 3);
194 #else /* not CONFIG_SERIAL_M32R_PLDSIO */
196 #define __sio_in(x) inl(x)
197 #define __sio_out(v,x) outl((v),(x))
199 static inline void sio_set_baud_rate(unsigned long baud
)
203 i
= boot_cpu_data
.bus_clock
/ (baud
* 16);
204 j
= (boot_cpu_data
.bus_clock
- (i
* baud
* 16)) / baud
;
208 __sio_out(i
, M32R_SIO0_BAUR_PORTL
);
209 __sio_out(j
, M32R_SIO0_RBAUR_PORTL
);
212 static void sio_reset(void)
214 __sio_out(0x00000300, M32R_SIO0_CR_PORTL
); /* init status */
215 __sio_out(0x00000800, M32R_SIO0_MOD1_PORTL
); /* 8bit */
216 __sio_out(0x00000080, M32R_SIO0_MOD0_PORTL
); /* 1stop non */
217 sio_set_baud_rate(BAUD_RATE
);
218 __sio_out(0x00000000, M32R_SIO0_TRCR_PORTL
);
219 __sio_out(0x00000003, M32R_SIO0_CR_PORTL
); /* RXCEN */
222 static void sio_init(void)
226 tmp
= __sio_in(M32R_SIO0_RXB_PORTL
);
227 tmp
= __sio_in(M32R_SIO0_RXB_PORTL
);
228 tmp
= __sio_in(M32R_SIO0_STS_PORTL
);
229 __sio_out(0x00000003, M32R_SIO0_CR_PORTL
);
232 static void sio_error(int *status
)
234 printk("SIO0 error[%04x]\n", *status
);
237 } while ((*status
= __sio_in(M32R_SIO0_CR_PORTL
)) != 3);
240 #endif /* CONFIG_SERIAL_M32R_PLDSIO */
242 static unsigned int sio_in(struct uart_sio_port
*up
, int offset
)
244 return __sio_in(up
->port
.iobase
+ offset
);
247 static void sio_out(struct uart_sio_port
*up
, int offset
, int value
)
249 __sio_out(value
, up
->port
.iobase
+ offset
);
252 static unsigned int serial_in(struct uart_sio_port
*up
, int offset
)
257 return __sio_in(offset
);
260 static void serial_out(struct uart_sio_port
*up
, int offset
, int value
)
265 __sio_out(value
, offset
);
268 static void m32r_sio_stop_tx(struct uart_port
*port
)
270 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
272 if (up
->ier
& UART_IER_THRI
) {
273 up
->ier
&= ~UART_IER_THRI
;
274 serial_out(up
, UART_IER
, up
->ier
);
278 static void m32r_sio_start_tx(struct uart_port
*port
)
280 #ifdef CONFIG_SERIAL_M32R_PLDSIO
281 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
282 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
284 if (!(up
->ier
& UART_IER_THRI
)) {
285 up
->ier
|= UART_IER_THRI
;
286 serial_out(up
, UART_IER
, up
->ier
);
287 serial_out(up
, UART_TX
, xmit
->buf
[xmit
->tail
]);
288 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
289 up
->port
.icount
.tx
++;
291 while((serial_in(up
, UART_LSR
) & UART_EMPTY
) != UART_EMPTY
);
293 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
295 if (!(up
->ier
& UART_IER_THRI
)) {
296 up
->ier
|= UART_IER_THRI
;
297 serial_out(up
, UART_IER
, up
->ier
);
302 static void m32r_sio_stop_rx(struct uart_port
*port
)
304 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
306 up
->ier
&= ~UART_IER_RLSI
;
307 up
->port
.read_status_mask
&= ~UART_LSR_DR
;
308 serial_out(up
, UART_IER
, up
->ier
);
311 static void m32r_sio_enable_ms(struct uart_port
*port
)
313 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
315 up
->ier
|= UART_IER_MSI
;
316 serial_out(up
, UART_IER
, up
->ier
);
319 static void receive_chars(struct uart_sio_port
*up
, int *status
)
321 struct tty_struct
*tty
= up
->port
.state
->port
.tty
;
327 ch
= sio_in(up
, SIORXB
);
329 up
->port
.icount
.rx
++;
331 if (unlikely(*status
& (UART_LSR_BI
| UART_LSR_PE
|
332 UART_LSR_FE
| UART_LSR_OE
))) {
334 * For statistics only
336 if (*status
& UART_LSR_BI
) {
337 *status
&= ~(UART_LSR_FE
| UART_LSR_PE
);
338 up
->port
.icount
.brk
++;
340 * We do the SysRQ and SAK checking
341 * here because otherwise the break
342 * may get masked by ignore_status_mask
343 * or read_status_mask.
345 if (uart_handle_break(&up
->port
))
347 } else if (*status
& UART_LSR_PE
)
348 up
->port
.icount
.parity
++;
349 else if (*status
& UART_LSR_FE
)
350 up
->port
.icount
.frame
++;
351 if (*status
& UART_LSR_OE
)
352 up
->port
.icount
.overrun
++;
355 * Mask off conditions which should be ingored.
357 *status
&= up
->port
.read_status_mask
;
359 if (up
->port
.line
== up
->port
.cons
->index
) {
360 /* Recover the break flag from console xmit */
361 *status
|= up
->lsr_break_flag
;
362 up
->lsr_break_flag
= 0;
365 if (*status
& UART_LSR_BI
) {
366 DEBUG_INTR("handling break....");
368 } else if (*status
& UART_LSR_PE
)
370 else if (*status
& UART_LSR_FE
)
373 if (uart_handle_sysrq_char(&up
->port
, ch
))
375 if ((*status
& up
->port
.ignore_status_mask
) == 0)
376 tty_insert_flip_char(tty
, ch
, flag
);
378 if (*status
& UART_LSR_OE
) {
380 * Overrun is special, since it's reported
381 * immediately, and doesn't affect the current
384 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
387 *status
= serial_in(up
, UART_LSR
);
388 } while ((*status
& UART_LSR_DR
) && (max_count
-- > 0));
389 tty_flip_buffer_push(tty
);
392 static void transmit_chars(struct uart_sio_port
*up
)
394 struct circ_buf
*xmit
= &up
->port
.state
->xmit
;
397 if (up
->port
.x_char
) {
398 #ifndef CONFIG_SERIAL_M32R_PLDSIO /* XXX */
399 serial_out(up
, UART_TX
, up
->port
.x_char
);
401 up
->port
.icount
.tx
++;
405 if (uart_circ_empty(xmit
) || uart_tx_stopped(&up
->port
)) {
406 m32r_sio_stop_tx(&up
->port
);
410 count
= up
->port
.fifosize
;
412 serial_out(up
, UART_TX
, xmit
->buf
[xmit
->tail
]);
413 xmit
->tail
= (xmit
->tail
+ 1) & (UART_XMIT_SIZE
- 1);
414 up
->port
.icount
.tx
++;
415 if (uart_circ_empty(xmit
))
417 while (!(serial_in(up
, UART_LSR
) & UART_LSR_THRE
));
419 } while (--count
> 0);
421 if (uart_circ_chars_pending(xmit
) < WAKEUP_CHARS
)
422 uart_write_wakeup(&up
->port
);
424 DEBUG_INTR("THRE...");
426 if (uart_circ_empty(xmit
))
427 m32r_sio_stop_tx(&up
->port
);
431 * This handles the interrupt from one port.
433 static inline void m32r_sio_handle_port(struct uart_sio_port
*up
,
436 DEBUG_INTR("status = %x...", status
);
439 receive_chars(up
, &status
);
445 * This is the serial driver's interrupt routine.
447 * Arjan thinks the old way was overly complex, so it got simplified.
448 * Alan disagrees, saying that need the complexity to handle the weird
449 * nature of ISA shared interrupts. (This is a special exception.)
451 * In order to handle ISA shared interrupts properly, we need to check
452 * that all ports have been serviced, and therefore the ISA interrupt
453 * line has been de-asserted.
455 * This means we need to loop through all ports. checking that they
456 * don't have an interrupt pending.
458 static irqreturn_t
m32r_sio_interrupt(int irq
, void *dev_id
)
460 struct irq_info
*i
= dev_id
;
461 struct list_head
*l
, *end
= NULL
;
462 int pass_counter
= 0;
464 DEBUG_INTR("m32r_sio_interrupt(%d)...", irq
);
466 #ifdef CONFIG_SERIAL_M32R_PLDSIO
467 // if (irq == PLD_IRQ_SIO0_SND)
468 // irq = PLD_IRQ_SIO0_RCV;
470 if (irq
== M32R_IRQ_SIO0_S
)
471 irq
= M32R_IRQ_SIO0_R
;
478 struct uart_sio_port
*up
;
481 up
= list_entry(l
, struct uart_sio_port
, list
);
483 sts
= sio_in(up
, SIOSTS
);
485 spin_lock(&up
->port
.lock
);
486 m32r_sio_handle_port(up
, sts
);
487 spin_unlock(&up
->port
.lock
);
490 } else if (end
== NULL
)
495 if (l
== i
->head
&& pass_counter
++ > PASS_LIMIT
) {
502 spin_unlock(&i
->lock
);
504 DEBUG_INTR("end.\n");
510 * To support ISA shared interrupts, we need to have one interrupt
511 * handler that ensures that the IRQ line has been deasserted
512 * before returning. Failing to do this will result in the IRQ
513 * line being stuck active, and, since ISA irqs are edge triggered,
514 * no more IRQs will be seen.
516 static void serial_do_unlink(struct irq_info
*i
, struct uart_sio_port
*up
)
518 spin_lock_irq(&i
->lock
);
520 if (!list_empty(i
->head
)) {
521 if (i
->head
== &up
->list
)
522 i
->head
= i
->head
->next
;
525 BUG_ON(i
->head
!= &up
->list
);
529 spin_unlock_irq(&i
->lock
);
532 static int serial_link_irq_chain(struct uart_sio_port
*up
)
534 struct irq_info
*i
= irq_lists
+ up
->port
.irq
;
535 int ret
, irq_flags
= 0;
537 spin_lock_irq(&i
->lock
);
540 list_add(&up
->list
, i
->head
);
541 spin_unlock_irq(&i
->lock
);
545 INIT_LIST_HEAD(&up
->list
);
547 spin_unlock_irq(&i
->lock
);
549 ret
= request_irq(up
->port
.irq
, m32r_sio_interrupt
,
550 irq_flags
, "SIO0-RX", i
);
551 ret
|= request_irq(up
->port
.irq
+ 1, m32r_sio_interrupt
,
552 irq_flags
, "SIO0-TX", i
);
554 serial_do_unlink(i
, up
);
560 static void serial_unlink_irq_chain(struct uart_sio_port
*up
)
562 struct irq_info
*i
= irq_lists
+ up
->port
.irq
;
564 BUG_ON(i
->head
== NULL
);
566 if (list_empty(i
->head
)) {
567 free_irq(up
->port
.irq
, i
);
568 free_irq(up
->port
.irq
+ 1, i
);
571 serial_do_unlink(i
, up
);
575 * This function is used to handle ports that do not have an interrupt.
577 static void m32r_sio_timeout(unsigned long data
)
579 struct uart_sio_port
*up
= (struct uart_sio_port
*)data
;
580 unsigned int timeout
;
583 sts
= sio_in(up
, SIOSTS
);
585 spin_lock(&up
->port
.lock
);
586 m32r_sio_handle_port(up
, sts
);
587 spin_unlock(&up
->port
.lock
);
590 timeout
= up
->port
.timeout
;
591 timeout
= timeout
> 6 ? (timeout
/ 2 - 2) : 1;
592 mod_timer(&up
->timer
, jiffies
+ timeout
);
595 static unsigned int m32r_sio_tx_empty(struct uart_port
*port
)
597 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
601 spin_lock_irqsave(&up
->port
.lock
, flags
);
602 ret
= serial_in(up
, UART_LSR
) & UART_LSR_TEMT
? TIOCSER_TEMT
: 0;
603 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
608 static unsigned int m32r_sio_get_mctrl(struct uart_port
*port
)
613 static void m32r_sio_set_mctrl(struct uart_port
*port
, unsigned int mctrl
)
618 static void m32r_sio_break_ctl(struct uart_port
*port
, int break_state
)
623 static int m32r_sio_startup(struct uart_port
*port
)
625 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
631 * If the "interrupt" for this port doesn't correspond with any
632 * hardware interrupt, we use a timer-based system. The original
633 * driver used to do this with IRQ0.
636 unsigned int timeout
= up
->port
.timeout
;
638 timeout
= timeout
> 6 ? (timeout
/ 2 - 2) : 1;
640 up
->timer
.data
= (unsigned long)up
;
641 mod_timer(&up
->timer
, jiffies
+ timeout
);
643 retval
= serial_link_irq_chain(up
);
649 * Finally, enable interrupts. Note: Modem status interrupts
650 * are set via set_termios(), which will be occurring imminently
651 * anyway, so we don't enable them here.
653 * - M32R_PLDSIO: 0x04
655 up
->ier
= UART_IER_MSI
| UART_IER_RLSI
| UART_IER_RDI
;
656 sio_out(up
, SIOTRCR
, up
->ier
);
659 * And clear the interrupt registers again for luck.
666 static void m32r_sio_shutdown(struct uart_port
*port
)
668 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
671 * Disable interrupts from this port
674 sio_out(up
, SIOTRCR
, 0);
677 * Disable break condition and FIFOs
683 del_timer_sync(&up
->timer
);
685 serial_unlink_irq_chain(up
);
688 static unsigned int m32r_sio_get_divisor(struct uart_port
*port
,
691 return uart_get_divisor(port
, baud
);
694 static void m32r_sio_set_termios(struct uart_port
*port
,
695 struct ktermios
*termios
, struct ktermios
*old
)
697 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
698 unsigned char cval
= 0;
700 unsigned int baud
, quot
;
702 switch (termios
->c_cflag
& CSIZE
) {
704 cval
= UART_LCR_WLEN5
;
707 cval
= UART_LCR_WLEN6
;
710 cval
= UART_LCR_WLEN7
;
714 cval
= UART_LCR_WLEN8
;
718 if (termios
->c_cflag
& CSTOPB
)
719 cval
|= UART_LCR_STOP
;
720 if (termios
->c_cflag
& PARENB
)
721 cval
|= UART_LCR_PARITY
;
722 if (!(termios
->c_cflag
& PARODD
))
723 cval
|= UART_LCR_EPAR
;
725 if (termios
->c_cflag
& CMSPAR
)
726 cval
|= UART_LCR_SPAR
;
730 * Ask the core to calculate the divisor for us.
732 #ifdef CONFIG_SERIAL_M32R_PLDSIO
733 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/4);
735 baud
= uart_get_baud_rate(port
, termios
, old
, 0, port
->uartclk
/16);
737 quot
= m32r_sio_get_divisor(port
, baud
);
740 * Ok, we're now changing the port state. Do it with
741 * interrupts disabled.
743 spin_lock_irqsave(&up
->port
.lock
, flags
);
745 sio_set_baud_rate(baud
);
748 * Update the per-port timeout.
750 uart_update_timeout(port
, termios
->c_cflag
, baud
);
752 up
->port
.read_status_mask
= UART_LSR_OE
| UART_LSR_THRE
| UART_LSR_DR
;
753 if (termios
->c_iflag
& INPCK
)
754 up
->port
.read_status_mask
|= UART_LSR_FE
| UART_LSR_PE
;
755 if (termios
->c_iflag
& (BRKINT
| PARMRK
))
756 up
->port
.read_status_mask
|= UART_LSR_BI
;
759 * Characteres to ignore
761 up
->port
.ignore_status_mask
= 0;
762 if (termios
->c_iflag
& IGNPAR
)
763 up
->port
.ignore_status_mask
|= UART_LSR_PE
| UART_LSR_FE
;
764 if (termios
->c_iflag
& IGNBRK
) {
765 up
->port
.ignore_status_mask
|= UART_LSR_BI
;
767 * If we're ignoring parity and break indicators,
768 * ignore overruns too (for real raw support).
770 if (termios
->c_iflag
& IGNPAR
)
771 up
->port
.ignore_status_mask
|= UART_LSR_OE
;
775 * ignore all characters if CREAD is not set
777 if ((termios
->c_cflag
& CREAD
) == 0)
778 up
->port
.ignore_status_mask
|= UART_LSR_DR
;
781 * CTS flow control flag and modem status interrupts
783 up
->ier
&= ~UART_IER_MSI
;
784 if (UART_ENABLE_MS(&up
->port
, termios
->c_cflag
))
785 up
->ier
|= UART_IER_MSI
;
787 serial_out(up
, UART_IER
, up
->ier
);
789 up
->lcr
= cval
; /* Save LCR */
790 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
793 static void m32r_sio_pm(struct uart_port
*port
, unsigned int state
,
794 unsigned int oldstate
)
796 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
799 up
->pm(port
, state
, oldstate
);
803 * Resource handling. This is complicated by the fact that resources
804 * depend on the port type. Maybe we should be claiming the standard
805 * 8250 ports, and then trying to get other resources as necessary?
808 m32r_sio_request_std_resource(struct uart_sio_port
*up
, struct resource
**res
)
810 unsigned int size
= 8 << up
->port
.regshift
;
811 #ifndef CONFIG_SERIAL_M32R_PLDSIO
816 switch (up
->port
.iotype
) {
818 if (up
->port
.mapbase
) {
819 #ifdef CONFIG_SERIAL_M32R_PLDSIO
820 *res
= request_mem_region(up
->port
.mapbase
, size
, "serial");
822 start
= up
->port
.mapbase
;
823 *res
= request_mem_region(start
, size
, "serial");
831 *res
= request_region(up
->port
.iobase
, size
, "serial");
839 static void m32r_sio_release_port(struct uart_port
*port
)
841 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
842 unsigned long start
, offset
= 0, size
= 0;
844 size
<<= up
->port
.regshift
;
846 switch (up
->port
.iotype
) {
848 if (up
->port
.mapbase
) {
852 iounmap(up
->port
.membase
);
853 up
->port
.membase
= NULL
;
855 start
= up
->port
.mapbase
;
858 release_mem_region(start
+ offset
, size
);
859 release_mem_region(start
, 8 << up
->port
.regshift
);
864 start
= up
->port
.iobase
;
867 release_region(start
+ offset
, size
);
868 release_region(start
+ offset
, 8 << up
->port
.regshift
);
876 static int m32r_sio_request_port(struct uart_port
*port
)
878 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
879 struct resource
*res
= NULL
;
882 ret
= m32r_sio_request_std_resource(up
, &res
);
885 * If we have a mapbase, then request that as well.
887 if (ret
== 0 && up
->port
.flags
& UPF_IOREMAP
) {
888 int size
= resource_size(res
);
890 up
->port
.membase
= ioremap(up
->port
.mapbase
, size
);
891 if (!up
->port
.membase
)
897 release_resource(res
);
903 static void m32r_sio_config_port(struct uart_port
*port
, int unused
)
905 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
908 spin_lock_irqsave(&up
->port
.lock
, flags
);
910 up
->port
.type
= (PORT_M32R_SIO
- PORT_M32R_BASE
+ 1);
911 up
->port
.fifosize
= uart_config
[up
->port
.type
].dfl_xmit_fifo_size
;
913 spin_unlock_irqrestore(&up
->port
.lock
, flags
);
917 m32r_sio_verify_port(struct uart_port
*port
, struct serial_struct
*ser
)
919 if (ser
->irq
>= nr_irqs
|| ser
->irq
< 0 ||
920 ser
->baud_base
< 9600 || ser
->type
< PORT_UNKNOWN
||
921 ser
->type
>= ARRAY_SIZE(uart_config
))
927 m32r_sio_type(struct uart_port
*port
)
929 int type
= port
->type
;
931 if (type
>= ARRAY_SIZE(uart_config
))
933 return uart_config
[type
].name
;
936 static struct uart_ops m32r_sio_pops
= {
937 .tx_empty
= m32r_sio_tx_empty
,
938 .set_mctrl
= m32r_sio_set_mctrl
,
939 .get_mctrl
= m32r_sio_get_mctrl
,
940 .stop_tx
= m32r_sio_stop_tx
,
941 .start_tx
= m32r_sio_start_tx
,
942 .stop_rx
= m32r_sio_stop_rx
,
943 .enable_ms
= m32r_sio_enable_ms
,
944 .break_ctl
= m32r_sio_break_ctl
,
945 .startup
= m32r_sio_startup
,
946 .shutdown
= m32r_sio_shutdown
,
947 .set_termios
= m32r_sio_set_termios
,
949 .type
= m32r_sio_type
,
950 .release_port
= m32r_sio_release_port
,
951 .request_port
= m32r_sio_request_port
,
952 .config_port
= m32r_sio_config_port
,
953 .verify_port
= m32r_sio_verify_port
,
956 static struct uart_sio_port m32r_sio_ports
[UART_NR
];
958 static void __init
m32r_sio_init_ports(void)
960 struct uart_sio_port
*up
;
961 static int first
= 1;
968 for (i
= 0, up
= m32r_sio_ports
; i
< ARRAY_SIZE(old_serial_port
);
970 up
->port
.iobase
= old_serial_port
[i
].port
;
971 up
->port
.irq
= irq_canonicalize(old_serial_port
[i
].irq
);
972 up
->port
.uartclk
= old_serial_port
[i
].baud_base
* 16;
973 up
->port
.flags
= old_serial_port
[i
].flags
;
974 up
->port
.membase
= old_serial_port
[i
].iomem_base
;
975 up
->port
.iotype
= old_serial_port
[i
].io_type
;
976 up
->port
.regshift
= old_serial_port
[i
].iomem_reg_shift
;
977 up
->port
.ops
= &m32r_sio_pops
;
981 static void __init
m32r_sio_register_ports(struct uart_driver
*drv
)
985 m32r_sio_init_ports();
987 for (i
= 0; i
< UART_NR
; i
++) {
988 struct uart_sio_port
*up
= &m32r_sio_ports
[i
];
991 up
->port
.ops
= &m32r_sio_pops
;
992 init_timer(&up
->timer
);
993 up
->timer
.function
= m32r_sio_timeout
;
998 uart_add_one_port(drv
, &up
->port
);
1002 #ifdef CONFIG_SERIAL_M32R_SIO_CONSOLE
1005 * Wait for transmitter & holding register to empty
1007 static inline void wait_for_xmitr(struct uart_sio_port
*up
)
1009 unsigned int status
, tmout
= 10000;
1011 /* Wait up to 10ms for the character(s) to be sent. */
1013 status
= sio_in(up
, SIOSTS
);
1018 } while ((status
& UART_EMPTY
) != UART_EMPTY
);
1020 /* Wait up to 1s for flow control if necessary */
1021 if (up
->port
.flags
& UPF_CONS_FLOW
) {
1028 static void m32r_sio_console_putchar(struct uart_port
*port
, int ch
)
1030 struct uart_sio_port
*up
= (struct uart_sio_port
*)port
;
1033 sio_out(up
, SIOTXB
, ch
);
1037 * Print a string to the serial port trying not to disturb
1038 * any possible real use of the port...
1040 * The console_lock must be held when we get here.
1042 static void m32r_sio_console_write(struct console
*co
, const char *s
,
1045 struct uart_sio_port
*up
= &m32r_sio_ports
[co
->index
];
1049 * First save the UER then disable the interrupts
1051 ier
= sio_in(up
, SIOTRCR
);
1052 sio_out(up
, SIOTRCR
, 0);
1054 uart_console_write(&up
->port
, s
, count
, m32r_sio_console_putchar
);
1057 * Finally, wait for transmitter to become empty
1058 * and restore the IER
1061 sio_out(up
, SIOTRCR
, ier
);
1064 static int __init
m32r_sio_console_setup(struct console
*co
, char *options
)
1066 struct uart_port
*port
;
1073 * Check whether an invalid uart number has been specified, and
1074 * if so, search for the first available port that does have
1077 if (co
->index
>= UART_NR
)
1079 port
= &m32r_sio_ports
[co
->index
].port
;
1084 spin_lock_init(&port
->lock
);
1087 uart_parse_options(options
, &baud
, &parity
, &bits
, &flow
);
1089 return uart_set_options(port
, co
, baud
, parity
, bits
, flow
);
1092 static struct uart_driver m32r_sio_reg
;
1093 static struct console m32r_sio_console
= {
1095 .write
= m32r_sio_console_write
,
1096 .device
= uart_console_device
,
1097 .setup
= m32r_sio_console_setup
,
1098 .flags
= CON_PRINTBUFFER
,
1100 .data
= &m32r_sio_reg
,
1103 static int __init
m32r_sio_console_init(void)
1107 m32r_sio_init_ports();
1108 register_console(&m32r_sio_console
);
1111 console_initcall(m32r_sio_console_init
);
1113 #define M32R_SIO_CONSOLE &m32r_sio_console
1115 #define M32R_SIO_CONSOLE NULL
1118 static struct uart_driver m32r_sio_reg
= {
1119 .owner
= THIS_MODULE
,
1120 .driver_name
= "sio",
1125 .cons
= M32R_SIO_CONSOLE
,
1129 * m32r_sio_suspend_port - suspend one serial port
1130 * @line: serial line number
1132 * Suspend one serial port.
1134 void m32r_sio_suspend_port(int line
)
1136 uart_suspend_port(&m32r_sio_reg
, &m32r_sio_ports
[line
].port
);
1140 * m32r_sio_resume_port - resume one serial port
1141 * @line: serial line number
1143 * Resume one serial port.
1145 void m32r_sio_resume_port(int line
)
1147 uart_resume_port(&m32r_sio_reg
, &m32r_sio_ports
[line
].port
);
1150 static int __init
m32r_sio_init(void)
1154 printk(KERN_INFO
"Serial: M32R SIO driver\n");
1156 for (i
= 0; i
< nr_irqs
; i
++)
1157 spin_lock_init(&irq_lists
[i
].lock
);
1159 ret
= uart_register_driver(&m32r_sio_reg
);
1161 m32r_sio_register_ports(&m32r_sio_reg
);
1166 static void __exit
m32r_sio_exit(void)
1170 for (i
= 0; i
< UART_NR
; i
++)
1171 uart_remove_one_port(&m32r_sio_reg
, &m32r_sio_ports
[i
].port
);
1173 uart_unregister_driver(&m32r_sio_reg
);
1176 module_init(m32r_sio_init
);
1177 module_exit(m32r_sio_exit
);
1179 EXPORT_SYMBOL(m32r_sio_suspend_port
);
1180 EXPORT_SYMBOL(m32r_sio_resume_port
);
1182 MODULE_LICENSE("GPL");
1183 MODULE_DESCRIPTION("Generic M32R SIO serial driver");