[PATCH v3 0/2] cpufreq: spacemit: Add cpufreq support for K1 SoC

Shuwei Wu posted 2 patches 1 week, 1 day ago
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(-)
[PATCH v3 0/2] cpufreq: spacemit: Add cpufreq support for K1 SoC
Posted by Shuwei Wu 1 week, 1 day ago
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
----------------------------------------------------------------------------

Signed-off-by: Shuwei Wu <shuwei.wu@mailbox.org>
---
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/20260410-shadow-deps-v2-0-4e16b8c0f60e@mailbox.org

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/20260308-shadow-deps-v1-0-0ceb5c7c07eb@mailbox.org

---
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: <20260206-spacemit-p1-v4-0-8f695d93811e@riscstar.com>
prerequisite-patch-id: 5da3e75b18291a5540d4f66d7a0600fb8975ef62
prerequisite-patch-id: bcf41917414ecef8cf743095d130f6004c32f6a5
prerequisite-patch-id: cfe3800f8c791ec4c63e070af9628e88e0fc31b9
prerequisite-message-id: <20260305-k1-clk-fix-v1-1-abca85d6e266@mailbox.org>
prerequisite-patch-id: 7c7fb9f87dba019ece4c97c45750349a7cd28f3a

Best regards,
-- 
Shuwei Wu <shuwei.wu@mailbox.org>
Re: [PATCH v3 0/2] cpufreq: spacemit: Add cpufreq support for K1 SoC
Posted by Gong Shuai 5 hours ago
On 6/12/2026 5:51 PM, Shuwei Wu wrote:
> 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
> ----------------------------------------------------------------------------
> 
> Signed-off-by: Shuwei Wu <shuwei.wu@mailbox.org>
> ---
> 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/20260410-shadow-deps-v2-0-4e16b8c0f60e@mailbox.org
> 
> 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/20260308-shadow-deps-v1-0-0ceb5c7c07eb@mailbox.org
> 
> ---
> 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: <20260206-spacemit-p1-v4-0-8f695d93811e@riscstar.com>
> prerequisite-patch-id: 5da3e75b18291a5540d4f66d7a0600fb8975ef62
> prerequisite-patch-id: bcf41917414ecef8cf743095d130f6004c32f6a5
> prerequisite-patch-id: cfe3800f8c791ec4c63e070af9628e88e0fc31b9
> prerequisite-message-id: <20260305-k1-clk-fix-v1-1-abca85d6e266@mailbox.org>
> prerequisite-patch-id: 7c7fb9f87dba019ece4c97c45750349a7cd28f3a
> 
> 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:

Tested-by: Gong Shuai <gsh517025@gmail.com> # OrangePi-RV2

If you send a new version, I'm also willing to test it again.

Thanks for the work.

Regards,
Shuai
Re: [PATCH v3 0/2] cpufreq: spacemit: Add cpufreq support for K1 SoC
Posted by Viresh Kumar 5 days, 14 hours ago
On 12-06-26, 17:51, Shuwei Wu wrote:
> Changes in v3:
> - Add a K1-specific cpufreq driver for the shared-rail, dual-clock topology

Why ?

> - Use one shared CPU OPP table and one cpufreq policy for all CPUs
> - Link to v2: https://lore.kernel.org/r/20260410-shadow-deps-v2-0-4e16b8c0f60e@mailbox.org

-- 
viresh
[PATCH] riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1, SoC
Posted by Vincent Legoll 6 days, 13 hours ago
[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:

Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # OrangePi-RV2


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

-- 

Vincent Legoll

Re: [PATCH] riscv: dts: spacemit: orangepi-rv2: Add cpu scaling for K1, SoC
Posted by Yixun Lan 5 days, 19 hours ago
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)


On 08:50 Sun 14 Jun     , Vincent Legoll wrote:
> [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
> 
It's ok to add your SoB while adding support for new board

> differently, please advise.
> 
> 
> Anyways, you can add my:
> 
> Tested-by: Vincent Legoll <vincent.legoll@gmail.com> # OrangePi-RV2
> 
> 
> 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
> 
> -- 
> 
> Vincent Legoll
> 

> From 9924789655ae5f4f98e7a5cdc3df3f34e7bfb659 Mon Sep 17 00:00:00 2001
> From: Vincent Legoll <vincent.legoll@gmail.com>
> 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
> 
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


> Signed-off-by: Vincent Legoll <vincent.legoll@gmail.com>
> ---
>  .../boot/dts/spacemit/k1-orangepi-rv2.dts     | 35 ++++++++++++++++++-
>  1 file changed, 34 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts b/arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts
> index 7c49bce427f3..62d25f579af6 100644
> --- a/arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts
> +++ b/arch/riscv/boot/dts/spacemit/k1-orangepi-rv2.dts
> @@ -8,6 +8,7 @@
>  
>  #include "k1.dtsi"
>  #include "k1-pinctrl.dtsi"
> +#include "k1-opp.dtsi"
keep alphabet sorted
>  
>  / {
>  	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>;
> -- 
> 2.54.0
> 


-- 
Yixun Lan (dlan)