Skip to content

Commit 30f04c7

Browse files
committed
ACPI: thermal: Simplify critical and hot trips representation
Notice that the only piece of information regarding the critical and hot trips that needs to be stored in the driver's local data structures is whether or not these trips are valid, so drop all of the redundant information from there and adjust the code accordingly. Among other things, this requires acpi_thermal_add() to be rearranged so as to obtain the critical trip temperature before populating the trip points table and for symmetry, the hot trip temperature is obtained earlier too. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]>
1 parent 06a5f76 commit 30f04c7

File tree

1 file changed

+33
-36
lines changed

1 file changed

+33
-36
lines changed

drivers/acpi/thermal.c

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ struct acpi_thermal_active {
107107
};
108108

109109
struct acpi_thermal_trips {
110-
struct acpi_thermal_trip critical;
111-
struct acpi_thermal_trip hot;
112110
struct acpi_thermal_passive passive;
113111
struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
112+
bool critical_valid;
113+
bool hot_valid;
114114
};
115115

116116
struct acpi_thermal {
@@ -391,7 +391,7 @@ static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
391391
dev_name(&adev->dev), event, 0);
392392
}
393393

394-
static void acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
394+
static long acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
395395
{
396396
unsigned long long tmp;
397397
acpi_status status;
@@ -420,52 +420,40 @@ static void acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
420420
}
421421

422422
set:
423-
tz->trips.critical.valid = true;
424-
tz->trips.critical.temperature = tmp;
425-
acpi_handle_debug(tz->device->handle, "Critical threshold [%lu]\n",
426-
tz->trips.critical.temperature);
427-
return;
423+
tz->trips.critical_valid = true;
424+
acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp);
425+
return tmp;
428426

429427
fail:
430-
tz->trips.critical.valid = false;
431-
tz->trips.critical.temperature = THERMAL_TEMP_INVALID;
428+
tz->trips.critical_valid = false;
429+
return THERMAL_TEMP_INVALID;
432430
}
433431

434-
static void acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
432+
static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
435433
{
436434
unsigned long long tmp;
437435
acpi_status status;
438436

439437
status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
440438
if (ACPI_FAILURE(status)) {
441-
tz->trips.hot.valid = false;
442-
tz->trips.hot.temperature = THERMAL_TEMP_INVALID;
439+
tz->trips.hot_valid = false;
443440
acpi_handle_debug(tz->device->handle, "No hot threshold\n");
444-
return;
441+
return THERMAL_TEMP_INVALID;
445442
}
446443

447-
tz->trips.hot.valid = true;
448-
tz->trips.hot.temperature = tmp;
449-
acpi_handle_debug(tz->device->handle, "Hot threshold [%lu]\n",
450-
tz->trips.hot.temperature);
444+
tz->trips.hot_valid = true;
445+
acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp);
446+
return tmp;
451447
}
452448

453449
static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
454450
{
455451
unsigned int count = 0;
456452
int i;
457453

458-
acpi_thermal_get_critical_trip(tz);
459-
acpi_thermal_get_hot_trip(tz);
460454
/* Passive and active trip points (optional). */
461455
__acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
462456

463-
if (tz->trips.critical.valid)
464-
count++;
465-
466-
if (tz->trips.hot.valid)
467-
count++;
468-
469457
if (tz->trips.passive.trip.valid)
470458
count++;
471459

@@ -578,10 +566,10 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal,
578566
int trip = -1;
579567
int result = 0;
580568

581-
if (tz->trips.critical.valid)
569+
if (tz->trips.critical_valid)
582570
trip++;
583571

584-
if (tz->trips.hot.valid)
572+
if (tz->trips.hot_valid)
585573
trip++;
586574

587575
if (tz->trips.passive.trip.valid) {
@@ -803,10 +791,9 @@ static void acpi_thermal_aml_dependency_fix(struct acpi_thermal *tz)
803791
* The heuristic below should work for all ACPI thermal zones which have a
804792
* critical trip point with a value being a multiple of 0.5 degree Celsius.
805793
*/
806-
static void acpi_thermal_guess_offset(struct acpi_thermal *tz)
794+
static void acpi_thermal_guess_offset(struct acpi_thermal *tz, long crit_temp)
807795
{
808-
if (tz->trips.critical.valid &&
809-
(tz->trips.critical.temperature % 5) == 1)
796+
if (tz->trips.critical_valid && crit_temp % 5 == 1)
810797
tz->kelvin_offset = 273100;
811798
else
812799
tz->kelvin_offset = 273200;
@@ -843,6 +830,7 @@ static int acpi_thermal_add(struct acpi_device *device)
843830
struct thermal_trip *trip;
844831
struct acpi_thermal *tz;
845832
unsigned int trip_count;
833+
int crit_temp, hot_temp;
846834
int passive_delay = 0;
847835
int result;
848836
int i;
@@ -864,6 +852,15 @@ static int acpi_thermal_add(struct acpi_device *device)
864852

865853
/* Get trip points [_CRT, _PSV, etc.] (required). */
866854
trip_count = acpi_thermal_get_trip_points(tz);
855+
856+
crit_temp = acpi_thermal_get_critical_trip(tz);
857+
if (tz->trips.critical_valid)
858+
trip_count++;
859+
860+
hot_temp = acpi_thermal_get_hot_trip(tz);
861+
if (tz->trips.hot_valid)
862+
trip_count++;
863+
867864
if (!trip_count) {
868865
pr_warn(FW_BUG "No valid trip points!\n");
869866
result = -ENODEV;
@@ -885,23 +882,23 @@ static int acpi_thermal_add(struct acpi_device *device)
885882
else
886883
acpi_thermal_get_polling_frequency(tz);
887884

888-
acpi_thermal_guess_offset(tz);
885+
acpi_thermal_guess_offset(tz, crit_temp);
889886

890887
trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL);
891888
if (!trip)
892889
return -ENOMEM;
893890

894891
tz->trip_table = trip;
895892

896-
if (tz->trips.critical.valid) {
893+
if (tz->trips.critical_valid) {
897894
trip->type = THERMAL_TRIP_CRITICAL;
898-
trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature);
895+
trip->temperature = acpi_thermal_temp(tz, crit_temp);
899896
trip++;
900897
}
901898

902-
if (tz->trips.hot.valid) {
899+
if (tz->trips.hot_valid) {
903900
trip->type = THERMAL_TRIP_HOT;
904-
trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature);
901+
trip->temperature = acpi_thermal_temp(tz, hot_temp);
905902
trip++;
906903
}
907904

0 commit comments

Comments
 (0)