ColdFire: Fix UART baudrate formula
PATCH 1/1 ColdFire: Fix UART baudrate formula
From: TsiChung Liew <[email protected]>
The formula "counter = (u32) (gd->bus_clk / gd->baudrate) / 32" can generate the wrong divisor due to integer division truncation. Round the calculated divisor value by adding 1/2 the baudrate before dividing by the baudrate.
Signed-off-by TsiChung Liew <[email protected]>
Acked-by Gerald Van Baren <[email protected]>
--- drivers/serial/mcfuart.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/serial/mcfuart.c +2 -2
@@ -63,8 +63,8 @@ int serial_init(void) uart->umr =UART_UMR_SB_STOP_BITS_1 ;/* Setting up BaudRate */ - counter = (u32) (gd->bus_clk / (gd->baudrate)); - counter >>=5 ; + counter = (u32) (gd->bus_clk / 32) + (gd->baudrate / 2)); + counter = counter / gd->baudrate;/* write to CTUR: divide counter upper byte */ uart->ubg1 = (u8) ((counter &0xff00 ) >>8 );
Signature · 1 line
1.5.4.1
PATCH 1/1 ColdFire: Fix UART baudrate formula
Quoted 18 lines · Tsi-Chung.Liew
From: TsiChung Liew <[email protected]>
The formula "counter = (u32) (
gd->bus_clk/gd->baudrate) / 32" can generate the wrong divisor due to integer division truncation. Round the calculated divisor value by adding 1/2 the baudrate before dividing by the baudrate.Signed-off-by TsiChung Liew <[email protected]>Acked-by Gerald Van Baren <[email protected]>--- drivers/serial/mcfuart.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)drivers/serial/mcfuart.c +0
-0
drivers/serial/mcfuart.c int serial_init(void) · line 66
Quoted 6 lines
drivers/serial/mcfuart.c +1
-2@@ -63,8 +63,8 @@ int serial_init(void) uart->umr =UART_UMR_SB_STOP_BITS_1 ;/* Setting up BaudRate */ - counter = (u32) (gd->bus_clk / (gd->baudrate)); - counter >>=5 ; + counter = (u32) (gd->bus_clk / 32) + (gd->baudrate / 2));
And you compiled this ??
Quoted 4 lines
drivers/serial/mcfuart.c +1
-0+ counter = counter / gd->baudrate;/* write to CTUR: divide counter upper byte */ uart->ubg1 = (u8) ((counter &0xff00 ) >>8 );