* improve similar pkg suggestions and share code in core-functions for all scripts...
[t2sde.git] / package / kernel / linux / riscv-unmatched-fans.patch
blobef0aeed773da35c974546afa2510e0362e8bfe83
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
13 @@ -47,6 +47,18 @@
14 gpios = <&gpio 2 GPIO_ACTIVE_LOW>;
17 + fan1 {
18 + compatible = "pwm-fan";
19 + pwms = <&pwm1 2 7812500 PWM_POLARITY_INVERTED>;
20 + active-low;
21 + };
23 + fan2 {
24 + compatible = "pwm-fan";
25 + pwms = <&pwm1 3 7812500 PWM_POLARITY_INVERTED>;
26 + active-low;
27 + };
29 led-controller-1 {
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
34 @@ -45,6 +45,7 @@
35 enum pwm_fan_enable_mode enable_mode;
36 bool regulator_enabled;
37 bool enabled;
38 + bool active_low;
40 int tach_count;
41 struct pwm_fan_tach *tachs;
43 @@ -227,6 +227,9 @@
44 if (!ret && update) {
45 pwm = final_pwm;
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);
53 @@ -476,6 +480,7 @@
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;
59 struct device *hwmon;
60 int ret;
61 @@ -526,6 +532,7 @@
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