cpufreq support for the D1
Subsystems (6)
v2 cover cpufreq support for the D1
This patch series adds support for cpufreq on the D1 SoC, and has been tested on a Lichee RV module.
Changes in v2:
- Revert opp-microvolt-speed0 property to <target min max>
- Add dt-bindings for "allwinner,sun50i-h6-operating-points"
- Enable sun50i h6 cpufreq multiarch support by moving Kconfig option to drivers/cpufreq/Kconfig instead of creating drivers/cpufreq/Kconfig.riscv
Brandon Cheo Fusi (5):
riscv: dts: allwinner: Update opp table to allow CPU frequency scaling
dt-bindings: opp: sun50i: Add binding for D1 CPUs
cpufreq: sun50i: Add D1 support
cpufreq: dt-platdev: Blocklist allwinner,sun20i-d1 SoC
cpufreq: Make sun50i h6 cpufreq Kconfig option arch generic
.../allwinner,sun50i-h6-operating-points.yaml | 4 +++- arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi | 18 +++++++++++++++--- drivers/cpufreq/Kconfig | 12 ++++++++++++ drivers/cpufreq/Kconfig.arm | 12 ------------ drivers/cpufreq/Makefile | 2 +- drivers/cpufreq/cpufreq-dt-platdev.c | 1 + drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 + 7 files changed, 33 insertions(+), 17 deletions(-)
Signature · 1 line
2.30.2
PATCH v2 1/5 riscv: dts: allwinner: Update opp table to allow CPU frequency scaling
Two OPPs are currently defined for the D1/D1s; one at 408MHz and another at 1.08GHz. Switching between these can be done with the "sun50i-cpufreq-nvmem" driver. This patch populates the opp table appropriately, inspired by
https://github.com/Tina-Linux/linux-5.4/blob/master/arch/riscv/boot/dts/sunxi/sun20iw1p1.dtsi
The supply voltages are PWM-controlled, but support for that IP is still in the works. So stick to a target vdd-cpu supply of 0.9V, which seems to be the default on most D1 boards.
--- arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi +15 -3
@@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller { }; opp_table_cpu: opp-table-cpu { - compatible = "operating-points-v2"; + compatible = "allwinner,sun20i-d1-operating-points", + "allwinner,sun50i-h6-operating-points"; + nvmem-cells = <&cpu_speed_grade>; + nvmem-cell-names = "speed"; + opp-shared; opp-408000000 { + clock-latency-ns = <244144>; /* 8 32k periods */ opp-hz = /bits/ 64 <408000000>; - opp-microvolt = <900000 900000 1100000>; + opp-microvolt-speed0 = <900000 900000 1100000>; }; opp-1080000000 { + clock-latency-ns = <244144>; /* 8 32k periods */ opp-hz = /bits/ 64 <1008000000>; - opp-microvolt = <900000 900000 1100000>; + opp-microvolt-speed0 = <900000 900000 1100000>; }; };
@@ -115,3 +121,9 @@ pmu { <0x00000000 0x0000000f 0xffffffff 0xffffffff 0x00020000>; }; }; + +&sid { + cpu_speed_grade: cpu-speed-grade@0 { + reg = <0x00 0x2>; + }; +};
Signature · 1 line
2.30.2
Samuel Holland
maintainerRe: [PATCH v2 1/5] riscv: dts: allwinner: Update opp table to allow CPU frequency scaling
Quoted 20 lines · Brandon Cheo Fusi
Two OPPs are currently defined for the D1/D1s; one at 408MHz and another at 1.08GHz. Switching between these can be done with the "sun50i-cpufreq-nvmem" driver. This patch populates the opp table appropriately, inspired by
https://github.com/Tina-Linux/linux-5.4/blob/master/arch/riscv/boot/dts/sunxi/sun20iw1p1.dtsiThe supply voltages are PWM-controlled, but support for that IP is still in the works. So stick to a target vdd-cpu supply of 0.9V, which seems to be the default on most D1 boards.
Signed-off-by Brandon Cheo Fusi <[email protected]>--- arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi +0
-0
arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi cpu0_intc: interrupt-controller { · line 43
Quoted 6 lines
arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi +2
-1@@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller { }; opp_table_cpu: opp-table-cpu { - compatible = "operating-points-v2"; + compatible = "allwinner,sun20i-d1-operating-points", + "allwinner,sun50i-h6-operating-points";
This is not correct. The compatible string specifies the algorithm for looking up the speed grade from the NVMEM cell, and D1 uses a totally different algorithm compared to H6:
https://github.com/Tina-Linux/linux-5.4/blob/master/drivers/cpufreq/sun50i-cpufreq-nvmem.c#L293-L338
So you cannot use a fallback compatible string here, and you need to add driver support for the D1's speed bin encoding.
Regards,
Samuel
Quoted 29 lines
arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi +13
-2+ nvmem-cells = <&cpu_speed_grade>; + nvmem-cell-names = "speed"; + opp-shared; opp-408000000 { + clock-latency-ns = <244144>; /* 8 32k periods */ opp-hz = /bits/ 64 <408000000>; - opp-microvolt = <900000 900000 1100000>; + opp-microvolt-speed0 = <900000 900000 1100000>; }; opp-1080000000 { + clock-latency-ns = <244144>; /* 8 32k periods */ opp-hz = /bits/ 64 <1008000000>; - opp-microvolt = <900000 900000 1100000>; + opp-microvolt-speed0 = <900000 900000 1100000>; }; };@@ -115,3 +121,9 @@ pmu { <0x00000000 0x0000000f 0xffffffff 0xffffffff 0x00020000>; }; }; + +&sid { + cpu_speed_grade: cpu-speed-grade@0 { + reg = <0x00 0x2>; + }; +};
PATCH v2 2/5 dt-bindings: opp: sun50i: Add binding for D1 CPUs
In reply to Brandon Cheo FusiAdd binding for D1 CPU OPPs.
--- .../bindings/opp/allwinner,sun50i-h6-operating-points.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml +3 -1
@@ -23,7 +23,9 @@ allOf: properties: compatible: - const: allwinner,sun50i-h6-operating-points + enum: + - allwinner,sun50i-h6-operating-points + - allwinner,sun20i-d1-operating-points nvmem-cells: description: |
Signature · 1 line
2.30.2
Re: [PATCH v2 2/5] dt-bindings: opp: sun50i: Add binding for D1 CPUs
Quoted 12 lines · Brandon Cheo Fusi
Add binding for D1 CPU OPPs.
Signed-off-by Brandon Cheo Fusi <[email protected]>--- .../bindings/opp/allwinner,sun50i-h6-operating-points.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml +0
-0
Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml allOf: · line 28
Quoted 7 lines
Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml +3
-1@@ -23,7 +23,9 @@ allOf: properties: compatible: - const: allwinner,sun50i-h6-operating-points + enum: + - allwinner,sun50i-h6-operating-points + - allwinner,sun20i-d1-operating-points
This doesn't match what you have in your devicetree.
Quoted 6 lines
Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml +0
-0nvmem-cells: description: |Signature · 1 line
2.30.2
Re: [PATCH v2 2/5] dt-bindings: opp: sun50i: Add binding for D1 CPUs
Quoted 14 lines · Conor Dooley
Quoted 13 lines · Brandon Cheo Fusi
Add binding for D1 CPU OPPs.
Signed-off-by Brandon Cheo Fusi <[email protected]>--- .../bindings/opp/allwinner,sun50i-h6-operating-points.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml +0
-0@@ -23,7 +23,9 @@ allOf:
Quoted 8 lines
Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml allOf: · line 28
Quoted 6 lines
Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml +3
-1properties: compatible: - const: allwinner,sun50i-h6-operating-points + enum: + - allwinner,sun50i-h6-operating-points + - allwinner,sun20i-d1-operating-pointsThis doesn't match what you have in your devicetree.
Per Samuel's comments in <[email protected]>
it looks like this binding is correct but the devicetree is wrong.
Thanks,
Conor.
PATCH v2 3/5 cpufreq: sun50i: Add D1 support
In reply to Brandon Cheo FusiAdd support for D1 based devices to the Allwinner H6 cpufreq driver
--- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 + 1 file changed, 1 insertion(+)
drivers/cpufreq/sun50i-cpufreq-nvmem.c +1 -0
@@ -160,6 +160,7 @@ static struct platform_driver sun50i_cpufreq_driver = {static const struct of_device_id sun50i_cpufreq_match_list[] = { { .compatible ="allwinner,sun50i-h6" }, + { .compatible ="allwinner,sun20i-d1" }, {} };MODULE_DEVICE_TABLE (of, sun50i_cpufreq_match_list);
Signature · 1 line
2.30.2
Re: [PATCH v2 3/5] cpufreq: sun50i: Add D1 support
Quoted 13 lines · Brandon Cheo Fusi
Add support for D1 based devices to the Allwinner H6 cpufreq driver
Signed-off-by Brandon Cheo Fusi <[email protected]>--- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 + 1 file changed, 1 insertion(+)drivers/cpufreq/sun50i-cpufreq-nvmem.c +0
-0
drivers/cpufreq/sun50i-cpufreq-nvmem.c static struct platform_driver sun50i_cpufreq_driver = { · line 163
Quoted 4 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c +1
-0@@ -160,6 +160,7 @@ static struct platform_driver sun50i_cpufreq_driver = {static const struct of_device_id sun50i_cpufreq_match_list[] = { { .compatible ="allwinner,sun50i-h6" }, + { .compatible ="allwinner,sun20i-d1" },
I thought the feedback in v2 was to drop this change, since the devicetree has the sun50i-h6 as a fallback compatible?
Re: [PATCH v2 3/5] cpufreq: sun50i: Add D1 support
On Mon, 18 Dec 2023 14:55:30 +0000
Conor Dooley <[email protected]> wrote:
Hi,
Quoted 15 lines · Brandon Cheo Fusi
Quoted 14 lines
Add support for D1 based devices to the Allwinner H6 cpufreq driver
Signed-off-by Brandon Cheo Fusi <[email protected]>--- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 + 1 file changed, 1 insertion(+)drivers/cpufreq/sun50i-cpufreq-nvmem.c +0
-0@@ -160,6 +160,7 @@ static struct platform_driver sun50i_cpufreq_driver = {
Quoted 6 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c static struct platform_driver sun50i_cpufreq_driver = { · line 163
Quoted 3 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c +1
-0static const struct of_device_id sun50i_cpufreq_match_list[] = { { .compatible ="allwinner,sun50i-h6" }, + { .compatible ="allwinner,sun20i-d1" },I thought the feedback in v2 was to drop this change, since the devicetree has the sun50i-h6 as a fallback compatible?
Well, this is the *board* (fallback) compatible string, so we cannot assign it as we like. The whole (existing) scheme is admittedly somewhat weird, because we not only match on a particular device compatible (like allwinner,sun20i-d1-operating-points), but also need to blocklist and re-match some parts against the *board compatible*, owing to the cpufreq-dt driver. The board name is basically used as a placeholder to find out the SoC, because there is (or was?) no other good way - the CPU DT nodes don't work for this. Back when this was introduced, this was the "least worst" solution.
I don't remember all the details, and didn't find time yet to look into this in more detail, but fixing this is non-trivial. If this isn't 6.8 material, I might have a look at this later this week/month.
Cheers,
Andre
Jernej Škrabec
maintainerRe: [PATCH v2 3/5] cpufreq: sun50i: Add D1 support
Dne ponedeljek, 18. december 2023 ob 16:53:45 CET je Andre Przywara napisal(a):
Quoted 37 lines
On Mon, 18 Dec 2023 14:55:30 +0000
Conor Dooley <[email protected]> wrote:Hi,
Quoted 15 lines · Brandon Cheo Fusi
Quoted 14 lines
Add support for D1 based devices to the Allwinner H6 cpufreq driver
Signed-off-by Brandon Cheo Fusi <[email protected]>--- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 + 1 file changed, 1 insertion(+)drivers/cpufreq/sun50i-cpufreq-nvmem.c +0
-0@@ -160,6 +160,7 @@ static struct platform_driver sun50i_cpufreq_driver = {Quoted 6 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c static struct platform_driver sun50i_cpufreq_driver = { · line 163
Quoted 3 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c +1
-0static const struct of_device_id sun50i_cpufreq_match_list[] = { { .compatible ="allwinner,sun50i-h6" }, + { .compatible ="allwinner,sun20i-d1" },I thought the feedback in v2 was to drop this change, since the devicetree has the sun50i-h6 as a fallback compatible?
Well, this is the *board* (fallback) compatible string, so we cannot assign it as we like. The whole (existing) scheme is admittedly somewhat weird, because we not only match on a particular device compatible (like allwinner,sun20i-d1-operating-points), but also need to blocklist and re-match some parts against the *board compatible*, owing to the cpufreq-dt driver. The board name is basically used as a placeholder to find out the SoC, because there is (or was?) no other good way - the CPU DT nodes don't work for this. Back when this was introduced, this was the "least worst" solution.
Quoted 3 lines
I don't remember all the details, and didn't find time yet to look into this in more detail, but fixing this is non-trivial. If this isn't 6.8 material, I might have a look at this later this week/month.
I would say it's 6.9 material. -rc6 already passed and it's not yet aligned with all maintainers.
Best regards,
Jernej
Re: [PATCH v2 3/5] cpufreq: sun50i: Add D1 support
In reply to Andre PrzywaraQuoted 20 lines · Andre Przywara
On Mon, 18 Dec 2023 14:55:30 +0000
Conor Dooley <[email protected]> wrote:Hi,
Quoted 15 lines · Brandon Cheo Fusi
Quoted 14 lines
Add support for D1 based devices to the Allwinner H6 cpufreq driver
Signed-off-by Brandon Cheo Fusi <[email protected]>--- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 + 1 file changed, 1 insertion(+)drivers/cpufreq/sun50i-cpufreq-nvmem.c +0
-0@@ -160,6 +160,7 @@ static struct platform_driver sun50i_cpufreq_driver = {
Quoted 8 lines
Quoted 6 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c static struct platform_driver sun50i_cpufreq_driver = { · line 163
Quoted 3 lines
drivers/cpufreq/sun50i-cpufreq-nvmem.c +1
-0static const struct of_device_id sun50i_cpufreq_match_list[] = { { .compatible ="allwinner,sun50i-h6" }, + { .compatible ="allwinner,sun20i-d1" },I thought the feedback in v2 was to drop this change, since the devicetree has the sun50i-h6 as a fallback compatible?
Well, this is the *board* (fallback) compatible string, so we cannot assign
Oh of course... That's both me and Jernej that tripped up on this. Brandon, please ignore the comment from me on this patch.
Thanks,
Conor.
PATCH v2 4/5 cpufreq: dt-platdev: Blocklist allwinner,sun20i-d1 SoC
In reply to Brandon Cheo FusiThe Allwinner D1 uses H6 cpufreq driver. Add it to blocklist so the "cpufreq-dt" device is not created twice.
--- drivers/cpufreq/cpufreq-dt-platdev.c | 1 + 1 file changed, 1 insertion(+)
drivers/cpufreq/cpufreq-dt-platdev.c +1 -0
@@ -104,6 +104,7 @@ static const struct of_device_id allowlist[] __initconst = {*/ static const struct of_device_id blocklist[]__initconst = { { .compatible ="allwinner,sun50i-h6" , }, + { .compatible ="allwinner,sun20i-d1" , }, { .compatible ="apple,arm-platform" , },
Signature · 1 line
2.30.2
PATCH v2 5/5 cpufreq: Make sun50i h6 cpufreq Kconfig option arch generic
In reply to Brandon Cheo FusiMove the Allwinner SUN50I cpufreq driver from Kconfig.arm to the main Kconfig file so it supports other architectures, like RISC-V in our case, and drop the 'ARM_' prefix.
--- drivers/cpufreq/Kconfig | 12 ++++++++++++ drivers/cpufreq/Kconfig.arm | 12 ------------ drivers/cpufreq/Makefile | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-)
drivers/cpufreq/Kconfig +12 -0
@@ -301,5 +301,17 @@ config QORIQ_CPUFREQ This adds the CPUFreq driver support for Freescale QorIQ SoCs which are capable of changing the CPU's frequency dynamically. +config ALLWINNER_SUN50I_CPUFREQ_NVMEM + tristate "Allwinner nvmem based SUN50I CPUFreq driver" + depends on ARCH_SUNXI + depends on NVMEM_SUNXI_SID + select PM_OPP + help + This adds the nvmem based CPUFreq driver for Allwinner + h6/D1 SoCs. + + To compile this driver as a module, choose M here: the + module will be called sun50i-cpufreq-nvmem. + endif endmenu
drivers/cpufreq/Kconfig.arm +0 -12
@@ -29,18 +29,6 @@ config ACPI_CPPC_CPUFREQ_FIE If in doubt, say N. -config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM - tristate "Allwinner nvmem based SUN50I CPUFreq driver" - depends on ARCH_SUNXI - depends on NVMEM_SUNXI_SID - select PM_OPP - help - This adds the nvmem based CPUFreq driver for Allwinner - h6 SoC. - - To compile this driver as a module, choose M here: the - module will be called sun50i-cpufreq-nvmem. - config ARM_APPLE_SOC_CPUFREQ tristate "Apple Silicon SoC CPUFreq support" depends on ARCH_APPLE || (COMPILE_TEST && 64BIT)
drivers/cpufreq/Makefile +1 -1
@@ -78,7 +78,7 @@ obj-$(CONFIG_ARM_SCMI_CPUFREQ) += scmi-cpufreq.o obj-$(CONFIG_ARM_SCPI_CPUFREQ) += scpi-cpufreq.o obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o obj-$(CONFIG_ARM_STI_CPUFREQ) += sti-cpufreq.o -obj-$(CONFIG_ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM) += sun50i-cpufreq-nvmem.o +obj-$(CONFIG_ALLWINNER_SUN50I_CPUFREQ_NVMEM) += sun50i-cpufreq-nvmem.o obj-$(CONFIG_ARM_TEGRA20_CPUFREQ) += tegra20-cpufreq.o obj-$(CONFIG_ARM_TEGRA124_CPUFREQ) += tegra124-cpufreq.o obj-$(CONFIG_ARM_TEGRA186_CPUFREQ) += tegra186-cpufreq.o
Signature · 1 line
2.30.2
Jernej Škrabec
maintainerRe: [PATCH v2 5/5] cpufreq: Make sun50i h6 cpufreq Kconfig option arch generic
Dne ponedeljek, 18. december 2023 ob 12:05:43 CET je Brandon Cheo Fusi napisal(a):
Quoted 61 lines
Move the Allwinner SUN50I cpufreq driver from
Kconfig.armto the mainKconfigfile so it supports other architectures, like RISC-V in our case, and drop the 'ARM_' prefix.Signed-off-by Brandon Cheo Fusi <[email protected]>--- drivers/cpufreq/Kconfig | 12 ++++++++++++ drivers/cpufreq/Kconfig.arm | 12 ------------ drivers/cpufreq/Makefile | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-)drivers/cpufreq/Kconfig +12
-0@@ -301,5 +301,17 @@ config QORIQ_CPUFREQ This adds the CPUFreq driver support for Freescale QorIQ SoCs which are capable of changing the CPU's frequency dynamically. +config ALLWINNER_SUN50I_CPUFREQ_NVMEM + tristate "Allwinner nvmem based SUN50I CPUFreq driver" + depends on ARCH_SUNXI + depends on NVMEM_SUNXI_SID + select PM_OPP + help + This adds the nvmem based CPUFreq driver for Allwinner + h6/D1 SoCs. + + To compile this driver as a module, choose M here: the + module will be called sun50i-cpufreq-nvmem. + endif endmenudrivers/cpufreq/Kconfig.arm +0
-12@@ -29,18 +29,6 @@ config ACPI_CPPC_CPUFREQ_FIE If in doubt, say N. -config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM - tristate "Allwinner nvmem based SUN50I CPUFreq driver" - depends on ARCH_SUNXI - depends on NVMEM_SUNXI_SID - select PM_OPP - help - This adds the nvmem based CPUFreq driver for Allwinner - h6 SoC. - - To compile this driver as a module, choose M here: the - module will be called sun50i-cpufreq-nvmem. - config ARM_APPLE_SOC_CPUFREQ tristate "Apple Silicon SoC CPUFreq support" depends on ARCH_APPLE || (COMPILE_TEST && 64BIT)drivers/cpufreq/Makefile +0
-0
drivers/cpufreq/Makefile obj-$(CONFIG_ARM_SCMI_CPUFREQ) += scmi-cpufreq.o · line 81
Quoted 5 lines
drivers/cpufreq/Makefile +1
-1@@ -78,7 +78,7 @@ obj-$(CONFIG_ARM_SCMI_CPUFREQ) += scmi-cpufreq.o obj-$(CONFIG_ARM_SCPI_CPUFREQ) += scpi-cpufreq.o obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o obj-$(CONFIG_ARM_STI_CPUFREQ) += sti-cpufreq.o -obj-$(CONFIG_ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM) += sun50i-cpufreq-nvmem.o +obj-$(CONFIG_ALLWINNER_SUN50I_CPUFREQ_NVMEM) += sun50i-cpufreq-nvmem.o
This should be moved, so it's sorted alphabetically.
Best regards,
Jernej
Quoted 4 lines
drivers/cpufreq/Makefile +0
-0obj-$(CONFIG_ARM_TEGRA20_CPUFREQ) += tegra20-cpufreq.o obj-$(CONFIG_ARM_TEGRA124_CPUFREQ) += tegra124-cpufreq.o obj-$(CONFIG_ARM_TEGRA186_CPUFREQ) += tegra186-cpufreq.o