powerHAL: Parameterize schedtune boost values

Since we're sharing this powerHAL between the
HiKey and HiKey960, use some property parameters
for some of the previously hard-coded schedtune
boost values.

Change-Id: Id436471b044e20b4db2191e657f073b94f64719e
Signed-off-by: John Stultz <john.stultz@linaro.org>
diff --git a/power/power_hikey.c b/power/power_hikey.c
index d54eae9..c3fb751 100644
--- a/power/power_hikey.c
+++ b/power/power_hikey.c
@@ -37,9 +37,15 @@
 #include <hardware/power.h>
 
 #define SCHEDTUNE_BOOST_PATH "/dev/stune/top-app/schedtune.boost"
-#define SCHEDTUNE_BOOST_NORM "10"
-#define SCHEDTUNE_BOOST_INTERACTIVE "40"
-#define SCHEDTUNE_BOOST_TIME_NS 1000000000LL
+#define SCHEDTUNE_BOOST_VAL_PROP "ro.config.schetune.touchboost.value"
+#define SCHEDTUNE_BOOST_TIME_PROP "ro.config.schetune.touchboost.time_ns"
+
+#define SCHEDTUNE_BOOST_VAL_DEFAULT "40"
+
+char schedtune_boost_norm[PROPERTY_VALUE_MAX] = "10";
+char schedtune_boost_interactive[PROPERTY_VALUE_MAX] = SCHEDTUNE_BOOST_VAL_DEFAULT;
+long long schedtune_boost_time_ns = 1000000000LL;
+
 #define INTERACTIVE_BOOSTPULSE_PATH "/sys/devices/system/cpu/cpufreq/interactive/boostpulse"
 #define INTERACTIVE_IO_IS_BUSY_PATH "/sys/devices/system/cpu/cpufreq/interactive/io_is_busy"
 #define CPU_MAX_FREQ_PATH "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
@@ -197,7 +203,7 @@
     if (hikey->schedtune_boost_fd < 0)
         return hikey->schedtune_boost_fd;
 
-    len = write(hikey->schedtune_boost_fd, booststr, 2);
+    len = write(hikey->schedtune_boost_fd, booststr, strlen(booststr));
     if (len < 0) {
         strerror_r(errno, buf, sizeof(buf));
         ALOGE("Error writing to %s: %s\n", SCHEDTUNE_BOOST_PATH, buf);
@@ -223,7 +229,7 @@
                 continue;
             }
 
-            schedtune_sysfs_boost(hikey, SCHEDTUNE_BOOST_NORM);
+            schedtune_sysfs_boost(hikey, schedtune_boost_norm);
             hikey->deboost_time = 0;
             pthread_mutex_unlock(&hikey->lock);
             break;
@@ -241,10 +247,10 @@
 
     now = gettime_ns();
     if (!hikey->deboost_time) {
-        schedtune_sysfs_boost(hikey, SCHEDTUNE_BOOST_INTERACTIVE);
+        schedtune_sysfs_boost(hikey, schedtune_boost_interactive);
         sem_post(&hikey->signal_lock);
     }
-    hikey->deboost_time = now + SCHEDTUNE_BOOST_TIME_NS;
+    hikey->deboost_time = now + schedtune_boost_time_ns;
 
     return 0;
 }
@@ -254,16 +260,34 @@
     char buf[50];
     pthread_t tid;
 
-
     hikey->deboost_time = 0;
     sem_init(&hikey->signal_lock, 0, 1);
 
-    hikey->schedtune_boost_fd = open(SCHEDTUNE_BOOST_PATH, O_WRONLY);
+    hikey->schedtune_boost_fd = open(SCHEDTUNE_BOOST_PATH, O_RDWR);
     if (hikey->schedtune_boost_fd < 0) {
         strerror_r(errno, buf, sizeof(buf));
         ALOGE("Error opening %s: %s\n", SCHEDTUNE_BOOST_PATH, buf);
+        return;
     }
 
+    schedtune_boost_time_ns = property_get_int64(SCHEDTUNE_BOOST_TIME_PROP,
+                                                 1000000000LL);
+    property_get(SCHEDTUNE_BOOST_VAL_PROP, schedtune_boost_interactive,
+                 SCHEDTUNE_BOOST_VAL_DEFAULT);
+
+    if (hikey->schedtune_boost_fd >= 0) {
+        size_t len = read(hikey->schedtune_boost_fd, schedtune_boost_norm,
+                          PROPERTY_VALUE_MAX);
+	if (len <= 0)
+            ALOGE("Error reading normal boost value\n");
+	else if (schedtune_boost_norm[len] == '\n')
+            schedtune_boost_norm[len] = '\0';
+
+    }
+
+    ALOGV("Starting with schedtune boost norm: %s touchboost: %s and boosttime: %lld\n",
+	  schedtune_boost_norm, schedtune_boost_interactive, schedtune_boost_time_ns);
+
     pthread_create(&tid, NULL, schedtune_deboost_thread, hikey);
 }