From: "Davíð Steinn Geirsson" <david@dsg.is>
To: Guenter Roeck <linux@roeck-us.net>,
Jean Delvare <jdelvare@suse.com>,
linux-hwmon@vger.kernel.org
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
devicetree@vger.kernel.org,
"Uwe Kleine-König" <ukleinek@kernel.org>,
linux-pwm@vger.kernel.org, "Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Randy Dunlap" <rdunlap@infradead.org>,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
"Davíð Steinn Geirsson" <david@dsg.is>
Subject: [PATCH 3/4] hwmon: (adt7475) Add thermal zone sensor support
Date: Sat, 14 Nov 2026 00:41:09 +0000 [thread overview]
Message-ID: <20261114004110.328050-4-david@dsg.is> (raw)
In-Reply-To: <20261114004110.328050-1-david@dsg.is>
Register the temperature channels as thermal zone sensors. Sensor id N
is temperature channel N, i.e. temp(N+1). Document this in adt7475.rst.
The hwmon core reads a sensor's temperature while registering the
thermal zone, from within hwmon_device_register_with_info(). Read the
chip limits before registering, so that the temperature encoding
(CONFIG5 two's complement bit) is known for that first read.
With CONFIG_THERMAL_OF, devices that have a devicetree node, or sit
below one (the hwmon core uses the nearest ancestor's node), see two
changes:
- Each temperature channel that no thermal zone uses logs
"tempN_input not attached to any thermal zone" once at probe.
- When a thermal zone uses a channel, the hwmon core sets that
channel's min and max limit registers to the zone's current trip
window, as it does for other drivers registering thermal sensors.
Signed-off-by: Davíð Steinn Geirsson <david@dsg.is>
---
This patch was written with Claude Code, using the models Claude
Opus 5.5 and Claude Fable 5.2. They wrote the code and the initial
commit message draft, which I cleaned up. I directed the design,
reviewed the result, compared against the datasheet as far as I
could, and ran tests including on actual hardware.
Documentation/hwmon/adt7475.rst | 3 +++
drivers/hwmon/adt7475.c | 17 ++++++++++++-----
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/Documentation/hwmon/adt7475.rst b/Documentation/hwmon/adt7475.rst
index f90f769d82d6..b5976e3ff3d4 100644
--- a/Documentation/hwmon/adt7475.rst
+++ b/Documentation/hwmon/adt7475.rst
@@ -118,6 +118,9 @@ with a resolution of 0.25 degree Celsius. Temperature readings can be
configured either for two's complement format or "Offset 64" format,
wherein 64 is subtracted from the raw value to get the temperature value.
+With ``#thermal-sensor-cells = <1>`` in the device node, thermal sensor id N
+is temperature channel N, reported as temp(N+1).
+
The datasheet is very detailed and describes a procedure for determining
an optimal configuration for the automatic PWM control.
diff --git a/drivers/hwmon/adt7475.c b/drivers/hwmon/adt7475.c
index d5bdb8011e6d..73c19c10bb34 100644
--- a/drivers/hwmon/adt7475.c
+++ b/drivers/hwmon/adt7475.c
@@ -1243,6 +1243,9 @@ static const struct hwmon_ops adt7475_hwmon_ops = {
HWMON_PWM_FREQ | HWMON_PWM_AUTO_CHANNELS_TEMP)
static const struct hwmon_channel_info * const adt7475_info[] = {
+ /* The hwmon core only looks for HWMON_C_REGISTER_TZ in info[0] */
+ HWMON_CHANNEL_INFO(chip,
+ HWMON_C_REGISTER_TZ),
HWMON_CHANNEL_INFO(in,
ADT7475_IN_CONFIG, /* in0: +2.5V */
ADT7475_IN_CONFIG, /* in1: Vccp */
@@ -1928,6 +1931,15 @@ static int adt7475_probe(struct i2c_client *client)
break;
}
+ /*
+ * Read the limits and settings once, before registering: the hwmon
+ * core reads the thermal sensors while registering, and that needs
+ * the temperature encoding from CONFIG5.
+ */
+ ret = adt7475_update_limits(client);
+ if (ret)
+ return ret;
+
data->groups[group_num++] = &adt7475_attr_group;
/* Features that can be disabled individually */
@@ -1966,11 +1978,6 @@ static int adt7475_probe(struct i2c_client *client)
(data->bypass_attn & (1 << 3)) ? " in3" : "",
(data->bypass_attn & (1 << 4)) ? " in4" : "");
- /* Limits and settings, should never change update more than once */
- ret = adt7475_update_limits(client);
- if (ret)
- return ret;
-
return 0;
}
--
2.56.0
next prev parent reply other threads:[~2026-11-14 0:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-14 0:41 [PATCH 0/4] hwmon: (adt7475) Add thermal sensor and PWM provider support Davíð Steinn Geirsson
2026-11-14 0:41 ` [PATCH 1/4] dt-bindings: hwmon: adt7475: Add #thermal-sensor-cells Davíð Steinn Geirsson
2026-11-14 0:41 ` [PATCH 2/4] hwmon: (adt7475) Convert to hwmon_device_register_with_info() Davíð Steinn Geirsson
2026-11-14 0:41 ` Davíð Steinn Geirsson [this message]
2026-11-14 0:41 ` [PATCH 4/4] hwmon: (adt7475) Expose fan control via PWM framework Davíð Steinn Geirsson
2026-11-14 1:03 ` [PATCH 0/4] hwmon: (adt7475) Add thermal sensor and PWM provider support Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261114004110.328050-4-david@dsg.is \
--to=david@dsg.is \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=krzk+dt@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=rdunlap@infradead.org \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.org \
--cc=ukleinek@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox