serial: ns16550: use DIV_ROUND_CLOSEST macro to compute the divisor
authorMasahiro Yamada <yamada.m@jp.panasonic.com>
Fri, 11 Jul 2014 11:29:03 +0000 (20:29 +0900)
committerTom Rini <trini@ti.com>
Tue, 22 Jul 2014 11:44:25 +0000 (07:44 -0400)
The function still returns the same value.

The comment block is no longer necessary because our intention is
clear enough by using DIV_ROUND_CLOSEST() macro.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
drivers/serial/serial_ns16550.c

index 056ef2a9a133921fc3b5d7e34dfc8eeb46efe305..49e2c1f14f69c17e953a2ca14d65303ef31f0b9c 100644 (file)
@@ -130,13 +130,9 @@ static int calc_divisor (NS16550_t port)
 #endif
 
 #define MODE_X_DIV 16
-       /* Compute divisor value. Normally, we should simply return:
-        *   CONFIG_SYS_NS16550_CLK) / MODE_X_DIV / gd->baudrate
-        * but we need to round that value by adding 0.5.
-        * Rounding is especially important at high baud rates.
-        */
-       return (CONFIG_SYS_NS16550_CLK + (gd->baudrate * (MODE_X_DIV / 2))) /
-               (MODE_X_DIV * gd->baudrate);
+
+       return DIV_ROUND_CLOSEST(CONFIG_SYS_NS16550_CLK,
+                                               MODE_X_DIV * gd->baudrate);
 }
 
 void