From: Guenter Roeck <linux@roeck-us.net>
To: linux-hwmon@vger.kernel.org
Cc: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Jaroslav Pulchart <jaroslav.pulchart@gooddata.com>,
"Rafael J . Wysocki" <rafael@kernel.org>,
lihuisong <lihuisong@huawei.com>,
Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH RFT 4/5] hwmon: Implement hwmon_update_groups()
Date: Fri, 23 Jan 2026 10:22:07 -0800 [thread overview]
Message-ID: <20260123182208.2229670-5-linux@roeck-us.net> (raw)
In-Reply-To: <20260123182208.2229670-1-linux@roeck-us.net>
In some situations the visibility of hwmon sysfs attributes may change.
Support this by providing a new API function hwmon_update_groups()
to update both visible attributes and thermal zones.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
Documentation/hwmon/hwmon-kernel-api.rst | 8 ++++++++
drivers/hwmon/hwmon.c | 24 ++++++++++++++++++++++++
include/linux/hwmon.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/hwmon/hwmon-kernel-api.rst b/Documentation/hwmon/hwmon-kernel-api.rst
index 1d7f1397a827..a41b1038fbf0 100644
--- a/Documentation/hwmon/hwmon-kernel-api.rst
+++ b/Documentation/hwmon/hwmon-kernel-api.rst
@@ -42,6 +42,8 @@ register/unregister functions::
char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
+ int hwmon_update_groups(struct device *dev);
+
void hwmon_lock(struct device *dev);
void hwmon_unlock(struct device *dev);
@@ -89,6 +91,12 @@ for other functions such as interrupt handlers or for attributes which are
fully implemented in the driver, hwmon_lock() and hwmon_unlock() can be used
to ensure that calls to those functions are serialized.
+If the visibility of sysfs attributes changes during runtime, the driver
+needs to call hwmon_update_groups() with the hwmon device as parameter
+to update attribute visibility. If the driver registered thermal zones
+using hwmon_device_register_with_info() and the visibility of thermal
+sensors changes, this call will also update thermal zones as needed.
+
Using devm_hwmon_device_register_with_info()
--------------------------------------------
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index cb89218a0b6a..9163b8290dbe 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -330,6 +330,11 @@ static int hwmon_thermal_register_sensors(struct device *dev)
return hwmon_thermal_handle_sensors(dev, false);
}
+static int hwmon_thermal_update_sensors(struct device *dev)
+{
+ return hwmon_thermal_handle_sensors(dev, true);
+}
+
static void hwmon_thermal_notify(struct device *dev, int index)
{
struct hwmon_thermal_data *tzdata = hwmon_thermal_find_tz(dev, index);
@@ -799,6 +804,25 @@ static const int __templates_size[] = {
[hwmon_intrusion] = ARRAY_SIZE(hwmon_intrusion_attr_templates),
};
+int hwmon_update_groups(struct device *dev)
+{
+ struct hwmon_device *hwdev = to_hwmon_device(dev);
+ const struct hwmon_chip_info *chip = hwdev->chip;
+ const struct hwmon_channel_info * const *info;
+ int ret;
+
+ ret = sysfs_update_groups(&dev->kobj, dev->groups);
+ if (ret || !chip)
+ return ret;
+
+ info = chip->info;
+ if (info[0]->type != hwmon_chip || !(info[0]->config[0] & HWMON_C_REGISTER_TZ))
+ return 0;
+
+ return hwmon_thermal_update_sensors(dev);
+}
+EXPORT_SYMBOL_GPL(hwmon_update_groups);
+
int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel)
{
diff --git a/include/linux/hwmon.h b/include/linux/hwmon.h
index 301a83afbd66..8cadba24ed4b 100644
--- a/include/linux/hwmon.h
+++ b/include/linux/hwmon.h
@@ -492,6 +492,8 @@ int hwmon_notify_event(struct device *dev, enum hwmon_sensor_types type,
char *hwmon_sanitize_name(const char *name);
char *devm_hwmon_sanitize_name(struct device *dev, const char *name);
+int hwmon_update_groups(struct device *dev);
+
void hwmon_lock(struct device *dev);
void hwmon_unlock(struct device *dev);
--
2.45.2
next prev parent reply other threads:[~2026-01-23 18:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-23 18:22 [PATCH RFT 0/5] hwmon: Introduce hwmon_update_groups() Guenter Roeck
2026-01-23 18:22 ` [PATCH RFT 1/5] hwmon: Handle attribute visibility evaluation in device core Guenter Roeck
2026-01-23 18:22 ` [PATCH RFT 2/5] hwmon: Provide helper function to find thermal zones Guenter Roeck
2026-01-23 18:22 ` [PATCH RFT 3/5] hwmon: Add support for updating " Guenter Roeck
2026-01-30 15:44 ` Guenter Roeck
2026-01-23 18:22 ` Guenter Roeck [this message]
2026-01-23 18:22 ` [PATCH RFT 5/5] hwmon: (acpi_power_meter) Use hwmon_update_groups() to update sensor visibility 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=20260123182208.2229670-5-linux@roeck-us.net \
--to=linux@roeck-us.net \
--cc=jaroslav.pulchart@gooddata.com \
--cc=lihuisong@huawei.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@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