power.h revision 501fc0f18249468d485415a3a7f892c644271e63
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 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) 30 31/** 32 * The id of this module 33 */ 34#define POWER_HARDWARE_MODULE_ID "power" 35 36/* 37 * Power hint identifiers passed to (*powerHint) 38 */ 39 40typedef enum { 41 POWER_HINT_VSYNC = 0x00000001, 42 POWER_HINT_INTERACTION = 0x00000002, 43 POWER_HINT_VIDEO_ENCODE = 0x00000003, 44 POWER_HINT_VIDEO_DECODE = 0x00000004 45} power_hint_t; 46 47/** 48 * Every hardware module must have a data structure named HAL_MODULE_INFO_SYM 49 * and the fields of this data structure must begin with hw_module_t 50 * followed by module specific information. 51 */ 52typedef struct power_module { 53 struct hw_module_t common; 54 55 /* 56 * (*init)() performs power management setup actions at runtime 57 * startup, such as to set default cpufreq parameters. This is 58 * called only by the Power HAL instance loaded by 59 * PowerManagerService. 60 */ 61 void (*init)(struct power_module *module); 62 63 /* 64 * (*setInteractive)() performs power management actions upon the 65 * system entering interactive state (that is, the system is awake 66 * and ready for interaction, often with UI devices such as 67 * display and touchscreen enabled) or non-interactive state (the 68 * system appears asleep, display usually turned off). The 69 * non-interactive state is usually entered after a period of 70 * inactivity, in order to conserve battery power during 71 * such inactive periods. 72 * 73 * Typical actions are to turn on or off devices and adjust 74 * cpufreq parameters. This function may also call the 75 * appropriate interfaces to allow the kernel to suspend the 76 * system to low-power sleep state when entering non-interactive 77 * state, and to disallow low-power suspend when the system is in 78 * interactive state. When low-power suspend state is allowed, the 79 * kernel may suspend the system whenever no wakelocks are held. 80 * 81 * on is non-zero when the system is transitioning to an 82 * interactive / awake state, and zero when transitioning to a 83 * non-interactive / asleep state. 84 * 85 * This function is called to enter non-interactive state after 86 * turning off the screen (if present), and called to enter 87 * interactive state prior to turning on the screen. 88 */ 89 void (*setInteractive)(struct power_module *module, int on); 90 91 /* 92 * (*powerHint) is called to pass hints on power requirements, which 93 * may result in adjustment of power/performance parameters of the 94 * cpufreq governor and other controls. The possible hints are: 95 * 96 * POWER_HINT_VSYNC 97 * 98 * Foreground app has started or stopped requesting a VSYNC pulse 99 * from SurfaceFlinger. If the app has started requesting VSYNC 100 * then CPU and GPU load is expected soon, and it may be appropriate 101 * to raise speeds of CPU, memory bus, etc. The data parameter is 102 * non-zero to indicate VSYNC pulse is now requested, or zero for 103 * VSYNC pulse no longer requested. 104 * 105 * POWER_HINT_INTERACTION 106 * 107 * User is interacting with the device, for example, touchscreen 108 * events are incoming. CPU and GPU load may be expected soon, 109 * and it may be appropriate to raise speeds of CPU, memory bus, 110 * etc. The data parameter is unused. 111 * 112 * A particular platform may choose to ignore any hint. 113 * 114 * availability: version 0.2 115 * 116 */ 117 void (*powerHint)(struct power_module *module, power_hint_t hint, 118 void *data); 119} power_module_t; 120 121 122__END_DECLS 123 124#endif // ANDROID_INCLUDE_HARDWARE_POWER_H 125