]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
thermal: tegra: Use thermal_zone_for_each_trip() for walking trip points
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 1 Aug 2024 12:09:30 +0000 (14:09 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 2 Aug 2024 11:50:04 +0000 (13:50 +0200)
It is generally inefficient to iterate over trip indices and call
thermal_zone_get_trip() every time to get the struct thermal_trip
corresponding to the given trip index, so modify the Tegra thermal
drivers to use thermal_zone_for_each_trip() for walking trips.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Link: https://patch.msgid.link/1819430.VLH7GnMWUR@rjwysocki.net
[ rjw: Dropped an unused local variable ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/tegra/soctherm.c
drivers/thermal/tegra/tegra30-tsensor.c

index d3dfc34c62c6844ab60de141f04bdfc0a6e80226..a023c948afbddd6d9fc1a00b2fe310c71147bda9 100644 (file)
@@ -682,24 +682,25 @@ static const struct thermal_zone_device_ops tegra_of_thermal_ops = {
        .set_trips = tegra_thermctl_set_trips,
 };
 
-static int get_hot_temp(struct thermal_zone_device *tz, int *trip_id, int *temp)
+static int get_hot_trip_cb(struct thermal_trip *trip, void *arg)
 {
-       int i, ret;
-       struct thermal_trip trip;
+       const struct thermal_trip **trip_ret = arg;
 
-       for (i = 0; i < thermal_zone_get_num_trips(tz); i++) {
+       if (trip->type != THERMAL_TRIP_HOT)
+               return 0;
 
-               ret = thermal_zone_get_trip(tz, i, &trip);
-               if (ret)
-                       return -EINVAL;
+       *trip_ret = trip;
+       /* Return nonzero to terminate the search. */
+       return 1;
+}
 
-               if (trip.type == THERMAL_TRIP_HOT) {
-                       *trip_id = i;
-                       return 0;
-               }
-       }
+static const struct thermal_trip *get_hot_trip(struct thermal_zone_device *tz)
+{
+       const struct thermal_trip *trip = NULL;
 
-       return -EINVAL;
+       thermal_zone_for_each_trip(tz, get_hot_trip_cb, &trip);
+
+       return trip;
 }
 
 /**
@@ -731,8 +732,9 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
                                      struct thermal_zone_device *tz)
 {
        struct tegra_soctherm *ts = dev_get_drvdata(dev);
+       const struct thermal_trip *hot_trip;
        struct soctherm_throt_cfg *stc;
-       int i, trip, temperature, ret;
+       int i, temperature, ret;
 
        /* Get thermtrips. If missing, try to get critical trips. */
        temperature = tsensor_group_thermtrip_get(ts, sg->id);
@@ -749,8 +751,8 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
        dev_info(dev, "thermtrip: will shut down when %s reaches %d mC\n",
                 sg->name, temperature);
 
-       ret = get_hot_temp(tz, &trip, &temperature);
-       if (ret) {
+       hot_trip = get_hot_trip(tz);
+       if (!hot_trip) {
                dev_info(dev, "throttrip: %s: missing hot temperature\n",
                         sg->name);
                return 0;
@@ -763,7 +765,7 @@ static int tegra_soctherm_set_hwtrips(struct device *dev,
                        continue;
 
                cdev = ts->throt_cfgs[i].cdev;
-               if (get_thermal_instance(tz, cdev, trip))
+               if (thermal_trip_is_bound_to_cdev(tz, hot_trip, cdev))
                        stc = find_throttle_cfg_by_name(ts, cdev->type);
                else
                        continue;
index de50f4618265d63dbf82d51732cd63f11cdf7e4c..6245f6b97f43ec4e022527d97ede22c05ebea46d 100644 (file)
@@ -308,11 +308,21 @@ struct trip_temps {
        int crit_trip;
 };
 
+static int tegra_tsensor_get_trips_cb(struct thermal_trip *trip, void *arg)
+{
+       struct trip_temps *temps = arg;
+
+       if (trip->type == THERMAL_TRIP_HOT)
+               temps->hot_trip = trip->temperature;
+       else if (trip->type == THERMAL_TRIP_CRITICAL)
+               temps->crit_trip = trip->temperature;
+
+       return 0;
+}
+
 static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
                                               struct trip_temps *temps)
 {
-       unsigned int i;
-
        /*
         * 90C is the maximal critical temperature of all Tegra30 SoC variants,
         * use it for the default trip if unspecified in a device-tree.
@@ -320,18 +330,7 @@ static void tegra_tsensor_get_hw_channel_trips(struct thermal_zone_device *tzd,
        temps->hot_trip  = 85000;
        temps->crit_trip = 90000;
 
-       for (i = 0; i < thermal_zone_get_num_trips(tzd); i++) {
-
-               struct thermal_trip trip;
-
-               thermal_zone_get_trip(tzd, i, &trip);
-
-               if (trip.type == THERMAL_TRIP_HOT)
-                       temps->hot_trip = trip.temperature;
-
-               if (trip.type == THERMAL_TRIP_CRITICAL)
-                       temps->crit_trip = trip.temperature;
-       }
+       thermal_zone_for_each_trip(tzd, tegra_tsensor_get_trips_cb, temps);
 
        /* clamp hardware trips to the calibration limits */
        temps->hot_trip = clamp(temps->hot_trip, 25000, 90000);