2023-12-14 10:34:39

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH 0/5] cpufreq support for the D1

This patch series adds support for cpufreq on the D1 SoC, and a new
Kconfig.riscv file to cater to cpufreq drivers that support RISC-V
SoCs.

The changes have been tested on a Lichee RV module.

Brandon Cheo Fusi (5):
riscv: dts: allwinner: Update opp table to allow CPU frequency scaling
cpufreq: sun50i: Add D1 support
cpufreq: dt-platdev: Blocklist allwinner,sun20i-d1 SoC
cpufreq: Add support for RISC-V CPU Frequency scaling drivers
cpufreq: Make sun50i h6 cpufreq Kconfig option generic

arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi | 18 +++++++++++++++---
drivers/cpufreq/Kconfig | 4 ++++
drivers/cpufreq/Kconfig.arm | 4 ++--
drivers/cpufreq/Kconfig.riscv | 16 ++++++++++++++++
drivers/cpufreq/Makefile | 2 +-
drivers/cpufreq/cpufreq-dt-platdev.c | 1 +
drivers/cpufreq/sun50i-cpufreq-nvmem.c | 1 +
7 files changed, 40 insertions(+), 6 deletions(-)
create mode 100644 drivers/cpufreq/Kconfig.riscv

--
2.30.2


2023-12-14 10:35:00

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH 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, with inspiration from
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 fixed 0.9V vdd-cpu supply,
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(-)

diff --git a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
index 64c3c2e6c..e211fe4c7 100644
--- a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
+++ b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
@@ -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>;
};

opp-1080000000 {
+ clock-latency-ns = <244144>; /* 8 32k periods */
opp-hz = /bits/ 64 <1008000000>;
- opp-microvolt = <900000 900000 1100000>;
+ opp-microvolt-speed0 = <900000>;
};
};

@@ -115,3 +121,8 @@ pmu {
<0x00000000 0x0000000f 0xffffffff 0xffffffff 0x00020000>;
};
};
+
+&sid {
+ cpu_speed_grade: cpu-speed-grade@0 {
+ reg = <0x00 0x2>;
+ };
+};
--
2.30.2

2023-12-14 10:35:26

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH 2/5] cpufreq: sun50i: Add D1 support

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(+)

diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
index 32a9c88f8..ccf83780f 100644
--- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
+++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
@@ -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);
--
2.30.2

2023-12-14 10:35:37

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH 3/5] cpufreq: dt-platdev: Blocklist allwinner,sun20i-d1 SoC

The Allwinner D1 uses H6 cpufreq driver. Add it to blocklist
so the "cpufreq-dt" device is not created twice.

Signed-off-by: Brandon Cheo Fusi <[email protected]>
---
drivers/cpufreq/cpufreq-dt-platdev.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c b/drivers/cpufreq/cpufreq-dt-platdev.c
index bd1e1357c..2febcfc2c 100644
--- a/drivers/cpufreq/cpufreq-dt-platdev.c
+++ b/drivers/cpufreq/cpufreq-dt-platdev.c
@@ -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", },

--
2.30.2

2023-12-14 10:35:59

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH 4/5] cpufreq: Add support for RISC-V CPU Frequency scaling drivers

Add Kconfig file for cpufreq scaling drivers that can handle RISC-V
CPUs. An entry is included for the Allwinner H6 cpufreq driver that
works with D1.

Signed-off-by: Brandon Cheo Fusi <[email protected]>
---
drivers/cpufreq/Kconfig | 4 ++++
drivers/cpufreq/Kconfig.riscv | 16 ++++++++++++++++
2 files changed, 20 insertions(+)
create mode 100644 drivers/cpufreq/Kconfig.riscv

diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig
index 35efb53d5..4bef39fed 100644
--- a/drivers/cpufreq/Kconfig
+++ b/drivers/cpufreq/Kconfig
@@ -239,6 +239,10 @@ if PPC32 || PPC64
source "drivers/cpufreq/Kconfig.powerpc"
endif

+if RISCV
+source "drivers/cpufreq/Kconfig.riscv"
+endif
+
if MIPS
config BMIPS_CPUFREQ
tristate "BMIPS CPUfreq Driver"
diff --git a/drivers/cpufreq/Kconfig.riscv b/drivers/cpufreq/Kconfig.riscv
new file mode 100644
index 000000000..025c7c439
--- /dev/null
+++ b/drivers/cpufreq/Kconfig.riscv
@@ -0,0 +1,16 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# RISC-V CPU Frequency scaling drivers
+#
+
+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.
\ No newline at end of file
--
2.30.2

2023-12-14 10:36:14

by Brandon Cheo Fusi

[permalink] [raw]
Subject: [PATCH 5/5] cpufreq: Make sun50i h6 cpufreq Kconfig option generic

Remove the 'ARM_' prefix from the Allwinner SUN50I cpufreq driver
Kconfig.arm option as that driver can support the D1, a RISC-V
chip.

Signed-off-by: Brandon Cheo Fusi <[email protected]>
---
drivers/cpufreq/Kconfig.arm | 4 ++--
drivers/cpufreq/Makefile | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/cpufreq/Kconfig.arm b/drivers/cpufreq/Kconfig.arm
index f91160689..510604781 100644
--- a/drivers/cpufreq/Kconfig.arm
+++ b/drivers/cpufreq/Kconfig.arm
@@ -29,14 +29,14 @@ config ACPI_CPPC_CPUFREQ_FIE

If in doubt, say N.

-config ARM_ALLWINNER_SUN50I_CPUFREQ_NVMEM
+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 SoC.
+ H6/D1 SoCs.

To compile this driver as a module, choose M here: the
module will be called sun50i-cpufreq-nvmem.
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile
index 8d141c71b..110b676d2 100644
--- a/drivers/cpufreq/Makefile
+++ b/drivers/cpufreq/Makefile
@@ -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
--
2.30.2

2023-12-14 11:15:04

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH 1/5] riscv: dts: allwinner: Update opp table to allow CPU frequency scaling

On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> 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, with inspiration from
> 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 fixed 0.9V vdd-cpu supply,
> 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(-)
>
> diff --git a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> index 64c3c2e6c..e211fe4c7 100644
> --- a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> +++ b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> @@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller {
> };
>
> opp_table_cpu: opp-table-cpu {
> - compatible = "operating-points-v2";
> + compatible = "allwinner,sun20i-d1-operating-points",

I don't think you should add a new compatible for every SoC that needs
to be supported by a DT bindings and cpufreq driver. Maybe you should
just reuse "allwinner,sun50i-h6-operating-points" and it will work
fine for you ?

Rob ?

> + "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>;

The separate property name thing was required when you could have
different values for different SoC instances, which can be read from
efuses, like in your case.

But all I see is speed0 here, why don't you always set opp-microvolt
then ?

Also why degrade from min/max/target type to just target ?

> };
>
> opp-1080000000 {
> + clock-latency-ns = <244144>; /* 8 32k periods */
> opp-hz = /bits/ 64 <1008000000>;
> - opp-microvolt = <900000 900000 1100000>;
> + opp-microvolt-speed0 = <900000>;
> };
> };
>
> @@ -115,3 +121,8 @@ pmu {
> <0x00000000 0x0000000f 0xffffffff 0xffffffff 0x00020000>;
> };
> };
> +
> +&sid {
> + cpu_speed_grade: cpu-speed-grade@0 {
> + reg = <0x00 0x2>;
> + };
> +};
> --
> 2.30.2

--
viresh

2023-12-14 11:17:17

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH 4/5] cpufreq: Add support for RISC-V CPU Frequency scaling drivers

On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> Add Kconfig file for cpufreq scaling drivers that can handle RISC-V
> CPUs. An entry is included for the Allwinner H6 cpufreq driver that
> works with D1.
>
> Signed-off-by: Brandon Cheo Fusi <[email protected]>
> ---
> drivers/cpufreq/Kconfig | 4 ++++
> drivers/cpufreq/Kconfig.riscv | 16 ++++++++++++++++
> 2 files changed, 20 insertions(+)
> create mode 100644 drivers/cpufreq/Kconfig.riscv

We don't have a separate kconfig file for each architecture. Only if
there are too many entries for an architecture, we add a new file.

--
viresh

2023-12-14 13:47:34

by Conor Dooley

[permalink] [raw]
Subject: Re: [PATCH 1/5] riscv: dts: allwinner: Update opp table to allow CPU frequency scaling

On Thu, Dec 14, 2023 at 04:44:46PM +0530, Viresh Kumar wrote:
> On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> > 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, with inspiration from
> > 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 fixed 0.9V vdd-cpu supply,
> > 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(-)
> >
> > diff --git a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > index 64c3c2e6c..e211fe4c7 100644
> > --- a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > +++ b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > @@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller {
> > };
> >
> > opp_table_cpu: opp-table-cpu {
> > - compatible = "operating-points-v2";
> > + compatible = "allwinner,sun20i-d1-operating-points",
>
> I don't think you should add a new compatible for every SoC that needs
> to be supported by a DT bindings and cpufreq driver. Maybe you should
> just reuse "allwinner,sun50i-h6-operating-points" and it will work
> fine for you ?
>
> Rob ?

The driver can definitely just reuse sun50i-h6, but the binding and
devicetree should have a soc-specific compatible for the sun20i-d1.

That said, the compatible does need to be documented, there's a
dt-bindings patch missing from this series.

Cheers,
Conor.


Attachments:
(No filename) (1.84 kB)
signature.asc (235.00 B)
Download all attachments

2023-12-14 16:30:01

by Jernej Škrabec

[permalink] [raw]
Subject: Re: [PATCH 2/5] cpufreq: sun50i: Add D1 support

On Thursday, December 14, 2023 11:33:39 AM CET Brandon Cheo Fusi wrote:
> 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(+)
>
> diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> index 32a9c88f8..ccf83780f 100644
> --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> @@ -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" },

This is not needed, as there is no functionality change.

Best regards,
Jernej

> {}
> };
> MODULE_DEVICE_TABLE(of, sun50i_cpufreq_match_list);
>




2023-12-14 16:30:52

by Jernej Škrabec

[permalink] [raw]
Subject: Re: [PATCH 3/5] cpufreq: dt-platdev: Blocklist allwinner,sun20i-d1 SoC

On Thursday, December 14, 2023 11:33:40 AM CET Brandon Cheo Fusi wrote:
> The Allwinner D1 uses H6 cpufreq driver. Add it to blocklist
> so the "cpufreq-dt" device is not created twice.
>
> Signed-off-by: Brandon Cheo Fusi <[email protected]>
> ---
> drivers/cpufreq/cpufreq-dt-platdev.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/cpufreq/cpufreq-dt-platdev.c b/drivers/cpufreq/cpufreq-dt-platdev.c
> index bd1e1357c..2febcfc2c 100644
> --- a/drivers/cpufreq/cpufreq-dt-platdev.c
> +++ b/drivers/cpufreq/cpufreq-dt-platdev.c
> @@ -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", },

This should not be needed since you're using H6 variant for a fallback.

Best regards,
Jernej

>
> { .compatible = "apple,arm-platform", },
>
>




2023-12-14 16:37:19

by Jernej Škrabec

[permalink] [raw]
Subject: Re: [PATCH 1/5] riscv: dts: allwinner: Update opp table to allow CPU frequency scaling

On Thursday, December 14, 2023 2:47:14 PM CET Conor Dooley wrote:
> On Thu, Dec 14, 2023 at 04:44:46PM +0530, Viresh Kumar wrote:
> > On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> > > 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, with inspiration from
> > > 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 fixed 0.9V vdd-cpu supply,
> > > 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(-)
> > >
> > > diff --git a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > > index 64c3c2e6c..e211fe4c7 100644
> > > --- a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > > +++ b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > > @@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller {
> > > };
> > >
> > > opp_table_cpu: opp-table-cpu {
> > > - compatible = "operating-points-v2";
> > > + compatible = "allwinner,sun20i-d1-operating-points",
> >
> > I don't think you should add a new compatible for every SoC that needs
> > to be supported by a DT bindings and cpufreq driver. Maybe you should
> > just reuse "allwinner,sun50i-h6-operating-points" and it will work
> > fine for you ?
> >
> > Rob ?
>
> The driver can definitely just reuse sun50i-h6, but the binding and
> devicetree should have a soc-specific compatible for the sun20i-d1.

Correct. This is to avoid later regrets if it turns out there are some slight
differences or additional functionality.

Best regards,
Jernej

>
> That said, the compatible does need to be documented, there's a
> dt-bindings patch missing from this series.
>
> Cheers,
> Conor.




2023-12-14 16:40:41

by Andre Przywara

[permalink] [raw]
Subject: Re: [PATCH 2/5] cpufreq: sun50i: Add D1 support

On Thu, 14 Dec 2023 17:29:30 +0100
Jernej Škrabec <[email protected]> wrote:

Hi,

> On Thursday, December 14, 2023 11:33:39 AM CET Brandon Cheo Fusi wrote:
> > 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(+)
> >
> > diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > index 32a9c88f8..ccf83780f 100644
> > --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > @@ -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" },
>
> This is not needed, as there is no functionality change.

That was my first reflex, too, but this is the *board* (fallback)
compatible, listed in the root node, so you have to list it here for each
SoC, together with the respective blocklist in the next patch.
We are doing the same for the H616, and actually also need that for the
H618. Weird, I know, but last time I check not easy to fix.

Cheers,
Andre

2023-12-14 17:17:43

by Jernej Škrabec

[permalink] [raw]
Subject: Re: [PATCH 2/5] cpufreq: sun50i: Add D1 support

On Thursday, December 14, 2023 5:40:10 PM CET Andre Przywara wrote:
> On Thu, 14 Dec 2023 17:29:30 +0100
> Jernej Škrabec <[email protected]> wrote:
>
> Hi,
>
> > On Thursday, December 14, 2023 11:33:39 AM CET Brandon Cheo Fusi wrote:
> > > 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(+)
> > >
> > > diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > > index 32a9c88f8..ccf83780f 100644
> > > --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > > +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c
> > > @@ -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" },
> >
> > This is not needed, as there is no functionality change.
>
> That was my first reflex, too, but this is the *board* (fallback)
> compatible, listed in the root node, so you have to list it here for each
> SoC, together with the respective blocklist in the next patch.
> We are doing the same for the H616, and actually also need that for the
> H618. Weird, I know, but last time I check not easy to fix.

Oh, that's bad. What's the rationale to have so complicated probe method?
Why not using standard, compatible based one?

Best regards,
Jernej



2023-12-15 15:16:04

by Brandon Cheo Fusi

[permalink] [raw]
Subject: Re: [PATCH 1/5] riscv: dts: allwinner: Update opp table to allow CPU frequency scaling

On Thu, Dec 14, 2023 at 12:14 PM Viresh Kumar <[email protected]> wrote:
>
> On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> > 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, with inspiration from
> > 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 fixed 0.9V vdd-cpu supply,
> > 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(-)
> >
> > diff --git a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > index 64c3c2e6c..e211fe4c7 100644
> > --- a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > +++ b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > @@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller {
> >       };
> >
> >       opp_table_cpu: opp-table-cpu {
> > -             compatible = "operating-points-v2";
> > +             compatible = "allwinner,sun20i-d1-operating-points",
>
> I don't think you should add a new compatible for every SoC that needs
> to be supported by a DT bindings and cpufreq driver. Maybe you should
> just reuse "allwinner,sun50i-h6-operating-points" and it will work
> fine for you ?
>
> Rob ?
>
> > +                              "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>;
>
> The separate property name thing was required when you could have
> different values for different SoC instances, which can be read from
> efuses, like in your case.
>
> But all I see is speed0 here, why don't you always set opp-microvolt
> then ?
>

Setting opp-microvolt would be ok, but opp-microvolt-speed0 was chosen for
consistency with the driver bindings here
https://elixir.bootlin.com/linux/latest/source/Documentation/devicetree/bindings/opp/allwinner,sun50i-h6-operating-points.yaml#L52

> Also why degrade from min/max/target type to just target ?
>

This is a mistake on my part as I thought requesting non default voltages
was going to be a problem with lack of PWM support. Will be reverted in v2.

> >               };
> >
> >               opp-1080000000 {
> > +                     clock-latency-ns = <244144>; /* 8 32k periods */
> >                       opp-hz = /bits/ 64 <1008000000>;
> > -                     opp-microvolt = <900000 900000 1100000>;
> > +                     opp-microvolt-speed0 = <900000>;
> >               };
> >       };
> >
> > @@ -115,3 +121,8 @@ pmu {
> >                       <0x00000000 0x0000000f 0xffffffff 0xffffffff 0x00020000>;
> >       };
> >  };
> > +
> > +&sid {
> > +     cpu_speed_grade: cpu-speed-grade@0 {
> > +             reg = <0x00 0x2>;
> > +     };
> > +};
> > --
> > 2.30.2
>
> --
> viresh

Thank you for reviewing.
Brandon.

2023-12-15 15:19:21

by Brandon Cheo Fusi

[permalink] [raw]
Subject: Re: [PATCH 4/5] cpufreq: Add support for RISC-V CPU Frequency scaling drivers

On Thu, Dec 14, 2023 at 12:17 PM Viresh Kumar <[email protected]> wrote:
>
> On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> > Add Kconfig file for cpufreq scaling drivers that can handle RISC-V
> > CPUs. An entry is included for the Allwinner H6 cpufreq driver that
> > works with D1.
> >
> > Signed-off-by: Brandon Cheo Fusi <[email protected]>
> > ---
> > drivers/cpufreq/Kconfig | 4 ++++
> > drivers/cpufreq/Kconfig.riscv | 16 ++++++++++++++++
> > 2 files changed, 20 insertions(+)
> > create mode 100644 drivers/cpufreq/Kconfig.riscv
>
> We don't have a separate kconfig file for each architecture. Only if
> there are too many entries for an architecture, we add a new file.
>
> --
> viresh

The sun50i cpufreq driver is currently only available when CONFIG_ARM or
CONFIG_ARM64 is selected, so this was the only decent way I could think
of making it accessible on either one of CONFIG_(ARM | ARM64 | RISC-V).
Any suggestions for a better workaround ?

Also I think future cpufreq drivers for RISC-V are going to happen, so we
might as well have the Kconfig file.

Kind Regards,
Brandon.

2023-12-15 15:24:02

by Brandon Cheo Fusi

[permalink] [raw]
Subject: Re: [PATCH 1/5] riscv: dts: allwinner: Update opp table to allow CPU frequency scaling

On Thu, Dec 14, 2023 at 5:37 PM Jernej Škrabec <[email protected]> wrote:
>
> On Thursday, December 14, 2023 2:47:14 PM CET Conor Dooley wrote:
> > On Thu, Dec 14, 2023 at 04:44:46PM +0530, Viresh Kumar wrote:
> > > On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
> > > > 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, with inspiration from
> > > > 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 fixed 0.9V vdd-cpu supply,
> > > > 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(-)
> > > >
> > > > diff --git a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > > > index 64c3c2e6c..e211fe4c7 100644
> > > > --- a/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > > > +++ b/arch/riscv/boot/dts/allwinner/sun20i-d1s.dtsi
> > > > @@ -39,16 +39,22 @@ cpu0_intc: interrupt-controller {
> > > >   };
> > > >
> > > >   opp_table_cpu: opp-table-cpu {
> > > > -         compatible = "operating-points-v2";
> > > > +         compatible = "allwinner,sun20i-d1-operating-points",
> > >
> > > I don't think you should add a new compatible for every SoC that needs
> > > to be supported by a DT bindings and cpufreq driver. Maybe you should
> > > just reuse "allwinner,sun50i-h6-operating-points" and it will work
> > > fine for you ?
> > >
> > > Rob ?
> >
> > The driver can definitely just reuse sun50i-h6, but the binding and
> > devicetree should have a soc-specific compatible for the sun20i-d1.
>
> Correct. This is to avoid later regrets if it turns out there are some slight
> differences or additional functionality.
>
> Best regards,
> Jernej
>
> >
> > That said, the compatible does need to be documented, there's a
> > dt-bindings patch missing from this series.
> >
> > Cheers,
> > Conor.
>
>
>
>

This dt-bindings patch will be available in v2

Thanks for reviewing.
Brandon.

2023-12-15 21:10:01

by Samuel Holland

[permalink] [raw]
Subject: Re: [PATCH 4/5] cpufreq: Add support for RISC-V CPU Frequency scaling drivers

Hi Brandon,

On 12/15/23 09:17, Brandon Cheo Fusi wrote:
> On Thu, Dec 14, 2023 at 12:17 PM Viresh Kumar <[email protected]> wrote:
>>
>> On 14-12-23, 11:33, Brandon Cheo Fusi wrote:
>>> Add Kconfig file for cpufreq scaling drivers that can handle RISC-V
>>> CPUs. An entry is included for the Allwinner H6 cpufreq driver that
>>> works with D1.
>>>
>>> Signed-off-by: Brandon Cheo Fusi <[email protected]>
>>> ---
>>> drivers/cpufreq/Kconfig | 4 ++++
>>> drivers/cpufreq/Kconfig.riscv | 16 ++++++++++++++++
>>> 2 files changed, 20 insertions(+)
>>> create mode 100644 drivers/cpufreq/Kconfig.riscv
>>
>> We don't have a separate kconfig file for each architecture. Only if
>> there are too many entries for an architecture, we add a new file.
>>
>> --
>> viresh
>
> The sun50i cpufreq driver is currently only available when CONFIG_ARM or
> CONFIG_ARM64 is selected, so this was the only decent way I could think
> of making it accessible on either one of CONFIG_(ARM | ARM64 | RISC-V).
> Any suggestions for a better workaround ?

Move the option to the main drivers/cpufreq/Kconfig, like QORIQ_CPUFREQ,
which is also used with multiple architectures (PowerPC and ARM, in that
case). We don't want two options for the same driver.

Regards,
Samuel


2023-12-18 06:10:06

by Viresh Kumar

[permalink] [raw]
Subject: Re: [PATCH 4/5] cpufreq: Add support for RISC-V CPU Frequency scaling drivers

On 15-12-23, 15:09, Samuel Holland wrote:
> Move the option to the main drivers/cpufreq/Kconfig, like QORIQ_CPUFREQ,
> which is also used with multiple architectures (PowerPC and ARM, in that
> case). We don't want two options for the same driver.

+1

--
viresh