Skip to contentSkip to conversation

serial: bfin_uart: Don't switch baud rate untill the transfer buffer is empty.

PATCH New Sonic Zhang 1 participant 1 message Nov 19, 2012 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 serial: bfin_uart: Don't switch baud rate untill the transfer buffer is empty.

From: Sonic Zhang <[email protected]>

set_termios may be invoked before the former data transfer is completed. Block until the tranfer is done.

---
 drivers/tty/serial/bfin_uart.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/tty/serial/bfin_uart.c +9 -0
index 9242d56..f8dc8f1 100644
@@ -800,6 +800,7 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
 	unsigned long flags;
 	unsigned int baud, quot;
 	unsigned int ier, lcr = 0;
+	unsigned long timeout;
 
 	switch (termios->c_cflag & CSIZE) {
 	case CS8:
@@ -869,6 +870,14 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
 
 	UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
 
+	/* Wait till the transfer buffer is empty */
+	timeout = jiffies + msecs_to_jiffies(10);
+	while (UART_GET_GCTL(uart) & UCEN && !(UART_GET_LSR(uart) & TEMT))
+		if (time_after(jiffies, timeout)) {
+			dev_warn(port->dev, "timeout waiting for TX buffer empty\n");
+			break;
+		}
+
 	/* Disable UART */
 	ier = UART_GET_IER(uart);
 	UART_PUT_GCTL(uart, UART_GET_GCTL(uart) & ~UCEN);
Signature · 1 line
1.7.0.4