Skip to content

Commit

Permalink
serial: bfin_uart: Don't switch baud rate untill the transfer buffer …
Browse files Browse the repository at this point in the history
…is empty.

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

Signed-off-by: Sonic Zhang <sonic.zhang@analog.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Sonic Zhang authored and Greg Kroah-Hartman committed Nov 21, 2012
1 parent 159a8e9 commit 1cd3f2d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/tty/serial/bfin_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,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:
Expand Down Expand Up @@ -868,6 +869,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);
Expand Down

0 comments on commit 1cd3f2d

Please sign in to comment.