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

Message ID 1356081706-31239-1-git-send-email-javier.martinez@collabora.co.uk
State Superseded
Delegated to: Tom Rini
Headers show

Commit Message

Javier Martinez Canillas Dec. 21, 2012, 9:21 a.m.
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@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);