From: Kunihiko Hayashi Date: Wed, 13 Jul 2022 01:38:59 +0000 (+0900) Subject: serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=c6bceb4e360d704fb9746541c18a1a08f49353fc;p=u-boot.git serial: zynq: Use DIV_ROUND_CLOSEST() to calcurate divider value Since the calulation of "bgen" is rounded down, using a higher baudrate will result in a larger difference from the actual baudrate. Should use DIV_ROUND_CLOSEST() like the Linux driver. Signed-off-by: Kunihiko Hayashi Link: https://lore.kernel.org/r/1657676339-6055-1-git-send-email-hayashi.kunihiko@socionext.com Signed-off-by: Michal Simek --- diff --git a/drivers/serial/serial_zynq.c b/drivers/serial/serial_zynq.c index 83adfb5fb9..295337a817 100644 --- a/drivers/serial/serial_zynq.c +++ b/drivers/serial/serial_zynq.c @@ -75,7 +75,7 @@ static void _uart_zynq_serial_setbrg(struct uart_zynq *regs, * Find acceptable values for baud generation. */ for (bdiv = 4; bdiv < 255; bdiv++) { - bgen = clock / (baud * (bdiv + 1)); + bgen = DIV_ROUND_CLOSEST(clock, baud * (bdiv + 1)); if (bgen < 2 || bgen > 65535) continue;