Messages in this thread Patch in this message |  | | From | Daniel Lezcano <> | | Subject | [PATCH v3 02/11] thermal/core: Add a non-OF registering function | | Date | Wed, 29 Apr 2026 18:14:15 +0200 |
| |
In order to propose an alternative to non OF code registering a cooling device, provide functions which are not for OF code. That sets the scene for OF and non-OF code split.
Signed-off-by: Daniel Lezcano <daniel.lezcano@oss.qualcomm.com> --- drivers/thermal/thermal_core.c | 35 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 16 ++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 664a4cc95199..5c954bcae4a4 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1194,6 +1194,41 @@ static void thermal_cooling_device_release(void *data) thermal_cooling_device_unregister(cdev); } +/** + * devm_thermal_cooling_device_register() - register a thermal cooling device + * @dev: a valid struct device pointer of a sensor device. + * @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_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_cooling_device_register(NULL, type, devdata, ops); + if (IS_ERR(cdev)) + return cdev; + + ret = devm_add_action_or_reset(dev, thermal_cooling_device_release, cdev); + if (ret) + return ERR_PTR(ret); + + return cdev; +} +EXPORT_SYMBOL_GPL(devm_thermal_cooling_device_register); + /** * devm_thermal_of_cooling_device_register() - register an OF thermal cooling * device diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 0ddc77aeeca2..50b43e328ab9 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -253,8 +253,12 @@ void thermal_zone_device_update(struct thermal_zone_device *, struct thermal_cooling_device *thermal_cooling_device_register(const char *, void *, const struct thermal_cooling_device_ops *); struct thermal_cooling_device * -thermal_of_cooling_device_register(struct device_node *np, const char *, void *, - const struct thermal_cooling_device_ops *); +devm_thermal_cooling_device_register(struct device *dev, const char *type, + void *devdata, const struct thermal_cooling_device_ops *ops); + +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); struct thermal_cooling_device * devm_thermal_of_cooling_device_register(struct device *dev, struct device_node *np, @@ -304,6 +308,14 @@ static inline struct thermal_cooling_device * thermal_cooling_device_register(const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { return ERR_PTR(-ENODEV); } + +static inline struct thermal_cooling_device * +devm_thermal_cooling_device_register(struct device *dev, const char *type, + void *devdata, const struct thermal_cooling_device_ops *ops) +{ + return ERR_PTR(-ENODEV); +} + static inline struct thermal_cooling_device * thermal_of_cooling_device_register(struct device_node *np, const char *type, void *devdata, -- 2.43.0
|  |