
Sometimes we want to be sure that the output FIFO has fully drained (e.g. because we are about to reset or the port or reset the board). Add a function for this.
Signed-off-by: Simon Glass sjg@chromium.org --- Changes in v2: - Add function to drain the ns16550's FIFO
drivers/serial/ns16550.c | 11 +++++++++++ include/ns16550.h | 3 +++ 2 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c index 0c23955..a082112 100644 --- a/drivers/serial/ns16550.c +++ b/drivers/serial/ns16550.c @@ -6,6 +6,7 @@
#include <config.h> #include <ns16550.h> +#include <common.h> #include <watchdog.h> #include <linux/types.h> #include <asm/io.h> @@ -115,4 +116,14 @@ int NS16550_tstc(NS16550_t com_port) return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0; }
+/* Wait for the UART's output buffer and holding register to drain */ +void NS16550_drain(NS16550_t regs) +{ + u32 mask = UART_LSR_TEMT | UART_LSR_THRE; + + /* Wait for the UART to finish sending */ + while ((serial_in(®s->lsr) & mask) != mask) + udelay(100); +} + #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ diff --git a/include/ns16550.h b/include/ns16550.h index e9d2eda..16b3828 100644 --- a/include/ns16550.h +++ b/include/ns16550.h @@ -166,4 +166,7 @@ void NS16550_init(NS16550_t com_port, int baud_divisor); void NS16550_putc(NS16550_t com_port, char c); char NS16550_getc(NS16550_t com_port); int NS16550_tstc(NS16550_t com_port); + +/* Wait for the UART's output buffer and holding register to drain */ +void NS16550_drain(NS16550_t regs); void NS16550_reinit(NS16550_t com_port, int baud_divisor);