Merge branch 'next' of git://git.denx.de/u-boot-avr32
[platform/kernel/u-boot.git] / drivers / serial / serial.c
index 76425d8..b361eef 100644 (file)
@@ -26,7 +26,7 @@
 #ifdef CFG_NS16550_SERIAL
 
 #include <ns16550.h>
-#ifdef CFG_NS87308
+#ifdef CONFIG_NS87308
 #include <ns87308.h>
 #endif
 
@@ -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)
@@ -153,7 +159,7 @@ int serial_init (void)
 {
        int clock_divisor;
 
-#ifdef CFG_NS87308
+#ifdef CONFIG_NS87308
        initialise_ns87308();
 #endif