summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorZhang Jiejing <jiejing.zhang@freescale.com>2012-02-06 14:51:58 +0800
committerZhang Jiejing <jiejing.zhang@freescale.com>2012-02-08 13:20:23 +0800
commit1b6feda9a4216683aa12da0a33f7871ee0540540 (patch)
tree622720a11e93a73ab9e92c7552aa96f10cdcef3e /kernel
parentdd9eb70f8322b620eac8904740fcf63bce98b13e (diff)
ENGR00173756-1 Android: cpufreq: add cpu frquency governor save/restore function.
improve the power consumption situation for audio playback, background downloading,etc tasks. the scaling governor is set to conservative when display is turned off and the default governor is saved. The governor is restored when display is turned on. Signed-off-by: Wen Yi <wyi@nvidia.com> Signed-off-by: Zhang Jiejing <jiejing.zhang@freescale.com>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/power/Kconfig7
-rw-r--r--kernel/power/Makefile1
-rw-r--r--kernel/power/cpufreq_earlysuspend.c160
3 files changed, 168 insertions, 0 deletions
diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
index b29772f0ec65..f8a559ce65d3 100644
--- a/kernel/power/Kconfig
+++ b/kernel/power/Kconfig
@@ -49,6 +49,13 @@ config HAS_WAKELOCK
config HAS_EARLYSUSPEND
bool
+config CPUFREQ_GOV_ON_EARLYSUPSEND
+ bool "Use conservative cpu frequency governor when device enters early suspend"
+ depends on HAS_EARLYSUSPEND && CPU_FREQ
+ default n
+ help
+ Also will restore to original cpu frequency governor when device is resumed
+
config WAKELOCK
bool "Wake lock"
depends on PM && RTC_CLASS
diff --git a/kernel/power/Makefile b/kernel/power/Makefile
index 9b224e16b191..d1fb60636fd3 100644
--- a/kernel/power/Makefile
+++ b/kernel/power/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_USER_WAKELOCK) += userwakelock.o
obj-$(CONFIG_EARLYSUSPEND) += earlysuspend.o
obj-$(CONFIG_CONSOLE_EARLYSUSPEND) += consoleearlysuspend.o
obj-$(CONFIG_FB_EARLYSUSPEND) += fbearlysuspend.o
+obj-$(CONFIG_CPUFREQ_GOV_ON_EARLYSUPSEND) += cpufreq_earlysuspend.o
obj-$(CONFIG_SUSPEND_TIME) += suspend_time.o
obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
diff --git a/kernel/power/cpufreq_earlysuspend.c b/kernel/power/cpufreq_earlysuspend.c
new file mode 100644
index 000000000000..fe2571d684e4
--- /dev/null
+++ b/kernel/power/cpufreq_earlysuspend.c
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C)2012 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/fs.h>
+#include <linux/earlysuspend.h>
+#include <linux/cpufreq.h>
+
+void cpufreq_save_default_governor(void);
+void cpufreq_restore_default_governor(void);
+void cpufreq_set_conservative_governor(void);
+void cpufreq_set_conservative_governor_param(int up_th, int down_th);
+
+#define SET_CONSERVATIVE_GOVERNOR_UP_THRESHOLD 95
+#define SET_CONSERVATIVE_GOVERNOR_DOWN_THRESHOLD 50
+
+static char cpufreq_gov_default[32];
+static char *cpufreq_gov_conservative = "conservative";
+static char *cpufreq_sysfs_place_holder = "/sys/devices/system/cpu/cpu%i/cpufreq/scaling_governor";
+static char *cpufreq_gov_conservative_param = "/sys/devices/system/cpu/cpufreq/conservative/%s";
+
+static void cpufreq_set_governor(char *governor)
+{
+ struct file *scaling_gov = NULL;
+ char buf[128];
+ int i;
+ loff_t offset = 0;
+
+ if (governor == NULL)
+ return;
+
+ for_each_online_cpu(i) {
+ sprintf(buf, cpufreq_sysfs_place_holder, i);
+ scaling_gov = filp_open(buf, O_RDWR, 0);
+ if (scaling_gov != NULL) {
+ if (scaling_gov->f_op != NULL &&
+ scaling_gov->f_op->write != NULL)
+ scaling_gov->f_op->write(scaling_gov,
+ governor,
+ strlen(governor),
+ &offset);
+ else
+ pr_err("f_op might be null\n");
+
+ filp_close(scaling_gov, NULL);
+ } else {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ }
+ }
+}
+
+void cpufreq_save_default_governor(void)
+{
+ int ret;
+ struct cpufreq_policy current_policy;
+ ret = cpufreq_get_policy(&current_policy, 0);
+ if (ret < 0)
+ pr_err("%s: cpufreq_get_policy got error", __func__);
+ memcpy(cpufreq_gov_default, current_policy.governor->name, 32);
+}
+
+void cpufreq_restore_default_governor(void)
+{
+ cpufreq_set_governor(cpufreq_gov_default);
+}
+
+void cpufreq_set_conservative_governor_param(int up_th, int down_th)
+{
+ struct file *gov_param = NULL;
+ static char buf[128], parm[8];
+ loff_t offset = 0;
+
+ if (up_th <= down_th) {
+ printk(KERN_ERR "%s: up_th(%d) is lesser than down_th(%d)\n",
+ __func__, up_th, down_th);
+ return;
+ }
+
+ sprintf(parm, "%d", up_th);
+ sprintf(buf, cpufreq_gov_conservative_param , "up_threshold");
+ gov_param = filp_open(buf, O_RDONLY, 0);
+ if (gov_param != NULL) {
+ if (gov_param->f_op != NULL &&
+ gov_param->f_op->write != NULL)
+ gov_param->f_op->write(gov_param,
+ parm,
+ strlen(parm),
+ &offset);
+ else
+ pr_err("f_op might be null\n");
+
+ filp_close(gov_param, NULL);
+ } else {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ }
+
+ sprintf(parm, "%d", down_th);
+ sprintf(buf, cpufreq_gov_conservative_param , "down_threshold");
+ gov_param = filp_open(buf, O_RDONLY, 0);
+ if (gov_param != NULL) {
+ if (gov_param->f_op != NULL &&
+ gov_param->f_op->write != NULL)
+ gov_param->f_op->write(gov_param,
+ parm,
+ strlen(parm),
+ &offset);
+ else
+ pr_err("f_op might be null\n");
+
+ filp_close(gov_param, NULL);
+ } else {
+ pr_err("%s. Can't open %s\n", __func__, buf);
+ }
+}
+
+static void cpufreq_early_suspend(struct early_suspend *p)
+{
+ cpufreq_save_default_governor();
+ cpufreq_set_conservative_governor();
+ cpufreq_set_conservative_governor_param(
+ SET_CONSERVATIVE_GOVERNOR_UP_THRESHOLD,
+ SET_CONSERVATIVE_GOVERNOR_DOWN_THRESHOLD);
+}
+
+static void cpufreq_late_resume(struct early_suspend *p)
+{
+ cpufreq_restore_default_governor();
+}
+
+struct early_suspend cpufreq_earlysuspend = {
+ .level = EARLY_SUSPEND_LEVEL_POST_DISABLE_FB,
+ .suspend = cpufreq_early_suspend,
+ .resume = cpufreq_late_resume,
+};
+
+void cpufreq_set_conservative_governor(void)
+{
+ cpufreq_set_governor(cpufreq_gov_conservative);
+}
+
+static int __init cpufreq_on_earlysuspend_init(void)
+{
+ register_early_suspend(&cpufreq_earlysuspend);
+ return 0;
+}
+
+static void __exit cpufreq_on_earlysuspend_exit(void)
+{
+ unregister_early_suspend(&cpufreq_earlysuspend);
+}
+
+module_init(cpufreq_on_earlysuspend_init);
+module_exit(cpufreq_on_earlysuspend_exit);