mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/4] hwmon: (adt7470) Add thermal framework support
@ 2026-07-16 21:21 Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470 Luiz Angelo Daros de Luca
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-16 21:21 UTC (permalink / raw)
  To: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley, de Luca
  Cc: linux-hwmon, devicetree, linux-kernel

The ADT7470 is a temperature monitor and PWM fan controller capable of
monitoring up to 10 external temperature sensors and controlling up to 4
PWM outputs.

Currently, the driver exposes these sensors and PWM controls solely via
the standard hwmon sysfs interface. This patch series integrates the
ADT7470 driver with the kernel's thermal subsystem, allowing its
temperature sensors to be referenced by Device Tree thermal zones.

To avoid saturating the I2C bus during frequent polling by the thermal
core, the thermal callbacks are designed to read from the driver's
internal cache.

Patch 1 adds the YAML device tree binding documentation, defining
the necessary #cooling-cells and #thermal-sensor-cells properties.
Patch 2 performs a minor refactoring to introduce the ADT7470_PWM_MAX
macro, replacing hardcoded values.
Patch 3 registers the 4 PWM channels as optional thermal cooling
devices.
Patch 4 registers the external temperature sensors as optional thermal
zones.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>

---
Luiz Angelo Daros de Luca (4):
      dt-bindings: hwmon: add binding for adi,adt7470
      hwmon: (adt7470) Add ADT7470_PWM_MAX macro
      hwmon: (adt7470) Add thermal cooling device support
      hwmon: (adt7470) Add thermal zone sensor support

 .../devicetree/bindings/hwmon/adi,adt7470.yaml     |  53 ++++++
 drivers/hwmon/adt7470.c                            | 180 ++++++++++++++++++++-
 2 files changed, 230 insertions(+), 3 deletions(-)
---
base-commit: ca078d004cf58137bcf8cb24a8b271397431ba58
change-id: 20260716-adt7470_thermalzone-59a102278d72

Best regards,
--  
Luiz Angelo Daros de Luca <luizluca@gmail.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470
  2026-07-16 21:21 [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Luiz Angelo Daros de Luca
@ 2026-07-16 21:21 ` Luiz Angelo Daros de Luca
  2026-07-17  2:33   ` Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 2/4] hwmon: (adt7470) Add ADT7470_PWM_MAX macro Luiz Angelo Daros de Luca
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-16 21:21 UTC (permalink / raw)
  To: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley, de Luca
  Cc: linux-hwmon, devicetree, linux-kernel

The Analog Devices ADT7470 is a temperature monitor and PWM fan
controller. It supports up to 10 external temperature sensors and
up to 4 PWM fan outputs.

Add the YAML device tree binding documentation for it. This includes
support for the thermal framework by defining the "#cooling-cells"
and "#thermal-sensor-cells" properties.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 .../devicetree/bindings/hwmon/adi,adt7470.yaml     | 53 ++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/Documentation/devicetree/bindings/hwmon/adi,adt7470.yaml b/Documentation/devicetree/bindings/hwmon/adi,adt7470.yaml
new file mode 100644
index 000000000000..e0c0fdadd1cf
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/adi,adt7470.yaml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/hwmon/adi,adt7470.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Analog Devices ADT7470 hwmon sensor
+
+maintainers:
+  - Luiz Angelo Daros de Luca <luizluca@gmail.com>
+
+description: |
+  The ADT7470 is a temperature monitor and multiple PWM outputs.
+  It supports monitoring up to 10 external temperature sensors and controlling
+  up to four fans.
+
+properties:
+  compatible:
+    const: adi,adt7470
+
+  reg:
+    maxItems: 1
+
+  "#cooling-cells":
+    const: 2
+    description: |
+      Cooling device exposing the 4 PWM channels.
+
+  "#thermal-sensor-cells":
+    const: 1
+    description: |
+      Number of cells required to uniquely identify the temperature sensors.
+      Valid index values are 0 to 9, corresponding to temp1 through temp10.
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        hwmon@2f {
+            compatible = "adi,adt7470";
+            reg = <0x2f>;
+            #cooling-cells = <2>;
+            #thermal-sensor-cells = <1>;
+        };
+    };

-- 
2.55.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/4] hwmon: (adt7470) Add ADT7470_PWM_MAX macro
  2026-07-16 21:21 [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470 Luiz Angelo Daros de Luca
@ 2026-07-16 21:21 ` Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 3/4] hwmon: (adt7470) Add thermal cooling device support Luiz Angelo Daros de Luca
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-16 21:21 UTC (permalink / raw)
  To: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley, de Luca
  Cc: linux-hwmon, devicetree, linux-kernel

Instead of a magic 255, use a macro to refer to it.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 drivers/hwmon/adt7470.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 664349756dc2..4ac292cd7f47 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -100,6 +100,7 @@ static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
 #define ADT7470_REG_FAN_MAX(x)	(ADT7470_REG_FAN_MAX_BASE_ADDR + ((x) * 2))
 
 #define ADT7470_PWM_COUNT	4
+#define ADT7470_PWM_MAX		255
 #define ADT7470_REG_PWM(x)	(ADT7470_REG_PWM_BASE_ADDR + (x))
 #define ADT7470_REG_PWM_MAX(x)	(ADT7470_REG_PWM_MAX_BASE_ADDR + (x))
 #define ADT7470_REG_PWM_MIN(x)	(ADT7470_REG_PWM_MIN_BASE_ADDR + (x))
@@ -811,7 +812,7 @@ static int adt7470_pwm_write(struct device *dev, u32 attr, int channel, long val
 
 	switch (attr) {
 	case hwmon_pwm_input:
-		val = clamp_val(val, 0, 255);
+		val = clamp_val(val, 0, ADT7470_PWM_MAX);
 		mutex_lock(&data->lock);
 		data->pwm[channel] = val;
 		err = regmap_write(data->regmap, ADT7470_REG_PWM(channel),
@@ -869,7 +870,7 @@ static ssize_t pwm_max_store(struct device *dev,
 	if (kstrtol(buf, 10, &temp))
 		return -EINVAL;
 
-	temp = clamp_val(temp, 0, 255);
+	temp = clamp_val(temp, 0, ADT7470_PWM_MAX);
 
 	mutex_lock(&data->lock);
 	data->pwm_max[attr->index] = temp;
@@ -904,7 +905,7 @@ static ssize_t pwm_min_store(struct device *dev,
 	if (kstrtol(buf, 10, &temp))
 		return -EINVAL;
 
-	temp = clamp_val(temp, 0, 255);
+	temp = clamp_val(temp, 0, ADT7470_PWM_MAX);
 
 	mutex_lock(&data->lock);
 	data->pwm_min[attr->index] = temp;

-- 
2.55.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 3/4] hwmon: (adt7470) Add thermal cooling device support
  2026-07-16 21:21 [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470 Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 2/4] hwmon: (adt7470) Add ADT7470_PWM_MAX macro Luiz Angelo Daros de Luca
@ 2026-07-16 21:21 ` Luiz Angelo Daros de Luca
  2026-07-16 21:21 ` [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support Luiz Angelo Daros de Luca
  2026-07-16 23:14 ` [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Guenter Roeck
  4 siblings, 0 replies; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-16 21:21 UTC (permalink / raw)
  To: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley, de Luca
  Cc: linux-hwmon, devicetree, linux-kernel

The ADT7470 has four PWM outputs that can be used to control fans.
Register each PWM output as an optional thermal cooling device via
Device Tree so it can be referenced by thermal zones.

When the thermal subsystem sets a cooling state, the driver switches
the corresponding PWM channel to manual mode so that the requested duty
cycle takes effect.

Registration is optional: when the "#cooling-cells" property is absent,
devm_thermal_of_child_cooling_device_register() returns -ENODEV and the
driver silently skips that PWM channel.

The PWM cache is populated with an explicit adt7470_update_sensors()
call before the cooling devices are registered, so that an early
get_cur_state() call from the thermal core does not observe stale
(zeroed) values.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 drivers/hwmon/adt7470.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)

diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index 4ac292cd7f47..b865f4bd50f8 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -22,6 +22,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/util_macros.h>
+#include <linux/thermal.h>
 
 /* Addresses to scan */
 static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
@@ -142,6 +143,13 @@ static const unsigned short normal_i2c[] = { 0x2C, 0x2E, 0x2F, I2C_CLIENT_END };
 #define ADT7470_FREQ_MASK	0x70
 #define ADT7470_FREQ_SHIFT	4
 
+struct adt7470_data;
+
+struct adt7470_cooling_device {
+	struct adt7470_data *data;
+	int pwm_index;
+};
+
 struct adt7470_data {
 	struct regmap		*regmap;
 	struct mutex		lock;
@@ -171,6 +179,8 @@ struct adt7470_data {
 
 	struct task_struct	*auto_update;
 	unsigned int		auto_update_interval;
+
+	struct adt7470_cooling_device cooling_devices[ADT7470_PWM_COUNT];
 };
 
 /*
@@ -846,6 +856,107 @@ static int adt7470_pwm_write(struct device *dev, u32 attr, int channel, long val
 	return err;
 }
 
+static int adt7470_get_max_state(struct thermal_cooling_device *cdev,
+				 unsigned long *state)
+{
+	*state = ADT7470_PWM_MAX;
+	return 0;
+}
+
+static int adt7470_get_cur_state(struct thermal_cooling_device *cdev,
+				 unsigned long *state)
+{
+	struct adt7470_cooling_device *cooling = cdev->devdata;
+	struct adt7470_data *data = cooling->data;
+
+	mutex_lock(&data->lock);
+	*state = data->pwm[cooling->pwm_index];
+	mutex_unlock(&data->lock);
+
+	return 0;
+}
+
+static int adt7470_set_cur_state(struct thermal_cooling_device *cdev,
+				 unsigned long state)
+{
+	struct adt7470_cooling_device *cooling = cdev->devdata;
+	struct adt7470_data *data = cooling->data;
+	unsigned int pwm_auto_reg_mask;
+	int err;
+
+	if (cooling->pwm_index & 1)
+		pwm_auto_reg_mask = ADT7470_PWM2_AUTO_MASK;
+	else
+		pwm_auto_reg_mask = ADT7470_PWM1_AUTO_MASK;
+
+	state = clamp_val(state, 0, ADT7470_PWM_MAX);
+
+	mutex_lock(&data->lock);
+
+	if (data->pwm[cooling->pwm_index] == state &&
+	    data->pwm_automatic[cooling->pwm_index] == 0) {
+		mutex_unlock(&data->lock);
+		return 0;
+	}
+
+	/* Put the PWM channel in manual mode before updating it. */
+	err = regmap_update_bits(data->regmap,
+				 ADT7470_REG_PWM_CFG(cooling->pwm_index),
+				 pwm_auto_reg_mask, 0);
+	if (err < 0)
+		goto out;
+
+	data->pwm_automatic[cooling->pwm_index] = 0;
+
+	err = regmap_write(data->regmap,
+			   ADT7470_REG_PWM(cooling->pwm_index), state);
+
+	if (err < 0)
+		goto out;
+
+	data->pwm[cooling->pwm_index] = state;
+out:
+	mutex_unlock(&data->lock);
+
+	return err;
+}
+
+static const struct thermal_cooling_device_ops adt7470_cooling_ops = {
+	.get_max_state = adt7470_get_max_state,
+	.get_cur_state = adt7470_get_cur_state,
+	.set_cur_state = adt7470_set_cur_state,
+};
+
+static int adt7470_register_cooling_devices(struct device *dev,
+					    struct adt7470_data *data)
+{
+	int i;
+
+	for (i = 0; i < ADT7470_PWM_COUNT; i++) {
+		struct thermal_cooling_device *cdev;
+		char cdev_name[THERMAL_NAME_LENGTH];
+
+		data->cooling_devices[i].data = data;
+		data->cooling_devices[i].pwm_index = i;
+
+		snprintf(cdev_name, sizeof(cdev_name), "adt7470-pwm%d", i);
+		cdev = devm_thermal_of_child_cooling_device_register(dev,
+								     dev->of_node, cdev_name,
+								     &data->cooling_devices[i],
+								     &adt7470_cooling_ops);
+
+		if (IS_ERR(cdev)) {
+			if (PTR_ERR(cdev) == -ENODEV)
+				continue;
+			return dev_warn_probe(dev, PTR_ERR(cdev),
+					      "failed to register cooling device %s\n",
+					      cdev_name);
+		}
+	}
+
+	return 0;
+}
+
 static ssize_t pwm_max_show(struct device *dev,
 			    struct device_attribute *devattr, char *buf)
 {
@@ -1281,6 +1392,17 @@ static int adt7470_probe(struct i2c_client *client)
 	if (IS_ERR(hwmon_dev))
 		return PTR_ERR(hwmon_dev);
 
+	if (IS_ENABLED(CONFIG_THERMAL)) {
+		/* fill the cache before registering the cooling devices */
+		err = adt7470_update_sensors(data);
+		if (err)
+			return err;
+
+		err = adt7470_register_cooling_devices(dev, data);
+		if (err)
+			return err;
+	}
+
 	data->auto_update = kthread_run(adt7470_update_thread, client, "%s",
 					dev_name(hwmon_dev));
 	if (IS_ERR(data->auto_update))

-- 
2.55.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support
  2026-07-16 21:21 [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Luiz Angelo Daros de Luca
                   ` (2 preceding siblings ...)
  2026-07-16 21:21 ` [PATCH 3/4] hwmon: (adt7470) Add thermal cooling device support Luiz Angelo Daros de Luca
@ 2026-07-16 21:21 ` Luiz Angelo Daros de Luca
  2026-07-16 23:12   ` Guenter Roeck
  2026-07-16 23:14 ` [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Guenter Roeck
  4 siblings, 1 reply; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-16 21:21 UTC (permalink / raw)
  To: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley, de Luca
  Cc: linux-hwmon, devicetree, linux-kernel

Expose the ADT7470 external temperature sensors to the thermal framework
via Device Tree. The thermal callbacks use the driver's cached sensor data,
avoiding any I2C bus traffic during frequent polling by the thermal core.

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
---
 drivers/hwmon/adt7470.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index b865f4bd50f8..44fe310f0650 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -150,6 +150,11 @@ struct adt7470_cooling_device {
 	int pwm_index;
 };
 
+struct adt7470_thermal_sensor {
+	struct adt7470_data *data;
+	int id;
+};
+
 struct adt7470_data {
 	struct regmap		*regmap;
 	struct mutex		lock;
@@ -181,6 +186,7 @@ struct adt7470_data {
 	unsigned int		auto_update_interval;
 
 	struct adt7470_cooling_device cooling_devices[ADT7470_PWM_COUNT];
+	struct adt7470_thermal_sensor thermal_sensors[ADT7470_TEMP_COUNT];
 };
 
 /*
@@ -957,6 +963,47 @@ static int adt7470_register_cooling_devices(struct device *dev,
 	return 0;
 }
 
+static int adt7470_get_temp(struct thermal_zone_device *tz, int *temp)
+{
+	struct adt7470_thermal_sensor *sensor = thermal_zone_device_priv(tz);
+	struct adt7470_data *data = sensor->data;
+
+	mutex_lock(&data->lock);
+	*temp = 1000 * data->temp[sensor->id];
+	mutex_unlock(&data->lock);
+
+	return 0;
+}
+
+static const struct thermal_zone_device_ops adt7470_thermal_ops = {
+	.get_temp = adt7470_get_temp,
+};
+
+static int adt7470_register_thermal_sensors(struct device *dev,
+					    struct adt7470_data *data)
+{
+	int i;
+
+	for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
+		struct thermal_zone_device *tz;
+
+		data->thermal_sensors[i].data = data;
+		data->thermal_sensors[i].id = i;
+
+		tz = devm_thermal_of_zone_register(dev, i, &data->thermal_sensors[i],
+						   &adt7470_thermal_ops);
+		if (IS_ERR(tz)) {
+			if (PTR_ERR(tz) == -ENODEV)
+				continue;
+			return dev_warn_probe(dev, PTR_ERR(tz),
+					      "failed to register thermal zone %d\n",
+					      i);
+		}
+	}
+
+	return 0;
+}
+
 static ssize_t pwm_max_show(struct device *dev,
 			    struct device_attribute *devattr, char *buf)
 {
@@ -1401,6 +1448,10 @@ static int adt7470_probe(struct i2c_client *client)
 		err = adt7470_register_cooling_devices(dev, data);
 		if (err)
 			return err;
+
+		err = adt7470_register_thermal_sensors(dev, data);
+		if (err)
+			return err;
 	}
 
 	data->auto_update = kthread_run(adt7470_update_thread, client, "%s",

-- 
2.55.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support
  2026-07-16 21:21 ` [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support Luiz Angelo Daros de Luca
@ 2026-07-16 23:12   ` Guenter Roeck
  2026-07-17  2:48     ` Luiz Angelo Daros de Luca
  0 siblings, 1 reply; 10+ messages in thread
From: Guenter Roeck @ 2026-07-16 23:12 UTC (permalink / raw)
  To: Luiz Angelo Daros de Luca, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-hwmon, devicetree, linux-kernel

On 7/16/26 14:21, Luiz Angelo Daros de Luca wrote:
> Expose the ADT7470 external temperature sensors to the thermal framework
> via Device Tree. The thermal callbacks use the driver's cached sensor data,
> avoiding any I2C bus traffic during frequent polling by the thermal core.
> 

Detailed explanation why HWMON_C_REGISTER_TZ does not work or is
insufficient goes here and into the driver code as comment.

Thanks,
Guenter

> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
> ---
>   drivers/hwmon/adt7470.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 51 insertions(+)
> 
> diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
> index b865f4bd50f8..44fe310f0650 100644
> --- a/drivers/hwmon/adt7470.c
> +++ b/drivers/hwmon/adt7470.c
> @@ -150,6 +150,11 @@ struct adt7470_cooling_device {
>   	int pwm_index;
>   };
>   
> +struct adt7470_thermal_sensor {
> +	struct adt7470_data *data;
> +	int id;
> +};
> +
>   struct adt7470_data {
>   	struct regmap		*regmap;
>   	struct mutex		lock;
> @@ -181,6 +186,7 @@ struct adt7470_data {
>   	unsigned int		auto_update_interval;
>   
>   	struct adt7470_cooling_device cooling_devices[ADT7470_PWM_COUNT];
> +	struct adt7470_thermal_sensor thermal_sensors[ADT7470_TEMP_COUNT];
>   };
>   
>   /*
> @@ -957,6 +963,47 @@ static int adt7470_register_cooling_devices(struct device *dev,
>   	return 0;
>   }
>   
> +static int adt7470_get_temp(struct thermal_zone_device *tz, int *temp)
> +{
> +	struct adt7470_thermal_sensor *sensor = thermal_zone_device_priv(tz);
> +	struct adt7470_data *data = sensor->data;
> +
> +	mutex_lock(&data->lock);
> +	*temp = 1000 * data->temp[sensor->id];
> +	mutex_unlock(&data->lock);
> +
> +	return 0;
> +}
> +
> +static const struct thermal_zone_device_ops adt7470_thermal_ops = {
> +	.get_temp = adt7470_get_temp,
> +};
> +
> +static int adt7470_register_thermal_sensors(struct device *dev,
> +					    struct adt7470_data *data)
> +{
> +	int i;
> +
> +	for (i = 0; i < ADT7470_TEMP_COUNT; i++) {
> +		struct thermal_zone_device *tz;
> +
> +		data->thermal_sensors[i].data = data;
> +		data->thermal_sensors[i].id = i;
> +
> +		tz = devm_thermal_of_zone_register(dev, i, &data->thermal_sensors[i],
> +						   &adt7470_thermal_ops);
> +		if (IS_ERR(tz)) {
> +			if (PTR_ERR(tz) == -ENODEV)
> +				continue;
> +			return dev_warn_probe(dev, PTR_ERR(tz),
> +					      "failed to register thermal zone %d\n",
> +					      i);
> +		}
> +	}
> +
> +	return 0;
> +}
> +
>   static ssize_t pwm_max_show(struct device *dev,
>   			    struct device_attribute *devattr, char *buf)
>   {
> @@ -1401,6 +1448,10 @@ static int adt7470_probe(struct i2c_client *client)
>   		err = adt7470_register_cooling_devices(dev, data);
>   		if (err)
>   			return err;
> +
> +		err = adt7470_register_thermal_sensors(dev, data);
> +		if (err)
> +			return err;
>   	}
>   
>   	data->auto_update = kthread_run(adt7470_update_thread, client, "%s",
> 


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] hwmon: (adt7470) Add thermal framework support
  2026-07-16 21:21 [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Luiz Angelo Daros de Luca
                   ` (3 preceding siblings ...)
  2026-07-16 21:21 ` [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support Luiz Angelo Daros de Luca
@ 2026-07-16 23:14 ` Guenter Roeck
  2026-07-16 23:19   ` Luiz Angelo Daros de Luca
  4 siblings, 1 reply; 10+ messages in thread
From: Guenter Roeck @ 2026-07-16 23:14 UTC (permalink / raw)
  To: Luiz Angelo Daros de Luca, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley
  Cc: linux-hwmon, devicetree, linux-kernel

On 7/16/26 14:21, Luiz Angelo Daros de Luca wrote:
> The ADT7470 is a temperature monitor and PWM fan controller capable of
> monitoring up to 10 external temperature sensors and controlling up to 4
> PWM outputs.
> 
> Currently, the driver exposes these sensors and PWM controls solely via
> the standard hwmon sysfs interface. This patch series integrates the
> ADT7470 driver with the kernel's thermal subsystem, allowing its
> temperature sensors to be referenced by Device Tree thermal zones.
> 
> To avoid saturating the I2C bus during frequent polling by the thermal
> core, the thermal callbacks are designed to read from the driver's
> internal cache.
> 
> Patch 1 adds the YAML device tree binding documentation, defining
> the necessary #cooling-cells and #thermal-sensor-cells properties.
> Patch 2 performs a minor refactoring to introduce the ADT7470_PWM_MAX
> macro, replacing hardcoded values.
> Patch 3 registers the 4 PWM channels as optional thermal cooling
> devices.
> Patch 4 registers the external temperature sensors as optional thermal
> zones.
> 
> Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>

This chip is 20+ years old, and it is very unlikely that it is used
in current designs. Please provide evidence that this code is actually
needed and not just a coding exercise.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/4] hwmon: (adt7470) Add thermal framework support
  2026-07-16 23:14 ` [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Guenter Roeck
@ 2026-07-16 23:19   ` Luiz Angelo Daros de Luca
  0 siblings, 0 replies; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-16 23:19 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-hwmon,
	devicetree, linux-kernel

> This chip is 20+ years old, and it is very unlikely that it is used
> in current designs. Please provide evidence that this code is actually
> needed and not just a coding exercise.

I understand. It is used in multiple Edgecore switches like ECS2100.
I'm preparing a port to OpenWrt.

https://github.com/luizluca/openwrt/commits/ecs2110/
https://forum.openwrt.org/t/add-support-for-edgecore-ecs2100-ecs4100-switches/251818/10

Regards,

Luiz

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470
  2026-07-16 21:21 ` [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470 Luiz Angelo Daros de Luca
@ 2026-07-17  2:33   ` Luiz Angelo Daros de Luca
  0 siblings, 0 replies; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-17  2:33 UTC (permalink / raw)
  To: Guenter Roeck, Rob Herring, Krzysztof Kozlowski, Conor Dooley, de Luca
  Cc: linux-hwmon, devicetree, linux-kernel

> +  "#cooling-cells":
> +    const: 2
> +    description: |
> +      Cooling device exposing the 4 PWM channels.

Since "thermal/of: Support cooling device ID in cooling-spec", I could
be 2 or 3. I don't know if I should use enum [2, 3] or just go
directly to the new const: 3.
My test device has only the 0 channel in use and 2 is fine for now.

Sashiko also asked to require #pwm-cells, but it would mean to
implement a parser for that too. I don't know if it is worth it but I
can do it if needed.
Regards,

Luiz

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support
  2026-07-16 23:12   ` Guenter Roeck
@ 2026-07-17  2:48     ` Luiz Angelo Daros de Luca
  0 siblings, 0 replies; 10+ messages in thread
From: Luiz Angelo Daros de Luca @ 2026-07-17  2:48 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-hwmon,
	devicetree, linux-kernel

> Detailed explanation why HWMON_C_REGISTER_TZ does not work or is
> insufficient goes here and into the driver code as comment.

No need to explain anything. I was just unaware of the existence of
HWMON_C_REGISTER_TZ.

You are absolutely right. I'll refactor the driver to use it and make
the code much cleaner. Thanks!

Regards,

Luiz

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-07-17  2:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-16 21:21 [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Luiz Angelo Daros de Luca
2026-07-16 21:21 ` [PATCH 1/4] dt-bindings: hwmon: add binding for adi,adt7470 Luiz Angelo Daros de Luca
2026-07-17  2:33   ` Luiz Angelo Daros de Luca
2026-07-16 21:21 ` [PATCH 2/4] hwmon: (adt7470) Add ADT7470_PWM_MAX macro Luiz Angelo Daros de Luca
2026-07-16 21:21 ` [PATCH 3/4] hwmon: (adt7470) Add thermal cooling device support Luiz Angelo Daros de Luca
2026-07-16 21:21 ` [PATCH 4/4] hwmon: (adt7470) Add thermal zone sensor support Luiz Angelo Daros de Luca
2026-07-16 23:12   ` Guenter Roeck
2026-07-17  2:48     ` Luiz Angelo Daros de Luca
2026-07-16 23:14 ` [PATCH 0/4] hwmon: (adt7470) Add thermal framework support Guenter Roeck
2026-07-16 23:19   ` Luiz Angelo Daros de Luca

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox