Support cooling device with ID in the OF
Subsystems (19)
v3 cover Support cooling device with ID in the OF
Ultra short description. Dt Cooling device description:
Old: <&mycdev min max>
New: <&mycdev min max> OR/AND <&mycdev id min max>
Depends on series:
https://lore.kernel.org/all/[email protected]/
A cooling device can be a single cooling device or a cooling device controller with multiple cooling devices attached to it.
The thermal framework builds a connection between a cooling device and a thermal zone when there is a trip point to be mitigated by the cooling device. In the Linux kernel thermal semantic, the action of connecting the cooling device and the thermal zone is called a binding.
The description of the aforementioned connection depends on the firmware definition and in our case it is through the device tree. The cooling map describes this connection.
How is it done ?
For a single cooling device, the DT describes:
* A cooling device:
mycooling_device {
...
};* A cooling map in a thermal zone
mythermal_zone {
...
cooling-maps {
map0 {
...
cooling-device = <&mycooling_device min max>;
...
};
}
...};
For a cooling device controller with multiple cooling devices attached, the DT describes:
* A cooling device controller:
mycooling_device_ctrl {
mycooling_device1 {
...
};
mycooling_device2 {
...
};
...
mycooling_deviceN {
...
};};
* A cooling map in a thermal zone
mythermal_zone {
...
cooling-maps {
map0 {
...
cooling-device = <&mycooling_device1 min max>;
...
};
}
...};
When the cooling device "mycooling_device" is registered, then the binding function will browse all the cooling maps and matches the node device pointer to do the association (the pĥandle in the cooling map vs the cooling device node).
That is how the connection between the cooling device and the thermal zone is done.
DT maintainers consider the above description with child nodes is incorrect if a child node doesn't have its own bindings as explained in the documentation [1].
Gaurav Kohli posted a series to support the QMI TMD (Qualcomm Messaging Interface based Thermal Mitigation Devices) [2]. This device is a dedicated, centralized cooling device controller managing a set of cooling devices.
Because of the above restrictions with child nodes there is no DT bindings allowing to do the connection between the cooling device inside the cooling device controller and a thermal zone.
A QMI TMD is not a standalone cooling device neither a multiple cooling devices with their own DT description.
For this reason, the proposed changes with child nodes has been rejected [3].
As a solution, it has been proposed to fold all these child nodes into an array and add an id in the cooling maps to identify the cooling device entry in the controller node [4].
Given the thermal zone has the same mechanism [5], that is a phandle to a sensor node and an sensor specifier. The proposed approach makes sense as it is consistent with the thermal zone description.
This series provides a cleanup around the usage of the OF code which is interleaved with non-OF code. The OF and the non-OF code are separated and remain self-encapsulated.
Then the function to register a cooling device is renamed to reflect the legacy usage and a new function is introduced with the id parameter.
Finally, the DT bindings is updated with the new format and the thermal OF is changed to handle the new DT bindings.
Given the trivial changes impacting the files outside of the thermal framework, this series is designed to have all changes going through the thermal tree.
Thanks!
[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/writing-bindings.rst
[2] https://lore.kernel.org/all/[email protected]/
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/
[5] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/devicetree/bindings/thermal/thermal-zones.yaml#n99
---
Changelog:
- V3
- Reordered and reworked the patches to be git bisect safe
- Reworked devm usage by using a more adequate function doing the same as the group of calls to devm*
- Pass an init callback instead of moving thermal_cooling_device_init_complete() out of the function and calling it in different places
- Sent separetely changes to the tegra soctherm driver
- V2
- Added stubs for OF functions in order to prevent to break the git bisectability compilation
- Added missing call to thermal_cooling_device_init_complete() in devm_thermal_of_cooling_device_register()
- Fixed assymetry in devm_ calls for the tegra/soctherm() driver
- Fixed kernel documentation for API changes
- Added missing static inline for a API stub
- Hardened the test with two or three arguments in the cooling spec
- Narrowed const: 2 strict in pwm-fan
---
Daniel Lezcano (10):
thermal/core: Use devm_add_action_or_reset() when registering a
cooling device
Add a non-OF registering funciton
thermal/of: Move the node pointer assignation in the OF code file hwmon:: Use non-OF thermal cooling device register function thermal/core: Put of_node field cooling device structure under Kconfig
option
thermal/of: Move OF code where it belongs to
thermal/of: Rename the devm_thermal_of_cooling_device_register()
function
thermal/of: Introduce cooling device of_index
thermal/of: Pass the of_index and add a function to register with an
index
thermal/of: Process cooling device index in cooling-spec
Gaurav Kohli (1):
dt-bindings: thermal: cooling-devices: Update support for 3 cells
cooling device
.../devicetree/bindings/hwmon/pwm-fan.yaml | 3 +- .../thermal/thermal-cooling-devices.yaml | 8 +- .../bindings/thermal/thermal-zones.yaml | 3 +- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 5 +- drivers/hwmon/amc6821.c | 2 +- drivers/hwmon/aspeed-pwm-tacho.c | 5 +- drivers/hwmon/cros_ec_hwmon.c | 4 +- drivers/hwmon/dell-smm-hwmon.c | 4 +- drivers/hwmon/emc2305.c | 6 +- drivers/hwmon/gpio-fan.c | 6 +- drivers/hwmon/max6650.c | 6 +- drivers/hwmon/mlxreg-fan.c | 4 +- drivers/hwmon/npcm750-pwm-fan.c | 6 +- drivers/hwmon/pwm-fan.c | 5 +- drivers/hwmon/qnap-mcu-hwmon.c | 6 +- drivers/hwmon/tc654.c | 5 +- drivers/memory/tegra/tegra210-emc-core.c | 4 +- drivers/soc/qcom/qcom_aoss.c | 2 +- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/cpuidle_cooling.c | 2 +- drivers/thermal/devfreq_cooling.c | 2 +- drivers/thermal/khadas_mcu_fan.c | 7 +- drivers/thermal/tegra/soctherm.c | 6 +- drivers/thermal/thermal_core.c | 106 ++++-------- drivers/thermal/thermal_core.h | 6 + drivers/thermal/thermal_of.c | 157 +++++++++++++++++- include/linux/thermal.h | 71 ++++++-- 27 files changed, 303 insertions(+), 140 deletions(-)
Signature · 1 line
2.43.0
PATCH v3 1/11 thermal/core: Use devm_add_action_or_reset() when registering a cooling device
Use devm_add_action_or_reset() which does the replaced code. It results in a simpler and more concise code.
--- drivers/thermal/thermal_core.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)
drivers/thermal/thermal_core.c +13 -17
@@ -1187,10 +1187,11 @@ thermal_of_cooling_device_register(struct device_node *np, }EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register); -static void thermal_cooling_device_release (struct device *dev,void *res) +static void thermal_cooling_device_release (void *data) { -thermal_cooling_device_unregister ( - *(struct thermal_cooling_device **)res); +struct thermal_cooling_device *cdev = data; + +thermal_cooling_device_unregister (cdev); }/**
@@ -1216,23 +1217,18 @@ devm_thermal_of_cooling_device_register(struct device *dev, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - struct thermal_cooling_device **ptr, *tcd; + struct thermal_cooling_device *cdev; +int ret; - ptr =devres_alloc (thermal_cooling_device_release,sizeof (*ptr), -GFP_KERNEL ); -if (!ptr) -return ERR_PTR (-ENOMEM ); + cdev =__thermal_cooling_device_register (np, type, devdata, ops); +if (IS_ERR (cdev)) +return cdev; - tcd =__thermal_cooling_device_register (np, type, devdata, ops); -if (IS_ERR (tcd)) { -devres_free (ptr); -return tcd; - } - - *ptr = tcd; -devres_add (dev, ptr); + ret =devm_add_action_or_reset (dev, thermal_cooling_device_release, cdev); +if (ret) +return ERR_PTR (ret); -return tcd; +return cdev; }EXPORT_SYMBOL_GPL (devm_thermal_of_cooling_device_register);
Signature · 1 line
2.43.0
PATCH v3 2/11 thermal/core: Add a non-OF registering function
In reply to Daniel LezcanoIn 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.
--- drivers/thermal/thermal_core.c | 35 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 16 ++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-)
drivers/thermal/thermal_core.c +35 -0
@@ -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
include/linux/thermal.h +14 -2
@@ -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,
Signature · 1 line
2.43.0
PATCH v3 3/11 thermal/of: Move the node pointer assignation in the OF code file
In reply to Daniel LezcanoThe node pointer being assigned to the cooling device structure is an action done by the thermal OF only and does not belong to the core framework code. Move the node pointer assignation in the thermal OF code. Consequently, the devm_thermal_of_cooling_device_register() can call its non-devm version resulting in a more intuitive design of the API.
--- drivers/thermal/thermal_core.c | 51 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-)
drivers/thermal/thermal_core.c +26 -25
@@ -1040,26 +1040,11 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device *thermal_zone_cdev_bind (tz, cdev); } -/** -* __thermal_cooling_device_register() - register a new thermal cooling device -* @np: a pointer to a device tree node. -* @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. -* 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) +__thermal_cooling_device_register (const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops, +void (*initcb)(struct thermal_cooling_device *, +void *),void *data) {struct thermal_cooling_device *cdev;unsigned long current_state;
@@ -1089,7 +1074,6 @@ __thermal_cooling_device_register(struct device_node *np,mutex_init (&cdev->lock);INIT_LIST_HEAD (&cdev->thermal_instances); - cdev->np = np; cdev->ops = ops; cdev->updated = false; cdev->device.class = &thermal_class;
@@ -1127,6 +1111,9 @@ __thermal_cooling_device_register(struct device_node *np,if (current_state <= cdev->max_state)thermal_debug_cdev_add (cdev, current_state); +if (initcb) +initcb (cdev, data); +thermal_cooling_device_init_complete (cdev);return cdev;
@@ -1146,7 +1133,7 @@ __thermal_cooling_device_register(struct device_node *np,* 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. +* @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
@@ -1159,10 +1146,17 @@ 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); + return __thermal_cooling_device_register(type, devdata, ops, NULL, NULL); }EXPORT_SYMBOL_GPL (thermal_cooling_device_register); +static void thermal_of_cooling_device_init (struct thermal_cooling_device *cdev,void *data) +{ +struct device_node *np = data; + + cdev->np = np; +} +/** * thermal_of_cooling_device_register() - register an OF thermal cooling device * @np: a pointer to a device tree node.
@@ -1183,7 +1177,14 @@ thermal_of_cooling_device_register(struct device_node *np, 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; + + cdev =__thermal_cooling_device_register (type, devdata, ops, + thermal_of_cooling_device_init, np); +if (IS_ERR (cdev)) +return cdev; + +return cdev; }EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register);
@@ -1217,7 +1218,7 @@ devm_thermal_cooling_device_register(struct device *dev,struct thermal_cooling_device *cdev;int ret; - cdev =__thermal_cooling_device_register (NULL , type, devdata, ops); + cdev =thermal_cooling_device_register (type, devdata, ops);if (IS_ERR (cdev))return cdev;
@@ -1255,7 +1256,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;
Signature · 1 line
2.43.0
PATCH v3 4/11 hwmon:: Use non-OF thermal cooling device register function
In reply to Daniel LezcanoMake HWMON drivers which are not based on device tree to use the corresponding non-OF functions.
--- drivers/hwmon/cros_ec_hwmon.c | 4 ++-- drivers/hwmon/dell-smm-hwmon.c | 4 ++-- drivers/hwmon/mlxreg-fan.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-)
drivers/hwmon/cros_ec_hwmon.c +2 -2
@@ -532,8 +532,8 @@ static void cros_ec_hwmon_register_fan_cooling_devices(struct device *dev, cpriv->hwmon_priv = priv; cpriv->index = i; - cdev =devm_thermal_of_cooling_device_register (dev,NULL , type, cpriv, - &cros_ec_thermal_cooling_ops); + cdev =devm_thermal_cooling_device_register (dev, type, cpriv, + &cros_ec_thermal_cooling_ops);if (IS_ERR (cdev)) {dev_warn (dev,"failed to register fan %zu as a cooling device: %pe\n" , i, cdev);
drivers/hwmon/dell-smm-hwmon.c +2 -2
@@ -1161,8 +1161,8 @@ static int dell_smm_init_cdev(struct device *dev, u8 fan_num)if (cdata) { cdata->fan_num = fan_num; cdata->data = data; - cdev =devm_thermal_of_cooling_device_register (dev,NULL , name, cdata, - &dell_smm_cooling_ops); + cdev =devm_thermal_cooling_device_register (dev, name, cdata, + &dell_smm_cooling_ops);if (IS_ERR (cdev)) {devm_kfree (dev, cdata); ret =PTR_ERR (cdev);
drivers/hwmon/mlxreg-fan.c +2 -2
@@ -583,8 +583,8 @@ static int mlxreg_fan_cooling_config(struct device *dev, struct mlxreg_fan *fan) pwm->fan = fan;/* Set minimal PWM speed. */ pwm->last_hwmon_state =MLXREG_FAN_PWM_DUTY2STATE (MLXREG_FAN_MIN_DUTY ); - pwm->cdev =devm_thermal_of_cooling_device_register (dev,NULL , mlxreg_fan_name[i], - pwm, &mlxreg_fan_cooling_ops); + pwm->cdev =devm_thermal_cooling_device_register (dev, mlxreg_fan_name[i], + pwm, &mlxreg_fan_cooling_ops);if (IS_ERR (pwm->cdev)) {dev_err (dev,"Failed to register cooling device\n" );return PTR_ERR (pwm->cdev);
Signature · 1 line
2.43.0
PATCH v3 5/11 thermal/core: Put of_node field cooling device structure under Kconfig option
In reply to Daniel LezcanoThe device node pointer in the cooling device structure is only needed by the thermal OF in order to bind a thermal zone with a cooling device. Now only the OF based drivers are using the thermal OF functions and do not call the function with a NULL device_node parameter as before. We can put this field under the CONFIG_THERMAL_OF condition and make it go away if the device tree is not used.
--- include/linux/thermal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
include/linux/thermal.h +3 -1
@@ -125,7 +125,6 @@ struct thermal_cooling_device {const char *type;unsigned long max_state;struct device device; -struct device_node *np;void *devdata;void *stats;const struct thermal_cooling_device_ops *ops;
@@ -133,6 +132,9 @@ struct thermal_cooling_device {struct mutex lock;/* protect thermal_instances list */ struct list_head thermal_instances;struct list_head node; +#ifdef CONFIG_THERMAL_OF +struct device_node *np; +#endif #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs;#endif
Signature · 1 line
2.43.0
PATCH v3 6/11 thermal/of: Move OF code where it belongs to
In reply to Daniel LezcanoThe functions:
- thermal_of_cooling_device_register()
- devm_thermal_of_cooling_device_register()
are related to thermal-of but they are implemented in thermal-core. Move these functions to the right file.
--- drivers/thermal/thermal_core.c | 78 +------------------------------- drivers/thermal/thermal_core.h | 6 +++ drivers/thermal/thermal_of.c | 83 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 48 ++++++++++++-------- 4 files changed, 118 insertions(+), 97 deletions(-)
drivers/thermal/thermal_core.c +1 -77
@@ -1040,7 +1040,7 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device *thermal_zone_cdev_bind (tz, cdev); } -static struct thermal_cooling_device * +struct thermal_cooling_device * __thermal_cooling_device_register(const char *type, void *devdata, const struct thermal_cooling_device_ops *ops, void (*initcb)(struct thermal_cooling_device *,
@@ -1150,44 +1150,6 @@ thermal_cooling_device_register(const char *type, void *devdata, }EXPORT_SYMBOL_GPL (thermal_cooling_device_register); -static void thermal_of_cooling_device_init (struct thermal_cooling_device *cdev,void *data) -{ -struct device_node *np = data; - - cdev->np = np; -} - -/** -* thermal_of_cooling_device_register() - register an OF thermal cooling device -* @np: a pointer to a device tree node. -* @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 * -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 *cdev; - - cdev =__thermal_cooling_device_register (type, devdata, ops, - thermal_of_cooling_device_init, np); -if (IS_ERR (cdev)) -return cdev; - -return cdev; -} -EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register); -static void thermal_cooling_device_release (void *data) {struct thermal_cooling_device *cdev = data;
@@ -1230,44 +1192,6 @@ devm_thermal_cooling_device_register(struct device *dev, }EXPORT_SYMBOL_GPL (devm_thermal_cooling_device_register); -/** -* devm_thermal_of_cooling_device_register() - register an OF thermal cooling -* device -* @dev: a valid struct device pointer of a sensor device. -* @np: a pointer to a device tree node. -* @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, -struct device_node *np, -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, 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_of_cooling_device_register); -static bool thermal_cooling_device_present (struct thermal_cooling_device *cdev) {struct thermal_cooling_device *pos =NULL ;
drivers/thermal/thermal_core.h +6 -0
@@ -269,6 +269,12 @@ void thermal_zone_device_critical_shutdown(struct thermal_zone_device *tz);void thermal_governor_update_tz (struct thermal_zone_device *tz,enum thermal_notify_event reason); +struct thermal_cooling_device * +__thermal_cooling_device_register (const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops, +void (*initcb)(struct thermal_cooling_device *, +void *),void *data); +/* Helpers */ #define for_each_trip_desc (__tz, __td) \ for (__td = __tz->trips; __td - __tz->trips < __tz->num_trips; __td++)
drivers/thermal/thermal_of.c +83 -0
86 lines not on this page · raw message
include/linux/thermal.h +28 -20
76 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v3 7/11 thermal/of: Rename the devm_thermal_of_cooling_device_register() function
In reply to Daniel LezcanoThe cooling devices can be composed with a cooling device controller and a set of cooling devices attached to it. Until now, the DT bindings were described using a node for the cooling device controller and child nodes for all the cooling devices.
Recently, a new set of cooling devices were proposed with the same bindings. Those were rejected because DT maintainers do not want this format anymore. In place, a cooling device will be created with an id. Whatever its meaning, the thermal OF will bind a thermal zone and a cooling device by checking the device node pointer + the id are matching the cooling map with the cooling device.
Actually this approach is consistent with the thermal which are also registered with a device and an id.
In order to do a distinction between the old binding with child nodes and the incoming new binding, let's rename the registering function with a self-explanatory name.
Rename the functions:
devm_thermal_of_cooling_device_register() -> devm_thermal_of_child_cooling_device_register()
Used the command:
find . -type f -name '*.[ch]' -exec \
sed -i 's/devm_thermal_of_cooling_device_register/\
devm_thermal_of_child_cooling_device_register/g' {} \;Did not used clang-format-diff because it does not indent correctly and checkpatch complained. Manually reindented to make checkpatch happy
--- drivers/hwmon/amc6821.c | 2 +- drivers/hwmon/aspeed-pwm-tacho.c | 5 +++-- drivers/hwmon/emc2305.c | 6 +++--- drivers/hwmon/gpio-fan.c | 6 ++++-- drivers/hwmon/max6650.c | 6 +++--- drivers/hwmon/npcm750-pwm-fan.c | 6 ++++-- drivers/hwmon/pwm-fan.c | 5 +++-- drivers/hwmon/qnap-mcu-hwmon.c | 6 +++--- drivers/hwmon/tc654.c | 5 +++-- drivers/memory/tegra/tegra210-emc-core.c | 4 ++-- drivers/soc/qcom/qcom_aoss.c | 2 +- drivers/thermal/khadas_mcu_fan.c | 7 ++++--- drivers/thermal/tegra/soctherm.c | 6 +++--- drivers/thermal/thermal_of.c | 15 +++++++++------ include/linux/thermal.h | 16 ++++++++-------- 15 files changed, 54 insertions(+), 43 deletions(-)
drivers/hwmon/amc6821.c +1 -1
@@ -1076,7 +1076,7 @@ static int amc6821_probe(struct i2c_client *client) "Failed to initialize hwmon\n");if (IS_ENABLED (CONFIG_THERMAL ) && fan_np && data->fan_cooling_levels) -return PTR_ERR_OR_ZERO (devm_thermal_of_cooling_device_register (dev, +return PTR_ERR_OR_ZERO (devm_thermal_of_child_cooling_device_register (dev, fan_np, client->name, data, &amc6821_cooling_ops));return 0 ;
drivers/hwmon/aspeed-pwm-tacho.c +3 -2
@@ -841,8 +841,9 @@ static int aspeed_create_pwm_cooling(struct device *dev, }snprintf (cdev->name,MAX_CDEV_NAME_LEN ,"%pOFn%d" , child, pwm_port); - cdev->tcdev =devm_thermal_of_cooling_device_register (dev, child, - cdev->name, cdev, &aspeed_pwm_cool_ops); + cdev->tcdev =devm_thermal_of_child_cooling_device_register (dev, child, + cdev->name, cdev, + &aspeed_pwm_cool_ops);if (IS_ERR (cdev->tcdev))return PTR_ERR (cdev->tcdev);
drivers/hwmon/emc2305.c +3 -3
@@ -309,9 +309,9 @@ static int emc2305_set_single_tz(struct device *dev, struct device_node *fan_nod pwm = data->pwm_min[cdev_idx]; data->cdev_data[cdev_idx].cdev = -devm_thermal_of_cooling_device_register (dev, fan_node, - emc2305_fan_name[idx], data, - &emc2305_cooling_ops); +devm_thermal_of_child_cooling_device_register (dev, fan_node, + emc2305_fan_name[idx], data, + &emc2305_cooling_ops);if (IS_ERR (data->cdev_data[cdev_idx].cdev)) {dev_err (dev,"Failed to register cooling device %s\n" , emc2305_fan_name[idx]);
drivers/hwmon/gpio-fan.c +4 -2
@@ -592,8 +592,10 @@ static int gpio_fan_probe(struct platform_device *pdev) }/* Optional cooling device register for Device tree platforms */ - fan_data->cdev =devm_thermal_of_cooling_device_register (dev, np, -"gpio-fan" , fan_data, &gpio_fan_cool_ops); + fan_data->cdev =devm_thermal_of_child_cooling_device_register (dev, np, +"gpio-fan" , + fan_data, + &gpio_fan_cool_ops);dev_info (dev,"GPIO fan initialized\n" );
drivers/hwmon/max6650.c +3 -3
@@ -793,9 +793,9 @@ static int max6650_probe(struct i2c_client *client)return err;if (IS_ENABLED (CONFIG_THERMAL )) { - cooling_dev =devm_thermal_of_cooling_device_register (dev, - dev->of_node, client->name, - data, &max6650_cooling_ops); + cooling_dev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, + client->name, data, + &max6650_cooling_ops);if (IS_ERR (cooling_dev)) {dev_warn (dev,"thermal cooling device register failed: %ld\n" ,PTR_ERR (cooling_dev));
drivers/hwmon/npcm750-pwm-fan.c +4 -2
@@ -857,8 +857,10 @@ static int npcm7xx_create_pwm_cooling(struct device *dev,snprintf (cdev->name,THERMAL_NAME_LENGTH ,"%pOFn%d" , child, pwm_port); - cdev->tcdev =devm_thermal_of_cooling_device_register (dev, child, - cdev->name, cdev, &npcm7xx_pwm_cool_ops); + cdev->tcdev =devm_thermal_of_child_cooling_device_register (dev, child, + cdev->name, + cdev, + &npcm7xx_pwm_cool_ops);if (IS_ERR (cdev->tcdev))return PTR_ERR (cdev->tcdev);
drivers/hwmon/pwm-fan.c +3 -2
@@ -685,8 +685,9 @@ static int pwm_fan_probe(struct platform_device *pdev) ctx->pwm_fan_state = ctx->pwm_fan_max_state;if (IS_ENABLED (CONFIG_THERMAL )) { - cdev =devm_thermal_of_cooling_device_register (dev, - dev->of_node,"pwm-fan" , ctx, &pwm_fan_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, +"pwm-fan" , ctx, + &pwm_fan_cooling_ops);if (IS_ERR (cdev)) { ret =PTR_ERR (cdev); dev_err(dev,
drivers/hwmon/qnap-mcu-hwmon.c +3 -3
@@ -337,9 +337,9 @@ static int qnap_mcu_hwmon_probe(struct platform_device *pdev)* levels and only succeed with either no or correct cooling levels. */ if (IS_ENABLED (CONFIG_THERMAL ) && hwm->fan_cooling_levels) { - cdev =devm_thermal_of_cooling_device_register (dev, -to_of_node (hwm->fan_node),"qnap-mcu-hwmon" , - hwm, &qnap_mcu_hwmon_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev,to_of_node (hwm->fan_node), +"qnap-mcu-hwmon" , hwm, + &qnap_mcu_hwmon_cooling_ops);if (IS_ERR (cdev))return dev_err_probe (dev,PTR_ERR (cdev),"Failed to register qnap-mcu-hwmon as cooling device\n" );
drivers/hwmon/tc654.c +3 -2
@@ -541,8 +541,9 @@ static int tc654_probe(struct i2c_client *client)if (IS_ENABLED (CONFIG_THERMAL )) {struct thermal_cooling_device *cdev; - cdev =devm_thermal_of_cooling_device_register (dev, dev->of_node, client->name, - hwmon_dev, &tc654_fan_cool_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev, dev->of_node, + client->name, hwmon_dev, + &tc654_fan_cool_ops);return PTR_ERR_OR_ZERO (cdev); }
drivers/memory/tegra/tegra210-emc-core.c +2 -2
@@ -1966,8 +1966,8 @@ static int tegra210_emc_probe(struct platform_device *pdev)tegra210_emc_debugfs_init (emc); - cd =devm_thermal_of_cooling_device_register (emc->dev, np,"emc" , emc, - &tegra210_emc_cd_ops); + cd =devm_thermal_of_child_cooling_device_register (emc->dev, np,"emc" , emc, + &tegra210_emc_cd_ops);if (IS_ERR (cd)) { err =PTR_ERR (cd); dev_err(emc->dev, "failed to register cooling device: %d\n",
drivers/soc/qcom/qcom_aoss.c +1 -1
@@ -381,7 +381,7 @@ static int qmp_cooling_device_add(struct qmp *qmp, qmp_cdev->qmp = qmp; qmp_cdev->state = !qmp_cdev_max_state; qmp_cdev->name = cdev_name; - qmp_cdev->cdev =devm_thermal_of_cooling_device_register + qmp_cdev->cdev =devm_thermal_of_child_cooling_device_register (qmp->dev, node, cdev_name, qmp_cdev, &qmp_cooling_device_ops);
drivers/thermal/khadas_mcu_fan.c +4 -3
@@ -90,9 +90,10 @@ static int khadas_mcu_fan_probe(struct platform_device *pdev) ctx->mcu = mcu;platform_set_drvdata (pdev, ctx); - cdev =devm_thermal_of_cooling_device_register (dev->parent, - dev->parent->of_node,"khadas-mcu-fan" , ctx, - &khadas_mcu_fan_cooling_ops); + cdev =devm_thermal_of_child_cooling_device_register (dev->parent, + dev->parent->of_node, +"khadas-mcu-fan" , ctx, + &khadas_mcu_fan_cooling_ops);if (IS_ERR (cdev)) { ret =PTR_ERR (cdev); dev_err(dev, "Failed to register khadas-mcu-fan as cooling device: %d\n",
drivers/thermal/tegra/soctherm.c +3 -3
@@ -1707,9 +1707,9 @@ static void soctherm_init_hw_throt_cdev(struct platform_device *pdev) stc->init = true; }else { - tcd =devm_thermal_of_cooling_device_register (dev, np_stcc, - (char *)name, ts, - &throt_cooling_ops); + tcd =devm_thermal_of_child_cooling_device_register (dev, np_stcc, + (char *)name, ts, + &throt_cooling_ops);if (IS_ERR_OR_NULL (tcd)) { dev_err(dev, "throttle-cfg: %s: failed to register cooling device\n",
drivers/thermal/thermal_of.c +9 -6
@@ -557,7 +557,7 @@ static void thermal_of_cooling_device_release(void *data) }/** -* devm_thermal_of_cooling_device_register() - register an OF thermal cooling +* devm_thermal_of_child_cooling_device_register() - register an OF thermal cooling * device * @dev: a valid struct device pointer of a sensor device. * @np: a pointer to a device tree node.
@@ -570,14 +570,17 @@ static void thermal_of_cooling_device_release(void *data)* 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. * +* This function should be used when a cooling controller has child +* nodes which are referenced in the thermal zone cooling map. +* * 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, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) +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_cooling_device *cdev;int ret;
@@ -592,4 +595,4 @@ devm_thermal_of_cooling_device_register(struct device *dev,return cdev; } -EXPORT_SYMBOL_GPL (devm_thermal_of_cooling_device_register); +EXPORT_SYMBOL_GPL (devm_thermal_of_child_cooling_device_register);
include/linux/thermal.h +8 -8
@@ -205,10 +205,10 @@ thermal_of_cooling_device_register(struct device_node *np, const char *type, voi const struct thermal_cooling_device_ops *ops);struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops); +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);#else static inline
@@ -232,10 +232,10 @@ thermal_of_cooling_device_register(struct device_node *np, }static inline struct thermal_cooling_device * -devm_thermal_of_cooling_device_register (struct device *dev, -struct device_node *np, -const char *type,void *devdata, -const struct thermal_cooling_device_ops *ops) +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) {return ERR_PTR (-ENODEV ); }
Signature · 1 line
2.43.0
PATCH v3 8/11 thermal/of: Introduce cooling device of_index
In reply to Daniel LezcanoAs described in the previous change, the new incoming DT binding will describe a tuple device_node + cooling device id, instead of child nodes.
Let's augment thermal_of_cooling_device_register() to receive the cooling device id and propagate the changes to the four remaining drivers using the non-devm version of the cooling device registering function.
Add the id in the cooling device structure and store the value when registering it.
--- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 5 +++-- drivers/thermal/cpufreq_cooling.c | 2 +- drivers/thermal/cpuidle_cooling.c | 2 +- drivers/thermal/devfreq_cooling.c | 2 +- drivers/thermal/thermal_of.c | 21 ++++++++++++++++----- include/linux/thermal.h | 6 ++++-- 6 files changed, 26 insertions(+), 12 deletions(-)
drivers/gpu/drm/etnaviv/etnaviv_gpu.c +3 -2
@@ -1791,8 +1791,9 @@ static int etnaviv_gpu_bind(struct device *dev, struct device *master,int ret;if (IS_ENABLED (CONFIG_DRM_ETNAVIV_THERMAL )) { - gpu->cooling =thermal_of_cooling_device_register (dev->of_node, - (char *)dev_name (dev), gpu, &cooling_ops); + gpu->cooling =thermal_of_cooling_device_register (dev->of_node,0 , +dev_name (dev), + gpu, &cooling_ops);if (IS_ERR (gpu->cooling))return PTR_ERR (gpu->cooling); }
drivers/thermal/cpufreq_cooling.c +1 -1
@@ -592,7 +592,7 @@ __cpufreq_cooling_register(struct device_node *np,if (!name) goto remove_qos_req; - cdev =thermal_of_cooling_device_register (np, name, cpufreq_cdev, + cdev =thermal_of_cooling_device_register (np,0 , name, cpufreq_cdev, cooling_ops);kfree (name);
drivers/thermal/cpuidle_cooling.c +1 -1
@@ -207,7 +207,7 @@ static int __cpuidle_cooling_register(struct device_node *np, goto out_unregister; } - cdev =thermal_of_cooling_device_register (np, name, idle_cdev, + cdev =thermal_of_cooling_device_register (np,0 , name, idle_cdev, &cpuidle_cooling_ops);if (IS_ERR (cdev)) { ret =PTR_ERR (cdev);
drivers/thermal/devfreq_cooling.c +1 -1
@@ -454,7 +454,7 @@ of_devfreq_cooling_register_power(struct device_node *np, struct devfreq *df,if (!name) goto remove_qos_req; - cdev =thermal_of_cooling_device_register (np, name, dfc, ops); + cdev =thermal_of_cooling_device_register (np,0 , name, dfc, ops);kfree (name);if (IS_ERR (cdev)) {
drivers/thermal/thermal_of.c +16 -5
@@ -511,16 +511,23 @@ void devm_thermal_of_zone_unregister(struct device *dev, struct thermal_zone_dev }EXPORT_SYMBOL_GPL (devm_thermal_of_zone_unregister); +struct thermal_of_cdev_init { +struct device_node *np; +int of_index; +}; +static void thermal_of_cooling_device_init (struct thermal_cooling_device *cdev,void *data) { -struct device_node *np = data; +struct thermal_of_cdev_init *of_cdev = data; - cdev->np = np; + cdev->np = of_cdev->np; + cdev->of_index = of_cdev->of_index; }/** * thermal_of_cooling_device_register() - register an OF thermal cooling device * @np: a pointer to a device tree node. +* @of_index: a cooling device index in the cooling controller * @type: the thermal cooling device type. * @devdata: device private data. * @ops: standard thermal cooling devices callbacks.
@@ -534,14 +541,18 @@ static void thermal_of_cooling_device_init(struct thermal_cooling_device *cdev,* ERR_PTR. Caller must check return value with IS_ERR*() helpers. */ struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, +thermal_of_cooling_device_register (struct device_node *np,int of_index,const char *type,void *devdata,const struct thermal_cooling_device_ops *ops) {struct thermal_cooling_device *cdev; +struct thermal_of_cdev_init of_cdev = { + .np = np, + .of_index = of_index, + }; cdev =__thermal_cooling_device_register (type, devdata, ops, - thermal_of_cooling_device_init, np); + thermal_of_cooling_device_init, &of_cdev);if (IS_ERR (cdev))return cdev;
@@ -585,7 +596,7 @@ devm_thermal_of_child_cooling_device_register(struct device *dev,struct thermal_cooling_device *cdev;int ret; - cdev =thermal_of_cooling_device_register (np, type, devdata, ops); + cdev =thermal_of_cooling_device_register (np,0 , type, devdata, ops);if (IS_ERR (cdev))return cdev;
include/linux/thermal.h +4 -2
@@ -134,6 +134,7 @@ struct thermal_cooling_device {struct list_head node;#ifdef CONFIG_THERMAL_OF struct device_node *np; +int of_index;#endif #ifdef CONFIG_THERMAL_DEBUGFS struct thermal_debugfs *debugfs;
@@ -201,7 +202,8 @@ struct thermal_zone_device *devm_thermal_of_zone_register(struct device *dev, invoid devm_thermal_of_zone_unregister (struct device *dev,struct thermal_zone_device *tz);struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np,const char *type,void *devdata, +thermal_of_cooling_device_register (struct device_node *np,int of_index, +const char *type,void *data,const struct thermal_cooling_device_ops *ops); struct thermal_cooling_device *
@@ -224,7 +226,7 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, }static inline struct thermal_cooling_device * -thermal_of_cooling_device_register (struct device_node *np, +thermal_of_cooling_device_register (struct device_node *np,int of_index,const char *type,void *devdata,const struct thermal_cooling_device_ops *ops) {
Signature · 1 line
2.43.0
PATCH v3 9/11 thermal/of: Pass the of_index and add a function to register with an index
In reply to Daniel LezcanoIntroduce a new function devm_thermal_of_cooling_device_register() which will register a cooling device and its id.
--- drivers/thermal/thermal_of.c | 58 ++++++++++++++++++++++++++++-------- include/linux/thermal.h | 13 ++++++++ 2 files changed, 59 insertions(+), 12 deletions(-)
drivers/thermal/thermal_of.c +46 -12
@@ -567,6 +567,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, +int of_index,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, of_index, 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. +* @of_index: 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,int of_index, +const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops) +{ +return __devm_thermal_of_cooling_device_register (dev, dev->of_node, of_index, + 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
@@ -593,17 +638,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);
include/linux/thermal.h +13 -0
@@ -206,6 +206,11 @@ thermal_of_cooling_device_register(struct device_node *np, int of_index, 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,int of_index, +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, int of_index,return ERR_PTR (-ENODEV ); } +static inline struct thermal_cooling_device * +devm_thermal_of_cooling_device_register (struct device *dev,int of_index, +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,
Signature · 1 line
2.43.0
PATCH v3 10/11 thermal/of: Process cooling device index in cooling-spec
In reply to Daniel LezcanoThe new DT bindings format describes a cooling device spec with the cooling device node, the id and the mitigation limits.
Depending on the version of the DT bindings, in order to bind, check with the device node pointer only or, in addition, the cooling device id.
--- drivers/thermal/thermal_of.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/thermal/thermal_of.c +22 -4
@@ -259,16 +259,34 @@ static bool thermal_of_get_cooling_spec(struct device_node *map_np, int index,of_node_put (cooling_spec.np); -if (cooling_spec.args_count <2 ) { -pr_err ("wrong reference to cooling device, missing limits\n" ); +/* +* There are two formats: +* - Legacy format : <&cdev lower upper> +* - New format : <&cdev of_index lower upper> +* +* With the new format, along with the device node pointer, +* the of_index must match with the cooling device of_index in +* order to bind +*/ +if (cooling_spec.args_count <2 || cooling_spec.args_count >3 ) { +pr_err ("Invalid number of cooling device parameters\n" );return false; } +if (cooling_spec.args_count ==3 && + cooling_spec.args[0 ] != cdev->of_index) +return false; +if (cooling_spec.np != cdev->np)return false; - c->lower = cooling_spec.args[0 ]; - c->upper = cooling_spec.args[1 ]; +if (cooling_spec.args_count !=3 ) { + c->lower = cooling_spec.args[0 ]; + c->upper = cooling_spec.args[1 ]; + }else { + c->lower = cooling_spec.args[1 ]; + c->upper = cooling_spec.args[2 ]; + } c->weight = weight;return true;
Signature · 1 line
2.43.0
PATCH v3 11/11 dt-bindings: thermal: cooling-devices: Update support for 3 cells cooling device
In reply to Daniel LezcanoFrom: Gaurav Kohli <[email protected]>
Extend the thermal cooling device binding to support a 3 cells specifier along with the 2 cells format.
Update #cooling-cells property to enum to support both 2 and 3 arguments.
Fix pwm-fan.yaml to restrict the number of cells to 'const: 2'
--- Documentation/devicetree/bindings/hwmon/pwm-fan.yaml | 3 ++- .../bindings/thermal/thermal-cooling-devices.yaml | 8 ++++++-- .../devicetree/bindings/thermal/thermal-zones.yaml | 3 ++- 3 files changed, 10 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/hwmon/pwm-fan.yaml +2 -1
@@ -63,7 +63,8 @@ properties: description: The PWM that is used to control the fan. maxItems: 1 - "#cooling-cells": true + "#cooling-cells": + const: 2 required: - compatible
Documentation/devicetree/bindings/thermal/thermal-cooling-devices.yaml +6 -2
@@ -44,10 +44,14 @@ select: true properties: "#cooling-cells": description: - Must be 2, in order to specify minimum and maximum cooling state used in + Must be 2 or 3. If 2, specifies minimum and maximum cooling state used in the cooling-maps reference. The first cell is the minimum cooling state and the second cell is the maximum cooling state requested. - const: 2 + If 3, the first cell specifies the thermal mitigation device specifier + index for devices that support multiple thermal mitigation mechanisms. + The two other cells are respectively the minimum cooling state and the + maximum cooling state. + enum: [2, 3] additionalProperties: true
Documentation/devicetree/bindings/thermal/thermal-zones.yaml +2 -1
@@ -214,7 +214,8 @@ patternProperties: device. Using the THERMAL_NO_LIMIT (-1UL) constant in the cooling-device phandle limit specifier lets the framework use the minimum and maximum cooling state for that cooling - device automatically. + device automatically. If three arguments are specified, + the first argument is the cooling device specifier. contribution: $ref: /schemas/types.yaml#/definitions/uint32
Signature · 1 line
2.43.0
Re: [PATCH v3 01/11] thermal/core: Use devm_add_action_or_reset() when registering a cooling device
In reply to Daniel LezcanoQuoted 5 lines · Daniel Lezcano
Use
devm_add_action_or_reset()which does the replaced code. It results in a simpler and more concise code.Signed-off-by Daniel Lezcano <[email protected]>
Quoted 59 lines
--- drivers/thermal/thermal_core.c | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-)drivers/thermal/thermal_core.c +13
-18@@ -1187,10 +1187,11 @@ thermal_of_cooling_device_register(struct device_node *np, }EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register); -static void thermal_cooling_device_release (struct device *dev,void *res) +static void thermal_cooling_device_release (void *data) { -thermal_cooling_device_unregister ( - *(struct thermal_cooling_device **)res); +struct thermal_cooling_device *cdev = data; + +thermal_cooling_device_unregister (cdev); }/** @@ -1216,23 +1217,18 @@ devm_thermal_of_cooling_device_register(struct device *dev, const char *type, void *devdata, const struct thermal_cooling_device_ops *ops) { - struct thermal_cooling_device **ptr, *tcd; + struct thermal_cooling_device *cdev; +int ret; - ptr =devres_alloc (thermal_cooling_device_release,sizeof (*ptr), -GFP_KERNEL ); -if (!ptr) -return ERR_PTR (-ENOMEM ); + cdev =__thermal_cooling_device_register (np, type, devdata, ops); +if (IS_ERR (cdev)) +return cdev; - tcd =__thermal_cooling_device_register (np, type, devdata, ops); -if (IS_ERR (tcd)) { -devres_free (ptr); -return tcd; - } - - *ptr = tcd; -devres_add (dev, ptr); + ret =devm_add_action_or_reset (dev, thermal_cooling_device_release, cdev); +if (ret) +return ERR_PTR (ret); -return tcd; +return cdev; }EXPORT_SYMBOL_GPL (devm_thermal_of_cooling_device_register); --2.43.0
Rafael J. Wysocki
maintainerRe: [PATCH v3 02/11] thermal/core: Add a non-OF registering function
In reply to Daniel LezcanoQuoted 41 lines · Daniel Lezcano
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 <[email protected]>--- drivers/thermal/thermal_core.c | 35 ++++++++++++++++++++++++++++++++++ include/linux/thermal.h | 16 ++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-)drivers/thermal/thermal_core.c +22
-0@@ -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;
drivers/thermal/thermal_core.c static void thermal_cooling_device_release(void *data) · line 1228
Quoted 10 lines
drivers/thermal/thermal_core.c +10
-0+ + 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;
After the previous patch, this may just be a wrapper around devm_thermal_of_cooling_device_register() passing NULL as np to it.
Quoted 44 lines
drivers/thermal/thermal_core.c +3
-0+} +EXPORT_SYMBOL_GPL (devm_thermal_cooling_device_register); +/** * devm_thermal_of_cooling_device_register() - register an OF thermal cooling * device include/linux/thermal.h +14
-3@@ -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
Rafael J. Wysocki
maintainerRe: [PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file
In reply to Daniel LezcanoQuoted 7 lines · Daniel Lezcano
The node pointer being assigned to the cooling device structure is an action done by the thermal OF only and does not belong to the core framework code. Move the node pointer assignation in the thermal OF code. Consequently, the
devm_thermal_of_cooling_device_register()can call its non-devm version resulting in a more intuitive design of the API.
I wouldn't make this change.
It adds overhead to the OF case that's not really necessary and complicates the code just to avoid using struct device_node pointers in the core and I'm not really convinced that passing a function pointer to __thermal_cooling_device_register() is so much better.
Quoted 123 lines
Signed-off-by Daniel Lezcano <[email protected]>--- drivers/thermal/thermal_core.c | 51 +++++++++++++++++----------------- 1 file changed, 26 insertions(+), 25 deletions(-)drivers/thermal/thermal_core.c +26
-26@@ -1040,26 +1040,11 @@ static void thermal_cooling_device_init_complete(struct thermal_cooling_device *thermal_zone_cdev_bind (tz, cdev); } -/** -* __thermal_cooling_device_register() - register a new thermal cooling device -* @np: a pointer to a device tree node. -* @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. -* 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) +__thermal_cooling_device_register (const char *type,void *devdata, +const struct thermal_cooling_device_ops *ops, +void (*initcb)(struct thermal_cooling_device *, +void *),void *data) {struct thermal_cooling_device *cdev;unsigned long current_state;@@ -1089,7 +1074,6 @@ __thermal_cooling_device_register(struct device_node *np,mutex_init (&cdev->lock);INIT_LIST_HEAD (&cdev->thermal_instances); - cdev->np = np; cdev->ops = ops; cdev->updated = false; cdev->device.class = &thermal_class;@@ -1127,6 +1111,9 @@ __thermal_cooling_device_register(struct device_node *np,if (current_state <= cdev->max_state)thermal_debug_cdev_add (cdev, current_state); +if (initcb) +initcb (cdev, data); +thermal_cooling_device_init_complete (cdev);return cdev;@@ -1146,7 +1133,7 @@ __thermal_cooling_device_register(struct device_node *np,* 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. +* @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 @@ -1159,10 +1146,17 @@ 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); + return __thermal_cooling_device_register(type, devdata, ops, NULL, NULL); }EXPORT_SYMBOL_GPL (thermal_cooling_device_register); +static void thermal_of_cooling_device_init (struct thermal_cooling_device *cdev,void *data) +{ +struct device_node *np = data; + + cdev->np = np; +} +/** * thermal_of_cooling_device_register() - register an OF thermal cooling device * @np: a pointer to a device tree node. @@ -1183,7 +1177,14 @@ thermal_of_cooling_device_register(struct device_node *np, 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; + + cdev =__thermal_cooling_device_register (type, devdata, ops, + thermal_of_cooling_device_init, np); +if (IS_ERR (cdev)) +return cdev; + +return cdev; }EXPORT_SYMBOL_GPL (thermal_of_cooling_device_register);@@ -1217,7 +1218,7 @@ devm_thermal_cooling_device_register(struct device *dev,struct thermal_cooling_device *cdev;int ret; - cdev =__thermal_cooling_device_register (NULL , type, devdata, ops); + cdev =thermal_cooling_device_register (type, devdata, ops);if (IS_ERR (cdev))return cdev;@@ -1255,7 +1256,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; --2.43.0
Rafael J. Wysocki
maintainerRe: [PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Daniel Lezcano
The node pointer being assigned to the cooling device structure is an action done by the thermal OF only and does not belong to the core framework code. Move the node pointer assignation in the thermal OF code. Consequently, the
devm_thermal_of_cooling_device_register()can call its non-devm version resulting in a more intuitive design of the API.
Quoted 6 lines
I wouldn't make this change.
It adds overhead to the OF case that's not really necessary and complicates the code just to avoid using struct
device_nodepointers in the core and I'm not really convinced that passing a function pointer to__thermal_cooling_device_register()is so much better.
I would start with splitting __thermal_cooling_device_register() so that it becomes (sorry for the white space breakage induced by GMail)
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 *cdev;
cdev = thermal_cooling_device_alloc(ops);
if (IS_ERR(cdev))
return cdev;
cdev->np = np;
return thermal_cooling_device_add(cdev, type, devdata, ops);
}where thermal_cooling_device_alloc() does all of the ops and other checks and the cdev struct allocation, and thermal_cooling_device_add() does everything else previously done by __thermal_cooling_device_register() itself.
Then, it could be renamed to __thermal_of_cooling_device_register() and the non-of variant would simply skip the np assignment (and it would not take np as an argument).
You can deal with the devm_ variants of the above analogously.
Re: [PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file
Quoted 43 lines · Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Daniel Lezcano
The node pointer being assigned to the cooling device structure is an action done by the thermal OF only and does not belong to the core framework code. Move the node pointer assignation in the thermal OF code. Consequently, the
devm_thermal_of_cooling_device_register()can call its non-devm version resulting in a more intuitive design of the API.Quoted 6 lines
I wouldn't make this change.
It adds overhead to the OF case that's not really necessary and complicates the code just to avoid using struct
device_nodepointers in the core and I'm not really convinced that passing a function pointer to__thermal_cooling_device_register()is so much better.I would start with splitting
__thermal_cooling_device_register()so that it becomes (sorry for the white space breakage induced by GMail)static struct
thermal_cooling_device* __thermal_cooling_device_register(structdevice_node*np,
const char *type, void *devdata, const structthermal_cooling_device_ops*ops){ struct thermal_cooling_device *cdev; cdev = thermal_cooling_device_alloc(ops); if (IS_ERR(cdev)) return cdev; cdev->np = np; return thermal_cooling_device_add(cdev, type, devdata, ops); }where
thermal_cooling_device_alloc()does all of the ops and other checks and the cdev struct allocation, andthermal_cooling_device_add()does everything else previously done by__thermal_cooling_device_register()itself.
Quoted 5 lines
Then, it could be renamed to
__thermal_of_cooling_device_register()and the non-of variant would simply skip the np assignment (and it would not take np as an argument).You can deal with the
devm_variants of the above analogously.
So we will end up with:
static 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 *cdev;
cdev = thermal_cooling_device_alloc(ops);
if (IS_ERR(cdev))
return cdev;
cdev->np = np;
return thermal_cooling_device_add(cdev, type, devdata, ops);
}and
static 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;
cdev = thermal_cooling_device_alloc(ops);
if (IS_ERR(cdev))
return cdev;
return thermal_cooling_device_add(cdev, type, devdata, ops);
}Right ?
That is what I did more or less initially [1]. It resulted into exporting thermal_cooling_device_init_complete(). Here it is similar, with other functions.
The reason why I added an init callback in the thermal_cooling_device_register() function is to centralize the cooling device register logic into the core code only.
By exporting the thermal_cooling_device_add() and thermal_cooling_device_alloc() we duplicate the logic and IMO it is not desirable.
By introducing a init callback, the core code gives the opportunity to any extra layers to initialize some private data in the cooling device before the init completion
Rafael J. Wysocki
maintainerRe: [PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file
Quoted 84 lines · Daniel Lezcano
Quoted 43 lines · Rafael J. Wysocki
Quoted 11 lines · Rafael J. Wysocki
Quoted 7 lines · Daniel Lezcano
The node pointer being assigned to the cooling device structure is an action done by the thermal OF only and does not belong to the core framework code. Move the node pointer assignation in the thermal OF code. Consequently, the
devm_thermal_of_cooling_device_register()can call its non-devm version resulting in a more intuitive design of the API.Quoted 6 lines
I wouldn't make this change.
It adds overhead to the OF case that's not really necessary and complicates the code just to avoid using struct
device_nodepointers in the core and I'm not really convinced that passing a function pointer to__thermal_cooling_device_register()is so much better.I would start with splitting
__thermal_cooling_device_register()so that it becomes (sorry for the white space breakage induced by GMail)static struct
thermal_cooling_device* __thermal_cooling_device_register(structdevice_node*np,
const char *type, void *devdata, const structthermal_cooling_device_ops*ops){ struct thermal_cooling_device *cdev; cdev = thermal_cooling_device_alloc(ops); if (IS_ERR(cdev)) return cdev; cdev->np = np; return thermal_cooling_device_add(cdev, type, devdata, ops); }where
thermal_cooling_device_alloc()does all of the ops and other checks and the cdev struct allocation, andthermal_cooling_device_add()does everything else previously done by__thermal_cooling_device_register()itself.Quoted 5 lines
Then, it could be renamed to
__thermal_of_cooling_device_register()and the non-of variant would simply skip the np assignment (and it would not take np as an argument).You can deal with the
devm_variants of the above analogously.So we will end up with:
static struct
thermal_cooling_device* __thermal_of_cooling_device_register(structdevice_node*np,
const char *type, void *devdata, const structthermal_cooling_device_ops*ops){ struct thermal_cooling_device *cdev; cdev = thermal_cooling_device_alloc(ops); if (IS_ERR(cdev)) return cdev; cdev->np = np; return thermal_cooling_device_add(cdev, type, devdata, ops); }and
static struct
thermal_cooling_device* __thermal_cooling_device_register(const char *type, void *devdata,
const structthermal_cooling_device_ops*ops){ struct thermal_cooling_device *cdev; cdev = thermal_cooling_device_alloc(ops); if (IS_ERR(cdev)) return cdev; return thermal_cooling_device_add(cdev, type, devdata, ops); }
Quoted 5 lines
Right ?
That is what I did more or less initially [1]. It resulted into exporting
thermal_cooling_device_init_complete(). Here it is similar, with other functions.
They don't need to be exported outside the thermal subsystem though and they don't need to be exported to modules.
Quoted 3 lines
The reason why I added an init callback in the
thermal_cooling_device_register()function is to centralize the cooling device register logic into the core code only.
That still would be done by the core code.
Quoted 3 lines
By exporting the
thermal_cooling_device_add()andthermal_cooling_device_alloc()we duplicate the logic and IMO it is not desirable.
Well, you want the logic to be duplicate, kind of, if you want both the OF and non-OF variants to be there.
Quoted 6 lines
By introducing a init callback, the core code gives the opportunity to any extra layers to initialize some private data in the cooling device before the init completion
I don't think that adding the init callback is a good idea, sorry.
Re: [PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file
On 5/5/26 12:20, Rafael J. Wysocki wrote:
[ ... ]
Quoted 4 lines
Quoted 2 lines
I don't think that adding the init callback is a good idea, sorry.
Ok.
May I create a separate preparatory changes splitting the function and then rebase the current series on top of it ? So we end up with smaller chunk of changes ?
Rafael J. Wysocki
maintainerRe: [PATCH v3 03/11] thermal/of: Move the node pointer assignation in the OF code file
Quoted 8 lines · Daniel Lezcano
On 5/5/26 12:20, Rafael J. Wysocki wrote:
[ ... ]
Quoted 3 lines
Quoted 2 lines
Quoted 7 lines
Quoted 1 line
I don't think that adding the init callback is a good idea, sorry.
Ok.
May I create a separate preparatory changes splitting the function and then rebase the current series on top of it ? So we end up with smaller chunk of changes ?
Sure, go ahead.
Re: [PATCH v3 01/11] thermal/core: Use devm_add_action_or_reset() when registering a cooling device
In reply to Rafael J. WysockiQuoted 11 lines · Rafael J. Wysocki
Quoted 5 lines · Daniel Lezcano
Use
devm_add_action_or_reset()which does the replaced code. It results in a simpler and more concise code.Signed-off-by Daniel Lezcano <[email protected]>Reviewed-by Rafael J. Wysocki (Intel) <[email protected]>Quoted 1 line
---
I've applied this change on my tree
Thanks