blob: 67ca07ee2db15c2fff3fc35b6a1850b6f1bbef3e [file] [log] [blame]
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +05301/*
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
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
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +053051#define MIN_VAL(X,Y) ((X>Y)?(Y):(X))
52
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053053static int saved_interactive_mode = -1;
54static int display_hint_sent;
55static int video_encode_hint_sent;
56static int cam_preview_hint_sent;
57
58pthread_mutex_t camera_hint_mutex = PTHREAD_MUTEX_INITIALIZER;
59static int camera_hint_ref_count;
60static void process_video_encode_hint(void *metadata);
61//static void process_cam_preview_hint(void *metadata);
62
63static bool is_target_SDM630() /* Returns value=630 if target is SDM630 else value 0 */
64{
65 int fd;
66 bool is_target_SDM630=false;
67 char buf[10] = {0};
68 fd = open("/sys/devices/soc0/soc_id", O_RDONLY);
69 if (fd >= 0) {
70 if (read(fd, buf, sizeof(buf) - 1) == -1) {
71 ALOGW("Unable to read soc_id");
72 is_target_SDM630 = false;
73 } else {
74 int soc_id = atoi(buf);
75 if (soc_id == 318 || soc_id== 327) {
76 is_target_SDM630 = true; /* Above SOCID for SDM630 */
77 }
78 }
79 }
80 close(fd);
81 return is_target_SDM630;
82}
83
84int power_hint_override(struct power_module *module, power_hint_t hint,
85 void *data)
86{
87
88 switch(hint) {
89 case POWER_HINT_VSYNC:
90 break;
91 case POWER_HINT_VIDEO_ENCODE:
92 {
93 process_video_encode_hint(data);
94 return HINT_HANDLED;
95 }
96 }
97 return HINT_NONE;
98}
99
100int set_interactive_override(struct power_module *module, int on)
101{
102 char governor[80];
103 char tmp_str[NODE_MAX];
104 int resource_values[20];
105 int num_resources;
106 struct video_encode_metadata_t video_encode_metadata;
107 int rc;
108
109 ALOGI("Got set_interactive hint");
110
111 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU0) == -1) {
112 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU1) == -1) {
113 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU2) == -1) {
114 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU3) == -1) {
115 ALOGE("Can't obtain scaling governor.");
116 return HINT_HANDLED;
117 }
118 }
119 }
120 }
121
122 if (!on) {
123 /* Display off. */
124 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
125 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
126 /*
127 1. CPUfreq params
128 - hispeed freq for big - 1113Mhz
129 - go hispeed load for big - 95
130 - above_hispeed_delay for big - 40ms
131 2. BusDCVS V2 params
132 - Sample_ms of 10ms
133 */
134 if(is_target_SDM630()){
135 int res[] = { 0x41414000, 0x459,
136 0x41410000, 0x5F,
137 0x41400000, 0x4,
138 0x41820000, 0xA };
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530139 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530140 num_resources = sizeof(res)/sizeof(res[0]);
141 }
142 /*
143 1. CPUfreq params
144 - hispeed freq for little - 902Mhz
145 - go hispeed load for little - 95
146 - above_hispeed_delay for little - 40ms
147 2. BusDCVS V2 params
148 - Sample_ms of 10ms
149 3. Sched group upmigrate - 500
150 */
151 else{
152 int res[] = { 0x41414100, 0x386,
153 0x41410100, 0x5F,
154 0x41400100, 0x4,
155 0x41820000, 0xA,
156 0x40C54000, 0x1F4};
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530157 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530158 num_resources = sizeof(res)/sizeof(res[0]);
159
160 }
161 if (!display_hint_sent) {
162 perform_hint_action(DISPLAY_STATE_HINT_ID,
163 resource_values, num_resources);
164 display_hint_sent = 1;
165 }
166 }
167
168 } else {
169 /* Display on. */
170 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
171 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
172
173 undo_hint_action(DISPLAY_STATE_HINT_ID);
174 display_hint_sent = 0;
175 }
176 }
177 saved_interactive_mode = !!on;
178 return HINT_HANDLED;
179}
180
181
182/* Video Encode Hint */
183static void process_video_encode_hint(void *metadata)
184{
185 char governor[80];
186 int resource_values[20];
187 int num_resources;
188 struct video_encode_metadata_t video_encode_metadata;
189
190 ALOGI("Got process_video_encode_hint");
191
192 if (get_scaling_governor_check_cores(governor,
193 sizeof(governor),CPU0) == -1) {
194 if (get_scaling_governor_check_cores(governor,
195 sizeof(governor),CPU1) == -1) {
196 if (get_scaling_governor_check_cores(governor,
197 sizeof(governor),CPU2) == -1) {
198 if (get_scaling_governor_check_cores(governor,
199 sizeof(governor),CPU3) == -1) {
200 ALOGE("Can't obtain scaling governor.");
201 // return HINT_HANDLED;
202 }
203 }
204 }
205 }
206
207 /* Initialize encode metadata struct fields. */
208 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
209 video_encode_metadata.state = -1;
210 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
211
212 if (metadata) {
213 if (parse_video_encode_metadata((char *)metadata,
214 &video_encode_metadata) == -1) {
215 ALOGE("Error occurred while parsing metadata.");
216 return;
217 }
218 } else {
219 return;
220 }
221
222 if (video_encode_metadata.state == 1) {
223 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
224 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
225 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
226 /*
227 1. CPUfreq params
228 - hispeed freq for big - 1113Mhz
229 - go hispeed load for big - 95
230 - above_hispeed_delay for big - 40ms
231 - target loads - 90
232 2. BusDCVS V2 params
233 - Sample_ms of 10ms
234 */
235 if(is_target_SDM630()){
236 int res[] = { 0x41414000, 0x459,
237 0x41410000, 0x5F,
238 0x41400000, 0x4,
239 0x41420000, 0x5A,
240 0x41820000, 0xA};;
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530241 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530242 num_resources = sizeof(res)/sizeof(res[0]);
243
244 }
245 /*
246 1. CPUfreq params
247 - hispeed freq for little - 902Mhz
248 - go hispeed load for little - 95
249 - above_hispeed_delay for little - 40ms
250 2. BusDCVS V2 params
251 - Sample_ms of 10ms
252 */
253 else{
254 int res[] = { 0x41414100, 0x386,
255 0x41410100, 0x5F,
256 0x41400100, 0x4,
257 0x41820000, 0xA};
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530258 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530259 num_resources = sizeof(res)/sizeof(res[0]);
260 }
261 pthread_mutex_lock(&camera_hint_mutex);
262 camera_hint_ref_count++;
263 if (camera_hint_ref_count == 1) {
264 if (!video_encode_hint_sent) {
265 perform_hint_action(video_encode_metadata.hint_id,
266 resource_values, num_resources);
267 video_encode_hint_sent = 1;
268 }
269 }
270 pthread_mutex_unlock(&camera_hint_mutex);
271 }
272 } else if (video_encode_metadata.state == 0) {
273 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
274 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
275 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
276 pthread_mutex_lock(&camera_hint_mutex);
277 camera_hint_ref_count--;
278 if (!camera_hint_ref_count) {
279 undo_hint_action(video_encode_metadata.hint_id);
280 video_encode_hint_sent = 0;
281 }
282 pthread_mutex_unlock(&camera_hint_mutex);
283 return ;
284 }
285 }
286 return;
287}
288
289