• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_INCLUDE_HARDWARE_THERMAL_H
18 #define ANDROID_INCLUDE_HARDWARE_THERMAL_H
19 
20 #include <stdbool.h>
21 #include <stdint.h>
22 #include <float.h>
23 #include <sys/cdefs.h>
24 #include <sys/types.h>
25 
26 #include <hardware/hardware.h>
27 
28 __BEGIN_DECLS
29 
30 #define THERMAL_HARDWARE_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
31 
32 #define THERMAL_HARDWARE_MODULE_ID "thermal"
33 
34 // This value is returned if a desired temperature is not available.
35 #define UNKNOWN_TEMPERATURE -FLT_MAX
36 
37 /** Device temperature types. Must be kept in sync with
38  * framework/base/core/java/android/os/HardwarePropertiesManager.java
39  */
40 enum temperature_type {
41     DEVICE_TEMPERATURE_UNKNOWN  = -1,
42     DEVICE_TEMPERATURE_CPU      = 0,
43     DEVICE_TEMPERATURE_GPU      = 1,
44     DEVICE_TEMPERATURE_BATTERY  = 2,
45     DEVICE_TEMPERATURE_SKIN     = 3
46 };
47 
48 enum cooling_type {
49     /** Fan cooling device speed in RPM. */
50     FAN_RPM                     = 0,
51 };
52 
53 typedef struct {
54   /**
55    * This temperature's type.
56    */
57   enum temperature_type type;
58 
59   /**
60    * Name of this temperature.
61    * All temperatures of the same "type" must have a different "name".
62    */
63   const char *name;
64 
65   /**
66    * Current temperature in Celsius. If not available set by HAL to
67    * UNKNOWN_TEMPERATURE.
68    * Current temperature can be in any units if
69    * type=DEVICE_TEMPERATURE_UNKNOWN.
70    */
71   float current_value;
72 
73   /**
74    * Throttling temperature constant for this temperature.
75    * If not available, set by HAL to UNKNOWN_TEMPERATURE.
76    */
77   float throttling_threshold;
78 
79   /**
80    * Shutdown temperature constant for this temperature.
81    * If not available, set by HAL to UNKNOWN_TEMPERATURE.
82    */
83   float shutdown_threshold;
84 
85   /**
86    * Threshold temperature above which the VR mode clockrate minimums cannot
87    * be maintained for this device.
88    * If not available, set by HAL to UNKNOWN_TEMPERATURE.
89    */
90   float vr_throttling_threshold;
91 } temperature_t;
92 
93 typedef struct {
94     /**
95      * This cooling device type.
96      */
97     enum cooling_type type;
98 
99     /**
100      * Name of this cooling device.
101      * All cooling devices of the same "type" must have a different "name".
102      */
103     const char *name;
104 
105     /**
106      * Current cooling device value. Units depend on cooling device "type".
107      */
108     float current_value;
109 } cooling_device_t;
110 
111 typedef struct {
112     /**
113      * Name of this CPU.
114      * All CPUs must have a different "name".
115      */
116     const char *name;
117 
118     /**
119      * Active time since the last boot in ms.
120      */
121     uint64_t active;
122 
123     /**
124      * Total time since the last boot in ms.
125      */
126     uint64_t total;
127 
128     /**
129      * Is set to true when a core is online.
130      * If the core is offline, all other members except |name| should be ignored.
131      */
132     bool is_online;
133 } cpu_usage_t;
134 
135 typedef struct thermal_module {
136     struct hw_module_t common;
137 
138     /*
139      * (*getTemperatures) is called to get temperatures in Celsius.
140      *
141      * @param list If NULL, this method only returns number of temperatures
142      *     and caller should allocate a temperature_t array with that number
143      *     of elements.
144      *     Caller is responsible for allocating temperature_t array |list| of
145      *     large enough size (not less than returned number of temperatures).
146      *     If |list| is not NULL and this method returns non-negative value,
147      *     it's filled with the current temperatures. If the resulting
148      *     temperature list is longer than |size| elements, the remaining
149      *     temperatures are discarded and not stored, but counted for the value
150      *     returned by this method.
151      *     The order of temperatures of built-in devices (such as CPUs, GPUs and
152      *     etc.) in the |list| is kept the same regardless the number of calls
153      *     to this method even if they go offline, if these devices exist on
154      *     boot. The method always returns and never removes such temperatures.
155      * @param size The capacity of |list|, in elements, if |list| is not NULL.
156      *
157      * @return number of temperatures or negative value -errno on error.
158      *
159      */
160     ssize_t (*getTemperatures)(struct thermal_module *module, temperature_t *list, size_t size);
161 
162     /*
163      * (*getCpuUsages) is called to get CPU usage information of each core:
164      *     active and total times in ms since first boot.
165      *
166      * @param list If NULL, this method only returns number of cores and caller
167      *     should allocate a cpu_usage_t array with that number of elements.
168      *     Caller is responsible for allocating cpu_usage_t array |list| of
169      *     large enough size (not less than returned number of CPUs).
170      *     If |list| is not NULL and this method returns non-negative value,
171      *     it's filled with the current CPU usages.
172      *     The order of CPUs in the |list| is kept the same regardless the
173      *     number of calls to this method.
174      *
175      * @return constant number of CPUs or negative value -errno on error.
176      *
177      */
178     ssize_t (*getCpuUsages)(struct thermal_module *module, cpu_usage_t *list);
179 
180     /*
181      * (*getCoolingDevices) is called to get the cooling devices information.
182      *
183      * @param list If NULL, this method only returns number of cooling devices
184      *     and caller should allocate a cooling_device_t array with that number
185      *     of elements.
186      *     Caller is responsible for allocating cooling_device_t array |list| of
187      *     large enough size (not less than returned number of cooling devices).
188      *     If |list| is not NULL and this method returns non-negative value,
189      *     it's filled with the current cooling device information. If the
190      *     resulting cooling device list is longer than |size| elements, the
191      *     remaining cooling device informations are discarded and not stored,
192      *     but counted for the value returned by this method.
193      *     The order of built-in coolling devices in the |list| is kept the same
194      *     regardless the number of calls to this method even if they go
195      *     offline, if these devices exist on boot. The method always returns
196      *     and never removes from the list such coolling devices.
197      * @param size The capacity of |list|, in elements, if |list| is not NULL.
198      *
199      * @return number of cooling devices or negative value -errno on error.
200      *
201      */
202     ssize_t (*getCoolingDevices)(struct thermal_module *module, cooling_device_t *list,
203                                  size_t size);
204 
205 } thermal_module_t;
206 
207 __END_DECLS
208 
209 #endif  // ANDROID_INCLUDE_HARDWARE_THERMAL_H
210