[U-Boot-Users] [PATCH] drivers/serial.c: Correct divisor calculation

Hi,
This patch fixes the UART divisor calculation in the generic serial driver by doing a division with correct rounding.
Note: There are quite a few board-specific serial drivers which calculate the UART divisor without correct rounding. These need to be fixed too.
Note: The patch to drivers/serial_pl010.c proposed by Robert Deliƫn on 5. Dec 2006 has the same problem (macro UART_PL010_BAUD2DIVISOR).
Regards, Daniel
diff --git a/drivers/serial.c b/drivers/serial.c index 76425d8..c122cf4 100644 --- a/drivers/serial.c +++ b/drivers/serial.c @@ -124,6 +124,7 @@ static NS16550_t serial_ports[4] = {
static int calc_divisor (NS16550_t port) { + unsigned long tmp; #ifdef CONFIG_OMAP1510 /* If can't cleanly clock 115200 set div to 1 */ if ((CFG_NS16550_CLK == 12000000) && (gd->baudrate == 115200)) { @@ -144,7 +145,8 @@ static int calc_divisor (NS16550_t port) #else #define MODE_X_DIV 16 #endif - return (CFG_NS16550_CLK / MODE_X_DIV / gd->baudrate); + tmp = MODE_X_DIV * gd->baudrate; + return (CFG_NS16550_CLK + tmp / 2) / tmp;
}
participants (1)
-
Daniel Hobi