blob: 304eaffa51bbad37962f7154cda73d0171083a37 [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
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053058static int camera_hint_ref_count;
59static void process_video_encode_hint(void *metadata);
60//static void process_cam_preview_hint(void *metadata);
61
62static 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-Tawaba2a70712017-12-31 01:21:40 +020083int power_hint_override(power_hint_t hint, void *data)
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053084{
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-Tawaba2a70712017-12-31 01:21:40 +020098int set_interactive_override(int on)
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053099{
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. */
122 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
123 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
124 /*
125 1. CPUfreq params
126 - hispeed freq for big - 1113Mhz
127 - go hispeed load for big - 95
128 - above_hispeed_delay for big - 40ms
129 2. BusDCVS V2 params
130 - Sample_ms of 10ms
131 */
132 if(is_target_SDM630()){
133 int res[] = { 0x41414000, 0x459,
134 0x41410000, 0x5F,
135 0x41400000, 0x4,
136 0x41820000, 0xA };
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530137 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530138 num_resources = sizeof(res)/sizeof(res[0]);
139 }
140 /*
141 1. CPUfreq params
142 - hispeed freq for little - 902Mhz
143 - go hispeed load for little - 95
144 - above_hispeed_delay for little - 40ms
145 2. BusDCVS V2 params
146 - Sample_ms of 10ms
147 3. Sched group upmigrate - 500
148 */
149 else{
150 int res[] = { 0x41414100, 0x386,
151 0x41410100, 0x5F,
152 0x41400100, 0x4,
153 0x41820000, 0xA,
154 0x40C54000, 0x1F4};
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530155 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530156 num_resources = sizeof(res)/sizeof(res[0]);
157
158 }
159 if (!display_hint_sent) {
160 perform_hint_action(DISPLAY_STATE_HINT_ID,
161 resource_values, num_resources);
162 display_hint_sent = 1;
163 }
164 }
165
166 } else {
167 /* Display on. */
168 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
169 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
170
171 undo_hint_action(DISPLAY_STATE_HINT_ID);
172 display_hint_sent = 0;
173 }
174 }
175 saved_interactive_mode = !!on;
176 return HINT_HANDLED;
177}
178
179
180/* Video Encode Hint */
181static void process_video_encode_hint(void *metadata)
182{
183 char governor[80];
184 int resource_values[20];
185 int num_resources;
186 struct video_encode_metadata_t video_encode_metadata;
187
188 ALOGI("Got process_video_encode_hint");
189
190 if (get_scaling_governor_check_cores(governor,
191 sizeof(governor),CPU0) == -1) {
192 if (get_scaling_governor_check_cores(governor,
193 sizeof(governor),CPU1) == -1) {
194 if (get_scaling_governor_check_cores(governor,
195 sizeof(governor),CPU2) == -1) {
196 if (get_scaling_governor_check_cores(governor,
197 sizeof(governor),CPU3) == -1) {
198 ALOGE("Can't obtain scaling governor.");
199 // return HINT_HANDLED;
200 }
201 }
202 }
203 }
204
205 /* Initialize encode metadata struct fields. */
206 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
207 video_encode_metadata.state = -1;
208 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
209
210 if (metadata) {
211 if (parse_video_encode_metadata((char *)metadata,
212 &video_encode_metadata) == -1) {
213 ALOGE("Error occurred while parsing metadata.");
214 return;
215 }
216 } else {
217 return;
218 }
219
220 if (video_encode_metadata.state == 1) {
221 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
222 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
223 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
224 /*
225 1. CPUfreq params
226 - hispeed freq for big - 1113Mhz
227 - go hispeed load for big - 95
228 - above_hispeed_delay for big - 40ms
Nikhil Kumar Kansala044cf32017-04-24 16:11:37 +0530229 - target loads - 95
230 - nr_run - 5
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530231 2. BusDCVS V2 params
232 - Sample_ms of 10ms
233 */
234 if(is_target_SDM630()){
235 int res[] = { 0x41414000, 0x459,
236 0x41410000, 0x5F,
237 0x41400000, 0x4,
Nikhil Kumar Kansala044cf32017-04-24 16:11:37 +0530238 0x41420000, 0x5F,
239 0x40C2C000, 0X5,
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 }
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530261 camera_hint_ref_count++;
262 if (camera_hint_ref_count == 1) {
263 if (!video_encode_hint_sent) {
264 perform_hint_action(video_encode_metadata.hint_id,
265 resource_values, num_resources);
266 video_encode_hint_sent = 1;
267 }
268 }
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530269 }
270 } else if (video_encode_metadata.state == 0) {
271 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
272 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
273 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530274 camera_hint_ref_count--;
275 if (!camera_hint_ref_count) {
276 undo_hint_action(video_encode_metadata.hint_id);
277 video_encode_hint_sent = 0;
278 }
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530279 return ;
280 }
281 }
282 return;
283}
284
285