Lines Matching +full:bcm7271 +full:- +full:uart

1 // SPDX-License-Identifier: GPL-2.0-only
4 * 8250-core based driver for Broadcom ns16550a UARTs
20 #include <linux/dma-mapping.h>
28 /* Register definitions for UART DMA block. Version 1.1 or later. */
157 #define UDMA_RX_BUFS_REG_OFFSET (UDMA_RX_BUF1_PTR_LO - UDMA_RX_BUF0_PTR_LO)
169 #define UDMA_TX_BUFS_REG_OFFSET (UDMA_TX_BUF1_PTR_LO - UDMA_TX_BUF0_PTR_LO)
251 return readl(priv->regs[reg_type] + offset); in udma_readl()
257 writel(value, priv->regs[reg_type] + offset); in udma_writel()
263 void __iomem *reg = priv->regs[reg_type] + offset; in udma_set()
274 void __iomem *reg = priv->regs[reg_type] + offset; in udma_unset()
283 * The UART DMA engine hardware can be used by multiple UARTS, but
285 * the first UART to request the DMA engine will get it and any
305 if (waits-- == 0) in brcmuart_arbitration()
339 daddr = priv->rx_addr; in brcmuart_init_dma_hardware()
352 daddr = priv->tx_addr; in brcmuart_init_dma_hardware()
369 struct brcmuart_priv *priv = p->port.private_data; in start_rx_dma()
382 priv->rx_next_buf = 0; in start_rx_dma()
385 priv->rx_running = true; in start_rx_dma()
390 struct brcmuart_priv *priv = p->port.private_data; in stop_rx_dma()
393 if (priv->rx_running) in stop_rx_dma()
399 struct brcmuart_priv *priv = p->port.private_data; in stop_tx_dma()
406 priv->tx_running = false; in stop_tx_dma()
416 struct brcmuart_priv *priv = p->port.private_data; in brcmuart_tx_dma()
417 struct circ_buf *xmit = &p->port.state->xmit; in brcmuart_tx_dma()
420 if (uart_tx_stopped(&p->port) || priv->tx_running || in brcmuart_tx_dma()
424 tx_size = CIRC_CNT_TO_END(xmit->head, xmit->tail, UART_XMIT_SIZE); in brcmuart_tx_dma()
426 priv->dma.tx_err = 0; in brcmuart_tx_dma()
427 memcpy(priv->tx_buf, &xmit->buf[xmit->tail], tx_size); in brcmuart_tx_dma()
428 uart_xmit_advance(&p->port, tx_size); in brcmuart_tx_dma()
431 uart_write_wakeup(&p->port); in brcmuart_tx_dma()
437 priv->tx_running = true; in brcmuart_tx_dma()
444 struct brcmuart_priv *priv = up->private_data; in brcmuart_rx_buf_done_isr()
445 struct tty_port *tty_port = &up->state->port; in brcmuart_rx_buf_done_isr()
455 dev_err(up->dev, "RX done interrupt but DATA_RDY not found\n"); in brcmuart_rx_buf_done_isr()
462 up->icount.overrun++; in brcmuart_rx_buf_done_isr()
463 dev_warn(up->dev, "RX OVERRUN Error\n"); in brcmuart_rx_buf_done_isr()
466 up->icount.frame++; in brcmuart_rx_buf_done_isr()
467 dev_warn(up->dev, "RX FRAMING Error\n"); in brcmuart_rx_buf_done_isr()
470 up->icount.parity++; in brcmuart_rx_buf_done_isr()
471 dev_warn(up->dev, "RX PARITY Error\n"); in brcmuart_rx_buf_done_isr()
476 priv->rx_bufs + (index * RX_BUF_SIZE), in brcmuart_rx_buf_done_isr()
479 dev_warn(up->dev, "Flip buffer overrun of %d bytes\n", in brcmuart_rx_buf_done_isr()
480 length - copied); in brcmuart_rx_buf_done_isr()
481 up->icount.overrun += length - copied; in brcmuart_rx_buf_done_isr()
483 up->icount.rx += length; in brcmuart_rx_buf_done_isr()
485 priv->dma_rx_partial_buf++; in brcmuart_rx_buf_done_isr()
491 priv->rx_missing_close_timeout++; in brcmuart_rx_buf_done_isr()
493 priv->dma_rx_full_buf++; in brcmuart_rx_buf_done_isr()
500 struct brcmuart_priv *priv = up->private_data; in brcmuart_rx_isr()
501 struct device *dev = up->dev; in brcmuart_rx_isr()
507 check_isr = UDMA_INTR_RX_READY_BUF0 << priv->rx_next_buf; in brcmuart_rx_isr()
509 brcmuart_rx_buf_done_isr(up, priv->rx_next_buf); in brcmuart_rx_isr()
518 priv->rx_err++; in brcmuart_rx_isr()
520 priv->rx_timeout++; in brcmuart_rx_isr()
524 priv->rx_abort++; in brcmuart_rx_isr()
525 priv->rx_running = false; in brcmuart_rx_isr()
527 /* If not ABORT, re-enable RX buffer */ in brcmuart_rx_isr()
530 UDMA_RX_BUFx_STATUS(priv->rx_next_buf), in brcmuart_rx_isr()
533 priv->rx_next_buf++; in brcmuart_rx_isr()
534 if (priv->rx_next_buf == RX_BUFS_COUNT) in brcmuart_rx_isr()
535 priv->rx_next_buf = 0; in brcmuart_rx_isr()
541 struct brcmuart_priv *priv = up->private_data; in brcmuart_tx_isr()
542 struct device *dev = up->dev; in brcmuart_tx_isr()
544 struct circ_buf *xmit = &port_8250->port.state->xmit; in brcmuart_tx_isr()
547 if (priv->tx_running) in brcmuart_tx_isr()
551 priv->tx_running = false; in brcmuart_tx_isr()
559 struct device *dev = up->dev; in brcmuart_isr()
560 struct brcmuart_priv *priv = up->private_data; in brcmuart_isr()
592 struct brcmuart_priv *priv = up->port.private_data; in brcmuart_startup()
594 priv->shutdown = false; in brcmuart_startup()
597 * prevent serial8250_do_startup() from allocating non-existent in brcmuart_startup()
600 up->dma = NULL; in brcmuart_startup()
603 if (!priv->dma_enabled) in brcmuart_startup()
612 up->ier &= ~UART_IER_RDI; in brcmuart_startup()
613 serial_port_out(port, UART_IER, up->ier); in brcmuart_startup()
616 priv->tx_running = false; in brcmuart_startup()
617 priv->dma.rx_dma = NULL; in brcmuart_startup()
618 priv->dma.tx_dma = brcmuart_tx_dma; in brcmuart_startup()
619 up->dma = &priv->dma; in brcmuart_startup()
629 struct brcmuart_priv *priv = up->port.private_data; in brcmuart_shutdown()
633 priv->shutdown = true; in brcmuart_shutdown()
634 if (priv->dma_enabled) { in brcmuart_shutdown()
646 up->dma = NULL; in brcmuart_shutdown()
661 priv->default_mux_rate = clk_get_rate(priv->baud_mux_clk); in init_real_clk_rates()
662 for (x = 0; x < ARRAY_SIZE(priv->real_rates); x++) { in init_real_clk_rates()
663 if (priv->rate_table[x] == 0) { in init_real_clk_rates()
664 priv->real_rates[x] = 0; in init_real_clk_rates()
667 rc = clk_set_rate(priv->baud_mux_clk, priv->rate_table[x]); in init_real_clk_rates()
670 priv->rate_table[x]); in init_real_clk_rates()
671 priv->real_rates[x] = priv->rate_table[x]; in init_real_clk_rates()
673 priv->real_rates[x] = clk_get_rate(priv->baud_mux_clk); in init_real_clk_rates()
676 clk_set_rate(priv->baud_mux_clk, priv->default_mux_rate); in init_real_clk_rates()
687 int best_index = -1; in set_clock_mux()
696 if (priv->baud_mux_clk == NULL) in set_clock_mux()
700 for (i = 0; i < ARRAY_SIZE(priv->real_rates); i++) { in set_clock_mux()
701 if (priv->real_rates[i] == 0) in set_clock_mux()
703 rate = priv->real_rates[i] / 16; in set_clock_mux()
716 hires_err = (hires_err - hires_baud); in set_clock_mux()
718 hires_err = (hires_baud - hires_err); in set_clock_mux()
721 dev_dbg(up->dev, in set_clock_mux()
723 baud, priv->real_rates[i], percent / 100, in set_clock_mux()
731 if (best_index == -1) { in set_clock_mux()
732 dev_err(up->dev, "Error, %d BAUD rate is too fast.\n", baud); in set_clock_mux()
735 rate = priv->real_rates[best_index]; in set_clock_mux()
736 rc = clk_set_rate(priv->baud_mux_clk, rate); in set_clock_mux()
738 dev_err(up->dev, "Error selecting BAUD MUX clock\n"); in set_clock_mux()
742 dev_err(up->dev, "Error, baud: %d has %u.%u%% error\n", in set_clock_mux()
746 dev_dbg(up->dev, "Selecting BAUD MUX rate: %u\n", rate); in set_clock_mux()
747 dev_dbg(up->dev, "Requested baud: %u, Actual baud: %u\n", in set_clock_mux()
753 priv->char_wait = ns_to_ktime(i); in set_clock_mux()
755 up->uartclk = rate; in set_clock_mux()
763 struct brcmuart_priv *priv = up->private_data; in brcmstb_set_termios()
765 if (priv->dma_enabled) in brcmstb_set_termios()
769 if (p8250->mcr & UART_MCR_AFE) in brcmstb_set_termios()
770 p8250->port.status |= UPSTAT_AUTOCTS; in brcmstb_set_termios()
771 if (priv->dma_enabled) in brcmstb_set_termios()
778 struct brcmuart_priv *priv = p->private_data; in brcmuart_handle_irq()
790 if (((iir & UART_IIR_ID) == UART_IIR_RX_TIMEOUT) && !(priv->shutdown)) { in brcmuart_handle_irq()
802 if ((ier & UART_IER_RDI) && (up->mcr & UART_MCR_AFE)) { in brcmuart_handle_irq()
808 hrtimer_start(&priv->hrt, priv->char_wait, in brcmuart_handle_irq()
826 struct uart_port *p = priv->up; in brcmuart_hrtimer_func()
831 if (priv->shutdown) in brcmuart_hrtimer_func()
843 priv->rx_bad_timeout_no_char++; in brcmuart_hrtimer_func()
845 priv->rx_bad_timeout_late_char++; in brcmuart_hrtimer_func()
848 /* re-enable receive unless upper layer has disabled it */ in brcmuart_hrtimer_func()
849 if ((up->ier & (UART_IER_RLSI | UART_IER_RDI)) == in brcmuart_hrtimer_func()
864 .compatible = "brcm,bcm7278-uart",
868 .compatible = "brcm,bcm7271-uart",
878 if (priv->rx_bufs) in brcmuart_free_bufs()
879 dma_free_coherent(dev, priv->rx_size, priv->rx_bufs, in brcmuart_free_bufs()
880 priv->rx_addr); in brcmuart_free_bufs()
881 if (priv->tx_buf) in brcmuart_free_bufs()
882 dma_free_coherent(dev, priv->tx_size, priv->tx_buf, in brcmuart_free_bufs()
883 priv->tx_addr); in brcmuart_free_bufs()
888 struct brcmuart_priv *priv = port->private_data; in brcmuart_throttle()
895 struct brcmuart_priv *priv = port->private_data; in brcmuart_unthrottle()
903 struct brcmuart_priv *priv = s->private; in debugfs_stats_show()
906 priv->rx_err); in debugfs_stats_show()
908 priv->rx_timeout); in debugfs_stats_show()
910 priv->rx_abort); in debugfs_stats_show()
912 priv->rx_bad_timeout_late_char); in debugfs_stats_show()
914 priv->rx_bad_timeout_no_char); in debugfs_stats_show()
916 priv->rx_missing_close_timeout); in debugfs_stats_show()
917 if (priv->dma_enabled) { in debugfs_stats_show()
919 priv->dma_rx_partial_buf); in debugfs_stats_show()
921 priv->dma_rx_full_buf); in debugfs_stats_show()
930 priv->debugfs_dir = debugfs_create_dir(device, brcmuart_debugfs_root); in brcmuart_init_debugfs()
931 debugfs_create_file("stats", 0444, priv->debugfs_dir, priv, in brcmuart_init_debugfs()
939 struct device_node *np = pdev->dev.of_node; in brcmuart_probe()
942 struct device *dev = &pdev->dev; in brcmuart_probe()
954 "uart", "dma_rx", "dma_tx", "dma_intr2", "dma_arb" in brcmuart_probe()
963 return -ENOMEM; in brcmuart_probe()
966 if (!of_id || !of_id->data) in brcmuart_probe()
967 priv->rate_table = brcmstb_rate_table; in brcmuart_probe()
969 priv->rate_table = of_id->data; in brcmuart_probe()
976 priv->regs[x] = devm_ioremap(dev, regs->start, in brcmuart_probe()
978 if (!priv->regs[x]) in brcmuart_probe()
979 return -ENOMEM; in brcmuart_probe()
981 mapbase = regs->start; in brcmuart_probe()
982 membase = priv->regs[x]; in brcmuart_probe()
986 /* We should have just the uart base registers or all the registers */ in brcmuart_probe()
988 return dev_err_probe(dev, -EINVAL, "%s registers not specified\n", in brcmuart_probe()
1003 priv->dma_enabled = true; in brcmuart_probe()
1011 "Timeout arbitrating for UART DMA hardware\n"); in brcmuart_probe()
1015 of_property_read_u32(np, "clock-frequency", &clk_rate); in brcmuart_probe()
1025 priv->baud_mux_clk = baud_mux_clk; in brcmuart_probe()
1027 clk_rate = priv->default_mux_rate; in brcmuart_probe()
1033 ret = dev_err_probe(dev, -EINVAL, "clock-frequency or clk not defined\n"); in brcmuart_probe()
1037 dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not "); in brcmuart_probe()
1061 hrtimer_init(&priv->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in brcmuart_probe()
1062 priv->hrt.function = brcmuart_hrtimer_func; in brcmuart_probe()
1070 if (priv->dma_enabled) { in brcmuart_probe()
1071 priv->rx_size = RX_BUF_SIZE * RX_BUFS_COUNT; in brcmuart_probe()
1072 priv->rx_bufs = dma_alloc_coherent(dev, in brcmuart_probe()
1073 priv->rx_size, in brcmuart_probe()
1074 &priv->rx_addr, GFP_KERNEL); in brcmuart_probe()
1075 if (!priv->rx_bufs) { in brcmuart_probe()
1076 ret = -ENOMEM; in brcmuart_probe()
1079 priv->tx_size = UART_XMIT_SIZE; in brcmuart_probe()
1080 priv->tx_buf = dma_alloc_coherent(dev, in brcmuart_probe()
1081 priv->tx_size, in brcmuart_probe()
1082 &priv->tx_addr, GFP_KERNEL); in brcmuart_probe()
1083 if (!priv->tx_buf) { in brcmuart_probe()
1084 ret = -ENOMEM; in brcmuart_probe()
1094 priv->line = ret; in brcmuart_probe()
1096 priv->up = &new_port->port; in brcmuart_probe()
1097 if (priv->dma_enabled) { in brcmuart_probe()
1104 IRQF_SHARED, "uart DMA irq", &new_port->port); in brcmuart_probe()
1111 brcmuart_init_debugfs(priv, dev_name(&pdev->dev)); in brcmuart_probe()
1115 serial8250_unregister_port(priv->line); in brcmuart_probe()
1119 if (priv->dma_enabled) in brcmuart_probe()
1128 debugfs_remove_recursive(priv->debugfs_dir); in brcmuart_remove()
1129 hrtimer_cancel(&priv->hrt); in brcmuart_remove()
1130 serial8250_unregister_port(priv->line); in brcmuart_remove()
1131 brcmuart_free_bufs(&pdev->dev, priv); in brcmuart_remove()
1132 if (priv->dma_enabled) in brcmuart_remove()
1139 struct uart_8250_port *up = serial8250_get_port(priv->line); in brcmuart_suspend()
1140 struct uart_port *port = &up->port; in brcmuart_suspend()
1148 priv->saved_mctrl = port->mctrl; in brcmuart_suspend()
1149 port->mctrl &= ~TIOCM_RTS; in brcmuart_suspend()
1152 serial8250_suspend_port(priv->line); in brcmuart_suspend()
1153 clk_disable_unprepare(priv->baud_mux_clk); in brcmuart_suspend()
1161 struct uart_8250_port *up = serial8250_get_port(priv->line); in brcmuart_resume()
1162 struct uart_port *port = &up->port; in brcmuart_resume()
1166 ret = clk_prepare_enable(priv->baud_mux_clk); in brcmuart_resume()
1174 ret = clk_set_rate(priv->baud_mux_clk, priv->default_mux_rate); in brcmuart_resume()
1177 if (priv->dma_enabled) { in brcmuart_resume()
1180 return(-EBUSY); in brcmuart_resume()
1183 start_rx_dma(serial8250_get_port(priv->line)); in brcmuart_resume()
1185 serial8250_resume_port(priv->line); in brcmuart_resume()
1187 if (priv->saved_mctrl & TIOCM_RTS) { in brcmuart_resume()
1190 port->mctrl |= TIOCM_RTS; in brcmuart_resume()
1191 port->ops->set_mctrl(port, port->mctrl); in brcmuart_resume()
1204 .name = "bcm7271-uart",