clk: bcm2835: Round UART input clock up
authorIvan T. Ivanov <iivanov@suse.de>
Mon, 12 Sep 2022 08:13:04 +0000 (11:13 +0300)
committerStephen Boyd <sboyd@kernel.org>
Fri, 30 Sep 2022 21:29:42 +0000 (14:29 -0700)
commitf690a4d7a8f66430662975511c86819dc9965bcc
treedf4e175ba1286cf98cb142fba83a96c5a1a2a404
parent6c5422851d8be8c7451e968fd2e6da41b6109e17
clk: bcm2835: Round UART input clock up

It was reported that RPi3[1] and RPi Zero 2W boards have issues with
the Bluetooth. It turns out that when switching from initial to
operation speed host and device no longer can talk each other because
host uses incorrect UART baud rate.

The UART driver used in this case is amba-pl011. Original fix, see
below Github link[2], was inside pl011 module, but somehow it didn't
look as the right place to fix. Beside that this original rounding
function is not exactly perfect for all possible clock values. So I
deiced to move the hack to the platform which actually need it.

The UART clock is initialised to be as close to the requested
frequency as possible without exceeding it. Now that there is a
clock manager that returns the actual frequencies, an expected
48MHz clock is reported as 47999625. If the requested baud rate
== requested clock/16, there is no headroom and the slight
reduction in actual clock rate results in failure.

If increasing a clock by less than 0.1% changes it from ..999..
to ..000.., round it up.

[1] https://bugzilla.suse.com/show_bug.cgi?id=1188238
[2] https://github.com/raspberrypi/linux/commit/ab3f1b39537f6d3825b8873006fbe2fc5ff057b7

Cc: Phil Elwell <phil@raspberrypi.com>
Signed-off-by: Ivan T. Ivanov <iivanov@suse.de>
Reviewed-by: Stefan Wahren <stefan.wahren@i2se.com>
Link: https://lore.kernel.org/r/20220912081306.24662-1-iivanov@suse.de
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/bcm/clk-bcm2835.c