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>
29 /* Register definitions for UART DMA block. Version 1.1 or later. */
158 #define UDMA_RX_BUFS_REG_OFFSET (UDMA_RX_BUF1_PTR_LO - UDMA_RX_BUF0_PTR_LO)
170 #define UDMA_TX_BUFS_REG_OFFSET (UDMA_TX_BUF1_PTR_LO - UDMA_TX_BUF0_PTR_LO)
250 return readl(priv->regs[reg_type] + offset); in udma_readl()
256 writel(value, priv->regs[reg_type] + offset); in udma_writel()
262 void __iomem *reg = priv->regs[reg_type] + offset; in udma_set()
273 void __iomem *reg = priv->regs[reg_type] + offset; in udma_unset()
282 * The UART DMA engine hardware can be used by multiple UARTS, but
284 * the first UART to request the DMA engine will get it and any
304 if (waits-- == 0) in brcmuart_arbitration()
338 daddr = priv->rx_addr; in brcmuart_init_dma_hardware()
351 daddr = priv->tx_addr; in brcmuart_init_dma_hardware()
368 struct brcmuart_priv *priv = p->port.private_data; in start_rx_dma()
381 priv->rx_next_buf = 0; in start_rx_dma()
384 priv->rx_running = true; in start_rx_dma()
389 struct brcmuart_priv *priv = p->port.private_data; in stop_rx_dma()
392 if (priv->rx_running) in stop_rx_dma()
398 struct brcmuart_priv *priv = p->port.private_data; in stop_tx_dma()
405 priv->tx_running = false; in stop_tx_dma()
415 struct brcmuart_priv *priv = p->port.private_data; in brcmuart_tx_dma()
416 struct tty_port *tport = &p->port.state->port; in brcmuart_tx_dma()
419 if (uart_tx_stopped(&p->port) || priv->tx_running || in brcmuart_tx_dma()
420 kfifo_is_empty(&tport->xmit_fifo)) { in brcmuart_tx_dma()
424 priv->dma.tx_err = 0; in brcmuart_tx_dma()
425 tx_size = uart_fifo_out(&p->port, priv->tx_buf, UART_XMIT_SIZE); in brcmuart_tx_dma()
427 if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) in brcmuart_tx_dma()
428 uart_write_wakeup(&p->port); in brcmuart_tx_dma()
434 priv->tx_running = true; in brcmuart_tx_dma()
441 struct brcmuart_priv *priv = up->private_data; in brcmuart_rx_buf_done_isr()
442 struct tty_port *tty_port = &up->state->port; in brcmuart_rx_buf_done_isr()
452 dev_err(up->dev, "RX done interrupt but DATA_RDY not found\n"); in brcmuart_rx_buf_done_isr()
459 up->icount.overrun++; in brcmuart_rx_buf_done_isr()
460 dev_warn(up->dev, "RX OVERRUN Error\n"); in brcmuart_rx_buf_done_isr()
463 up->icount.frame++; in brcmuart_rx_buf_done_isr()
464 dev_warn(up->dev, "RX FRAMING Error\n"); in brcmuart_rx_buf_done_isr()
467 up->icount.parity++; in brcmuart_rx_buf_done_isr()
468 dev_warn(up->dev, "RX PARITY Error\n"); in brcmuart_rx_buf_done_isr()
473 priv->rx_bufs + (index * RX_BUF_SIZE), in brcmuart_rx_buf_done_isr()
476 dev_warn(up->dev, "Flip buffer overrun of %d bytes\n", in brcmuart_rx_buf_done_isr()
477 length - copied); in brcmuart_rx_buf_done_isr()
478 up->icount.overrun += length - copied; in brcmuart_rx_buf_done_isr()
480 up->icount.rx += length; in brcmuart_rx_buf_done_isr()
482 priv->dma_rx_partial_buf++; in brcmuart_rx_buf_done_isr()
488 priv->rx_missing_close_timeout++; in brcmuart_rx_buf_done_isr()
490 priv->dma_rx_full_buf++; in brcmuart_rx_buf_done_isr()
497 struct brcmuart_priv *priv = up->private_data; in brcmuart_rx_isr()
498 struct device *dev = up->dev; in brcmuart_rx_isr()
504 check_isr = UDMA_INTR_RX_READY_BUF0 << priv->rx_next_buf; in brcmuart_rx_isr()
506 brcmuart_rx_buf_done_isr(up, priv->rx_next_buf); in brcmuart_rx_isr()
515 priv->rx_err++; in brcmuart_rx_isr()
517 priv->rx_timeout++; in brcmuart_rx_isr()
521 priv->rx_abort++; in brcmuart_rx_isr()
522 priv->rx_running = false; in brcmuart_rx_isr()
524 /* If not ABORT, re-enable RX buffer */ in brcmuart_rx_isr()
527 UDMA_RX_BUFx_STATUS(priv->rx_next_buf), in brcmuart_rx_isr()
530 priv->rx_next_buf++; in brcmuart_rx_isr()
531 if (priv->rx_next_buf == RX_BUFS_COUNT) in brcmuart_rx_isr()
532 priv->rx_next_buf = 0; in brcmuart_rx_isr()
538 struct brcmuart_priv *priv = up->private_data; in brcmuart_tx_isr()
539 struct device *dev = up->dev; in brcmuart_tx_isr()
541 struct tty_port *tport = &port_8250->port.state->port; in brcmuart_tx_isr()
544 if (priv->tx_running) in brcmuart_tx_isr()
548 priv->tx_running = false; in brcmuart_tx_isr()
549 if (!kfifo_is_empty(&tport->xmit_fifo) && !uart_tx_stopped(up)) in brcmuart_tx_isr()
556 struct device *dev = up->dev; in brcmuart_isr()
557 struct brcmuart_priv *priv = up->private_data; in brcmuart_isr()
589 struct brcmuart_priv *priv = up->port.private_data; in brcmuart_startup()
591 priv->shutdown = false; in brcmuart_startup()
594 * prevent serial8250_do_startup() from allocating non-existent in brcmuart_startup()
597 up->dma = NULL; in brcmuart_startup()
600 if (!priv->dma_enabled) in brcmuart_startup()
609 up->ier &= ~UART_IER_RDI; in brcmuart_startup()
610 serial_port_out(port, UART_IER, up->ier); in brcmuart_startup()
613 priv->tx_running = false; in brcmuart_startup()
614 priv->dma.rx_dma = NULL; in brcmuart_startup()
615 priv->dma.tx_dma = brcmuart_tx_dma; in brcmuart_startup()
616 up->dma = &priv->dma; in brcmuart_startup()
626 struct brcmuart_priv *priv = up->port.private_data; in brcmuart_shutdown()
630 priv->shutdown = true; in brcmuart_shutdown()
631 if (priv->dma_enabled) { in brcmuart_shutdown()
643 up->dma = NULL; in brcmuart_shutdown()
658 priv->default_mux_rate = clk_get_rate(priv->baud_mux_clk); in init_real_clk_rates()
659 for (x = 0; x < ARRAY_SIZE(priv->real_rates); x++) { in init_real_clk_rates()
660 if (priv->rate_table[x] == 0) { in init_real_clk_rates()
661 priv->real_rates[x] = 0; in init_real_clk_rates()
664 rc = clk_set_rate(priv->baud_mux_clk, priv->rate_table[x]); in init_real_clk_rates()
667 priv->rate_table[x]); in init_real_clk_rates()
668 priv->real_rates[x] = priv->rate_table[x]; in init_real_clk_rates()
670 priv->real_rates[x] = clk_get_rate(priv->baud_mux_clk); in init_real_clk_rates()
673 clk_set_rate(priv->baud_mux_clk, priv->default_mux_rate); in init_real_clk_rates()
695 hires_err = (hires_rate - hires_baud); in find_quot()
697 hires_err = (hires_baud - hires_rate); in find_quot()
721 if (priv->baud_mux_clk == NULL) in set_clock_mux()
725 quot = find_quot(up->dev, priv->default_mux_rate, baud, &percent); in set_clock_mux()
728 best_freq = priv->default_mux_rate; in set_clock_mux()
733 for (i = 0; i < ARRAY_SIZE(priv->real_rates); i++) { in set_clock_mux()
734 freq = priv->real_rates[i]; in set_clock_mux()
735 if (freq == 0 || freq == priv->default_mux_rate) in set_clock_mux()
737 quot = find_quot(up->dev, freq, baud, &percent); in set_clock_mux()
749 dev_err(up->dev, "Error, %d BAUD rate is too fast.\n", baud); in set_clock_mux()
752 rc = clk_set_rate(priv->baud_mux_clk, best_freq); in set_clock_mux()
754 dev_err(up->dev, "Error selecting BAUD MUX clock\n"); in set_clock_mux()
758 dev_err(up->dev, "Error, baud: %d has %u.%u%% error\n", in set_clock_mux()
762 dev_dbg(up->dev, "Selecting BAUD MUX rate: %u\n", best_freq); in set_clock_mux()
763 dev_dbg(up->dev, "Requested baud: %u, Actual baud: %u\n", in set_clock_mux()
769 priv->char_wait = ns_to_ktime(i); in set_clock_mux()
771 up->uartclk = best_freq; in set_clock_mux()
779 struct brcmuart_priv *priv = up->private_data; in brcmstb_set_termios()
781 if (priv->dma_enabled) in brcmstb_set_termios()
785 if (p8250->mcr & UART_MCR_AFE) in brcmstb_set_termios()
786 p8250->port.status |= UPSTAT_AUTOCTS; in brcmstb_set_termios()
787 if (priv->dma_enabled) in brcmstb_set_termios()
794 struct brcmuart_priv *priv = p->private_data; in brcmuart_handle_irq()
806 if (((iir & UART_IIR_ID) == UART_IIR_RX_TIMEOUT) && !(priv->shutdown)) { in brcmuart_handle_irq()
818 if ((ier & UART_IER_RDI) && (up->mcr & UART_MCR_AFE)) { in brcmuart_handle_irq()
824 hrtimer_start(&priv->hrt, priv->char_wait, in brcmuart_handle_irq()
842 struct uart_port *p = priv->up; in brcmuart_hrtimer_func()
847 if (priv->shutdown) in brcmuart_hrtimer_func()
859 priv->rx_bad_timeout_no_char++; in brcmuart_hrtimer_func()
861 priv->rx_bad_timeout_late_char++; in brcmuart_hrtimer_func()
864 /* re-enable receive unless upper layer has disabled it */ in brcmuart_hrtimer_func()
865 if ((up->ier & (UART_IER_RLSI | UART_IER_RDI)) == in brcmuart_hrtimer_func()
880 .compatible = "brcm,bcm7278-uart",
884 .compatible = "brcm,bcm7271-uart",
894 if (priv->rx_bufs) in brcmuart_free_bufs()
895 dma_free_coherent(dev, priv->rx_size, priv->rx_bufs, in brcmuart_free_bufs()
896 priv->rx_addr); in brcmuart_free_bufs()
897 if (priv->tx_buf) in brcmuart_free_bufs()
898 dma_free_coherent(dev, priv->tx_size, priv->tx_buf, in brcmuart_free_bufs()
899 priv->tx_addr); in brcmuart_free_bufs()
904 struct brcmuart_priv *priv = port->private_data; in brcmuart_throttle()
911 struct brcmuart_priv *priv = port->private_data; in brcmuart_unthrottle()
919 struct brcmuart_priv *priv = s->private; in debugfs_stats_show()
922 priv->rx_err); in debugfs_stats_show()
924 priv->rx_timeout); in debugfs_stats_show()
926 priv->rx_abort); in debugfs_stats_show()
928 priv->rx_bad_timeout_late_char); in debugfs_stats_show()
930 priv->rx_bad_timeout_no_char); in debugfs_stats_show()
932 priv->rx_missing_close_timeout); in debugfs_stats_show()
933 if (priv->dma_enabled) { in debugfs_stats_show()
935 priv->dma_rx_partial_buf); in debugfs_stats_show()
937 priv->dma_rx_full_buf); in debugfs_stats_show()
946 priv->debugfs_dir = debugfs_create_dir(device, brcmuart_debugfs_root); in brcmuart_init_debugfs()
947 debugfs_create_file("stats", 0444, priv->debugfs_dir, priv, in brcmuart_init_debugfs()
957 struct device *dev = &pdev->dev; in brcmuart_probe()
967 "uart", "dma_rx", "dma_tx", "dma_intr2", "dma_arb" in brcmuart_probe()
973 return -ENOMEM; in brcmuart_probe()
975 of_id = of_match_node(brcmuart_dt_ids, dev->of_node); in brcmuart_probe()
976 if (!of_id || !of_id->data) in brcmuart_probe()
977 priv->rate_table = brcmstb_rate_table; in brcmuart_probe()
979 priv->rate_table = of_id->data; in brcmuart_probe()
986 priv->regs[x] = devm_ioremap(dev, regs->start, in brcmuart_probe()
988 if (!priv->regs[x]) in brcmuart_probe()
989 return -ENOMEM; in brcmuart_probe()
991 mapbase = regs->start; in brcmuart_probe()
992 membase = priv->regs[x]; in brcmuart_probe()
996 /* We should have just the uart base registers or all the registers */ in brcmuart_probe()
998 return dev_err_probe(dev, -EINVAL, "%s registers not specified\n", in brcmuart_probe()
1013 priv->dma_enabled = true; in brcmuart_probe()
1021 "Timeout arbitrating for UART DMA hardware\n"); in brcmuart_probe()
1025 dev_dbg(dev, "DMA is %senabled\n", priv->dma_enabled ? "" : "not "); in brcmuart_probe()
1051 priv->baud_mux_clk = baud_mux_clk; in brcmuart_probe()
1053 up.port.uartclk = priv->default_mux_rate; in brcmuart_probe()
1059 hrtimer_init(&priv->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in brcmuart_probe()
1060 priv->hrt.function = brcmuart_hrtimer_func; in brcmuart_probe()
1068 if (priv->dma_enabled) { in brcmuart_probe()
1069 priv->rx_size = RX_BUF_SIZE * RX_BUFS_COUNT; in brcmuart_probe()
1070 priv->rx_bufs = dma_alloc_coherent(dev, in brcmuart_probe()
1071 priv->rx_size, in brcmuart_probe()
1072 &priv->rx_addr, GFP_KERNEL); in brcmuart_probe()
1073 if (!priv->rx_bufs) { in brcmuart_probe()
1074 ret = -ENOMEM; in brcmuart_probe()
1077 priv->tx_size = UART_XMIT_SIZE; in brcmuart_probe()
1078 priv->tx_buf = dma_alloc_coherent(dev, in brcmuart_probe()
1079 priv->tx_size, in brcmuart_probe()
1080 &priv->tx_addr, GFP_KERNEL); in brcmuart_probe()
1081 if (!priv->tx_buf) { in brcmuart_probe()
1082 ret = -ENOMEM; in brcmuart_probe()
1092 priv->line = ret; in brcmuart_probe()
1094 priv->up = &new_port->port; in brcmuart_probe()
1095 if (priv->dma_enabled) { in brcmuart_probe()
1102 IRQF_SHARED, "uart DMA irq", &new_port->port); in brcmuart_probe()
1109 brcmuart_init_debugfs(priv, dev_name(&pdev->dev)); in brcmuart_probe()
1113 serial8250_unregister_port(priv->line); in brcmuart_probe()
1117 if (priv->dma_enabled) in brcmuart_probe()
1126 debugfs_remove_recursive(priv->debugfs_dir); in brcmuart_remove()
1127 hrtimer_cancel(&priv->hrt); in brcmuart_remove()
1128 serial8250_unregister_port(priv->line); in brcmuart_remove()
1129 brcmuart_free_bufs(&pdev->dev, priv); in brcmuart_remove()
1130 if (priv->dma_enabled) in brcmuart_remove()
1137 struct uart_8250_port *up = serial8250_get_port(priv->line); in brcmuart_suspend()
1138 struct uart_port *port = &up->port; in brcmuart_suspend()
1146 priv->saved_mctrl = port->mctrl; in brcmuart_suspend()
1147 port->mctrl &= ~TIOCM_RTS; in brcmuart_suspend()
1150 serial8250_suspend_port(priv->line); in brcmuart_suspend()
1151 clk_disable_unprepare(priv->baud_mux_clk); in brcmuart_suspend()
1159 struct uart_8250_port *up = serial8250_get_port(priv->line); in brcmuart_resume()
1160 struct uart_port *port = &up->port; in brcmuart_resume()
1164 ret = clk_prepare_enable(priv->baud_mux_clk); in brcmuart_resume()
1172 ret = clk_set_rate(priv->baud_mux_clk, priv->default_mux_rate); in brcmuart_resume()
1175 if (priv->dma_enabled) { in brcmuart_resume()
1178 return(-EBUSY); in brcmuart_resume()
1181 start_rx_dma(serial8250_get_port(priv->line)); in brcmuart_resume()
1183 serial8250_resume_port(priv->line); in brcmuart_resume()
1185 if (priv->saved_mctrl & TIOCM_RTS) { in brcmuart_resume()
1188 port->mctrl |= TIOCM_RTS; in brcmuart_resume()
1189 port->ops->set_mctrl(port, port->mctrl); in brcmuart_resume()
1202 .name = "bcm7271-uart",