Lines Matching +full:bcm6345 +full:- +full:uart
1 // SPDX-License-Identifier: GPL-2.0
7 * Serial driver for BCM63xx integrated UART.
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
71 * handy uart register accessor
76 return __raw_readl(port->membase + offset); in bcm_uart_readl()
82 __raw_writel(value, port->membase + offset); in bcm_uart_writel()
86 * serial core request to check if uart tx fifo is empty
204 spin_lock_irqsave(&port->lock, flags); in bcm_uart_break_ctl()
213 spin_unlock_irqrestore(&port->lock, flags); in bcm_uart_break_ctl()
221 return (port->type == PORT_BCM63XX) ? "bcm63xx_uart" : NULL; in bcm_uart_type()
229 struct tty_port *tty_port = &port->state->port; in bcm_uart_do_rx()
253 port->icount.overrun++; in bcm_uart_do_rx()
261 port->icount.rx++; in bcm_uart_do_rx()
268 port->icount.brk++; 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()
292 if ((cstat & port->ignore_status_mask) == 0) in bcm_uart_do_rx()
295 } while (--max_count); in bcm_uart_do_rx()
297 spin_unlock(&port->lock); in bcm_uart_do_rx()
299 spin_lock(&port->lock); in bcm_uart_do_rx()
311 if (port->x_char) { in bcm_uart_do_tx()
312 bcm_uart_writel(port, port->x_char, UART_FIFO_REG); in bcm_uart_do_tx()
313 port->icount.tx++; in bcm_uart_do_tx()
314 port->x_char = 0; in bcm_uart_do_tx()
323 xmit = &port->state->xmit; in bcm_uart_do_tx()
329 max_count = port->fifosize - val; in bcm_uart_do_tx()
331 while (max_count--) { in bcm_uart_do_tx()
334 c = xmit->buf[xmit->tail]; in bcm_uart_do_tx()
336 xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); in bcm_uart_do_tx()
337 port->icount.tx++; in bcm_uart_do_tx()
358 * process uart interrupt
366 spin_lock(&port->lock); in bcm_uart_interrupt()
387 spin_unlock(&port->lock); in bcm_uart_interrupt()
392 * enable rx & tx operation on uart
404 * disable rx & tx operation on uart
434 * serial core request to initialize uart and start rx operation
452 val |= (port->fifosize / 2) << UART_MCTL_RXFIFOTHRESH_SHIFT; in bcm_uart_startup()
453 val |= (port->fifosize / 2) << UART_MCTL_TXFIFOTHRESH_SHIFT; in bcm_uart_startup()
469 ret = request_irq(port->irq, bcm_uart_interrupt, 0, in bcm_uart_startup()
470 dev_name(port->dev), port); in bcm_uart_startup()
479 * serial core request to flush & disable uart
485 spin_lock_irqsave(&port->lock, flags); in bcm_uart_shutdown()
487 spin_unlock_irqrestore(&port->lock, flags); in bcm_uart_shutdown()
491 free_irq(port->irq, port); in bcm_uart_shutdown()
495 * serial core request to change current uart setting
505 spin_lock_irqsave(&port->lock, flags); in bcm_uart_set_termios()
508 for (tries = 3; !bcm_uart_tx_empty(port) && tries; tries--) in bcm_uart_set_termios()
511 /* disable uart while changing speed */ in bcm_uart_set_termios()
519 switch (new->c_cflag & CSIZE) { in bcm_uart_set_termios()
535 if (new->c_cflag & CSTOPB) in bcm_uart_set_termios()
541 if (new->c_cflag & PARENB) in bcm_uart_set_termios()
544 if (new->c_cflag & PARODD) in bcm_uart_set_termios()
549 baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16); in bcm_uart_set_termios()
550 quot = uart_get_divisor(port, baud) - 1; in bcm_uart_set_termios()
557 if (UART_ENABLE_MS(port, new->c_cflag)) in bcm_uart_set_termios()
563 port->read_status_mask = UART_FIFO_VALID_MASK; in bcm_uart_set_termios()
564 if (new->c_iflag & INPCK) { in bcm_uart_set_termios()
565 port->read_status_mask |= UART_FIFO_FRAMEERR_MASK; in bcm_uart_set_termios()
566 port->read_status_mask |= UART_FIFO_PARERR_MASK; in bcm_uart_set_termios()
568 if (new->c_iflag & (IGNBRK | BRKINT)) in bcm_uart_set_termios()
569 port->read_status_mask |= UART_FIFO_BRKDET_MASK; in bcm_uart_set_termios()
571 port->ignore_status_mask = 0; in bcm_uart_set_termios()
572 if (new->c_iflag & IGNPAR) in bcm_uart_set_termios()
573 port->ignore_status_mask |= UART_FIFO_PARERR_MASK; in bcm_uart_set_termios()
574 if (new->c_iflag & IGNBRK) in bcm_uart_set_termios()
575 port->ignore_status_mask |= UART_FIFO_BRKDET_MASK; in bcm_uart_set_termios()
576 if (!(new->c_cflag & CREAD)) in bcm_uart_set_termios()
577 port->ignore_status_mask |= UART_FIFO_VALID_MASK; in bcm_uart_set_termios()
579 uart_update_timeout(port, new->c_cflag, baud); in bcm_uart_set_termios()
581 spin_unlock_irqrestore(&port->lock, flags); in bcm_uart_set_termios()
585 * serial core request to claim uart iomem
594 * serial core request to release uart iomem
609 port->type = PORT_BCM63XX; in bcm_uart_config_port()
620 if (port->type != PORT_BCM63XX) in bcm_uart_verify_port()
621 return -EINVAL; in bcm_uart_verify_port()
622 if (port->irq != serinfo->irq) in bcm_uart_verify_port()
623 return -EINVAL; in bcm_uart_verify_port()
624 if (port->iotype != serinfo->io_type) in bcm_uart_verify_port()
625 return -EINVAL; in bcm_uart_verify_port()
626 if (port->mapbase != (unsigned long)serinfo->iomem_base) in bcm_uart_verify_port()
627 return -EINVAL; in bcm_uart_verify_port()
660 while (--tmout) { in wait_for_xmitr()
670 if (port->flags & UPF_CONS_FLOW) { in wait_for_xmitr()
672 while (--tmout) { in wait_for_xmitr()
702 port = &ports[co->index]; in bcm_console_write()
705 if (port->sysrq) { in bcm_console_write()
709 locked = spin_trylock(&port->lock); in bcm_console_write()
711 spin_lock(&port->lock); in bcm_console_write()
722 spin_unlock(&port->lock); in bcm_console_write()
727 * console core request to setup given console, find matching uart
738 if (co->index < 0 || co->index >= BCM63XX_NR_UARTS) in bcm_console_setup()
739 return -EINVAL; in bcm_console_setup()
740 port = &ports[co->index]; in bcm_console_setup()
741 if (!port->membase) in bcm_console_setup()
742 return -ENODEV; in bcm_console_setup()
757 .index = -1,
771 struct earlycon_device *dev = con->data; in bcm_early_write()
773 uart_console_write(&dev->port, s, n, bcm_console_putchar); in bcm_early_write()
774 wait_for_xmitr(&dev->port); in bcm_early_write()
780 if (!device->port.membase) in bcm_early_console_setup()
781 return -ENODEV; in bcm_early_console_setup()
783 device->con->write = bcm_early_write; in bcm_early_console_setup()
787 OF_EARLYCON_DECLARE(bcm63xx_uart, "brcm,bcm6345-uart", bcm_early_console_setup);
814 if (pdev->dev.of_node) { in bcm_uart_probe()
815 pdev->id = of_alias_get_id(pdev->dev.of_node, "serial"); in bcm_uart_probe()
817 if (pdev->id < 0) in bcm_uart_probe()
818 pdev->id = of_alias_get_id(pdev->dev.of_node, "uart"); in bcm_uart_probe()
821 if (pdev->id < 0 || pdev->id >= BCM63XX_NR_UARTS) in bcm_uart_probe()
822 return -EINVAL; in bcm_uart_probe()
824 port = &ports[pdev->id]; in bcm_uart_probe()
825 if (port->membase) in bcm_uart_probe()
826 return -EBUSY; in bcm_uart_probe()
831 return -ENODEV; in bcm_uart_probe()
833 port->mapbase = res_mem->start; in bcm_uart_probe()
834 port->membase = devm_ioremap_resource(&pdev->dev, res_mem); in bcm_uart_probe()
835 if (IS_ERR(port->membase)) in bcm_uart_probe()
836 return PTR_ERR(port->membase); in bcm_uart_probe()
840 return -ENODEV; in bcm_uart_probe()
842 clk = clk_get(&pdev->dev, "refclk"); in bcm_uart_probe()
843 if (IS_ERR(clk) && pdev->dev.of_node) in bcm_uart_probe()
844 clk = of_clk_get(pdev->dev.of_node, 0); in bcm_uart_probe()
847 return -ENODEV; in bcm_uart_probe()
849 port->iotype = UPIO_MEM; in bcm_uart_probe()
850 port->irq = res_irq->start; in bcm_uart_probe()
851 port->ops = &bcm_uart_ops; in bcm_uart_probe()
852 port->flags = UPF_BOOT_AUTOCONF; in bcm_uart_probe()
853 port->dev = &pdev->dev; in bcm_uart_probe()
854 port->fifosize = 16; in bcm_uart_probe()
855 port->uartclk = clk_get_rate(clk) / 2; in bcm_uart_probe()
856 port->line = pdev->id; in bcm_uart_probe()
857 port->has_sysrq = IS_ENABLED(CONFIG_SERIAL_BCM63XX_CONSOLE); in bcm_uart_probe()
862 ports[pdev->id].membase = NULL; in bcm_uart_probe()
876 ports[pdev->id].membase = NULL; in bcm_uart_remove()
881 { .compatible = "brcm,bcm6345-uart" },
923 MODULE_DESCRIPTION("Broadcom 63xx integrated uart driver");