[PATCH v4 3/5] thermal/drivers/generic-adc: Allow probe without TZ registration
From: Luca Weiss
Date: Tue Nov 17 2026 - 03:25:32 EST
If the devicetree node is not referenced in a zone under /thermal-zones,
devm_thermal_of_zone_register() will fail with -ENODEV.
Since the driver is now also registering as an IIO device[0], allow the
probe to continue without the thermal zone.
We also can't use gadc_thermal_get_temp() anymore because we haven't
necessarily initialized tz_dev.
Link: https://git.kernel.org/torvalds/c/3762f5851ac5 [0]
Signed-off-by: Luca Weiss <luca.weiss@xxxxxxxxxxxxx>
---
drivers/thermal/thermal-generic-adc.c | 27 +++++++++++++++------------
1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
index c6a7a65aa6a6..b73cd47bffa6 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -55,9 +55,8 @@ static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
return temp;
}
-static int gadc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
+static int gadc_thermal_iio_to_temp(struct gadc_thermal_info *gti, int *temp)
{
- struct gadc_thermal_info *gti = thermal_zone_device_priv(tz);
int val;
int ret;
@@ -70,6 +69,13 @@ static int gadc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
return 0;
}
+static int gadc_thermal_get_temp(struct thermal_zone_device *tz, int *temp)
+{
+ struct gadc_thermal_info *gti = thermal_zone_device_priv(tz);
+
+ return gadc_thermal_iio_to_temp(gti, temp);
+}
+
static const struct thermal_zone_device_ops gadc_thermal_ops = {
.get_temp = gadc_thermal_get_temp,
};
@@ -90,7 +96,7 @@ static int gadc_thermal_read_raw(struct iio_dev *indio_dev,
switch (mask) {
case IIO_CHAN_INFO_PROCESSED:
- ret = gadc_thermal_get_temp(gtinfo->tz_dev, val);
+ ret = gadc_thermal_iio_to_temp(gtinfo, val);
if (ret)
return ret;
@@ -193,16 +199,13 @@ static int gadc_thermal_probe(struct platform_device *pdev)
gti->tz_dev = devm_thermal_of_zone_register(dev, 0, gti,
&gadc_thermal_ops);
- if (IS_ERR(gti->tz_dev)) {
- ret = PTR_ERR(gti->tz_dev);
- if (ret != -EPROBE_DEFER)
- dev_err(dev,
- "Thermal zone sensor register failed: %d\n",
- ret);
+ ret = PTR_ERR_OR_ZERO(gti->tz_dev);
+ if (ret == -ENODEV)
+ dev_dbg(dev, "Thermal zone sensor register failed: %d\n", ret);
+ else if (ret)
return ret;
- }
-
- devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
+ else
+ devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
return gadc_iio_register(&pdev->dev, gti);
}
--
2.56.1