blob: 7fdf682cb2d6aefef42cc540da34e411b68c374d [file] [log] [blame]
Polina Bondarenko25cd7f02016-02-26 12:15:53 +01001/*
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 <sys/cdefs.h>
23#include <sys/types.h>
24
25#include <hardware/hardware.h>
26
27__BEGIN_DECLS
28
29#define THERMAL_HARDWARE_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
30
31#define THERMAL_HARDWARE_MODULE_ID "thermal"
32
33// This value is returned if a desired temperature is not available.
34#define UNKNOWN_TEMPERATURE -FLT_MAX
35
36/** Device temperature types. Must be kept in sync with
37 * framework/base/core/java/android/os/HardwarePropertiesManager.java
38 */
39enum temperature_type {
40 DEVICE_TEMPERATURE_UNKNOWN = -1,
41 DEVICE_TEMPERATURE_CPU = 0,
42 DEVICE_TEMPERATURE_GPU = 1,
43 DEVICE_TEMPERATURE_BATTERY = 2,
44 DEVICE_TEMPERATURE_SKIN = 3
45};
46
47enum cooling_type {
48 /** Fan cooling device speed in RPM. */
49 FAN_RPM = 0,
50};
51
52typedef struct {
53 /**
54 * This temperature's type.
55 */
56 enum temperature_type type;
57
58 /**
59 * Name of this temperature.
60 * All temperatures of the same "type" must have a different "name".
61 */
62 const char *name;
63
64 /**
65 * Current temperature in Celsius. If not available set by HAL to
66 * UNKNOWN_TEMPERATURE.
67 * Current temperature can be in any units if
68 * type=DEVICE_TEMPERATURE_UNKNOWN.
69 */
70 float current_value;
71
72 /**
73 * Throttling temperature constant for this temperature.
74 * If not available, set by HAL to UNKNOWN_TEMPERATURE.
75 */
76 float throttling_threshold;
77
78 /**
79 * Shutdown temperature constant for this temperature.
80 * If not available, set by HAL to UNKNOWN_TEMPERATURE.
81 */
82 float shutdown_threshold;
83} temperature_t;
84
85typedef struct {
86 /**
87 * This cooling device type.
88 */
89 enum cooling_type type;
90
91 /**
92 * Name of this cooling device.
93 * All cooling devices of the same "type" must have a different "name".
94 */
95 const char *name;
96
97 /**
98 * Current cooling device value. Units depend on cooling device "type".
99 */
100 float current_value;
101} cooling_device_t;
102
103typedef struct {
104 /**
105 * Name of this CPU.
106 * All CPUs must have a different "name".
107 */
108 const char *name;
109
110 /**
111 * Active time since the last boot in ms.
112 */
113 uint64_t active;
114
115 /**
116 * Total time since the last boot in ms.
117 */
118 uint64_t total;
119
120 /**
121 * Is set to true when a core is online.
122 * If the core is offline, all other members except |name| should be ignored.
123 */
124 bool is_online;
125} cpu_usage_t;
126
127typedef struct thermal_module {
128 struct hw_module_t common;
129
130 /*
131 * (*getTemperatures) is called to get temperatures in Celsius.
132 *
133 * @param list If NULL, this method only returns number of temperatures
134 * and caller should allocate a temperature_t array with that number
135 * of elements.
136 * Caller is responsible for allocating temperature_t array |list| of
137 * large enough size (not less than returned number of temperatures).
138 * If |list| is not NULL and this method returns non-negative value,
139 * it's filled with the current temperatures. If the resulting
140 * temperature list is longer than |size| elements, the remaining
141 * temperatures are discarded and not stored, but counted for the value
142 * returned by this method.
143 * The order of temperatures of built-in devices (such as CPUs, GPUs and
144 * etc.) in the |list| is kept the same regardless the number of calls
145 * to this method even if they go offline, if these devices exist on
146 * boot. The method always returns and never removes such temperatures.
147 * @param size The capacity of |list|, in elements, if |list| is not NULL.
148 *
149 * @return number of temperatures or negative value -errno on error.
150 *
151 */
152 ssize_t (*getTemperatures)(struct thermal_module *module, temperature_t *list, size_t size);
153
154 /*
155 * (*getCpuUsages) is called to get CPU usage information of each core:
156 * active and total times in ms since first boot.
157 *
158 * @param list If NULL, this method only returns number of cores and caller
159 * should allocate a cpu_usage_t array with that number of elements.
160 * Caller is responsible for allocating cpu_usage_t array |list| of
161 * large enough size (not less than returned number of CPUs).
162 * If |list| is not NULL and this method returns non-negative value,
163 * it's filled with the current CPU usages.
164 * The order of CPUs in the |list| is kept the same regardless the
165 * number of calls to this method.
166 *
167 * @return constant number of CPUs or negative value -errno on error.
168 *
169 */
170 ssize_t (*getCpuUsages)(struct thermal_module *module, cpu_usage_t *list);
171
172 /*
173 * (*getCoolingDevices) is called to get the cooling devices information.
174 *
175 * @param list If NULL, this method only returns number of cooling devices
176 * and caller should allocate a cooling_device_t array with that number
177 * of elements.
178 * Caller is responsible for allocating cooling_device_t array |list| of
179 * large enough size (not less than returned number of cooling devices).
180 * If |list| is not NULL and this method returns non-negative value,
181 * it's filled with the current cooling device information. If the
182 * resulting cooling device list is longer than |size| elements, the
183 * remaining cooling device informations are discarded and not stored,
184 * but counted for the value returned by this method.
185 * The order of built-in coolling devices in the |list| is kept the same
186 * regardless the number of calls to this method even if they go
187 * offline, if these devices exist on boot. The method always returns
188 * and never removes from the list such coolling devices.
189 * @param size The capacity of |list|, in elements, if |list| is not NULL.
190 *
191 * @return number of cooling devices or negative value -errno on error.
192 *
193 */
194 ssize_t (*getCoolingDevices)(struct thermal_module *module, cooling_device_t *list,
195 size_t size);
196} thermal_module_t;
197
198__END_DECLS
199
200#endif // ANDROID_INCLUDE_HARDWARE_THERMAL_H