drivers/serial: Move conditional compilation to Makefile for CONFIG_* macros
[oweals/u-boot.git] / drivers / serial / serial.c
index 76425d87901ff13930b02183e9347349e0aa8c0e..8bbfcf9c0cba8a7115d1c3b5b680791d1e2e36f6 100644 (file)
@@ -144,8 +144,14 @@ static int calc_divisor (NS16550_t port)
 #else
 #define MODE_X_DIV 16
 #endif
-       return (CFG_NS16550_CLK / MODE_X_DIV / gd->baudrate);
 
+       /* Compute divisor value. Normally, we should simply return:
+        *   CFG_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 (CFG_NS16550_CLK + (gd->baudrate * (MODE_X_DIV / 2))) /
+               (MODE_X_DIV * gd->baudrate);
 }
 
 #if !defined(CONFIG_SERIAL_MULTI)