Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal: int340x: Use thermal_zone_for_each_trip()

Modify int340x_thermal_update_trips() to use thermal_zone_for_each_trip()
for walking trips instead of using the trips[] table passed to the
thermal zone registration function.

For this purpose, store active trip point indices in the priv fieids of
the corresponding thermal_trip structures.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>

+43 -37
+43 -37
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
··· 67 67 .critical = int340x_thermal_critical, 68 68 }; 69 69 70 + static inline void *int_to_trip_priv(int i) 71 + { 72 + return (void *)(long)i; 73 + } 74 + 75 + static inline int trip_priv_to_int(const struct thermal_trip *trip) 76 + { 77 + return (long)trip->priv; 78 + } 79 + 70 80 static int int340x_thermal_read_trips(struct acpi_device *zone_adev, 71 81 struct thermal_trip *zone_trips, 72 82 int trip_cnt) ··· 111 101 break; 112 102 113 103 zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE; 104 + zone_trips[trip_cnt].priv = int_to_trip_priv(i); 114 105 trip_cnt++; 115 106 } 116 107 ··· 223 212 } 224 213 EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove); 225 214 215 + static int int340x_update_one_trip(struct thermal_trip *trip, void *arg) 216 + { 217 + struct acpi_device *zone_adev = arg; 218 + int temp, err; 219 + 220 + switch (trip->type) { 221 + case THERMAL_TRIP_CRITICAL: 222 + err = thermal_acpi_critical_trip_temp(zone_adev, &temp); 223 + break; 224 + case THERMAL_TRIP_HOT: 225 + err = thermal_acpi_hot_trip_temp(zone_adev, &temp); 226 + break; 227 + case THERMAL_TRIP_PASSIVE: 228 + err = thermal_acpi_passive_trip_temp(zone_adev, &temp); 229 + break; 230 + case THERMAL_TRIP_ACTIVE: 231 + err = thermal_acpi_active_trip_temp(zone_adev, 232 + trip_priv_to_int(trip), 233 + &temp); 234 + break; 235 + default: 236 + err = -ENODEV; 237 + } 238 + if (err) 239 + temp = THERMAL_TEMP_INVALID; 240 + 241 + trip->temperature = temp; 242 + return 0; 243 + } 244 + 226 245 void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone) 227 246 { 228 - struct acpi_device *zone_adev = int34x_zone->adev; 229 - struct thermal_trip *zone_trips = int34x_zone->trips; 230 - int trip_cnt = int34x_zone->zone->num_trips; 231 - int act_trip_nr = 0; 232 - int i; 233 - 234 - mutex_lock(&int34x_zone->zone->lock); 235 - 236 - for (i = int34x_zone->aux_trip_nr; i < trip_cnt; i++) { 237 - int temp, err; 238 - 239 - switch (zone_trips[i].type) { 240 - case THERMAL_TRIP_CRITICAL: 241 - err = thermal_acpi_critical_trip_temp(zone_adev, &temp); 242 - break; 243 - case THERMAL_TRIP_HOT: 244 - err = thermal_acpi_hot_trip_temp(zone_adev, &temp); 245 - break; 246 - case THERMAL_TRIP_PASSIVE: 247 - err = thermal_acpi_passive_trip_temp(zone_adev, &temp); 248 - break; 249 - case THERMAL_TRIP_ACTIVE: 250 - err = thermal_acpi_active_trip_temp(zone_adev, act_trip_nr++, 251 - &temp); 252 - break; 253 - default: 254 - err = -ENODEV; 255 - } 256 - if (err) { 257 - zone_trips[i].temperature = THERMAL_TEMP_INVALID; 258 - continue; 259 - } 260 - 261 - zone_trips[i].temperature = temp; 262 - } 263 - 264 - mutex_unlock(&int34x_zone->zone->lock); 247 + thermal_zone_for_each_trip(int34x_zone->zone, int340x_update_one_trip, 248 + int34x_zone->adev); 265 249 } 266 250 EXPORT_SYMBOL_GPL(int340x_thermal_update_trips); 267 251