[PATCH 4.9 076/121] serial: uartps: Wait for tx_empty in console setup

From: Greg Kroah-Hartman
Date: Tue Sep 29 2020 - 08:43:06 EST


From: Raviteja Narayanam <raviteja.narayanam@xxxxxxxxxx>

[ Upstream commit 42e11948ddf68b9f799cad8c0ddeab0a39da33e8 ]

On some platforms, the log is corrupted while console is being
registered. It is observed that when set_termios is called, there
are still some bytes in the FIFO to be transmitted.

So, wait for tx_empty inside cdns_uart_console_setup before calling
set_termios.

Signed-off-by: Raviteja Narayanam <raviteja.narayanam@xxxxxxxxxx>
Reviewed-by: Shubhrajyoti Datta <shubhrajyoti.datta@xxxxxxxxxx>
Link: https://lore.kernel.org/r/1586413563-29125-2-git-send-email-raviteja.narayanam@xxxxxxxxxx
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
---
drivers/tty/serial/xilinx_uartps.c | 8 ++++++++
1 file changed, 8 insertions(+)

--- a/drivers/tty/serial/xilinx_uartps.c
+++ b/drivers/tty/serial/xilinx_uartps.c
@@ -1274,6 +1274,7 @@ static int cdns_uart_console_setup(struc
int bits = 8;
int parity = 'n';
int flow = 'n';
+ unsigned long time_out;

if (co->index < 0 || co->index >= CDNS_UART_NR_PORTS)
return -EINVAL;
@@ -1287,6 +1288,13 @@ static int cdns_uart_console_setup(struc
if (options)
uart_parse_options(options, &baud, &parity, &bits, &flow);

+ /* Wait for tx_empty before setting up the console */
+ time_out = jiffies + usecs_to_jiffies(TX_TIMEOUT);
+
+ while (time_before(jiffies, time_out) &&
+ cdns_uart_tx_empty(port) != TIOCSER_TEMT)
+ cpu_relax();
+
return uart_set_options(port, co, baud, parity, bits, flow);
}