4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: DongGi Jang <dg0402.jang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #ifndef __POWER_MANAGER_LIBRARY_H__
24 #define __POWER_MANAGER_LIBRARY_H__
27 * @defgroup POWER_MANAGER Power manager library
28 * @ingroup SYSTEM_FRAMEWORK
29 * @brief Power manager control API library
32 * @addtogroup POWER_MANAGER
34 * This library provides APIs to lock/unlock the power state of the system.
35 * Power Manager controls the power state as following.
36 * @image html power-manager-fsm.bmp "Fig. 1 State Diagram of Power Manager
37 * <br> If there is no user input for a certain time, PM changes the power state
38 * that has lower power consumption. <br> When the user input or other system interrupt occurs,
39 * PM rolls the state back immediately.<br> If applications or other frameworks want to stop
40 * enter the specific state of power manager, use pm_lock_state() and pm_unlock_state()
41 * <br> Be careful! A caller process should unlock the power state after locking without timeout.
42 * <br> If you want to stay the LCD normal state, you can use
43 * @li @c pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, 0)
44 * <p><br> After finishing your job with locking, call
45 * @li @c pm_unlock_state(LCD_NORMAL, PM_RESET_TIMER)
46 * <p><br> Additionally, you can use the timeout for lock the state.
47 * If timeout is set, caller process doesn't need to call the unlock API.
48 * But the process should be alive.
49 * If caller process is dead, lock condition would be drop by the power manager.
50 * <p><br> Here is sample codes
54 int main(int argc, char** argv)
58 printf("=========================================\n");
59 printf("= Lock / Unlock to transit a power manager state =\n");
60 printf("=========================================\n");
62 result = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW,0); //Lock on lcd-off until explicit unlock.
70 result = pm_unlock_state(LCD_NORMAL,PM_RESET_TIMER); //Unlock
76 result = pm_lock_state(LCD_OFF,STAY_CUR_STATE, 5000); // Lock on lcd-off during 5 seconds.
95 #define LCD_NORMAL 0x1 /**< NORMAL state */
96 #define LCD_DIM 0x2 /**< LCD dimming state */
97 #define LCD_OFF 0x4 /**< LCD off state */
98 #define SUSPEND 0x8 /**< Sleep state */
99 #define POWER_OFF 0x16 /**< Sleep state */
100 #define SETALL (LCD_DIM | LCD_OFF | LCD_NORMAL) /*< select all state - not supported yet */
102 /* parameters for pm_lock_state() */
103 #define GOTO_STATE_NOW 0x1
104 #define STAY_CUR_STATE 0x0
106 /* paramters for pm_unlcok_state() - details are described at 162 line */
107 #define PM_SLEEP_MARGIN 0x0 /**< keep guard time for unlock */
108 #define PM_RESET_TIMER 0x1 /**< reset timer for unlock */
109 #define PM_KEEP_TIMER 0x2 /**< keep timer for unlock */
112 * @fn int pm_lock_state (unsigned int state,
114 * unsigned int timeout);
115 * @brief This API is used to lock a particular power-state as the current power-state.\n
116 * The parameter state specifies the power state which you want to lock LCD_NORMAL, LCD_DIM, LCD_OFF. \n
117 * The second parameter Flag is set if you want to go the requested lock state directly.\n
118 * The third parameter timeout specifies lock-timeout in milliseconds.
119 * If the value 0 is selected, the power state remains locked until pm_unlock_state is called.
120 * @param[in] state target power state which you want to lock - LCD_NORMAL, LCD_DIM, LCD_OFF
121 * @param[in] flag set if you want to go the lock state directly - GOTO_STATE_NOW, STAY_CUR_STATE
122 * @param[in] timeout lock-timeout in miliseconds.
123 * 0 is always lock until calling pm_unlock_state
124 * If you call this function with same state in duplicate,
125 * only last one will be processed and others are ignored.
126 * @return 0 on success, -1 if failed
127 * @see pm_unlock_state(), pm_change_state()
131 * // Lock current state as LCD_NORMAL
132 * result = pm_lock_state(LCD_NORMAL, GOTO_STATE_NOW, SET_TIMEOUT);
134 * printf("[ERROR] return value result =%d, \n",result);
136 * printf("[SUCCESS]return value result =%d \n",result);
140 int pm_lock_state(unsigned int, unsigned int, unsigned int);
143 * @fn int pm_unlock_state (unsigned int state,
145 * @brief This API is used to Unlock the power state. \n
146 * The parameter state specifies the power state which you want to unlock .
147 * Some examples are LCD_NORMAL, LCD_DIM, LCD_OFF.\n
148 * The second parameter flag is set if you want to go to the requested state directly after unlocking. (NOT SUPPOERTED YET)
149 * This is valid only when the current state transition was blocked by the locking and this function call releases the blocking.
150 * @param[in] state target power state which you want to unlock
151 * @param[in] flag set timer which is going to the next state after unlocking
152 * PM_SLEEP_MARGIN - If the current status is lcd off, pm reset timer to 5 second. If the current status is not lcd off, pm pm uses the existing timer.
153 * PM_RESET_TIMER - Power-manager resets timer. (lcd normal : reset timer to predfined value which is set in setting module, lcd dim or off : reset timer to 5 seconds)
154 * PM_KEEP_TIMER - Power-manager uses the existing timer (if timer is already expired, pm changes the status) <br>
155 * @return 0 on success, -1 if failed
156 * @see pn_lock_state(), pm_change_state()
160 * //Un-lock NORMAL state so that power state change can occur with system-events
161 * result = pm_unlock_state(LCD_NORMAL,PM_RESET_TIMER);
163 * printf("[ERROR] return value result =%d, \n",result);
165 * printf("[SUCCESS]return value result =%d \n",result);
169 int pm_unlock_state(unsigned int, unsigned int);
172 * @fn int pm_change_state(unsigned int state);
173 * @brief This API is used to change the power manager state by force.
174 * @param[in] state power manager state - LCD_NORMAL, LCD_DIM, LCD_OFF
175 * @return 0 on success, -1 if failed.
176 * @see pm_lock_state(), pm_unlock_state()
180 * result = pm_change_state(LCD_OFF);
182 * printf("[ERROR] return value result =%d, \n",result);
184 * printf("[SUCCESS]return value result =%d \n",result);
188 int pm_change_state(unsigned int);
197 #endif /* __POWER_MANAGER_LIBRARY_H__ */