Re: [PATCH AUTOSEL 4.20 025/117] USB: serial: ftdi_sio: use rounding when calculating baud rate divisors

From: Sasha Levin
Date: Wed Jan 23 2019 - 08:58:35 EST


On Wed, Jan 09, 2019 at 09:24:37AM +0100, Johan Hovold wrote:
On Tue, Jan 08, 2019 at 02:24:53PM -0500, Sasha Levin wrote:
From: Nikolaj Fogh <nikolajfogh@xxxxxxxxx>

[ Upstream commit 6abd837104a3a8e1cda64fc4d7675f6c3ece9d8b ]

Improve baud-rate generation by using rounding-to-closest instead of
truncation in divisor calculation.

Results have been verified by logic analyzer on an FT232RT (232BM) chip.
The following table shows the wanted baud rate, the baud rate obtained
with the old method (truncation), with the new method (rounding) and the
baud rate generated by the windows 10 driver. The numbers in parentheses
is the error.

+- Wanted --+------ Old -------+------ New -------+------ Win -------+
|   9600  |   9600 (0.00%)  |   9604 (0.05%)  |   9605 (0.05%)  |
|   19200   |   19200 (0.00%)  |   19199 (0.01%)  |   19198 (0.01%)  |
|   38400   |   38395 (0.01%)  |   38431 (0.08%)  |   38394 (0.02%)  |
|   57600   |   57725 (0.22%)  |   57540 (0.10%)  |   57673 (0.13%)  |
|  115200   |  115307 (0.09%)  |  115330 (0.11%)  |  115320 (0.10%)  |
|  921600   |  919963 (0.18%)  |  920386 (0.13%)  |  920810 (0.09%)  |
|  961200   |  996512 (3.67%)  |  956480 (0.49%)  |  956937 (0.44%)  |
+-----------+------------------+------------------+------------------+

The error due to noise in the measurements is in the order of a few
tenths of a %. As can be seen, the baud rate is significantly improved
for some rates (e.g. 961200), and corresponds to the output given by the
windows driver.

The theoretical baud rate has been calculated for all baud rates from 1
to 3M, and as expected, the error is centered around 0, with a triangle
shape instead of a sawtooth, so the maximum error is decreased to half.

Signed-off-by: Nikolaj Fogh <nikolajfogh@xxxxxxxxx>
[ johan: edit commit message slightly ]
Signed-off-by: Johan Hovold <johan@xxxxxxxxxx>
Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

The stable tag was left out on purpose for this one to avoid breaking
working setups which may have compensated and adapted to this driver
behaviour which has been there since the driver was merged ages ago.

I'll drop it, thank you.

--
Thanks,
Sasha