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 "shared/plugin.h"
35 static PMMsg recv_data;
37 int check_dimstay(int next_state, int flag)
39 if (next_state != LCD_OFF)
42 if (!(flag & GOTO_STATE_NOW))
45 if (!(get_pm_status_flag() & DIMSTAY_FLAG))
51 static enum state_t get_state(int s_bits)
69 static int __pm_lock_internal(pid_t pid, int s_bits, int flag, int timeout)
73 cond = get_state(s_bits);
77 if (!display_plugin_state_is_there_default_trans(cond))
80 cond = SET_COND_REQUEST(cond, PM_REQUEST_LOCK);
82 if (flag & GOTO_STATE_NOW)
83 /* if the flag is true, go to the locking state directly */
84 cond = SET_COND_FLAG(cond, PM_REQUEST_CHANGE);
86 if (flag & HOLD_KEY_BLOCK)
87 cond = SET_COND_FLAG(cond, PM_FLAG_BLOCK_HOLDKEY);
90 recv_data.cond = cond;
91 recv_data.timeout = timeout;
93 poll_callback(PM_CONTROL_EVENT, &recv_data);
98 static int __pm_unlock_internal(pid_t pid, int s_bits, int flag)
102 cond = get_state(s_bits);
106 if (!display_plugin_state_is_there_default_trans(cond))
109 cond = SET_COND_REQUEST(cond, PM_REQUEST_UNLOCK);
111 if (flag & PM_KEEP_TIMER)
112 cond = SET_COND_FLAG(cond, PM_FLAG_KEEP_TIMER);
114 if (flag & PM_RESET_TIMER)
115 cond = SET_COND_FLAG(cond, PM_FLAG_RESET_TIMER);
118 recv_data.cond = cond;
119 recv_data.timeout = 0;
121 poll_callback(PM_CONTROL_EVENT, &recv_data);
126 static int __pm_change_internal(pid_t pid, int s_bits)
129 const int display_on = LCD_NORMAL | LCD_DIM;
131 cond = get_state(s_bits);
135 ret = is_lcdon_blocked();
136 if (ret != LCDON_BLOCK_NONE && (cond & display_on)) {
137 _W("LCDON is blocked, %d.", ret);
141 if (!display_plugin_state_is_there_default_trans(cond))
144 cond = SET_COND_REQUEST(cond, PM_REQUEST_CHANGE);
147 recv_data.cond = cond;
148 recv_data.timeout = 0;
150 poll_callback(PM_CONTROL_EVENT, &recv_data);
155 void init_pm_internal(void *data)
157 struct display_plugin *dp = (struct display_plugin *) data;
159 dp->pm_lock_internal = __pm_lock_internal;
160 dp->pm_unlock_internal = __pm_unlock_internal;
161 dp->pm_change_internal = __pm_change_internal;