Lines Matching +full:- +full:uart

1 // SPDX-License-Identifier: GPL-2.0
3 * ARC On-Chip(fpga) UART Driver
5 * Copyright (C) 2010-2012 Synopsys, Inc. (www.synopsys.com)
8 * -Decoupled the driver from arch/arc
10 * +Using early_platform_xxx() for early console (thx to mach-shmobile/xxx)
13 * -Is uart_tx_stopped() not done in tty write path as it has already been
17 * -New Serial Core based ARC UART driver
18 * -Derived largely from blackfin driver albiet with some major tweaks
21 * -check if sysreq works
37 * ARC UART Hardware Specs
42 * UART Register set (this is not a Standards Compliant IP)
54 /* Bits for UART Status Reg (R/W) */
67 /* Uart bit fiddling helpers: lowest level */
68 #define RBASE(port, reg) (port->membase + reg)
75 /* Uart bit fiddling helpers: API level */
76 #define UART_SET_DATA(uart, val) UART_REG_SET(uart, R_DATA, val) argument
77 #define UART_GET_DATA(uart) UART_REG_GET(uart, R_DATA) argument
79 #define UART_SET_BAUDH(uart, val) UART_REG_SET(uart, R_BAUDH, val) argument
80 #define UART_SET_BAUDL(uart, val) UART_REG_SET(uart, R_BAUDL, val) argument
82 #define UART_CLR_STATUS(uart, val) UART_REG_CLR(uart, R_STS, val) argument
83 #define UART_GET_STATUS(uart) UART_REG_GET(uart, R_STS) argument
85 #define UART_ALL_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB|TXIENB) argument
86 #define UART_RX_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, RXIENB) argument
87 #define UART_TX_IRQ_DISABLE(uart) UART_REG_CLR(uart, R_STS, TXIENB) argument
89 #define UART_ALL_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, RXIENB|TXIENB) argument
90 #define UART_RX_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, RXIENB) argument
91 #define UART_TX_IRQ_ENABLE(uart) UART_REG_OR(uart, R_STS, TXIENB) argument
108 #define DRIVER_NAME "arc-uart"
150 * Driver internal routine, used by both tty(serial core) as well as tx-isr
151 * -Called under spinlock in either cases
152 * -also tty->flow.stopped has already been checked
158 struct circ_buf *xmit = &port->state->xmit; in arc_serial_tx_chars()
162 if (unlikely(port->x_char)) { in arc_serial_tx_chars()
163 UART_SET_DATA(port, port->x_char); in arc_serial_tx_chars()
164 port->icount.tx++; in arc_serial_tx_chars()
165 port->x_char = 0; in arc_serial_tx_chars()
168 ch = xmit->buf[xmit->tail]; in arc_serial_tx_chars()
199 * UART has 4 deep RX-FIFO. Driver's recongnition of this fact in arc_serial_rx_chars()
201 * Upon getting a RX-Intr, such that RX-EMPTY=0, meaning data available, in arc_serial_rx_chars()
203 * RX-EMPTY=1. Multiple chars being avail, with a single Interrupt, in arc_serial_rx_chars()
204 * before RX-EMPTY=0, implies some sort of buffering going on in the in arc_serial_rx_chars()
205 * controller, which is indeed the Rx-FIFO. in arc_serial_rx_chars()
215 port->icount.overrun++; in arc_serial_rx_chars()
221 port->icount.frame++; in arc_serial_rx_chars()
230 port->icount.rx++; in arc_serial_rx_chars()
235 tty_flip_buffer_push(&port->state->port); in arc_serial_rx_chars()
243 * to keep things simple as well as efficient, it writes to UART in polled
249 * Thus Rx-interrupts are always enabled, while tx-interrupts are by default
254 * -checks-if-tty-buffer-has-char-to-send
255 * -writes-data-to-uart
256 * -enable-tx-intr
258 * Once data bits are pushed out, controller raises the Tx-room-avail-Interrupt.
262 * more char in tty buffer. In case of sending, it re-enables Tx-intr. In case
276 * notifications from the UART Controller. in arc_serial_isr()
282 spin_lock(&port->lock); in arc_serial_isr()
284 spin_unlock(&port->lock); in arc_serial_isr()
289 /* Unconditionally disable further Tx-Interrupts. in arc_serial_isr()
294 spin_lock(&port->lock); in arc_serial_isr()
299 spin_unlock(&port->lock); in arc_serial_isr()
324 /* ARC UART doesn't support sending Break signal */ in arc_serial_break_ctl()
329 /* Before we hook up the ISR, Disable all UART Interrupts */ in arc_serial_startup()
332 if (request_irq(port->irq, arc_serial_isr, 0, "arc uart rx-tx", port)) { in arc_serial_startup()
333 dev_warn(port->dev, "Unable to attach ARC UART intr\n"); in arc_serial_startup()
334 return -EBUSY; in arc_serial_startup()
345 free_irq(port->irq, port); in arc_serial_shutdown()
352 struct arc_uart_port *uart = to_arc_port(port); in arc_serial_set_termios() local
360 * Formula for ARC UART is: hw-val = ((CLK/(BAUD*4)) -1) in arc_serial_set_termios()
361 * spread over two 8-bit registers in arc_serial_set_termios()
365 hw_val = port->uartclk / (uart->baud * 4) - 1; in arc_serial_set_termios()
369 spin_lock_irqsave(&port->lock, flags); in arc_serial_set_termios()
379 * UART doesn't support Parity/Hardware Flow Control; in arc_serial_set_termios()
382 new->c_cflag &= ~(CMSPAR|CRTSCTS|CSIZE); in arc_serial_set_termios()
383 new->c_cflag |= CS8; in arc_serial_set_termios()
392 uart_update_timeout(port, new->c_cflag, baud); in arc_serial_set_termios()
394 spin_unlock_irqrestore(&port->lock, flags); in arc_serial_set_termios()
399 return port->type == PORT_ARC ? DRIVER_NAME : NULL; in arc_serial_type()
417 if (port->type != PORT_UNKNOWN && ser->type != PORT_ARC) in arc_serial_verify_port()
418 return -EINVAL; in arc_serial_verify_port()
429 port->type = PORT_ARC; in arc_serial_config_port()
486 if (co->index < 0 || co->index >= CONFIG_SERIAL_ARC_NR_PORTS) in arc_serial_console_setup()
487 return -ENODEV; in arc_serial_console_setup()
490 * The uart port backing the console (e.g. ttyARC1) might not have been in arc_serial_console_setup()
493 port = &arc_uart_ports[co->index].port; in arc_serial_console_setup()
494 if (!port->membase) in arc_serial_console_setup()
495 return -ENODEV; in arc_serial_console_setup()
501 * Serial core will call port->ops->set_termios( ) in arc_serial_console_setup()
521 struct uart_port *port = &arc_uart_ports[co->index].port; in arc_serial_console_write()
524 spin_lock_irqsave(&port->lock, flags); in arc_serial_console_write()
526 spin_unlock_irqrestore(&port->lock, flags); in arc_serial_console_write()
535 .index = -1,
542 struct earlycon_device *dev = con->data; in arc_early_serial_write()
544 uart_console_write(&dev->port, s, n, arc_serial_console_putchar); in arc_early_serial_write()
550 struct uart_port *port = &dev->port; in arc_early_console_setup()
553 if (!dev->port.membase) in arc_early_console_setup()
554 return -ENODEV; in arc_early_console_setup()
556 hw_val = port->uartclk / (dev->baud * 4) - 1; in arc_early_console_setup()
563 dev->con->write = arc_early_serial_write; in arc_early_console_setup()
566 OF_EARLYCON_DECLARE(arc_uart, "snps,arc-uart", arc_early_console_setup);
572 struct device_node *np = pdev->dev.of_node; in arc_serial_probe()
573 struct arc_uart_port *uart; in arc_serial_probe() local
580 return -ENODEV; in arc_serial_probe()
587 dev_err(&pdev->dev, "serial%d out of range\n", dev_id); in arc_serial_probe()
588 return -EINVAL; in arc_serial_probe()
591 uart = &arc_uart_ports[dev_id]; in arc_serial_probe()
592 port = &uart->port; in arc_serial_probe()
594 if (of_property_read_u32(np, "clock-frequency", &val)) { in arc_serial_probe()
595 dev_err(&pdev->dev, "clock-frequency property NOTset\n"); in arc_serial_probe()
596 return -EINVAL; in arc_serial_probe()
598 port->uartclk = val; in arc_serial_probe()
600 if (of_property_read_u32(np, "current-speed", &val)) { in arc_serial_probe()
601 dev_err(&pdev->dev, "current-speed property NOT set\n"); in arc_serial_probe()
602 return -EINVAL; in arc_serial_probe()
604 uart->baud = val; in arc_serial_probe()
606 port->membase = devm_platform_ioremap_resource(pdev, 0); in arc_serial_probe()
607 if (IS_ERR(port->membase)) { in arc_serial_probe()
608 /* No point of dev_err since UART itself is hosed here */ in arc_serial_probe()
609 return PTR_ERR(port->membase); in arc_serial_probe()
612 port->irq = irq_of_parse_and_map(np, 0); in arc_serial_probe()
614 port->dev = &pdev->dev; in arc_serial_probe()
615 port->iotype = UPIO_MEM; in arc_serial_probe()
616 port->flags = UPF_BOOT_AUTOCONF; in arc_serial_probe()
617 port->line = dev_id; in arc_serial_probe()
618 port->ops = &arc_serial_pops; in arc_serial_probe()
619 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_ARC_CONSOLE); in arc_serial_probe()
621 port->fifosize = ARC_UART_TX_FIFO_SIZE; in arc_serial_probe()
627 port->ignore_status_mask = 0; in arc_serial_probe()
633 { .compatible = "snps,arc-uart" },
673 MODULE_DESCRIPTION("ARC(Synopsys) On-Chip(fpga) serial driver");