Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 1 | /* |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012-2017, The Linux Foundation. All rights reserved. |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 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. |
Duy Truong | 7022245 | 2013-02-10 06:35:11 -0800 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation nor the names of its |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 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 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 30 | #define LOG_NIDEBUG 0 |
| 31 | |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 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 "QCOM PowerHAL" |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 41 | #include <utils/Log.h> |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 42 | #include <hardware/hardware.h> |
| 43 | #include <hardware/power.h> |
| 44 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 45 | #include "utils.h" |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 46 | #include "metadata-defs.h" |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 47 | #include "hint-data.h" |
| 48 | #include "performance.h" |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 49 | #include "power-common.h" |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 50 | |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 51 | static int saved_dcvs_cpu0_slack_max = -1; |
| 52 | static int saved_dcvs_cpu0_slack_min = -1; |
| 53 | static int saved_mpdecision_slack_max = -1; |
| 54 | static int saved_mpdecision_slack_min = -1; |
| 55 | static int saved_interactive_mode = -1; |
| 56 | static int slack_node_rw_failed = 0; |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 57 | static int display_hint_sent; |
Zhoulu Luo | 3b1fbdb | 2013-12-06 16:32:10 -0800 | [diff] [blame] | 58 | int display_boost; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 59 | |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 60 | static int power_device_open(const hw_module_t* module, const char* name, |
| 61 | hw_device_t** device); |
| 62 | |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 63 | static struct hw_module_methods_t power_module_methods = { |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 64 | .open = power_device_open, |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 67 | static void power_init(struct power_module *module) |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 68 | { |
| 69 | ALOGI("QCOM power HAL initing."); |
Zhoulu Luo | 3b1fbdb | 2013-12-06 16:32:10 -0800 | [diff] [blame] | 70 | |
| 71 | int fd; |
| 72 | char buf[10] = {0}; |
| 73 | |
| 74 | fd = open("/sys/devices/soc0/soc_id", O_RDONLY); |
| 75 | if (fd >= 0) { |
| 76 | if (read(fd, buf, sizeof(buf) - 1) == -1) { |
| 77 | ALOGW("Unable to read soc_id"); |
| 78 | } else { |
| 79 | int soc_id = atoi(buf); |
Dilip Gudlur | f18fc4c | 2014-01-15 14:24:45 -0800 | [diff] [blame] | 80 | if (soc_id == 194 || (soc_id >= 208 && soc_id <= 218) || soc_id == 178) { |
Zhoulu Luo | 3b1fbdb | 2013-12-06 16:32:10 -0800 | [diff] [blame] | 81 | display_boost = 1; |
| 82 | } |
| 83 | } |
| 84 | close(fd); |
| 85 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 88 | static void process_video_decode_hint(void *metadata) |
| 89 | { |
| 90 | char governor[80]; |
| 91 | struct video_decode_metadata_t video_decode_metadata; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 92 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 93 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
| 94 | ALOGE("Can't obtain scaling governor."); |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 95 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 96 | return; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 99 | if (metadata) { |
| 100 | ALOGI("Processing video decode hint. Metadata: %s", (char *)metadata); |
| 101 | } |
| 102 | |
| 103 | /* Initialize encode metadata struct fields. */ |
| 104 | memset(&video_decode_metadata, 0, sizeof(struct video_decode_metadata_t)); |
| 105 | video_decode_metadata.state = -1; |
| 106 | video_decode_metadata.hint_id = DEFAULT_VIDEO_DECODE_HINT_ID; |
| 107 | |
| 108 | if (metadata) { |
| 109 | if (parse_video_decode_metadata((char *)metadata, &video_decode_metadata) == |
| 110 | -1) { |
| 111 | ALOGE("Error occurred while parsing metadata."); |
| 112 | return; |
| 113 | } |
| 114 | } else { |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | if (video_decode_metadata.state == 1) { |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 119 | if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) && |
| 120 | (strlen(governor) == strlen(ONDEMAND_GOVERNOR))) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 121 | int resource_values[] = {THREAD_MIGRATION_SYNC_OFF}; |
| 122 | |
| 123 | perform_hint_action(video_decode_metadata.hint_id, |
| 124 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 125 | } else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 126 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 127 | int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 128 | |
| 129 | perform_hint_action(video_decode_metadata.hint_id, |
| 130 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 131 | } |
| 132 | } else if (video_decode_metadata.state == 0) { |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 133 | if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) && |
| 134 | (strlen(governor) == strlen(ONDEMAND_GOVERNOR))) { |
| 135 | } else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 136 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 137 | undo_hint_action(video_decode_metadata.hint_id); |
| 138 | } |
| 139 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void process_video_encode_hint(void *metadata) |
| 143 | { |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 144 | char governor[80]; |
| 145 | struct video_encode_metadata_t video_encode_metadata; |
| 146 | |
| 147 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
| 148 | ALOGE("Can't obtain scaling governor."); |
| 149 | |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | /* Initialize encode metadata struct fields. */ |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 154 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 155 | video_encode_metadata.state = -1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 156 | video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 157 | |
| 158 | if (metadata) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 159 | if (parse_video_encode_metadata((char *)metadata, &video_encode_metadata) == |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 160 | -1) { |
| 161 | ALOGE("Error occurred while parsing metadata."); |
| 162 | return; |
| 163 | } |
| 164 | } else { |
| 165 | return; |
| 166 | } |
| 167 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 168 | if (video_encode_metadata.state == 1) { |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 169 | if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) && |
| 170 | (strlen(governor) == strlen(ONDEMAND_GOVERNOR))) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 171 | int resource_values[] = {IO_BUSY_OFF, SAMPLING_DOWN_FACTOR_1, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 172 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 173 | perform_hint_action(video_encode_metadata.hint_id, |
| 174 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 175 | } else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 176 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
Anurag Singh | 6cda91c | 2013-12-18 18:24:14 -0800 | [diff] [blame] | 177 | int resource_values[] = {TR_MS_30, HISPEED_LOAD_90, HS_FREQ_1026, THREAD_MIGRATION_SYNC_OFF, |
| 178 | INTERACTIVE_IO_BUSY_OFF}; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 179 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 180 | perform_hint_action(video_encode_metadata.hint_id, |
| 181 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 182 | } |
| 183 | } else if (video_encode_metadata.state == 0) { |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 184 | if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) && |
| 185 | (strlen(governor) == strlen(ONDEMAND_GOVERNOR))) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 186 | undo_hint_action(video_encode_metadata.hint_id); |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 187 | } else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 188 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 189 | undo_hint_action(video_encode_metadata.hint_id); |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | int __attribute__ ((weak)) power_hint_override(struct power_module *module, power_hint_t hint, |
| 195 | void *data) |
| 196 | { |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 197 | return HINT_NONE; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Ajay Dudani | 5e67680 | 2015-04-07 23:56:52 -0700 | [diff] [blame] | 200 | /* Declare function before use */ |
| 201 | void interaction(int duration, int num_args, int opt_list[]); |
| 202 | |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 203 | static void power_hint(struct power_module *module, power_hint_t hint, |
| 204 | void *data) |
| 205 | { |
| 206 | /* Check if this hint has been overridden. */ |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 207 | if (power_hint_override(module, hint, data) == HINT_HANDLED) { |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 208 | /* The power_hint has been handled. We can skip the rest. */ |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | switch(hint) { |
| 213 | case POWER_HINT_VSYNC: |
| 214 | break; |
Ananth Raghavan Subramanian | e432dbf | 2017-03-24 16:30:12 -0700 | [diff] [blame] | 215 | case POWER_HINT_SUSTAINED_PERFORMANCE: |
| 216 | ALOGI("Sustained perf power hint not handled in power_hint_override"); |
| 217 | break; |
| 218 | case POWER_HINT_VR_MODE: |
| 219 | ALOGI("VR mode power hint not handled in power_hint_override"); |
| 220 | break; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 221 | case POWER_HINT_INTERACTION: |
Vince Leung | 699c1bc | 2013-08-14 17:40:36 -0700 | [diff] [blame] | 222 | { |
| 223 | int resources[] = {0x702, 0x20F, 0x30F}; |
| 224 | int duration = 3000; |
| 225 | |
| 226 | interaction(duration, sizeof(resources)/sizeof(resources[0]), resources); |
| 227 | } |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 228 | break; |
| 229 | case POWER_HINT_VIDEO_ENCODE: |
| 230 | process_video_encode_hint(data); |
| 231 | break; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 232 | case POWER_HINT_VIDEO_DECODE: |
| 233 | process_video_decode_hint(data); |
| 234 | break; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 238 | int __attribute__ ((weak)) set_interactive_override(struct power_module *module, int on) |
| 239 | { |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 240 | return HINT_NONE; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | void set_interactive(struct power_module *module, int on) |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 244 | { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 245 | char governor[80]; |
| 246 | char tmp_str[NODE_MAX]; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 247 | struct video_encode_metadata_t video_encode_metadata; |
Krishna Vanka | 42c06e1 | 2016-08-29 16:38:54 +0530 | [diff] [blame] | 248 | int rc = 0; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 249 | |
Balamurugan Thanikachalam | 930f9ae | 2017-07-11 14:42:21 +0530 | [diff] [blame] | 250 | if (!on) { |
| 251 | /* Send Display OFF hint to perf HAL */ |
| 252 | perf_hint_enable(VENDOR_HINT_DISPLAY_OFF, 0); |
| 253 | } else { |
| 254 | /* Send Display ON hint to perf HAL */ |
| 255 | perf_hint_enable(VENDOR_HINT_DISPLAY_ON, 0); |
| 256 | } |
| 257 | |
Anurag Singh | 057806b | 2013-04-16 16:53:45 -0700 | [diff] [blame] | 258 | if (set_interactive_override(module, on) == HINT_HANDLED) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 259 | return; |
| 260 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 261 | |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 262 | ALOGI("Got set_interactive hint"); |
Anurag Singh | fe93c1d | 2012-11-21 15:15:56 -0800 | [diff] [blame] | 263 | |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 264 | if (get_scaling_governor(governor, sizeof(governor)) == -1) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 265 | ALOGE("Can't obtain scaling governor."); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 266 | |
| 267 | return; |
| 268 | } |
| 269 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 270 | if (!on) { |
| 271 | /* Display off. */ |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 272 | if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) && |
| 273 | (strlen(governor) == strlen(ONDEMAND_GOVERNOR))) { |
Vince Leung | f72adfb | 2013-05-03 15:13:29 -0700 | [diff] [blame] | 274 | int resource_values[] = {DISPLAY_OFF, MS_500, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 10918c1 | 2012-11-09 17:35:20 -0800 | [diff] [blame] | 275 | |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 276 | if (!display_hint_sent) { |
| 277 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 278 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 279 | display_hint_sent = 1; |
| 280 | } |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 281 | } else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 282 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
Dilip Gudlur | 2eae266 | 2014-02-25 12:32:37 -0800 | [diff] [blame] | 283 | int resource_values[] = {TR_MS_50, THREAD_MIGRATION_SYNC_OFF}; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 284 | |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 285 | if (!display_hint_sent) { |
| 286 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 287 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 288 | display_hint_sent = 1; |
| 289 | } |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 290 | } else if ((strncmp(governor, MSMDCVS_GOVERNOR, strlen(MSMDCVS_GOVERNOR)) == 0) && |
| 291 | (strlen(governor) == strlen(MSMDCVS_GOVERNOR))) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 292 | if (saved_interactive_mode == 1){ |
| 293 | /* Display turned off. */ |
| 294 | if (sysfs_read(DCVS_CPU0_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 295 | if (!slack_node_rw_failed) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 296 | ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MAX_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 300 | } else { |
| 301 | saved_dcvs_cpu0_slack_max = atoi(tmp_str); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 302 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 303 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 304 | if (sysfs_read(DCVS_CPU0_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 305 | if (!slack_node_rw_failed) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 306 | ALOGE("Failed to read from %s", DCVS_CPU0_SLACK_MIN_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 310 | } else { |
| 311 | saved_dcvs_cpu0_slack_min = atoi(tmp_str); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 312 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 313 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 314 | if (sysfs_read(MPDECISION_SLACK_MAX_NODE, tmp_str, NODE_MAX - 1)) { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 315 | if (!slack_node_rw_failed) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 316 | ALOGE("Failed to read from %s", MPDECISION_SLACK_MAX_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 320 | } else { |
| 321 | saved_mpdecision_slack_max = atoi(tmp_str); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 324 | if (sysfs_read(MPDECISION_SLACK_MIN_NODE, tmp_str, NODE_MAX - 1)) { |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 325 | if(!slack_node_rw_failed) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 326 | ALOGE("Failed to read from %s", MPDECISION_SLACK_MIN_NODE); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | rc = 1; |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 330 | } else { |
| 331 | saved_mpdecision_slack_min = atoi(tmp_str); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 332 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 333 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 334 | /* Write new values. */ |
| 335 | if (saved_dcvs_cpu0_slack_max != -1) { |
| 336 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_max); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 337 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 338 | if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) { |
| 339 | if (!slack_node_rw_failed) { |
| 340 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE); |
| 341 | } |
| 342 | |
| 343 | rc = 1; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 344 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 345 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 346 | |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 347 | if (saved_dcvs_cpu0_slack_min != -1) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 348 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_dcvs_cpu0_slack_min); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 349 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 350 | if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) { |
| 351 | if(!slack_node_rw_failed) { |
| 352 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE); |
| 353 | } |
| 354 | |
| 355 | rc = 1; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 356 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 357 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 358 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 359 | if (saved_mpdecision_slack_max != -1) { |
| 360 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_max); |
| 361 | |
| 362 | if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) { |
| 363 | if(!slack_node_rw_failed) { |
| 364 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE); |
| 365 | } |
| 366 | |
| 367 | rc = 1; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | if (saved_mpdecision_slack_min != -1) { |
| 372 | snprintf(tmp_str, NODE_MAX, "%d", 10 * saved_mpdecision_slack_min); |
| 373 | |
| 374 | if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) { |
| 375 | if(!slack_node_rw_failed) { |
| 376 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE); |
| 377 | } |
| 378 | |
| 379 | rc = 1; |
| 380 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 381 | } |
| 382 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 383 | |
| 384 | slack_node_rw_failed = rc; |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 385 | } |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 386 | } else { |
| 387 | /* Display on. */ |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 388 | if ((strncmp(governor, ONDEMAND_GOVERNOR, strlen(ONDEMAND_GOVERNOR)) == 0) && |
| 389 | (strlen(governor) == strlen(ONDEMAND_GOVERNOR))) { |
Anurag Singh | 10918c1 | 2012-11-09 17:35:20 -0800 | [diff] [blame] | 390 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 391 | display_hint_sent = 0; |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 392 | } else if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 393 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 394 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
Anurag Singh | b15323a | 2013-06-08 16:55:44 -0700 | [diff] [blame] | 395 | display_hint_sent = 0; |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 396 | } else if ((strncmp(governor, MSMDCVS_GOVERNOR, strlen(MSMDCVS_GOVERNOR)) == 0) && |
| 397 | (strlen(governor) == strlen(MSMDCVS_GOVERNOR))) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 398 | if (saved_interactive_mode == -1 || saved_interactive_mode == 0) { |
| 399 | /* Display turned on. Restore if possible. */ |
| 400 | if (saved_dcvs_cpu0_slack_max != -1) { |
| 401 | snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_max); |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 402 | |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 403 | if (sysfs_write(DCVS_CPU0_SLACK_MAX_NODE, tmp_str) != 0) { |
| 404 | if (!slack_node_rw_failed) { |
| 405 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MAX_NODE); |
| 406 | } |
| 407 | |
| 408 | rc = 1; |
| 409 | } |
| 410 | } |
| 411 | |
Anurag Singh | 4ce3b94 | 2012-12-14 10:23:03 -0800 | [diff] [blame] | 412 | if (saved_dcvs_cpu0_slack_min != -1) { |
Anurag Singh | 6ec1206 | 2012-10-02 09:59:01 -0700 | [diff] [blame] | 413 | snprintf(tmp_str, NODE_MAX, "%d", saved_dcvs_cpu0_slack_min); |
| 414 | |
| 415 | if (sysfs_write(DCVS_CPU0_SLACK_MIN_NODE, tmp_str) != 0) { |
| 416 | if (!slack_node_rw_failed) { |
| 417 | ALOGE("Failed to write to %s", DCVS_CPU0_SLACK_MIN_NODE); |
| 418 | } |
| 419 | |
| 420 | rc = 1; |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | if (saved_mpdecision_slack_max != -1) { |
| 425 | snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_max); |
| 426 | |
| 427 | if (sysfs_write(MPDECISION_SLACK_MAX_NODE, tmp_str) != 0) { |
| 428 | if (!slack_node_rw_failed) { |
| 429 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MAX_NODE); |
| 430 | } |
| 431 | |
| 432 | rc = 1; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (saved_mpdecision_slack_min != -1) { |
| 437 | snprintf(tmp_str, NODE_MAX, "%d", saved_mpdecision_slack_min); |
| 438 | |
| 439 | if (sysfs_write(MPDECISION_SLACK_MIN_NODE, tmp_str) != 0) { |
| 440 | if (!slack_node_rw_failed) { |
| 441 | ALOGE("Failed to write to %s", MPDECISION_SLACK_MIN_NODE); |
| 442 | } |
| 443 | |
| 444 | rc = 1; |
| 445 | } |
| 446 | } |
| 447 | } |
| 448 | |
| 449 | slack_node_rw_failed = rc; |
| 450 | } |
Anurag Singh | 6f64e9f | 2012-10-09 16:08:38 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | saved_interactive_mode = !!on; |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 454 | } |
| 455 | |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame^] | 456 | static void set_feature(struct power_module *module, feature_t feature, int state) |
| 457 | { |
| 458 | switch (feature) { |
| 459 | #ifdef TAP_TO_WAKE_NODE |
| 460 | case POWER_FEATURE_DOUBLE_TAP_TO_WAKE: |
| 461 | sysfs_write(TAP_TO_WAKE_NODE, state ? "1" : "0"); |
| 462 | break; |
| 463 | #endif |
| 464 | default: |
| 465 | break; |
| 466 | } |
| 467 | } |
| 468 | |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 469 | static int power_device_open(const hw_module_t* module, const char* name, |
| 470 | hw_device_t** device) |
| 471 | { |
| 472 | int status = -EINVAL; |
| 473 | if (module && name && device) { |
| 474 | if (!strcmp(name, POWER_HARDWARE_MODULE_ID)) { |
| 475 | power_module_t *dev = (power_module_t *)malloc(sizeof(*dev)); |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 476 | |
| 477 | if(dev) { |
Ananth Raghavan Subramanian | d427e35 | 2017-07-19 20:26:49 -0700 | [diff] [blame] | 478 | memset(dev, 0, sizeof(*dev)); |
| 479 | |
| 480 | if(dev) { |
| 481 | /* initialize the fields */ |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame^] | 482 | dev->common.module_api_version = POWER_MODULE_API_VERSION_0_3; |
Ananth Raghavan Subramanian | d427e35 | 2017-07-19 20:26:49 -0700 | [diff] [blame] | 483 | dev->common.tag = HARDWARE_DEVICE_TAG; |
| 484 | dev->init = power_init; |
| 485 | dev->powerHint = power_hint; |
| 486 | dev->setInteractive = set_interactive; |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame^] | 487 | /* At the moment we support 0.3 APIs */ |
| 488 | dev->setFeature = set_feature, |
Ananth Raghavan Subramanian | d427e35 | 2017-07-19 20:26:49 -0700 | [diff] [blame] | 489 | dev->get_number_of_platform_modes = NULL, |
| 490 | dev->get_platform_low_power_stats = NULL, |
| 491 | dev->get_voter_list = NULL, |
| 492 | *device = (hw_device_t*)dev; |
| 493 | status = 0; |
| 494 | } else { |
| 495 | status = -ENOMEM; |
| 496 | } |
| 497 | } |
| 498 | else { |
Ananth Raghavan Subramanian | 65a6a06 | 2017-03-21 16:26:20 -0700 | [diff] [blame] | 499 | status = -ENOMEM; |
| 500 | } |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | return status; |
| 505 | } |
| 506 | |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 507 | struct power_module HAL_MODULE_INFO_SYM = { |
| 508 | .common = { |
| 509 | .tag = HARDWARE_MODULE_TAG, |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame^] | 510 | .module_api_version = POWER_MODULE_API_VERSION_0_3, |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 511 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
| 512 | .id = POWER_HARDWARE_MODULE_ID, |
| 513 | .name = "QCOM Power HAL", |
| 514 | .author = "Qualcomm", |
| 515 | .methods = &power_module_methods, |
| 516 | }, |
| 517 | |
| 518 | .init = power_init, |
| 519 | .powerHint = power_hint, |
| 520 | .setInteractive = set_interactive, |
Steve Kondik | e4f15bd | 2015-10-19 14:43:39 -0700 | [diff] [blame^] | 521 | .setFeature = set_feature, |
Anurag Singh | 9cec85b | 2012-09-04 21:46:24 -0700 | [diff] [blame] | 522 | }; |