thermal: core: Allow trip pointers to be used for cooling device binding
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 21 Sep 2023 18:01:43 +0000 (20:01 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 28 Sep 2023 10:57:10 +0000 (12:57 +0200)
Add new helper functions, thermal_bind_cdev_to_trip() and
thermal_unbind_cdev_from_trip(), to allow a trip pointer to be used for
binding a cooling device to a trip point and unbinding it, respectively,
and redefine the existing helpers, thermal_zone_bind_cooling_device()
and thermal_zone_unbind_cooling_device(), as wrappers around the new
ones, respectively.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org>
drivers/thermal/thermal_core.c
include/linux/thermal.h

index 31fe14a96d137418f62fb938e3c7307bcccc94bc..45d0aa0b69b79c0fd21ba4643280e3dd7da19deb 100644 (file)
@@ -600,10 +600,9 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
  */
 
 /**
- * thermal_zone_bind_cooling_device() - bind a cooling device to a thermal zone
+ * thermal_bind_cdev_to_trip - bind a cooling device to a thermal zone
  * @tz:                pointer to struct thermal_zone_device
- * @trip_index:        indicates which trip point the cooling devices is
- *             associated with in this thermal zone.
+ * @trip:      trip point the cooling devices is associated with in this zone.
  * @cdev:      pointer to struct thermal_cooling_device
  * @upper:     the Maximum cooling state for this trip point.
  *             THERMAL_NO_LIMIT means no upper limit,
@@ -621,8 +620,8 @@ struct thermal_zone_device *thermal_zone_get_by_id(int id)
  *
  * Return: 0 on success, the proper error value otherwise.
  */
-int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
-                                    int trip_index,
+int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
+                                    const struct thermal_trip *trip,
                                     struct thermal_cooling_device *cdev,
                                     unsigned long upper, unsigned long lower,
                                     unsigned int weight)
@@ -631,15 +630,9 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
        struct thermal_instance *pos;
        struct thermal_zone_device *pos1;
        struct thermal_cooling_device *pos2;
-       const struct thermal_trip *trip;
        bool upper_no_limit;
        int result;
 
-       if (trip_index >= tz->num_trips || trip_index < 0)
-               return -EINVAL;
-
-       trip = &tz->trips[trip_index];
-
        list_for_each_entry(pos1, &thermal_tz_list, node) {
                if (pos1 == tz)
                        break;
@@ -736,14 +729,26 @@ free_mem:
        kfree(dev);
        return result;
 }
+EXPORT_SYMBOL_GPL(thermal_bind_cdev_to_trip);
+
+int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
+                                    int trip_index,
+                                    struct thermal_cooling_device *cdev,
+                                    unsigned long upper, unsigned long lower,
+                                    unsigned int weight)
+{
+       if (trip_index < 0 || trip_index >= tz->num_trips)
+               return -EINVAL;
+
+       return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index], cdev,
+                                        upper, lower, weight);
+}
 EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
 
 /**
- * thermal_zone_unbind_cooling_device() - unbind a cooling device from a
- *                                       thermal zone.
+ * thermal_unbind_cdev_from_trip - unbind a cooling device from a thermal zone.
  * @tz:                pointer to a struct thermal_zone_device.
- * @trip_index:        indicates which trip point the cooling devices is
- *             associated with in this thermal zone.
+ * @trip:      trip point the cooling devices is associated with in this zone.
  * @cdev:      pointer to a struct thermal_cooling_device.
  *
  * This interface function unbind a thermal cooling device from the certain
@@ -752,16 +757,14 @@ EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
  *
  * Return: 0 on success, the proper error value otherwise.
  */
-int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
-                                      int trip_index,
-                                      struct thermal_cooling_device *cdev)
+int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
+                                 const struct thermal_trip *trip,
+                                 struct thermal_cooling_device *cdev)
 {
        struct thermal_instance *pos, *next;
-       const struct thermal_trip *trip;
 
        mutex_lock(&tz->lock);
        mutex_lock(&cdev->lock);
-       trip = &tz->trips[trip_index];
        list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
                if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) {
                        list_del(&pos->tz_node);
@@ -784,6 +787,17 @@ unbind:
        kfree(pos);
        return 0;
 }
+EXPORT_SYMBOL_GPL(thermal_unbind_cdev_from_trip);
+
+int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
+                                      int trip_index,
+                                      struct thermal_cooling_device *cdev)
+{
+       if (trip_index < 0 || trip_index >= tz->num_trips)
+               return -EINVAL;
+
+       return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index], cdev);
+}
 EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);
 
 static void thermal_release(struct device *dev)
index 6cfcae22ba123acd6c14de5a16c2340b0adb1b35..6710a4ace992af48c1974ac2abc2ffc84697352b 100644 (file)
@@ -320,10 +320,18 @@ const char *thermal_zone_device_type(struct thermal_zone_device *tzd);
 int thermal_zone_device_id(struct thermal_zone_device *tzd);
 struct device *thermal_zone_device(struct thermal_zone_device *tzd);
 
+int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
+                             const struct thermal_trip *trip,
+                             struct thermal_cooling_device *cdev,
+                             unsigned long upper, unsigned long lower,
+                             unsigned int weight);
 int thermal_zone_bind_cooling_device(struct thermal_zone_device *, int,
                                     struct thermal_cooling_device *,
                                     unsigned long, unsigned long,
                                     unsigned int);
+int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
+                                 const struct thermal_trip *trip,
+                                 struct thermal_cooling_device *cdev);
 int thermal_zone_unbind_cooling_device(struct thermal_zone_device *, int,
                                       struct thermal_cooling_device *);
 void thermal_zone_device_update(struct thermal_zone_device *,