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 "shared/common.h"
23 #include "shared/devices.h"
24 #include "shared/device-notifier.h"
26 #include "display/core.h"
27 #include "display/device-interface.h"
28 #include "display/display-backlight.h"
29 #include "display/display-ops.h"
30 #include "display-info.h"
31 #include "powersaver.h"
34 static struct _backlight_ops *backlight_ops;
36 static int set_powersaver_mode(int mode)
39 const struct display_ops *hbm_ops = NULL;
40 struct hbmsetstate hss;
43 if (mode == POWERSAVER_ENHANCED)
45 _D("Powersaver mode %d pmqos %d.", mode, pmqos);
46 device_notify(DEVICE_NOTIFIER_ULTRAPOWERSAVING, (void *)&pmqos);
48 display_backlight_set_force_brightness(0);
49 set_force_lcdtimeout(0);
51 FIND_DISPLAY(hbm_ops, "hbm");
52 if (hbm_ops && hbm_ops->func(HBM_GET_STATE, 0)) {
55 hbm_ops->func(HBM_SET_TIMEOUT_STATE, &hss);
58 display_backlight_update_by_default_brightness();
59 get_run_timeout(&timeout);
60 state_st(S_NORMAL)->timeout = timeout;
61 state_st(get_pm_cur_state())->trans(EVENT_INPUT);
66 static void powersaver_status_changed(keynode_t *key_nodes, void *data)
68 int status, mode, ret;
70 if (key_nodes == NULL) {
71 _E("Wrong parameter, key_nodes is null.");
75 status = vconf_keynode_get_int(key_nodes);
76 if (status == SETTING_PSMODE_NORMAL)
77 mode = POWERSAVER_OFF;
78 else if (status == SETTING_PSMODE_WEARABLE)
79 mode = POWERSAVER_BASIC;
80 else if (status == SETTING_PSMODE_WEARABLE_ENHANCED)
81 mode = POWERSAVER_ENHANCED;
85 ret = set_powersaver_mode(mode);
87 _E("Failed to update powersaver state %d.", ret);
90 static int delayed_init_done(void *data)
94 int mode = POWERSAVER_OFF;
105 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
106 powersaver_status_changed, NULL);
108 _E("Failed to vconf_notify_key_changed.");
110 ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &status);
112 _E("Failed to vconf get bool.");
117 case SETTING_PSMODE_WEARABLE:
118 mode = POWERSAVER_BASIC;
120 case SETTING_PSMODE_WEARABLE_ENHANCED:
121 mode = POWERSAVER_ENHANCED;
128 _D("Powersaver mode on, %d.", mode);
129 device_notify(DEVICE_NOTIFIER_PMQOS_ULTRAPOWERSAVING, (void *)&pmqos);
130 ret = set_powersaver_mode(mode);
132 _E("Failed to update powersaver state, %d.", ret);
137 static void powersaver_init(void *data)
139 register_notifier(DEVICE_NOTIFIER_DELAYED_INIT, delayed_init_done);
142 static void powersaver_exit(void *data)
146 ret = vconf_ignore_key_changed(VCONFKEY_SETAPPL_PSMODE,
147 powersaver_status_changed);
149 _E("Failed to vconf_ignore_key_changed.");
152 static const struct device_ops powersaver_device_ops = {
153 DECLARE_NAME_LEN("powersaver"),
154 .init = powersaver_init,
155 .exit = powersaver_exit,
158 DEVICE_OPS_REGISTER(&powersaver_device_ops)
160 static void __CONSTRUCTOR__ initialize(void)
162 backlight_ops = get_var_backlight_ops();
164 _E("Failed to get backlight operator variable.");