serial: fsl_lpuart: consider TX FIFO too in lpuart32_tx_empty

This change “serial: fsl_lpuart: consider TX FIFO too in lpuart32_tx_empty” in Linux kernel is authored by Atsushi Nemoto <atsushi.nemoto [at] sord.co.jp> on Mon Jan 21 17:37:28 2019 +0900.

serial: fsl_lpuart: consider TX FIFO too in lpuart32_tx_empty

The commit 3876a00fcb6b ("tty: serial: fsl_lpuart: consider TX FIFO
too in tx_empty") fixed lpuart_tx_empty only.
Fix lpuart32_tx_empty too.

Signed-off-by: Atsushi Nemoto <atsushi.nemoto@sord.co.jp>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

This Linux change may have been applied to various maintained Linux releases and you can find Linux releases including commit 46dd6d7.

There are 14 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/tty/serial/fsl_lpuart.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 2389986..5e13946 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -664,8 +664,18 @@ static unsigned int lpuart_tx_empty(struct uart_port *port)
 
 static unsigned int lpuart32_tx_empty(struct uart_port *port)
 {
-	return (lpuart32_read(port, UARTSTAT) & UARTSTAT_TC) ?
-		TIOCSER_TEMT : 0;
+	struct lpuart_port *sport = container_of(port,
+			struct lpuart_port, port);
+	unsigned long stat = lpuart32_read(port, UARTSTAT);
+	unsigned long sfifo = lpuart32_read(port, UARTFIFO);
+
+	if (sport->dma_tx_in_progress)
+		return 0;
+
+	if (stat & UARTSTAT_TC && sfifo & UARTFIFO_TXEMPT)
+		return TIOCSER_TEMT;
+
+	return 0;
 }
 
 static bool lpuart_is_32(struct lpuart_port *sport)

The commit for this change in Linux stable tree is 46dd6d7 (patch).

Leave a Reply

Your email address will not be published. Required fields are marked *