18 #if defined(CONFIG_SERIAL_VT8500_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
19 # define SUPPORT_SYSRQ
22 #include <linux/hrtimer.h>
24 #include <linux/module.h>
30 #include <linux/tty.h>
32 #include <linux/serial_core.h>
33 #include <linux/serial.h>
34 #include <linux/slab.h>
43 #define VT8500_URTDR 0x0000
44 #define VT8500_URRDR 0x0004
45 #define VT8500_URDIV 0x0008
46 #define VT8500_URLCR 0x000C
47 #define VT8500_URICR 0x0010
48 #define VT8500_URIER 0x0014
49 #define VT8500_URISR 0x0018
50 #define VT8500_URUSR 0x001c
51 #define VT8500_URFCR 0x0020
52 #define VT8500_URFIDX 0x0024
53 #define VT8500_URBKR 0x0028
54 #define VT8500_URTOD 0x002c
55 #define VT8500_TXFIFO 0x1000
56 #define VT8500_RXFIFO 0x1020
64 #define TXFAE (1 << 2)
66 #define RXFAF (1 << 4)
68 #define TXUDR (1 << 6)
69 #define RXOVER (1 << 7)
72 #define TCTS (1 << 10)
73 #define RXTOUT (1 << 11)
74 #define BKDONE (1 << 12)
77 #define RX_FIFO_INTS (RXFAF | RXFF | RXOVER | PER | FER | RXTOUT)
78 #define TX_FIFO_INTS (TXFAE | TXFE | TXUDR)
80 #define VT8500_MAX_PORTS 6
94 static unsigned long vt8500_ports_in_use;
102 static inline unsigned int vt8500_read(
struct uart_port *
port,
unsigned int off)
170 }
else if (c &
PER) {
177 tty_insert_flip_char(tty, c, flag);
184 static void handle_tx(
struct uart_port *port)
194 vt8500_stop_tx(port);
212 vt8500_stop_tx(port);
215 static void vt8500_start_tx(
struct uart_port *port)
228 static void handle_delta_cts(
struct uart_port *port)
239 spin_lock(&port->
lock);
250 handle_delta_cts(port);
252 spin_unlock(&port->
lock);
257 static unsigned int vt8500_tx_empty(
struct uart_port *port)
263 static unsigned int vt8500_get_mctrl(
struct uart_port *port)
274 static void vt8500_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
278 static void vt8500_break_ctl(
struct uart_port *port,
int break_ctl)
281 vt8500_write(port, vt8500_read(port,
VT8500_URLCR) | (1 << 9),
285 static int vt8500_set_baud_rate(
struct uart_port *port,
unsigned int baud)
288 unsigned int loops = 1000;
292 if (
unlikely((baud < 900) || (baud > 921600)))
295 div |= (921600 /
baud) - 1;
297 while ((vt8500_read(port,
VT8500_URUSR) & (1 << 5)) && --loops)
304 static int vt8500_startup(
struct uart_port *port)
311 "vt8500_serial%d", port->
line);
314 vt8500_port->
name, port);
323 static void vt8500_shutdown(
struct uart_port *port)
325 struct vt8500_port *vt8500_port =
328 vt8500_port->
ier = 0;
336 static void vt8500_set_termios(
struct uart_port *port,
340 struct vt8500_port *vt8500_port =
344 unsigned int loops = 1000;
350 baud = vt8500_set_baud_rate(port, baud);
356 lcr &= ~((1 << 5) | (1 << 4));
410 spin_unlock_irqrestore(&port->
lock, flags);
413 static const char *vt8500_type(
struct uart_port *port)
415 struct vt8500_port *vt8500_port =
417 return vt8500_port->
name;
420 static void vt8500_release_port(
struct uart_port *port)
424 static int vt8500_request_port(
struct uart_port *port)
429 static void vt8500_config_port(
struct uart_port *port,
int flags)
434 static int vt8500_verify_port(
struct uart_port *port,
447 #ifdef CONFIG_SERIAL_VT8500_CONSOLE
451 unsigned int status, tmout = 10000;
460 }
while (status & 0x10);
463 static void vt8500_console_putchar(
struct uart_port *port,
int c)
469 static void vt8500_console_write(
struct console *co,
const char *
s,
472 struct vt8500_port *vt8500_port = vt8500_uart_ports[co->
index];
481 vt8500_console_putchar);
493 struct vt8500_port *vt8500_port;
502 vt8500_port = vt8500_uart_ports[co->
index];
511 co, baud, parity, bits, flow);
514 static struct console vt8500_console = {
516 .write = vt8500_console_write,
518 .setup = vt8500_console_setup,
521 .data = &vt8500_uart_driver,
524 #define VT8500_CONSOLE (&vt8500_console)
527 #define VT8500_CONSOLE NULL
530 static struct uart_ops vt8500_uart_pops = {
531 .tx_empty = vt8500_tx_empty,
532 .set_mctrl = vt8500_set_mctrl,
533 .get_mctrl = vt8500_get_mctrl,
534 .stop_tx = vt8500_stop_tx,
535 .start_tx = vt8500_start_tx,
536 .stop_rx = vt8500_stop_rx,
537 .enable_ms = vt8500_enable_ms,
538 .break_ctl = vt8500_break_ctl,
539 .startup = vt8500_startup,
540 .shutdown = vt8500_shutdown,
541 .set_termios = vt8500_set_termios,
543 .release_port = vt8500_release_port,
544 .request_port = vt8500_request_port,
545 .config_port = vt8500_config_port,
546 .verify_port = vt8500_verify_port,
551 .driver_name =
"vt8500_serial",
552 .dev_name =
"ttyWMT",
559 struct vt8500_port *vt8500_port;
567 if (!mmres || !irqres)
570 vt8500_port = kzalloc(
sizeof(
struct vt8500_port),
GFP_KERNEL);
584 sizeof(vt8500_ports_in_use));
598 vt8500_port->
uart.mapbase = mmres->
start;
600 vt8500_port->
uart.fifosize = 16;
601 vt8500_port->
uart.ops = &vt8500_uart_pops;
603 vt8500_port->
uart.dev = &pdev->
dev;
606 vt8500_port->
clk = of_clk_get(pdev->
dev.of_node, 0);
607 if (vt8500_port->
clk) {
611 pr_warn(
"%s: serial clock source not specified\n", __func__);
612 vt8500_port->
uart.uartclk = 24000000;
616 "VT8500 UART%d", pdev->
id);
619 if (!vt8500_port->
uart.membase) {
624 vt8500_uart_ports[
port] = vt8500_port;
628 platform_set_drvdata(pdev, vt8500_port);
639 struct vt8500_port *vt8500_port = platform_get_drvdata(pdev);
641 platform_set_drvdata(pdev,
NULL);
649 { .compatible =
"via,vt8500-uart", },
654 .probe = vt8500_serial_probe,
657 .name =
"vt8500_serial",
663 static int __init vt8500_serial_init(
void)
679 static void __exit vt8500_serial_exit(
void)
681 #ifdef CONFIG_SERIAL_VT8500_CONSOLE