From: Stefan Wahren <stefan.wahren@i2se.com>
To: "Ivan T. Ivanov" <iivanov@suse.de>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>,
Florian Fainelli <f.fainelli@gmail.com>,
Ray Jui <rjui@broadcom.com>,
Scott Branden <sbranden@broadcom.com>,
Broadcom internal kernel review list
<bcm-kernel-feedback-list@broadcom.com>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Maxime Ripard <maxime@cerno.tech>,
Nicolas Saenz Julienne <nsaenz@kernel.org>
Cc: Phil Elwell <phil@raspberrypi.com>,
kernel test robot <lkp@intel.com>,
linux-clk@vger.kernel.org, linux-rpi-kernel@lists.infradead.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org
Subject: Re: [PATCH v4] clk: bcm2835: Round UART input clock up
Date: Sun, 4 Sep 2022 15:49:11 +0200 [thread overview]
Message-ID: <9afe7000-d4c7-0b67-1dfd-7200efe73c0e@i2se.com> (raw)
In-Reply-To: <20220829132943.144608-1-iivanov@suse.de>
Hi Ivan,
Am 29.08.22 um 15:29 schrieb Ivan T. Ivanov:
> 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>
> ---
>
> Changes since v3
> * Rework 'scaler' calculation to avoid overflow
> * Update Phil Elwell email address
>
> Changes since v2
> * Added more information in commit message
> * Changed hand crafted round function with the one form math.h
>
> Changes since v1
> Make bcm2835_clock_round() static to fix following warning
> when compiling for riscv:
> drivers/clk/bcm/clk-bcm2835.c:997:15: warning: no previous prototype for 'bcm2835_clock_round' [-Wmissing-prototypes]
> Reported-by: kernel test robot <lkp@intel.com>
>
> drivers/clk/bcm/clk-bcm2835.c | 35 +++++++++++++++++++++++++++++++++--
> 1 file changed, 33 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/clk/bcm/clk-bcm2835.c b/drivers/clk/bcm/clk-bcm2835.c
> index 48a1eb9f2d55..26a5c9a0dd34 100644
> --- a/drivers/clk/bcm/clk-bcm2835.c
> +++ b/drivers/clk/bcm/clk-bcm2835.c
> @@ -30,6 +30,7 @@
> #include <linux/debugfs.h>
> #include <linux/delay.h>
> #include <linux/io.h>
> +#include <linux/math.h>
> #include <linux/module.h>
> #include <linux/of_device.h>
> #include <linux/platform_device.h>
> @@ -502,6 +503,8 @@ struct bcm2835_clock_data {
> bool low_jitter;
>
> u32 tcnt_mux;
> +
> + bool round_up;
> };
>
> struct bcm2835_gate_data {
> @@ -993,12 +996,34 @@ static long bcm2835_clock_rate_from_divisor(struct bcm2835_clock *clock,
> return temp;
> }
>
> +static unsigned long bcm2835_clock_round(unsigned long clk)
sorry, i missed this in my last mail. Please use "rate" instead of "clk"
here.
> +{
> + unsigned long scaler;
> + unsigned long limit;;
> +
> + limit = clk / 100000;
> +
> + scaler = 1;
> + while (scaler < limit)
> + scaler *= 10;
> +
> + /*
> + * If increasing a clock by less than 0.1% changes it
> + * from ..999.. to ..000.., round up.
> + */
> + if ((clk + scaler - 1) / scaler % 1000 == 0)
> + clk = roundup(clk, scaler);
> +
> + return clk;
> +}
> +
>
prev parent reply other threads:[~2022-09-04 13:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-29 13:29 Ivan T. Ivanov
2022-09-04 13:38 ` Stefan Wahren
2022-09-04 13:49 ` Stefan Wahren [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9afe7000-d4c7-0b67-1dfd-7200efe73c0e@i2se.com \
--to=stefan.wahren@i2se.com \
--cc=aou@eecs.berkeley.edu \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=f.fainelli@gmail.com \
--cc=iivanov@suse.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-rpi-kernel@lists.infradead.org \
--cc=lkp@intel.com \
--cc=maxime@cerno.tech \
--cc=mturquette@baylibre.com \
--cc=nsaenz@kernel.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=phil@raspberrypi.com \
--cc=rjui@broadcom.com \
--cc=sboyd@kernel.org \
--cc=sbranden@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®