@@ -177,6 +177,15 @@ static bool acpi_thermal_trip_valid(struct acpi_thermal_trip *acpi_trip)
177
177
return acpi_trip -> temp_dk != THERMAL_TEMP_INVALID ;
178
178
}
179
179
180
+ static int active_trip_index (struct acpi_thermal * tz ,
181
+ struct acpi_thermal_trip * acpi_trip )
182
+ {
183
+ struct acpi_thermal_active * active ;
184
+
185
+ active = container_of (acpi_trip , struct acpi_thermal_active , trip );
186
+ return active - tz -> trips .active ;
187
+ }
188
+
180
189
static long get_passive_temp (struct acpi_thermal * tz )
181
190
{
182
191
unsigned long long tmp ;
@@ -213,21 +222,18 @@ static long get_active_temp(struct acpi_thermal *tz, int index)
213
222
}
214
223
215
224
static void acpi_thermal_update_trip (struct acpi_thermal * tz ,
216
- int index )
225
+ const struct thermal_trip * trip )
217
226
{
218
- struct acpi_thermal_trip * acpi_trip ;
219
-
220
- acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
221
- & tz -> trips .passive .trip : & tz -> trips .active [index ].trip ;
222
- if (!acpi_thermal_trip_valid (acpi_trip ))
223
- return ;
227
+ struct acpi_thermal_trip * acpi_trip = trip -> priv ;
224
228
225
- if (index == ACPI_THERMAL_TRIP_PASSIVE ) {
229
+ if (trip -> type == THERMAL_TRIP_PASSIVE ) {
226
230
if (psv > 0 )
227
231
return ;
228
232
229
233
acpi_trip -> temp_dk = get_passive_temp (tz );
230
234
} else {
235
+ int index = active_trip_index (tz , acpi_trip );
236
+
231
237
acpi_trip -> temp_dk = get_active_temp (tz , index );
232
238
}
233
239
@@ -264,31 +270,39 @@ static bool update_trip_devices(struct acpi_thermal *tz,
264
270
return true;
265
271
}
266
272
267
- static void acpi_thermal_update_trip_devices (struct acpi_thermal * tz , int index )
273
+ static void acpi_thermal_update_trip_devices (struct acpi_thermal * tz ,
274
+ const struct thermal_trip * trip )
268
275
{
269
- struct acpi_thermal_trip * acpi_trip ;
270
-
271
- acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
272
- & tz -> trips .passive .trip : & tz -> trips .active [index ].trip ;
273
- if (!acpi_thermal_trip_valid (acpi_trip ))
274
- return ;
276
+ struct acpi_thermal_trip * acpi_trip = trip -> priv ;
277
+ int index = trip -> type == THERMAL_TRIP_PASSIVE ?
278
+ ACPI_THERMAL_TRIP_PASSIVE : active_trip_index (tz , acpi_trip );
275
279
276
- if (update_trip_devices (tz , acpi_trip , index , true)) {
280
+ if (update_trip_devices (tz , acpi_trip , index , true))
277
281
return ;
278
- }
279
282
280
283
acpi_trip -> temp_dk = THERMAL_TEMP_INVALID ;
281
284
ACPI_THERMAL_TRIPS_EXCEPTION (tz , "state" );
282
285
}
283
286
287
+ struct adjust_trip_data {
288
+ struct acpi_thermal * tz ;
289
+ u32 event ;
290
+ };
291
+
284
292
static int acpi_thermal_adjust_trip (struct thermal_trip * trip , void * data )
285
293
{
286
294
struct acpi_thermal_trip * acpi_trip = trip -> priv ;
287
- struct acpi_thermal * tz = data ;
295
+ struct adjust_trip_data * atd = data ;
296
+ struct acpi_thermal * tz = atd -> tz ;
288
297
289
- if (!acpi_trip )
298
+ if (!acpi_trip || ! acpi_thermal_trip_valid ( acpi_trip ) )
290
299
return 0 ;
291
300
301
+ if (atd -> event == ACPI_THERMAL_NOTIFY_THRESHOLDS )
302
+ acpi_thermal_update_trip (tz , trip );
303
+ else
304
+ acpi_thermal_update_trip_devices (tz , trip );
305
+
292
306
if (acpi_thermal_trip_valid (acpi_trip ))
293
307
trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temp_dk );
294
308
else
@@ -297,25 +311,6 @@ static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
297
311
return 0 ;
298
312
}
299
313
300
- static void acpi_thermal_adjust_thermal_zone (struct thermal_zone_device * thermal ,
301
- unsigned long data )
302
- {
303
- struct acpi_thermal * tz = thermal_zone_device_priv (thermal );
304
- int i ;
305
-
306
- if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS ) {
307
- acpi_thermal_update_trip (tz , ACPI_THERMAL_TRIP_PASSIVE );
308
- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
309
- acpi_thermal_update_trip (tz , i );
310
- } else {
311
- acpi_thermal_update_trip_devices (tz , ACPI_THERMAL_TRIP_PASSIVE );
312
- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
313
- acpi_thermal_update_trip_devices (tz , i );
314
- }
315
-
316
- for_each_thermal_trip (tz -> thermal_zone , acpi_thermal_adjust_trip , tz );
317
- }
318
-
319
314
static void acpi_queue_thermal_check (struct acpi_thermal * tz )
320
315
{
321
316
if (!work_pending (& tz -> thermal_check_work ))
@@ -324,17 +319,18 @@ static void acpi_queue_thermal_check(struct acpi_thermal *tz)
324
319
325
320
static void acpi_thermal_trips_update (struct acpi_thermal * tz , u32 event )
326
321
{
322
+ struct adjust_trip_data atd = { .tz = tz , .event = event };
327
323
struct acpi_device * adev = tz -> device ;
328
324
329
325
/*
330
- * Use thermal_zone_device_exec () to carry out the trip points
326
+ * Use thermal_zone_for_each_trip () to carry out the trip points
331
327
* update, so as to protect thermal_get_trend() from getting stale
332
328
* trip point temperatures and to prevent thermal_zone_device_update()
333
329
* invoked from acpi_thermal_check_fn() from producing inconsistent
334
330
* results.
335
331
*/
336
- thermal_zone_device_exec (tz -> thermal_zone ,
337
- acpi_thermal_adjust_thermal_zone , event );
332
+ thermal_zone_for_each_trip (tz -> thermal_zone ,
333
+ acpi_thermal_adjust_trip , & atd );
338
334
acpi_queue_thermal_check (tz );
339
335
acpi_bus_generate_netlink_event (adev -> pnp .device_class ,
340
336
dev_name (& adev -> dev ), event , 0 );
0 commit comments