[PATCH 1/4] thermal/of: Add thermal_zone_get_zone_by_node() API
From: Manivannan Sadhasivam via B4 Relay
Date: Wed Nov 25 2026 - 05:18:15 EST
From: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
Add an API to allow the drivers to get a registered thermal zone from OF
node.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@xxxxxxxxxxxxxxxx>
---
drivers/thermal/thermal_of.c | 21 +++++++++++++++++++++
include/linux/thermal.h | 8 ++++++++
2 files changed, 29 insertions(+)
diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c
index 9e96fb1b033e..e38f67c19c8e 100644
--- a/drivers/thermal/thermal_of.c
+++ b/drivers/thermal/thermal_of.c
@@ -530,6 +530,27 @@ void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_dev
}
EXPORT_SYMBOL_GPL(devm_thermal_of_zone_unregister);
+/**
+ * thermal_zone_get_zone_by_node() - get a registered zone from its OF node
+ * @np: device tree node of the thermal zone
+ *
+ * Thermal zones described in the device tree are registered using the name
+ * of their device tree node, so resolve @np to its registered thermal zone
+ * by that name.
+ *
+ * Return: a valid thermal zone on success, an ERR_PTR otherwise (-EINVAL for
+ * an invalid argument, -ENODEV if no zone matches @np and -EEXIST if the name
+ * is not unique).
+ */
+struct thermal_zone_device *thermal_zone_get_zone_by_node(struct device_node *np)
+{
+ if (!np)
+ return ERR_PTR(-EINVAL);
+
+ return thermal_zone_get_zone_by_name(np->name);
+}
+EXPORT_SYMBOL_GPL(thermal_zone_get_zone_by_node);
+
/**
* thermal_of_cooling_device_register() - register an OF thermal cooling device
* @np: a pointer to a device tree node.
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 306ad17aed89..c5278d1ff0ef 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -216,6 +216,8 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,
struct device_node *np,
const char *type, void *devdata,
const struct thermal_cooling_device_ops *ops);
+
+struct thermal_zone_device *thermal_zone_get_zone_by_node(struct device_node *np);
#else
static inline
@@ -254,6 +256,12 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,
{
return ERR_PTR(-ENODEV);
}
+
+static inline struct thermal_zone_device *
+thermal_zone_get_zone_by_node(struct device_node *np)
+{
+ return ERR_PTR(-ENODEV);
+}
#endif
int for_each_thermal_trip(struct thermal_zone_device *tz,
--
2.43.0