Skip to content

Commit 4be3233

Browse files
committed
ACPI: thermal: Simplify initialization of critical and hot trips
Use the observation that the critical and hot trip points are never updated by the ACPI thermal driver, because the flags passed from acpi_thermal_notify() to acpi_thermal_trips_update() do not include ACPI_TRIPS_CRITICAL or ACPI_TRIPS_HOT, to move the initialization of those trip points directly into acpi_thermal_get_trip_points() and reduce the size of __acpi_thermal_trips_update(). Also make the critical and hot trip points initialization code more straightforward and drop the flags that are not needed any more. Signed-off-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Daniel Lezcano <[email protected]>
1 parent 6465e26 commit 4be3233

File tree

1 file changed

+66
-64
lines changed

1 file changed

+66
-64
lines changed

drivers/acpi/thermal.c

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,13 @@
4343
#define ACPI_THERMAL_MAX_ACTIVE 10
4444
#define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65
4545

46-
#define ACPI_TRIPS_CRITICAL BIT(0)
47-
#define ACPI_TRIPS_HOT BIT(1)
48-
#define ACPI_TRIPS_PASSIVE BIT(2)
49-
#define ACPI_TRIPS_ACTIVE BIT(3)
50-
#define ACPI_TRIPS_DEVICES BIT(4)
46+
#define ACPI_TRIPS_PASSIVE BIT(0)
47+
#define ACPI_TRIPS_ACTIVE BIT(1)
48+
#define ACPI_TRIPS_DEVICES BIT(2)
5149

5250
#define ACPI_TRIPS_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE)
5351

54-
#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \
55-
ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \
56-
ACPI_TRIPS_DEVICES)
52+
#define ACPI_TRIPS_INIT (ACPI_TRIPS_THRESHOLDS | ACPI_TRIPS_DEVICES)
5753

5854
/*
5955
* This exception is thrown out in two cases:
@@ -196,62 +192,6 @@ static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag)
196192
bool valid = false;
197193
int i;
198194

199-
/* Critical Shutdown */
200-
if (flag & ACPI_TRIPS_CRITICAL) {
201-
status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
202-
tz->trips.critical.temperature = tmp;
203-
/*
204-
* Treat freezing temperatures as invalid as well; some
205-
* BIOSes return really low values and cause reboots at startup.
206-
* Below zero (Celsius) values clearly aren't right for sure..
207-
* ... so lets discard those as invalid.
208-
*/
209-
if (ACPI_FAILURE(status)) {
210-
tz->trips.critical.valid = false;
211-
acpi_handle_debug(tz->device->handle,
212-
"No critical threshold\n");
213-
} else if (tmp <= 2732) {
214-
pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp);
215-
tz->trips.critical.valid = false;
216-
} else {
217-
tz->trips.critical.valid = true;
218-
acpi_handle_debug(tz->device->handle,
219-
"Found critical threshold [%lu]\n",
220-
tz->trips.critical.temperature);
221-
}
222-
if (tz->trips.critical.valid) {
223-
if (crt == -1) {
224-
tz->trips.critical.valid = false;
225-
} else if (crt > 0) {
226-
unsigned long crt_k = celsius_to_deci_kelvin(crt);
227-
228-
/*
229-
* Allow override critical threshold
230-
*/
231-
if (crt_k > tz->trips.critical.temperature)
232-
pr_info("Critical threshold %d C\n", crt);
233-
234-
tz->trips.critical.temperature = crt_k;
235-
}
236-
}
237-
}
238-
239-
/* Critical Sleep (optional) */
240-
if (flag & ACPI_TRIPS_HOT) {
241-
status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
242-
if (ACPI_FAILURE(status)) {
243-
tz->trips.hot.valid = false;
244-
acpi_handle_debug(tz->device->handle,
245-
"No hot threshold\n");
246-
} else {
247-
tz->trips.hot.temperature = tmp;
248-
tz->trips.hot.valid = true;
249-
acpi_handle_debug(tz->device->handle,
250-
"Found hot threshold [%lu]\n",
251-
tz->trips.hot.temperature);
252-
}
253-
}
254-
255195
/* Passive (optional) */
256196
if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) ||
257197
flag == ACPI_TRIPS_INIT) {
@@ -451,11 +391,73 @@ static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
451391
dev_name(&adev->dev), event, 0);
452392
}
453393

394+
static void acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
395+
{
396+
unsigned long long tmp;
397+
acpi_status status;
398+
399+
if (crt > 0) {
400+
tmp = celsius_to_deci_kelvin(crt);
401+
goto set;
402+
}
403+
if (crt == -1) {
404+
acpi_handle_debug(tz->device->handle, "Critical threshold disabled\n");
405+
goto fail;
406+
}
407+
408+
status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
409+
if (ACPI_FAILURE(status)) {
410+
acpi_handle_debug(tz->device->handle, "No critical threshold\n");
411+
goto fail;
412+
}
413+
if (tmp <= 2732) {
414+
/*
415+
* Below zero (Celsius) values clearly aren't right for sure,
416+
* so discard them as invalid.
417+
*/
418+
pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp);
419+
goto fail;
420+
}
421+
422+
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;
428+
429+
fail:
430+
tz->trips.critical.valid = false;
431+
tz->trips.critical.temperature = THERMAL_TEMP_INVALID;
432+
}
433+
434+
static void acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
435+
{
436+
unsigned long long tmp;
437+
acpi_status status;
438+
439+
status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
440+
if (ACPI_FAILURE(status)) {
441+
tz->trips.hot.valid = false;
442+
tz->trips.hot.temperature = THERMAL_TEMP_INVALID;
443+
acpi_handle_debug(tz->device->handle, "No hot threshold\n");
444+
return;
445+
}
446+
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);
451+
}
452+
454453
static int acpi_thermal_get_trip_points(struct acpi_thermal *tz)
455454
{
456455
bool valid;
457456
int i;
458457

458+
acpi_thermal_get_critical_trip(tz);
459+
acpi_thermal_get_hot_trip(tz);
460+
/* Passive and active trip points (optional). */
459461
__acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT);
460462

461463
valid = tz->trips.critical.valid |

0 commit comments

Comments
 (0)