* [PATCH v3 0/5] clk: imx: scu and fracn pll update
@ 2024-10-27 12:00 Peng Fan (OSS)
2024-10-27 12:00 ` [PATCH v3 1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858) Peng Fan (OSS)
` (5 more replies)
0 siblings, 6 replies; 10+ messages in thread
From: Peng Fan (OSS) @ 2024-10-27 12:00 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Abel Vesa,
Peng Fan, Jacky Bai, Carlos Song
Patch 1 is to resubmit [1] with comments addressed.
Patch 2 and Patch 3 are for i.MX93 Fracn PLL fix.
Patch 4 is for clk scu fix
Patch 5 is for hdmi. Fix tag not needed.
Detailed information is in commit log of each patch.
[1] https://lore.kernel.org/lkml/20240228082649.1633083-1-peng.fan@oss.nxp.com/
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
Changes in v3:
- Drop some comments in patch 1 per Abel
- Address build warning per kernel robot in patch 1
- Add a new patch, patch 4
- Link to v2: https://lore.kernel.org/r/20241018-imx-clk-v1-v2-0-92c0b66ca970@nxp.com
Changes in v2:
- Patch 1: use HZ_PER_MHZ, use unsigned long, add errata link
- Patch 4: Drop fence_write, just use readl
- Link to v1: https://lore.kernel.org/r/20241014-imx-clk-v1-v1-0-ee75876d3102@nxp.com
---
Dong Aisheng (1):
clk: imx: clk-scu: fix clk enable state save and restore
Peng Fan (4):
clk: imx: lpcg-scu: SW workaround for errata (e10858)
clk: imx: fracn-gppll: correct PLL initialization flow
clk: imx: fracn-gppll: fix pll power up
clk: imx: lpcg-scu: Skip HDMI LPCG clock save/restore
drivers/clk/imx/clk-fracn-gppll.c | 10 +++++++---
drivers/clk/imx/clk-lpcg-scu.c | 41 ++++++++++++++++++++++++++++++++-------
drivers/clk/imx/clk-scu.c | 2 +-
3 files changed, 42 insertions(+), 11 deletions(-)
---
base-commit: 099aca1fb909cf2295ae6eac3c2fa34026f1047d
change-id: 20241014-imx-clk-v1-24c26cfa1d79
Best regards,
--
Peng Fan <peng.fan@nxp.com>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858)
2024-10-27 12:00 [PATCH v3 0/5] clk: imx: scu and fracn pll update Peng Fan (OSS)
@ 2024-10-27 12:00 ` Peng Fan (OSS)
2024-11-05 9:58 ` Abel Vesa
2024-10-27 12:00 ` [PATCH v3 2/5] clk: imx: fracn-gppll: correct PLL initialization flow Peng Fan (OSS)
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Peng Fan (OSS) @ 2024-10-27 12:00 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Abel Vesa,
Peng Fan
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>
---
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
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 2/5] clk: imx: fracn-gppll: correct PLL initialization flow
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-10-27 12:00 ` 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)
` (3 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Peng Fan (OSS) @ 2024-10-27 12:00 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Abel Vesa,
Peng Fan, Jacky Bai
From: Peng Fan <peng.fan@nxp.com>
Per i.MX93 Reference Mannual 22.4 Initialization information
1. Program appropriate value of DIV[ODIV], DIV[RDIV] and DIV[MFI]
as per Integer mode.
2. Wait for 5 μs.
3. Program the following field in CTRL register.
Set CTRL[POWERUP] to 1'b1 to enable PLL block.
4. Poll PLL_STATUS[PLL_LOCK] register, and wait till PLL_STATUS[PLL_LOCK]
is 1'b1 and pll_lock output signal is 1'b1.
5. Set CTRL[CLKMUX_EN] to 1'b1 to enable PLL output clock.
So move the CLKMUX_EN operation after PLL locked.
Fixes: 1b26cb8a77a4 ("clk: imx: support fracn gppll")
Co-developed-by: Jacky Bai <ping.bai@nxp.com>
Signed-off-by: Jacky Bai <ping.bai@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/clk/imx/clk-fracn-gppll.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/imx/clk-fracn-gppll.c b/drivers/clk/imx/clk-fracn-gppll.c
index 591e0364ee5c113859a7b6271c8c11e98a0e0ffc..4749c3e0b7051cf53876664808aa28742f6861f7 100644
--- a/drivers/clk/imx/clk-fracn-gppll.c
+++ b/drivers/clk/imx/clk-fracn-gppll.c
@@ -303,13 +303,13 @@ static int clk_fracn_gppll_prepare(struct clk_hw *hw)
val |= POWERUP_MASK;
writel_relaxed(val, pll->base + PLL_CTRL);
- val |= CLKMUX_EN;
- writel_relaxed(val, pll->base + PLL_CTRL);
-
ret = clk_fracn_gppll_wait_lock(pll);
if (ret)
return ret;
+ val |= CLKMUX_EN;
+ writel_relaxed(val, pll->base + PLL_CTRL);
+
val &= ~CLKMUX_BYPASS;
writel_relaxed(val, pll->base + PLL_CTRL);
--
2.37.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 3/5] clk: imx: fracn-gppll: fix pll power up
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-10-27 12:00 ` [PATCH v3 2/5] clk: imx: fracn-gppll: correct PLL initialization flow Peng Fan (OSS)
@ 2024-10-27 12:00 ` 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)
` (2 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Peng Fan (OSS) @ 2024-10-27 12:00 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Abel Vesa,
Peng Fan, Jacky Bai
From: Peng Fan <peng.fan@nxp.com>
To i.MX93 which features dual Cortex-A55 cores and DSU, when using
writel_relaxed to write value to PLL registers, the value might be
buffered. To make sure the value has been written into the hardware,
using readl to read back the register could achieve the goal.
current PLL power up flow can be simplified as below:
1. writel_relaxed to set the PLL POWERUP bit;
2. readl_poll_timeout to check the PLL lock bit:
a). timeout = ktime_add_us(ktime_get(), timeout_us);
b). readl the pll the lock reg;
c). check if the pll lock bit ready
d). check if timeout
But in some corner cases, both the write in step 1 and read in
step 2 will be blocked by other bus transaction in the SoC for a
long time, saying the value into real hardware is just before step b).
That means the timeout counting has begins for quite sometime since
step a), but value still not written into real hardware until bus
released just at a point before step b).
Then there maybe chances that the pll lock bit is not ready
when readl done but the timeout happens. readl_poll_timeout will
err return due to timeout. To avoid such unexpected failure,
read back the reg to make sure the write has been done in HW
reg.
So use readl after writel_relaxed to fix the issue.
Since we are here, to avoid udelay to run before writel_relaxed, use
readl before udelay.
Fixes: 1b26cb8a77a4 ("clk: imx: support fracn gppll")
Co-developed-by: Jacky Bai <ping.bai@nxp.com>
Signed-off-by: Jacky Bai <ping.bai@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/clk/imx/clk-fracn-gppll.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/clk/imx/clk-fracn-gppll.c b/drivers/clk/imx/clk-fracn-gppll.c
index 4749c3e0b7051cf53876664808aa28742f6861f7..85771afd4698ae6a0d8a7e82193301e187049255 100644
--- a/drivers/clk/imx/clk-fracn-gppll.c
+++ b/drivers/clk/imx/clk-fracn-gppll.c
@@ -254,9 +254,11 @@ static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate,
pll_div = FIELD_PREP(PLL_RDIV_MASK, rate->rdiv) | rate->odiv |
FIELD_PREP(PLL_MFI_MASK, rate->mfi);
writel_relaxed(pll_div, pll->base + PLL_DIV);
+ readl(pll->base + PLL_DIV);
if (pll->flags & CLK_FRACN_GPPLL_FRACN) {
writel_relaxed(rate->mfd, pll->base + PLL_DENOMINATOR);
writel_relaxed(FIELD_PREP(PLL_MFN_MASK, rate->mfn), pll->base + PLL_NUMERATOR);
+ readl(pll->base + PLL_NUMERATOR);
}
/* Wait for 5us according to fracn mode pll doc */
@@ -265,6 +267,7 @@ static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate,
/* Enable Powerup */
tmp |= POWERUP_MASK;
writel_relaxed(tmp, pll->base + PLL_CTRL);
+ readl(pll->base + PLL_CTRL);
/* Wait Lock */
ret = clk_fracn_gppll_wait_lock(pll);
@@ -302,6 +305,7 @@ static int clk_fracn_gppll_prepare(struct clk_hw *hw)
val |= POWERUP_MASK;
writel_relaxed(val, pll->base + PLL_CTRL);
+ readl(pll->base + PLL_CTRL);
ret = clk_fracn_gppll_wait_lock(pll);
if (ret)
--
2.37.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 4/5] clk: imx: clk-scu: fix clk enable state save and restore
2024-10-27 12:00 [PATCH v3 0/5] clk: imx: scu and fracn pll update Peng Fan (OSS)
` (2 preceding siblings ...)
2024-10-27 12:00 ` [PATCH v3 3/5] clk: imx: fracn-gppll: fix pll power up Peng Fan (OSS)
@ 2024-10-27 12:00 ` 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
5 siblings, 0 replies; 10+ messages in thread
From: Peng Fan (OSS) @ 2024-10-27 12:00 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Abel Vesa,
Peng Fan, Carlos Song
From: Dong Aisheng <aisheng.dong@nxp.com>
The scu clk_ops only inplements prepare() and unprepare() callback.
Saving the clock state during suspend by checking clk_hw_is_enabled()
is not safe as it's possible that some device drivers may only
disable the clocks without unprepare. Then the state retention will not
work for such clocks.
Fixing it by checking clk_hw_is_prepared() which is more reasonable
and safe.
Fixes: d0409631f466 ("clk: imx: scu: add suspend/resume support")
Reviewed-by: Peng Fan <peng.fan@nxp.com>
Tested-by: Carlos Song <carlos.song@nxp.com>
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
drivers/clk/imx/clk-scu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/imx/clk-scu.c b/drivers/clk/imx/clk-scu.c
index b1dd0c08e091b6b61f6972eb630adacaa4f288c2..b27186aaf2a15628910ea6a3d4aaa5320ec4295a 100644
--- a/drivers/clk/imx/clk-scu.c
+++ b/drivers/clk/imx/clk-scu.c
@@ -596,7 +596,7 @@ static int __maybe_unused imx_clk_scu_suspend(struct device *dev)
clk->rate = clk_scu_recalc_rate(&clk->hw, 0);
else
clk->rate = clk_hw_get_rate(&clk->hw);
- clk->is_enabled = clk_hw_is_enabled(&clk->hw);
+ clk->is_enabled = clk_hw_is_prepared(&clk->hw);
if (clk->parent)
dev_dbg(dev, "save parent %s idx %u\n", clk_hw_get_name(clk->parent),
--
2.37.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH v3 5/5] clk: imx: lpcg-scu: Skip HDMI LPCG clock save/restore
2024-10-27 12:00 [PATCH v3 0/5] clk: imx: scu and fracn pll update Peng Fan (OSS)
` (3 preceding siblings ...)
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 ` Peng Fan (OSS)
2024-11-05 10:21 ` [PATCH v3 0/5] clk: imx: scu and fracn pll update Abel Vesa
5 siblings, 0 replies; 10+ messages in thread
From: Peng Fan (OSS) @ 2024-10-27 12:00 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Abel Vesa,
Peng Fan
From: Peng Fan <peng.fan@nxp.com>
On i.MX8QM, HDMI LPCG clocks operation needs SCU clock "hdmi_ipg_clk"
to be ON. While during noirq suspend phase, "hdmi_ipg_clk" is disabled
by HDMI IRQ STEER driver, so SError will be triggered when accessing
the HDMI LPCG registers.
Skip all HDMI LPCG clocks save/restore to avoid SError during
system suspend/resume, it will NOT introduce additional power consumption
as their parent clock is disabled when suspend.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/clk/imx/clk-lpcg-scu.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/clk/imx/clk-lpcg-scu.c b/drivers/clk/imx/clk-lpcg-scu.c
index 620afdf8dc03e9564bb074ca879cf778f7fc6419..6376557a3c3d03130ca8168a6cb69eda73c43abe 100644
--- a/drivers/clk/imx/clk-lpcg-scu.c
+++ b/drivers/clk/imx/clk-lpcg-scu.c
@@ -161,6 +161,9 @@ static int __maybe_unused imx_clk_lpcg_scu_suspend(struct device *dev)
{
struct clk_lpcg_scu *clk = dev_get_drvdata(dev);
+ if (!strncmp("hdmi_lpcg", clk_hw_get_name(&clk->hw), strlen("hdmi_lpcg")))
+ return 0;
+
clk->state = readl_relaxed(clk->reg);
dev_dbg(dev, "save lpcg state 0x%x\n", clk->state);
@@ -171,6 +174,9 @@ static int __maybe_unused imx_clk_lpcg_scu_resume(struct device *dev)
{
struct clk_lpcg_scu *clk = dev_get_drvdata(dev);
+ if (!strncmp("hdmi_lpcg", clk_hw_get_name(&clk->hw), strlen("hdmi_lpcg")))
+ return 0;
+
writel(clk->state, clk->reg);
lpcg_e10858_writel(0, clk->reg, clk->state);
dev_dbg(dev, "restore lpcg state 0x%x\n", clk->state);
--
2.37.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH v3 1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858)
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
0 siblings, 0 replies; 10+ messages in thread
From: Abel Vesa @ 2024-11-05 9:58 UTC (permalink / raw)
To: Peng Fan (OSS)
Cc: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong, linux-clk, imx, linux-arm-kernel, linux-kernel,
Peng Fan
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
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 2/5] clk: imx: fracn-gppll: correct PLL initialization flow
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
0 siblings, 0 replies; 10+ messages in thread
From: Abel Vesa @ 2024-11-05 9:59 UTC (permalink / raw)
To: Peng Fan (OSS)
Cc: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong, linux-clk, imx, linux-arm-kernel, linux-kernel,
Peng Fan, Jacky Bai
On 24-10-27 20:00:08, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> Per i.MX93 Reference Mannual 22.4 Initialization information
> 1. Program appropriate value of DIV[ODIV], DIV[RDIV] and DIV[MFI]
> as per Integer mode.
> 2. Wait for 5 μs.
> 3. Program the following field in CTRL register.
> Set CTRL[POWERUP] to 1'b1 to enable PLL block.
> 4. Poll PLL_STATUS[PLL_LOCK] register, and wait till PLL_STATUS[PLL_LOCK]
> is 1'b1 and pll_lock output signal is 1'b1.
> 5. Set CTRL[CLKMUX_EN] to 1'b1 to enable PLL output clock.
>
> So move the CLKMUX_EN operation after PLL locked.
>
> Fixes: 1b26cb8a77a4 ("clk: imx: support fracn gppll")
> Co-developed-by: Jacky Bai <ping.bai@nxp.com>
> Signed-off-by: Jacky Bai <ping.bai@nxp.com>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> drivers/clk/imx/clk-fracn-gppll.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/imx/clk-fracn-gppll.c b/drivers/clk/imx/clk-fracn-gppll.c
> index 591e0364ee5c113859a7b6271c8c11e98a0e0ffc..4749c3e0b7051cf53876664808aa28742f6861f7 100644
> --- a/drivers/clk/imx/clk-fracn-gppll.c
> +++ b/drivers/clk/imx/clk-fracn-gppll.c
> @@ -303,13 +303,13 @@ static int clk_fracn_gppll_prepare(struct clk_hw *hw)
> val |= POWERUP_MASK;
> writel_relaxed(val, pll->base + PLL_CTRL);
>
> - val |= CLKMUX_EN;
> - writel_relaxed(val, pll->base + PLL_CTRL);
> -
> ret = clk_fracn_gppll_wait_lock(pll);
> if (ret)
> return ret;
>
> + val |= CLKMUX_EN;
> + writel_relaxed(val, pll->base + PLL_CTRL);
> +
> val &= ~CLKMUX_BYPASS;
> writel_relaxed(val, pll->base + PLL_CTRL);
>
>
> --
> 2.37.1
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 3/5] clk: imx: fracn-gppll: fix pll power up
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
0 siblings, 0 replies; 10+ messages in thread
From: Abel Vesa @ 2024-11-05 10:00 UTC (permalink / raw)
To: Peng Fan (OSS)
Cc: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong, linux-clk, imx, linux-arm-kernel, linux-kernel,
Peng Fan, Jacky Bai
On 24-10-27 20:00:09, Peng Fan (OSS) wrote:
> From: Peng Fan <peng.fan@nxp.com>
>
> To i.MX93 which features dual Cortex-A55 cores and DSU, when using
> writel_relaxed to write value to PLL registers, the value might be
> buffered. To make sure the value has been written into the hardware,
> using readl to read back the register could achieve the goal.
>
> current PLL power up flow can be simplified as below:
> 1. writel_relaxed to set the PLL POWERUP bit;
> 2. readl_poll_timeout to check the PLL lock bit:
> a). timeout = ktime_add_us(ktime_get(), timeout_us);
> b). readl the pll the lock reg;
> c). check if the pll lock bit ready
> d). check if timeout
>
> But in some corner cases, both the write in step 1 and read in
> step 2 will be blocked by other bus transaction in the SoC for a
> long time, saying the value into real hardware is just before step b).
> That means the timeout counting has begins for quite sometime since
> step a), but value still not written into real hardware until bus
> released just at a point before step b).
>
> Then there maybe chances that the pll lock bit is not ready
> when readl done but the timeout happens. readl_poll_timeout will
> err return due to timeout. To avoid such unexpected failure,
> read back the reg to make sure the write has been done in HW
> reg.
>
> So use readl after writel_relaxed to fix the issue.
>
> Since we are here, to avoid udelay to run before writel_relaxed, use
> readl before udelay.
>
> Fixes: 1b26cb8a77a4 ("clk: imx: support fracn gppll")
> Co-developed-by: Jacky Bai <ping.bai@nxp.com>
> Signed-off-by: Jacky Bai <ping.bai@nxp.com>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Abel Vesa <abel.vesa@linaro.org>
> ---
> drivers/clk/imx/clk-fracn-gppll.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/drivers/clk/imx/clk-fracn-gppll.c b/drivers/clk/imx/clk-fracn-gppll.c
> index 4749c3e0b7051cf53876664808aa28742f6861f7..85771afd4698ae6a0d8a7e82193301e187049255 100644
> --- a/drivers/clk/imx/clk-fracn-gppll.c
> +++ b/drivers/clk/imx/clk-fracn-gppll.c
> @@ -254,9 +254,11 @@ static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate,
> pll_div = FIELD_PREP(PLL_RDIV_MASK, rate->rdiv) | rate->odiv |
> FIELD_PREP(PLL_MFI_MASK, rate->mfi);
> writel_relaxed(pll_div, pll->base + PLL_DIV);
> + readl(pll->base + PLL_DIV);
> if (pll->flags & CLK_FRACN_GPPLL_FRACN) {
> writel_relaxed(rate->mfd, pll->base + PLL_DENOMINATOR);
> writel_relaxed(FIELD_PREP(PLL_MFN_MASK, rate->mfn), pll->base + PLL_NUMERATOR);
> + readl(pll->base + PLL_NUMERATOR);
> }
>
> /* Wait for 5us according to fracn mode pll doc */
> @@ -265,6 +267,7 @@ static int clk_fracn_gppll_set_rate(struct clk_hw *hw, unsigned long drate,
> /* Enable Powerup */
> tmp |= POWERUP_MASK;
> writel_relaxed(tmp, pll->base + PLL_CTRL);
> + readl(pll->base + PLL_CTRL);
>
> /* Wait Lock */
> ret = clk_fracn_gppll_wait_lock(pll);
> @@ -302,6 +305,7 @@ static int clk_fracn_gppll_prepare(struct clk_hw *hw)
>
> val |= POWERUP_MASK;
> writel_relaxed(val, pll->base + PLL_CTRL);
> + readl(pll->base + PLL_CTRL);
>
> ret = clk_fracn_gppll_wait_lock(pll);
> if (ret)
>
> --
> 2.37.1
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/5] clk: imx: scu and fracn pll update
2024-10-27 12:00 [PATCH v3 0/5] clk: imx: scu and fracn pll update Peng Fan (OSS)
` (4 preceding siblings ...)
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 ` Abel Vesa
5 siblings, 0 replies; 10+ messages in thread
From: Abel Vesa @ 2024-11-05 10:21 UTC (permalink / raw)
To: Abel Vesa, Michael Turquette, Stephen Boyd, Shawn Guo,
Sascha Hauer, Pengutronix Kernel Team, Fabio Estevam,
Aisheng Dong, Peng Fan (OSS)
Cc: linux-clk, imx, linux-arm-kernel, linux-kernel, Peng Fan,
Jacky Bai, Carlos Song
On Sun, 27 Oct 2024 20:00:06 +0800, Peng Fan (OSS) wrote:
> Patch 1 is to resubmit [1] with comments addressed.
> Patch 2 and Patch 3 are for i.MX93 Fracn PLL fix.
> Patch 4 is for clk scu fix
> Patch 5 is for hdmi. Fix tag not needed.
>
> Detailed information is in commit log of each patch.
>
> [...]
Applied, thanks!
[1/5] clk: imx: lpcg-scu: SW workaround for errata (e10858)
commit: 5ee063fac85656bea9cfe3570af147ba1701ba18
[2/5] clk: imx: fracn-gppll: correct PLL initialization flow
commit: 557be501c38e1864b948fc6ccdf4b035d610a2ea
[3/5] clk: imx: fracn-gppll: fix pll power up
commit: ff4279618f0aec350b0fb41b2b35841324fbd96e
[4/5] clk: imx: clk-scu: fix clk enable state save and restore
commit: e81361f6cf9bf4a1848b0813bc4becb2250870b8
[5/5] clk: imx: lpcg-scu: Skip HDMI LPCG clock save/restore
commit: 92888f39193419c117e282cce7fd762ba78784a4
Best regards,
--
Abel Vesa <abel.vesa@linaro.org>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2024-11-05 10:24 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).