Sravan Kumar Ambapuram | eea8e56 | 2016-02-28 15:09:37 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 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 | static int saved_interactive_mode = -1; |
| 52 | static int display_hint_sent; |
| 53 | static int video_encode_hint_sent; |
| 54 | static int cam_preview_hint_sent; |
| 55 | |
| 56 | static void process_video_encode_hint(void *metadata); |
| 57 | static void process_cam_preview_hint(void *metadata); |
| 58 | |
| 59 | int power_hint_override(struct power_module *module, power_hint_t hint, |
| 60 | void *data) |
| 61 | { |
| 62 | |
| 63 | switch(hint) { |
| 64 | case POWER_HINT_VSYNC: |
| 65 | break; |
| 66 | case POWER_HINT_VIDEO_ENCODE: |
| 67 | { |
| 68 | process_video_encode_hint(data); |
| 69 | return HINT_HANDLED; |
| 70 | } |
| 71 | case POWER_HINT_CAM_PREVIEW: |
| 72 | { |
| 73 | process_cam_preview_hint(data); |
| 74 | return HINT_HANDLED; |
| 75 | } |
| 76 | } |
| 77 | return HINT_NONE; |
| 78 | } |
| 79 | |
| 80 | int set_interactive_override(struct power_module *module, int on) |
| 81 | { |
| 82 | char governor[80]; |
| 83 | char tmp_str[NODE_MAX]; |
| 84 | struct video_encode_metadata_t video_encode_metadata; |
| 85 | int rc; |
| 86 | |
| 87 | ALOGI("Got set_interactive hint"); |
| 88 | |
| 89 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU0) == -1) { |
| 90 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU1) == -1) { |
| 91 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU2) == -1) { |
| 92 | if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU3) == -1) { |
| 93 | ALOGE("Can't obtain scaling governor."); |
| 94 | return HINT_HANDLED; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (!on) { |
| 101 | /* Display off. */ |
| 102 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 103 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 104 | /* timer rate - 40mS*/ |
| 105 | int resource_values[] = {0x41424000, 0x28, |
| 106 | }; |
| 107 | if (!display_hint_sent) { |
| 108 | perform_hint_action(DISPLAY_STATE_HINT_ID, |
| 109 | resource_values, sizeof(resource_values)/sizeof(resource_values[0])); |
| 110 | display_hint_sent = 1; |
| 111 | } |
| 112 | } /* Perf time rate set for CORE0,CORE4 8952 target*/ |
| 113 | |
| 114 | } else { |
| 115 | /* Display on. */ |
| 116 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 117 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 118 | |
| 119 | undo_hint_action(DISPLAY_STATE_HINT_ID); |
| 120 | display_hint_sent = 0; |
| 121 | } |
| 122 | } |
| 123 | saved_interactive_mode = !!on; |
| 124 | return HINT_HANDLED; |
| 125 | } |
| 126 | |
| 127 | /* Video Encode Hint */ |
| 128 | static void process_video_encode_hint(void *metadata) |
| 129 | { |
| 130 | char governor[80]; |
| 131 | struct video_encode_metadata_t video_encode_metadata; |
| 132 | |
| 133 | ALOGI("Got process_video_encode_hint"); |
| 134 | |
| 135 | if (get_scaling_governor_check_cores(governor, |
| 136 | sizeof(governor),CPU0) == -1) { |
| 137 | if (get_scaling_governor_check_cores(governor, |
| 138 | sizeof(governor),CPU1) == -1) { |
| 139 | if (get_scaling_governor_check_cores(governor, |
| 140 | sizeof(governor),CPU2) == -1) { |
| 141 | if (get_scaling_governor_check_cores(governor, |
| 142 | sizeof(governor),CPU3) == -1) { |
| 143 | ALOGE("Can't obtain scaling governor."); |
| 144 | return HINT_HANDLED; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /* Initialize encode metadata struct fields. */ |
| 151 | memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t)); |
| 152 | video_encode_metadata.state = -1; |
| 153 | video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID; |
| 154 | |
| 155 | if (metadata) { |
| 156 | if (parse_video_encode_metadata((char *)metadata, |
| 157 | &video_encode_metadata) == -1) { |
| 158 | ALOGE("Error occurred while parsing metadata."); |
| 159 | return; |
| 160 | } |
| 161 | } else { |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | if (video_encode_metadata.state == 1) { |
| 166 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, |
| 167 | strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 168 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 169 | /* Sched_load and migration_notification disable |
| 170 | * timer rate - 40mS*/ |
| 171 | int resource_values[] = {0x41430000, 0x1, |
| 172 | 0x41434000, 0x1, |
| 173 | 0x41424000, 0x28, |
| 174 | }; |
| 175 | if (!video_encode_hint_sent) { |
| 176 | perform_hint_action(video_encode_metadata.hint_id, |
| 177 | resource_values, |
| 178 | sizeof(resource_values)/sizeof(resource_values[0])); |
| 179 | video_encode_hint_sent = 1; |
| 180 | } |
| 181 | } |
| 182 | } else if (video_encode_metadata.state == 0) { |
| 183 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, |
| 184 | strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 185 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 186 | undo_hint_action(video_encode_metadata.hint_id); |
| 187 | video_encode_hint_sent = 0; |
| 188 | return ; |
| 189 | } |
| 190 | } |
| 191 | return; |
| 192 | } |
| 193 | |
| 194 | /* Camera Preview Hint */ |
| 195 | static void process_cam_preview_hint(void *metadata) |
| 196 | { |
| 197 | char governor[80]; |
| 198 | struct cam_preview_metadata_t cam_preview_metadata; |
| 199 | ALOGI("Got process_video_encode_hint"); |
| 200 | |
| 201 | if (get_scaling_governor_check_cores(governor, |
| 202 | sizeof(governor),CPU0) == -1) { |
| 203 | if (get_scaling_governor_check_cores(governor, |
| 204 | sizeof(governor),CPU1) == -1) { |
| 205 | if (get_scaling_governor_check_cores(governor, |
| 206 | sizeof(governor),CPU2) == -1) { |
| 207 | if (get_scaling_governor_check_cores(governor, |
| 208 | sizeof(governor),CPU3) == -1) { |
| 209 | ALOGE("Can't obtain scaling governor."); |
| 210 | return HINT_HANDLED; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /* Initialize cam preveiw metadata struct fields. */ |
| 217 | memset(&cam_preview_metadata, 0, sizeof(struct cam_preview_metadata_t)); |
| 218 | cam_preview_metadata.state = -1; |
| 219 | cam_preview_metadata.hint_id = CAM_PREVIEW_HINT_ID; |
| 220 | |
| 221 | if (metadata) { |
| 222 | if (parse_cam_preview_metadata((char *)metadata, |
| 223 | &cam_preview_metadata) == -1) { |
| 224 | ALOGE("Error occurred while parsing metadata."); |
| 225 | return; |
| 226 | } |
| 227 | } else { |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | if (cam_preview_metadata.state == 1) { |
| 232 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, |
| 233 | strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 234 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 235 | /* Sched_load and migration_notification disable |
| 236 | * timer rate - 40mS*/ |
| 237 | int resource_values[] = {0x41430000, 0x1, |
| 238 | 0x41434000, 0x1, |
| 239 | 0x41424000, 0x28, |
| 240 | }; |
| 241 | if (!cam_preview_hint_sent) { |
| 242 | perform_hint_action(cam_preview_metadata.hint_id, |
| 243 | resource_values, |
| 244 | sizeof(resource_values)/sizeof(resource_values[0])); |
| 245 | cam_preview_hint_sent = 1; |
| 246 | } |
| 247 | } |
| 248 | } else if (cam_preview_metadata.state == 0) { |
| 249 | if ((strncmp(governor, INTERACTIVE_GOVERNOR, |
| 250 | strlen(INTERACTIVE_GOVERNOR)) == 0) && |
| 251 | (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) { |
| 252 | undo_hint_action(cam_preview_metadata.hint_id); |
| 253 | cam_preview_hint_sent = 0; |
| 254 | return ; |
| 255 | } |
| 256 | } |
| 257 | return; |
| 258 | } |
| 259 | |