]> git.hungrycats.org Git - linux/commitdiff
[SERIAL] Pick nearest baud rate divider
authorRoger Blofeld <blofeldus@com.rmk.(none)>
Tue, 5 Oct 2004 11:07:18 +0000 (12:07 +0100)
committerRussell King <rmk@flint.arm.linux.org.uk>
Tue, 5 Oct 2004 11:07:18 +0000 (12:07 +0100)
From: Roger Blofeld

This patch modifies uart_get_divisor to select the nearest baud rate
divider rather than the lowest.  It minimizes baud rate errors.

For example, if uartclk is 33000000 and baud is 115200 the ratio is about
17.9 The current code selects 17 (5% error) but should select 18 (0.5%
error)

Signed-off-by: Andrew Morton
Signed-off-by: Russell King
drivers/serial/serial_core.c

index 2f88f6da9698dfb9d23e07f300555458863dbb7d..1ac6c9d8144cdf047c87bc98d8e07315cea16204 100644 (file)
@@ -395,7 +395,7 @@ uart_get_divisor(struct uart_port *port, unsigned int baud)
        if (baud == 38400 && (port->flags & UPF_SPD_MASK) == UPF_SPD_CUST)
                quot = port->custom_divisor;
        else
-               quot = port->uartclk / (16 * baud);
+               quot = (port->uartclk + (8 * baud)) / (16 * baud);
 
        return quot;
 }