From: Abel Vesa <abel.vesa@linaro.org>
To: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
Cc: Abel Vesa <abelvesa@kernel.org>,
Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@kernel.org>, Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
Aisheng Dong <aisheng.dong@nxp.com>,
linux-clk@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Peng Fan <peng.fan@nxp.com>
Subject: Re: [PATCH v3 1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858)
Date: Tue, 5 Nov 2024 11:58:54 +0200 [thread overview]
Message-ID: <ZynsXhzcoyfCzLwq@linaro.org> (raw)
In-Reply-To: <20241027-imx-clk-v1-v3-1-89152574d1d7@nxp.com>
On 24-10-27 20:00:07, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> Back-to-back LPCG writes can be ignored by the LPCG register due to
> a HW bug. The writes need to be separated by at least 4 cycles of
> the gated clock. See https://www.nxp.com.cn/docs/en/errata/IMX8_1N94W.pdf
>
> The workaround is implemented as follows:
> 1. For clocks running greater than or equal to 24MHz, a read
> followed by the write will provide sufficient delay.
> 2. For clocks running below 24MHz, add a delay of 4 clock cylces
> after the write to the LPCG register.
>
> Fixes: 2f77296d3df9 ("clk: imx: add lpcg clock support")
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> drivers/clk/imx/clk-lpcg-scu.c | 37 +++++++++++++++++++++++++++++--------
> 1 file changed, 29 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/clk/imx/clk-lpcg-scu.c b/drivers/clk/imx/clk-lpcg-scu.c
> index dd5abd09f3e206a5073767561b517d5b3320b28c..620afdf8dc03e9564bb074ca879cf778f7fc6419 100644
> --- a/drivers/clk/imx/clk-lpcg-scu.c
> +++ b/drivers/clk/imx/clk-lpcg-scu.c
> @@ -6,10 +6,12 @@
>
> #include <linux/bits.h>
> #include <linux/clk-provider.h>
> +#include <linux/delay.h>
> #include <linux/err.h>
> #include <linux/io.h>
> #include <linux/slab.h>
> #include <linux/spinlock.h>
> +#include <linux/units.h>
>
> #include "clk-scu.h"
>
> @@ -41,6 +43,29 @@ struct clk_lpcg_scu {
>
> #define to_clk_lpcg_scu(_hw) container_of(_hw, struct clk_lpcg_scu, hw)
>
> +/* e10858 -LPCG clock gating register synchronization errata */
> +static void lpcg_e10858_writel(unsigned long rate, void __iomem *reg, u32 val)
> +{
> + writel(val, reg);
> +
> + if (rate >= 24 * HZ_PER_MHZ || rate == 0) {
> + /*
> + * The time taken to access the LPCG registers from the AP core
> + * through the interconnect is longer than the minimum delay
> + * of 4 clock cycles required by the errata.
> + * Adding a readl will provide sufficient delay to prevent
> + * back-to-back writes.
> + */
> + readl(reg);
> + } else {
> + /*
> + * For clocks running below 24MHz, wait a minimum of
> + * 4 clock cycles.
> + */
> + ndelay(4 * (DIV_ROUND_UP(1000 * HZ_PER_MHZ, rate)));
> + }
> +}
> +
> static int clk_lpcg_scu_enable(struct clk_hw *hw)
> {
> struct clk_lpcg_scu *clk = to_clk_lpcg_scu(hw);
> @@ -57,7 +82,8 @@ static int clk_lpcg_scu_enable(struct clk_hw *hw)
> val |= CLK_GATE_SCU_LPCG_HW_SEL;
>
> reg |= val << clk->bit_idx;
> - writel(reg, clk->reg);
> +
> + lpcg_e10858_writel(clk_hw_get_rate(hw), clk->reg, reg);
>
> spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
>
> @@ -74,7 +100,7 @@ static void clk_lpcg_scu_disable(struct clk_hw *hw)
>
> reg = readl_relaxed(clk->reg);
> reg &= ~(CLK_GATE_SCU_LPCG_MASK << clk->bit_idx);
> - writel(reg, clk->reg);
> + lpcg_e10858_writel(clk_hw_get_rate(hw), clk->reg, reg);
>
> spin_unlock_irqrestore(&imx_lpcg_scu_lock, flags);
> }
> @@ -145,13 +171,8 @@ static int __maybe_unused imx_clk_lpcg_scu_resume(struct device *dev)
> {
> struct clk_lpcg_scu *clk = dev_get_drvdata(dev);
>
> - /*
> - * FIXME: Sometimes writes don't work unless the CPU issues
> - * them twice
> - */
> -
> - writel(clk->state, clk->reg);
> writel(clk->state, clk->reg);
> + lpcg_e10858_writel(0, clk->reg, clk->state);
> dev_dbg(dev, "restore lpcg state 0x%x\n", clk->state);
>
> return 0;
>
> --
> 2.37.1
>
next prev parent reply other threads:[~2024-11-05 10:02 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-27 12:00 [PATCH v3 0/5] clk: imx: scu and fracn pll update Peng Fan (OSS)
2024-10-27 12:00 ` [PATCH v3 1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858) Peng Fan (OSS)
2024-11-05 9:58 ` Abel Vesa [this message]
2024-10-27 12:00 ` [PATCH v3 2/5] clk: imx: fracn-gppll: correct PLL initialization flow Peng Fan (OSS)
2024-11-05 9:59 ` Abel Vesa
2024-10-27 12:00 ` [PATCH v3 3/5] clk: imx: fracn-gppll: fix pll power up Peng Fan (OSS)
2024-11-05 10:00 ` Abel Vesa
2024-10-27 12:00 ` [PATCH v3 4/5] clk: imx: clk-scu: fix clk enable state save and restore Peng Fan (OSS)
2024-10-27 12:00 ` [PATCH v3 5/5] clk: imx: lpcg-scu: Skip HDMI LPCG clock save/restore Peng Fan (OSS)
2024-11-05 10:21 ` [PATCH v3 0/5] clk: imx: scu and fracn pll update Abel Vesa
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=ZynsXhzcoyfCzLwq@linaro.org \
--to=abel.vesa@linaro.org \
--cc=abelvesa@kernel.org \
--cc=aisheng.dong@nxp.com \
--cc=festevam@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=peng.fan@nxp.com \
--cc=peng.fan@oss.nxp.com \
--cc=s.hauer@pengutronix.de \
--cc=sboyd@kernel.org \
--cc=shawnguo@kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).