[U-Boot-Users] [PATCH v2] Round the serial port clock divisor valuereturned by calc_divisor()
Hugo Villeneuve
hugo.villeneuve at lyrtech.com
Tue Jul 15 17:19:08 CEST 2008
u-boot-users-bounces at lists.sourceforge.net wrote:
> This formula is better at avoiding integer overflow.
>
> Signed-off-by: Gerald Van Baren <vanbaren at cideas.com>
> ---
>
> This is my latest entry in the baud rate rounding dual. Since it
> doesn't multiply the master BRG clock but instead adds the baud rate
> scaled by 1/2 the clock multiplier, it should not overflow (for a
> master clock right at the edge of overflowing itself, it still will
> overflow, but that is pretty unlikely).
>
> This compiles OK on the mpc7448hpc2. I have only tested it on a
> calculator. I have NOT tested it on real hardware.
I have tested it on my board and it works.
I also tested it on my board by using the clock value of the mpc7448hpc2 board, and printing the computed value which was correct.
> drivers/serial/serial.c | 16 +++++-----------
> 1 files changed, 5 insertions(+), 11 deletions(-)
> ...
> - /* 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 (2/4).
> - * Rounding is especially important at high baud rates.
> + /*
> + * Compute divisor value, rounding it properly. Rounding is
> + * especially important at high baud rates.
> */
Please keep the comments explaining the base formula: it is not easy to reverse-engineer an optimized formula to figure out what is the base formula.
I will resubmit a patch with your fix and my comments.
Hugo V.
More information about the U-Boot
mailing list