Add Device Tree nodes to enable a PWM controlled fan and it's associated
thermal management for the Lichee Pi 4A board.
This enables temperature-controlled active cooling for the Lichee Pi 4A
board based on SoC temperature.
Reviewed-by: Drew Fustini <fustini@kernel.org>
Tested-by: Drew Fustini <fustini@kernel.org>
Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com>
---
arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts | 67 +++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts
index 4020c727f09e8e2286fdc7fecd79dbd8eba69556..c58c2085ca92a3234f1350500cedae4157f0c35f 100644
--- a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts
+++ b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts
@@ -28,9 +28,76 @@ aliases {
chosen {
stdout-path = "serial0:115200n8";
};
+
+ thermal-zones {
+ cpu-thermal {
+ polling-delay = <1000>;
+ polling-delay-passive = <1000>;
+ thermal-sensors = <&pvt 0>;
+
+ trips {
+ fan_config0: fan-trip0 {
+ temperature = <39000>;
+ hysteresis = <5000>;
+ type = "active";
+ };
+
+ fan_config1: fan-trip1 {
+ temperature = <50000>;
+ hysteresis = <5000>;
+ type = "active";
+ };
+
+ fan_config2: fan-trip2 {
+ temperature = <60000>;
+ hysteresis = <5000>;
+ type = "active";
+ };
+ };
+
+ cooling-maps {
+ map-active-0 {
+ cooling-device = <&fan 1 1>;
+ trip = <&fan_config0>;
+ };
+
+ map-active-1 {
+ cooling-device = <&fan 2 2>;
+ trip = <&fan_config1>;
+ };
+
+ map-active-2 {
+ cooling-device = <&fan 3 3>;
+ trip = <&fan_config2>;
+ };
+ };
+ };
+ };
+
+ fan: pwm-fan {
+ pinctrl-names = "default";
+ pinctrl-0 = <&fan_pins>;
+ compatible = "pwm-fan";
+ #cooling-cells = <2>;
+ pwms = <&pwm 1 10000000 0>;
+ cooling-levels = <0 66 196 255>;
+ };
+
};
&padctrl0_apsys {
+ fan_pins: fan-0 {
+ pwm1-pins {
+ pins = "GPIO3_3"; /* PWM1 */
+ function = "pwm";
+ bias-disable;
+ drive-strength = <25>;
+ input-disable;
+ input-schmitt-disable;
+ slew-rate = <0>;
+ };
+ };
+
uart0_pins: uart0-0 {
tx-pins {
pins = "UART0_TXD";
--
2.34.1
On Wed, Aug 20, 2025 at 10:35:42AM +0200, Michal Wilczynski wrote: > Add Device Tree nodes to enable a PWM controlled fan and it's associated > thermal management for the Lichee Pi 4A board. > > This enables temperature-controlled active cooling for the Lichee Pi 4A > board based on SoC temperature. > > Reviewed-by: Drew Fustini <fustini@kernel.org> > Tested-by: Drew Fustini <fustini@kernel.org> > Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> > --- > arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts | 67 +++++++++++++++++++++++ > 1 file changed, 67 insertions(+) Do you think it makes sense to coordinate this with the "Initial thermal management for Lichee Pi 4A board" series [1] from Icenowy? Thanks, Drew [1] https://lore.kernel.org/linux-riscv/20250816093209.2600355-1-uwu@icenowy.me/
On 8/22/25 22:49, Drew Fustini wrote: > On Wed, Aug 20, 2025 at 10:35:42AM +0200, Michal Wilczynski wrote: >> Add Device Tree nodes to enable a PWM controlled fan and it's associated >> thermal management for the Lichee Pi 4A board. >> >> This enables temperature-controlled active cooling for the Lichee Pi 4A >> board based on SoC temperature. >> >> Reviewed-by: Drew Fustini <fustini@kernel.org> >> Tested-by: Drew Fustini <fustini@kernel.org> >> Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> >> --- >> arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts | 67 +++++++++++++++++++++++ >> 1 file changed, 67 insertions(+) > > Do you think it makes sense to coordinate this with the "Initial thermal > management for Lichee Pi 4A board" series [1] from Icenowy? Hi, It seems to me like using the HW PWM is just a better solution for driving the fans. However as pointed in the discussion currently Rust requires LLVM, so people compiling with gcc will not be able to compile the driver for some time until the gcc support becomes better. I think there is a way to express in Device Tree the fallback logic - if Rust not available then use SW PWM. So I guess the pragmatic way to go is to merge SW PWM temporary fix first, and later when gcc becomes better at compiling Rust patch it up to use HW PWM instead. > > Thanks, > Drew > > [1] https://lore.kernel.org/linux-riscv/20250816093209.2600355-1-uwu@icenowy.me/ > Best regards, -- Michal Wilczynski <m.wilczynski@samsung.com>
On Sat, Aug 23, 2025 at 12:14 PM Michal Wilczynski <m.wilczynski@samsung.com> wrote: > > However as pointed in the discussion currently Rust > requires LLVM, so people compiling with gcc will not be able to compile > the driver for some time until the gcc support becomes better. In case it helps/clarifies: the C side can be built with GCC (i.e. building without `LLVM=1`, with Rust using its LLVM backend), but it is a best-effort hack and the goal is to eventually use `rustc_codegen_gcc` and/or GCC Rust. Some users/distributions use it nevertheless. Cheers, Miguel
On 8/23/25 12:13, Michal Wilczynski wrote: > > > On 8/22/25 22:49, Drew Fustini wrote: >> On Wed, Aug 20, 2025 at 10:35:42AM +0200, Michal Wilczynski wrote: >>> Add Device Tree nodes to enable a PWM controlled fan and it's associated >>> thermal management for the Lichee Pi 4A board. >>> >>> This enables temperature-controlled active cooling for the Lichee Pi 4A >>> board based on SoC temperature. >>> >>> Reviewed-by: Drew Fustini <fustini@kernel.org> >>> Tested-by: Drew Fustini <fustini@kernel.org> >>> Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> >>> --- >>> arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts | 67 +++++++++++++++++++++++ >>> 1 file changed, 67 insertions(+) >> >> Do you think it makes sense to coordinate this with the "Initial thermal >> management for Lichee Pi 4A board" series [1] from Icenowy? > > Hi, > It seems to me like using the HW PWM is just a better solution for > driving the fans. However as pointed in the discussion currently Rust > requires LLVM, so people compiling with gcc will not be able to compile > the driver for some time until the gcc support becomes better. > > I think there is a way to express in Device Tree the fallback logic - Sorry I meant 'there is NO way to express this in Device tree' > if Rust not available then use SW PWM. So I guess the pragmatic way to > go is to merge SW PWM temporary fix first, and later when gcc becomes > better at compiling Rust patch it up to use HW PWM instead. > >> >> Thanks, >> Drew >> >> [1] https://lore.kernel.org/linux-riscv/20250816093209.2600355-1-uwu@icenowy.me/ >> > > Best regards, Best regards, -- Michal Wilczynski <m.wilczynski@samsung.com>
On Wed, Aug 20, 2025 at 10:35:42AM +0200, Michal Wilczynski wrote: > Add Device Tree nodes to enable a PWM controlled fan and it's associated > thermal management for the Lichee Pi 4A board. > > This enables temperature-controlled active cooling for the Lichee Pi 4A > board based on SoC temperature. > > Reviewed-by: Drew Fustini <fustini@kernel.org> > Tested-by: Drew Fustini <fustini@kernel.org> > Signed-off-by: Michal Wilczynski <m.wilczynski@samsung.com> > --- > arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts | 67 +++++++++++++++++++++++ > 1 file changed, 67 insertions(+) > > diff --git a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts > index 4020c727f09e8e2286fdc7fecd79dbd8eba69556..c58c2085ca92a3234f1350500cedae4157f0c35f 100644 > --- a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts > +++ b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts > @@ -28,9 +28,76 @@ aliases { > chosen { > stdout-path = "serial0:115200n8"; > }; > + > + thermal-zones { > + cpu-thermal { > + polling-delay = <1000>; > + polling-delay-passive = <1000>; > + thermal-sensors = <&pvt 0>; > + > + trips { > + fan_config0: fan-trip0 { > + temperature = <39000>; > + hysteresis = <5000>; > + type = "active"; > + }; > + > + fan_config1: fan-trip1 { > + temperature = <50000>; > + hysteresis = <5000>; > + type = "active"; > + }; > + > + fan_config2: fan-trip2 { > + temperature = <60000>; > + hysteresis = <5000>; > + type = "active"; > + }; > + }; > + > + cooling-maps { > + map-active-0 { > + cooling-device = <&fan 1 1>; > + trip = <&fan_config0>; > + }; > + > + map-active-1 { > + cooling-device = <&fan 2 2>; > + trip = <&fan_config1>; > + }; > + > + map-active-2 { > + cooling-device = <&fan 3 3>; > + trip = <&fan_config2>; > + }; > + }; > + }; > + }; > + > + fan: pwm-fan { > + pinctrl-names = "default"; > + pinctrl-0 = <&fan_pins>; > + compatible = "pwm-fan"; > + #cooling-cells = <2>; > + pwms = <&pwm 1 10000000 0>; > + cooling-levels = <0 66 196 255>; > + }; > + > }; > > &padctrl0_apsys { > + fan_pins: fan-0 { > + pwm1-pins { > + pins = "GPIO3_3"; /* PWM1 */ > + function = "pwm"; > + bias-disable; > + drive-strength = <25>; > + input-disable; > + input-schmitt-disable; > + slew-rate = <0>; > + }; > + }; > + > uart0_pins: uart0-0 { > tx-pins { > pins = "UART0_TXD"; > > -- > 2.34.1 Reviewed-by: Elle Rhumsaa <elle@weathered-steel.dev>
© 2016 - 2025 Red Hat, Inc.