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>
12 #include "thermal_core.h"
15 * Minimum temperature for full military grade is 218°K (-55°C) and
16 * max temperature is 448°K (175°C). We can consider those values as
17 * the boundaries for the [trips] temperature returned by the
18 * firmware. Any values out of these boundaries may be considered
19 * bogus and we can assume the firmware has no data to provide.
21 #define TEMP_MIN_DECIK 2180
22 #define TEMP_MAX_DECIK 4480
24 static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
27 unsigned long long temp;
30 status = acpi_evaluate_integer(adev->handle, obj_name, NULL, &temp);
31 if (ACPI_FAILURE(status)) {
32 acpi_handle_debug(adev->handle, "%s evaluation failed\n", obj_name);
36 if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) {
37 *ret_temp = deci_kelvin_to_millicelsius(temp);
39 acpi_handle_debug(adev->handle, "%s result %llu out of range\n",
41 *ret_temp = THERMAL_TEMP_INVALID;
48 * thermal_acpi_active_trip_temp - Retrieve active trip point temperature
49 * @adev: Target thermal zone ACPI device object.
50 * @id: Active cooling level (0 - 9).
51 * @ret_temp: Address to store the retrieved temperature value on success.
53 * Evaluate the _ACx object for the thermal zone represented by @adev to obtain
54 * the temperature of the active cooling trip point corresponding to the active
55 * cooling level given by @id.
57 * Return 0 on success or a negative error value on failure.
59 int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
61 char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
66 return thermal_acpi_trip_temp(adev, obj_name, ret_temp);
68 EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
71 * thermal_acpi_passive_trip_temp - Retrieve passive trip point temperature
72 * @adev: Target thermal zone ACPI device object.
73 * @ret_temp: Address to store the retrieved temperature value on success.
75 * Evaluate the _PSV object for the thermal zone represented by @adev to obtain
76 * the temperature of the passive cooling trip point.
78 * Return 0 on success or -ENODATA on failure.
80 int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
82 return thermal_acpi_trip_temp(adev, "_PSV", ret_temp);
84 EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
87 * thermal_acpi_hot_trip_temp - Retrieve hot trip point temperature
88 * @adev: Target thermal zone ACPI device object.
89 * @ret_temp: Address to store the retrieved temperature value on success.
91 * Evaluate the _HOT object for the thermal zone represented by @adev to obtain
92 * the temperature of the trip point at which the system is expected to be put
93 * into the S4 sleep state.
95 * Return 0 on success or -ENODATA on failure.
97 int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
99 return thermal_acpi_trip_temp(adev, "_HOT", ret_temp);
101 EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
104 * thermal_acpi_critical_trip_temp - Retrieve critical trip point temperature
105 * @adev: Target thermal zone ACPI device object.
106 * @ret_temp: Address to store the retrieved temperature value on success.
108 * Evaluate the _CRT object for the thermal zone represented by @adev to obtain
109 * the temperature of the critical cooling trip point.
111 * Return 0 on success or -ENODATA on failure.
113 int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
115 return thermal_acpi_trip_temp(adev, "_CRT", ret_temp);
117 EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);