From f30d43663f07544eb836d0502a5c492895b87324 Mon Sep 17 00:00:00 2001 From: nuclearmistake Date: Sat, 22 Sep 2012 16:46:34 -0400 Subject: tuna: make tuna powerhal conditionally set max_freq properly -read value of both scaling_max_freq and screen_off_max_freq from sysfs (previously, power_hal only did the former) -if scaling_max_freq is larger than screen_off_max_freq, then save it into our scaling_max_freq variable, because it is truly the scaling_max_freq otherwise, the scaling_max_freq sysfs path has had screen_off_max_freq written to it, so we don't save it to scaling_max_freq. -write the appropriate value (screen_off_max if screen is off, etc.) to scaling_max_freq sysfs path Change-Id: I10cd571df61a5d583dd73be0cb6c7c2201477a96 Signed-off-by: nuclearmistake --- power/power_tuna.c | 58 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/power/power_tuna.c b/power/power_tuna.c index 1676209..455137d 100644 --- a/power/power_tuna.c +++ b/power/power_tuna.c @@ -35,6 +35,9 @@ static char screen_off_max_freq[MAX_BUF_SZ] = "700000"; static char scaling_max_freq[MAX_BUF_SZ] = "1200000"; +/* for tracking previous screen state */ +static int previous_state = 0; + struct tuna_power_module { struct power_module base; pthread_mutex_t lock; @@ -123,29 +126,44 @@ 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. + * Lower maximum frequency when screen changes from on to off. + * Return it to previous value when screen changes from off to on. + * 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)); - - /* make sure it's not the screen off freq, if the "on" - * call is skipped (can happen if you press the power - * button repeatedly) we might have read it. We should - * skip it if that's the case + + //screen state has changed since last call + if (on != previous_state) + { + char buf_screen_off_max[MAX_BUF_SZ], buf_scaling_max[MAX_BUF_SZ]; + int screen_off_max, scaling_max; + + previous_state = on; + + //read value of screen-off max from sysfs, and convert to int for comparison + if (sysfs_read(SCREENOFFMAXFREQ_PATH, buf_screen_off_max, sizeof(buf_screen_off_max)) != -1) + screen_off_max = atoi(buf_screen_off_max); + + //read value of max from sysfs, and convert to int for comparison + if (sysfs_read(SCALINGMAXFREQ_PATH, buf_scaling_max, sizeof(buf_scaling_max)) != -1) + scaling_max = atoi(buf_scaling_max); + + /* If scaling_max_freq > screen_off_max_freq, then scaling_max_freq is really the maximum frequency, so save it for the next time the screen comes on. + * If screen_off_max_freq == 0, then we're just going to write our saved scalin_max_freq back to sysfs no matter what + * If scaling_max_freq == screen_off_max_freq, then scaling_max_freq has the screen_off_max in it, so DON'T SAVE IT TO OUR MAX VARIABLE! */ - if (len != -1 && strncmp(buf, screen_off_max_freq, - strlen(screen_off_max_freq)) != 0) - memcpy(scaling_max_freq, buf, sizeof(buf)); - sysfs_write(SCALINGMAXFREQ_PATH, screen_off_max_freq); - } else - sysfs_write(SCALINGMAXFREQ_PATH, scaling_max_freq); + if (scaling_max > screen_off_max) + memcpy(scaling_max_freq, + (scaling_max > screen_off_max) ? buf_scaling_max : buf_screen_off_max, + strlen((scaling_max > screen_off_max) ? buf_scaling_max : buf_screen_off_max)); + + memcpy(screen_off_max_freq, + (scaling_max <= screen_off_max && screen_off_max > 0) ? buf_scaling_max : buf_screen_off_max, + strlen((scaling_max <= screen_off_max && screen_off_max > 0) ? buf_scaling_max : buf_screen_off_max)); + + //write the appropriate value for scaling_max back to sysfs + sysfs_write(SCALINGMAXFREQ_PATH, on?scaling_max_freq:screen_off_max_freq); + } } static void tuna_power_hint(struct power_module *module, power_hint_t hint, -- cgit v1.2.3