arm64: dts: qcom: sm8550: add TRNG node
[linux-modified.git] / drivers / thermal / thermal_acpi.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright 2023 Linaro Limited
4  * Copyright 2023 Intel Corporation
5  *
6  * Library routines for populating a generic thermal trip point structure
7  * with data obtained by evaluating a specific object in the ACPI Namespace.
8  */
9 #include <linux/acpi.h>
10 #include <linux/units.h>
11 #include <linux/thermal.h>
12
13 /*
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.
19  */
20 #define TEMP_MIN_DECIK  2180
21 #define TEMP_MAX_DECIK  4480
22
23 static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
24                                   int *ret_temp)
25 {
26         unsigned long long temp;
27         acpi_status status;
28
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);
32                 return -ENODATA;
33         }
34
35         if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) {
36                 *ret_temp = deci_kelvin_to_millicelsius(temp);
37         } else {
38                 acpi_handle_debug(adev->handle, "%s result %llu out of range\n",
39                                   obj_name, temp);
40                 *ret_temp = THERMAL_TEMP_INVALID;
41         }
42
43         return 0;
44 }
45
46 /**
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.
51  *
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.
55  *
56  * Return 0 on success or a negative error value on failure.
57  */
58 int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
59 {
60         char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
61
62         if (id < 0 || id > 9)
63                 return -EINVAL;
64
65         return thermal_acpi_trip_temp(adev, obj_name, ret_temp);
66 }
67 EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
68
69 /**
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.
73  *
74  * Evaluate the _PSV object for the thermal zone represented by @adev to obtain
75  * the temperature of the passive cooling trip point.
76  *
77  * Return 0 on success or -ENODATA on failure.
78  */
79 int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
80 {
81         return thermal_acpi_trip_temp(adev, "_PSV", ret_temp);
82 }
83 EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
84
85 /**
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.
89  *
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.
93  *
94  * Return 0 on success or -ENODATA on failure.
95  */
96 int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
97 {
98         return thermal_acpi_trip_temp(adev, "_HOT", ret_temp);
99 }
100 EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
101
102 /**
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.
106  *
107  * Evaluate the _CRT object for the thermal zone represented by @adev to obtain
108  * the temperature of the critical cooling trip point.
109  *
110  * Return 0 on success or -ENODATA on failure.
111  */
112 int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
113 {
114         return thermal_acpi_trip_temp(adev, "_CRT", ret_temp);
115 }
116 EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);