On Sun, Dec 05, 2021 at 12:41:34AM +0100, Christopher Zimmermann wrote:
> Hi,
> 
> pwmfan0 doesn't attach on RockPro64 because there are no cooling levels
> defined in the device tree:
> 
> pwmfan0 at mainbus0: no cooling levels
> 
> Also the dtb thermal zone does not care about the fan.
> 
> I added the cooling levels and tried to overwrite the default rk3399.dtsi
> thermal zone in rk3399-rockpro64.dtsi.
> 
> This seems to work pretty well now.
> 
> OK?

A related change exists since linux 5.16-rc1

commit d09ebc6ba9ccb9b36fb860b5239d488edc794dcb
Author: Peter Geis <pgwipe...@gmail.com>
Date:   Fri Jul 30 11:17:27 2021 -0400

    arm64: dts: rockchip: add thermal fan control to rockpro64
    
    The rockpro64 had a fan node since
    commit 5882d65c1691 ("arm64: dts: rockchip: Add PWM fan for RockPro64")
    however it was never tied into the thermal driver for automatic control.
    
    Add the links to the thermal node to permit the kernel to handle this
    automatically.
    Borrowed from the (rk3399-khadas-edge.dtsi).
    
    Signed-off-by: Peter Geis <pgwipe...@gmail.com>
    Link: https://lore.kernel.org/r/20210730151727.729822-1-pgwipe...@gmail.com
    Signed-off-by: Heiko Stuebner <he...@sntech.de>

diff --git a/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi 
b/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
index 6bff8db7d33e..83db4ca67334 100644
--- a/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
+++ b/arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
@@ -69,6 +69,7 @@ diy_led: led-1 {
 
        fan: pwm-fan {
                compatible = "pwm-fan";
+               cooling-levels = <0 100 150 200 255>;
                #cooling-cells = <2>;
                fan-supply = <&vcc12v_dcin>;
                pwms = <&pwm1 0 50000 0>;
@@ -245,6 +246,34 @@ &cpu_b1 {
        cpu-supply = <&vdd_cpu_b>;
 };
 
+&cpu_thermal {
+       trips {
+               cpu_warm: cpu_warm {
+                       temperature = <55000>;
+                       hysteresis = <2000>;
+                       type = "active";
+               };
+
+               cpu_hot: cpu_hot {
+                       temperature = <65000>;
+                       hysteresis = <2000>;
+                       type = "active";
+               };
+       };
+
+       cooling-maps {
+               map2 {
+                       trip = <&cpu_warm>;
+                       cooling-device = <&fan THERMAL_NO_LIMIT 1>;
+               };
+
+               map3 {
+                       trip = <&cpu_hot>;
+                       cooling-device = <&fan 2 THERMAL_NO_LIMIT>;
+               };
+       };
+};
+
 &emmc_phy {
        status = "okay";
 };

> 
> To me it seems a bit impractical to hardcode cooling levels because
> different fans might react differently.
> 
> Would it be a good idea to add a r/w sysctl knob for each cooling device ?
> Or maybo only for cooling devices which are fans?
> 
> 
> Christopher
> 
> 
> Index: patch-arch_arm64_boot_dts_rockchip_rk3399-rockpro64_dtsi
> ===================================================================
> RCS file: 
> /cvs/ports/sysutils/dtb/patches/patch-arch_arm64_boot_dts_rockchip_rk3399-rockpro64_dtsi,v
> retrieving revision 1.1
> diff -u -p -r1.1 patch-arch_arm64_boot_dts_rockchip_rk3399-rockpro64_dtsi
> --- patch-arch_arm64_boot_dts_rockchip_rk3399-rockpro64_dtsi  12 Apr 2020 
> 10:59:07 -0000      1.1
> +++ patch-arch_arm64_boot_dts_rockchip_rk3399-rockpro64_dtsi  4 Dec 2021 
> 23:25:06 -0000
> @@ -3,12 +3,99 @@ $OpenBSD: patch-arch_arm64_boot_dts_rock
>  Index: arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
>  --- arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi.orig
>  +++ arch/arm64/boot/dts/rockchip/rk3399-rockpro64.dtsi
> -@@ -11,7 +11,7 @@
> +@@ -17,7 +17,7 @@
> +     };
> - / {
>       chosen {
>  -            stdout-path = "serial2:1500000n8";
>  +            stdout-path = "serial2:115200n8";
>       };
>       clkin_gmac: external-gmac-clock {
> +@@ -71,9 +71,86 @@
> +             compatible = "pwm-fan";
> +             #cooling-cells = <2>;
> +             fan-supply = <&vcc12v_dcin>;
> ++            cooling-levels = <0 50 70 90 255>;
> +             pwms = <&pwm1 0 50000 0>;
> +     };
> + ++  thermal_zones: thermal-zones {
> ++            cpu_thermal: cpu-thermal {
> ++                    polling-delay-passive = <100>;
> ++                    polling-delay = <1000>;
> ++
> ++                    thermal-sensors = <&tsadc 0>;
> ++
> ++                    trips {
> ++                            cpu_alert0: cpu_alert0 {
> ++                                    temperature = <40000>;
> ++                                    hysteresis = <2000>;
> ++                                    type = "passive";
> ++                            };
> ++                            cpu_alert1: cpu_alert1 {
> ++                                    temperature = <75000>;
> ++                                    hysteresis = <2000>;
> ++                                    type = "passive";
> ++                            };
> ++                            cpu_crit: cpu_crit {
> ++                                    temperature = <95000>;
> ++                                    hysteresis = <2000>;
> ++                                    type = "critical";
> ++                            };
> ++                    };
> ++
> ++                    cooling-maps {
> ++                            map0 {
> ++                                    trip = <&cpu_alert0>;
> ++                                    cooling-device =
> ++                                            <&fan 1 3>,
> ++                                            <&cpu_b0 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>,
> ++                                            <&cpu_b1 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>;
> ++
> ++                            };
> ++                            map1 {
> ++                                    trip = <&cpu_alert1>;
> ++                                    cooling-device =
> ++                                            <&fan 4 THERMAL_NO_LIMIT>,
> ++                                            <&cpu_l0 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>,
> ++                                            <&cpu_l1 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>,
> ++                                            <&cpu_l2 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>,
> ++                                            <&cpu_l3 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>,
> ++                                            <&cpu_b0 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>,
> ++                                            <&cpu_b1 THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>;
> ++                            };
> ++                    };
> ++            };
> ++
> ++            gpu_thermal: gpu-thermal {
> ++                    polling-delay-passive = <100>;
> ++                    polling-delay = <1000>;
> ++
> ++                    thermal-sensors = <&tsadc 1>;
> ++
> ++                    trips {
> ++                            gpu_alert0: gpu_alert0 {
> ++                                    temperature = <75000>;
> ++                                    hysteresis = <2000>;
> ++                                    type = "passive";
> ++                            };
> ++                            gpu_crit: gpu_crit {
> ++                                    temperature = <95000>;
> ++                                    hysteresis = <2000>;
> ++                                    type = "critical";
> ++                            };
> ++                    };
> ++
> ++                    cooling-maps {
> ++                            map0 {
> ++                                    trip = <&gpu_alert0>;
> ++                                    cooling-device =
> ++                                            <&gpu THERMAL_NO_LIMIT 
> THERMAL_NO_LIMIT>;
> ++                            };
> ++                    };
> ++            };
> ++    };
> +     sdio_pwrseq: sdio-pwrseq {
> +             compatible = "mmc-pwrseq-simple";
> +             clocks = <&rk808 1>;
> 
> 

Reply via email to