1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright 2023 Linaro Limited
4 * Copyright 2023 Intel Corporation
6 * Library routines for populating a generic thermal trip point structure
7 * with data obtained by evaluating a specific object in the ACPI Namespace.
9 #include <linux/acpi.h>
10 #include <linux/units.h>
11 #include <linux/thermal.h>
14 * Minimum temperature for full military grade is 218°K (-55°C) and
15 * max temperature is 448°K (175°C). We can consider those values as
16 * the boundaries for the [trips] temperature returned by the
17 * firmware. Any values out of these boundaries may be considered
18 * bogus and we can assume the firmware has no data to provide.
20 #define TEMP_MIN_DECIK 2180
21 #define TEMP_MAX_DECIK 4480
23 static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
26 unsigned long long temp;
29 status = acpi_evaluate_integer(adev->handle, obj_name, NULL, &temp);
30 if (ACPI_FAILURE(status)) {
31 acpi_handle_debug(adev->handle, "%s evaluation failed\n", obj_name);
35 if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) {
36 *ret_temp = deci_kelvin_to_millicelsius(temp);
38 acpi_handle_debug(adev->handle, "%s result %llu out of range\n",
40 *ret_temp = THERMAL_TEMP_INVALID;
47 * thermal_acpi_active_trip_temp - Retrieve active trip point temperature
48 * @adev: Target thermal zone ACPI device object.
49 * @id: Active cooling level (0 - 9).
50 * @ret_temp: Address to store the retrieved temperature value on success.
52 * Evaluate the _ACx object for the thermal zone represented by @adev to obtain
53 * the temperature of the active cooling trip point corresponding to the active
54 * cooling level given by @id.
56 * Return 0 on success or a negative error value on failure.
58 int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
60 char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
65 return thermal_acpi_trip_temp(adev, obj_name, ret_temp);
67 EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
70 * thermal_acpi_passive_trip_temp - Retrieve passive trip point temperature
71 * @adev: Target thermal zone ACPI device object.
72 * @ret_temp: Address to store the retrieved temperature value on success.
74 * Evaluate the _PSV object for the thermal zone represented by @adev to obtain
75 * the temperature of the passive cooling trip point.
77 * Return 0 on success or -ENODATA on failure.
79 int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
81 return thermal_acpi_trip_temp(adev, "_PSV", ret_temp);
83 EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
86 * thermal_acpi_hot_trip_temp - Retrieve hot trip point temperature
87 * @adev: Target thermal zone ACPI device object.
88 * @ret_temp: Address to store the retrieved temperature value on success.
90 * Evaluate the _HOT object for the thermal zone represented by @adev to obtain
91 * the temperature of the trip point at which the system is expected to be put
92 * into the S4 sleep state.
94 * Return 0 on success or -ENODATA on failure.
96 int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
98 return thermal_acpi_trip_temp(adev, "_HOT", ret_temp);
100 EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
103 * thermal_acpi_critical_trip_temp - Retrieve critical trip point temperature
104 * @adev: Target thermal zone ACPI device object.
105 * @ret_temp: Address to store the retrieved temperature value on success.
107 * Evaluate the _CRT object for the thermal zone represented by @adev to obtain
108 * the temperature of the critical cooling trip point.
110 * Return 0 on success or -ENODATA on failure.
112 int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
114 return thermal_acpi_trip_temp(adev, "_CRT", ret_temp);
116 EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);