@@ -184,94 +184,6 @@ static int acpi_thermal_temp(struct acpi_thermal *tz, int temp_deci_k)
184
184
tz -> kelvin_offset );
185
185
}
186
186
187
- static void __acpi_thermal_trips_update (struct acpi_thermal * tz , int flag )
188
- {
189
- acpi_status status ;
190
- unsigned long long tmp ;
191
- struct acpi_handle_list devices ;
192
- bool valid = false;
193
- int i ;
194
-
195
- /* Active (optional) */
196
- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
197
- char name [5 ] = { '_' , 'A' , 'C' , ('0' + i ), '\0' };
198
- valid = tz -> trips .active [i ].trip .valid ;
199
-
200
- if (act == -1 )
201
- break ; /* disable all active trip points */
202
-
203
- if (flag == ACPI_TRIPS_INIT || ((flag & ACPI_TRIPS_ACTIVE ) &&
204
- tz -> trips .active [i ].trip .valid )) {
205
- status = acpi_evaluate_integer (tz -> device -> handle ,
206
- name , NULL , & tmp );
207
- if (ACPI_FAILURE (status )) {
208
- tz -> trips .active [i ].trip .valid = false;
209
- if (i == 0 )
210
- break ;
211
-
212
- if (act <= 0 )
213
- break ;
214
-
215
- if (i == 1 )
216
- tz -> trips .active [0 ].trip .temperature =
217
- celsius_to_deci_kelvin (act );
218
- else
219
- /*
220
- * Don't allow override higher than
221
- * the next higher trip point
222
- */
223
- tz -> trips .active [i - 1 ].trip .temperature =
224
- min_t (unsigned long ,
225
- tz -> trips .active [i - 2 ].trip .temperature ,
226
- celsius_to_deci_kelvin (act ));
227
-
228
- break ;
229
- } else {
230
- tz -> trips .active [i ].trip .temperature = tmp ;
231
- tz -> trips .active [i ].trip .valid = true;
232
- }
233
- }
234
-
235
- name [2 ] = 'L' ;
236
- if ((flag & ACPI_TRIPS_DEVICES ) && tz -> trips .active [i ].trip .valid ) {
237
- memset (& devices , 0 , sizeof (struct acpi_handle_list ));
238
- status = acpi_evaluate_reference (tz -> device -> handle ,
239
- name , NULL , & devices );
240
- if (ACPI_FAILURE (status )) {
241
- acpi_handle_info (tz -> device -> handle ,
242
- "Invalid active%d threshold\n" , i );
243
- tz -> trips .active [i ].trip .valid = false;
244
- } else {
245
- tz -> trips .active [i ].trip .valid = true;
246
- }
247
-
248
- if (memcmp (& tz -> trips .active [i ].devices , & devices ,
249
- sizeof (struct acpi_handle_list ))) {
250
- memcpy (& tz -> trips .active [i ].devices , & devices ,
251
- sizeof (struct acpi_handle_list ));
252
- ACPI_THERMAL_TRIPS_EXCEPTION (flag , tz , "device" );
253
- }
254
- }
255
- if ((flag & ACPI_TRIPS_ACTIVE ) || (flag & ACPI_TRIPS_DEVICES ))
256
- if (valid != tz -> trips .active [i ].trip .valid )
257
- ACPI_THERMAL_TRIPS_EXCEPTION (flag , tz , "state" );
258
-
259
- if (!tz -> trips .active [i ].trip .valid )
260
- break ;
261
- }
262
-
263
- if (flag & ACPI_TRIPS_DEVICES ) {
264
- memset (& devices , 0 , sizeof (devices ));
265
- status = acpi_evaluate_reference (tz -> device -> handle , "_TZD" ,
266
- NULL , & devices );
267
- if (ACPI_SUCCESS (status ) &&
268
- memcmp (& tz -> devices , & devices , sizeof (devices ))) {
269
- tz -> devices = devices ;
270
- ACPI_THERMAL_TRIPS_EXCEPTION (flag , tz , "device" );
271
- }
272
- }
273
- }
274
-
275
187
static void update_acpi_thermal_trip_temp (struct acpi_thermal_trip * acpi_trip ,
276
188
int temp )
277
189
{
@@ -338,6 +250,78 @@ static void acpi_thermal_update_passive_devices(struct acpi_thermal *tz)
338
250
ACPI_THERMAL_TRIPS_EXCEPTION (ACPI_TRIPS_PASSIVE , tz , "state" );
339
251
}
340
252
253
+ static long get_active_temp (struct acpi_thermal * tz , int index )
254
+ {
255
+ char method [] = { '_' , 'A' , 'C' , '0' + index , '\0' };
256
+ unsigned long long tmp ;
257
+ acpi_status status ;
258
+
259
+ status = acpi_evaluate_integer (tz -> device -> handle , method , NULL , & tmp );
260
+ if (ACPI_FAILURE (status ))
261
+ return THERMAL_TEMP_INVALID ;
262
+
263
+ /*
264
+ * If an override has been provided, apply it so there are no active
265
+ * trips with thresholds greater than the override.
266
+ */
267
+ if (act > 0 ) {
268
+ unsigned long long override = celsius_to_deci_kelvin (act );
269
+
270
+ if (tmp > override )
271
+ tmp = override ;
272
+ }
273
+ return tmp ;
274
+ }
275
+
276
+ static void acpi_thermal_update_active_trip (struct acpi_thermal * tz , int index )
277
+ {
278
+ struct acpi_thermal_trip * acpi_trip = & tz -> trips .active [index ].trip ;
279
+
280
+ if (!acpi_trip -> valid )
281
+ return ;
282
+
283
+ update_acpi_thermal_trip_temp (acpi_trip , get_active_temp (tz , index ));
284
+ if (!acpi_trip -> valid )
285
+ ACPI_THERMAL_TRIPS_EXCEPTION (ACPI_TRIPS_ACTIVE , tz , "state" );
286
+ }
287
+
288
+ static bool update_active_devices (struct acpi_thermal * tz , int index , bool compare )
289
+ {
290
+ char method [] = { '_' , 'A' , 'L' , '0' + index , '\0' };
291
+ struct acpi_handle_list devices ;
292
+ acpi_status status ;
293
+
294
+ memset (& devices , 0 , sizeof (devices ));
295
+
296
+ status = acpi_evaluate_reference (tz -> device -> handle , method , NULL , & devices );
297
+ if (ACPI_FAILURE (status )) {
298
+ acpi_handle_info (tz -> device -> handle ,
299
+ "Missing device list for active threshold %d\n" ,
300
+ index );
301
+ return false;
302
+ }
303
+
304
+ if (compare && memcmp (& tz -> trips .active [index ].devices , & devices , sizeof (devices )))
305
+ ACPI_THERMAL_TRIPS_EXCEPTION (ACPI_TRIPS_ACTIVE , tz , "device" );
306
+
307
+ memcpy (& tz -> trips .active [index ].devices , & devices , sizeof (devices ));
308
+ return true;
309
+ }
310
+
311
+ static void acpi_thermal_update_active_devices (struct acpi_thermal * tz , int index )
312
+ {
313
+ struct acpi_thermal_trip * acpi_trip = & tz -> trips .active [index ].trip ;
314
+
315
+ if (!acpi_trip -> valid )
316
+ return ;
317
+
318
+ if (update_active_devices (tz , index , true))
319
+ return ;
320
+
321
+ update_acpi_thermal_trip_temp (acpi_trip , THERMAL_TEMP_INVALID );
322
+ ACPI_THERMAL_TRIPS_EXCEPTION (ACPI_TRIPS_ACTIVE , tz , "state" );
323
+ }
324
+
341
325
static int acpi_thermal_adjust_trip (struct thermal_trip * trip , void * data )
342
326
{
343
327
struct acpi_thermal_trip * acpi_trip = trip -> priv ;
@@ -358,18 +342,18 @@ static void acpi_thermal_adjust_thermal_zone(struct thermal_zone_device *thermal
358
342
unsigned long data )
359
343
{
360
344
struct acpi_thermal * tz = thermal_zone_device_priv (thermal );
361
- int flag ;
345
+ int i ;
362
346
363
347
if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS ) {
364
348
acpi_thermal_update_passive_trip (tz );
365
- flag = ACPI_TRIPS_THRESHOLDS ;
349
+ for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
350
+ acpi_thermal_update_active_trip (tz , i );
366
351
} else {
367
352
acpi_thermal_update_passive_devices (tz );
368
- flag = ACPI_TRIPS_DEVICES ;
353
+ for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
354
+ acpi_thermal_update_active_devices (tz , i );
369
355
}
370
356
371
- __acpi_thermal_trips_update (tz , flag );
372
-
373
357
for_each_thermal_trip (tz -> thermal_zone , acpi_thermal_adjust_trip , tz );
374
358
}
375
359
@@ -498,6 +482,28 @@ static bool acpi_thermal_init_passive_trip(struct acpi_thermal *tz)
498
482
return false;
499
483
}
500
484
485
+ static bool acpi_thermal_init_active_trip (struct acpi_thermal * tz , int index )
486
+ {
487
+ long temp ;
488
+
489
+ if (act == -1 )
490
+ goto fail ;
491
+
492
+ temp = get_active_temp (tz , index );
493
+ if (temp == THERMAL_TEMP_INVALID )
494
+ goto fail ;
495
+
496
+ if (!update_active_devices (tz , index , false))
497
+ goto fail ;
498
+
499
+ update_acpi_thermal_trip_temp (& tz -> trips .active [index ].trip , temp );
500
+ return true;
501
+
502
+ fail :
503
+ update_acpi_thermal_trip_temp (& tz -> trips .active [index ].trip , THERMAL_TEMP_INVALID );
504
+ return false;
505
+ }
506
+
501
507
static int acpi_thermal_get_trip_points (struct acpi_thermal * tz )
502
508
{
503
509
unsigned int count = 0 ;
@@ -506,11 +512,8 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
506
512
if (acpi_thermal_init_passive_trip (tz ))
507
513
count ++ ;
508
514
509
- /* Active trip points (optional). */
510
- __acpi_thermal_trips_update (tz , ACPI_TRIPS_INIT );
511
-
512
515
for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ ) {
513
- if (tz -> trips . active [ i ]. trip . valid )
516
+ if (acpi_thermal_init_active_trip ( tz , i ) )
514
517
count ++ ;
515
518
else
516
519
break ;
0 commit comments