]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
tty: serial: fsl_lpuart: consider TX FIFO too in tx_empty
authorStefan Agner <stefan@agner.ch>
Tue, 19 Jul 2016 07:43:03 +0000 (13:13 +0530)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Aug 2016 13:48:28 +0000 (15:48 +0200)
Currently the tx_empty callback only considers the Transmit Complete Flag (TC).
The reference manual is not quite clear if the TC flag covers the TX FIFO too.
Debug prints on real hardware have shown that from time to time the TC flag is
asserted (indicating Transmitter idle) while there are still data in the
TX FIFO. Hence, in this case the serial core will call the shutdown callback
even though there are data remaining in the TX FIFO buffers.

Avoid early shutdowns by considering the TX FIFO empty flag too. Also avoid
theoretical race conditions between DMA and the driver by checking whether the
TX DMA is in progress too.

Signed-off-by: Stefan Agner <stefan@agner.ch>
Signed-off-by: Bhuvanchandra DV <bhuvanchandra.dv@toradex.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/fsl_lpuart.c

index 7f95f782a48561e5ef466230c1a54dc8cf17455d..35592ff565fb3cd813ed966afb54d6bfda554830 100644 (file)
@@ -810,8 +810,18 @@ static irqreturn_t lpuart32_int(int irq, void *dev_id)
 /* return TIOCSER_TEMT when transmitter is not busy */
 static unsigned int lpuart_tx_empty(struct uart_port *port)
 {
-       return (readb(port->membase + UARTSR1) & UARTSR1_TC) ?
-               TIOCSER_TEMT : 0;
+       struct lpuart_port *sport = container_of(port,
+                       struct lpuart_port, port);
+       unsigned char sr1 = readb(port->membase + UARTSR1);
+       unsigned char sfifo = readb(port->membase + UARTSFIFO);
+
+       if (sport->dma_tx_in_progress)
+               return 0;
+
+       if (sr1 & UARTSR1_TC && sfifo & UARTSFIFO_TXEMPT)
+               return TIOCSER_TEMT;
+
+       return 0;
 }
 
 static unsigned int lpuart32_tx_empty(struct uart_port *port)