Skip to contentSkip to conversation

clk: starfive: pll: Fix lower rate of CPUfreq by setting PLL0 rate to 1.5GHz

PATCH Superseded Xingyu Wu 4 participants 9 messages Apr 2, 2024 – Apr 7, 2024

Subsystems (6)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Xingyu Wu

author maintainer
#0 lore raw

PATCH v3 1/1 clk: starfive: pll: Fix lower rate of CPUfreq by setting PLL0 rate to 1.5GHz

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++
 2 files changed, 107 insertions(+)
arch/riscv/boot/dts/starfive/jh7110-starfive-visionfive-2.dtsi +5 -0
index 45b58b6f3df8..0c57d833fb29 100644
@@ -336,6 +336,11 @@ &pwmdac {
 	status = "okay";
 };
 
+&pllclk {
+	assigned-clocks = <&pllclk JH7110_PLLCLK_PLL0_OUT>;
+	assigned-clock-rates = <1500000000>;
+};
+
 &qspi {
 	#address-cells = <1>;
 	#size-cells = <0>;
drivers/clk/starfive/clk-starfive-jh7110-pll.c +102 -0

161 lines not on this page · raw message

Signature · 7 lines
2.25.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw
Quoted 35 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

...

Quoted 11 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct platform_device *pdev)
 	struct jh7110_pll_priv *priv;
 	unsigned int idx;
 	int ret;
+	struct device_node *np;
+	struct resource res;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 572

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct platform_device *pdev)
 			return ret;
 	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL, "starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Best regards,
Krzysztof

#2 lore raw
Quoted 89 lines · Krzysztof Kozlowski
Quoted 35 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110 SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2: https://lore.kernel.org/all/[email protected]/
v1: https://lore.kernel.org/all/[email protected]/

Quoted 5 lines

Thanks,
Xingyu Wu

---
  .../jh7110-starfive-visionfive-2.dtsi         |   5 +
  .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

...

Quoted 11 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct platform_device *pdev)
  	struct jh7110_pll_priv *priv;
  	unsigned int idx;
  	int ret;
+	struct device_node *np;
+	struct resource res;
 
  	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  	if (!priv)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 572

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct platform_device *pdev)
  			return ret;
  	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL, "starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Quoted 9 lines

Best regards,
Krzysztof

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Hi Xingyu,

Echoing Krzysztof's point. This piece code seems wrong to me. This logic belongs to syscrg, rather than pll. Why don't you do the pll0->osc->pll0 switching from syscrg side during probing?

Bo

author maintainer
#3 lore raw
Quoted 125 lines

-----Original Message-----
From: Bo Gan <[email protected]>
Sent: 2024年4月3日 8:27
To: Krzysztof Kozlowski <[email protected]>; Xingyu Wu <[email protected]>; Michael Turquette <[email protected]>; Stephen Boyd <[email protected]>; Conor Dooley <[email protected]>; Emil Renner Berthing <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>
Cc: Paul Walmsley <[email protected]>; Palmer Dabbelt <[email protected]>; Albert Ou <[email protected]>; Hal Feng <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v3] clk: starfive: pll: Fix lower rate of CPUfreq by setting PLL0 rate to 1.5GHz

Quoted 47 lines · Krzysztof Kozlowski
Quoted 40 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for

JH7110 SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@starfiv
etech.com/
v1:
https://lore.kernel.org/all/20230811033631.160912-1-xingyu.wu@starfiv
etech.com/

Quoted 5 lines

Thanks,
Xingyu Wu

---
  .../jh7110-starfive-visionfive-2.dtsi         |   5 +
  .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++
Quoted 7 lines

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

...

Review static int jh7110_pll_probe(struct platform_device

Quoted 2 lines
(quoted diff) +0 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct platform_device

*pdev)

Quoted 9 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device

Quoted 9 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
  	struct jh7110_pll_priv *priv;
  	unsigned int idx;
  	int ret;
+	struct device_node *np;
+	struct resource res;
 
  	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
  	if (!priv)
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct platform_device

*pdev)

Quoted 31 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 572

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
  			return ret;
  	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL, "starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Quoted 9 lines

Best regards,
Krzysztof

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

Quoted 7 lines

Hi Xingyu,

Echoing Krzysztof's point. This piece code seems wrong to me. This logic belongs to syscrg, rather than pll. Why don't you do the pll0->osc->pll0 switching from syscrg side during probing?

Bo

Yes, That's what I thought and I did it in previous patches. But Emil seemed to like to put the steps into the clk_set_rate() when setting PLL0 rate[1]. So I tried to use this way in this patch.

[1]: https://lore.kernel.org/all/CAJM55Z-gYpn_FjG2Zb__Nt=rbrNQN8QDNB=KEFdeVkz9Ptv72Q@mail.gmail.com/

Best regards,
Xingyu Wu
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

author maintainer
#4 lore raw
In reply to Krzysztof Kozlowski
Quoted 42 lines · Krzysztof Kozlowski
Quoted 40 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110

SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@starfive
tech.com/
v1:
https://lore.kernel.org/all/20230811033631.160912-1-xingyu.wu@starfive
tech.com/

Quoted 8 lines
Quoted 5 lines

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

OK, I will submit that in two patches.

Quoted 36 lines

...

Review static int jh7110_pll_probe(struct platform_device

Quoted 2 lines
(quoted diff) +0 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device

Quoted 9 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 	struct jh7110_pll_priv *priv;
 	unsigned int idx;
 	int ret;
+	struct device_node *np;
+	struct resource res;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 572

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 			return ret;
 	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL, "starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
Quoted 8 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Because setting PLL0 rate need specific steps and use the clocks of SYSCRG. But SYSCRG driver also need PLL clock to be clock source when adding clock providers. I tried to add SYSCRG clocks in 'clocks' property in DT and use clk_get() to get the clocks. But it could not run and crash. So I use ioremap() instead.

Best regards,
Xingyu Wu

#5 lore raw
Quoted 99 lines · Xingyu Wu
Quoted 42 lines · Krzysztof Kozlowski
Quoted 40 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for JH7110

SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@starfive
tech.com/
v1:
https://lore.kernel.org/all/20230811033631.160912-1-xingyu.wu@starfive
tech.com/

Quoted 8 lines
Quoted 5 lines

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

OK, I will submit that in two patches.

Quoted 36 lines

...

Review static int jh7110_pll_probe(struct platform_device

Quoted 2 lines
(quoted diff) +0 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device

Quoted 9 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 	struct jh7110_pll_priv *priv;
 	unsigned int idx;
 	int ret;
+	struct device_node *np;
+	struct resource res;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 572

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 			return ret;
 	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL, "starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
Quoted 8 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Quoted 1 line

Because setting PLL0 rate need specific steps and use the clocks of SYSCRG.

That's not a reason to map other device's IO. That could be a reason for having syscon or some other sort of relationship, like clock or reset.

Quoted 4 lines

But SYSCRG driver also need PLL clock to be clock source when adding clock providers. I tried to add SYSCRG clocks in 'clocks' property in DT and use clk_get() to get the clocks. But it could not run and crash. So I use ioremap() instead.

So instead of properly model the relationship, you entangle the drivers even more.

Please come with a proper design for this. I have no clue about your hardware, but that looks like you are asynchronously configuring the same hardware in two different places.

Sorry, that's poor code.

Best regards,
Krzysztof

author maintainer
#6 lore raw
Quoted 121 lines · Krzysztof Kozlowski
Quoted 105 lines · Xingyu Wu
Quoted 45 lines · Krzysztof Kozlowski
Quoted 43 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for

JH7110
SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@starfi
ve
tech.com/
v1:
https://lore.kernel.org/all/20230811033631.160912-1-xingyu.wu@starfi
ve
tech.com/

Quoted 8 lines
Quoted 5 lines

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

OK, I will submit that in two patches.

Quoted 39 lines

...

Quoted 3 lines
(quoted diff) +0 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct

platform_device

*pdev)

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 	struct jh7110_pll_priv *priv;
 	unsigned int idx;
 	int ret;
+	struct device_node *np;
+	struct resource res;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct

platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +3 -0
 			return ret;
 	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL,
+"starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
Quoted 8 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Quoted 1 line

Because setting PLL0 rate need specific steps and use the clocks of SYSCRG.

That's not a reason to map other device's IO. That could be a reason for having syscon or some other sort of relationship, like clock or reset.

Quoted 5 lines

But SYSCRG driver also need PLL clock to be clock source when adding clock providers. I tried to add SYSCRG clocks in 'clocks' property in DT and use
clk_get() to get the clocks. But it could not run and crash. So I use ioremap() instead.

So instead of properly model the relationship, you entangle the drivers even more.

Quoted 8 lines

Please come with a proper design for this. I have no clue about your hardware, but that looks like you are asynchronously configuring the same hardware in two different places.

Sorry, that's poor code.

Best regards,
Krzysztof

Hi Krzysztof,

If I use the old patch[1] like v2 and set the PLL0 default rate in the SYSCRG driver, will it be better?

[1]: https://lore.kernel.org/all/[email protected]/

Thanks,
Xingyu Wu

_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv

#7 lore raw

Hi Xingyu,

Quoted 131 lines · Xingyu Wu
Quoted 121 lines · Krzysztof Kozlowski
Quoted 105 lines · Xingyu Wu
Quoted 45 lines · Krzysztof Kozlowski
Quoted 43 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for

JH7110
SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@starfi
ve
tech.com/
v1:
https://lore.kernel.org/all/20230811033631.160912-1-xingyu.wu@starfi
ve
tech.com/

Quoted 8 lines
Quoted 5 lines

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

OK, I will submit that in two patches.

Quoted 39 lines

...

Quoted 3 lines
(quoted diff) +0 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct

platform_device

*pdev)

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 	struct jh7110_pll_priv *priv;
 	unsigned int idx;
 	int ret;
+	struct device_node *np;
+	struct resource res;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct

platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +3 -0
 			return ret;
 	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL,
+"starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
Quoted 8 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Quoted 1 line

Because setting PLL0 rate need specific steps and use the clocks of SYSCRG.

That's not a reason to map other device's IO. That could be a reason for having syscon or some other sort of relationship, like clock or reset.

Quoted 5 lines

But SYSCRG driver also need PLL clock to be clock source when adding clock providers. I tried to add SYSCRG clocks in 'clocks' property in DT and use
clk_get() to get the clocks. But it could not run and crash. So I use ioremap() instead.

So instead of properly model the relationship, you entangle the drivers even more.

Quoted 8 lines

Please come with a proper design for this. I have no clue about your hardware, but that looks like you are asynchronously configuring the same hardware in two different places.

Sorry, that's poor code.

Best regards,
Krzysztof

Quoted 6 lines

Hi Krzysztof,

If I use the old patch[1] like v2 and set the PLL0 default rate in the SYSCRG driver, will it be better?

[1]: https://lore.kernel.org/all/[email protected]/

Both reparenting cpu_root and enforcing the maximum cpu_core frequency can be accomplished with clk notifiers. See for example ccu_mux_notifier_register() in drivers/clk/sunxi-ng/ccu_mux.c.

Regards,
Samuel

author maintainer
#8 lore raw
Quoted 144 lines · Samuel Holland

Hi Xingyu,

Quoted 140 lines · Xingyu Wu
Quoted 125 lines · Krzysztof Kozlowski
Quoted 108 lines · Xingyu Wu
Quoted 48 lines · Krzysztof Kozlowski
Quoted 46 lines · Xingyu Wu

CPUfreq supports 4 cpu frequency loads on 375/500/750/1500MHz. But now PLL0 rate is 1GHz and the cpu frequency loads become 333/500/500/1000MHz in fact.

So PLL0 rate should be default set to 1.5GHz. But setting the PLL0 rate need certain steps:

1. Change the parent of cpu_root clock to OSC clock.
2. Change the divider of cpu_core if PLL0 rate is higher than 1.25GHz before CPUfreq boot.
3. Change the parent of cpu_root clock back to PLL0 clock.

Fixes e2c510d6d630 ("riscv: dts: starfive: Add cpu scaling for

JH7110
SoC")

---

Hi Stephen and Emil,

This patch fixes the issue about lower rate of CPUfreq[1] by setting
PLL0 rate to 1.5GHz.

In order not to affect the cpu operation, setting the PLL0 rate need certain steps. The cpu_root's parent clock should be changed first. And the divider of the cpu_core clock should be set to 2 so they won't crash when setting 1.5GHz without voltage regulation. Due to PLL driver boot earlier than SYSCRG driver, cpu_core and cpu_root clocks are using by ioremap().

[1]: https://github.com/starfive-tech/VisionFive2/issues/55

Previous patch link:
v2:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@star
fi
ve
tech.com/
v1:
https://lore.kernel.org/all/20230811033631.160912-1-xingyu.wu@star
fi
ve
tech.com/

Quoted 8 lines
Quoted 5 lines

Thanks,
Xingyu Wu

---
 .../jh7110-starfive-visionfive-2.dtsi         |   5 +
 .../clk/starfive/clk-starfive-jh7110-pll.c    | 102 ++++++++++++++++++

Please do not mix DTS and driver code. That's not really portable. DTS is being exported and used in other projects.

OK, I will submit that in two patches.

Quoted 39 lines

...

Quoted 3 lines
(quoted diff) +0 -0
@@ -458,6 +535,8 @@ static int jh7110_pll_probe(struct

platform_device

*pdev)

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +2 -0
 	struct jh7110_pll_priv *priv;
 	unsigned int idx;
 	int ret;
+	struct device_node *np;
+	struct resource res;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
 	if (!priv)
@@ -489,6 +568,29 @@ static int jh7110_pll_probe(struct

platform_device

*pdev)

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev)

Quoted 6 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +3 -0
 			return ret;
 	}
 
+	priv->is_first_set = true;
+	np = of_find_compatible_node(NULL, NULL,
+"starfive,jh7110-syscrg");

Your drivers should not do it. It's fragile, hides true link/dependency. Please use phandles.

Quoted 10 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +10 -0
+	if (!np) {
+		ret = PTR_ERR(np);
+		dev_err(priv->dev, "failed to get syscrg node\n");
+		goto np_put;
+	}
+
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret) {
+		dev_err(priv->dev, "failed to get syscrg resource\n");
+		goto np_put;
Quoted 8 lines

drivers/clk/starfive/clk-starfive-jh7110-pll.c static int jh7110_pll_probe(struct platform_device *pdev) · line 587

Quoted 5 lines
drivers/clk/starfive/clk-starfive-jh7110-pll.c +5 -0
+	}
+
+	priv->syscrg_base = ioremap(res.start, resource_size(&res));
+	if (!priv->syscrg_base)
+		ret = -ENOMEM;

Why are you mapping other device's IO? How are you going to ensure synced access to registers?

Quoted 1 line

Because setting PLL0 rate need specific steps and use the clocks of SYSCRG.

That's not a reason to map other device's IO. That could be a reason for having syscon or some other sort of relationship, like clock or reset.

Quoted 6 lines

But SYSCRG driver also need PLL clock to be clock source when adding clock providers. I tried to add SYSCRG clocks in 'clocks' property in DT and use
clk_get() to get the clocks. But it could not run and crash. So I use
ioremap() instead.

So instead of properly model the relationship, you entangle the drivers even more.

Quoted 8 lines

Please come with a proper design for this. I have no clue about your hardware, but that looks like you are asynchronously configuring the same hardware in two different places.

Sorry, that's poor code.

Best regards,
Krzysztof

Hi Krzysztof,

If I use the old patch[1] like v2 and set the PLL0 default rate in the SYSCRG driver, will it be better?

Quoted 8 lines
Quoted 3 lines

[1]:
https://lore.kernel.org/all/20230821152915.208366-1-xingyu.wu@starfive
tech.com/

Both reparenting cpu_root and enforcing the maximum cpu_core frequency can be accomplished with clk notifiers. See for example ccu_mux_notifier_register() in drivers/clk/sunxi-ng/ccu_mux.c.

This seems like a good idea. I'll try it.

Thanks,
Xingyu Wu
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv