From 1c16606aac8f03be80d9c38ada00fd03123e0dbe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Patrik=20Dahlstr=C3=B6m?= Date: Sat, 21 Dec 2019 17:25:12 +0100 Subject: [PATCH] serial: ns16550: Use old baud rate divisor for flushing if not given MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If baud_divisor is not set (i.e. == -1), we should use the baud divisor already in use for flushing the xmit register. If we don't flush the xmit register, then SPL will hang. Signed-off-by: Patrik Dahlström --- drivers/serial/ns16550.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index a92d2b1de8..9851663dc5 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -171,6 +171,13 @@ void NS16550_init(NS16550_t com_port, int baud_divisor) == UART_LSR_THRE) { if (baud_divisor != -1) NS16550_setbrg(com_port, baud_divisor); + else { + // Re-use old baud rate divisor to flush transmit reg. + const int dll = serial_in(&com_port->dll); + const int dlm = serial_in(&com_port->dlm); + const int divisor = dll | (dlm << 8); + NS16550_setbrg(com_port, divisor); + } serial_out(0, &com_port->mdr1); } #endif -- 2.39.5