blob: f15e3cdb154b8be3abace161cb501181febd895f [file] [log] [blame]
Todd Poynorc82792c2012-01-10 00:32:42 -08001/*
2 * Copyright (C) 2012 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_POWER_H
18#define ANDROID_INCLUDE_HARDWARE_POWER_H
19
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -070020#include <stdbool.h>
Todd Poynorc82792c2012-01-10 00:32:42 -080021#include <stdint.h>
22#include <sys/cdefs.h>
23#include <sys/types.h>
24
25#include <hardware/hardware.h>
26
27__BEGIN_DECLS
28
Mathias Agopian5cb1de82012-04-26 19:49:40 -070029#define POWER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
30#define POWER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
Ruchi Kandoid0917132014-10-29 10:43:38 -070031#define POWER_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
Ruchi Kandoi94898652016-01-13 09:09:57 -080032#define POWER_MODULE_API_VERSION_0_4 HARDWARE_MODULE_API_VERSION(0, 4)
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -070033#define POWER_MODULE_API_VERSION_0_5 HARDWARE_MODULE_API_VERSION(0, 5)
Mathias Agopian5cb1de82012-04-26 19:49:40 -070034
Todd Poynorc82792c2012-01-10 00:32:42 -080035/**
36 * The id of this module
37 */
38#define POWER_HARDWARE_MODULE_ID "power"
39
Todd Poynor2f143fb2012-04-24 13:39:15 -070040/*
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -070041 * Platform-level sleep state stats.
42 * Maximum length of Platform-level sleep state name.
43 */
44#define POWER_STATE_NAME_MAX_LENGTH 100
45
46/*
47 * Platform-level sleep state stats.
48 * Maximum length of Platform-level sleep state voter name.
49 */
50#define POWER_STATE_VOTER_NAME_MAX_LENGTH 100
51
52/*
Todd Poynor2f143fb2012-04-24 13:39:15 -070053 * Power hint identifiers passed to (*powerHint)
54 */
55
56typedef enum {
Todd Poynor2f143fb2012-04-24 13:39:15 -070057 POWER_HINT_VSYNC = 0x00000001,
Todd Poynorbcdb4cd2012-05-03 14:49:02 -070058 POWER_HINT_INTERACTION = 0x00000002,
Iliyan Malchev1a70c0f2013-06-25 18:50:49 -070059 /* DO NOT USE POWER_HINT_VIDEO_ENCODE/_DECODE! They will be removed in
60 * KLP.
61 */
Mekala Natarajan501fc0f2013-06-19 15:57:22 -070062 POWER_HINT_VIDEO_ENCODE = 0x00000003,
Ruchi Kandoi62f67552014-05-02 13:52:51 -070063 POWER_HINT_VIDEO_DECODE = 0x00000004,
Ruchi Kandoi94898652016-01-13 09:09:57 -080064 POWER_HINT_LOW_POWER = 0x00000005,
Ruchi Kandoi403bc142016-03-09 15:16:30 -080065 POWER_HINT_SUSTAINED_PERFORMANCE = 0x00000006,
Wei Wanga787ab72016-05-18 11:27:54 -070066 POWER_HINT_VR_MODE = 0x00000007,
67 POWER_HINT_LAUNCH = 0x00000008
Todd Poynor2f143fb2012-04-24 13:39:15 -070068} power_hint_t;
69
Ruchi Kandoid0917132014-10-29 10:43:38 -070070typedef enum {
71 POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001
72} feature_t;
73
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -070074/*
75 * Platform-level sleep state stats:
76 * power_state_voter_t struct is useful for describing the individual voters when a
77 * Platform-level sleep state is chosen by aggregation of votes from multiple
78 * clients/system conditions.
79 *
80 * This helps in attirbuting what in the device is blocking the device from
81 * entering the lowest Platform-level sleep state.
82 */
83typedef struct {
84 /*
85 * Name of the voter.
86 */
87 char name[POWER_STATE_VOTER_NAME_MAX_LENGTH];
88
89 /*
90 * Total time in msec the voter voted for the platform sleep state since boot.
91 */
92 uint64_t total_time_in_msec_voted_for_since_boot;
93
94 /*
95 * Number of times the voter voted for the platform sleep state since boot.
96 */
97 uint64_t total_number_of_times_voted_since_boot;
98} power_state_voter_t;
99
100/*
101 * Platform-level sleep state stats:
102 * power_state_platform_sleep_state_t represents the Platform-level sleep state the
103 * device is capable of getting into.
104 *
105 * SoCs usually have more than one Platform-level sleep state.
106 *
107 * The caller calls the get_number_of_platform_modes function to figure out the size
108 * of power_state_platform_sleep_state_t array where each array element represents
109 * a specific Platform-level sleep state.
110 *
111 * Higher the index deeper the state is i.e. lesser steady-state power is consumed
112 * by the platform to be resident in that state.
113 *
114 * Caller allocates power_state_voter_t *voters for each Platform-level sleep state by
115 * calling get_voter_list.
116 */
117typedef struct {
118 /*
119 * Platform-level Sleep state name.
120 */
121 char name[POWER_STATE_NAME_MAX_LENGTH];
122
123 /*
124 * Time spent in msec at this platform-level sleep state since boot.
125 */
126 uint64_t residency_in_msec_since_boot;
127
128 /*
129 * Total number of times system entered this state.
130 */
131 uint64_t total_transitions;
132
133 /*
134 * This platform-level sleep state can only be reached during system suspend.
135 */
136 bool supported_only_in_suspend;
137
138 /*
139 * The following fields are useful if the Platform-level sleep state
140 * is chosen by aggregation votes from multiple clients/system conditions.
141 * All the voters have to say yes or all the system conditions need to be
142 * met to enter a platform-level sleep state.
143 *
144 * Setting number_of_voters to zero implies either the info is not available
145 * or the system does not follow a voting mechanism to choose this
146 * Platform-level sleep state.
147 */
148 uint32_t number_of_voters;
149
150 /*
151 * Voter list - Has to be allocated by the caller.
152 *
153 * Caller allocates power_state_voter_t *voters for each Platform-level sleep state
154 * by calling get_voter_list.
155 */
156 power_state_voter_t *voters;
157} power_state_platform_sleep_state_t;
158
Todd Poynorc82792c2012-01-10 00:32:42 -0800159/**
160 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
161 * and the fields of this data structure must begin with hw_module_t
162 * followed by module specific information.
163 */
164typedef struct power_module {
165 struct hw_module_t common;
166
167 /*
168 * (*init)() performs power management setup actions at runtime
Todd Poynor2f143fb2012-04-24 13:39:15 -0700169 * startup, such as to set default cpufreq parameters. This is
170 * called only by the Power HAL instance loaded by
171 * PowerManagerService.
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -0700172 *
173 * Platform-level sleep state stats:
174 * Can Also be used to initiate device specific Platform-level
175 * Sleep state nodes from version 0.5 onwards.
Todd Poynorc82792c2012-01-10 00:32:42 -0800176 */
177 void (*init)(struct power_module *module);
178
179 /*
180 * (*setInteractive)() performs power management actions upon the
181 * system entering interactive state (that is, the system is awake
182 * and ready for interaction, often with UI devices such as
183 * display and touchscreen enabled) or non-interactive state (the
184 * system appears asleep, display usually turned off). The
185 * non-interactive state is usually entered after a period of
186 * inactivity, in order to conserve battery power during
187 * such inactive periods.
188 *
189 * Typical actions are to turn on or off devices and adjust
190 * cpufreq parameters. This function may also call the
191 * appropriate interfaces to allow the kernel to suspend the
192 * system to low-power sleep state when entering non-interactive
193 * state, and to disallow low-power suspend when the system is in
194 * interactive state. When low-power suspend state is allowed, the
195 * kernel may suspend the system whenever no wakelocks are held.
196 *
197 * on is non-zero when the system is transitioning to an
198 * interactive / awake state, and zero when transitioning to a
199 * non-interactive / asleep state.
200 *
201 * This function is called to enter non-interactive state after
202 * turning off the screen (if present), and called to enter
203 * interactive state prior to turning on the screen.
204 */
205 void (*setInteractive)(struct power_module *module, int on);
Todd Poynor2f143fb2012-04-24 13:39:15 -0700206
207 /*
208 * (*powerHint) is called to pass hints on power requirements, which
209 * may result in adjustment of power/performance parameters of the
210 * cpufreq governor and other controls. The possible hints are:
211 *
212 * POWER_HINT_VSYNC
213 *
214 * Foreground app has started or stopped requesting a VSYNC pulse
215 * from SurfaceFlinger. If the app has started requesting VSYNC
216 * then CPU and GPU load is expected soon, and it may be appropriate
217 * to raise speeds of CPU, memory bus, etc. The data parameter is
218 * non-zero to indicate VSYNC pulse is now requested, or zero for
219 * VSYNC pulse no longer requested.
220 *
Todd Poynorbcdb4cd2012-05-03 14:49:02 -0700221 * POWER_HINT_INTERACTION
222 *
223 * User is interacting with the device, for example, touchscreen
224 * events are incoming. CPU and GPU load may be expected soon,
225 * and it may be appropriate to raise speeds of CPU, memory bus,
Michael Wright147d5402015-09-16 23:28:19 +0100226 * etc. The data parameter is the estimated length of the interaction
227 * in milliseconds, or 0 if unknown.
Todd Poynorbcdb4cd2012-05-03 14:49:02 -0700228 *
Ruchi Kandoi62f67552014-05-02 13:52:51 -0700229 * POWER_HINT_LOW_POWER
230 *
231 * Low power mode is activated or deactivated. Low power mode
232 * is intended to save battery at the cost of performance. The data
233 * parameter is non-zero when low power mode is activated, and zero
234 * when deactivated.
235 *
Ruchi Kandoi94898652016-01-13 09:09:57 -0800236 * POWER_HINT_SUSTAINED_PERFORMANCE
237 *
238 * Sustained Performance mode is actived or deactivated. Sustained
239 * performance mode is intended to provide a consistent level of
240 * performance for a prolonged amount of time. The data parameter is
241 * non-zero when sustained performance mode is activated, and zero
242 * when deactivated.
243 *
Ruchi Kandoi403bc142016-03-09 15:16:30 -0800244 * POWER_HINT_VR_MODE
245 *
246 * VR Mode is activated or deactivated. VR mode is intended to
247 * provide minimum guarantee for performance for the amount of time the
248 * device can sustain it. The data parameter is non-zero when the mode
249 * is activated and zero when deactivated.
250 *
Todd Poynor2f143fb2012-04-24 13:39:15 -0700251 * A particular platform may choose to ignore any hint.
Mathias Agopian5cb1de82012-04-26 19:49:40 -0700252 *
253 * availability: version 0.2
254 *
Todd Poynor2f143fb2012-04-24 13:39:15 -0700255 */
256 void (*powerHint)(struct power_module *module, power_hint_t hint,
257 void *data);
Ruchi Kandoid0917132014-10-29 10:43:38 -0700258
259 /*
260 * (*setFeature) is called to turn on or off a particular feature
261 * depending on the state parameter. The possible features are:
262 *
263 * FEATURE_DOUBLE_TAP_TO_WAKE
264 *
265 * Enabling/Disabling this feature will allow/disallow the system
266 * to wake up by tapping the screen twice.
267 *
268 * availability: version 0.3
269 *
270 */
271 void (*setFeature)(struct power_module *module, feature_t feature, int state);
272
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -0700273 /*
274 * Platform-level sleep state stats:
275 * Report cumulative info on the statistics on platform-level sleep states since boot.
276 *
277 * Caller of the function queries the get_number_of_sleep_states and allocates the
278 * memory for the power_state_platform_sleep_state_t *list before calling this function.
279 *
280 * power_stats module is responsible to assign values to all the fields as
281 * necessary.
282 *
283 * Higher the index deeper the state is i.e. lesser steady-state power is consumed
284 * by the platform to be resident in that state.
285 *
286 * The function returns 0 on success or negative value -errno on error.
287 * EINVAL - *list is NULL.
288 * EIO - filesystem nodes access error.
289 *
290 * availability: version 0.5
291 */
292 int (*get_platform_low_power_stats)(struct power_module *module,
293 power_state_platform_sleep_state_t *list);
294
295 /*
296 * Platform-level sleep state stats:
297 * This function is called to determine the number of platform-level sleep states
298 * for get_platform_low_power_stats.
299 *
300 * The value returned by this function is used to allocate memory for
301 * power_state_platform_sleep_state_t *list for get_platform_low_power_stats.
302 *
303 * The number of parameters must not change for successive calls.
304 *
305 * Return number of parameters on success or negative value -errno on error.
306 * EIO - filesystem nodes access error.
307 *
308 * availability: version 0.5
309 */
310 ssize_t (*get_number_of_platform_modes)(struct power_module *module);
311
312 /*
313 * Platform-level sleep state stats:
314 * Provides the number of voters for each of the Platform-level sleep state.
315 *
316 * Caller uses this function to allocate memory for the power_state_voter_t list.
317 *
318 * Caller has to allocate the space for the *voter array which is
319 * get_number_of_platform_modes() long.
320 *
321 * Return 0 on success or negative value -errno on error.
322 * EINVAL - *voter is NULL.
323 * EIO - filesystem nodes access error.
324 *
325 * availability: version 0.5
326 */
327 int (*get_voter_list)(struct power_module *module, size_t *voter);
328
Todd Poynorc82792c2012-01-10 00:32:42 -0800329} power_module_t;
330
331
332__END_DECLS
333
334#endif // ANDROID_INCLUDE_HARDWARE_POWER_H