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