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 main loop.
24 * This file includes Main loop, the FSM, signal processing.
35 #include <sys/types.h>
40 #include <vconf-keys.h>
42 #include <libsyscommon/list.h>
43 #include <libsyscommon/resource-manager.h>
44 #include <system/syscommon-plugin-deviced-common-interface.h>
45 #include <system/syscommon-plugin-deviced-display-interface.h>
46 #include <device/display-internal.h>
47 #include <hal/device/hal-device-power.h>
49 #include <libsyscommon/log.h>
50 #include "device-interface.h"
53 * @addtogroup POWER_MANAGER
57 static enum device_ops_status status = DEVICE_OPS_STATUS_UNINIT;
59 static struct state states[DEVICED_DISPLAY_STATE_END] = {
60 { DEVICED_DISPLAY_STATE_START, "DEVICED_DISPLAY_STATE_START", NULL, NULL, NULL, NULL },
61 { DEVICED_DISPLAY_STATE_ON, "DEVICED_DISPLAY_STATE_ON", NULL, NULL, NULL, NULL },
62 { DEVICED_DISPLAY_STATE_DIM, "DEVICED_DISPLAY_STATE_DIM", NULL, NULL, NULL, NULL },
63 { DEVICED_DISPLAY_STATE_OFF, "DEVICED_DISPLAY_STATE_OFF", NULL, NULL, NULL, NULL },
64 { DEVICED_DISPLAY_STATE_SLEEP, "DEVICED_DISPLAY_STATE_SLEEP", NULL, NULL, NULL, NULL },
67 #define LOCK_SCREEN_WATING_TIME 300 /* 0.3 second */
68 #define LONG_PRESS_INTERVAL 2 /* 2 seconds */
69 #define SAMPLING_INTERVAL 1 /* 1 sec */
70 #define BRIGHTNESS_CHANGE_STEP 10
71 #define LCD_ALWAYS_ON 0
72 #define ACCEL_SENSOR_ON 1
73 #define CONTINUOUS_SAMPLING 1
74 #define LCDOFF_TIMEOUT 300 /* milli second */
76 static struct display_config display_conf = {
77 .lock_wait_time = LOCK_SCREEN_WATING_TIME,
78 .longpress_interval = LONG_PRESS_INTERVAL,
79 .lightsensor_interval = SAMPLING_INTERVAL,
80 .lcdoff_timeout = LCDOFF_TIMEOUT,
81 .pm_default_brightness = 80,
82 .brightness_change_step = BRIGHTNESS_CHANGE_STEP,
83 .lcd_always_on = LCD_ALWAYS_ON,
85 .framerate_app = {0, 0, 0, 0},
87 .powerkey_doublepress = 0,
88 .accel_sensor_on = ACCEL_SENSOR_ON,
89 .continuous_sampling = CONTINUOUS_SAMPLING,
90 .timeout_enable = true,
91 .input_support = true,
92 .display_init_direction = DISPLAY_INIT_DIRECTION_HORIZONTAL,
93 .aod_enter_level = 40,
95 .touch_wakeup = false,
96 .display_on_usb_conn_changed = true,
97 .display_dpms_type = DISPLAY_DPMS_TYPE_WINDOW_MANAGER,
100 inline const struct display_config* get_var_display_config()
102 return &display_conf;
105 inline struct state* state_st(enum deviced_display_state state)
107 return &states[state];
110 static void init_display_states(void *data)
112 struct display_plugin *dp = (struct display_plugin *) data;
113 for(int i = 0; i < DEVICED_DISPLAY_STATE_END; i++)
114 dp->display_states[i] = &states[i];
120 static int display_probe(void *data)
122 struct display_plugin *dp = (struct display_plugin *) data;
125 dp->config = &display_conf;
126 init_display_states(dp);
127 setup_display_plugin_backlight_ops(dp);
128 dp->set_dim_state = NULL;
129 dp->get_device_flags = NULL;
130 dp->lcd_on_procedure = NULL;
131 dp->lcd_off_procedure = NULL;
132 dp->custom_lcd_on = NULL;
133 dp->custom_lcd_off = NULL;
134 dp->display_on_by_reason = NULL;
135 dp->display_off_by_reason = NULL;
136 dp->default_saving_mode = NULL;
137 dp->is_lcdon_blocked = is_lcdon_blocked;
138 dp->proc_change_state = NULL;
140 /* check display feature */
141 if (!is_feature_display_supported())
147 static void display_init(void *data)
151 /* load configutation */
152 ret = display_load_config(&display_conf);
154 _W("Failed to load '%s', use default value: %d",
155 DISPLAY_CONF_FILE, ret);
158 static void display_exit(void *data)
163 static int display_start(enum device_flags flags)
166 if (flags & NORMAL_MODE) {
167 if (flags & LCD_PANEL_OFF_MODE)
169 syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
170 DEVICED_DISPLAY_ATTR_INT_DPMS_STATE, DEVICED_DPMS_STANDBY);
173 syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
174 DEVICED_DISPLAY_ATTR_INT_DPMS_STATE, DEVICED_DPMS_ON);
179 /* CORE LOGIC MODE */
180 if (!(flags & CORE_LOGIC_MODE))
183 display_get_display_ops_status(&status);
184 if (status == DEVICE_OPS_STATUS_START)
187 if (display_probe(NULL) < 0)
195 static int display_stop(enum device_flags flags)
198 if (flags & NORMAL_MODE) {
199 syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
200 DEVICED_DISPLAY_ATTR_INT_DPMS_STATE, DEVICED_DPMS_OFF);
202 } else if (flags & FORCE_OFF_MODE) {
203 syscommon_resman_set_resource_attr_int(SYSCOMMON_RESOURCE_ID(DEVICED_RESOURCE_TYPE_DISPLAY),
204 DEVICED_DISPLAY_ATTR_INT_DPMS_STATE, DEVICED_DPMS_FORCE_OFF);
208 /* CORE LOGIC MODE */
209 if (!(flags & CORE_LOGIC_MODE))
212 display_get_display_ops_status(&status);
213 if (status == DEVICE_OPS_STATUS_STOP)
221 static int display_status(void)
226 static const struct device_ops display_plugin_device_ops = {
227 .disable_auto_init = true,
228 DECLARE_NAME_LEN("display-plugin"),
229 .probe = display_probe,
230 .init = display_init,
231 .exit = display_exit,
232 .start = display_start,
233 .stop = display_stop,
234 .status = display_status,
237 DEVICE_OPS_REGISTER(&display_plugin_device_ops)