Skip to content

Commit 574b922

Browse files
luizlucajonasjelonek
authored andcommitted
kernel: backport adt7470 PWM/thermal support from v7.3
Backport a series of upstream patches for the adt7470 hwmon driver, accepted for kernel v7.3. It exposes the fan control lines via the generic PWM framework and thermal zone sensors. Instead of relying on userland scripts, the kernel can now control the fan speed directly through standard cooling maps and PWM fans configured in the DTS. Currently in the tree, only edgecore_ecs4100-12ph seems to use this chip. Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com> Link: openwrt#24803 Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
1 parent d9f4284 commit 574b922

8 files changed

Lines changed: 463 additions & 4 deletions

target/linux/bcm27xx/patches-6.18/0310-hwmon-Add-RP1-ADC-and-temperature-driver.patch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
2121

2222
--- a/drivers/hwmon/Kconfig
2323
+++ b/drivers/hwmon/Kconfig
24-
@@ -2663,6 +2663,13 @@ config SENSORS_INTEL_M10_BMC_HWMON
24+
@@ -2664,6 +2664,13 @@ config SENSORS_INTEL_M10_BMC_HWMON
2525
sensors monitor various telemetry data of different components on the
2626
card, e.g. board temperature, FPGA core temperature/voltage/current.
2727

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
From 9f446d82bdbcea89c2795a8a6ce7a7c2cac02129 Mon Sep 17 00:00:00 2001
2+
From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
3+
Date: Wed, 5 Aug 2026 10:15:17 -0300
4+
Subject: [PATCH 1/4] dt-bindings: hwmon: add adi,adt7470
5+
6+
The Analog Devices ADT7470 is a multichannel temperature sensor and
7+
PWM fan controller. It supports monitoring up to 10 external
8+
temperature sensors and controlling up to 4 fans.
9+
10+
Add the device tree binding documentation for it. This includes
11+
support for the thermal framework by defining the "#thermal-sensor-cells"
12+
property, and models the fan control lines as PWM channels by
13+
defining the "#pwm-cells" property.
14+
15+
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
16+
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
17+
Link: https://lore.kernel.org/r/20260805-adt7470_thermalzone-v6-1-5605a5f95467@gmail.com
18+
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
19+
---
20+
.../bindings/hwmon/adi,adt7470.yaml | 58 +++++++++++++++++++
21+
1 file changed, 58 insertions(+)
22+
create mode 100644 Documentation/devicetree/bindings/hwmon/adi,adt7470.yaml
23+
24+
--- /dev/null
25+
+++ b/Documentation/devicetree/bindings/hwmon/adi,adt7470.yaml
26+
@@ -0,0 +1,58 @@
27+
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
28+
+%YAML 1.2
29+
+---
30+
+$id: http://devicetree.org/schemas/hwmon/adi,adt7470.yaml#
31+
+$schema: http://devicetree.org/meta-schemas/core.yaml#
32+
+
33+
+title: Analog Devices ADT7470 hwmon sensor
34+
+
35+
+maintainers:
36+
+ - Luiz Angelo Daros de Luca <luizluca@gmail.com>
37+
+
38+
+description:
39+
+ Multi-channel temperature monitor and PWM fan controller.
40+
+ It supports monitoring up to 10 external temperature sensors and
41+
+ controlling up to 4 fans. The fan control lines are modeled
42+
+ as standard PWM channels.
43+
+
44+
+properties:
45+
+ compatible:
46+
+ const: adi,adt7470
47+
+
48+
+ reg:
49+
+ maxItems: 1
50+
+
51+
+ "#pwm-cells":
52+
+ const: 3
53+
+
54+
+ "#thermal-sensor-cells":
55+
+ const: 1
56+
+ description:
57+
+ Valid index values are 0 to 9, corresponding to temp1 through temp10.
58+
+
59+
+required:
60+
+ - compatible
61+
+ - reg
62+
+
63+
+allOf:
64+
+ - if:
65+
+ required:
66+
+ - "#thermal-sensor-cells"
67+
+ then:
68+
+ $ref: /schemas/thermal/thermal-sensor.yaml#
69+
+
70+
+unevaluatedProperties: false
71+
+
72+
+examples:
73+
+ - |
74+
+ i2c {
75+
+ #address-cells = <1>;
76+
+ #size-cells = <0>;
77+
+
78+
+ hwmon@2f {
79+
+ compatible = "adi,adt7470";
80+
+ reg = <0x2f>;
81+
+ #pwm-cells = <3>;
82+
+ #thermal-sensor-cells = <1>;
83+
+ };
84+
+ };
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
From bdec2083b9d8a4a29b717686e573e7113f8d9470 Mon Sep 17 00:00:00 2001
2+
From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
3+
Date: Wed, 5 Aug 2026 10:15:18 -0300
4+
Subject: [PATCH 2/4] hwmon: (adt7470) Add ADT7470_PWM_MAX macro
5+
6+
Instead of a magic 255, use a macro to refer to it.
7+
8+
Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
9+
Link: https://lore.kernel.org/r/20260805-adt7470_thermalzone-v6-2-5605a5f95467@gmail.com
10+
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
11+
---
12+
drivers/hwmon/adt7470.c | 7 ++++---
13+
1 file changed, 4 insertions(+), 3 deletions(-)
14+
15+
--- a/drivers/hwmon/adt7470.c
16+
+++ b/drivers/hwmon/adt7470.c
17+
@@ -100,6 +100,7 @@ static const unsigned short normal_i2c[]
18+
#define ADT7470_REG_FAN_MAX(x) (ADT7470_REG_FAN_MAX_BASE_ADDR + ((x) * 2))
19+
20+
#define ADT7470_PWM_COUNT 4
21+
+#define ADT7470_PWM_MAX 255
22+
#define ADT7470_REG_PWM(x) (ADT7470_REG_PWM_BASE_ADDR + (x))
23+
#define ADT7470_REG_PWM_MAX(x) (ADT7470_REG_PWM_MAX_BASE_ADDR + (x))
24+
#define ADT7470_REG_PWM_MIN(x) (ADT7470_REG_PWM_MIN_BASE_ADDR + (x))
25+
@@ -850,7 +851,7 @@ static int adt7470_pwm_write(struct devi
26+
27+
switch (attr) {
28+
case hwmon_pwm_input:
29+
- val = clamp_val(val, 0, 255);
30+
+ val = clamp_val(val, 0, ADT7470_PWM_MAX);
31+
mutex_lock(&data->lock);
32+
err = regmap_write(data->regmap, ADT7470_REG_PWM(channel),
33+
val);
34+
@@ -910,7 +911,7 @@ static ssize_t pwm_max_store(struct devi
35+
if (kstrtol(buf, 10, &temp))
36+
return -EINVAL;
37+
38+
- temp = clamp_val(temp, 0, 255);
39+
+ temp = clamp_val(temp, 0, ADT7470_PWM_MAX);
40+
41+
mutex_lock(&data->lock);
42+
data->pwm_max[attr->index] = temp;
43+
@@ -945,7 +946,7 @@ static ssize_t pwm_min_store(struct devi
44+
if (kstrtol(buf, 10, &temp))
45+
return -EINVAL;
46+
47+
- temp = clamp_val(temp, 0, 255);
48+
+ temp = clamp_val(temp, 0, ADT7470_PWM_MAX);
49+
50+
mutex_lock(&data->lock);
51+
data->pwm_min[attr->index] = temp;

0 commit comments

Comments
 (0)