diff options
author | Yi Pei <neopimail@gmail.com> | 2025-07-20 20:37:18 +0530 |
---|---|---|
committer | Anup Patel <anup@brainfault.org> | 2025-07-20 20:37:18 +0530 |
commit | b8f370aa3714ef37023e523c37c1981b0a5d1e12 (patch) | |
tree | 4433d40b5f5c7e24c9a7c97f4472a83641a33c78 | |
parent | a32a91069119e7a5aa31e6bc51d5e00860be3d80 (diff) | |
download | opensbi-b8f370aa3714ef37023e523c37c1981b0a5d1e12.zip opensbi-b8f370aa3714ef37023e523c37c1981b0a5d1e12.tar.gz opensbi-b8f370aa3714ef37023e523c37c1981b0a5d1e12.tar.bz2 |
lib: utils/serial: Clear LSR status and check RBR status
On some platforms, read RBR when it is empty may result in an error.
Signed-off-by: Yi Pei <neopimail@gmail.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
Link: https://lore.kernel.org/r/CAFPVDjQZ1gpf8-u--RBbAL1Y0FfDN2vZ3g=wBw+Bp-8ppuz3HA@mail.gmail.com
Signed-off-by: Anup Patel <anup@brainfault.org>
-rw-r--r-- | lib/utils/serial/uart8250.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/utils/serial/uart8250.c b/lib/utils/serial/uart8250.c index 82fb142..1737408 100644 --- a/lib/utils/serial/uart8250.c +++ b/lib/utils/serial/uart8250.c @@ -133,10 +133,9 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift, set_reg(UART_FCR_OFFSET, 0x01); /* No modem control DTR RTS */ set_reg(UART_MCR_OFFSET, 0x00); - /* Clear line status */ - get_reg(UART_LSR_OFFSET); - /* Read receive buffer */ - get_reg(UART_RBR_OFFSET); + /* Clear line status and read receive buffer */ + if (get_reg(UART_LSR_OFFSET) & UART_LSR_DR) + get_reg(UART_RBR_OFFSET); /* Set scratchpad */ set_reg(UART_SCR_OFFSET, 0x00); |