On Tue, Jul 12, 2022 at 01:53:00PM +0200, Marek Behún wrote:
From: Pali Rohár pali@kernel.org
The baud rate generating divisor is a 17-bit wide (14 bits integer part and 3 bits fractional part).
Example: base clock = 48 MHz requested baud rate = 180 Baud divisor = 48,000,000 / (16 * 180) = 0b100000100011010.101
In this case the MSB gets discarded because of the overflow, and the actually used divisor will be 0b100011010.101 = 282.625, resulting in baud rate 10615 Baud, instead of the requested 180 Baud.
The best possible thing to do in this case is to generate lowest possible baud rate (in the example it would be 183 Baud), by using maximum possible divisor.
Actually, the best way to handle this is to add a sanity check for the lowest supported check as you do in the next patch. That one makes this change superfluous.
In case of divisor overflow, use maximum possible divisor.
Johan