]> git.sur5r.net Git - u-boot/commitdiff
Round the serial port clock divisor value returned by calc_divisor()
authorHugo Villeneuve <hugo.villeneuve@lyrtech.com>
Tue, 8 Jul 2008 18:54:58 +0000 (14:54 -0400)
committerWolfgang Denk <wd@denx.de>
Wed, 9 Jul 2008 22:48:31 +0000 (00:48 +0200)
Round the serial port clock divisor value returned by
calc_divisor().

Signed-off-by: Hugo Villeneuve <hugo.villeneuve@lyrtech.com>
Signed-off-by: John Roberts <john.roberts@pwav.com>
drivers/serial/serial.c

index 76425d87901ff13930b02183e9347349e0aa8c0e..182ca2d149ead9aba81003418e0e6c418dec2890 100644 (file)
@@ -144,8 +144,13 @@ 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 or 8/16.
+        * Rounding is especially important at high baud rates.
+        */
+       return (((16 * CFG_NS16550_CLK) / MODE_X_DIV / gd->baudrate) + 8) / 16;
 }
 
 #if !defined(CONFIG_SERIAL_MULTI)