vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #define LOG_NIDEBUG 0 |
| 31 | |
| 32 | #include <errno.h> |
| 33 | #include <string.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/stat.h> |
| 36 | #include <fcntl.h> |
| 37 | #include <dlfcn.h> |
| 38 | #include <stdlib.h> |
| 39 | |
| 40 | #define LOG_TAG "QTI PowerHAL" |
| 41 | #include <utils/Log.h> |
| 42 | #include <hardware/hardware.h> |
| 43 | #include <hardware/power.h> |
| 44 | |
| 45 | #include "utils.h" |
| 46 | #include "metadata-defs.h" |
| 47 | #include "hint-data.h" |
| 48 | #include "performance.h" |
| 49 | #include "power-common.h" |
| 50 | |
| 51 | #define MIN_FREQ_CPU0_DISP_OFF 400000 |
| 52 | #define MIN_FREQ_CPU0_DISP_ON 960000 |
| 53 | |
Nikhil Kumar Kansal | 1bd0289 | 2015-07-22 18:47:46 +0530 | [diff] [blame] | 54 | char scaling_min_freq[4][80] ={ |
| 55 | "sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", |
| 56 | "sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq", |
| 57 | "sys/devices/system/cpu/cpu2/cpufreq/scaling_min_freq", |
| 58 | "sys/devices/system/cpu/cpu3/cpufreq/scaling_min_freq" |
| 59 | }; |
| 60 | |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 61 | static int saved_dcvs_cpu0_slack_max = -1; |
| 62 | static int saved_dcvs_cpu0_slack_min = -1; |
| 63 | static int saved_mpdecision_slack_max = -1; |
| 64 | static int saved_mpdecision_slack_min = -1; |
| 65 | static int saved_interactive_mode = -1; |
| 66 | static int slack_node_rw_failed = 0; |
| 67 | static int display_hint_sent; |
| 68 | int display_boost; |
| 69 | |
| 70 | static int is_target_8916() /* Returns value=8916 if target is 8916 else value 0 */ |
| 71 | { |
| 72 | int fd; |
| 73 | int is_target_8916=0; |
| 74 | char buf[10] = {0}; |
| 75 | |
| 76 | fd = open("/sys/devices/soc0/soc_id", O_RDONLY); |
| 77 | if (fd >= 0) { |
| 78 | if (read(fd, buf, sizeof(buf) - 1) == -1) { |
| 79 | ALOGW("Unable to read soc_id"); |
| 80 | is_target_8916 = 0; |
| 81 | } else { |
| 82 | int soc_id = atoi(buf); |
| 83 | if (soc_id == 206 || (soc_id >= 247 && soc_id <= 250)) { |
| 84 | is_target_8916 = 8916; /* Above SOCID for 8916 */ |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | close(fd); |
| 89 | return is_target_8916; |
| 90 | } |
| 91 | |
Rashed Abdel-Tawab | a2a7071 | 2017-12-31 01:21:40 +0200 | [diff] [blame^] | 92 | int power_hint_override(power_hint_t hint, void *data) |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 93 | { |
| 94 | |
| 95 | switch(hint) { |
| 96 | case POWER_HINT_VSYNC: |
| 97 | break; |
| 98 | case POWER_HINT_INTERACTION: |
| 99 | { |
| 100 | int resources[] = {0x702, 0x20F, 0x30F}; |
| 101 | int duration = 3000; |
| 102 | |
| 103 | interaction(duration, sizeof(resources)/sizeof(resources[0]), resources); |
| 104 | } |
| 105 | return HINT_HANDLED; |
| 106 | case POWER_HINT_VIDEO_ENCODE: /* Do nothing for encode case */ |
| 107 | return HINT_HANDLED; |
| 108 | case POWER_HINT_VIDEO_DECODE: /*Do nothing for encode case */ |
| 109 | return HINT_HANDLED; |
Nikhil Kumar Kansal | 1bd0289 | 2015-07-22 18:47:46 +0530 | [diff] [blame] | 110 | default: |
| 111 | return HINT_HANDLED; |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 112 | } |
| 113 | return HINT_NONE; |
| 114 | } |
| 115 | |
Rashed Abdel-Tawab | a2a7071 | 2017-12-31 01:21:40 +0200 | [diff] [blame^] | 116 | int set_interactive_override(int on) |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 117 | { |
| 118 | char governor[80]; |
| 119 | char tmp_str[NODE_MAX]; |
| 120 | struct video_encode_metadata_t video_encode_metadata; |
| 121 | int rc; |
| 122 | |
| 123 | ALOGI("Got set_interactive hint"); |
Nikhil Kumar Kansal | 1bd0289 | 2015-07-22 18:47:46 +0530 | [diff] [blame] | 124 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU0) == -1) { |
| 125 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU1) == -1) { |
| 126 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU2) == -1) { |
| 127 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU3) == -1) { |
| 128 | ALOGE("Can't obtain scaling governor."); |
| 129 | return HINT_HANDLED; |
| 130 | } |
| 131 | } |
| 132 | } |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | if (!on) { |
| 136 | /* Display off. */ |
| 137 | switch(is_target_8916()) { |
| 138 | |
| 139 | case 8916: |
| 140 | { |
| 141 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 142 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 143 | int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF}; |
| 144 | |
| 145 | if (!display_hint_sent) { |
| 146 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 147 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 148 | display_hint_sent = 1; |
| 149 | } |
| 150 | } /* Perf time rate set for 8916 target*/ |
| 151 | } /* End of Switch case for 8916 */ |
| 152 | break ; |
| 153 | |
| 154 | default: |
| 155 | { |
| 156 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 157 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 158 | int resource_values[] = {TR_MS_CPU0_50,TR_MS_CPU4_50, THREAD_MIGRATION_SYNC_OFF}; |
| 159 | |
| 160 | /* Set CPU0 MIN FREQ to 400Mhz avoid extra peak power |
| 161 | impact in volume key press */ |
| 162 | snprintf(tmp_str, NODE_MAX, "%d", MIN_FREQ_CPU0_DISP_OFF); |
Nikhil Kumar Kansal | 1bd0289 | 2015-07-22 18:47:46 +0530 | [diff] [blame] | 163 | if (sysfs_write(scaling_min_freq[0], tmp_str) != 0) { |
| 164 | if (sysfs_write(scaling_min_freq[1], tmp_str) != 0) { |
| 165 | if (sysfs_write(scaling_min_freq[2], tmp_str) != 0) { |
| 166 | if (sysfs_write(scaling_min_freq[3], tmp_str) != 0) { |
| 167 | if(!slack_node_rw_failed) { |
| 168 | ALOGE("Failed to write to %s",SCALING_MIN_FREQ ); |
| 169 | } |
| 170 | rc = 1; |
| 171 | } |
| 172 | } |
| 173 | } |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | if (!display_hint_sent) { |
| 177 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 178 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 179 | display_hint_sent = 1; |
| 180 | } |
| 181 | } /* Perf time rate set for CORE0,CORE4 8939 target*/ |
| 182 | }/* End of Switch case for 8939 */ |
| 183 | break ; |
| 184 | } |
| 185 | |
| 186 | } else { |
| 187 | /* Display on. */ |
| 188 | switch(is_target_8916()){ |
| 189 | case 8916: |
| 190 | { |
| 191 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 192 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 193 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
| 194 | display_hint_sent = 0; |
| 195 | } |
| 196 | } |
| 197 | break ; |
| 198 | default : |
| 199 | { |
| 200 | |
| 201 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 202 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 203 | |
| 204 | /* Recovering MIN_FREQ in display ON case */ |
Nikhil Kumar Kansal | 1bd0289 | 2015-07-22 18:47:46 +0530 | [diff] [blame] | 205 | snprintf(tmp_str, NODE_MAX, "%d", MIN_FREQ_CPU0_DISP_ON); |
| 206 | if (sysfs_write(scaling_min_freq[0], tmp_str) != 0) { |
| 207 | if (sysfs_write(scaling_min_freq[1], tmp_str) != 0) { |
| 208 | if (sysfs_write(scaling_min_freq[2], tmp_str) != 0) { |
| 209 | if (sysfs_write(scaling_min_freq[3], tmp_str) != 0) { |
| 210 | if(!slack_node_rw_failed) { |
| 211 | ALOGE("Failed to write to %s",SCALING_MIN_FREQ ); |
| 212 | } |
| 213 | rc = 1; |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | } |
vaibhav bhalla | eef51ad | 2015-02-23 20:11:59 +0530 | [diff] [blame] | 218 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
| 219 | display_hint_sent = 0; |
| 220 | } |
| 221 | |
| 222 | } |
| 223 | break ; |
| 224 | } /* End of check condition during the DISPLAY ON case */ |
| 225 | } |
| 226 | saved_interactive_mode = !!on; |
| 227 | return HINT_HANDLED; |
| 228 | } |
| 229 | |