From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kenneth Johansson Date: Thu, 29 May 2008 22:59:52 +0200 Subject: [U-Boot-Users] [PATCH] ColdFire: Fix UART baudrate formula In-Reply-To: <1212092779-29359-1-git-send-email-Tsi-Chung.Liew@freescale.com> References: <1212092779-29359-1-git-send-email-Tsi-Chung.Liew@freescale.com> Message-ID: <1212094792.2236.15.camel@localhost.localdomain> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de On Thu, 2008-05-29 at 15:26 -0500, Tsi-Chung.Liew wrote: > From: TsiChung Liew > > 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 > Acked-by: Gerald Van Baren > --- > drivers/serial/mcfuart.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c > index 88f3eb1..75e85b7 100644 > --- a/drivers/serial/mcfuart.c > +++ b/drivers/serial/mcfuart.c > @@ -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 ?? > + counter = counter / gd->baudrate; > > /* write to CTUR: divide counter upper byte */ > uart->ubg1 = (u8) ((counter & 0xff00) >> 8);