From: Yu Tu Date: Thu, 7 Apr 2022 08:13:53 +0000 (+0800) Subject: tty: serial: meson: Use DIV_ROUND_CLOSEST to calculate baud rates X-Git-Tag: v5.19-rc1~47^2~143 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=368ab68b18de104719f386a5cfe3595673cc96de;p=thirdparty%2Flinux.git tty: serial: meson: Use DIV_ROUND_CLOSEST to calculate baud rates Due to chip process differences, chip designers recommend using baud rates as close to and larger as possible in order to reduce clock errors. Signed-off-by: Yu Tu Reviewed-by: Neil Armstrong Link: https://lore.kernel.org/r/20220407081355.13602-2-yu.tu@amlogic.com Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c index 2bf1c57e0981e..8e59624935af1 100644 --- a/drivers/tty/serial/meson_uart.c +++ b/drivers/tty/serial/meson_uart.c @@ -299,10 +299,10 @@ static void meson_uart_change_speed(struct uart_port *port, unsigned long baud) cpu_relax(); if (port->uartclk == 24000000) { - val = ((port->uartclk / 3) / baud) - 1; + val = DIV_ROUND_CLOSEST(port->uartclk / 3, baud) - 1; val |= AML_UART_BAUD_XTAL; } else { - val = ((port->uartclk * 10 / (baud * 4) + 5) / 10) - 1; + val = DIV_ROUND_CLOSEST(port->uartclk / 4, baud) - 1; } val |= AML_UART_BAUD_USE; writel(val, port->membase + AML_UART_REG5);