Skip to content

Commit a013e98

Browse files
SFxingyuwuConchuOD
authored andcommitted
clk: starfive: jh7110-sys: Add PLL clocks source from DTS
Modify PLL clocks source to be got from DTS or the fixed factor clocks. Signed-off-by: Xingyu Wu <xingyu.wu@starfivetech.com> Reviewed-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
1 parent 616bc1d commit a013e98

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

drivers/clk/starfive/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ config CLK_STARFIVE_JH7110_SYS
3535
select AUXILIARY_BUS
3636
select CLK_STARFIVE_JH71X0
3737
select RESET_STARFIVE_JH7110 if RESET_CONTROLLER
38+
select CLK_STARFIVE_JH7110_PLL
3839
default ARCH_STARFIVE
3940
help
4041
Say yes here to support the system clock controller on the

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

Lines changed: 44 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/auxiliary_bus.h>
10+
#include <linux/clk.h>
1011
#include <linux/clk-provider.h>
1112
#include <linux/init.h>
1213
#include <linux/io.h>
@@ -389,6 +390,7 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
389390
struct jh71x0_clk_priv *priv;
390391
unsigned int idx;
391392
int ret;
393+
struct clk *pllclk;
392394

393395
priv = devm_kzalloc(&pdev->dev,
394396
struct_size(priv, reg, JH7110_SYSCLK_END),
@@ -402,28 +404,42 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
402404
if (IS_ERR(priv->base))
403405
return PTR_ERR(priv->base);
404406

405-
/*
406-
* These PLL clocks are not actually fixed factor clocks and can be
407-
* controlled by the syscon registers of JH7110. They will be dropped
408-
* and registered in the PLL clock driver instead.
409-
*/
410-
/* 24MHz -> 1000.0MHz */
411-
priv->pll[0] = devm_clk_hw_register_fixed_factor(priv->dev, "pll0_out",
412-
"osc", 0, 125, 3);
413-
if (IS_ERR(priv->pll[0]))
414-
return PTR_ERR(priv->pll[0]);
415-
416-
/* 24MHz -> 1066.0MHz */
417-
priv->pll[1] = devm_clk_hw_register_fixed_factor(priv->dev, "pll1_out",
418-
"osc", 0, 533, 12);
419-
if (IS_ERR(priv->pll[1]))
420-
return PTR_ERR(priv->pll[1]);
421-
422-
/* 24MHz -> 1188.0MHz */
423-
priv->pll[2] = devm_clk_hw_register_fixed_factor(priv->dev, "pll2_out",
424-
"osc", 0, 99, 2);
425-
if (IS_ERR(priv->pll[2]))
426-
return PTR_ERR(priv->pll[2]);
407+
/* Use fixed factor clocks if can not get the PLL clocks from DTS */
408+
pllclk = clk_get(priv->dev, "pll0_out");
409+
if (IS_ERR(pllclk)) {
410+
/* 24MHz -> 1000.0MHz */
411+
priv->pll[0] = devm_clk_hw_register_fixed_factor(priv->dev, "pll0_out",
412+
"osc", 0, 125, 3);
413+
if (IS_ERR(priv->pll[0]))
414+
return PTR_ERR(priv->pll[0]);
415+
} else {
416+
clk_put(pllclk);
417+
priv->pll[0] = NULL;
418+
}
419+
420+
pllclk = clk_get(priv->dev, "pll1_out");
421+
if (IS_ERR(pllclk)) {
422+
/* 24MHz -> 1066.0MHz */
423+
priv->pll[1] = devm_clk_hw_register_fixed_factor(priv->dev, "pll1_out",
424+
"osc", 0, 533, 12);
425+
if (IS_ERR(priv->pll[1]))
426+
return PTR_ERR(priv->pll[1]);
427+
} else {
428+
clk_put(pllclk);
429+
priv->pll[1] = NULL;
430+
}
431+
432+
pllclk = clk_get(priv->dev, "pll2_out");
433+
if (IS_ERR(pllclk)) {
434+
/* 24MHz -> 1188.0MHz */
435+
priv->pll[2] = devm_clk_hw_register_fixed_factor(priv->dev, "pll2_out",
436+
"osc", 0, 99, 2);
437+
if (IS_ERR(priv->pll[2]))
438+
return PTR_ERR(priv->pll[2]);
439+
} else {
440+
clk_put(pllclk);
441+
priv->pll[2] = NULL;
442+
}
427443

428444
for (idx = 0; idx < JH7110_SYSCLK_END; idx++) {
429445
u32 max = jh7110_sysclk_data[idx].max;
@@ -462,6 +478,12 @@ static int __init jh7110_syscrg_probe(struct platform_device *pdev)
462478
parents[i].fw_name = "tdm_ext";
463479
else if (pidx == JH7110_SYSCLK_MCLK_EXT)
464480
parents[i].fw_name = "mclk_ext";
481+
else if (pidx == JH7110_SYSCLK_PLL0_OUT && !priv->pll[0])
482+
parents[i].fw_name = "pll0_out";
483+
else if (pidx == JH7110_SYSCLK_PLL1_OUT && !priv->pll[1])
484+
parents[i].fw_name = "pll1_out";
485+
else if (pidx == JH7110_SYSCLK_PLL2_OUT && !priv->pll[2])
486+
parents[i].fw_name = "pll2_out";
465487
else
466488
parents[i].hw = priv->pll[pidx - JH7110_SYSCLK_PLL0_OUT];
467489
}

0 commit comments

Comments
 (0)