From cd0a582c3ddeceb07c1d1a6f9adc14130e5d9890 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 27 Jul 2022 10:17:03 +0200 Subject: [PATCH] 4.19-stable patches added patches: serial-mvebu-uart-correctly-report-configured-baudrate-value.patch --- ...tly-report-configured-baudrate-value.patch | 93 +++++++++++++++++++ queue-4.19/series | 1 + 2 files changed, 94 insertions(+) create mode 100644 queue-4.19/serial-mvebu-uart-correctly-report-configured-baudrate-value.patch diff --git a/queue-4.19/serial-mvebu-uart-correctly-report-configured-baudrate-value.patch b/queue-4.19/serial-mvebu-uart-correctly-report-configured-baudrate-value.patch new file mode 100644 index 00000000000..c27dca320c3 --- /dev/null +++ b/queue-4.19/serial-mvebu-uart-correctly-report-configured-baudrate-value.patch @@ -0,0 +1,93 @@ +From 4f532c1e25319e42996ec18a1f473fd50c8e575d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Pali=20Roh=C3=A1r?= +Date: Tue, 28 Jun 2022 12:09:22 +0200 +Subject: serial: mvebu-uart: correctly report configured baudrate value +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Pali Rohár + +commit 4f532c1e25319e42996ec18a1f473fd50c8e575d upstream. + +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: 68a0db1d7da2 ("serial: mvebu-uart: add function to change baudrate") +Cc: stable +Reviewed-by: Ilpo Järvinen +Signed-off-by: Pali Rohár +Link: https://lore.kernel.org/r/20220628100922.10717-1-pali@kernel.org +Signed-off-by: Greg Kroah-Hartman +--- + drivers/tty/serial/mvebu-uart.c | 25 +++++++++++++------------ + 1 file changed, 13 insertions(+), 12 deletions(-) + +--- a/drivers/tty/serial/mvebu-uart.c ++++ b/drivers/tty/serial/mvebu-uart.c +@@ -442,14 +442,14 @@ static void mvebu_uart_shutdown(struct u + } + } + +-static int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud) ++static unsigned int mvebu_uart_baud_rate_set(struct uart_port *port, unsigned int baud) + { + struct mvebu_uart *mvuart = to_mvuart(port); + unsigned int d_divisor, m_divisor; + u32 brdv; + + if (IS_ERR(mvuart->clk)) +- return -PTR_ERR(mvuart->clk); ++ return 0; + + /* + * The baudrate is derived from the UART clock thanks to two divisors: +@@ -469,7 +469,7 @@ static int mvebu_uart_baud_rate_set(stru + brdv |= d_divisor; + writel(brdv, port->membase + UART_BRDV); + +- return 0; ++ return DIV_ROUND_CLOSEST(port->uartclk, d_divisor * m_divisor); + } + + static void mvebu_uart_set_termios(struct uart_port *port, +@@ -506,15 +506,11 @@ static void mvebu_uart_set_termios(struc + max_baud = 230400; + + baud = uart_get_baud_rate(port, termios, old, min_baud, max_baud); +- if (mvebu_uart_baud_rate_set(port, baud)) { +- /* No clock available, baudrate cannot be changed */ +- if (old) +- baud = uart_get_baud_rate(port, old, NULL, +- min_baud, max_baud); +- } else { +- tty_termios_encode_baud_rate(termios, baud, baud); +- uart_update_timeout(port, termios->c_cflag, baud); +- } ++ baud = mvebu_uart_baud_rate_set(port, baud); ++ ++ /* In case baudrate cannot be changed, report previous old value */ ++ if (baud == 0 && old) ++ baud = tty_termios_baud_rate(old); + + /* Only the following flag changes are supported */ + if (old) { +@@ -525,6 +521,11 @@ static void mvebu_uart_set_termios(struc + termios->c_cflag |= CS8; + } + ++ if (baud != 0) { ++ tty_termios_encode_baud_rate(termios, baud, baud); ++ uart_update_timeout(port, termios->c_cflag, baud); ++ } ++ + spin_unlock_irqrestore(&port->lock, flags); + } + diff --git a/queue-4.19/series b/queue-4.19/series index 19c7fc68518..7231a4a3296 100644 --- a/queue-4.19/series +++ b/queue-4.19/series @@ -49,3 +49,4 @@ bluetooth-rfcomm-replace-use-of-memcpy_from_msg-with-bt_skb_sendmmsg.patch bluetooth-fix-passing-null-to-ptr_err.patch bluetooth-sco-fix-sco_send_frame-returning-skb-len.patch bluetooth-fix-bt_skb_sendmmsg-not-allocating-partial-chunks.patch +serial-mvebu-uart-correctly-report-configured-baudrate-value.patch -- 2.47.3