| .. | .. |
|---|
| 809 | 809 | struct lpuart_port, port); |
|---|
| 810 | 810 | unsigned long stat = lpuart32_read(port, UARTSTAT); |
|---|
| 811 | 811 | unsigned long sfifo = lpuart32_read(port, UARTFIFO); |
|---|
| 812 | + unsigned long ctrl = lpuart32_read(port, UARTCTRL); |
|---|
| 812 | 813 | |
|---|
| 813 | 814 | if (sport->dma_tx_in_progress) |
|---|
| 814 | 815 | return 0; |
|---|
| 815 | 816 | |
|---|
| 816 | | - if (stat & UARTSTAT_TC && sfifo & UARTFIFO_TXEMPT) |
|---|
| 817 | + /* |
|---|
| 818 | + * LPUART Transmission Complete Flag may never be set while queuing a break |
|---|
| 819 | + * character, so avoid checking for transmission complete when UARTCTRL_SBK |
|---|
| 820 | + * is asserted. |
|---|
| 821 | + */ |
|---|
| 822 | + if ((stat & UARTSTAT_TC && sfifo & UARTFIFO_TXEMPT) || ctrl & UARTCTRL_SBK) |
|---|
| 817 | 823 | return TIOCSER_TEMT; |
|---|
| 818 | 824 | |
|---|
| 819 | 825 | return 0; |
|---|
| .. | .. |
|---|
| 1056 | 1062 | unsigned long sr = lpuart32_read(&sport->port, UARTSTAT); |
|---|
| 1057 | 1063 | |
|---|
| 1058 | 1064 | if (sr & (UARTSTAT_PE | UARTSTAT_FE)) { |
|---|
| 1059 | | - /* Read DR to clear the error flags */ |
|---|
| 1060 | | - lpuart32_read(&sport->port, UARTDATA); |
|---|
| 1065 | + /* Clear the error flags */ |
|---|
| 1066 | + lpuart32_write(&sport->port, sr, UARTSTAT); |
|---|
| 1061 | 1067 | |
|---|
| 1062 | 1068 | if (sr & UARTSTAT_PE) |
|---|
| 1063 | 1069 | sport->port.icount.parity++; |
|---|
| .. | .. |
|---|
| 1214 | 1220 | * 10ms at any baud rate. |
|---|
| 1215 | 1221 | */ |
|---|
| 1216 | 1222 | sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits / 1000) * 2; |
|---|
| 1217 | | - sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1)); |
|---|
| 1223 | + sport->rx_dma_rng_buf_len = (1 << fls(sport->rx_dma_rng_buf_len)); |
|---|
| 1218 | 1224 | if (sport->rx_dma_rng_buf_len < 16) |
|---|
| 1219 | 1225 | sport->rx_dma_rng_buf_len = 16; |
|---|
| 1220 | 1226 | |
|---|
| .. | .. |
|---|
| 1278 | 1284 | struct dma_chan *chan = sport->dma_rx_chan; |
|---|
| 1279 | 1285 | |
|---|
| 1280 | 1286 | dmaengine_terminate_all(chan); |
|---|
| 1287 | + del_timer_sync(&sport->lpuart_timer); |
|---|
| 1281 | 1288 | dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE); |
|---|
| 1282 | 1289 | kfree(sport->rx_ring.buf); |
|---|
| 1283 | 1290 | sport->rx_ring.tail = 0; |
|---|
| .. | .. |
|---|
| 1450 | 1457 | { |
|---|
| 1451 | 1458 | unsigned long temp; |
|---|
| 1452 | 1459 | |
|---|
| 1453 | | - temp = lpuart32_read(port, UARTCTRL) & ~UARTCTRL_SBK; |
|---|
| 1460 | + temp = lpuart32_read(port, UARTCTRL); |
|---|
| 1454 | 1461 | |
|---|
| 1455 | | - if (break_state != 0) |
|---|
| 1456 | | - temp |= UARTCTRL_SBK; |
|---|
| 1457 | | - |
|---|
| 1458 | | - lpuart32_write(port, temp, UARTCTRL); |
|---|
| 1462 | + /* |
|---|
| 1463 | + * LPUART IP now has two known bugs, one is CTS has higher priority than the |
|---|
| 1464 | + * break signal, which causes the break signal sending through UARTCTRL_SBK |
|---|
| 1465 | + * may impacted by the CTS input if the HW flow control is enabled. It |
|---|
| 1466 | + * exists on all platforms we support in this driver. |
|---|
| 1467 | + * Another bug is i.MX8QM LPUART may have an additional break character |
|---|
| 1468 | + * being sent after SBK was cleared. |
|---|
| 1469 | + * To avoid above two bugs, we use Transmit Data Inversion function to send |
|---|
| 1470 | + * the break signal instead of UARTCTRL_SBK. |
|---|
| 1471 | + */ |
|---|
| 1472 | + if (break_state != 0) { |
|---|
| 1473 | + /* |
|---|
| 1474 | + * Disable the transmitter to prevent any data from being sent out |
|---|
| 1475 | + * during break, then invert the TX line to send break. |
|---|
| 1476 | + */ |
|---|
| 1477 | + temp &= ~UARTCTRL_TE; |
|---|
| 1478 | + lpuart32_write(port, temp, UARTCTRL); |
|---|
| 1479 | + temp |= UARTCTRL_TXINV; |
|---|
| 1480 | + lpuart32_write(port, temp, UARTCTRL); |
|---|
| 1481 | + } else { |
|---|
| 1482 | + /* Disable the TXINV to turn off break and re-enable transmitter. */ |
|---|
| 1483 | + temp &= ~UARTCTRL_TXINV; |
|---|
| 1484 | + lpuart32_write(port, temp, UARTCTRL); |
|---|
| 1485 | + temp |= UARTCTRL_TE; |
|---|
| 1486 | + lpuart32_write(port, temp, UARTCTRL); |
|---|
| 1487 | + } |
|---|
| 1459 | 1488 | } |
|---|
| 1460 | 1489 | |
|---|
| 1461 | 1490 | static void lpuart_setup_watermark(struct lpuart_port *sport) |
|---|
| .. | .. |
|---|
| 1723 | 1752 | static void lpuart_dma_shutdown(struct lpuart_port *sport) |
|---|
| 1724 | 1753 | { |
|---|
| 1725 | 1754 | if (sport->lpuart_dma_rx_use) { |
|---|
| 1726 | | - del_timer_sync(&sport->lpuart_timer); |
|---|
| 1727 | 1755 | lpuart_dma_rx_free(&sport->port); |
|---|
| 1728 | 1756 | sport->lpuart_dma_rx_use = false; |
|---|
| 1729 | 1757 | } |
|---|
| .. | .. |
|---|
| 1874 | 1902 | * Since timer function acqures sport->port.lock, need to stop before |
|---|
| 1875 | 1903 | * acquring same lock because otherwise del_timer_sync() can deadlock. |
|---|
| 1876 | 1904 | */ |
|---|
| 1877 | | - if (old && sport->lpuart_dma_rx_use) { |
|---|
| 1878 | | - del_timer_sync(&sport->lpuart_timer); |
|---|
| 1905 | + if (old && sport->lpuart_dma_rx_use) |
|---|
| 1879 | 1906 | lpuart_dma_rx_free(&sport->port); |
|---|
| 1880 | | - } |
|---|
| 1881 | 1907 | |
|---|
| 1882 | 1908 | spin_lock_irqsave(&sport->port.lock, flags); |
|---|
| 1883 | 1909 | |
|---|
| .. | .. |
|---|
| 2109 | 2135 | * Since timer function acqures sport->port.lock, need to stop before |
|---|
| 2110 | 2136 | * acquring same lock because otherwise del_timer_sync() can deadlock. |
|---|
| 2111 | 2137 | */ |
|---|
| 2112 | | - if (old && sport->lpuart_dma_rx_use) { |
|---|
| 2113 | | - del_timer_sync(&sport->lpuart_timer); |
|---|
| 2138 | + if (old && sport->lpuart_dma_rx_use) |
|---|
| 2114 | 2139 | lpuart_dma_rx_free(&sport->port); |
|---|
| 2115 | | - } |
|---|
| 2116 | 2140 | |
|---|
| 2117 | 2141 | spin_lock_irqsave(&sport->port.lock, flags); |
|---|
| 2118 | 2142 | |
|---|
| .. | .. |
|---|
| 2139 | 2163 | /* update the per-port timeout */ |
|---|
| 2140 | 2164 | uart_update_timeout(port, termios->c_cflag, baud); |
|---|
| 2141 | 2165 | |
|---|
| 2142 | | - /* wait transmit engin complete */ |
|---|
| 2143 | | - lpuart32_write(&sport->port, 0, UARTMODIR); |
|---|
| 2144 | | - lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC); |
|---|
| 2166 | + /* |
|---|
| 2167 | + * LPUART Transmission Complete Flag may never be set while queuing a break |
|---|
| 2168 | + * character, so skip waiting for transmission complete when UARTCTRL_SBK is |
|---|
| 2169 | + * asserted. |
|---|
| 2170 | + */ |
|---|
| 2171 | + if (!(old_ctrl & UARTCTRL_SBK)) { |
|---|
| 2172 | + lpuart32_write(&sport->port, 0, UARTMODIR); |
|---|
| 2173 | + lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC); |
|---|
| 2174 | + } |
|---|
| 2145 | 2175 | |
|---|
| 2146 | 2176 | /* disable transmit and receive */ |
|---|
| 2147 | 2177 | lpuart32_write(&sport->port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE), |
|---|
| .. | .. |
|---|
| 2559 | 2589 | OF_EARLYCON_DECLARE(lpuart32, "fsl,ls1021a-lpuart", lpuart32_early_console_setup); |
|---|
| 2560 | 2590 | OF_EARLYCON_DECLARE(lpuart32, "fsl,ls1028a-lpuart", ls1028a_early_console_setup); |
|---|
| 2561 | 2591 | OF_EARLYCON_DECLARE(lpuart32, "fsl,imx7ulp-lpuart", lpuart32_imx_early_console_setup); |
|---|
| 2592 | +OF_EARLYCON_DECLARE(lpuart32, "fsl,imx8ulp-lpuart", lpuart32_imx_early_console_setup); |
|---|
| 2562 | 2593 | OF_EARLYCON_DECLARE(lpuart32, "fsl,imx8qxp-lpuart", lpuart32_imx_early_console_setup); |
|---|
| 2563 | 2594 | EARLYCON_DECLARE(lpuart, lpuart_early_console_setup); |
|---|
| 2564 | 2595 | EARLYCON_DECLARE(lpuart32, lpuart32_early_console_setup); |
|---|
| .. | .. |
|---|
| 2586 | 2617 | struct device_node *np = pdev->dev.of_node; |
|---|
| 2587 | 2618 | struct lpuart_port *sport; |
|---|
| 2588 | 2619 | struct resource *res; |
|---|
| 2620 | + irq_handler_t handler; |
|---|
| 2589 | 2621 | int ret; |
|---|
| 2590 | 2622 | |
|---|
| 2591 | 2623 | sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL); |
|---|
| .. | .. |
|---|
| 2658 | 2690 | |
|---|
| 2659 | 2691 | if (lpuart_is_32(sport)) { |
|---|
| 2660 | 2692 | lpuart_reg.cons = LPUART32_CONSOLE; |
|---|
| 2661 | | - ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart32_int, 0, |
|---|
| 2662 | | - DRIVER_NAME, sport); |
|---|
| 2693 | + handler = lpuart32_int; |
|---|
| 2663 | 2694 | } else { |
|---|
| 2664 | 2695 | lpuart_reg.cons = LPUART_CONSOLE; |
|---|
| 2665 | | - ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart_int, 0, |
|---|
| 2666 | | - DRIVER_NAME, sport); |
|---|
| 2696 | + handler = lpuart_int; |
|---|
| 2667 | 2697 | } |
|---|
| 2668 | | - |
|---|
| 2669 | | - if (ret) |
|---|
| 2670 | | - goto failed_irq_request; |
|---|
| 2671 | 2698 | |
|---|
| 2672 | 2699 | ret = uart_get_rs485_mode(&sport->port); |
|---|
| 2673 | 2700 | if (ret) |
|---|
| .. | .. |
|---|
| 2684 | 2711 | if (ret) |
|---|
| 2685 | 2712 | goto failed_attach_port; |
|---|
| 2686 | 2713 | |
|---|
| 2714 | + ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0, |
|---|
| 2715 | + DRIVER_NAME, sport); |
|---|
| 2716 | + if (ret) |
|---|
| 2717 | + goto failed_irq_request; |
|---|
| 2718 | + |
|---|
| 2687 | 2719 | return 0; |
|---|
| 2688 | 2720 | |
|---|
| 2721 | +failed_irq_request: |
|---|
| 2722 | + uart_remove_one_port(&lpuart_reg, &sport->port); |
|---|
| 2689 | 2723 | failed_get_rs485: |
|---|
| 2690 | 2724 | failed_attach_port: |
|---|
| 2691 | | -failed_irq_request: |
|---|
| 2692 | 2725 | lpuart_disable_clks(sport); |
|---|
| 2693 | 2726 | return ret; |
|---|
| 2694 | 2727 | } |
|---|
| .. | .. |
|---|
| 2738 | 2771 | * EDMA driver during suspend will forcefully release any |
|---|
| 2739 | 2772 | * non-idle DMA channels. If port wakeup is enabled or if port |
|---|
| 2740 | 2773 | * is console port or 'no_console_suspend' is set the Rx DMA |
|---|
| 2741 | | - * cannot resume as as expected, hence gracefully release the |
|---|
| 2774 | + * cannot resume as expected, hence gracefully release the |
|---|
| 2742 | 2775 | * Rx DMA path before suspend and start Rx DMA path on resume. |
|---|
| 2743 | 2776 | */ |
|---|
| 2744 | 2777 | if (irq_wake) { |
|---|
| 2745 | | - del_timer_sync(&sport->lpuart_timer); |
|---|
| 2746 | 2778 | lpuart_dma_rx_free(&sport->port); |
|---|
| 2747 | 2779 | } |
|---|
| 2748 | 2780 | |
|---|