# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/linux/sifive-fans.patch.disabled # Copyright (C) 2021 - 2022 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License version 2 as used by the T2 SDE. # --- T2-COPYRIGHT-NOTE-END --- Let's implement some minimal viable HiFive Unmatched PWM fan control. Signed-off-by: René Rebe --- ./arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts.vanilla 2024-04-01 18:58:55.930393689 +0200 +++ ./arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts 2024-04-01 20:32:34.682852300 +0200 @@ -47,6 +47,18 @@ gpios = <&gpio 2 GPIO_ACTIVE_LOW>; }; + fan1 { + compatible = "pwm-fan"; + pwms = <&pwm1 2 7812500 PWM_POLARITY_INVERTED>; + active-low; + }; + + fan2 { + compatible = "pwm-fan"; + pwms = <&pwm1 3 7812500 PWM_POLARITY_INVERTED>; + active-low; + }; + led-controller-1 { compatible = "pwm-leds"; --- ./drivers/hwmon/pwm-fan.c.vanilla 2024-04-01 20:38:04.170820553 +0200 +++ ./drivers/hwmon/pwm-fan.c 2024-04-01 20:57:57.418705578 +0200 @@ -45,6 +45,7 @@ enum pwm_fan_enable_mode enable_mode; bool regulator_enabled; bool enabled; + bool active_low; int tach_count; struct pwm_fan_tach *tachs; @@ -207,6 +208,9 @@ period = state->period; state->duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM); + if (ctx->active_low) + state->duty_cycle = state->period - state->duty_cycle; + ret = pwm_apply_might_sleep(ctx->pwm, state); if (ret) return ret; @@ -476,6 +480,7 @@ { struct thermal_cooling_device *cdev; struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; struct pwm_fan_ctx *ctx; struct device *hwmon; int ret; @@ -526,6 +532,7 @@ } ctx->enable_mode = pwm_disable_reg_enable; + ctx->active_low = of_property_read_bool(np, "active-low"); /* * Set duty cycle to maximum allowed and enable PWM output as well as