1 # --- T2-COPYRIGHT-BEGIN ---
2 # t2/package/*/linux/riscv-unmatched-fans.patch
3 # Copyright (C) 2021 - 2025 The T2 SDE Project
4 # SPDX-License-Identifier: GPL-2.0 or patched project license
5 # --- T2-COPYRIGHT-END ---
7 Let's implement some minimal viable HiFive Unmatched PWM fan control.
9 Signed-off-by: René Rebe <rene@exactcode.com>
11 --- ./arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts.vanilla 2024-04-01 18:58:55.930393689 +0200
12 +++ ./arch/riscv/boot/dts/sifive/hifive-unmatched-a00.dts 2024-04-01 20:32:34.682852300 +0200
14 gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
18 + compatible = "pwm-fan";
19 + pwms = <&pwm1 2 7812500 PWM_POLARITY_INVERTED>;
24 + compatible = "pwm-fan";
25 + pwms = <&pwm1 3 7812500 PWM_POLARITY_INVERTED>;
30 compatible = "pwm-leds";
32 --- linux-6.13/drivers/hwmon/pwm-fan.c.vanilla 2025-02-03 11:42:43.909573585 +0100
33 +++ linux-6.13/drivers/hwmon/pwm-fan.c 2025-02-03 11:44:47.423592732 +0100
35 enum pwm_fan_enable_mode enable_mode;
36 bool regulator_enabled;
41 struct pwm_fan_tach *tachs;
46 state->duty_cycle = DIV_ROUND_UP(pwm * (period - 1), MAX_PWM);
47 + if (ctx->active_low)
48 + state->duty_cycle = state->period - state->duty_cycle;
50 usleep_range(ctx->pwm_usec_from_stopped,
51 ctx->pwm_usec_from_stopped * 2);
52 ret = pwm_apply_might_sleep(ctx->pwm, state);
55 struct thermal_cooling_device *cdev;
56 struct device *dev = &pdev->dev;
57 + struct device_node *np = dev->of_node;
58 struct pwm_fan_ctx *ctx;
64 ctx->enable_mode = pwm_disable_reg_enable;
65 + ctx->active_low = of_property_read_bool(np, "active-low");
68 * Set duty cycle to maximum allowed and enable PWM output as well as