blob: b7a9632b670892a792de506a7731370678325689 [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,
Luca Stefanieccedf92016-08-25 17:59:24 +020066 POWER_HINT_VR_MODE = 0x00000007,
Dilip Gudlurb10adae2015-08-14 19:30:13 -070067 POWER_HINT_CAM_PREVIEW = 0x00000008,
Steve Kondik5393ed72013-11-01 20:28:10 +000068
69 POWER_HINT_CPU_BOOST = 0x00000010,
70 POWER_HINT_LAUNCH_BOOST = 0x00000011,
71 POWER_HINT_AUDIO = 0x00000020,
72 POWER_HINT_SET_PROFILE = 0x00000030
73
Todd Poynor2f143fb2012-04-24 13:39:15 -070074} power_hint_t;
75
Ruchi Kandoid0917132014-10-29 10:43:38 -070076typedef enum {
Steve Kondik5393ed72013-11-01 20:28:10 +000077 POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001,
78 POWER_FEATURE_SUPPORTED_PROFILES = 0x00001000
Ruchi Kandoid0917132014-10-29 10:43:38 -070079} feature_t;
80
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -070081/*
82 * Platform-level sleep state stats:
83 * power_state_voter_t struct is useful for describing the individual voters when a
84 * Platform-level sleep state is chosen by aggregation of votes from multiple
85 * clients/system conditions.
86 *
87 * This helps in attirbuting what in the device is blocking the device from
88 * entering the lowest Platform-level sleep state.
89 */
90typedef struct {
91 /*
92 * Name of the voter.
93 */
94 char name[POWER_STATE_VOTER_NAME_MAX_LENGTH];
95
96 /*
97 * Total time in msec the voter voted for the platform sleep state since boot.
98 */
99 uint64_t total_time_in_msec_voted_for_since_boot;
100
101 /*
102 * Number of times the voter voted for the platform sleep state since boot.
103 */
104 uint64_t total_number_of_times_voted_since_boot;
105} power_state_voter_t;
106
107/*
108 * Platform-level sleep state stats:
109 * power_state_platform_sleep_state_t represents the Platform-level sleep state the
110 * device is capable of getting into.
111 *
112 * SoCs usually have more than one Platform-level sleep state.
113 *
114 * The caller calls the get_number_of_platform_modes function to figure out the size
115 * of power_state_platform_sleep_state_t array where each array element represents
116 * a specific Platform-level sleep state.
117 *
118 * Higher the index deeper the state is i.e. lesser steady-state power is consumed
119 * by the platform to be resident in that state.
120 *
121 * Caller allocates power_state_voter_t *voters for each Platform-level sleep state by
122 * calling get_voter_list.
123 */
124typedef struct {
125 /*
126 * Platform-level Sleep state name.
127 */
128 char name[POWER_STATE_NAME_MAX_LENGTH];
129
130 /*
131 * Time spent in msec at this platform-level sleep state since boot.
132 */
133 uint64_t residency_in_msec_since_boot;
134
135 /*
136 * Total number of times system entered this state.
137 */
138 uint64_t total_transitions;
139
140 /*
141 * This platform-level sleep state can only be reached during system suspend.
142 */
143 bool supported_only_in_suspend;
144
145 /*
146 * The following fields are useful if the Platform-level sleep state
147 * is chosen by aggregation votes from multiple clients/system conditions.
148 * All the voters have to say yes or all the system conditions need to be
149 * met to enter a platform-level sleep state.
150 *
151 * Setting number_of_voters to zero implies either the info is not available
152 * or the system does not follow a voting mechanism to choose this
153 * Platform-level sleep state.
154 */
155 uint32_t number_of_voters;
156
157 /*
158 * Voter list - Has to be allocated by the caller.
159 *
160 * Caller allocates power_state_voter_t *voters for each Platform-level sleep state
161 * by calling get_voter_list.
162 */
163 power_state_voter_t *voters;
164} power_state_platform_sleep_state_t;
165
Todd Poynorc82792c2012-01-10 00:32:42 -0800166/**
Steve Kondik5393ed72013-11-01 20:28:10 +0000167 * Process info, passed as an opaque handle when
168 * using POWER_HINT_LAUNCH_BOOST.
169 */
170typedef struct launch_boost_info {
171 pid_t pid;
172 const char* packageName;
173} launch_boost_info_t;
174
175/**
Todd Poynorc82792c2012-01-10 00:32:42 -0800176 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
177 * and the fields of this data structure must begin with hw_module_t
178 * followed by module specific information.
179 */
180typedef struct power_module {
181 struct hw_module_t common;
182
183 /*
184 * (*init)() performs power management setup actions at runtime
Todd Poynor2f143fb2012-04-24 13:39:15 -0700185 * startup, such as to set default cpufreq parameters. This is
186 * called only by the Power HAL instance loaded by
187 * PowerManagerService.
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -0700188 *
189 * Platform-level sleep state stats:
190 * Can Also be used to initiate device specific Platform-level
191 * Sleep state nodes from version 0.5 onwards.
Todd Poynorc82792c2012-01-10 00:32:42 -0800192 */
193 void (*init)(struct power_module *module);
194
195 /*
196 * (*setInteractive)() performs power management actions upon the
197 * system entering interactive state (that is, the system is awake
198 * and ready for interaction, often with UI devices such as
199 * display and touchscreen enabled) or non-interactive state (the
200 * system appears asleep, display usually turned off). The
201 * non-interactive state is usually entered after a period of
202 * inactivity, in order to conserve battery power during
203 * such inactive periods.
204 *
205 * Typical actions are to turn on or off devices and adjust
206 * cpufreq parameters. This function may also call the
207 * appropriate interfaces to allow the kernel to suspend the
208 * system to low-power sleep state when entering non-interactive
209 * state, and to disallow low-power suspend when the system is in
210 * interactive state. When low-power suspend state is allowed, the
211 * kernel may suspend the system whenever no wakelocks are held.
212 *
213 * on is non-zero when the system is transitioning to an
214 * interactive / awake state, and zero when transitioning to a
215 * non-interactive / asleep state.
216 *
217 * This function is called to enter non-interactive state after
218 * turning off the screen (if present), and called to enter
219 * interactive state prior to turning on the screen.
220 */
221 void (*setInteractive)(struct power_module *module, int on);
Todd Poynor2f143fb2012-04-24 13:39:15 -0700222
223 /*
224 * (*powerHint) is called to pass hints on power requirements, which
225 * may result in adjustment of power/performance parameters of the
226 * cpufreq governor and other controls. The possible hints are:
227 *
228 * POWER_HINT_VSYNC
229 *
230 * Foreground app has started or stopped requesting a VSYNC pulse
231 * from SurfaceFlinger. If the app has started requesting VSYNC
232 * then CPU and GPU load is expected soon, and it may be appropriate
233 * to raise speeds of CPU, memory bus, etc. The data parameter is
234 * non-zero to indicate VSYNC pulse is now requested, or zero for
235 * VSYNC pulse no longer requested.
236 *
Todd Poynorbcdb4cd2012-05-03 14:49:02 -0700237 * POWER_HINT_INTERACTION
238 *
239 * User is interacting with the device, for example, touchscreen
240 * events are incoming. CPU and GPU load may be expected soon,
241 * and it may be appropriate to raise speeds of CPU, memory bus,
Michael Wright147d5402015-09-16 23:28:19 +0100242 * etc. The data parameter is the estimated length of the interaction
243 * in milliseconds, or 0 if unknown.
Todd Poynorbcdb4cd2012-05-03 14:49:02 -0700244 *
Ruchi Kandoi62f67552014-05-02 13:52:51 -0700245 * POWER_HINT_LOW_POWER
246 *
247 * Low power mode is activated or deactivated. Low power mode
248 * is intended to save battery at the cost of performance. The data
249 * parameter is non-zero when low power mode is activated, and zero
250 * when deactivated.
251 *
Ruchi Kandoi94898652016-01-13 09:09:57 -0800252 * POWER_HINT_SUSTAINED_PERFORMANCE
253 *
254 * Sustained Performance mode is actived or deactivated. Sustained
255 * performance mode is intended to provide a consistent level of
256 * performance for a prolonged amount of time. The data parameter is
257 * non-zero when sustained performance mode is activated, and zero
258 * when deactivated.
259 *
Ruchi Kandoi403bc142016-03-09 15:16:30 -0800260 * POWER_HINT_VR_MODE
261 *
262 * VR Mode is activated or deactivated. VR mode is intended to
263 * provide minimum guarantee for performance for the amount of time the
264 * device can sustain it. The data parameter is non-zero when the mode
265 * is activated and zero when deactivated.
266 *
Steve Kondik5393ed72013-11-01 20:28:10 +0000267 * POWER_HINT_CPU_BOOST
268 *
269 * An operation is happening where it would be ideal for the CPU to
270 * be boosted for a specific duration. The data parameter is an
271 * integer value of the boost duration in microseconds.
272 *
Todd Poynor2f143fb2012-04-24 13:39:15 -0700273 * A particular platform may choose to ignore any hint.
Mathias Agopian5cb1de82012-04-26 19:49:40 -0700274 *
275 * availability: version 0.2
276 *
Todd Poynor2f143fb2012-04-24 13:39:15 -0700277 */
278 void (*powerHint)(struct power_module *module, power_hint_t hint,
279 void *data);
Ruchi Kandoid0917132014-10-29 10:43:38 -0700280
281 /*
282 * (*setFeature) is called to turn on or off a particular feature
283 * depending on the state parameter. The possible features are:
284 *
285 * FEATURE_DOUBLE_TAP_TO_WAKE
286 *
287 * Enabling/Disabling this feature will allow/disallow the system
288 * to wake up by tapping the screen twice.
289 *
290 * availability: version 0.3
291 *
292 */
293 void (*setFeature)(struct power_module *module, feature_t feature, int state);
294
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -0700295 /*
Steve Kondik5393ed72013-11-01 20:28:10 +0000296 * (*getFeature) is called to get the current value of a particular
297 * feature or capability from the hardware or PowerHAL
298 */
299 int (*getFeature)(struct power_module *module, feature_t feature);
300
301 /*
Badhri Jagan Sridharan2b238d62016-04-03 21:46:07 -0700302 * Platform-level sleep state stats:
303 * Report cumulative info on the statistics on platform-level sleep states since boot.
304 *
305 * Caller of the function queries the get_number_of_sleep_states and allocates the
306 * memory for the power_state_platform_sleep_state_t *list before calling this function.
307 *
308 * power_stats module is responsible to assign values to all the fields as
309 * necessary.
310 *
311 * Higher the index deeper the state is i.e. lesser steady-state power is consumed
312 * by the platform to be resident in that state.
313 *
314 * The function returns 0 on success or negative value -errno on error.
315 * EINVAL - *list is NULL.
316 * EIO - filesystem nodes access error.
317 *
318 * availability: version 0.5
319 */
320 int (*get_platform_low_power_stats)(struct power_module *module,
321 power_state_platform_sleep_state_t *list);
322
323 /*
324 * Platform-level sleep state stats:
325 * This function is called to determine the number of platform-level sleep states
326 * for get_platform_low_power_stats.
327 *
328 * The value returned by this function is used to allocate memory for
329 * power_state_platform_sleep_state_t *list for get_platform_low_power_stats.
330 *
331 * The number of parameters must not change for successive calls.
332 *
333 * Return number of parameters on success or negative value -errno on error.
334 * EIO - filesystem nodes access error.
335 *
336 * availability: version 0.5
337 */
338 ssize_t (*get_number_of_platform_modes)(struct power_module *module);
339
340 /*
341 * Platform-level sleep state stats:
342 * Provides the number of voters for each of the Platform-level sleep state.
343 *
344 * Caller uses this function to allocate memory for the power_state_voter_t list.
345 *
346 * Caller has to allocate the space for the *voter array which is
347 * get_number_of_platform_modes() long.
348 *
349 * Return 0 on success or negative value -errno on error.
350 * EINVAL - *voter is NULL.
351 * EIO - filesystem nodes access error.
352 *
353 * availability: version 0.5
354 */
355 int (*get_voter_list)(struct power_module *module, size_t *voter);
356
Todd Poynorc82792c2012-01-10 00:32:42 -0800357} power_module_t;
358
Todd Poynorc82792c2012-01-10 00:32:42 -0800359__END_DECLS
360
361#endif // ANDROID_INCLUDE_HARDWARE_POWER_H