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"
29 static int set_powersaver_mode(int on)
32 int brightness, timeout;
34 _I("powersaver mode %s", (on ? "on" : "off"));
35 device_notify(DEVICE_NOTIFIER_POWERSAVER, (void*)on);
37 /* powersaver mode off */
39 backlight_ops.set_force_brightness(0);
40 set_force_lcdtimeout(0);
44 /* powersaver mode on (brightness) */
45 ret = vconf_get_int(VCONFKEY_SETAPPL_EMERGENCY_LCD_BRIGHTNESS_INT,
48 _E("Failed to get powersaver brightness!");
51 ret = backlight_ops.set_force_brightness(brightness);
53 _E("Failed to set force brightness!");
56 _I("force brightness %d", brightness);
58 /* powersaver mode on (lcd timeout) */
59 ret = vconf_get_int(VCONFKEY_SETAPPL_EMERGENCY_LCD_TIMEOUT_INT,
62 _E("Failed to get powersaver lcd timeout!");
65 ret = set_force_lcdtimeout(timeout);
67 _E("Failed to set force timeout!");
70 _I("force timeout %d", timeout);
73 /* update internal state */
75 hbm_set_state_with_timeout(false, 0);
76 backlight_ops.update();
77 ret = get_run_timeout(&timeout);
79 states[S_NORMAL].timeout = timeout;
80 states[pm_cur_state].trans(EVENT_INPUT);
85 static void powersaver_status_changed(keynode_t *key_nodes, void *data)
89 if (key_nodes == NULL) {
90 _E("wrong parameter, key_nodes is null");
94 status = vconf_keynode_get_int(key_nodes);
95 if (status == SETTING_PSMODE_NORMAL)
97 else if (status == SETTING_PSMODE_WEARABLE)
102 ret = set_powersaver_mode(on);
104 _E("Failed to update powersaver state %d", ret);
107 static int booting_done(void *data)
111 ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &status);
113 _E("Failed to vconf get bool!");
117 if (status != SETTING_PSMODE_WEARABLE)
120 _D("powersaver mode on!");
121 ret = set_powersaver_mode(true);
123 _E("Failed to update powersaver state %d", ret);
128 static void powersaver_init(void *data)
132 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
133 powersaver_status_changed, NULL);
135 _E("Failed to vconf_notify_key_changed!");
137 register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
140 static void powersaver_exit(void *data)
144 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
145 powersaver_status_changed);
147 _E("Failed to vconf_ignore_key_changed!");
149 unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
152 static const struct device_ops powersaver_device_ops = {
153 .priority = DEVICE_PRIORITY_NORMAL,
154 .name = "powersaver",
155 .init = powersaver_init,
156 .exit = powersaver_exit,
159 DEVICE_OPS_REGISTER(&powersaver_device_ops)