Skip to content

Commit 538d547

Browse files
SFxingyuwubebarino
authored andcommitted
clk: starfive: jh7110-sys: Add notifier for PLL0 clock
Add notifier function for PLL0 clock. In the function, the cpu_root clock should be operated by saving its current parent and setting a new safe parent (osc clock) before setting the PLL0 clock rate. After setting PLL0 rate, it should be switched back to the original parent clock. Fixes: e2c510d ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC") Cc: stable@vger.kernel.org Reviewed-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com> Link: https://lore.kernel.org/r/20240826080430.179788-2-xingyu.wu@starfivetech.com Reviewed-by: Hal Feng <hal.feng@starfivetech.com> Tested-by: Michael Jeanson <mjeanson@efficios.com> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
1 parent aa2eb2c commit 538d547

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

drivers/clk/starfive/clk-starfive-jh7110-sys.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,32 @@ int jh7110_reset_controller_register(struct jh71x0_clk_priv *priv,
385385
}
386386
EXPORT_SYMBOL_GPL(jh7110_reset_controller_register);
387387

388+
/*
389+
* This clock notifier is called when the rate of PLL0 clock is to be changed.
390+
* The cpu_root clock should save the curent parent clock and switch its parent
391+
* clock to osc before PLL0 rate will be changed. Then switch its parent clock
392+
* back after the PLL0 rate is completed.
393+
*/
394+
static int jh7110_pll0_clk_notifier_cb(struct notifier_block *nb,
395+
unsigned long action, void *data)
396+
{
397+
struct jh71x0_clk_priv *priv = container_of(nb, struct jh71x0_clk_priv, pll_clk_nb);
398+
struct clk *cpu_root = priv->reg[JH7110_SYSCLK_CPU_ROOT].hw.clk;
399+
int ret = 0;
400+
401+
if (action == PRE_RATE_CHANGE) {
402+
struct clk *osc = clk_get(priv->dev, "osc");
403+
404+
priv->original_clk = clk_get_parent(cpu_root);
405+
ret = clk_set_parent(cpu_root, osc);
406+
clk_put(osc);
407+
} else if (action == POST_RATE_CHANGE) {
408+
ret = clk_set_parent(cpu_root, priv->original_clk);
409+
}
410+
411+
return notifier_from_errno(ret);
412+
}
413+
388414
static int __init jh7110_syscrg_probe(struct platform_device *pdev)
389415
{
390416
struct jh71x0_clk_priv *priv;
@@ -413,7 +439,10 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
413439
if (IS_ERR(priv->pll[0]))
414440
return PTR_ERR(priv->pll[0]);
415441
} else {
416-
clk_put(pllclk);
442+
priv->pll_clk_nb.notifier_call = jh7110_pll0_clk_notifier_cb;
443+
ret = clk_notifier_register(pllclk, &priv->pll_clk_nb);
444+
if (ret)
445+
return ret;
417446
priv->pll[0] = NULL;
418447
}
419448

drivers/clk/starfive/clk-starfive-jh71x0.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ struct jh71x0_clk_priv {
114114
spinlock_t rmw_lock;
115115
struct device *dev;
116116
void __iomem *base;
117+
struct clk *original_clk;
118+
struct notifier_block pll_clk_nb;
117119
struct clk_hw *pll[3];
118120
struct jh71x0_clk reg[];
119121
};

0 commit comments

Comments
 (0)