4 * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License);
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 * @brief Power Manager poll implementation
29 #include "device-interface.h"
31 #include "display-ops.h"
32 #include "display-plugin.h"
33 #include "display-state-transition.h"
34 #include "shared/plugin.h"
36 static PMMsg recv_data;
38 int check_dimstay(int next_state, int flag)
40 if (next_state != LCD_OFF)
43 if (!(flag & GOTO_STATE_NOW))
46 if (!(get_pm_status_flag() & DIMSTAY_FLAG))
52 static enum state_t get_state(int s_bits)
70 static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout)
74 cond = get_state(s_bits);
78 if (!display_state_transition_is_display_state_support_transition(cond))
81 cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK);
83 if (flag & GOTO_STATE_NOW)
84 /* if the flag is true, go to the locking state directly */
85 cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE);
87 if (flag & HOLD_KEY_BLOCK)
88 cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY);
91 recv_data.cond = cond;
92 recv_data.timeout = timeout;
94 poll_callback(PM_CONTROL_EVENT, &recv_data);
99 static int __pm_unlock_internal(pid_t pid, int s_bits, int flag)
103 cond = get_state(s_bits);
107 if (!display_state_transition_is_display_state_support_transition(cond))
110 cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK);
112 if (flag & PM_KEEP_TIMER)
113 cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER);
115 if (flag & PM_RESET_TIMER)
116 cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER);
119 recv_data.cond = cond;
120 recv_data.timeout = 0;
122 poll_callback(PM_CONTROL_EVENT, &recv_data);
127 static int __pm_change_internal(pid_t pid, int s_bits)
130 const int display_on = LCD_NORMAL | LCD_DIM;
132 cond = get_state(s_bits);
136 ret = is_lcdon_blocked();
137 if (ret != LCDON_BLOCK_NONE && (cond & display_on)) {
138 _W("LCDON is blocked, %d.", ret);
142 if (!display_state_transition_is_display_state_support_transition(cond))
145 cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE);
148 recv_data.cond = cond;
149 recv_data.timeout = 0;
151 poll_callback(PM_CONTROL_EVENT, &recv_data);
156 void init_pm_internal(void *data)
158 struct display_plugin *dp = (struct display_plugin *) data;
160 dp->pm_lock_internal = __pm_lock_internal;
161 dp->pm_unlock_internal = __pm_unlock_internal;
162 dp->pm_change_internal = __pm_change_internal;