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"
27 static int power_saving_custom_cpu_cb(keynode_t *key_nodes, void *data)
31 val = vconf_keynode_get_bool(key_nodes);
32 device_notify(DEVICE_NOTIFIER_PMQOS_POWERSAVING, (void*)val);
36 static int emergency_cpu_cb(keynode_t *key_nodes, void *data)
40 val = vconf_keynode_get_int(key_nodes);
41 if (val == SETTING_PSMODE_EMERGENCY)
45 device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val);
49 static void set_freq_limit(void)
54 ret = vconf_get_bool(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU,
57 _E("failed to get vconf key");
63 device_notify(DEVICE_NOTIFIER_PMQOS_POWERSAVING, (void*)val);
66 static void set_emergency_limit(void)
70 ret = vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &val);
72 _E("failed to get vconf key");
75 if (val != SETTING_PSMODE_EMERGENCY)
79 device_notify(DEVICE_NOTIFIER_PMQOS_EMERGENCY, (void*)val);
83 static int booting_done(void *data)
86 set_emergency_limit();
91 static void powersaver_init(void *data)
95 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PWRSV_CUSTMODE_CPU,
96 (void *)power_saving_custom_cpu_cb, NULL);
98 _E("Failed to vconf_notify_key_changed!");
99 ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE,
100 (void *)emergency_cpu_cb, NULL);
102 _E("Failed to vconf_notify_key_changed!");
103 register_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
106 static void powersaver_exit(void *data)
108 unregister_notifier(DEVICE_NOTIFIER_BOOTING_DONE, booting_done);
111 static const struct device_ops powersaver_device_ops = {
112 .priority = DEVICE_PRIORITY_NORMAL,
113 .name = "powersaver",
114 .init = powersaver_init,
115 .exit = powersaver_exit,
118 DEVICE_OPS_REGISTER(&powersaver_device_ops)