Lines Matching +full:port +full:-

1 // SPDX-License-Identifier: GPL-2.0
37 * - rx fifo full
38 * - rx fifo above threshold
39 * - rx fifo not empty for too long
53 * - tx fifo empty
54 * - tx fifo below threshold
73 static inline unsigned int bcm_uart_readl(struct uart_port *port, in bcm_uart_readl() argument
76 return __raw_readl(port->membase + offset); in bcm_uart_readl()
79 static inline void bcm_uart_writel(struct uart_port *port, in bcm_uart_writel() argument
82 __raw_writel(value, port->membase + offset); in bcm_uart_writel()
88 static unsigned int bcm_uart_tx_empty(struct uart_port *port) in bcm_uart_tx_empty() argument
92 val = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_tx_empty()
99 static void bcm_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) in bcm_uart_set_mctrl() argument
103 val = bcm_uart_readl(port, UART_MCTL_REG); in bcm_uart_set_mctrl()
110 bcm_uart_writel(port, val, UART_MCTL_REG); in bcm_uart_set_mctrl()
112 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_set_mctrl()
117 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_set_mctrl()
123 static unsigned int bcm_uart_get_mctrl(struct uart_port *port) in bcm_uart_get_mctrl() argument
128 val = bcm_uart_readl(port, UART_EXTINP_REG); in bcm_uart_get_mctrl()
143 static void bcm_uart_stop_tx(struct uart_port *port) in bcm_uart_stop_tx() argument
147 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_stop_tx()
149 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_stop_tx()
151 val = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_stop_tx()
153 bcm_uart_writel(port, val, UART_IR_REG); in bcm_uart_stop_tx()
159 static void bcm_uart_start_tx(struct uart_port *port) in bcm_uart_start_tx() argument
163 val = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_start_tx()
165 bcm_uart_writel(port, val, UART_IR_REG); in bcm_uart_start_tx()
167 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_start_tx()
169 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_start_tx()
173 * serial core request to stop rx, called before port shutdown
175 static void bcm_uart_stop_rx(struct uart_port *port) in bcm_uart_stop_rx() argument
179 val = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_stop_rx()
181 bcm_uart_writel(port, val, UART_IR_REG); in bcm_uart_stop_rx()
187 static void bcm_uart_enable_ms(struct uart_port *port) in bcm_uart_enable_ms() argument
191 val = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_enable_ms()
193 bcm_uart_writel(port, val, UART_IR_REG); in bcm_uart_enable_ms()
199 static void bcm_uart_break_ctl(struct uart_port *port, int ctl) in bcm_uart_break_ctl() argument
204 uart_port_lock_irqsave(port, &flags); in bcm_uart_break_ctl()
206 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_break_ctl()
211 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_break_ctl()
213 uart_port_unlock_irqrestore(port, flags); in bcm_uart_break_ctl()
217 * return port type in string format
219 static const char *bcm_uart_type(struct uart_port *port) in bcm_uart_type() argument
221 return (port->type == PORT_BCM63XX) ? "bcm63xx_uart" : NULL; in bcm_uart_type()
227 static void bcm_uart_do_rx(struct uart_port *port) in bcm_uart_do_rx() argument
229 struct tty_port *tty_port = &port->state->port; in bcm_uart_do_rx()
234 * serial port */ in bcm_uart_do_rx()
242 iestat = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_do_rx()
249 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_do_rx()
251 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_do_rx()
253 port->icount.overrun++; in bcm_uart_do_rx()
260 cstat = c = bcm_uart_readl(port, UART_FIFO_REG); in bcm_uart_do_rx()
261 port->icount.rx++; in bcm_uart_do_rx()
268 port->icount.brk++; in bcm_uart_do_rx()
269 if (uart_handle_break(port)) in bcm_uart_do_rx()
274 port->icount.parity++; in bcm_uart_do_rx()
276 port->icount.frame++; in bcm_uart_do_rx()
279 cstat &= port->read_status_mask; in bcm_uart_do_rx()
288 if (uart_prepare_sysrq_char(port, c)) in bcm_uart_do_rx()
291 if ((cstat & port->ignore_status_mask) == 0) in bcm_uart_do_rx()
294 } while (--max_count); in bcm_uart_do_rx()
303 static void bcm_uart_do_tx(struct uart_port *port) in bcm_uart_do_tx() argument
309 val = bcm_uart_readl(port, UART_MCTL_REG); in bcm_uart_do_tx()
311 pending = uart_port_tx_limited_flags(port, ch, UART_TX_NOSTOP, in bcm_uart_do_tx()
312 port->fifosize - val, in bcm_uart_do_tx()
314 bcm_uart_writel(port, ch, UART_FIFO_REG), in bcm_uart_do_tx()
320 val = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_do_tx()
322 bcm_uart_writel(port, val, UART_IR_REG); in bcm_uart_do_tx()
324 if (uart_tx_stopped(port)) in bcm_uart_do_tx()
325 bcm_uart_stop_tx(port); in bcm_uart_do_tx()
333 struct uart_port *port; in bcm_uart_interrupt() local
336 port = dev_id; in bcm_uart_interrupt()
337 uart_port_lock(port); in bcm_uart_interrupt()
339 irqstat = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_interrupt()
341 bcm_uart_do_rx(port); in bcm_uart_interrupt()
344 bcm_uart_do_tx(port); in bcm_uart_interrupt()
349 estat = bcm_uart_readl(port, UART_EXTINP_REG); in bcm_uart_interrupt()
351 uart_handle_cts_change(port, in bcm_uart_interrupt()
354 uart_handle_dcd_change(port, in bcm_uart_interrupt()
358 uart_unlock_and_check_sysrq(port); in bcm_uart_interrupt()
365 static void bcm_uart_enable(struct uart_port *port) in bcm_uart_enable() argument
369 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_enable()
371 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_enable()
377 static void bcm_uart_disable(struct uart_port *port) in bcm_uart_disable() argument
381 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_disable()
384 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_disable()
390 static void bcm_uart_flush(struct uart_port *port) in bcm_uart_flush() argument
395 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_flush()
397 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_flush()
401 (void)bcm_uart_readl(port, UART_FIFO_REG); in bcm_uart_flush()
407 static int bcm_uart_startup(struct uart_port *port) in bcm_uart_startup() argument
412 /* mask all irq and flush port */ in bcm_uart_startup()
413 bcm_uart_disable(port); in bcm_uart_startup()
414 bcm_uart_writel(port, 0, UART_IR_REG); in bcm_uart_startup()
415 bcm_uart_flush(port); in bcm_uart_startup()
418 (void)bcm_uart_readl(port, UART_EXTINP_REG); in bcm_uart_startup()
421 val = bcm_uart_readl(port, UART_MCTL_REG); in bcm_uart_startup()
423 val |= (port->fifosize / 2) << UART_MCTL_RXFIFOTHRESH_SHIFT; in bcm_uart_startup()
424 val |= (port->fifosize / 2) << UART_MCTL_TXFIFOTHRESH_SHIFT; in bcm_uart_startup()
425 bcm_uart_writel(port, val, UART_MCTL_REG); in bcm_uart_startup()
428 val = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_startup()
431 bcm_uart_writel(port, val, UART_CTL_REG); in bcm_uart_startup()
437 bcm_uart_writel(port, val, UART_EXTINP_REG); in bcm_uart_startup()
440 ret = request_irq(port->irq, bcm_uart_interrupt, 0, in bcm_uart_startup()
441 dev_name(port->dev), port); in bcm_uart_startup()
444 bcm_uart_writel(port, UART_RX_INT_MASK, UART_IR_REG); in bcm_uart_startup()
445 bcm_uart_enable(port); in bcm_uart_startup()
452 static void bcm_uart_shutdown(struct uart_port *port) in bcm_uart_shutdown() argument
456 uart_port_lock_irqsave(port, &flags); in bcm_uart_shutdown()
457 bcm_uart_writel(port, 0, UART_IR_REG); in bcm_uart_shutdown()
458 uart_port_unlock_irqrestore(port, flags); in bcm_uart_shutdown()
460 bcm_uart_disable(port); in bcm_uart_shutdown()
461 bcm_uart_flush(port); in bcm_uart_shutdown()
462 free_irq(port->irq, port); in bcm_uart_shutdown()
468 static void bcm_uart_set_termios(struct uart_port *port, struct ktermios *new, in bcm_uart_set_termios() argument
475 uart_port_lock_irqsave(port, &flags); in bcm_uart_set_termios()
478 for (tries = 3; !bcm_uart_tx_empty(port) && tries; tries--) in bcm_uart_set_termios()
482 bcm_uart_disable(port); in bcm_uart_set_termios()
483 bcm_uart_flush(port); in bcm_uart_set_termios()
486 ctl = bcm_uart_readl(port, UART_CTL_REG); in bcm_uart_set_termios()
489 switch (new->c_cflag & CSIZE) { in bcm_uart_set_termios()
505 if (new->c_cflag & CSTOPB) in bcm_uart_set_termios()
511 if (new->c_cflag & PARENB) in bcm_uart_set_termios()
514 if (new->c_cflag & PARODD) in bcm_uart_set_termios()
516 bcm_uart_writel(port, ctl, UART_CTL_REG); in bcm_uart_set_termios()
519 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16); in bcm_uart_set_termios()
520 quot = uart_get_divisor(port, baud) - 1; in bcm_uart_set_termios()
521 bcm_uart_writel(port, quot, UART_BAUD_REG); in bcm_uart_set_termios()
524 ier = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_set_termios()
527 if (UART_ENABLE_MS(port, new->c_cflag)) in bcm_uart_set_termios()
530 bcm_uart_writel(port, ier, UART_IR_REG); in bcm_uart_set_termios()
533 port->read_status_mask = UART_FIFO_VALID_MASK; in bcm_uart_set_termios()
534 if (new->c_iflag & INPCK) { in bcm_uart_set_termios()
535 port->read_status_mask |= UART_FIFO_FRAMEERR_MASK; in bcm_uart_set_termios()
536 port->read_status_mask |= UART_FIFO_PARERR_MASK; in bcm_uart_set_termios()
538 if (new->c_iflag & (IGNBRK | BRKINT)) in bcm_uart_set_termios()
539 port->read_status_mask |= UART_FIFO_BRKDET_MASK; in bcm_uart_set_termios()
541 port->ignore_status_mask = 0; in bcm_uart_set_termios()
542 if (new->c_iflag & IGNPAR) in bcm_uart_set_termios()
543 port->ignore_status_mask |= UART_FIFO_PARERR_MASK; in bcm_uart_set_termios()
544 if (new->c_iflag & IGNBRK) in bcm_uart_set_termios()
545 port->ignore_status_mask |= UART_FIFO_BRKDET_MASK; in bcm_uart_set_termios()
546 if (!(new->c_cflag & CREAD)) in bcm_uart_set_termios()
547 port->ignore_status_mask |= UART_FIFO_VALID_MASK; in bcm_uart_set_termios()
549 uart_update_timeout(port, new->c_cflag, baud); in bcm_uart_set_termios()
550 bcm_uart_enable(port); in bcm_uart_set_termios()
551 uart_port_unlock_irqrestore(port, flags); in bcm_uart_set_termios()
557 static int bcm_uart_request_port(struct uart_port *port) in bcm_uart_request_port() argument
566 static void bcm_uart_release_port(struct uart_port *port) in bcm_uart_release_port() argument
572 * serial core request to do any port required autoconfiguration
574 static void bcm_uart_config_port(struct uart_port *port, int flags) in bcm_uart_config_port() argument
577 if (bcm_uart_request_port(port)) in bcm_uart_config_port()
579 port->type = PORT_BCM63XX; in bcm_uart_config_port()
584 * serial core request to check that port information in serinfo are
587 static int bcm_uart_verify_port(struct uart_port *port, in bcm_uart_verify_port() argument
590 if (port->type != PORT_BCM63XX) in bcm_uart_verify_port()
591 return -EINVAL; in bcm_uart_verify_port()
592 if (port->irq != serinfo->irq) in bcm_uart_verify_port()
593 return -EINVAL; in bcm_uart_verify_port()
594 if (port->iotype != serinfo->io_type) in bcm_uart_verify_port()
595 return -EINVAL; in bcm_uart_verify_port()
596 if (port->mapbase != (unsigned long)serinfo->iomem_base) in bcm_uart_verify_port()
597 return -EINVAL; in bcm_uart_verify_port()
605 static bool bcm_uart_tx_full(struct uart_port *port) in bcm_uart_tx_full() argument
609 val = bcm_uart_readl(port, UART_MCTL_REG); in bcm_uart_tx_full()
611 return !(port->fifosize - val); in bcm_uart_tx_full()
614 static int bcm_uart_poll_get_char(struct uart_port *port) in bcm_uart_poll_get_char() argument
618 iestat = bcm_uart_readl(port, UART_IR_REG); in bcm_uart_poll_get_char()
622 return bcm_uart_readl(port, UART_FIFO_REG); in bcm_uart_poll_get_char()
625 static void bcm_uart_poll_put_char(struct uart_port *port, unsigned char c) in bcm_uart_poll_put_char() argument
627 while (bcm_uart_tx_full(port)) { in bcm_uart_poll_put_char()
631 bcm_uart_writel(port, c, UART_FIFO_REG); in bcm_uart_poll_put_char()
662 static void wait_for_xmitr(struct uart_port *port) in wait_for_xmitr() argument
668 while (--tmout) { in wait_for_xmitr()
671 val = bcm_uart_readl(port, UART_IR_REG); in wait_for_xmitr()
678 if (port->flags & UPF_CONS_FLOW) { in wait_for_xmitr()
680 while (--tmout) { in wait_for_xmitr()
683 val = bcm_uart_readl(port, UART_EXTINP_REG); in wait_for_xmitr()
694 static void bcm_console_putchar(struct uart_port *port, unsigned char ch) in bcm_console_putchar() argument
696 wait_for_xmitr(port); in bcm_console_putchar()
697 bcm_uart_writel(port, ch, UART_FIFO_REG); in bcm_console_putchar()
706 struct uart_port *port; in bcm_console_write() local
710 port = &ports[co->index]; in bcm_console_write()
713 locked = uart_port_trylock_irqsave(port, &flags); in bcm_console_write()
715 uart_port_lock_irqsave(port, &flags); in bcm_console_write()
718 uart_console_write(port, s, count, bcm_console_putchar); in bcm_console_write()
721 wait_for_xmitr(port); in bcm_console_write()
724 uart_port_unlock_irqrestore(port, flags); in bcm_console_write()
729 * port and setup it.
733 struct uart_port *port; in bcm_console_setup() local
739 if (co->index < 0 || co->index >= BCM63XX_NR_UARTS) in bcm_console_setup()
740 return -EINVAL; in bcm_console_setup()
741 port = &ports[co->index]; in bcm_console_setup()
742 if (!port->membase) in bcm_console_setup()
743 return -ENODEV; in bcm_console_setup()
747 return uart_set_options(port, co, baud, parity, bits, flow); in bcm_console_setup()
758 .index = -1,
772 struct earlycon_device *dev = con->data; in bcm_early_write()
774 uart_console_write(&dev->port, s, n, bcm_console_putchar); in bcm_early_write()
775 wait_for_xmitr(&dev->port); in bcm_early_write()
781 if (!device->port.membase) in bcm_early_console_setup()
782 return -ENODEV; in bcm_early_console_setup()
784 device->con->write = bcm_early_write; in bcm_early_console_setup()
788 OF_EARLYCON_DECLARE(bcm63xx_uart, "brcm,bcm6345-uart", bcm_early_console_setup);
811 struct uart_port *port; in bcm_uart_probe() local
815 if (pdev->dev.of_node) { in bcm_uart_probe()
816 pdev->id = of_alias_get_id(pdev->dev.of_node, "serial"); in bcm_uart_probe()
818 if (pdev->id < 0) in bcm_uart_probe()
819 pdev->id = of_alias_get_id(pdev->dev.of_node, "uart"); in bcm_uart_probe()
822 if (pdev->id < 0 || pdev->id >= BCM63XX_NR_UARTS) in bcm_uart_probe()
823 return -EINVAL; in bcm_uart_probe()
825 port = &ports[pdev->id]; in bcm_uart_probe()
826 if (port->membase) in bcm_uart_probe()
827 return -EBUSY; in bcm_uart_probe()
828 memset(port, 0, sizeof(*port)); in bcm_uart_probe()
830 port->membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res_mem); in bcm_uart_probe()
831 if (IS_ERR(port->membase)) in bcm_uart_probe()
832 return PTR_ERR(port->membase); in bcm_uart_probe()
833 port->mapbase = res_mem->start; in bcm_uart_probe()
838 port->irq = ret; in bcm_uart_probe()
840 clk = clk_get(&pdev->dev, "refclk"); in bcm_uart_probe()
841 if (IS_ERR(clk) && pdev->dev.of_node) in bcm_uart_probe()
842 clk = of_clk_get(pdev->dev.of_node, 0); in bcm_uart_probe()
845 return -ENODEV; in bcm_uart_probe()
847 port->iotype = UPIO_MEM; in bcm_uart_probe()
848 port->ops = &bcm_uart_ops; in bcm_uart_probe()
849 port->flags = UPF_BOOT_AUTOCONF; in bcm_uart_probe()
850 port->dev = &pdev->dev; in bcm_uart_probe()
851 port->fifosize = 16; in bcm_uart_probe()
852 port->uartclk = clk_get_rate(clk) / 2; in bcm_uart_probe()
853 port->line = pdev->id; in bcm_uart_probe()
854 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_BCM63XX_CONSOLE); in bcm_uart_probe()
857 ret = uart_add_one_port(&bcm_uart_driver, port); in bcm_uart_probe()
859 ports[pdev->id].membase = NULL; in bcm_uart_probe()
862 platform_set_drvdata(pdev, port); in bcm_uart_probe()
868 struct uart_port *port; in bcm_uart_remove() local
870 port = platform_get_drvdata(pdev); in bcm_uart_remove()
871 uart_remove_one_port(&bcm_uart_driver, port); in bcm_uart_remove()
872 /* mark port as free */ in bcm_uart_remove()
873 ports[pdev->id].membase = NULL; in bcm_uart_remove()
877 { .compatible = "brcm,bcm6345-uart" },