From: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
To: daniel.lezcano@oss.qualcomm.com, rafael@kernel.org
Cc: Zhang Rui <rui.zhang@intel.com>,
Lukasz Luba <lukasz.luba@arm.com>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Anvesh Jain P <anvesh.p@oss.qualcomm.com>,
Ulf Hansson <ulf.hansson@oss.qualcomm.com>,
linux-pm@vger.kernel.org,
Daniel Lezcano <daniel.lezcano@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v1 07/12] thermal: core: Initialize aggregation during zone registration
Date: Thu, 19 Nov 2026 10:46:49 +0100 [thread overview]
Message-ID: <20261119094706.3439040-8-daniel.lezcano@oss.qualcomm.com> (raw)
In-Reply-To: <20261119094706.3439040-1-daniel.lezcano@oss.qualcomm.com>
Recognize aggregation descriptions in thermal_zone_device_register_with_trips()
and call a private thermal_zone_aggregate_register() helper before
publishing the zone. Encapsulate validation followed by coefficient
initialization in thermal_aggregation.c and propagate failures to
the caller.
Allow aggregated zones to omit the driver get_temp callback in registration
and thermal_zone_get_temp(), since their temperature is calculated by the
thermal core. Preserve the callback requirement for non-aggregated zones.
Document that callers must keep the aggregation description and source
zones alive and stable throughout the registered zone lifetime. Hardware
set_trips operations remain rejected by aggregation validation.
Provide a private stub returning -EOPNOTSUPP when thermal aggregation
is disabled, preserving the ordinary thermal zone path.
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
---
drivers/thermal/thermal_aggregation.c | 32 ++++++++++++++++++++++-----
drivers/thermal/thermal_core.c | 14 +++++++++++-
drivers/thermal/thermal_core.h | 11 +++++++++
drivers/thermal/thermal_helpers.c | 2 +-
4 files changed, 52 insertions(+), 7 deletions(-)
diff --git a/drivers/thermal/thermal_aggregation.c b/drivers/thermal/thermal_aggregation.c
index 05668e53fed8..1a7e17757025 100644
--- a/drivers/thermal/thermal_aggregation.c
+++ b/drivers/thermal/thermal_aggregation.c
@@ -23,8 +23,7 @@
* Return: 0 on success or -EINVAL for invalid arguments. Entries are unchanged
* on failure.
*/
-static int __maybe_unused
-thermal_zone_aggregate_init_coefficients(struct thermal_zone_aggregate *aggregate)
+static int thermal_zone_aggregate_init_coefficients(struct thermal_zone_aggregate *aggregate)
{
unsigned int initialized = 0;
unsigned int base, remainder, i;
@@ -110,9 +109,8 @@ thermal_zone_aggregate_init_coefficients(struct thermal_zone_aggregate *aggregat
* specification, aggregated sources or destination set_trips,
* or -ENODEV for missing or exiting sources.
*/
-static int __maybe_unused
-thermal_zone_aggregate_validate(struct thermal_zone_aggregate *aggregate,
- const struct thermal_zone_device_ops *ops)
+static int thermal_zone_aggregate_validate(struct thermal_zone_aggregate *aggregate,
+ const struct thermal_zone_device_ops *ops)
{
unsigned int initialized = 0;
unsigned int i;
@@ -157,6 +155,30 @@ thermal_zone_aggregate_validate(struct thermal_zone_aggregate *aggregate,
return 0;
}
+/**
+ * thermal_zone_aggregate_register() - prepare an aggregation for zone registration
+ * @aggregate: caller-owned aggregation description
+ * @ops: operations of the destination thermal zone
+ *
+ * Validate the description before initializing default coefficients. Call before
+ * publishing the destination zone, without holding thermal zone locks. The
+ * caller retains ownership of the description and source references and must
+ * keep them alive and stable until the destination zone is unregistered.
+ *
+ * Return: 0 on success or an error from validation or coefficient initialization.
+ */
+int thermal_zone_aggregate_register(struct thermal_zone_aggregate *aggregate,
+ const struct thermal_zone_device_ops *ops)
+{
+ int ret;
+
+ ret = thermal_zone_aggregate_validate(aggregate, ops);
+ if (ret)
+ return ret;
+
+ return thermal_zone_aggregate_init_coefficients(aggregate);
+}
+
/**
* thermal_zone_get_temp_aggregate() - read an aggregated zone temperature
* @tz: aggregate zone with a previously validated aggregation description
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 02c2c08077bf..cab2bc1d0ac3 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -1431,6 +1431,12 @@ static void thermal_zone_device_release(struct device *dev)
* thermal_zone_device_unregister() must be called when the device is no
* longer needed. The passive cooling depends on the .get_trend() return value.
*
+ * If @tzp contains an aggregation description, validate it and initialize its
+ * coefficients before publication. The caller must keep the description and
+ * referenced source zones alive and stable for the registered zone's lifetime.
+ * Aggregated zones do not require a get_temp callback and cannot use set_trips
+ * to program hardware temperature boundaries.
+ *
* Return: a pointer to the created struct thermal_zone_device or an
* in case of error, an ERR_PTR. Caller must check return value with
* IS_ERR*() helpers.
@@ -1470,7 +1476,7 @@ thermal_zone_device_register_with_trips(const char *type,
return ERR_PTR(-EINVAL);
}
- if (!ops || !ops->get_temp) {
+ if (!ops || (!ops->get_temp && !(tzp && tzp->aggregate))) {
pr_err("Thermal zone device ops not defined or invalid\n");
return ERR_PTR(-EINVAL);
}
@@ -1484,6 +1490,12 @@ thermal_zone_device_register_with_trips(const char *type,
if (thermal_class_unavailable)
return ERR_PTR(-ENODEV);
+ if (tzp && tzp->aggregate) {
+ result = thermal_zone_aggregate_register(tzp->aggregate, ops);
+ if (result)
+ return ERR_PTR(result);
+ }
+
tz = kzalloc_flex(*tz, trips, num_trips);
if (!tz)
return ERR_PTR(-ENOMEM);
diff --git a/drivers/thermal/thermal_core.h b/drivers/thermal/thermal_core.h
index 34903cfeec33..0c1cd3c16cb9 100644
--- a/drivers/thermal/thermal_core.h
+++ b/drivers/thermal/thermal_core.h
@@ -321,6 +321,17 @@ static inline int thermal_zone_get_temp_aggregate(struct thermal_zone_device *tz
return -EOPNOTSUPP;
}
#endif
+#ifdef CONFIG_THERMAL_AGGREGATION
+int thermal_zone_aggregate_register(struct thermal_zone_aggregate *aggregate,
+ const struct thermal_zone_device_ops *ops);
+#else
+static inline int
+thermal_zone_aggregate_register(struct thermal_zone_aggregate *aggregate,
+ const struct thermal_zone_device_ops *ops)
+{
+ return -EOPNOTSUPP;
+}
+#endif
void thermal_zone_set_trip_hyst(struct thermal_zone_device *tz,
struct thermal_trip *trip, int hyst);
diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c
index cf84d4c1ef65..bf5ff50ecfde 100644
--- a/drivers/thermal/thermal_helpers.c
+++ b/drivers/thermal/thermal_helpers.c
@@ -136,7 +136,7 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp)
guard(thermal_zone)(tz);
- if (!tz->ops.get_temp)
+ if (!tz->ops.get_temp && !(tz->tzp && tz->tzp->aggregate))
return -EINVAL;
ret = __thermal_zone_get_temp(tz, temp);
--
2.43.0
next prev parent reply other threads:[~2026-11-19 9:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:46 [PATCH v1 00/12] thermal: Add multi-source thermal zone aggregation Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 01/12] thermal: core: Add thermal zone device reference helpers Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 02/12] thermal: core: Introduce private thermal zone aggregation structures Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 03/12] thermal: core: Validate thermal zone aggregation descriptions Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 04/12] thermal: core: Initialize thermal zone aggregation coefficients Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 05/12] thermal: core: Dispatch aggregate temperature reads Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 06/12] thermal: core: Calculate aggregated thermal zone temperatures Daniel Lezcano
2026-11-19 9:46 ` Daniel Lezcano [this message]
2026-11-19 9:46 ` [PATCH v1 08/12] thermal: of: Separate zone parsing from sensor lookup Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 09/12] thermal: of: Track registered hardware temperature sources Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 10/12] thermal: of: Instantiate aggregates after their source zones Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 11/12] dt-bindings: thermal: Describe multi-source zone aggregation Daniel Lezcano
2026-11-19 9:46 ` [PATCH v1 12/12] thermal: testing: Add KUnit coverage for " Daniel Lezcano
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=20261119094706.3439040-8-daniel.lezcano@oss.qualcomm.com \
--to=daniel.lezcano@oss.qualcomm.com \
--cc=anvesh.p@oss.qualcomm.com \
--cc=daniel.lezcano@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukasz.luba@arm.com \
--cc=rafael@kernel.org \
--cc=robh@kernel.org \
--cc=rui.zhang@intel.com \
--cc=ulf.hansson@oss.qualcomm.com \
/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