提交 deeaf963 编写于 作者: P Pali Rohár 提交者: Greg Kroah-Hartman

serial: mvebu-uart: correctly calculate minimal possible baudrate

For default (x16) scheme which is currently used by mvebu-uart.c driver,
maximal divisor of UART base clock is 1023*16. Therefore there is limit for
minimal supported baudrate. This change calculate it correctly and prevents
setting invalid divisor 0 into hardware registers.
Signed-off-by: NPali Rohár <pali@kernel.org>
Fixes: 68a0db1d ("serial: mvebu-uart: add function to change baudrate")
Link: https://lore.kernel.org/r/20210624224909.6350-4-pali@kernel.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
上级 ecd6b010
...@@ -481,7 +481,7 @@ static void mvebu_uart_set_termios(struct uart_port *port, ...@@ -481,7 +481,7 @@ static void mvebu_uart_set_termios(struct uart_port *port,
struct ktermios *old) struct ktermios *old)
{ {
unsigned long flags; unsigned long flags;
unsigned int baud; unsigned int baud, min_baud, max_baud;
spin_lock_irqsave(&port->lock, flags); spin_lock_irqsave(&port->lock, flags);
...@@ -500,16 +500,21 @@ static void mvebu_uart_set_termios(struct uart_port *port, ...@@ -500,16 +500,21 @@ static void mvebu_uart_set_termios(struct uart_port *port,
port->ignore_status_mask |= STAT_RX_RDY(port) | STAT_BRK_ERR; port->ignore_status_mask |= STAT_RX_RDY(port) | STAT_BRK_ERR;
/* /*
* Maximal divisor is 1023 * 16 when using default (x16) scheme.
* Maximum achievable frequency with simple baudrate divisor is 230400. * Maximum achievable frequency with simple baudrate divisor is 230400.
* Since the error per bit frame would be of more than 15%, achieving * Since the error per bit frame would be of more than 15%, achieving
* higher frequencies would require to implement the fractional divisor * higher frequencies would require to implement the fractional divisor
* feature. * feature.
*/ */
baud = uart_get_baud_rate(port, termios, old, 0, 230400); min_baud = DIV_ROUND_UP(port->uartclk, 1023 * 16);
max_baud = 230400;
baud = uart_get_baud_rate(port, termios, old, min_baud, max_baud);
if (mvebu_uart_baud_rate_set(port, baud)) { if (mvebu_uart_baud_rate_set(port, baud)) {
/* No clock available, baudrate cannot be changed */ /* No clock available, baudrate cannot be changed */
if (old) if (old)
baud = uart_get_baud_rate(port, old, NULL, 0, 230400); baud = uart_get_baud_rate(port, old, NULL,
min_baud, max_baud);
} else { } else {
tty_termios_encode_baud_rate(termios, baud, baud); tty_termios_encode_baud_rate(termios, baud, baud);
uart_update_timeout(port, termios->c_cflag, baud); uart_update_timeout(port, termios->c_cflag, baud);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册