4 * Copyright (c) 2014 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 #include "core/common.h"
23 #include "core/devices.h"
24 #include "core/device-notifier.h"
26 #include "display/core.h"
27 #include "display/device-interface.h"
28 #include "powersaver.h"
30 static int set_powersaver_mode(int mode)
33 int brightness, timeout;
35 _I("powersaver mode %d", mode);
36 device_notify(DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING, (void*)mode);
38 /* powersaver mode off */
39 if (mode == POWERSAVER_OFF ||
40 mode == POWERSAVER_BASIC ||
41 mode == POWERSAVER_ENHANCED) {
42 backlight_ops.set_force_brightness(0);
43 set_force_lcdtimeout(0);
47 /* powersaver mode on (brightness) */
48 ret = vconf_get_int(VCONFKEY_SETAPPL_EMERGENCY_LCD_BRIGHTNESS_INT,
51 _E("Failed to get powersaver brightness!");
54 ret = backlight_ops.set_force_brightness(brightness);
56 _E("Failed to set force brightness!");
59 _I("force brightness %d", brightness);
61 /* powersaver mode on (lcd timeout) */
62 ret = vconf_get_int(VCONFKEY_SETAPPL_EMERGENCY_LCD_TIMEOUT_INT,
65 _E("Failed to get powersaver lcd timeout!");
68 ret = set_force_lcdtimeout(timeout);
70 _E("Failed to set force timeout!");
73 _I("force timeout %d", timeout);
76 /* update internal state */
78 hbm_set_state_with_timeout(false, 0);
79 backlight_ops.update();
80 ret = get_run_timeout(&timeout);
82 states[S_NORMAL].timeout = timeout;
83 states[pm_cur_state].trans(EVENT_INPUT);
88 static void powersaver_status_changed(keynode_t *key_nodes, void *data)
90 int status, mode, ret;
92 if (key_nodes == NULL) {
93 _E("wrong parameter, key_nodes is null");
97 status = vconf_keynode_get_int(key_nodes);
98 if (status == SETTING_PSMODE_NORMAL)
99 mode = POWERSAVER_OFF;
100 else if (status == SETTING_PSMODE_WEARABLE)
101 mode = POWERSAVER_BASIC;
102 else if (status == SETTING_PSMODE_WEARABLE_ENHANCED)
103 mode = POWERSAVER_ENHANCED;
107 ret = set_powersaver_mode(mode);
109 _E("Failed to update powersaver state %d", ret);
112 static void powersaver_init(void *data)
115 int mode = POWERSAVER_OFF;
117 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
118 powersaver_status_changed, NULL);
120 _E("Failed to vconf_notify_key_changed!");
122 ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &status);
124 _E("Failed to vconf get bool!");
129 case SETTING_PSMODE_WEARABLE:
130 mode = POWERSAVER_BASIC;
132 case SETTING_PSMODE_WEARABLE_ENHANCED:
133 mode = POWERSAVER_ENHANCED;
139 _D("powersaver mode on! %d", mode);
140 ret = set_powersaver_mode(mode);
142 _E("Failed to update powersaver state %d", ret);
145 static void powersaver_exit(void *data)
149 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
150 powersaver_status_changed);
152 _E("Failed to vconf_ignore_key_changed!");
155 static const struct device_ops powersaver_device_ops = {
156 .priority = DEVICE_PRIORITY_NORMAL,
157 .name = "powersaver-micro",
158 .init = powersaver_init,
159 .exit = powersaver_exit,
162 DEVICE_OPS_REGISTER(&powersaver_device_ops)