cpufreq: spacemit: Add cpufreq support for K1 SoC
Subsystems (4)
v3 cover cpufreq: spacemit: Add cpufreq support for K1 SoC
This series enables CPU frequency scaling for the SpacemiT K1 SoC.
K1 has two CPU cluster clocks but one shared CPU voltage rail. Add a small K1-specific cpufreq driver so the two clocks and the shared OPP transition can be handled together.
Tested on Banana Pi BPI-F3. The system boots with all eight CPUs online, the K1 cpufreq driver registers one policy for CPUs 0-7, and both CPU cluster clocks follow the selected cpufreq rate.
~ # cat /sys/devices/system/cpu/online
0-7
~ # ls /sys/devices/system/cpu/cpufreq
policy0
~ # cat /sys/devices/system/cpu/cpufreq/policy0/affected_cpus 0 1 2 3 4 5 6 7
~ # cat /sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies 614400 819000 1000000 1228800 1600000
With the userspace governor:
----------------------------------------------------------------------------
Frequency | scaling_cur | cpu_c0_core | cpu_c1_core | Real | User (kHz) | (kHz) | (Hz) | (Hz) | (s) | (s) -------------+-------------+-------------+-------------+---------+---------- 1,600,000 | 1,600,000 | 1600000000 | 1600000000 | 1.80s | 1.80s 1,228,800 | 1,228,800 | 1228800000 | 1228800000 | 2.33s | 2.33s 1,000,000 | 1,000,000 | 1000000000 | 1000000000 | 2.88s | 2.87s 819,000 | 819,000 | 819200000 | 819200000 | 3.53s | 3.52s 614,400 | 614,400 | 614400000 | 614400000 | 4.72s | 4.72s
----------------------------------------------------------------------------
---
Changes in v3:
- Add a K1-specific cpufreq driver for the shared-rail, dual-clock topology
- Use one shared CPU OPP table and one cpufreq policy for all CPUs
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Move OPP tables to dedicated k1-opp.dtsi
- Enable OPP only on BPI-F3 with cpu-supply present
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Shuwei Wu (2):
cpufreq: spacemit: Add K1 cpufreq driver
riscv: dts: spacemit: Add cpu scaling for K1 SoC
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts | 35 +++- arch/riscv/boot/dts/spacemit/k1-opp.dtsi | 70 +++++++ arch/riscv/boot/dts/spacemit/k1.dtsi | 8 + drivers/cpufreq/Kconfig | 4 + drivers/cpufreq/Kconfig.riscv | 15 ++ drivers/cpufreq/Makefile | 3 + drivers/cpufreq/cpufreq-dt-platdev.c | 2 + drivers/cpufreq/spacemit-k1-cpufreq.c | 251 ++++++++++++++++++++++++ 8 files changed, 387 insertions(+), 1 deletion(-)
---
base-commit: 5164e95565d3fd508ca8a95351323f5716dfb695
change-id: 20260307-shadow-deps-3582a78aa756
prerequisite-patch-id: 154bd4f720ce5065d58b988de8f273207b44572e
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 5da3e75b18291a5540d4f66d7a0600fb8975ef62
prerequisite-patch-id: bcf41917414ecef8cf743095d130f6004c32f6a5
prerequisite-patch-id: cfe3800f8c791ec4c63e070af9628e88e0fc31b9
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: 7c7fb9f87dba019ece4c97c45750349a7cd28f3a
Best regards,
Signature · 1 line
Shuwei Wu <[email protected]>
PATCH v3 1/2 cpufreq: spacemit: Add K1 cpufreq driver
K1 has two CPU cluster clocks but one shared CPU voltage rail. Use one cpufreq policy for all CPUs, let the OPP core handle the shared regulator and the cluster0 clock, and update the cluster1 clock explicitly.
Block spacemit,k1 from cpufreq-dt probing when OPP v2 nodes are present, as K1 needs the dedicated driver for safe transitions.
---
Changes in v3:
- Add a K1-specific cpufreq driver for the shared-rail, dual-clock topology
- Add spacemit,k1 to the cpufreq-dt blocklist
--- drivers/cpufreq/Kconfig | 4 + drivers/cpufreq/Kconfig.riscv | 15 ++ drivers/cpufreq/Makefile | 3 + drivers/cpufreq/cpufreq-dt-platdev.c | 2 + drivers/cpufreq/spacemit-k1-cpufreq.c | 251 ++++++++++++++++++++++++++++++++++ 5 files changed, 275 insertions(+)
drivers/cpufreq/Kconfig +4 -0
@@ -259,6 +259,10 @@ endif source "drivers/cpufreq/Kconfig.arm" +if RISCV +source "drivers/cpufreq/Kconfig.riscv" +endif + if PPC32 || PPC64 source "drivers/cpufreq/Kconfig.powerpc" endif
drivers/cpufreq/Kconfig.riscv new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# RISC-V CPU Frequency scaling drivers +# + +config RISCV_SPACEMIT_K1_CPUFREQ + tristate "SpacemiT K1 CPUFreq driver" + depends on ARCH_SPACEMIT || COMPILE_TEST + depends on OF && COMMON_CLK + select PM_OPP + help + Enable CPU frequency scaling for SpacemiT K1 SoC. + K1 has two CPU cluster clocks and one shared CPU voltage rail. + The driver keeps all CPUs in one policy and updates both cluster + clocks with the shared OPP transition.
drivers/cpufreq/Makefile +3 -0
@@ -89,6 +89,9 @@ obj-$(CONFIG_ARM_TEGRA194_CPUFREQ) += tegra194-cpufreq.o obj-$(CONFIG_ARM_TI_CPUFREQ) += ti-cpufreq.o obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o +################################################################################## +# RISC-V SoC drivers +obj-$(CONFIG_RISCV_SPACEMIT_K1_CPUFREQ) += spacemit-k1-cpufreq.o ################################################################################## # PowerPC platform drivers
drivers/cpufreq/cpufreq-dt-platdev.c +2 -0
@@ -185,6 +185,8 @@ static const struct of_device_id blocklist[] __initconst = { { .compatible = "qcom,sm8550", }, { .compatible = "qcom,sm8650", }, + { .compatible = "spacemit,k1", }, + { .compatible = "st,stih407", }, { .compatible = "st,stih410", }, { .compatible = "st,stih418", },
drivers/cpufreq/spacemit-k1-cpufreq.c new file +251 -0
251 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] Unaligned initial cluster frequencies can cause cluster 1 to undervoltage and crash during the…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unaligned initial cluster frequencies can cause cluster 1 to undervoltage and crash during the first cpufreq transition. --
commit de194d59d1b015bd0b960104ac00570cfd3ba072
Author: Shuwei Wu <[email protected]>
cpufreq: spacemit: Add K1 cpufreq driver
This commit adds a CPU frequency scaling driver for the SpacemiT K1 SoC. It handles two cluster clocks and one shared CPU voltage rail within a single cpufreq policy.
Quoted 5 lines
drivers/cpufreq/spacemit-k1-cpufreq.c new file +0
-0
[ ... ]
drivers/cpufreq/spacemit-k1-cpufreq.c line 41
Quoted 13 lines
drivers/cpufreq/spacemit-k1-cpufreq.c new file +13
-0+static int k1_cpufreq_set_target (struct cpufreq_policy *policy, +unsigned int index) +{ +struct k1_cpufreq_priv *priv = policy->driver_data; +unsigned long old_freq = policy->cur *1000UL ; +unsigned long new_freq = policy->freq_table[index].frequency *1000UL ; +int ret; + +if (!old_freq) + old_freq =clk_get_rate (priv->cluster0_clk); + +if (new_freq > old_freq) { + ret =dev_pm_opp_set_rate (priv->cpu_dev, new_freq);
[Severity: High]
Could this cause an undervoltage crash on cluster 1 during the first transition?
The transition logic assumes old_freq (which comes from cluster 0) represents the current speed of both clusters. If the bootloader leaves cluster 1 running at a higher frequency than cluster 0 (e.g., cluster 0 at 500 MHz, cluster 1 at 1.2 GHz), and new_freq is an intermediate value like 800 MHz:
new_freq (800) > old_freq (500), so dev_pm_opp_set_rate() sets the shared regulator to the 800 MHz voltage level. Since cluster 1 is invisible to the OPP and regulator core, its voltage drops to the 800 MHz level while it is still physically running at 1.2 GHz.
[ ... ]
Quoted 2 lines
drivers/cpufreq/spacemit-k1-cpufreq.c new file +2
-0+static int k1_cpufreq_probe (struct platform_device *pdev) +{
[ ... ]
drivers/cpufreq/spacemit-k1-cpufreq.c line 126
Quoted 9 lines
drivers/cpufreq/spacemit-k1-cpufreq.c new file +9
-0+ priv->cluster0_clk =clk_get (priv->cpu_dev,NULL ); +if (IS_ERR (priv->cluster0_clk)) { + ret =PTR_ERR (priv->cluster0_clk); +dev_err_probe (priv->cpu_dev, ret,"failed to get cluster0 clock\n" ); + goto free_cpumask; + } + + priv->cluster1_clk =clk_get (cpu4_dev,NULL ); +if (IS_ERR (priv->cluster1_clk)) {
[Severity: High]
Should the driver synchronize both cluster clocks to a safe state (like the maximum of their initial frequencies) here during probe before registering the cpufreq driver?
The clocks are acquired here but their initial rates are never read or aligned, leaving them vulnerable to the mismatch described above.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Viresh Kumar
maintainerRe: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
In reply to Shuwei WuQuoted 3 lines · Shuwei Wu
K1 has two CPU cluster clocks but one shared CPU voltage rail. Use one cpufreq policy for all CPUs, let the OPP core handle the shared regulator and the cluster0 clock, and update the cluster1 clock explicitly.
If the clusters can do DVFS individually (as they have separate clocks), this should be represented as two separate policies. Isn't it ?
Signature · 1 line
viresh
Re: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
Hi Viresh,
Thanks for your reply.
Quoted 7 lines · Viresh Kumar
Quoted 3 lines · Shuwei Wu
K1 has two CPU cluster clocks but one shared CPU voltage rail. Use one cpufreq policy for all CPUs, let the OPP core handle the shared regulator and the cluster0 clock, and update the cluster1 clock explicitly.
If the clusters can do DVFS individually (as they have separate clocks), this should be represented as two separate policies. Isn't it ?
The clusters have separate clocks, but they share the same voltage supply.[1] So two independent policies would be unsafe: one policy could lower the shared voltage while the other cluster is still running at a higher frequency. This means they can't use different policies.
From a hardware perspective, the eight cores of the K1 are homogeneous, so using the same policy for them is relatively reasonable.
I used a K1-specific driver because cpufreq-dt only manages one CPU clock through the CPU device used for the OPP transition.
On K1, the policy needs to control two independent cluster clocks and one shared regulator, so the driver has to update the second cluster clock explicitly and keep the ordering safe: raise voltage before raising either cluster, and lower both cluster clocks before lowering the shared voltage.
[1] https://lore.kernel.org/spacemit/[email protected]/
Signature · 2 lines
Best regards, Shuwei Wu
Viresh Kumar
maintainerRe: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
Hi Shuwei,
Quoted 3 lines · Shuwei Wu
The clusters have separate clocks, but they share the same voltage supply.[1] So two independent policies would be unsafe: one policy could lower the shared voltage while the other cluster is still running at a higher frequency.
No, both will vote for the regulator contraints using CPU device and the regulator core will make sure it doesn't break any of them. This is what all frameworks do, regulator, clk, etc.
Quoted 1 line
This means they can't use different policies.
This is incorrect.
Quoted 2 lines
From a hardware perspective, the eight cores of the K1 are homogeneous, so using the same policy for them is relatively reasonable.
Right, but this is inefficient. One cluster can be idle, or in low freq mode while other can be in higher. They MUST be two policies.
Quoted 8 lines
I used a K1-specific driver because cpufreq-dt only manages one CPU clock through the CPU device used for the OPP transition.
On K1, the policy needs to control two independent cluster clocks and one shared regulator, so the driver has to update the second cluster clock explicitly and keep the ordering safe: raise voltage before raising either cluster, and lower both cluster clocks before lowering the shared voltage.
Signature · 1 line
viresh
Re: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
Hi Viresh,
Thanks for pointing it out.
Quoted 13 lines · Viresh Kumar
Hi Shuwei,
Quoted 3 lines · Shuwei Wu
The clusters have separate clocks, but they share the same voltage supply.[1] So two independent policies would be unsafe: one policy could lower the shared voltage while the other cluster is still running at a higher frequency.
No, both will vote for the regulator contraints using CPU device and the regulator core will make sure it doesn't break any of them. This is what all frameworks do, regulator, clk, etc.
Quoted 1 line
This means they can't use different policies.
Quoted 7 lines
This is incorrect.
Quoted 2 lines
From a hardware perspective, the eight cores of the K1 are homogeneous, so using the same policy for them is relatively reasonable.
Right, but this is inefficient. One cluster can be idle, or in low freq mode while other can be in higher. They MUST be two policies.
Yes, you're right. Two policies are not inherently unsafe. The regulator framework handles multi-consumer voting correctly.
The actual problem was using single value opp-microvolt. With one cluster at a low frequency holding a precise [950000, 950000] on the shared rail, and the other requesting [1050000, 1050000] for 1.6 GHz, the regulator finds no intersection:
~ # echo 1600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed
[ 544.744195] buck1: Restricting voltage, 1050000-950000uV
[ 544.757073] cpu cpu0: _set_opp_voltage: failed to set
voltage (1050000 1050000 1050000 mV): -22
[ 544.771304] cpufreq: __target_index: Failed to change
cpu frequency: -22The fix is to use the <target min max> triplet for the lower OPPs so the regulator always has a valid intersection:
- cpu_opp_table: opp-table-cpu {
+ cluster0_opp_table: opp-table-cluster0 {
compatible = "operating-points-v2";
opp-shared;
opp-614400000 {
- opp-microvolt = <950000>;
+ opp-microvolt = <950000 950000 1050000>;
};
opp-819000000 {
- opp-microvolt = <950000>;
+ opp-microvolt = <950000 950000 1050000>;
};
...
opp-1600000000 {
opp-microvolt = <1050000>;
};
};
+ cluster1_opp_table: opp-table-cluster1 {
+ // same OPP entries and voltage ranges as above
+ };
- &cpu_0 { operating-points-v2 = <&cpu_opp_table>; };
+ &cpu_0 { operating-points-v2 = <&cluster0_opp_table>; };
...
- &cpu_7 { operating-points-v2 = <&cpu_opp_table>; };
+ &cpu_3 { operating-points-v2 = <&cluster0_opp_table>; };
+ &cpu_4 { operating-points-v2 = <&cluster1_opp_table>; };
...+ &cpu_7 { operating-points-v2 = <&cluster1_opp_table>; };
This way the low frequency cluster accepts up to 1.05 V on the rail. That is safe: high voltage at low frequency costs power but does not cause instability.
With two cpufreq-dt policies (one per cluster) and these ranges, neither cluster blocks the other. Tested on BPI-F3 and OrangePi Rv2 boards, works as expected.
Does this look good to you, or would you prefer a different approach?
Quoted 9 lines
Quoted 9 lines
I used a K1-specific driver because cpufreq-dt only manages one CPU clock through the CPU device used for the OPP transition.
On K1, the policy needs to control two independent cluster clocks and one shared regulator, so the driver has to update the second cluster clock explicitly and keep the ordering safe: raise voltage before raising either cluster, and lower both cluster clocks before lowering the shared voltage.
Signature · 2 lines
Best regards, Shuwei Wu
Viresh Kumar
maintainerRe: [PATCH v3 1/2] cpufreq: spacemit: Add K1 cpufreq driver
Quoted 4 lines · Shuwei Wu
With two cpufreq-dt policies (one per cluster) and these ranges, neither cluster blocks the other. Tested on BPI-F3 and OrangePi Rv2 boards, works as expected.
Does this look good to you, or would you prefer a different approach?
Looks correct.
Signature · 1 line
viresh
PATCH v3 2/2 riscv: dts: spacemit: Add cpu scaling for K1 SoC
In reply to Shuwei WuUse one shared CPU OPP table for all CPUs and add CPU clock properties for the two CPU clock clusters.
Enable CPU DVFS on Banana Pi BPI-F3 by including the OPP table and wiring the CPU nodes to the CPU regulator supply.
---
Changes in v3:
- Use one shared CPU OPP table for all CPUs
Changes in v2:
- Add k1-opp.dtsi with OPP tables for both CPU clusters
- Assign CPU supplies and include OPP table for Banana Pi BPI-F3
--- arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts | 35 ++++++++++++- arch/riscv/boot/dts/spacemit/k1-opp.dtsi | 70 +++++++++++++++++++++++++ arch/riscv/boot/dts/spacemit/k1.dtsi | 8 +++ 3 files changed, 112 insertions(+), 1 deletion(-)
arch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts +34 -1
@@ -5,6 +5,7 @@ #include "k1.dtsi" #include "k1-pinctrl.dtsi" +#include "k1-opp.dtsi" / { model = "Banana Pi BPI-F3";
@@ -86,6 +87,38 @@ &combo_phy { status = "okay"; }; +&cpu_0 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_1 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_2 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_3 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_4 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_5 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_6 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_7 { + cpu-supply = <&buck1_0v9>; +}; + &emmc { bus-width = <8>; mmc-hs400-1_8v;
@@ -201,7 +234,7 @@ pmic@41 { dldoin2-supply = <&buck5>; regulators { - buck1 { + buck1_0v9: buck1 { regulator-min-microvolt = <500000>; regulator-max-microvolt = <3450000>; regulator-ramp-delay = <5000>;
arch/riscv/boot/dts/spacemit/k1-opp.dtsi new file +70 -0
70 lines not on this page · raw message
arch/riscv/boot/dts/spacemit/k1.dtsi +8 -0
@@ -54,6 +54,7 @@ cpu_0: cpu@0 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <0>; + clocks = <&syscon_apmu CLK_CPU_C0_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -84,6 +85,7 @@ cpu_1: cpu@1 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <1>; + clocks = <&syscon_apmu CLK_CPU_C0_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -114,6 +116,7 @@ cpu_2: cpu@2 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <2>; + clocks = <&syscon_apmu CLK_CPU_C0_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -144,6 +147,7 @@ cpu_3: cpu@3 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <3>; + clocks = <&syscon_apmu CLK_CPU_C0_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -174,6 +178,7 @@ cpu_4: cpu@4 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <4>; + clocks = <&syscon_apmu CLK_CPU_C1_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -204,6 +209,7 @@ cpu_5: cpu@5 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <5>; + clocks = <&syscon_apmu CLK_CPU_C1_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -234,6 +240,7 @@ cpu_6: cpu@6 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <6>; + clocks = <&syscon_apmu CLK_CPU_C1_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
@@ -264,6 +271,7 @@ cpu_7: cpu@7 { compatible = "spacemit,x60", "riscv"; device_type = "cpu"; reg = <7>; + clocks = <&syscon_apmu CLK_CPU_C1_CORE>; riscv,isa = "rv64imafdcbv_zicbom_zicbop_zicboz_zicntr_zicond_zicsr_zifencei_zihintpause_zihpm_zfh_zba_zbb_zbc_zbs_zkt_zvfh_zvkt_sscofpmf_sstc_svinval_svnapot_svpbmt"; riscv,isa-base = "rv64i"; riscv,isa-extensions = "i", "m", "a", "f", "d", "c", "b", "v", "zicbom",
Signature · 1 line
2.53.0
PATCH 1/1 riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1, SoC
In reply to Shuwei Wu[RESEND] as I cannot see yesterday's
Hello,
I tested (on OrangePi RV2) the attached patch applied over
spacemit/for-next + Shuwei Wu's V3 series.
This is a copy/paste of Shuwei Wu's work, so I don't know
if I can submit this with my SoB or if it should be done
differently, please advise.
Anyways, you can add my:
To the relevant patches from your series, if that's useful,
because it looks like it is working properly:
On Void linux (musl libc):
uname -a
Linux opirv2 7.1.0-rc1-00043-gb860bca13be4 #14 SMP PREEMPT Sat Jun 13 11:02:13 CEST 2026 riscv64 GNU/Linux
awk --version | head -1
GNU Awk 5.3.2, API 4.0
echo userspace > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor
echo 1600000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed time awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.300s
user 0m0.299s
sys 0m0.001s
echo 1228800 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed time awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.432s
user 0m0.429s
sys 0m0.004s
echo 1000000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed time awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.476s
user 0m0.476s
sys 0m0.001s
echo 819000 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed time awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.582s
user 0m0.581s
sys 0m0.001s
echo 614400 > /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed time awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.778s
user 0m0.773s
sys 0m0.005s
Signature · 1 line
Vincent Legoll
From 9924789655ae5f4f98e7a5cdc3df3f34e7bfb659 Mon Sep 17 00:00:00 2001
From: Vincent Legoll <[email protected]>
Date: Sat, 13 Jun 2026 10:49:34 +0200
Subject: [PATCH] riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1
SoC
Enable CPU DVFS on OrangePi RV2
This is a copy/paste from Shuwei Wu's BPI-F3 DTS modifications
--- .../boot/dts/spacemit/k1-orangepi-rv2.dts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +34 -1
@@ -8,6 +8,7 @@ #include "k1.dtsi" #include "k1-pinctrl.dtsi" +#include "k1-opp.dtsi" / { model = "OrangePi RV2";
@@ -80,6 +81,38 @@ &combo_phy { status = "okay"; }; +&cpu_0 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_1 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_2 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_3 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_4 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_5 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_6 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_7 { + cpu-supply = <&buck1_0v9>; +}; + &emmc { bus-width = <8>; mmc-hs400-1_8v;
@@ -162,7 +195,7 @@ pmic@41 { dldoin2-supply = <&buck5>; regulators { - buck1 { + buck1_0v9: buck1 { regulator-min-microvolt = <500000>; regulator-max-microvolt = <3450000>; regulator-ramp-delay = <5000>;
Signature · 1 line
2.54.0
Yixun Lan
maintainerRe: [PATCH] riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1, SoC
Hi Vincent,
Please send the patch directly instead of attached file, it's more
easy for people to review and apply, suggest to use b4, or
"git send-email" (old way)
Quoted 7 lines · Vincent Legoll
[RESEND] as I cannot see yesterday's
Hello,
Quoted 9 lines
I tested (on OrangePi RV2) the attached patch applied over
spacemit/for-next + Shuwei Wu's V3 series.
This is a copy/paste of Shuwei Wu's work, so I don't know
if I can submit this with my SoB or if it should be done
It's ok to add your SoB while adding support for new board
Quoted 68 lines
differently, please advise.
Anyways, you can add my:
To the relevant patches from your series, if that's useful,
because it looks like it is working properly:
On Void linux (musl libc):
uname -a
Linux opirv2 7.1.0-rc1-00043-gb860bca13be4 #14 SMP PREEMPT Sat Jun 13 11:02:13 CEST 2026 riscv64 GNU/Linuxawk --version | head -1
GNU Awk 5.3.2, API 4.0echo userspace >
/sys/devices/system/cpu/cpufreq/policy0/scaling_governorecho 1600000 >
/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeedtime awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.300s
user 0m0.299s
sys 0m0.001secho 1228800 >
/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeedtime awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.432s
user 0m0.429s
sys 0m0.004secho 1000000 >
/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeedtime awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.476s
user 0m0.476s
sys 0m0.001secho 819000 >
/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeedtime awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.582s
user 0m0.581s
sys 0m0.001secho 614400 >
/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeedtime awk 'BEGIN{for(i=0;i<1000000;i++){}}'
real 0m0.778s
user 0m0.773s
sys 0m0.005sSignature · 10 lines
Vincent Legoll From 9924789655ae5f4f98e7a5cdc3df3f34e7bfb659 Mon Sep 17 00:00:00 2001 From: Vincent Legoll <[email protected]> Date: Sat, 13 Jun 2026 10:49:34 +0200 Subject: [PATCH] riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1 SoC Enable CPU DVFS on OrangePi RV2
..
Quoted 2 lines
This is a copy/paste from Shuwei Wu's BPI-F3 DTS modifications
It's quite common that people do copy/paste for additional board support, no need to mention it in commit message which I think it isn't really useful
Quoted 10 lines
Signed-off-by Vincent Legoll <[email protected]>--- .../boot/dts/spacemit/k1-orangepi-rv2.dts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +0
-0
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts line 11
Quoted 4 lines
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +1
-0@@ -8,6 +8,7 @@ #include "k1.dtsi" #include "k1-pinctrl.dtsi" +#include "k1-opp.dtsi"
keep alphabet sorted
Quoted 54 lines
arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts +33
-1/ { model = "OrangePi RV2";@@ -80,6 +81,38 @@ &combo_phy { status = "okay"; }; +&cpu_0 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_1 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_2 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_3 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_4 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_5 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_6 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_7 { + cpu-supply = <&buck1_0v9>; +}; + &emmc { bus-width = <8>; mmc-hs400-1_8v;@@ -162,7 +195,7 @@ pmic@41 { dldoin2-supply = <&buck5>; regulators { - buck1 { + buck1_0v9: buck1 { regulator-min-microvolt = <500000>; regulator-max-microvolt = <3450000>; regulator-ramp-delay = <5000>;Signature · 1 line
2.54.0
Signature · 1 line
Yixun Lan (dlan)
PATCH 1/1 riscv: dts: spacemit: k1-musepi-pro: add cpu scaling
In reply to Shuwei WuEnable CPU DVFS by including the OPP table and wiring the CPU nodes to the CPU regulator supply.
--- .../riscv/boot/dts/spacemit/k1-musepi-pro.dts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-)
arch/riscv/boot/dts/spacemit/k1-musepi-pro.dts +34 -1
@@ -9,6 +9,7 @@ #include "k1.dtsi" #include "k1-pinctrl.dtsi" +#include "k1-opp.dtsi" / { model = "SpacemiT MusePi Pro";
@@ -99,6 +100,38 @@ &combo_phy { status = "okay"; }; +&cpu_0 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_1 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_2 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_3 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_4 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_5 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_6 { + cpu-supply = <&buck1_0v9>; +}; + +&cpu_7 { + cpu-supply = <&buck1_0v9>; +}; + ð0 { phy-handle = <&rgmii0>; phy-mode = "rgmii-id";
@@ -178,7 +211,7 @@ pmic@41 { dldoin2-supply = <&buck5>; regulators { - buck1 { + buck1_0v9: buck1 { regulator-min-microvolt = <500000>; regulator-max-microvolt = <3450000>; regulator-ramp-delay = <5000>;
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH] riscv: dts: spacemit: k1-musepi-pro: add cpu scaling
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] The devicetree file includes 'k1-opp.dtsi', but this file is missing from the tree. --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The devicetree file includes 'k1-opp.dtsi', but this file is missing from the tree. --
commit dbb35bd6325bb2f268c9e7237e65d5c614a6f755
Author: Andre Heider <[email protected]>
riscv: dts: spacemit: k1-musepi-pro: add cpu scaling
This commit enables CPU DVFS for the SpacemiT MusePi Pro board by including an OPP table and wiring the CPU nodes to the buck1_0v9 regulator supply.
arch/riscv/boot/dts/spacemit/k1-musepi-pro.dts line 12
Quoted 9 lines
arch/riscv/boot/dts/spacemit/k1-musepi-pro.dts +1
-0@@ -9,6 +9,7 @@ #include "k1.dtsi" #include "k1-pinctrl.dtsi" +#include "k1-opp.dtsi"
[Severity: Low]
Is the k1-opp.dtsi file missing from this series?
It appears this include will cause a devicetree compilation failure because the file does not exist in the tree.
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Viresh Kumar
maintainerQuoted 2 lines · Shuwei Wu
Changes in v3:
- Add a K1-specific cpufreq driver for the shared-rail, dual-clock topology
Why ?
Quoted 2 lines
- Use one shared CPU OPP table and one cpufreq policy for all CPUs
- Link to v2: https://lore.kernel.org/r/[email protected]
Signature · 1 line
viresh
Quoted 71 lines · Shuwei Wu
This series enables CPU frequency scaling for the SpacemiT K1 SoC.
K1 has two CPU cluster clocks but one shared CPU voltage rail. Add a small K1-specific cpufreq driver so the two clocks and the shared OPP transition can be handled together.
Tested on Banana Pi BPI-F3. The system boots with all eight CPUs online, the K1 cpufreq driver registers one policy for CPUs 0-7, and both CPU cluster clocks follow the selected cpufreq rate.
~ # cat
/sys/devices/system/cpu/online
0-7~ # ls
/sys/devices/system/cpu/cpufreq
policy0~ # cat
/sys/devices/system/cpu/cpufreq/policy0/affected_cpus0 1 2 3 4 5 6 7~ # cat
/sys/devices/system/cpu/cpufreq/policy0/scaling_available_frequencies614400 819000 1000000 1228800 1600000With the userspace governor:
----------------------------------------------------------------------------Frequency | scaling_cur | cpu_c0_core | cpu_c1_core | Real | User (kHz) | (kHz) | (Hz) | (Hz) | (s) | (s) -------------+-------------+-------------+-------------+---------+---------- 1,600,000 | 1,600,000 | 1600000000 | 1600000000 | 1.80s | 1.80s 1,228,800 | 1,228,800 | 1228800000 | 1228800000 | 2.33s | 2.33s 1,000,000 | 1,000,000 | 1000000000 | 1000000000 | 2.88s | 2.87s 819,000 | 819,000 | 819200000 | 819200000 | 3.53s | 3.52s 614,400 | 614,400 | 614400000 | 614400000 | 4.72s | 4.72s----------------------------------------------------------------------------
Signed-off-by Shuwei Wu <[email protected]>---
Changes in v3:
- Add a K1-specific cpufreq driver for the shared-rail, dual-clock topology
- Use one shared CPU OPP table and one cpufreq policy for all CPUs
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Move OPP tables to dedicatedk1-opp.dtsi
- Enable OPP only on BPI-F3 with cpu-supply present
- Link to v1: https://lore.kernel.org/r/[email protected]---
Shuwei Wu (2):
cpufreq: spacemit: Add K1 cpufreq driver
riscv: dts: spacemit: Add cpu scaling for K1 SoCarch/riscv/boot/dts/spacemit/k1-bananapi-f3.dts | 35 +++- arch/riscv/boot/dts/spacemit/k1-opp.dtsi | 70 +++++++ arch/riscv/boot/dts/spacemit/k1.dtsi | 8 + drivers/cpufreq/Kconfig | 4 + drivers/cpufreq/Kconfig.riscv | 15 ++ drivers/cpufreq/Makefile | 3 + drivers/cpufreq/cpufreq-dt-platdev.c | 2 + drivers/cpufreq/spacemit-k1-cpufreq.c | 251 ++++++++++++++++++++++++ 8 files changed, 387 insertions(+), 1 deletion(-)---
base-commit:5164e95565d3fd508ca8a95351323f5716dfb695
change-id: 20260307-shadow-deps-3582a78aa756
prerequisite-patch-id:154bd4f720ce5065d58b988de8f273207b44572e
prerequisite-message-id: <[email protected]>
prerequisite-patch-id:5da3e75b18291a5540d4f66d7a0600fb8975ef62
prerequisite-patch-id:bcf41917414ecef8cf743095d130f6004c32f6a5
prerequisite-patch-id:cfe3800f8c791ec4c63e070af9628e88e0fc31b9
prerequisite-message-id: <[email protected]>
prerequisite-patch-id:7c7fb9f87dba019ece4c97c45750349a7cd28f3a
Quoted 1 line
Best regards,
Hi Shuwei and Vincent,
I have tested this series on the OrangePi RV2 board (4GB) on top of linux-next (next-20260619), with the v3 cpufreq series and Vincent's patch "k1-orangepi-rv2: Add cpu scaling" applied.
The driver works as expected: all 8 CPUs are online and share a single policy (policy0). Writing to /sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed correctly changes the frequency for all cores simultaneously, and all scaling_setspeed files show the same value. The frequency transitions are smooth, and performance (tested with a simple awk loop, following Vincent's approach) scales linearly with the set frequency.
Both of you can add my tag:
If you send a new version, I'm also willing to test it again.
Thanks for the work.
Regards,
Shuai