aboutsummaryrefslogtreecommitdiff
path: root/power
diff options
context:
space:
mode:
Diffstat (limited to 'power')
-rw-r--r--power/Android.mk29
-rw-r--r--power/power.c125
2 files changed, 154 insertions, 0 deletions
diff --git a/power/Android.mk b/power/Android.mk
new file mode 100644
index 0000000..06e4852
--- /dev/null
+++ b/power/Android.mk
@@ -0,0 +1,29 @@
+# Copyright (C) 2011 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := power.$(TARGET_BOARD_PLATFORM)
+LOCAL_MODULE_RELATIVE_PATH := hw
+LOCAL_SRC_FILES := power.c
+LOCAL_SHARED_LIBRARIES := liblog
+LOCAL_MODULE_TAGS := optional
+
+ifneq ($(TARGET_TAP_TO_WAKE_NODE),)
+ LOCAL_CFLAGS += -DTAP_TO_WAKE_NODE=\"$(TARGET_TAP_TO_WAKE_NODE)\"
+endif
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/power/power.c b/power/power.c
new file mode 100644
index 0000000..29653ca
--- /dev/null
+++ b/power/power.c
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2016 CyanogenMod
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define LOG_TAG "MTK PowerHAL"
+#include <utils/Log.h>
+
+#include <hardware/hardware.h>
+#include <hardware/power.h>
+
+#define MT_RUSH_BOOST_PATH "/proc/hps/rush_boost_enabled"
+#define MT_FPS_UPPER_BOUND_PATH "/d/ged/hal/fps_upper_bound"
+
+
+#define POWER_HINT_POWER_SAVING 0x00000101
+#define POWER_HINT_PERFORMANCE_BOOST 0x00000102
+#define POWER_HINT_BALANCE 0x00000103
+
+static void power_init(struct power_module *module)
+{
+}
+
+static void power_set_interactive(struct power_module *module, int on)
+{
+}
+
+static void power_fwrite(const char *path, char *s)
+{
+ char buf[64];
+ int len;
+ int fd = open(path, O_WRONLY);
+
+ if (fd < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGE("Error opening %s: %s\n", path, buf);
+ return;
+ }
+
+ len = write(fd, s, strlen(s));
+ if (len < 0) {
+ strerror_r(errno, buf, sizeof(buf));
+ ALOGE("Error writing to %s: %s\n", path, buf);
+ }
+
+ close(fd);
+}
+
+static void power_hint(struct power_module *module, power_hint_t hint,
+ void *data) {
+ int32_t dataint = -1;
+ switch (hint) {
+ case POWER_HINT_LOW_POWER:
+ dataint = *(int32_t *)data;
+ if (dataint) {
+ power_fwrite(MT_FPS_UPPER_BOUND_PATH, "30");
+ power_fwrite(MT_RUSH_BOOST_PATH, "0");
+ } else {
+ power_fwrite(MT_FPS_UPPER_BOUND_PATH, "60");
+ power_fwrite(MT_RUSH_BOOST_PATH, "1");
+ }
+ ALOGI("POWER_HINT_LOW_POWER");
+ break;
+ case POWER_HINT_VSYNC:
+ case POWER_HINT_INTERACTION:
+ case POWER_HINT_CPU_BOOST:
+ case POWER_HINT_LAUNCH_BOOST:
+ case POWER_HINT_AUDIO:
+ case POWER_HINT_SET_PROFILE:
+ case POWER_HINT_VIDEO_ENCODE:
+ case POWER_HINT_VIDEO_DECODE:
+ break;
+ default:
+ break;
+ }
+}
+
+void set_feature(struct power_module *module, feature_t feature, int state)
+{
+#ifdef TAP_TO_WAKE_NODE
+ char tmp_str[64];
+ if (feature == POWER_FEATURE_DOUBLE_TAP_TO_WAKE) {
+ snprintf(tmp_str, 64, "%d", state);
+ power_fwrite(TAP_TO_WAKE_NODE, tmp_str);
+ return;
+ }
+#endif
+}
+
+static struct hw_module_methods_t power_module_methods = {
+ .open = NULL,
+};
+
+struct power_module HAL_MODULE_INFO_SYM = {
+ .common = {
+ .tag = HARDWARE_MODULE_TAG,
+ .module_api_version = POWER_MODULE_API_VERSION_0_2,
+ .hal_api_version = HARDWARE_HAL_API_VERSION,
+ .id = POWER_HARDWARE_MODULE_ID,
+ .name = "MTK Power HAL",
+ .author = "Cyanogen",
+ .methods = &power_module_methods,
+ },
+
+ .init = power_init,
+ .setInteractive = power_set_interactive,
+ .powerHint = power_hint,
+ .setFeature = set_feature,
+};