[PATCH 03/13] serial: linflexuart: Check FIFO full before writing

Larisa Grigore posted 13 patches 1 month, 2 weeks ago
[PATCH 03/13] serial: linflexuart: Check FIFO full before writing
Posted by Larisa Grigore 1 month, 2 weeks ago
In FIFO mode, the transmitter FIFO should be checked to ensure it is not
full before writing a character.

Fixes: 09864c1cdf5c ("tty: serial: Add linflexuart driver for S32V234")
Signed-off-by: Larisa Grigore <larisa.grigore@oss.nxp.com>
---
 drivers/tty/serial/fsl_linflexuart.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/fsl_linflexuart.c b/drivers/tty/serial/fsl_linflexuart.c
index 016011fd8760..9111e7af62ea 100644
--- a/drivers/tty/serial/fsl_linflexuart.c
+++ b/drivers/tty/serial/fsl_linflexuart.c
@@ -555,22 +555,24 @@ static struct uart_port *linflex_ports[UART_NR];
 static void linflex_console_putchar(struct uart_port *port, unsigned char ch)
 {
 	unsigned long cr;
+	bool fifo_mode;
 
 	cr = readl(port->membase + UARTCR);
+	fifo_mode = cr & LINFLEXD_UARTCR_TFBM;
+
+	if (fifo_mode)
+		while (readl(port->membase + UARTSR) &
+					LINFLEXD_UARTSR_DTFTFF)
+			;
 
 	writeb(ch, port->membase + BDRL);
 
-	if (!(cr & LINFLEXD_UARTCR_TFBM))
+	if (!fifo_mode) {
 		while ((readl(port->membase + UARTSR) &
 					LINFLEXD_UARTSR_DTFTFF)
 				!= LINFLEXD_UARTSR_DTFTFF)
 			;
-	else
-		while (readl(port->membase + UARTSR) &
-					LINFLEXD_UARTSR_DTFTFF)
-			;
 
-	if (!(cr & LINFLEXD_UARTCR_TFBM)) {
 		writel((readl(port->membase + UARTSR) |
 					LINFLEXD_UARTSR_DTFTFF),
 					port->membase + UARTSR);
-- 
2.47.0