16 #if defined(CONFIG_SERIAL_BCM63XX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
20 #include <linux/kernel.h>
24 #include <linux/module.h>
27 #include <linux/tty.h>
30 #include <linux/serial.h>
31 #include <linux/serial_core.h>
38 #define BCM63XX_NR_UARTS 2
50 #define UART_RX_INT_MASK (UART_IR_MASK(UART_IR_RXOVER) | \
51 UART_IR_MASK(UART_IR_RXTHRESH) | \
52 UART_IR_MASK(UART_IR_RXTIMEOUT))
54 #define UART_RX_INT_STAT (UART_IR_STAT(UART_IR_RXOVER) | \
55 UART_IR_STAT(UART_IR_RXTHRESH) | \
56 UART_IR_STAT(UART_IR_RXTIMEOUT))
65 #define UART_TX_INT_MASK (UART_IR_MASK(UART_IR_TXEMPTY) | \
66 UART_IR_MASK(UART_IR_TXTRESH))
68 #define UART_TX_INT_STAT (UART_IR_STAT(UART_IR_TXEMPTY) | \
69 UART_IR_STAT(UART_IR_TXTRESH))
76 #define UART_EXTINP_INT_MASK (UART_EXTINP_IRMASK(UART_EXTINP_IR_CTS) | \
77 UART_EXTINP_IRMASK(UART_EXTINP_IR_DCD))
82 static inline unsigned int bcm_uart_readl(
struct uart_port *
port,
108 static void bcm_uart_set_mctrl(
struct uart_port *port,
unsigned int mctrl)
132 static unsigned int bcm_uart_get_mctrl(
struct uart_port *port)
152 static void bcm_uart_stop_tx(
struct uart_port *port)
168 static void bcm_uart_start_tx(
struct uart_port *port)
184 static void bcm_uart_stop_rx(
struct uart_port *port)
196 static void bcm_uart_enable_ms(
struct uart_port *port)
208 static void bcm_uart_break_ctl(
struct uart_port *port,
int ctl)
222 spin_unlock_irqrestore(&port->
lock, flags);
228 static const char *bcm_uart_type(
struct uart_port *port)
236 static void bcm_uart_do_rx(
struct uart_port *port)
245 tty = port->
state->port.tty;
247 unsigned int iestat,
c,
cstat;
279 if (uart_handle_break(port))
290 if (cstat & UART_FIFO_BRKDET_MASK)
292 if (cstat & UART_FIFO_FRAMEERR_MASK)
294 if (cstat & UART_FIFO_PARERR_MASK)
303 tty_insert_flip_char(tty, c, flag);
305 }
while (--max_count);
314 static void bcm_uart_do_tx(
struct uart_port *port)
326 if (uart_tx_stopped(port)) {
327 bcm_uart_stop_tx(port);
331 xmit = &port->
state->xmit;
339 while (max_count--) {
371 unsigned int irqstat;
374 spin_lock(&port->
lock);
378 bcm_uart_do_rx(port);
381 bcm_uart_do_tx(port);
389 estat & UART_EXTINP_CTS_MASK);
392 estat & UART_EXTINP_DCD_MASK);
395 spin_unlock(&port->
lock);
402 static void bcm_uart_enable(
struct uart_port *port)
414 static void bcm_uart_disable(
struct uart_port *port)
427 static void bcm_uart_flush(
struct uart_port *port)
444 static int bcm_uart_startup(
struct uart_port *port)
450 bcm_uart_disable(port);
452 bcm_uart_flush(port);
478 bcm_uart_type(port), port);
482 bcm_uart_enable(port);
489 static void bcm_uart_shutdown(
struct uart_port *port)
495 spin_unlock_irqrestore(&port->
lock, flags);
497 bcm_uart_disable(port);
498 bcm_uart_flush(port);
505 static void bcm_uart_set_termios(
struct uart_port *port,
515 bcm_uart_disable(port);
516 bcm_uart_flush(port);
522 switch (new->c_cflag &
CSIZE) {
538 if (new->c_cflag &
CSTOPB)
544 if (new->c_cflag &
PARENB)
547 if (new->c_cflag &
PARODD)
567 if (new->c_iflag &
INPCK) {
571 if (new->c_iflag & (
BRKINT))
575 if (new->c_iflag &
IGNPAR)
577 if (new->c_iflag &
IGNBRK)
579 if (!(new->c_cflag &
CREAD))
583 bcm_uart_enable(port);
584 spin_unlock_irqrestore(&port->
lock, flags);
590 static int bcm_uart_request_port(
struct uart_port *port)
602 dev_err(port->
dev,
"Unable to map registers\n");
612 static void bcm_uart_release_port(
struct uart_port *port)
621 static void bcm_uart_config_port(
struct uart_port *port,
int flags)
624 if (bcm_uart_request_port(port))
634 static int bcm_uart_verify_port(
struct uart_port *port,
639 if (port->
irq != serinfo->
irq)
649 static struct uart_ops bcm_uart_ops = {
650 .tx_empty = bcm_uart_tx_empty,
651 .get_mctrl = bcm_uart_get_mctrl,
652 .set_mctrl = bcm_uart_set_mctrl,
653 .start_tx = bcm_uart_start_tx,
654 .stop_tx = bcm_uart_stop_tx,
655 .stop_rx = bcm_uart_stop_rx,
656 .enable_ms = bcm_uart_enable_ms,
657 .break_ctl = bcm_uart_break_ctl,
658 .startup = bcm_uart_startup,
659 .shutdown = bcm_uart_shutdown,
660 .set_termios = bcm_uart_set_termios,
661 .type = bcm_uart_type,
662 .release_port = bcm_uart_release_port,
663 .request_port = bcm_uart_request_port,
664 .config_port = bcm_uart_config_port,
665 .verify_port = bcm_uart_verify_port,
670 #ifdef CONFIG_SERIAL_BCM63XX_CONSOLE
693 if (val & UART_EXTINP_CTS_MASK)
703 static void bcm_console_putchar(
struct uart_port *port,
int ch)
712 static void bcm_console_write(
struct console *co,
const char *
s,
726 locked = spin_trylock(&port->
lock);
728 spin_lock(&port->
lock);
739 spin_unlock(&port->
lock);
768 static struct console bcm63xx_console = {
770 .write = bcm_console_write,
772 .setup = bcm_console_setup,
775 .data = &bcm_uart_driver,
778 static int __init bcm63xx_console_init(
void)
786 #define BCM63XX_CONSOLE (&bcm63xx_console)
788 #define BCM63XX_CONSOLE NULL
793 .driver_name =
"bcm63xx_uart",
814 if (ports[pdev->
id].membase)
830 memset(port, 0,
sizeof(*port));
834 port->
ops = &bcm_uart_ops;
847 platform_set_drvdata(pdev, port);
855 port = platform_get_drvdata(pdev);
857 platform_set_drvdata(pdev,
NULL);
867 .probe = bcm_uart_probe,
871 .name =
"bcm63xx_uart",
875 static int __init bcm_uart_init(
void)
890 static void __exit bcm_uart_exit(
void)