Skip to content

Commit 4f532c1

Browse files
paligregkh
authored andcommitted
serial: mvebu-uart: correctly report configured baudrate value
Functions tty_termios_encode_baud_rate() and uart_update_timeout() should be called with the baudrate value which was set to hardware. Linux then report exact values via ioctl(TCGETS2) to userspace. Change mvebu_uart_baud_rate_set() function to return baudrate value which was set to hardware and propagate this value to above mentioned functions. With this change userspace would see precise value in termios c_ospeed field. Fixes: 68a0db1 ("serial: mvebu-uart: add function to change baudrate") Cc: stable <[email protected]> Reviewed-by: Ilpo Järvinen <[email protected]> Signed-off-by: Pali Rohár <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f9b1122 commit 4f532c1

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

drivers/tty/serial/mvebu-uart.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,14 @@ static void mvebu_uart_shutdown(struct uart_port *port)
470470
}
471471
}
472472

473-
static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud)
473+
static unsigned int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud)
474474
{
475475
unsigned int d_divisor, m_divisor;
476476
unsigned long flags;
477477
u32 brdv, osamp;
478478

479479
if (!port->uartclk)
480-
return -EOPNOTSUPP;
480+
return 0;
481481

482482
/*
483483
* The baudrate is derived from the UART clock thanks to divisors:
@@ -548,7 +548,7 @@ static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud)
548548
(m_divisor << 16) | (m_divisor << 24);
549549
writel(osamp, port->membase + UART_OSAMP);
550550

551-
return 0;
551+
return DIV_ROUND_CLOSEST(port->uartclk, d_divisor * m_divisor);
552552
}
553553

554554
static void mvebu_uart_set_termios(struct uart_port *port,
@@ -587,15 +587,11 @@ static void mvebu_uart_set_termios(struct uart_port *port,
587587
max_baud = port->uartclk / 80;
588588

589589
baud = uart_get_baud_rate(port, termios, old, min_baud, max_baud);
590-
if (mvebu_uart_baud_rate_set(port, baud)) {
591-
/* No clock available, baudrate cannot be changed */
592-
if (old)
593-
baud = uart_get_baud_rate(port, old, NULL,
594-
min_baud, max_baud);
595-
} else {
596-
tty_termios_encode_baud_rate(termios, baud, baud);
597-
uart_update_timeout(port, termios->c_cflag, baud);
598-
}
590+
baud = mvebu_uart_baud_rate_set(port, baud);
591+
592+
/* In case baudrate cannot be changed, report previous old value */
593+
if (baud == 0 && old)
594+
baud = tty_termios_baud_rate(old);
599595

600596
/* Only the following flag changes are supported */
601597
if (old) {
@@ -606,6 +602,11 @@ static void mvebu_uart_set_termios(struct uart_port *port,
606602
termios->c_cflag |= CS8;
607603
}
608604

605+
if (baud != 0) {
606+
tty_termios_encode_baud_rate(termios, baud, baud);
607+
uart_update_timeout(port, termios->c_cflag, baud);
608+
}
609+
609610
spin_unlock_irqrestore(&port->lock, flags);
610611
}
611612

0 commit comments

Comments
 (0)