blob: 29ef4dcd088d9ff17f5c36512a3484645cf4bc3c [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
20#include <stdint.h>
21#include <sys/cdefs.h>
22#include <sys/types.h>
23
24#include <hardware/hardware.h>
25
26__BEGIN_DECLS
27
Mathias Agopian5cb1de82012-04-26 19:49:40 -070028#define POWER_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
29#define POWER_MODULE_API_VERSION_0_2 HARDWARE_MODULE_API_VERSION(0, 2)
Ruchi Kandoid0917132014-10-29 10:43:38 -070030#define POWER_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3)
Ruchi Kandoi94898652016-01-13 09:09:57 -080031#define POWER_MODULE_API_VERSION_0_4 HARDWARE_MODULE_API_VERSION(0, 4)
Mathias Agopian5cb1de82012-04-26 19:49:40 -070032
Todd Poynorc82792c2012-01-10 00:32:42 -080033/**
34 * The id of this module
35 */
36#define POWER_HARDWARE_MODULE_ID "power"
37
Todd Poynor2f143fb2012-04-24 13:39:15 -070038/*
39 * Power hint identifiers passed to (*powerHint)
40 */
41
42typedef enum {
Todd Poynor2f143fb2012-04-24 13:39:15 -070043 POWER_HINT_VSYNC = 0x00000001,
Todd Poynorbcdb4cd2012-05-03 14:49:02 -070044 POWER_HINT_INTERACTION = 0x00000002,
Iliyan Malchev1a70c0f2013-06-25 18:50:49 -070045 /* DO NOT USE POWER_HINT_VIDEO_ENCODE/_DECODE! They will be removed in
46 * KLP.
47 */
Mekala Natarajan501fc0f2013-06-19 15:57:22 -070048 POWER_HINT_VIDEO_ENCODE = 0x00000003,
Ruchi Kandoi62f67552014-05-02 13:52:51 -070049 POWER_HINT_VIDEO_DECODE = 0x00000004,
Ruchi Kandoi94898652016-01-13 09:09:57 -080050 POWER_HINT_LOW_POWER = 0x00000005,
51 POWER_HINT_SUSTAINED_PERFORMANCE = 0x00000006
Todd Poynor2f143fb2012-04-24 13:39:15 -070052} power_hint_t;
53
Ruchi Kandoid0917132014-10-29 10:43:38 -070054typedef enum {
55 POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001
56} feature_t;
57
Todd Poynorc82792c2012-01-10 00:32:42 -080058/**
59 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM
60 * and the fields of this data structure must begin with hw_module_t
61 * followed by module specific information.
62 */
63typedef struct power_module {
64 struct hw_module_t common;
65
66 /*
67 * (*init)() performs power management setup actions at runtime
Todd Poynor2f143fb2012-04-24 13:39:15 -070068 * startup, such as to set default cpufreq parameters. This is
69 * called only by the Power HAL instance loaded by
70 * PowerManagerService.
Todd Poynorc82792c2012-01-10 00:32:42 -080071 */
72 void (*init)(struct power_module *module);
73
74 /*
75 * (*setInteractive)() performs power management actions upon the
76 * system entering interactive state (that is, the system is awake
77 * and ready for interaction, often with UI devices such as
78 * display and touchscreen enabled) or non-interactive state (the
79 * system appears asleep, display usually turned off). The
80 * non-interactive state is usually entered after a period of
81 * inactivity, in order to conserve battery power during
82 * such inactive periods.
83 *
84 * Typical actions are to turn on or off devices and adjust
85 * cpufreq parameters. This function may also call the
86 * appropriate interfaces to allow the kernel to suspend the
87 * system to low-power sleep state when entering non-interactive
88 * state, and to disallow low-power suspend when the system is in
89 * interactive state. When low-power suspend state is allowed, the
90 * kernel may suspend the system whenever no wakelocks are held.
91 *
92 * on is non-zero when the system is transitioning to an
93 * interactive / awake state, and zero when transitioning to a
94 * non-interactive / asleep state.
95 *
96 * This function is called to enter non-interactive state after
97 * turning off the screen (if present), and called to enter
98 * interactive state prior to turning on the screen.
99 */
100 void (*setInteractive)(struct power_module *module, int on);
Todd Poynor2f143fb2012-04-24 13:39:15 -0700101
102 /*
103 * (*powerHint) is called to pass hints on power requirements, which
104 * may result in adjustment of power/performance parameters of the
105 * cpufreq governor and other controls. The possible hints are:
106 *
107 * POWER_HINT_VSYNC
108 *
109 * Foreground app has started or stopped requesting a VSYNC pulse
110 * from SurfaceFlinger. If the app has started requesting VSYNC
111 * then CPU and GPU load is expected soon, and it may be appropriate
112 * to raise speeds of CPU, memory bus, etc. The data parameter is
113 * non-zero to indicate VSYNC pulse is now requested, or zero for
114 * VSYNC pulse no longer requested.
115 *
Todd Poynorbcdb4cd2012-05-03 14:49:02 -0700116 * POWER_HINT_INTERACTION
117 *
118 * User is interacting with the device, for example, touchscreen
119 * events are incoming. CPU and GPU load may be expected soon,
120 * and it may be appropriate to raise speeds of CPU, memory bus,
Michael Wright147d5402015-09-16 23:28:19 +0100121 * etc. The data parameter is the estimated length of the interaction
122 * in milliseconds, or 0 if unknown.
Todd Poynorbcdb4cd2012-05-03 14:49:02 -0700123 *
Ruchi Kandoi62f67552014-05-02 13:52:51 -0700124 * POWER_HINT_LOW_POWER
125 *
126 * Low power mode is activated or deactivated. Low power mode
127 * is intended to save battery at the cost of performance. The data
128 * parameter is non-zero when low power mode is activated, and zero
129 * when deactivated.
130 *
Ruchi Kandoi94898652016-01-13 09:09:57 -0800131 * POWER_HINT_SUSTAINED_PERFORMANCE
132 *
133 * Sustained Performance mode is actived or deactivated. Sustained
134 * performance mode is intended to provide a consistent level of
135 * performance for a prolonged amount of time. The data parameter is
136 * non-zero when sustained performance mode is activated, and zero
137 * when deactivated.
138 *
Todd Poynor2f143fb2012-04-24 13:39:15 -0700139 * A particular platform may choose to ignore any hint.
Mathias Agopian5cb1de82012-04-26 19:49:40 -0700140 *
141 * availability: version 0.2
142 *
Todd Poynor2f143fb2012-04-24 13:39:15 -0700143 */
144 void (*powerHint)(struct power_module *module, power_hint_t hint,
145 void *data);
Ruchi Kandoid0917132014-10-29 10:43:38 -0700146
147 /*
148 * (*setFeature) is called to turn on or off a particular feature
149 * depending on the state parameter. The possible features are:
150 *
151 * FEATURE_DOUBLE_TAP_TO_WAKE
152 *
153 * Enabling/Disabling this feature will allow/disallow the system
154 * to wake up by tapping the screen twice.
155 *
156 * availability: version 0.3
157 *
158 */
159 void (*setFeature)(struct power_module *module, feature_t feature, int state);
160
Todd Poynorc82792c2012-01-10 00:32:42 -0800161} power_module_t;
162
163
164__END_DECLS
165
166#endif // ANDROID_INCLUDE_HARDWARE_POWER_H