Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, 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 | |
Michael Bestas | 1add9ac | 2018-03-25 22:56:44 +0300 | [diff] [blame] | 40 | #define LOG_TAG "QCOM PowerHAL" |
Ethan Chen | a42f4a8 | 2018-03-01 21:31:15 -0800 | [diff] [blame] | 41 | #include <log/log.h> |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 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 | |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 51 | #define MIN_VAL(X,Y) ((X>Y)?(Y):(X)) |
| 52 | |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 53 | static int saved_interactive_mode = -1; |
| 54 | static int display_hint_sent; |
| 55 | static int video_encode_hint_sent; |
| 56 | static int cam_preview_hint_sent; |
| 57 | |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 58 | static int camera_hint_ref_count; |
| 59 | static void process_video_encode_hint(void *metadata); |
| 60 | //static void process_cam_preview_hint(void *metadata); |
| 61 | |
| 62 | static bool is_target_SDM630() /* Returns value=630 if target is SDM630 else value 0 */ |
| 63 | { |
| 64 | int fd; |
| 65 | bool is_target_SDM630=false; |
| 66 | char buf[10] = {0}; |
| 67 | fd = open("/sys/devices/soc0/soc_id", O_RDONLY); |
| 68 | if (fd >= 0) { |
| 69 | if (read(fd, buf, sizeof(buf) - 1) == -1) { |
| 70 | ALOGW("Unable to read soc_id"); |
| 71 | is_target_SDM630 = false; |
| 72 | } else { |
| 73 | int soc_id = atoi(buf); |
| 74 | if (soc_id == 318 || soc_id== 327) { |
| 75 | is_target_SDM630 = true; /* Above SOCID for SDM630 */ |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 | close(fd); |
| 80 | return is_target_SDM630; |
| 81 | } |
| 82 | |
Rashed Abdel-Tawab | a2a7071 | 2017-12-31 01:21:40 +0200 | [diff] [blame] | 83 | int power_hint_override(power_hint_t hint, void *data) |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 84 | { |
| 85 | |
| 86 | switch(hint) { |
| 87 | case POWER_HINT_VSYNC: |
| 88 | break; |
| 89 | case POWER_HINT_VIDEO_ENCODE: |
| 90 | { |
| 91 | process_video_encode_hint(data); |
| 92 | return HINT_HANDLED; |
| 93 | } |
| 94 | } |
| 95 | return HINT_NONE; |
| 96 | } |
| 97 | |
Rashed Abdel-Tawab | a2a7071 | 2017-12-31 01:21:40 +0200 | [diff] [blame] | 98 | int set_interactive_override(int on) |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 99 | { |
| 100 | char governor[80]; |
| 101 | char tmp_str[NODE_MAX]; |
| 102 | int resource_values[20]; |
| 103 | int num_resources; |
| 104 | struct video_encode_metadata_t video_encode_metadata; |
| 105 | int rc; |
| 106 | |
| 107 | ALOGI("Got set_interactive hint"); |
| 108 | |
| 109 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU0) == -1) { |
| 110 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU1) == -1) { |
| 111 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU2) == -1) { |
| 112 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU3) == -1) { |
| 113 | ALOGE("Can't obtain scaling governor."); |
| 114 | return HINT_HANDLED; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (!on) { |
| 121 | /* Display off. */ |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 122 | if (is_interactive_governor(governor)) { |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 123 | /* |
| 124 | 1. CPUfreq params |
| 125 | - hispeed freq for big - 1113Mhz |
| 126 | - go hispeed load for big - 95 |
| 127 | - above_hispeed_delay for big - 40ms |
| 128 | 2. BusDCVS V2 params |
| 129 | - Sample_ms of 10ms |
| 130 | */ |
| 131 | if(is_target_SDM630()){ |
| 132 | int res[] = { 0x41414000, 0x459, |
| 133 | 0x41410000, 0x5F, |
| 134 | 0x41400000, 0x4, |
| 135 | 0x41820000, 0xA }; |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 136 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame^] | 137 | num_resources = ARRAY_SIZE(res); |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 138 | } |
| 139 | /* |
| 140 | 1. CPUfreq params |
| 141 | - hispeed freq for little - 902Mhz |
| 142 | - go hispeed load for little - 95 |
| 143 | - above_hispeed_delay for little - 40ms |
| 144 | 2. BusDCVS V2 params |
| 145 | - Sample_ms of 10ms |
| 146 | 3. Sched group upmigrate - 500 |
| 147 | */ |
| 148 | else{ |
| 149 | int res[] = { 0x41414100, 0x386, |
| 150 | 0x41410100, 0x5F, |
| 151 | 0x41400100, 0x4, |
| 152 | 0x41820000, 0xA, |
| 153 | 0x40C54000, 0x1F4}; |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 154 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame^] | 155 | num_resources = ARRAY_SIZE(res); |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 156 | |
| 157 | } |
| 158 | if (!display_hint_sent) { |
| 159 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 160 | resource_values, num_resources); |
| 161 | display_hint_sent = 1; |
| 162 | } |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 163 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 164 | } else { |
| 165 | /* Display on. */ |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 166 | if (is_interactive_governor(governor)) { |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 167 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
| 168 | display_hint_sent = 0; |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 169 | } |
| 170 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 171 | saved_interactive_mode = !!on; |
| 172 | return HINT_HANDLED; |
| 173 | } |
| 174 | |
| 175 | |
| 176 | /* Video Encode Hint */ |
| 177 | static void process_video_encode_hint(void *metadata) |
| 178 | { |
| 179 | char governor[80]; |
| 180 | int resource_values[20]; |
| 181 | int num_resources; |
| 182 | struct video_encode_metadata_t video_encode_metadata; |
| 183 | |
| 184 | ALOGI("Got process_video_encode_hint"); |
| 185 | |
| 186 | if (get_scaling_governor_check_cores(governor, |
| 187 | sizeof(governor),CPU0) == -1) { |
| 188 | if (get_scaling_governor_check_cores(governor, |
| 189 | sizeof(governor),CPU1) == -1) { |
| 190 | if (get_scaling_governor_check_cores(governor, |
| 191 | sizeof(governor),CPU2) == -1) { |
| 192 | if (get_scaling_governor_check_cores(governor, |
| 193 | sizeof(governor),CPU3) == -1) { |
| 194 | ALOGE("Can't obtain scaling governor."); |
| 195 | // return HINT_HANDLED; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /* Initialize encode metadata struct fields. */ |
| 202 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
| 203 | video_encode_metadata.state = -1; |
| 204 | video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID; |
| 205 | |
| 206 | if (metadata) { |
| 207 | if (parse_video_encode_metadata((char *)metadata, |
| 208 | &video_encode_metadata) == -1) { |
| 209 | ALOGE("Error occurred while parsing metadata."); |
| 210 | return; |
| 211 | } |
| 212 | } else { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | if (video_encode_metadata.state == 1) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 217 | if (is_interactive_governor(governor)) { |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 218 | /* |
| 219 | 1. CPUfreq params |
| 220 | - hispeed freq for big - 1113Mhz |
| 221 | - go hispeed load for big - 95 |
| 222 | - above_hispeed_delay for big - 40ms |
Nikhil Kumar Kansal | a044cf3 | 2017-04-24 16:11:37 +0530 | [diff] [blame] | 223 | - target loads - 95 |
| 224 | - nr_run - 5 |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 225 | 2. BusDCVS V2 params |
| 226 | - Sample_ms of 10ms |
| 227 | */ |
| 228 | if(is_target_SDM630()){ |
| 229 | int res[] = { 0x41414000, 0x459, |
| 230 | 0x41410000, 0x5F, |
| 231 | 0x41400000, 0x4, |
Nikhil Kumar Kansal | a044cf3 | 2017-04-24 16:11:37 +0530 | [diff] [blame] | 232 | 0x41420000, 0x5F, |
| 233 | 0x40C2C000, 0X5, |
| 234 | 0x41820000, 0xA}; |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 235 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame^] | 236 | num_resources = ARRAY_SIZE(res); |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 237 | |
| 238 | } |
| 239 | /* |
| 240 | 1. CPUfreq params |
| 241 | - hispeed freq for little - 902Mhz |
| 242 | - go hispeed load for little - 95 |
| 243 | - above_hispeed_delay for little - 40ms |
| 244 | 2. BusDCVS V2 params |
| 245 | - Sample_ms of 10ms |
| 246 | */ |
| 247 | else{ |
| 248 | int res[] = { 0x41414100, 0x386, |
| 249 | 0x41410100, 0x5F, |
| 250 | 0x41400100, 0x4, |
| 251 | 0x41820000, 0xA}; |
Nikhil Kumar Kansal | 839d56f | 2017-04-18 15:50:25 +0530 | [diff] [blame] | 252 | memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res))); |
Zhao Wei Liew | d4fe61e | 2016-06-26 11:37:59 +0800 | [diff] [blame^] | 253 | num_resources = ARRAY_SIZE(res); |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 254 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 255 | camera_hint_ref_count++; |
| 256 | if (camera_hint_ref_count == 1) { |
| 257 | if (!video_encode_hint_sent) { |
| 258 | perform_hint_action(video_encode_metadata.hint_id, |
| 259 | resource_values, num_resources); |
| 260 | video_encode_hint_sent = 1; |
| 261 | } |
| 262 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 263 | } |
| 264 | } else if (video_encode_metadata.state == 0) { |
Ethan Chen | 4b4acdf | 2018-03-01 21:41:04 -0800 | [diff] [blame] | 265 | if (is_interactive_governor(governor)) { |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 266 | camera_hint_ref_count--; |
| 267 | if (!camera_hint_ref_count) { |
| 268 | undo_hint_action(video_encode_metadata.hint_id); |
| 269 | video_encode_hint_sent = 0; |
| 270 | } |
Vara Prasad A V S G | 9b7a758 | 2017-04-07 17:32:37 +0530 | [diff] [blame] | 271 | return ; |
| 272 | } |
| 273 | } |
| 274 | return; |
| 275 | } |
| 276 | |
| 277 | |