diff options
author | Zhao Wei Liew <zhaoweiliew@gmail.com> | 2016-07-19 19:57:06 +0800 |
---|---|---|
committer | Michael Bestas <mkbestas@lineageos.org> | 2019-10-23 01:12:56 +0300 |
commit | 71131ea4e0f0a05a51443571970e4f74cb14de65 (patch) | |
tree | 5956a90ba3cd005f4c6a82e8a354cbb435dbb370 | |
parent | b989cae4900c6647bd5fddfd9930c01e999025ea (diff) | |
download | vendor_qcom_opensource_power-71131ea4e0f0a05a51443571970e4f74cb14de65.tar.gz vendor_qcom_opensource_power-71131ea4e0f0a05a51443571970e4f74cb14de65.tar.bz2 vendor_qcom_opensource_power-71131ea4e0f0a05a51443571970e4f74cb14de65.zip |
power: Simplify soc_id checks
- Get soc_id in a common util function
- Return boolean values for the target-specific soc_id checks
Change-Id: I038c435d28855859f36566de7acf881037d070f2
-rw-r--r-- | power-660.c | 33 | ||||
-rw-r--r-- | power-8916.c | 148 | ||||
-rw-r--r-- | power-8952.c | 33 | ||||
-rw-r--r-- | power-8953.c | 33 | ||||
-rw-r--r-- | utils.c | 24 | ||||
-rw-r--r-- | utils.h | 2 |
6 files changed, 134 insertions, 139 deletions
diff --git a/power-660.c b/power-660.c index b2f0b70..56c5d7c 100644 --- a/power-660.c +++ b/power-660.c @@ -59,25 +59,20 @@ static int camera_hint_ref_count; static void process_video_encode_hint(void* metadata); // static void process_cam_preview_hint(void *metadata); -/* Returns true is target is SDM630/SDM455 else false*/ -static bool is_target_SDM630() { - int fd; - bool is_target_SDM630 = false; - char buf[10] = {0}; - fd = open("/sys/devices/soc0/soc_id", O_RDONLY); - if (fd >= 0) { - if (read(fd, buf, sizeof(buf) - 1) == -1) { - ALOGW("Unable to read soc_id"); - is_target_SDM630 = false; - } else { - int soc_id = atoi(buf); - if (soc_id == 318 || soc_id == 327 || soc_id == 385) { - is_target_SDM630 = true; /* Above SOCID for SDM630/SDM455 */ - } - } - } - close(fd); - return is_target_SDM630; +/** + * If target is SDM630/SDM455: + * return true + * else: + * return false + */ +static bool is_target_SDM630(void) { + static bool is_SDM630 = false; + int soc_id; + + soc_id = get_soc_id(); + if (soc_id == 318 || soc_id == 327 || soc_id == 385) is_SDM630 = true; + + return is_SDM630; } int power_hint_override(power_hint_t hint, void* data) { diff --git a/power-8916.c b/power-8916.c index 873c51d..8241aeb 100644 --- a/power-8916.c +++ b/power-8916.c @@ -60,26 +60,20 @@ static int slack_node_rw_failed = 0; static int display_hint_sent; int display_boost; -static int is_target_8916() /* Returns value=8916 if target is 8916 else value 0 */ -{ - int fd; - int is_target_8916 = 0; - char buf[10] = {0}; - - fd = open("/sys/devices/soc0/soc_id", O_RDONLY); - if (fd >= 0) { - if (read(fd, buf, sizeof(buf) - 1) == -1) { - ALOGW("Unable to read soc_id"); - is_target_8916 = 0; - } else { - int soc_id = atoi(buf); - if (soc_id == 206 || (soc_id >= 247 && soc_id <= 250)) { - is_target_8916 = 8916; /* Above SOCID for 8916 */ - } - } - } - close(fd); - return is_target_8916; +/** + * If target is 8916: + * return true + * else: + * return false + */ +static bool is_target_8916(void) { + static bool is_8916 = false; + int soc_id; + + soc_id = get_soc_id(); + if (soc_id == 206 || (soc_id >= 247 && soc_id <= 250)) is_8916 = true; + + return is_8916; } int power_hint_override(power_hint_t hint, void* data) { @@ -123,81 +117,71 @@ int set_interactive_override(int on) { if (!on) { /* Display off. */ - switch (is_target_8916()) { - case 8916: { - if (is_interactive_governor(governor)) { - int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF}; - - if (!display_hint_sent) { - perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values, - sizeof(resource_values) / sizeof(resource_values[0])); - display_hint_sent = 1; - } - } /* Perf time rate set for 8916 target*/ - } /* End of Switch case for 8916 */ - break; - - default: { - if (is_interactive_governor(governor)) { - int resource_values[] = {TR_MS_CPU0_50, TR_MS_CPU4_50, - THREAD_MIGRATION_SYNC_OFF}; - - /* Set CPU0 MIN FREQ to 400Mhz avoid extra peak power - impact in volume key press */ - snprintf(tmp_str, NODE_MAX, "%d", MIN_FREQ_CPU0_DISP_OFF); - if (sysfs_write(scaling_min_freq[0], tmp_str) != 0) { - if (sysfs_write(scaling_min_freq[1], tmp_str) != 0) { - if (sysfs_write(scaling_min_freq[2], tmp_str) != 0) { - if (sysfs_write(scaling_min_freq[3], tmp_str) != 0) { - if (!slack_node_rw_failed) { - ALOGE("Failed to write to %s", SCALING_MIN_FREQ); - } - rc = 1; + if (is_target_8916()) { + if (is_interactive_governor(governor)) { + int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF}; + + if (!display_hint_sent) { + perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values, + sizeof(resource_values) / sizeof(resource_values[0])); + display_hint_sent = 1; + } + } /* Perf time rate set for 8916 target*/ + /* End of display hint for 8916 */ + } else { + if (is_interactive_governor(governor)) { + int resource_values[] = {TR_MS_CPU0_50, TR_MS_CPU4_50, THREAD_MIGRATION_SYNC_OFF}; + + /* Set CPU0 MIN FREQ to 400Mhz avoid extra peak power + impact in volume key press */ + snprintf(tmp_str, NODE_MAX, "%d", MIN_FREQ_CPU0_DISP_OFF); + if (sysfs_write(scaling_min_freq[0], tmp_str) != 0) { + if (sysfs_write(scaling_min_freq[1], tmp_str) != 0) { + if (sysfs_write(scaling_min_freq[2], tmp_str) != 0) { + if (sysfs_write(scaling_min_freq[3], tmp_str) != 0) { + if (!slack_node_rw_failed) { + ALOGE("Failed to write to %s", SCALING_MIN_FREQ); } + rc = 1; } } } + } - if (!display_hint_sent) { - perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values, - sizeof(resource_values) / sizeof(resource_values[0])); - display_hint_sent = 1; - } - } /* Perf time rate set for CORE0,CORE4 8939 target*/ - } /* End of Switch case for 8939 */ - break; + if (!display_hint_sent) { + perform_hint_action(DISPLAY_STATE_HINT_ID, resource_values, + sizeof(resource_values) / sizeof(resource_values[0])); + display_hint_sent = 1; + } + } /* Perf time rate set for CORE0,CORE4 8939 target*/ + /* End of display hint for 8939 */ } - } else { /* Display on. */ - switch (is_target_8916()) { - case 8916: { - if (is_interactive_governor(governor)) { - undo_hint_action(DISPLAY_STATE_HINT_ID); - display_hint_sent = 0; - } - } break; - default: { - if (is_interactive_governor(governor)) { - /* Recovering MIN_FREQ in display ON case */ - snprintf(tmp_str, NODE_MAX, "%d", MIN_FREQ_CPU0_DISP_ON); - if (sysfs_write(scaling_min_freq[0], tmp_str) != 0) { - if (sysfs_write(scaling_min_freq[1], tmp_str) != 0) { - if (sysfs_write(scaling_min_freq[2], tmp_str) != 0) { - if (sysfs_write(scaling_min_freq[3], tmp_str) != 0) { - if (!slack_node_rw_failed) { - ALOGE("Failed to write to %s", SCALING_MIN_FREQ); - } - rc = 1; + if (is_target_8916()) { + if (is_interactive_governor(governor)) { + undo_hint_action(DISPLAY_STATE_HINT_ID); + display_hint_sent = 0; + } + } else { + if (is_interactive_governor(governor)) { + /* Recovering MIN_FREQ in display ON case */ + snprintf(tmp_str, NODE_MAX, "%d", MIN_FREQ_CPU0_DISP_ON); + if (sysfs_write(scaling_min_freq[0], tmp_str) != 0) { + if (sysfs_write(scaling_min_freq[1], tmp_str) != 0) { + if (sysfs_write(scaling_min_freq[2], tmp_str) != 0) { + if (sysfs_write(scaling_min_freq[3], tmp_str) != 0) { + if (!slack_node_rw_failed) { + ALOGE("Failed to write to %s", SCALING_MIN_FREQ); } + rc = 1; } } } - undo_hint_action(DISPLAY_STATE_HINT_ID); - display_hint_sent = 0; } - - } break; + undo_hint_action(DISPLAY_STATE_HINT_ID); + display_hint_sent = 0; + } } /* End of check condition during the DISPLAY ON case */ } return HINT_HANDLED; diff --git a/power-8952.c b/power-8952.c index bc4d38b..f598fae 100644 --- a/power-8952.c +++ b/power-8952.c @@ -58,25 +58,20 @@ static void process_video_encode_hint(void* metadata); static int display_fd; #define SYS_DISPLAY_PWR "/sys/kernel/hbtp/display_pwr" -static bool is_target_SDM439() /* Returns value=1 if target is Hathi else value 0 */ -{ - int fd; - bool is_target_SDM439 = false; - char buf[10] = {0}; - fd = open("/sys/devices/soc0/soc_id", O_RDONLY); - if (fd >= 0) { - if (read(fd, buf, sizeof(buf) - 1) == -1) { - ALOGW("Unable to read soc_id"); - is_target_SDM439 = false; - } else { - int soc_id = atoi(buf); - if (soc_id == 353 || soc_id == 363 || soc_id == 354 || soc_id == 364) { - is_target_SDM439 = true; /* Above SOCID for SDM439/429 */ - } - } - } - close(fd); - return is_target_SDM439; +/** + * If target is SDM439/429: + * return true + * else: + * return false + */ +static bool is_target_SDM439(void) { + static bool is_SDM439 = false; + int soc_id; + + soc_id = get_soc_id(); + if (soc_id == 353 || soc_id == 363 || soc_id == 354 || soc_id == 364) is_SDM439 = true; + + return is_SDM439; } int power_hint_override(power_hint_t hint, void* data) { diff --git a/power-8953.c b/power-8953.c index bd10669..1cdd01d 100644 --- a/power-8953.c +++ b/power-8953.c @@ -62,25 +62,20 @@ static void process_video_encode_hint(void* metadata); static int display_fd; #define SYS_DISPLAY_PWR "/sys/kernel/hbtp/display_pwr" -static bool is_target_SDM632() /* Returns value=632 if target is SDM632 else value 0 */ -{ - int fd; - bool is_target_SDM632 = false; - char buf[10] = {0}; - fd = open("/sys/devices/soc0/soc_id", O_RDONLY); - if (fd >= 0) { - if (read(fd, buf, sizeof(buf) - 1) == -1) { - ALOGW("Unable to read soc_id"); - is_target_SDM632 = false; - } else { - int soc_id = atoi(buf); - if (soc_id == 349 || soc_id == 350) { - is_target_SDM632 = true; /* Above SOCID for SDM632 */ - } - } - } - close(fd); - return is_target_SDM632; +/** + * If target is SDM632: + * return true + * else: + * return false + */ +static bool is_target_SDM632(void) { + static bool is_SDM632 = false; + int soc_id; + + soc_id = get_soc_id(); + if (soc_id == 349 || soc_id == 350) is_SDM632 = true; + + return is_SDM632; } int power_hint_override(power_hint_t hint, void* data) { @@ -43,6 +43,9 @@ #define LOG_TAG "QTI PowerHAL" #include <log/log.h> +#define SOC_ID_0 "/sys/devices/soc0/soc_id" +#define SOC_ID_1 "/sys/devices/system/soc/soc0/id" + char scaling_gov_path[4][80] = {"sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", "sys/devices/system/cpu/cpu1/cpufreq/scaling_governor", "sys/devices/system/cpu/cpu2/cpufreq/scaling_governor", @@ -327,3 +330,24 @@ void undo_initial_hint_action() { } } } + +int get_soc_id(void) { + int fd; + int soc_id = -1; + char buf[10] = {0}; + + if (!access(SOC_ID_0, F_OK)) + fd = open(SOC_ID_0, O_RDONLY); + else + fd = open(SOC_ID_1, O_RDONLY); + + if (fd >= 0) { + if (read(fd, buf, sizeof(buf) - 1) == -1) + ALOGW("Unable to read soc_id"); + else + soc_id = atoi(buf); + } + + close(fd); + return soc_id; +} @@ -43,3 +43,5 @@ void release_request(int lock_handle); void interaction(int duration, int num_args, int opt_list[]); int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]); int perf_hint_enable(int hint_id, int duration); + +int get_soc_id(void); |