Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 1 | /* |
| 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 Agopian | 5cb1de8 | 2012-04-26 19:49:40 -0700 | [diff] [blame] | 28 | #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 Kandoi | d091713 | 2014-10-29 10:43:38 -0700 | [diff] [blame] | 30 | #define POWER_MODULE_API_VERSION_0_3 HARDWARE_MODULE_API_VERSION(0, 3) |
Ruchi Kandoi | 9489865 | 2016-01-13 09:09:57 -0800 | [diff] [blame] | 31 | #define POWER_MODULE_API_VERSION_0_4 HARDWARE_MODULE_API_VERSION(0, 4) |
Mathias Agopian | 5cb1de8 | 2012-04-26 19:49:40 -0700 | [diff] [blame] | 32 | |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 33 | /** |
| 34 | * The id of this module |
| 35 | */ |
| 36 | #define POWER_HARDWARE_MODULE_ID "power" |
| 37 | |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 38 | /* |
| 39 | * Power hint identifiers passed to (*powerHint) |
| 40 | */ |
| 41 | |
| 42 | typedef enum { |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 43 | POWER_HINT_VSYNC = 0x00000001, |
Todd Poynor | bcdb4cd | 2012-05-03 14:49:02 -0700 | [diff] [blame] | 44 | POWER_HINT_INTERACTION = 0x00000002, |
Iliyan Malchev | 1a70c0f | 2013-06-25 18:50:49 -0700 | [diff] [blame] | 45 | /* DO NOT USE POWER_HINT_VIDEO_ENCODE/_DECODE! They will be removed in |
| 46 | * KLP. |
| 47 | */ |
Mekala Natarajan | 501fc0f | 2013-06-19 15:57:22 -0700 | [diff] [blame] | 48 | POWER_HINT_VIDEO_ENCODE = 0x00000003, |
Ruchi Kandoi | 62f6755 | 2014-05-02 13:52:51 -0700 | [diff] [blame] | 49 | POWER_HINT_VIDEO_DECODE = 0x00000004, |
Ruchi Kandoi | 9489865 | 2016-01-13 09:09:57 -0800 | [diff] [blame] | 50 | POWER_HINT_LOW_POWER = 0x00000005, |
Ruchi Kandoi | 403bc14 | 2016-03-09 15:16:30 -0800 | [diff] [blame^] | 51 | POWER_HINT_SUSTAINED_PERFORMANCE = 0x00000006, |
| 52 | POWER_HINT_VR_MODE = 0x00000007 |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 53 | } power_hint_t; |
| 54 | |
Ruchi Kandoi | d091713 | 2014-10-29 10:43:38 -0700 | [diff] [blame] | 55 | typedef enum { |
| 56 | POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 0x00000001 |
| 57 | } feature_t; |
| 58 | |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 59 | /** |
| 60 | * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM |
| 61 | * and the fields of this data structure must begin with hw_module_t |
| 62 | * followed by module specific information. |
| 63 | */ |
| 64 | typedef struct power_module { |
| 65 | struct hw_module_t common; |
| 66 | |
| 67 | /* |
| 68 | * (*init)() performs power management setup actions at runtime |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 69 | * startup, such as to set default cpufreq parameters. This is |
| 70 | * called only by the Power HAL instance loaded by |
| 71 | * PowerManagerService. |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 72 | */ |
| 73 | void (*init)(struct power_module *module); |
| 74 | |
| 75 | /* |
| 76 | * (*setInteractive)() performs power management actions upon the |
| 77 | * system entering interactive state (that is, the system is awake |
| 78 | * and ready for interaction, often with UI devices such as |
| 79 | * display and touchscreen enabled) or non-interactive state (the |
| 80 | * system appears asleep, display usually turned off). The |
| 81 | * non-interactive state is usually entered after a period of |
| 82 | * inactivity, in order to conserve battery power during |
| 83 | * such inactive periods. |
| 84 | * |
| 85 | * Typical actions are to turn on or off devices and adjust |
| 86 | * cpufreq parameters. This function may also call the |
| 87 | * appropriate interfaces to allow the kernel to suspend the |
| 88 | * system to low-power sleep state when entering non-interactive |
| 89 | * state, and to disallow low-power suspend when the system is in |
| 90 | * interactive state. When low-power suspend state is allowed, the |
| 91 | * kernel may suspend the system whenever no wakelocks are held. |
| 92 | * |
| 93 | * on is non-zero when the system is transitioning to an |
| 94 | * interactive / awake state, and zero when transitioning to a |
| 95 | * non-interactive / asleep state. |
| 96 | * |
| 97 | * This function is called to enter non-interactive state after |
| 98 | * turning off the screen (if present), and called to enter |
| 99 | * interactive state prior to turning on the screen. |
| 100 | */ |
| 101 | void (*setInteractive)(struct power_module *module, int on); |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * (*powerHint) is called to pass hints on power requirements, which |
| 105 | * may result in adjustment of power/performance parameters of the |
| 106 | * cpufreq governor and other controls. The possible hints are: |
| 107 | * |
| 108 | * POWER_HINT_VSYNC |
| 109 | * |
| 110 | * Foreground app has started or stopped requesting a VSYNC pulse |
| 111 | * from SurfaceFlinger. If the app has started requesting VSYNC |
| 112 | * then CPU and GPU load is expected soon, and it may be appropriate |
| 113 | * to raise speeds of CPU, memory bus, etc. The data parameter is |
| 114 | * non-zero to indicate VSYNC pulse is now requested, or zero for |
| 115 | * VSYNC pulse no longer requested. |
| 116 | * |
Todd Poynor | bcdb4cd | 2012-05-03 14:49:02 -0700 | [diff] [blame] | 117 | * POWER_HINT_INTERACTION |
| 118 | * |
| 119 | * User is interacting with the device, for example, touchscreen |
| 120 | * events are incoming. CPU and GPU load may be expected soon, |
| 121 | * and it may be appropriate to raise speeds of CPU, memory bus, |
Michael Wright | 147d540 | 2015-09-16 23:28:19 +0100 | [diff] [blame] | 122 | * etc. The data parameter is the estimated length of the interaction |
| 123 | * in milliseconds, or 0 if unknown. |
Todd Poynor | bcdb4cd | 2012-05-03 14:49:02 -0700 | [diff] [blame] | 124 | * |
Ruchi Kandoi | 62f6755 | 2014-05-02 13:52:51 -0700 | [diff] [blame] | 125 | * POWER_HINT_LOW_POWER |
| 126 | * |
| 127 | * Low power mode is activated or deactivated. Low power mode |
| 128 | * is intended to save battery at the cost of performance. The data |
| 129 | * parameter is non-zero when low power mode is activated, and zero |
| 130 | * when deactivated. |
| 131 | * |
Ruchi Kandoi | 9489865 | 2016-01-13 09:09:57 -0800 | [diff] [blame] | 132 | * POWER_HINT_SUSTAINED_PERFORMANCE |
| 133 | * |
| 134 | * Sustained Performance mode is actived or deactivated. Sustained |
| 135 | * performance mode is intended to provide a consistent level of |
| 136 | * performance for a prolonged amount of time. The data parameter is |
| 137 | * non-zero when sustained performance mode is activated, and zero |
| 138 | * when deactivated. |
| 139 | * |
Ruchi Kandoi | 403bc14 | 2016-03-09 15:16:30 -0800 | [diff] [blame^] | 140 | * POWER_HINT_VR_MODE |
| 141 | * |
| 142 | * VR Mode is activated or deactivated. VR mode is intended to |
| 143 | * provide minimum guarantee for performance for the amount of time the |
| 144 | * device can sustain it. The data parameter is non-zero when the mode |
| 145 | * is activated and zero when deactivated. |
| 146 | * |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 147 | * A particular platform may choose to ignore any hint. |
Mathias Agopian | 5cb1de8 | 2012-04-26 19:49:40 -0700 | [diff] [blame] | 148 | * |
| 149 | * availability: version 0.2 |
| 150 | * |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 151 | */ |
| 152 | void (*powerHint)(struct power_module *module, power_hint_t hint, |
| 153 | void *data); |
Ruchi Kandoi | d091713 | 2014-10-29 10:43:38 -0700 | [diff] [blame] | 154 | |
| 155 | /* |
| 156 | * (*setFeature) is called to turn on or off a particular feature |
| 157 | * depending on the state parameter. The possible features are: |
| 158 | * |
| 159 | * FEATURE_DOUBLE_TAP_TO_WAKE |
| 160 | * |
| 161 | * Enabling/Disabling this feature will allow/disallow the system |
| 162 | * to wake up by tapping the screen twice. |
| 163 | * |
| 164 | * availability: version 0.3 |
| 165 | * |
| 166 | */ |
| 167 | void (*setFeature)(struct power_module *module, feature_t feature, int state); |
| 168 | |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 169 | } power_module_t; |
| 170 | |
| 171 | |
| 172 | __END_DECLS |
| 173 | |
| 174 | #endif // ANDROID_INCLUDE_HARDWARE_POWER_H |