blob: 1cda9c385f4eb02dfabe1bda1f4534cf38fa0901 [file] [log] [blame]
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +05301/*
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
51static int saved_interactive_mode = -1;
52static int display_hint_sent;
53static int video_encode_hint_sent;
54static int cam_preview_hint_sent;
55
Nikhil Kumar Kansal0f325ef2016-11-24 20:12:16 +053056static int camera_hint_ref_count;
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +053057static void process_video_encode_hint(void *metadata);
Panwar Viveka9345d12016-04-27 18:01:20 +053058//static void process_cam_preview_hint(void *metadata);
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053059
Rashed Abdel-Tawaba2a70712017-12-31 01:21:40 +020060int power_hint_override(power_hint_t hint, void *data)
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053061{
62
63 switch(hint) {
64 case POWER_HINT_VSYNC:
65 break;
66 case POWER_HINT_VIDEO_ENCODE:
67 {
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +053068 process_video_encode_hint(data);
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053069 return HINT_HANDLED;
70 }
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053071 }
72 return HINT_NONE;
73}
74
Rashed Abdel-Tawaba2a70712017-12-31 01:21:40 +020075int set_interactive_override(int on)
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053076{
77 char governor[80];
78 char tmp_str[NODE_MAX];
79 struct video_encode_metadata_t video_encode_metadata;
80 int rc;
81
82 ALOGI("Got set_interactive hint");
83
84 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU0) == -1) {
85 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU1) == -1) {
86 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU2) == -1) {
87 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU3) == -1) {
88 ALOGE("Can't obtain scaling governor.");
89 return HINT_HANDLED;
90 }
91 }
92 }
93 }
94
95 if (!on) {
96 /* Display off. */
97 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
98 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
99 /* timer rate - 40mS*/
100 int resource_values[] = {0x41424000, 0x28,
101 };
102 if (!display_hint_sent) {
103 perform_hint_action(DISPLAY_STATE_HINT_ID,
104 resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
105 display_hint_sent = 1;
106 }
107 } /* Perf time rate set for CORE0,CORE4 8952 target*/
108
109 } else {
110 /* Display on. */
111 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
112 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
113
114 undo_hint_action(DISPLAY_STATE_HINT_ID);
115 display_hint_sent = 0;
116 }
117 }
118 saved_interactive_mode = !!on;
119 return HINT_HANDLED;
120}
121
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +0530122
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530123/* Video Encode Hint */
124static void process_video_encode_hint(void *metadata)
125{
126 char governor[80];
127 struct video_encode_metadata_t video_encode_metadata;
128
129 ALOGI("Got process_video_encode_hint");
130
131 if (get_scaling_governor_check_cores(governor,
132 sizeof(governor),CPU0) == -1) {
133 if (get_scaling_governor_check_cores(governor,
134 sizeof(governor),CPU1) == -1) {
135 if (get_scaling_governor_check_cores(governor,
136 sizeof(governor),CPU2) == -1) {
137 if (get_scaling_governor_check_cores(governor,
138 sizeof(governor),CPU3) == -1) {
139 ALOGE("Can't obtain scaling governor.");
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +0530140 // return HINT_HANDLED;
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530141 }
142 }
143 }
144 }
145
146 /* Initialize encode metadata struct fields. */
147 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
148 video_encode_metadata.state = -1;
149 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
150
151 if (metadata) {
152 if (parse_video_encode_metadata((char *)metadata,
153 &video_encode_metadata) == -1) {
154 ALOGE("Error occurred while parsing metadata.");
155 return;
156 }
157 } else {
158 return;
159 }
160
161 if (video_encode_metadata.state == 1) {
162 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
163 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
164 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
165 /* Sched_load and migration_notification disable
166 * timer rate - 40mS*/
167 int resource_values[] = {0x41430000, 0x1,
168 0x41434000, 0x1,
169 0x41424000, 0x28,
170 };
Nikhil Kumar Kansal0f325ef2016-11-24 20:12:16 +0530171 camera_hint_ref_count++;
172 if (camera_hint_ref_count == 1) {
173 if (!video_encode_hint_sent) {
174 perform_hint_action(video_encode_metadata.hint_id,
175 resource_values,
176 sizeof(resource_values)/sizeof(resource_values[0]));
177 video_encode_hint_sent = 1;
178 }
179 }
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530180 }
181 } else if (video_encode_metadata.state == 0) {
182 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
183 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
184 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
Nikhil Kumar Kansal0f325ef2016-11-24 20:12:16 +0530185 camera_hint_ref_count--;
186 if (!camera_hint_ref_count) {
187 undo_hint_action(video_encode_metadata.hint_id);
188 video_encode_hint_sent = 0;
189 }
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530190 return ;
191 }
192 }
193 return;
194}
195
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530196