]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
thermal/of: Pass cdev_id and introduce devm registration helper
authorDaniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Tue, 26 May 2026 14:08:09 +0000 (16:08 +0200)
committerDaniel Lezcano <daniel.lezcano@kernel.org>
Wed, 3 Jun 2026 07:12:56 +0000 (09:12 +0200)
Extend the OF cooling device registration to support an explicit
cooling device identifier (cdev_id), preparing for upcoming DT
bindings where cooling devices are identified by a tuple (device node,
id) instead of relying on child nodes.

Introduce a new helper:

  devm_thermal_of_cooling_device_register()

which registers a cooling device using the device's of_node and an
explicit cdev_id. This complements the existing
devm_thermal_of_child_cooling_device_register() helper, which
remains dedicated to the legacy child-node based bindings.

Internally, factorize the devm registration logic into a common
helper to avoid code duplication.

Existing users are unaffected, as the child-based helper continues
to pass a default cdev_id of 0, preserving current behavior.

This change is a preparatory step for supporting indexed cooling
devices in thermal OF bindings.

Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@kernel.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Acked-by: Rafael J. Wysocki (Intel) <rafael@kernel.org>
Link: https://patch.msgid.link/20260526140802.1059293-20-daniel.lezcano@oss.qualcomm.com
drivers/thermal/thermal_of.c
include/linux/thermal.h

index 0110b195f7a36d44088644a67c421dcdbd4f81a5..3584024b76f553ec9d97850918eac570748ef12f 100644 (file)
@@ -558,6 +558,51 @@ static void thermal_of_cooling_device_release(void *data)
        thermal_cooling_device_unregister(cdev);
 }
 
+static struct thermal_cooling_device *
+__devm_thermal_of_cooling_device_register(struct device *dev, struct device_node *np,
+                                         u32 cdev_id, const char *type, void *devdata,
+                                         const struct thermal_cooling_device_ops *ops)
+{
+       struct thermal_cooling_device *cdev;
+       int ret;
+
+       cdev = thermal_of_cooling_device_register(np, cdev_id, type, devdata, ops);
+       if (IS_ERR(cdev))
+               return cdev;
+
+       ret = devm_add_action_or_reset(dev, thermal_of_cooling_device_release, cdev);
+       if (ret)
+               return ERR_PTR(ret);
+
+       return cdev;
+}
+
+/**
+ * devm_thermal_of_cooling_device_register() - register an OF thermal cooling device
+ * @dev:       a valid struct device pointer of a sensor device.
+ * @cdev_id:   a cooling device index in the cooling controller
+ * @type:      the thermal cooling device type.
+ * @devdata:   device private data.
+ * @ops:       standard thermal cooling devices callbacks.
+ *
+ * This function will register a cooling device with device tree node reference.
+ * This interface function adds a new thermal cooling device (fan/processor/...)
+ * to /sys/class/thermal/ folder as cooling_device[0-*]. It tries to bind itself
+ * to all the thermal zone devices registered at the same time.
+ *
+ * Return: a pointer to the created struct thermal_cooling_device or an
+ * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
+ */
+struct thermal_cooling_device *
+devm_thermal_of_cooling_device_register(struct device *dev, u32 cdev_id,
+                                       const char *type, void *devdata,
+                                       const struct thermal_cooling_device_ops *ops)
+{
+       return __devm_thermal_of_cooling_device_register(dev, dev->of_node, cdev_id,
+                                                        type, devdata, ops);
+}
+EXPORT_SYMBOL_GPL(devm_thermal_of_cooling_device_register);
+
 /**
  * devm_thermal_of_child_cooling_device_register() - register an OF thermal cooling
  *                                             device
@@ -584,17 +629,6 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,
                                              const char *type, void *devdata,
                                              const struct thermal_cooling_device_ops *ops)
 {
-        struct thermal_cooling_device *cdev;
-        int ret;
-
-       cdev = thermal_of_cooling_device_register(np, 0, type, devdata, ops);
-       if (IS_ERR(cdev))
-               return cdev;
-
-        ret = devm_add_action_or_reset(dev, thermal_of_cooling_device_release, cdev);
-        if (ret)
-                return ERR_PTR(ret);
-
-        return cdev;
+       return __devm_thermal_of_cooling_device_register(dev, np, 0, type, devdata, ops);
 }
 EXPORT_SYMBOL_GPL(devm_thermal_of_child_cooling_device_register);
index fb7649439dfa243b28c30cc9d8e0845c1417059b..81be6e6061b3f2dcde352bcd7b8f0905c2134a5f 100644 (file)
@@ -206,6 +206,11 @@ thermal_of_cooling_device_register(struct device_node *np, u32 cdev_id,
                                   const char *type, void *data,
                                   const struct thermal_cooling_device_ops *ops);
 
+struct thermal_cooling_device *
+devm_thermal_of_cooling_device_register(struct device *dev, u32 cdev_id,
+                                       const char *type, void *devdata,
+                                       const struct thermal_cooling_device_ops *ops);
+
 struct thermal_cooling_device *
 devm_thermal_of_child_cooling_device_register(struct device *dev,
                                              struct device_node *np,
@@ -233,6 +238,14 @@ thermal_of_cooling_device_register(struct device_node *np, u32 cdev_id,
        return ERR_PTR(-ENODEV);
 }
 
+static inline struct thermal_cooling_device *
+devm_thermal_of_cooling_device_register(struct device *dev, u32 cdev_id,
+                                       const char *type, void *devdata,
+                                       const struct thermal_cooling_device_ops *ops)
+{
+       return ERR_PTR(-ENODEV);
+}
+
 static inline struct thermal_cooling_device *
 devm_thermal_of_child_cooling_device_register(struct device *dev,
                                              struct device_node *np,