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 * Callback function that delivers information about a state transition.
82 typedef void (*change_state_wait_callback) (const struct device_change_state_info *info, void *user_data);
85 * Add callback for states to be transitioned. The action caused by the transition,
86 * e.g., wake unlock for sleep or shutdown for reboot, would be defered until calling
87 * device_power_change_state_wait_done().
89 * uint64_t state_bits: bitwise-ORing of interesting state.
90 * change_state_wait_callback cb: For every state transition to the state_bit, the cb will be invoked.
91 * void *user_data: user data for the callback.
93 int device_power_add_change_state_wait_callback(uint64_t state_bits, change_state_wait_callback cb, void *user_data);
96 * Notify the deviced that it is ready to transition state.
98 * uint64_t id: id of device_change_state_info that has received through callback.
100 int device_power_change_state_wait_done(uint64_t id);
103 * Remove callback of state transition.
105 void device_power_remove_change_state_wait_callback(uint64_t state_bits);
108 * Async callback of device_power_change_state()
110 * uint64_t state: which state it has transitioned.
111 * int retval: result of the method call.
112 * void *user_data: user data for the callback.
114 typedef void (*change_state_callback) (uint64_t state, int retval, void *user_data);
117 * Send a request to the deviced for changing power state. It doesn't ensure the whole execution
118 * of a callback subroutine - think of a request for sleep/poweroff/reboot state. To ensure
119 * the whole execution of a callback, use device_power_add_change_state_wait_callback() additionally.
120 * If both change_state_wait_callback and change_state_callback has registered to a state,
121 * it is unpredictable which callback will be invoked first.
123 * uint64_t state: which state to transition to
124 * int timeout_sec: maximum timeout of async method call. if it expires, then the second parameter of
125 * a callback function, int retval, gives -ETIMEDOUT error. If it is 0 or negative, it is set to
126 * the default, 10 seconds.
127 * change_state_callback cb: async callback function, nullable
128 * void *user_data: user data for the callback.
130 int device_power_change_state(uint64_t state, int timeout_sec, change_state_callback cb, void *user_data);
133 * Return 0 if cloning partition is in progress.
135 int device_power_check_reboot_allowed(void);
137 int device_power_get_state(uint64_t *state);