2 * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __TIZEN_SYSTEM_POWER_INTERNAL_H__
18 #define __TIZEN_SYSTEM_POWER_INTERNAL_H__
28 #include "device-error.h"
32 * @brief Power off the device.
33 * @details It operates synchronously.
36 * @privilege %http://tizen.org/privilege/reboot
37 * @return @c 0 on success,
38 * otherwise a negative error value
39 * @retval #DEVICE_ERROR_NONE Successful
40 * @retval #DEVICE_ERROR_INVALID_PARAMETER Invalid parameter
41 * @retval #DEVICE_ERROR_PERMISSION_DENIED Permission denied
42 * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
44 int device_power_poweroff(void);
47 POWER_STATE_MIN_INDEX = 4,
48 POWER_STATE_START_INDEX = POWER_STATE_MIN_INDEX,
49 POWER_STATE_NORMAL_INDEX,
50 POWER_STATE_SLEEP_INDEX,
51 POWER_STATE_POWEROFF_INDEX,
52 POWER_STATE_REBOOT_INDEX,
53 POWER_STATE_EXIT_INDEX,
54 POWER_STATE_MAX_INDEX,
57 #define POWER_STATE_START (1ULL << POWER_STATE_START_INDEX)
58 #define POWER_STATE_NORMAL (1ULL << POWER_STATE_NORMAL_INDEX)
59 #define POWER_STATE_SLEEP (1ULL << POWER_STATE_SLEEP_INDEX)
60 #define POWER_STATE_POWEROFF (1ULL << POWER_STATE_POWEROFF_INDEX)
61 #define POWER_STATE_REBOOT (1ULL << POWER_STATE_REBOOT_INDEX)
62 #define POWER_STATE_EXIT (1ULL << POWER_STATE_EXIT_INDEX)
63 #define POWER_STATE_ALL ((1ULL << POWER_STATE_MAX_INDEX) - (1ULL << POWER_STATE_MIN_INDEX))
65 #define SIGNAME_CHANGE_STATE_TO_START "ChangeStateToStart"
66 #define SIGNAME_CHANGE_STATE_TO_NORMAL "ChangeStateToNormal"
67 #define SIGNAME_CHANGE_STATE_TO_SLEEP "ChangeStateToSleep"
68 #define SIGNAME_CHANGE_STATE_TO_POWEROFF "ChangeStateToPowerOff"
69 #define SIGNAME_CHANGE_STATE_TO_REBOOT "ChangeStateToReboot"
70 #define SIGNAME_CHANGE_STATE_TO_EXIT "ChangeStateToExit"
72 struct device_change_state_info {
73 uint64_t prev_state; /* previous state before the state transition, one of POWER_STATE_* */
74 uint64_t next_state; /* current state that has been transitioned, one of POWER_STATE_* */
75 uint64_t id; /* unique id for each transition. it is used for wait-done */
76 int reason; /* integer that signifies what event has triggered the transition */
80 * @brief Called when a device power state is changed
81 * @details If both change_state_wait_callback and change_state_callback have registered to the same power state, \n
82 * then the change_state_wait_callback will be invoked first and the change_state_callback will follow.
83 * @param[out] info Information about state change
84 * @param[out] user_data User data passed from the callback registration
86 typedef void (*change_state_wait_callback) (const struct device_change_state_info *info, void *user_data);
89 * @brief Add a callback to observe power state change
90 * @details Register a callback for specific power state. \n
91 * The callback will be invoked when the deviced changes state to the designated power state. \n
92 * An actual action, such as triggering poweroff on changing state to POWER_STATE_POWEROFF or \n
93 * wake unlock on changing state to POWER_STATE_SLEEP, will be deferred to give a chance \n
94 * for the API caller to prepare for the action.
96 * @param[in] state_bits Bitwise ORed power state
97 * @param[in] cb Callback function
98 * @param[in] user_data Data to be passed to the callback function
99 * @return 0 on success,
100 * otherwise a negative error value
101 * @retval #DEVICE_ERROR_NONE Successful
102 * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
104 int device_power_add_change_state_wait_callback(uint64_t state_bits, change_state_wait_callback cb, void *user_data);
107 * @brief Notify the deviced that it is ready for the actual action.
108 * @details Notify the deviced that it is ok to take an actual action of change state. \n
109 * This API only works on the id received from change_state_wait_callback.
111 * @param[in] id Id of a state change
112 * @return 0 on success,
113 * otherwise a negative error value
114 * @retval #DEVICE_ERROR_NONE Successful
115 * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
117 int device_power_change_state_wait_done(uint64_t id);
120 * @brief Remove callback that has registered to power state.
122 * @param[in] state_bits Bitwise ORed power state
124 void device_power_remove_change_state_wait_callback(uint64_t state_bits);
127 * @brief Async callback of device_power_change_state().
128 * @details If both change_state_wait_callback and change_state_callback have registered to the same power state, \n
129 * then the change_state_wait_callback will be invoked first and the change_state_callback will follow.
131 * @param[out] state State to be changed
132 * @param[out] retval Return of change state
133 * @param[out] user_data The user data passed from the change state function
135 typedef void (*change_state_callback) (uint64_t state, int retval, void *user_data);
138 * @brief Send request for changing power state asynchronously.
140 * @param[in] state Target state
141 * @param[in] timeout_sec Timeout for the async reply in second, maximum of 10 seconds
142 * @param[in] cb Async callback of the request
143 * @param[in] user_data Data to be passed to the callback function
144 * @return 0 on success,
145 * otherwise a negative error value
146 * @retval #DEVICE_ERROR_NONE Successful
147 * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
149 int device_power_change_state(uint64_t state, int timeout_sec, change_state_callback cb, void *user_data);
152 * @brief Check if reboot is possible on the current device state
154 * @return 1 if a device is able to reboot,
157 int device_power_check_reboot_allowed(void);
160 * @brief Get internal power state of the deviced
162 * @param[out] state Internal power state of the deviced
163 * @return 0 on success,
164 * otherwise a negative error value
165 * @retval #DEVICE_ERROR_NONE Successful
166 * @retval #DEVICE_ERROR_OPERATION_FAILED Operation failed
168 int device_power_get_state(uint64_t *state);