29 #if defined(CONFIG_SERIAL_M32R_SIO_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
33 #include <linux/module.h>
34 #include <linux/tty.h>
40 #include <linux/serial.h>
47 #define BAUD_RATE 115200
49 #include <linux/serial_core.h>
57 #define DEBUG_AUTOCONF(fmt...) printk(fmt)
59 #define DEBUG_AUTOCONF(fmt...) do { } while (0)
63 #define DEBUG_INTR(fmt...) printk(fmt)
65 #define DEBUG_INTR(fmt...) do { } while (0)
68 #define PASS_LIMIT 256
70 #define BASE_BAUD 115200
73 #define STD_COM_FLAGS (UPF_BOOT_AUTOCONF | UPF_SKIP_TEST)
80 #if defined(CONFIG_PLAT_USRV)
82 #define SERIAL_PORT_DFNS \
84 { 0, BASE_BAUD, 0x3F8, PLD_IRQ_UART0, STD_COM_FLAGS }, \
85 { 0, BASE_BAUD, 0x2F8, PLD_IRQ_UART1, STD_COM_FLAGS },
89 #if defined(CONFIG_SERIAL_M32R_PLDSIO)
90 #define SERIAL_PORT_DFNS \
91 { 0, BASE_BAUD, ((unsigned long)PLD_ESIO0CR), PLD_IRQ_SIO0_RCV, \
94 #define SERIAL_PORT_DFNS \
95 { 0, BASE_BAUD, M32R_SIO_OFFSET, M32R_IRQ_SIO0_R, \
105 #define UART_NR ARRAY_SIZE(old_serial_port)
123 unsigned int state,
unsigned int old);
133 #ifdef CONFIG_SERIAL_M32R_PLDSIO
135 #define __sio_in(x) inw((unsigned long)(x))
136 #define __sio_out(v,x) outw((v),(unsigned long)(x))
138 static inline void sio_set_baud_rate(
unsigned long baud)
140 unsigned short sbaud;
145 static void sio_reset(
void)
157 static void sio_init(
void)
168 static void sio_error(
int *
status)
170 printk(
"SIO0 error[%04x]\n", *status);
178 #define __sio_in(x) inl(x)
179 #define __sio_out(v,x) outl((v),(x))
181 static inline void sio_set_baud_rate(
unsigned long baud)
194 static void sio_reset(
void)
204 static void sio_init(
void)
214 static void sio_error(
int *status)
216 printk(
"SIO0 error[%04x]\n", *status);
260 static void m32r_sio_start_tx(
struct uart_port *port)
262 #ifdef CONFIG_SERIAL_M32R_PLDSIO
271 up->
port.icount.tx++;
284 static void m32r_sio_stop_rx(
struct uart_port *port)
293 static void m32r_sio_enable_ms(
struct uart_port *port)
301 static void receive_chars(
struct uart_sio_port *up,
int *status)
311 up->
port.icount.rx++;
320 up->
port.icount.brk++;
327 if (uart_handle_break(&up->
port))
330 up->
port.icount.parity++;
332 up->
port.icount.frame++;
334 up->
port.icount.overrun++;
339 *status &= up->
port.read_status_mask;
341 if (up->
port.line == up->
port.cons->index) {
347 if (*status & UART_LSR_BI) {
350 }
else if (*status & UART_LSR_PE)
352 else if (*status & UART_LSR_FE)
357 if ((*status & up->
port.ignore_status_mask) == 0)
358 tty_insert_flip_char(tty, ch, flag);
360 if (*status & UART_LSR_OE) {
370 }
while ((*status &
UART_LSR_DR) && (max_count-- > 0));
379 if (up->
port.x_char) {
380 #ifndef CONFIG_SERIAL_M32R_PLDSIO
383 up->
port.icount.tx++;
388 m32r_sio_stop_tx(&up->
port);
392 count = up->
port.fifosize;
396 up->
port.icount.tx++;
401 }
while (--count > 0);
409 m32r_sio_stop_tx(&up->
port);
415 static inline void m32r_sio_handle_port(
struct uart_sio_port *up,
421 receive_chars(up, &status);
444 int pass_counter = 0;
448 #ifdef CONFIG_SERIAL_M32R_PLDSIO
467 spin_lock(&up->
port.lock);
468 m32r_sio_handle_port(up, sts);
469 spin_unlock(&up->
port.lock);
472 }
else if (end ==
NULL)
484 spin_unlock(&i->
lock);
500 spin_lock_irq(&i->
lock);
502 if (!list_empty(i->
head)) {
511 spin_unlock_irq(&i->
lock);
517 int ret, irq_flags = 0;
519 spin_lock_irq(&i->
lock);
523 spin_unlock_irq(&i->
lock);
527 INIT_LIST_HEAD(&up->
list);
529 spin_unlock_irq(&i->
lock);
532 irq_flags,
"SIO0-RX", i);
534 irq_flags,
"SIO0-TX", i);
536 serial_do_unlink(i, up);
542 static void serial_unlink_irq_chain(
struct uart_sio_port *up)
548 if (list_empty(i->
head)) {
553 serial_do_unlink(i, up);
559 static void m32r_sio_timeout(
unsigned long data)
567 spin_lock(&up->
port.lock);
568 m32r_sio_handle_port(up, sts);
569 spin_unlock(&up->
port.lock);
572 timeout = up->
port.timeout;
573 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
577 static unsigned int m32r_sio_tx_empty(
struct uart_port *port)
585 spin_unlock_irqrestore(&up->
port.lock, flags);
590 static unsigned int m32r_sio_get_mctrl(
struct uart_port *port)
595 static void m32r_sio_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
600 static void m32r_sio_break_ctl(
struct uart_port *port,
int break_state)
605 static int m32r_sio_startup(
struct uart_port *port)
618 unsigned int timeout = up->
port.timeout;
620 timeout = timeout > 6 ? (timeout / 2 - 2) : 1;
625 retval = serial_link_irq_chain(up);
648 static void m32r_sio_shutdown(
struct uart_port *port)
667 serial_unlink_irq_chain(up);
670 static unsigned int m32r_sio_get_divisor(
struct uart_port *port,
676 static void m32r_sio_set_termios(
struct uart_port *port,
680 unsigned char cval = 0;
682 unsigned int baud, quot;
714 #ifdef CONFIG_SERIAL_M32R_PLDSIO
719 quot = m32r_sio_get_divisor(port, baud);
727 sio_set_baud_rate(baud);
743 up->
port.ignore_status_mask = 0;
772 spin_unlock_irqrestore(&up->
port.lock, flags);
775 static void m32r_sio_pm(
struct uart_port *port,
unsigned int state,
776 unsigned int oldstate)
781 up->
pm(port, state, oldstate);
792 unsigned int size = 8 << up->
port.regshift;
793 #ifndef CONFIG_SERIAL_M32R_PLDSIO
798 switch (up->
port.iotype) {
800 if (up->
port.mapbase) {
801 #ifdef CONFIG_SERIAL_M32R_PLDSIO
804 start = up->
port.mapbase;
821 static void m32r_sio_release_port(
struct uart_port *port)
824 unsigned long start, offset = 0, size = 0;
826 size <<= up->
port.regshift;
828 switch (up->
port.iotype) {
830 if (up->
port.mapbase) {
837 start = up->
port.mapbase;
846 start = up->
port.iobase;
858 static int m32r_sio_request_port(
struct uart_port *port)
864 ret = m32r_sio_request_std_resource(up, &res);
870 int size = resource_size(res);
873 if (!up->
port.membase)
892 up->
port.fifosize = 1;
894 spin_unlock_irqrestore(&up->
port.lock, flags);
905 static struct uart_ops m32r_sio_pops = {
906 .tx_empty = m32r_sio_tx_empty,
907 .set_mctrl = m32r_sio_set_mctrl,
908 .get_mctrl = m32r_sio_get_mctrl,
909 .stop_tx = m32r_sio_stop_tx,
910 .start_tx = m32r_sio_start_tx,
911 .stop_rx = m32r_sio_stop_rx,
912 .enable_ms = m32r_sio_enable_ms,
913 .break_ctl = m32r_sio_break_ctl,
914 .startup = m32r_sio_startup,
915 .shutdown = m32r_sio_shutdown,
916 .set_termios = m32r_sio_set_termios,
918 .release_port = m32r_sio_release_port,
919 .request_port = m32r_sio_request_port,
920 .config_port = m32r_sio_config_port,
921 .verify_port = m32r_sio_verify_port,
926 static void __init m32r_sio_init_ports(
void)
929 static int first = 1;
936 for (i = 0, up = m32r_sio_ports; i <
ARRAY_SIZE(old_serial_port);
938 up->
port.iobase = old_serial_port[
i].
port;
945 up->
port.ops = &m32r_sio_pops;
953 m32r_sio_init_ports();
955 for (i = 0; i <
UART_NR; i++) {
959 up->
port.ops = &m32r_sio_pops;
961 up->
timer.function = m32r_sio_timeout;
970 #ifdef CONFIG_SERIAL_M32R_SIO_CONSOLE
977 unsigned int status, tmout = 10000;
981 status = sio_in(up,
SIOSTS);
986 }
while ((status & UART_EMPTY) != UART_EMPTY);
996 static void m32r_sio_console_putchar(
struct uart_port *port,
int ch)
1010 static void m32r_sio_console_write(
struct console *co,
const char *
s,
1047 port = &m32r_sio_ports[co->
index].port;
1061 static struct console m32r_sio_console = {
1063 .write = m32r_sio_console_write,
1065 .setup = m32r_sio_console_setup,
1068 .data = &m32r_sio_reg,
1071 static int __init m32r_sio_console_init(
void)
1075 m32r_sio_init_ports();
1081 #define M32R_SIO_CONSOLE &m32r_sio_console
1083 #define M32R_SIO_CONSOLE NULL
1088 .driver_name =
"sio",
1118 static int __init m32r_sio_init(
void)
1129 m32r_sio_register_ports(&m32r_sio_reg);
1134 static void __exit m32r_sio_exit(
void)