]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
thermal/core: Introduce non-OF thermal_cooling_device_register()
authorDaniel Lezcano <daniel.lezcano@oss.qualcomm.com>
Tue, 26 May 2026 14:08:02 +0000 (16:08 +0200)
committerDaniel Lezcano <daniel.lezcano@kernel.org>
Wed, 3 Jun 2026 07:12:38 +0000 (09:12 +0200)
Split the cooling device registration API into OF and non-OF variants.

Introduce thermal_cooling_device_register() for non-device-tree users
and rework thermal_of_cooling_device_register() to use the new
alloc/add split.

This removes the need for the internal __thermal_cooling_device_register()
helper and makes the separation between OF and non-OF users explicit.

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-13-daniel.lezcano@oss.qualcomm.com
drivers/thermal/thermal_core.c

index db01361569d76739bb3463189abc588283a77b4a..0b3db889d60df9fae47d15739c140529ac1cefb0 100644 (file)
@@ -1059,8 +1059,7 @@ out_put_device:
 }
 
 /**
- * __thermal_cooling_device_register() - register a new thermal cooling device
- * @np:                a pointer to a device tree node.
+ * thermal_cooling_device_register() - register a new thermal cooling device
  * @type:      the thermal cooling device type.
  * @devdata:   device private data.
  * @ops:       standard thermal cooling devices callbacks.
@@ -1068,16 +1067,13 @@ out_put_device:
  * 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.
- * It also gives the opportunity to link the cooling device to a device tree
- * node, so that it can be bound to a thermal zone created out of device tree.
  *
  * Return: a pointer to the created struct thermal_cooling_device or an
  * ERR_PTR. Caller must check return value with IS_ERR*() helpers.
  */
-static struct thermal_cooling_device *
-__thermal_cooling_device_register(struct device_node *np,
-                                 const char *type, void *devdata,
-                                 const struct thermal_cooling_device_ops *ops)
+struct thermal_cooling_device *
+thermal_cooling_device_register(const char *type, void *devdata,
+                               const struct thermal_cooling_device_ops *ops)
 {
        struct thermal_cooling_device *cdev;
        int ret;
@@ -1086,34 +1082,12 @@ __thermal_cooling_device_register(struct device_node *np,
        if (IS_ERR(cdev))
                return cdev;
 
-       cdev->np = np;
-
        ret = thermal_cooling_device_add(cdev, devdata);
        if (ret)
                return ERR_PTR(ret);
 
        return cdev;
 }
-
-/**
- * thermal_cooling_device_register() - register a new thermal cooling device
- * @type:      the thermal cooling device type.
- * @devdata:   device private data.
- * @ops:               standard thermal cooling devices callbacks.
- *
- * 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 *
-thermal_cooling_device_register(const char *type, void *devdata,
-                               const struct thermal_cooling_device_ops *ops)
-{
-       return __thermal_cooling_device_register(NULL, type, devdata, ops);
-}
 EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
 
 /**
@@ -1121,22 +1095,36 @@ EXPORT_SYMBOL_GPL(thermal_cooling_device_register);
  * @np:                a pointer to a device tree node.
  * @type:      the thermal cooling device type.
  * @devdata:   device private data.
- * @ops:               standard thermal cooling devices callbacks.
+ * @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.
+ * It also gives the opportunity to link the cooling device to a device tree
+ * node, so that it can be bound to a thermal zone created out of device tree.
  *
  * 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 *
 thermal_of_cooling_device_register(struct device_node *np,
-                                  const char *type, void *devdata,
-                                  const struct thermal_cooling_device_ops *ops)
+                                    const char *type, void *devdata,
+                                    const struct thermal_cooling_device_ops *ops)
 {
-       return __thermal_cooling_device_register(np, type, devdata, ops);
+       struct thermal_cooling_device *cdev;
+       int ret;
+
+       cdev = thermal_cooling_device_alloc(type, ops);
+       if (IS_ERR(cdev))
+               return cdev;
+
+       cdev->np = np;
+
+       ret = thermal_cooling_device_add(cdev, devdata);
+       if (ret)
+               return ERR_PTR(ret);
+
+       return cdev;
 }
 EXPORT_SYMBOL_GPL(thermal_of_cooling_device_register);
 
@@ -1173,7 +1161,7 @@ devm_thermal_of_cooling_device_register(struct device *dev,
        struct thermal_cooling_device *cdev;
        int ret;
 
-       cdev = __thermal_cooling_device_register(np, type, devdata, ops);
+       cdev = thermal_of_cooling_device_register(np, type, devdata, ops);
        if (IS_ERR(cdev))
                return cdev;