7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/tty.h>
14 #include <linux/serial.h>
18 #include <linux/slab.h>
25 #warning "Please try migrate to use new driver SCCNXP and report the status" \
26 "in the linux-serial mailing list."
28 #if defined(CONFIG_MAGIC_SYSRQ)
32 #include <linux/serial_core.h>
34 #define SC26XX_MAJOR 204
35 #define SC26XX_MINOR_START 205
56 #define WR_OPR_SET 0x38
57 #define WR_OPR_CLR 0x3C
60 #define READ_SC(p, r) readb((p)->membase + RD_##r)
61 #define WRITE_SC(p, r, v) writeb((v), (p)->membase + WR_##r)
64 #define RD_PORT_MRx 0x00
65 #define RD_PORT_SR 0x04
66 #define RD_PORT_RHR 0x0c
68 #define WR_PORT_MRx 0x00
69 #define WR_PORT_CSR 0x04
70 #define WR_PORT_CR 0x08
71 #define WR_PORT_THR 0x0c
74 #define SR_BREAK (1 << 7)
75 #define SR_FRAME (1 << 6)
76 #define SR_PARITY (1 << 5)
77 #define SR_OVERRUN (1 << 4)
78 #define SR_TXRDY (1 << 2)
79 #define SR_RXRDY (1 << 0)
81 #define CR_RES_MR (1 << 4)
82 #define CR_RES_RX (2 << 4)
83 #define CR_RES_TX (3 << 4)
84 #define CR_STRT_BRK (6 << 4)
85 #define CR_STOP_BRK (7 << 4)
86 #define CR_DIS_TX (1 << 3)
87 #define CR_ENA_TX (1 << 2)
88 #define CR_DIS_RX (1 << 1)
89 #define CR_ENA_RX (1 << 0)
92 #define ISR_RXRDYB (1 << 5)
93 #define ISR_TXRDYB (1 << 4)
94 #define ISR_RXRDYA (1 << 1)
95 #define ISR_TXRDYA (1 << 0)
98 #define IMR_RXRDY (1 << 1)
99 #define IMR_TXRDY (1 << 0)
112 #define READ_SC_PORT(p, r) read_sc_port(p, RD_PORT_##r)
113 #define WRITE_SC_PORT(p, r, v) write_sc_port(p, WR_PORT_##r, v)
123 up->
imr |= mask << (line * 4);
135 up->
imr &= ~(mask << (line * 4));
148 tty = port->
state->port.tty;
150 while (limit-- > 0) {
164 if (uart_handle_break(port))
174 if (status & SR_BREAK)
176 else if (status & SR_PARITY)
178 else if (status & SR_FRAME)
188 tty_insert_flip_char(tty, ch, flag);
193 static void transmit_chars(
struct uart_port *port)
200 xmit = &port->
state->xmit;
229 transmit_chars(&up->
port[0]);
231 tty = receive_chars(&up->
port[0]);
233 spin_unlock(&up->
port[0].lock);
238 spin_lock(&up->
port[1].lock);
242 transmit_chars(&up->
port[1]);
244 tty = receive_chars(&up->
port[1]);
246 spin_unlock_irqrestore(&up->
port[1].lock, flags);
255 static unsigned int sc26xx_tx_empty(
struct uart_port *port)
261 static void sc26xx_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
284 static unsigned int sc26xx_get_mctrl(
struct uart_port *port)
287 int line = port->
line;
315 static void sc26xx_stop_tx(
struct uart_port *port)
321 static void sc26xx_start_tx(
struct uart_port *port)
337 static void sc26xx_stop_rx(
struct uart_port *port)
342 static void sc26xx_enable_ms(
struct uart_port *port)
347 static void sc26xx_break_ctl(
struct uart_port *port,
int break_state)
349 if (break_state == -1)
356 static int sc26xx_startup(
struct uart_port *port)
374 static void sc26xx_shutdown(
struct uart_port *port)
389 unsigned int iflag,
cflag;
412 if ((cflag &
CREAD) == 0)
416 switch (cflag &
CSIZE) {
494 (port->
uartclk / (16 * quot)));
496 spin_unlock_irqrestore(&port->
lock, flags);
499 static const char *sc26xx_type(
struct uart_port *port)
504 static void sc26xx_release_port(
struct uart_port *port)
508 static int sc26xx_request_port(
struct uart_port *port)
513 static void sc26xx_config_port(
struct uart_port *port,
int flags)
522 static struct uart_ops sc26xx_ops = {
523 .tx_empty = sc26xx_tx_empty,
524 .set_mctrl = sc26xx_set_mctrl,
525 .get_mctrl = sc26xx_get_mctrl,
526 .stop_tx = sc26xx_stop_tx,
527 .start_tx = sc26xx_start_tx,
528 .stop_rx = sc26xx_stop_rx,
529 .enable_ms = sc26xx_enable_ms,
530 .break_ctl = sc26xx_break_ctl,
531 .startup = sc26xx_startup,
532 .shutdown = sc26xx_shutdown,
533 .set_termios = sc26xx_set_termios,
535 .release_port = sc26xx_release_port,
536 .request_port = sc26xx_request_port,
537 .config_port = sc26xx_config_port,
538 .verify_port = sc26xx_verify_port,
543 #ifdef CONFIG_SERIAL_SC26XX_CONSOLE
544 static void sc26xx_console_putchar(
struct uart_port *port,
char c)
551 while (limit-- > 0) {
559 spin_unlock_irqrestore(&port->
lock, flags);
562 static void sc26xx_console_write(
struct console *
con,
const char *
s,
unsigned n)
567 for (i = 0; i <
n; i++) {
569 sc26xx_console_putchar(port,
'\r');
570 sc26xx_console_putchar(port, *s++);
593 static struct console sc26xx_console = {
595 .write = sc26xx_console_write,
597 .setup = sc26xx_console_setup,
602 #define SC26XX_CONSOLE &sc26xx_console
604 #define SC26XX_CONSOLE NULL
609 .driver_name =
"SC26xx",
617 static u8 sc26xx_flags2mask(
unsigned int flags,
unsigned int bitpos)
619 unsigned int bit = (flags >> bitpos) & 15;
621 return bit ? (1 << (bit - 1)) : 0;
625 int line,
unsigned int data)
627 up->
dtr_mask[line] = sc26xx_flags2mask(data, 0);
628 up->
rts_mask[line] = sc26xx_flags2mask(data, 4);
629 up->
dsr_mask[line] = sc26xx_flags2mask(data, 8);
630 up->
cts_mask[line] = sc26xx_flags2mask(data, 12);
631 up->
dcd_mask[line] = sc26xx_flags2mask(data, 16);
632 up->
ri_mask[line] = sc26xx_flags2mask(data, 20);
639 unsigned int *sc26xx_data = dev->
dev.platform_data;
650 up->
port[0].line = 0;
651 up->
port[0].ops = &sc26xx_ops;
653 up->
port[0].uartclk = (29491200 / 16);
662 sc26xx_init_masks(up, 0, sc26xx_data[0]);
664 sc26xx_port = &up->
port[0];
666 up->
port[1].line = 1;
667 up->
port[1].ops = &sc26xx_ops;
669 up->
port[1].uartclk = (29491200 / 16);
671 up->
port[1].mapbase = up->
port[0].mapbase;
672 up->
port[1].membase = up->
port[0].membase;
678 sc26xx_init_masks(up, 1, sc26xx_data[1]);
688 goto out_unregister_driver;
692 goto out_remove_port0;
696 goto out_remove_ports;
706 out_unregister_driver:
735 .probe = sc26xx_probe,