tty/serial: atmel: fix fractional baud rate computation

The problem with previous code was it rounded values in wrong
place and produced wrong baud rate in some cases.

Signed-off-by: Alexey Starikovskiy <[email protected]>
[[email protected]: port to newer kernel and add commit log]
Signed-off-by: Nicolas Ferre <[email protected]>
Reviewed-by: Boris Brezillon <[email protected]>
Reviewed-by: Uwe Kleine-König <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Alexey Starikovskiy 2016-09-21 12:44:14 +02:00 • committed by Greg Kroah-Hartman
commit 36131cdfef
2 changed files with 7 additions and 4 deletions

View file

@ -2170,13 +2170,15 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios,
* accurately. This feature is enabled only when using normal mode.
* baudrate = selected clock / (8 * (2 - OVER) * (CD + FP / 8))
* Currently, OVER is always set to 0 so we get
* baudrate = selected clock (16 * (CD + FP / 8))
* baudrate = selected clock / (16 * (CD + FP / 8))
* then
* 8 CD + FP = selected clock / (2 * baudrate)
*/
if (atmel_port->has_frac_baudrate &&
(mode & ATMEL_US_USMODE) == ATMEL_US_USMODE_NORMAL) {
div = DIV_ROUND_CLOSEST(port->uartclk, baud);
cd = div / 16;
fp = DIV_ROUND_CLOSEST(div % 16, 2);
div = DIV_ROUND_CLOSEST(port->uartclk, baud * 2);
cd = div >> 3;
fp = div & ATMEL_US_FP_MASK;
} else {
cd = uart_get_divisor(port, baud);
}