Skip to content

Commit f845351

Browse files
committed
Merge branch 'acpi-thermal'
Merge ACPI thermal zone driver updates for 6.8-rc1: - Use generic ACPI helpers for evaluating trip point temperature objects in the ACPI thermal zone driver (Rafael J. Wysockii, Arnd Bergmann). - Add Thermal fast Sampling Period (_TFP) support to the ACPI thermal zone driver (Jeff Brasen). * acpi-thermal: ACPI: thermal_lib: include "internal.h" for function prototypes ACPI: thermal: Add Thermal fast Sampling Period (_TFP) support ACPI: thermal: Use library functions to obtain trip point temperature values ACPI: thermal_lib: Add functions returning temperature in deci-Kelvin thermal: ACPI: Move the ACPI thermal library to drivers/acpi/
2 parents f00571b + b14b2d5 commit f845351

File tree

11 files changed

+119
-64
lines changed

11 files changed

+119
-64
lines changed

drivers/acpi/Kconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ config ACPI_CCA_REQUIRED
6161
config ACPI_TABLE_LIB
6262
bool
6363

64+
config ACPI_THERMAL_LIB
65+
depends on THERMAL
66+
bool
67+
6468
config ACPI_DEBUGGER
6569
bool "AML debugger interface"
6670
select ACPI_DEBUG
@@ -327,6 +331,7 @@ config ACPI_THERMAL
327331
tristate "Thermal Zone"
328332
depends on ACPI_PROCESSOR
329333
select THERMAL
334+
select ACPI_THERMAL_LIB
330335
default y
331336
help
332337
This driver supports ACPI thermal zones. Most mobile and

drivers/acpi/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ obj-$(CONFIG_ACPI_TAD) += acpi_tad.o
8989
obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o
9090
obj-$(CONFIG_ACPI_PROCESSOR) += processor.o
9191
obj-$(CONFIG_ACPI) += container.o
92+
obj-$(CONFIG_ACPI_THERMAL_LIB) += thermal_lib.o
9293
obj-$(CONFIG_ACPI_THERMAL) += thermal.o
9394
obj-$(CONFIG_ACPI_PLATFORM_PROFILE) += platform_profile.o
9495
obj-$(CONFIG_ACPI_NFIT) += nfit/

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
#ifdef CONFIG_ARM64
8994
int acpi_arch_thermal_cpufreq_pctg(void);
9095
#else

drivers/acpi/thermal.c

Lines changed: 34 additions & 35 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
@@ -90,7 +92,7 @@ struct acpi_thermal_passive {
9092
struct acpi_thermal_trip trip;
9193
unsigned long tc1;
9294
unsigned long tc2;
93-
unsigned long tsp;
95+
unsigned long delay;
9496
};
9597

9698
struct acpi_thermal_active {
@@ -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,
@@ -337,52 +334,47 @@ static void acpi_thermal_trips_update(struct acpi_thermal *tz, u32 event)
337334
dev_name(&adev->dev), event, 0);
338335
}
339336

340-
static long acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
337+
static int acpi_thermal_get_critical_trip(struct acpi_thermal *tz)
341338
{
342-
unsigned long long tmp;
343-
acpi_status status;
339+
int temp;
344340

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

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

368362
set:
369-
acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp);
370-
return tmp;
363+
acpi_handle_debug(tz->device->handle, "Critical threshold [%d]\n", temp);
364+
return temp;
371365
}
372366

373-
static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
367+
static int acpi_thermal_get_hot_trip(struct acpi_thermal *tz)
374368
{
375-
unsigned long long tmp;
376-
acpi_status status;
369+
int temp;
377370

378-
status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp);
379-
if (ACPI_FAILURE(status)) {
371+
if (acpi_hot_trip_temp(tz->device, &temp) || temp == THERMAL_TEMP_INVALID) {
380372
acpi_handle_debug(tz->device->handle, "No hot threshold\n");
381373
return THERMAL_TEMP_INVALID;
382374
}
383375

384-
acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp);
385-
return tmp;
376+
acpi_handle_debug(tz->device->handle, "Hot threshold [%d]\n", temp);
377+
return temp;
386378
}
387379

388380
static bool passive_trip_params_init(struct acpi_thermal *tz)
@@ -402,11 +394,17 @@ static bool passive_trip_params_init(struct acpi_thermal *tz)
402394

403395
tz->trips.passive.tc2 = tmp;
404396

397+
status = acpi_evaluate_integer(tz->device->handle, "_TFP", NULL, &tmp);
398+
if (ACPI_SUCCESS(status)) {
399+
tz->trips.passive.delay = tmp;
400+
return true;
401+
}
402+
405403
status = acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, &tmp);
406404
if (ACPI_FAILURE(status))
407405
return false;
408406

409-
tz->trips.passive.tsp = tmp;
407+
tz->trips.passive.delay = tmp * 100;
410408

411409
return true;
412410
}
@@ -902,7 +900,7 @@ static int acpi_thermal_add(struct acpi_device *device)
902900

903901
acpi_trip = &tz->trips.passive.trip;
904902
if (acpi_thermal_trip_valid(acpi_trip)) {
905-
passive_delay = tz->trips.passive.tsp * 100;
903+
passive_delay = tz->trips.passive.delay;
906904

907905
trip->type = THERMAL_TRIP_PASSIVE;
908906
trip->temperature = acpi_thermal_temp(tz, acpi_trip->temp_dk);
@@ -1140,6 +1138,7 @@ static void __exit acpi_thermal_exit(void)
11401138
module_init(acpi_thermal_init);
11411139
module_exit(acpi_thermal_exit);
11421140

1141+
MODULE_IMPORT_NS(ACPI_THERMAL);
11431142
MODULE_AUTHOR("Paul Diefenbaugh");
11441143
MODULE_DESCRIPTION("ACPI Thermal Zone Driver");
11451144
MODULE_LICENSE("GPL");

drivers/thermal/thermal_acpi.c renamed to drivers/acpi/thermal_lib.c

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
* Copyright 2023 Linaro Limited
44
* Copyright 2023 Intel Corporation
55
*
6-
* Library routines for populating a generic thermal trip point structure
7-
* with data obtained by evaluating a specific object in the ACPI Namespace.
6+
* Library routines for retrieving trip point temperature values from the
7+
* platform firmware via ACPI.
88
*/
99
#include <linux/acpi.h>
1010
#include <linux/units.h>
1111
#include <linux/thermal.h>
12+
#include "internal.h"
1213

1314
/*
1415
* Minimum temperature for full military grade is 218°K (-55°C) and
@@ -17,11 +18,11 @@
1718
* firmware. Any values out of these boundaries may be considered
1819
* bogus and we can assume the firmware has no data to provide.
1920
*/
20-
#define TEMP_MIN_DECIK 2180
21-
#define TEMP_MAX_DECIK 4480
21+
#define TEMP_MIN_DECIK 2180ULL
22+
#define TEMP_MAX_DECIK 4480ULL
2223

23-
static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
24-
int *ret_temp)
24+
static int acpi_trip_temp(struct acpi_device *adev, char *obj_name,
25+
int *ret_temp)
2526
{
2627
unsigned long long temp;
2728
acpi_status status;
@@ -33,7 +34,7 @@ static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
3334
}
3435

3536
if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) {
36-
*ret_temp = deci_kelvin_to_millicelsius(temp);
37+
*ret_temp = temp;
3738
} else {
3839
acpi_handle_debug(adev->handle, "%s result %llu out of range\n",
3940
obj_name, temp);
@@ -43,6 +44,48 @@ static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
4344
return 0;
4445
}
4546

47+
int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
48+
{
49+
char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
50+
51+
if (id < 0 || id > 9)
52+
return -EINVAL;
53+
54+
return acpi_trip_temp(adev, obj_name, ret_temp);
55+
}
56+
EXPORT_SYMBOL_NS_GPL(acpi_active_trip_temp, ACPI_THERMAL);
57+
58+
int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
59+
{
60+
return acpi_trip_temp(adev, "_PSV", ret_temp);
61+
}
62+
EXPORT_SYMBOL_NS_GPL(acpi_passive_trip_temp, ACPI_THERMAL);
63+
64+
int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
65+
{
66+
return acpi_trip_temp(adev, "_HOT", ret_temp);
67+
}
68+
EXPORT_SYMBOL_NS_GPL(acpi_hot_trip_temp, ACPI_THERMAL);
69+
70+
int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
71+
{
72+
return acpi_trip_temp(adev, "_CRT", ret_temp);
73+
}
74+
EXPORT_SYMBOL_NS_GPL(acpi_critical_trip_temp, ACPI_THERMAL);
75+
76+
static int thermal_temp(int error, int temp_decik, int *ret_temp)
77+
{
78+
if (error)
79+
return error;
80+
81+
if (temp_decik == THERMAL_TEMP_INVALID)
82+
*ret_temp = THERMAL_TEMP_INVALID;
83+
else
84+
*ret_temp = deci_kelvin_to_millicelsius(temp_decik);
85+
86+
return 0;
87+
}
88+
4689
/**
4790
* thermal_acpi_active_trip_temp - Retrieve active trip point temperature
4891
* @adev: Target thermal zone ACPI device object.
@@ -57,12 +100,10 @@ static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
57100
*/
58101
int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
59102
{
60-
char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
61-
62-
if (id < 0 || id > 9)
63-
return -EINVAL;
103+
int temp_decik;
104+
int ret = acpi_active_trip_temp(adev, id, &temp_decik);
64105

65-
return thermal_acpi_trip_temp(adev, obj_name, ret_temp);
106+
return thermal_temp(ret, temp_decik, ret_temp);
66107
}
67108
EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
68109

@@ -78,7 +119,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
78119
*/
79120
int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
80121
{
81-
return thermal_acpi_trip_temp(adev, "_PSV", ret_temp);
122+
int temp_decik;
123+
int ret = acpi_passive_trip_temp(adev, &temp_decik);
124+
125+
return thermal_temp(ret, temp_decik, ret_temp);
82126
}
83127
EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
84128

@@ -95,7 +139,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
95139
*/
96140
int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
97141
{
98-
return thermal_acpi_trip_temp(adev, "_HOT", ret_temp);
142+
int temp_decik;
143+
int ret = acpi_hot_trip_temp(adev, &temp_decik);
144+
145+
return thermal_temp(ret, temp_decik, ret_temp);
99146
}
100147
EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
101148

@@ -111,6 +158,9 @@ EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
111158
*/
112159
int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
113160
{
114-
return thermal_acpi_trip_temp(adev, "_CRT", ret_temp);
161+
int temp_decik;
162+
int ret = acpi_critical_trip_temp(adev, &temp_decik);
163+
164+
return thermal_temp(ret, temp_decik, ret_temp);
115165
}
116166
EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);

drivers/thermal/Kconfig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,6 @@ config THERMAL_OF
7676
Say 'Y' here if you need to build thermal infrastructure
7777
based on device tree.
7878

79-
config THERMAL_ACPI
80-
depends on ACPI
81-
bool
82-
8379
config THERMAL_WRITABLE_TRIPS
8480
bool "Enable writable trip points"
8581
help

drivers/thermal/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ thermal_sys-$(CONFIG_THERMAL_NETLINK) += thermal_netlink.o
1313
# interface to/from other layers providing sensors
1414
thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o
1515
thermal_sys-$(CONFIG_THERMAL_OF) += thermal_of.o
16-
thermal_sys-$(CONFIG_THERMAL_ACPI) += thermal_acpi.o
1716

1817
# governors
1918
CFLAGS_gov_power_allocator.o := -I$(src)

drivers/thermal/intel/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ config INTEL_BXT_PMIC_THERMAL
8585
config INTEL_PCH_THERMAL
8686
tristate "Intel PCH Thermal Reporting Driver"
8787
depends on X86 && PCI
88-
select THERMAL_ACPI if ACPI
88+
select ACPI_THERMAL_LIB if ACPI
8989
help
9090
Enable this to support thermal reporting on certain intel PCHs.
9191
Thermal reporting device will provide temperature reading,

drivers/thermal/intel/int340x_thermal/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ config INT340X_THERMAL
99
select THERMAL_GOV_USER_SPACE
1010
select ACPI_THERMAL_REL
1111
select ACPI_FAN
12-
select THERMAL_ACPI
12+
select ACPI_THERMAL_LIB
1313
select INTEL_SOC_DTS_IOSF_CORE
1414
select INTEL_TCC
1515
select PROC_THERMAL_MMIO_RAPL if POWERCAP

include/linux/acpi.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ extern int acpi_blacklisted(void);
424424
extern void acpi_osi_setup(char *str);
425425
extern bool acpi_osi_is_win8(void);
426426

427+
#ifdef CONFIG_ACPI_THERMAL_LIB
428+
int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp);
429+
int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp);
430+
int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp);
431+
int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
432+
#endif
433+
427434
#ifdef CONFIG_ACPI_NUMA
428435
int acpi_map_pxm_to_node(int pxm);
429436
int acpi_get_node(acpi_handle handle);

0 commit comments

Comments
 (0)