summaryrefslogtreecommitdiffstats
path: root/power
diff options
context:
space:
mode:
authornuclearmistake <nuclearmistake@gmail.com>2012-09-22 16:46:34 -0400
committernuclearmistake <nuclearmistake@gmail.com>2012-10-13 11:11:25 -0400
commitf30d43663f07544eb836d0502a5c492895b87324 (patch)
tree87869fa763a1bd5096b6115a545fb4a7e967eebd /power
parent69619a27a38212ce0ae051fe5f762769112e203e (diff)
downloaddevice_samsung_tuna-f30d43663f07544eb836d0502a5c492895b87324.zip
device_samsung_tuna-f30d43663f07544eb836d0502a5c492895b87324.tar.gz
device_samsung_tuna-f30d43663f07544eb836d0502a5c492895b87324.tar.bz2
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 <nuclearmistake@gmail.com>
Diffstat (limited to 'power')
-rw-r--r--power/power_tuna.c58
1 files 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,