From nobody Fri Dec 19 16:01:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 812C9FA374E for ; Mon, 24 Oct 2022 16:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235693AbiJXQyx (ORCPT ); Mon, 24 Oct 2022 12:54:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235526AbiJXQts (ORCPT ); Mon, 24 Oct 2022 12:49:48 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688321C939; Mon, 24 Oct 2022 08:33:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 21FBAB81A1D; Mon, 24 Oct 2022 12:55:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E1F8C433D6; Mon, 24 Oct 2022 12:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666616119; bh=dGzsi4pDI1Jp9PjrvwwEhtLRXOy69barBNPW9yRhwBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Padg/s8LJJLKsx1K9vWm40og14de9j9Prpkj0+M3sBpZD098n72m1Db3ySUnjJg51 lanZ98vXq3O7IIQ9Es6t7vCJpWrpF5F1qbk8ALEeQX5vcBILy0CE/LRz2baFpvFS2J QxzCjhhTN6uRpzhRSBg/43dTCrN13vqCskoYur9Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Phil Elwell , "Ivan T. Ivanov" , Stefan Wahren , Stephen Boyd , Sasha Levin Subject: [PATCH 5.15 509/530] clk: bcm2835: Round UART input clock up Date: Mon, 24 Oct 2022 13:34:13 +0200 Message-Id: <20221024113108.075605977@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113044.976326639@linuxfoundation.org> References: <20221024113044.976326639@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ivan T. Ivanov [ Upstream commit f690a4d7a8f66430662975511c86819dc9965bcc ] 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 =3D=3D 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=3D1188238 [2] https://github.com/raspberrypi/linux/commit/ab3f1b39537f6d3825b8873006f= be2fc5ff057b7 Cc: Phil Elwell Signed-off-by: Ivan T. Ivanov Reviewed-by: Stefan Wahren Link: https://lore.kernel.org/r/20220912081306.24662-1-iivanov@suse.de Signed-off-by: Stephen Boyd Signed-off-by: Sasha Levin --- 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 f17b65d546e9..141ce19bc570 100644 --- a/drivers/clk/bcm/clk-bcm2835.c +++ b/drivers/clk/bcm/clk-bcm2835.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -502,6 +503,8 @@ struct bcm2835_clock_data { bool low_jitter; =20 u32 tcnt_mux; + + bool round_up; }; =20 struct bcm2835_gate_data { @@ -994,12 +997,34 @@ static unsigned long bcm2835_clock_rate_from_divisor(= struct bcm2835_clock *clock return temp; } =20 +static unsigned long bcm2835_round_rate(unsigned long rate) +{ + unsigned long scaler; + unsigned long limit; + + limit =3D rate / 100000; + + scaler =3D 1; + while (scaler < limit) + scaler *=3D 10; + + /* + * If increasing a clock by less than 0.1% changes it + * from ..999.. to ..000.., round up. + */ + if ((rate + scaler - 1) / scaler % 1000 =3D=3D 0) + rate =3D roundup(rate, scaler); + + return rate; +} + static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw, unsigned long parent_rate) { struct bcm2835_clock *clock =3D bcm2835_clock_from_hw(hw); struct bcm2835_cprman *cprman =3D clock->cprman; const struct bcm2835_clock_data *data =3D clock->data; + unsigned long rate; u32 div; =20 if (data->int_bits =3D=3D 0 && data->frac_bits =3D=3D 0) @@ -1007,7 +1032,12 @@ static unsigned long bcm2835_clock_get_rate(struct c= lk_hw *hw, =20 div =3D cprman_read(cprman, data->div_reg); =20 - return bcm2835_clock_rate_from_divisor(clock, parent_rate, div); + rate =3D bcm2835_clock_rate_from_divisor(clock, parent_rate, div); + + if (data->round_up) + rate =3D bcm2835_round_rate(rate); + + return rate; } =20 static void bcm2835_clock_wait_busy(struct bcm2835_clock *clock) @@ -2144,7 +2174,8 @@ static const struct bcm2835_clk_desc clk_desc_array[]= =3D { .div_reg =3D CM_UARTDIV, .int_bits =3D 10, .frac_bits =3D 12, - .tcnt_mux =3D 28), + .tcnt_mux =3D 28, + .round_up =3D true), =20 /* TV encoder clock. Only operating frequency is 108Mhz. */ [BCM2835_CLOCK_VEC] =3D REGISTER_PER_CLK( --=20 2.35.1