From d04712d6739ee8f73b5a568c14348e8a975ff653 Mon Sep 17 00:00:00 2001 From: Paul Reioux Date: Tue, 28 Aug 2012 15:35:42 +0200 Subject: Fixed overclocking Power HAL module Change-Id: I7fc7c517e04eee3933ab7107e788b50e41270b67 --- power/power_tuna.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'power') diff --git a/power/power_tuna.c b/power/power_tuna.c index 32ed3ff..34b488f 100644 --- a/power/power_tuna.c +++ b/power/power_tuna.c @@ -25,8 +25,16 @@ #include #include +#define SCALINGMAXFREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq" +#define SCREENOFFMAXFREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/screen_off_max_freq" #define BOOSTPULSE_PATH "/sys/devices/system/cpu/cpufreq/interactive/boostpulse" +#define MAX_BUF_SZ 10 + +/* initialize to something safe */ +static char screen_off_max_freq[MAX_BUF_SZ] = "700000"; +static char scaling_max_freq[MAX_BUF_SZ] = "1200000"; + struct tuna_power_module { struct power_module base; pthread_mutex_t lock; @@ -55,6 +63,23 @@ static void sysfs_write(char *path, char *s) close(fd); } +int sysfs_read(const char *path, char *buf, size_t size) +{ + int fd, len; + + fd = open(path, O_RDONLY); + if (fd < 0) + return -1; + + do { + len = read(fd, buf, size); + } while (len < 0 && errno == EINTR); + + close(fd); + + return len; +} + static void tuna_power_init(struct power_module *module) { sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/timer_rate", @@ -95,13 +120,27 @@ static int boostpulse_open(struct tuna_power_module *tuna) static void tuna_power_set_interactive(struct power_module *module, int on) { + int len; + + char buf[MAX_BUF_SZ]; + /* * Lower maximum frequency when screen is off. CPU 0 and 1 share a * cpufreq policy. */ + if (!on) { + /* read the current scaling max freq and save it before updating */ + len = sysfs_read(SCALINGMAXFREQ_PATH, buf, sizeof(buf)); + + if (len != -1) + memcpy(scaling_max_freq, buf, sizeof(buf)); - sysfs_write("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", - on ? "1200000" : "700000"); + sysfs_write("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", + on ? scaling_max_freq : screen_off_max_freq); + } + else + sysfs_write("/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", + on ? scaling_max_freq : screen_off_max_freq); } static void tuna_power_hint(struct power_module *module, power_hint_t hint, -- cgit v1.1