Skip to content

Commit 6908097

Browse files
committed
ACPI: thermal_lib: Add functions returning temperature in deci-Kelvin
Because the ACPI thermal driver generally operates temperature values in deci-Kelvin, it needs the library functions returning temperature for various trip point types to use deci-Kelvin too. To address that, arrange the ACPI thermal library code in three levels of functions where the high-level ones will return temperature in milli-Celsius, as needed by the thermal core and the majority of thermal drivers, the mid-level ones will return temperature in deci-Kelvin and will be called internally by the corresponding high- level functions, and all of the mid-level functions will call the same low-level one, acpi_trip_temp(), to actually evaluate ACPI objects to retrieve themperature values from the platform firmware. Going forward, this will allow the ACPI thermal driver to use the mid-level functions to provide temperature values needed by it, so as to reduce code duplication related to evaluating trip temperature ACPI control methods. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f475079 commit 6908097

File tree

1 file changed

+60
-15
lines changed

1 file changed

+60
-15
lines changed

drivers/acpi/thermal_lib.c

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
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>
@@ -17,11 +17,11 @@
1717
* firmware. Any values out of these boundaries may be considered
1818
* bogus and we can assume the firmware has no data to provide.
1919
*/
20-
#define TEMP_MIN_DECIK 2180
21-
#define TEMP_MAX_DECIK 4480
20+
#define TEMP_MIN_DECIK 2180ULL
21+
#define TEMP_MAX_DECIK 4480ULL
2222

23-
static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
24-
int *ret_temp)
23+
static int acpi_trip_temp(struct acpi_device *adev, char *obj_name,
24+
int *ret_temp)
2525
{
2626
unsigned long long temp;
2727
acpi_status status;
@@ -33,7 +33,7 @@ static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
3333
}
3434

3535
if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) {
36-
*ret_temp = deci_kelvin_to_millicelsius(temp);
36+
*ret_temp = temp;
3737
} else {
3838
acpi_handle_debug(adev->handle, "%s result %llu out of range\n",
3939
obj_name, temp);
@@ -43,6 +43,44 @@ static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
4343
return 0;
4444
}
4545

46+
int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
47+
{
48+
char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
49+
50+
if (id < 0 || id > 9)
51+
return -EINVAL;
52+
53+
return acpi_trip_temp(adev, obj_name, ret_temp);
54+
}
55+
56+
int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
57+
{
58+
return acpi_trip_temp(adev, "_PSV", ret_temp);
59+
}
60+
61+
int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
62+
{
63+
return acpi_trip_temp(adev, "_HOT", ret_temp);
64+
}
65+
66+
int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
67+
{
68+
return acpi_trip_temp(adev, "_CRT", ret_temp);
69+
}
70+
71+
static int thermal_temp(int error, int temp_decik, int *ret_temp)
72+
{
73+
if (error)
74+
return error;
75+
76+
if (temp_decik == THERMAL_TEMP_INVALID)
77+
*ret_temp = THERMAL_TEMP_INVALID;
78+
else
79+
*ret_temp = deci_kelvin_to_millicelsius(temp_decik);
80+
81+
return 0;
82+
}
83+
4684
/**
4785
* thermal_acpi_active_trip_temp - Retrieve active trip point temperature
4886
* @adev: Target thermal zone ACPI device object.
@@ -57,12 +95,10 @@ static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
5795
*/
5896
int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
5997
{
60-
char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
61-
62-
if (id < 0 || id > 9)
63-
return -EINVAL;
98+
int temp_decik;
99+
int ret = acpi_active_trip_temp(adev, id, &temp_decik);
64100

65-
return thermal_acpi_trip_temp(adev, obj_name, ret_temp);
101+
return thermal_temp(ret, temp_decik, ret_temp);
66102
}
67103
EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
68104

@@ -78,7 +114,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
78114
*/
79115
int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
80116
{
81-
return thermal_acpi_trip_temp(adev, "_PSV", ret_temp);
117+
int temp_decik;
118+
int ret = acpi_passive_trip_temp(adev, &temp_decik);
119+
120+
return thermal_temp(ret, temp_decik, ret_temp);
82121
}
83122
EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
84123

@@ -95,7 +134,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
95134
*/
96135
int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
97136
{
98-
return thermal_acpi_trip_temp(adev, "_HOT", ret_temp);
137+
int temp_decik;
138+
int ret = acpi_hot_trip_temp(adev, &temp_decik);
139+
140+
return thermal_temp(ret, temp_decik, ret_temp);
99141
}
100142
EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
101143

@@ -111,6 +153,9 @@ EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
111153
*/
112154
int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
113155
{
114-
return thermal_acpi_trip_temp(adev, "_CRT", ret_temp);
156+
int temp_decik;
157+
int ret = acpi_critical_trip_temp(adev, &temp_decik);
158+
159+
return thermal_temp(ret, temp_decik, ret_temp);
115160
}
116161
EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);

0 commit comments

Comments
 (0)