diff mbox series

[1/2] thermal: Add support for cooling device bind/unbind operations

Message ID 20230209163555.1993557-1-thierry.reding@gmail.com (mailing list archive)
State New, archived
Delegated to: Daniel Lezcano
Headers show
Series [1/2] thermal: Add support for cooling device bind/unbind operations | expand

Commit Message

Thierry Reding Feb. 9, 2023, 4:35 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

Drivers for cooling devices can implement these operations when they
need to perform extra work at the time when a cooling device is bound to
a given thermal zone.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 drivers/thermal/thermal_core.c | 11 +++++++++++
 include/linux/thermal.h        |  6 ++++++
 2 files changed, 17 insertions(+)

Comments

Daniel Lezcano Feb. 10, 2023, 12:31 p.m. UTC | #1
On Thu, Feb 09, 2023 at 05:35:54PM +0100, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Drivers for cooling devices can implement these operations when they
> need to perform extra work at the time when a cooling device is bound to
> a given thermal zone.

The approach is not correct.

I'll react to the initial email:

Re: thermal/drivers/tegra: Getting rid of the get_thermal_instance() usage

https://lore.kernel.org/all/Y9J4WAFyXyV%2FnqlG@orome/


 <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
diff mbox series

Patch

diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 0675df54c8e6..627fccd100ef 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -694,6 +694,14 @@  int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
 	mutex_unlock(&cdev->lock);
 	mutex_unlock(&tz->lock);
 
+	if (cdev->ops->bind) {
+		result = cdev->ops->bind(cdev, tz, trip, upper, lower, weight);
+		if (result < 0) {
+			pr_err("failed to bind %s to %s: %d\n", cdev->type,
+			       tz->type, result);
+		}
+	}
+
 	if (!result)
 		return 0;
 
@@ -730,6 +738,9 @@  int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
 {
 	struct thermal_instance *pos, *next;
 
+	if (cdev->ops->unbind)
+		cdev->ops->unbind(cdev, tz, trip);
+
 	mutex_lock(&tz->lock);
 	mutex_lock(&cdev->lock);
 	list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index 2bb4bf33f4f3..95ed8a0cbba8 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -89,6 +89,12 @@  struct thermal_trip {
 };
 
 struct thermal_cooling_device_ops {
+	int (*bind)(struct thermal_cooling_device *cdev,
+		    struct thermal_zone_device *tz, int trip_id,
+		    unsigned long upper, unsigned long lower,
+		    unsigned int weight);
+	void (*unbind)(struct thermal_cooling_device *cdev,
+		       struct thermal_zone_device *tz, int trip_id);
 	int (*get_max_state) (struct thermal_cooling_device *, unsigned long *);
 	int (*get_cur_state) (struct thermal_cooling_device *, unsigned long *);
 	int (*set_cur_state) (struct thermal_cooling_device *, unsigned long);