Skip to content

Commit 9c86472

Browse files
committed
ACPI: thermal: Use library functions to obtain trip point temperature values
Modify the ACPI thermal driver to use functions from the ACPI thermal library to obtain trip point temperature values instead of duplicating them locally. Among other things, this requires the functions in question to be exported to it, because it can be built as a module. It effectively changes the behavior of the driver to treat temperature values out of the reasonable range (-55 centigrade to 175 centigrade) as invalid, but there is no other expected functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 6908097 commit 9c86472

File tree

3 files changed

+34
-32
lines changed

3 files changed

+34
-32
lines changed

drivers/acpi/internal.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ bool acpi_scan_is_offline(struct acpi_device *adev, bool uevent);
8585
acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context);
8686
void acpi_scan_table_notify(void);
8787

88+
int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp);
89+
int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp);
90+
int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp);
91+
int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
92+
8893
/* --------------------------------------------------------------------------
8994
Device Node Initialization / Removal
9095
-------------------------------------------------------------------------- */

drivers/acpi/thermal.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <linux/uaccess.h>
3232
#include <linux/units.h>
3333

34+
#include "internal.h"
35+
3436
#define ACPI_THERMAL_CLASS "thermal_zone"
3537
#define ACPI_THERMAL_DEVICE_NAME "Thermal Zone"
3638
#define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80
@@ -188,24 +190,19 @@ static int active_trip_index(struct acpi_thermal *tz,
188190

189191
static long get_passive_temp(struct acpi_thermal *tz)
190192
{
191-
unsigned long long tmp;
192-
acpi_status status;
193+
int temp;
193194

194-
status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp);
195-
if (ACPI_FAILURE(status))
195+
if (acpi_passive_trip_temp(tz->device, &temp))
196196
return THERMAL_TEMP_INVALID;
197197

198-
return tmp;
198+
return temp;
199199
}
200200

201201
static long get_active_temp(struct acpi_thermal *tz, int index)
202202
{
203-
char method[] = { '_', 'A', 'C', '0' + index, '\0' };
204-
unsigned long long tmp;
205-
acpi_status status;
203+
int temp;
206204

207-
status = acpi_evaluate_integer(tz->device->handle, method, NULL, &tmp);
208-
if (ACPI_FAILURE(status))
205+
if (acpi_active_trip_temp(tz->device, index, &temp))
209206
return THERMAL_TEMP_INVALID;
210207

211208
/*
@@ -215,10 +212,10 @@ static long get_active_temp(struct acpi_thermal *tz, int index)
215212
if (act > 0) {
216213
unsigned long long override = celsius_to_deci_kelvin(act);
217214

218-
if (tmp > override)
219-
tmp = override;
215+
if (temp > override)
216+
return override;
220217
}
221-
return tmp;
218+
return temp;
222219
}
223220

224221
static void acpi_thermal_update_trip(struct acpi_thermal *tz,
@@ -339,52 +336,47 @@ static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
339336
dev_name(&adev->dev), event, 0);
340337
}
341338

342-
static long acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
339+
static int acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
343340
{
344-
unsigned long long tmp;
345-
acpi_status status;
341+
int temp;
346342

347343
if (crt > 0) {
348-
tmp = celsius_to_deci_kelvin(crt);
344+
temp = celsius_to_deci_kelvin(crt);
349345
goto set;
350346
}
351347
if (crt == -1) {
352348
acpi_handle_debug(tz->device->handle, "Critical threshold disabled\n");
353349
return THERMAL_TEMP_INVALID;
354350
}
355351

356-
status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp);
357-
if (ACPI_FAILURE(status)) {
358-
acpi_handle_debug(tz->device->handle, "No critical threshold\n");
352+
if (acpi_critical_trip_temp(tz->device, &temp))
359353
return THERMAL_TEMP_INVALID;
360-
}
361-
if (tmp <= 2732) {
354+
355+
if (temp <= 2732) {
362356
/*
363357
* Below zero (Celsius) values clearly aren't right for sure,
364358
* so discard them as invalid.
365359
*/
366-
pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp);
360+
pr_info(FW_BUG "Invalid critical threshold (%d)\n", temp);
367361
return THERMAL_TEMP_INVALID;
368362
}
369363

370364
set:
371-
acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp);
372-
return tmp;
365+
acpi_handle_debug(tz->device->handle, "Critical threshold [%d]\n", temp);
366+
return temp;
373367
}
374368

375-
static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
369+
static int acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
376370
{
377-
unsigned long long tmp;
378-
acpi_status status;
371+
int temp;
379372

380-
status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
381-
if (ACPI_FAILURE(status)) {
373+
if (acpi_hot_trip_temp(tz->device, &temp) || temp == THERMAL_TEMP_INVALID) {
382374
acpi_handle_debug(tz->device->handle, "No hot threshold\n");
383375
return THERMAL_TEMP_INVALID;
384376
}
385377

386-
acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp);
387-
return tmp;
378+
acpi_handle_debug(tz->device->handle, "Hot threshold [%d]\n", temp);
379+
return temp;
388380
}
389381

390382
static bool passive_trip_params_init(struct acpi_thermal *tz)
@@ -1142,6 +1134,7 @@ static void __exit acpi_thermal_exit(void)
11421134
module_init(acpi_thermal_init);
11431135
module_exit(acpi_thermal_exit);
11441136

1137+
MODULE_IMPORT_NS(ACPI_THERMAL);
11451138
MODULE_AUTHOR("Paul Diefenbaugh");
11461139
MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
11471140
MODULE_LICENSE("GPL");

drivers/acpi/thermal_lib.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,25 @@ int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
5252

5353
return acpi_trip_temp(adev, obj_name, ret_temp);
5454
}
55+
EXPORT_SYMBOL_NS_GPL(acpi_active_trip_temp, ACPI_THERMAL);
5556

5657
int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
5758
{
5859
return acpi_trip_temp(adev, "_PSV", ret_temp);
5960
}
61+
EXPORT_SYMBOL_NS_GPL(acpi_passive_trip_temp, ACPI_THERMAL);
6062

6163
int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
6264
{
6365
return acpi_trip_temp(adev, "_HOT", ret_temp);
6466
}
67+
EXPORT_SYMBOL_NS_GPL(acpi_hot_trip_temp, ACPI_THERMAL);
6568

6669
int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
6770
{
6871
return acpi_trip_temp(adev, "_CRT", ret_temp);
6972
}
73+
EXPORT_SYMBOL_NS_GPL(acpi_critical_trip_temp, ACPI_THERMAL);
7074

7175
static int thermal_temp(int error, int temp_decik, int *ret_temp)
7276
{

0 commit comments

Comments
 (0)