[U-Boot] [PATCH 1/1] serial/ns16550: check UART mode for TEMT value

Javier Martinez Canillas javier.martinez at collabora.co.uk
Fri Dec 21 10:21:46 CET 2012


On ns16550, the Transmitter Empty (TEMT) Bit is used to
indicate when the Transmitter Holding Register (THR) and
the Transmitter Shift Register (TSR) are both empty.

But ns16550 UART has two operation modes (16450 and FIFO)
and the TEMT bit logic value set is different on each mode.

On 16450, the TEMT bit is set to 1 when both THR and TSR are
empty and is set to 0 on FIFO mode.

So, checking the TEMT value without checking the current mode
and assuming a logical value of 1, can lead to U-Boot to hang
forever if the UART is initialized on FIFO mode by default.

Signed-off-by: Javier Martinez Canillas <javier.martinez at collabora.co.uk>
---
 drivers/serial/ns16550.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
index bbd91ca..d75d814 100644
--- a/drivers/serial/ns16550.c
+++ b/drivers/serial/ns16550.c
@@ -36,7 +36,9 @@
 
 void NS16550_init(NS16550_t com_port, int baud_divisor)
 {
-	while (!(serial_in(&com_port->lsr) & UART_LSR_TEMT))
+	int mode = serial_in(&com_port->fcr) & UART_FCR_FIFO_EN;
+
+	while (!(serial_in(&com_port->lsr) & UART_LSR_TEMT ^ mode))
 		;
 
 	serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier);
-- 
1.7.7.6



More information about the U-Boot mailing list