blob: 09df94189de5ccb413e9b7b1abc0a2f4cff18494 [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 +053056pthread_mutex_t camera_hint_mutex = PTHREAD_MUTEX_INITIALIZER;
57static int camera_hint_ref_count;
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +053058static void process_video_encode_hint(void *metadata);
Panwar Viveka9345d12016-04-27 18:01:20 +053059//static void process_cam_preview_hint(void *metadata);
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053060
61int power_hint_override(struct power_module *module, power_hint_t hint,
62 void *data)
63{
64
65 switch(hint) {
66 case POWER_HINT_VSYNC:
67 break;
68 case POWER_HINT_VIDEO_ENCODE:
69 {
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +053070 process_video_encode_hint(data);
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053071 return HINT_HANDLED;
72 }
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +053073 }
74 return HINT_NONE;
75}
76
77int set_interactive_override(struct power_module *module, int on)
78{
79 char governor[80];
80 char tmp_str[NODE_MAX];
81 struct video_encode_metadata_t video_encode_metadata;
82 int rc;
83
84 ALOGI("Got set_interactive hint");
85
86 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU0) == -1) {
87 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU1) == -1) {
88 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU2) == -1) {
89 if (get_scaling_governor_check_cores(governor, sizeof(governor),CPU3) == -1) {
90 ALOGE("Can't obtain scaling governor.");
91 return HINT_HANDLED;
92 }
93 }
94 }
95 }
96
97 if (!on) {
98 /* Display off. */
99 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
100 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
101 /* timer rate - 40mS*/
102 int resource_values[] = {0x41424000, 0x28,
103 };
104 if (!display_hint_sent) {
105 perform_hint_action(DISPLAY_STATE_HINT_ID,
106 resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
107 display_hint_sent = 1;
108 }
109 } /* Perf time rate set for CORE0,CORE4 8952 target*/
110
111 } else {
112 /* Display on. */
113 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
114 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
115
116 undo_hint_action(DISPLAY_STATE_HINT_ID);
117 display_hint_sent = 0;
118 }
119 }
120 saved_interactive_mode = !!on;
121 return HINT_HANDLED;
122}
123
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +0530124
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530125/* Video Encode Hint */
126static void process_video_encode_hint(void *metadata)
127{
128 char governor[80];
129 struct video_encode_metadata_t video_encode_metadata;
130
131 ALOGI("Got process_video_encode_hint");
132
133 if (get_scaling_governor_check_cores(governor,
134 sizeof(governor),CPU0) == -1) {
135 if (get_scaling_governor_check_cores(governor,
136 sizeof(governor),CPU1) == -1) {
137 if (get_scaling_governor_check_cores(governor,
138 sizeof(governor),CPU2) == -1) {
139 if (get_scaling_governor_check_cores(governor,
140 sizeof(governor),CPU3) == -1) {
141 ALOGE("Can't obtain scaling governor.");
Nikhil Kumar Kansaldeb9eb12016-08-11 11:45:40 +0530142 // return HINT_HANDLED;
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530143 }
144 }
145 }
146 }
147
148 /* Initialize encode metadata struct fields. */
149 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
150 video_encode_metadata.state = -1;
151 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
152
153 if (metadata) {
154 if (parse_video_encode_metadata((char *)metadata,
155 &video_encode_metadata) == -1) {
156 ALOGE("Error occurred while parsing metadata.");
157 return;
158 }
159 } else {
160 return;
161 }
162
163 if (video_encode_metadata.state == 1) {
164 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
165 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
166 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
167 /* Sched_load and migration_notification disable
168 * timer rate - 40mS*/
169 int resource_values[] = {0x41430000, 0x1,
170 0x41434000, 0x1,
171 0x41424000, 0x28,
172 };
Nikhil Kumar Kansal0f325ef2016-11-24 20:12:16 +0530173 pthread_mutex_lock(&camera_hint_mutex);
174 camera_hint_ref_count++;
175 if (camera_hint_ref_count == 1) {
176 if (!video_encode_hint_sent) {
177 perform_hint_action(video_encode_metadata.hint_id,
178 resource_values,
179 sizeof(resource_values)/sizeof(resource_values[0]));
180 video_encode_hint_sent = 1;
181 }
182 }
183 pthread_mutex_unlock(&camera_hint_mutex);
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530184 }
185 } else if (video_encode_metadata.state == 0) {
186 if ((strncmp(governor, INTERACTIVE_GOVERNOR,
187 strlen(INTERACTIVE_GOVERNOR)) == 0) &&
188 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
Nikhil Kumar Kansal0f325ef2016-11-24 20:12:16 +0530189 pthread_mutex_lock(&camera_hint_mutex);
190 camera_hint_ref_count--;
191 if (!camera_hint_ref_count) {
192 undo_hint_action(video_encode_metadata.hint_id);
193 video_encode_hint_sent = 0;
194 }
195 pthread_mutex_unlock(&camera_hint_mutex);
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530196 return ;
197 }
198 }
199 return;
200}
201
Sravan Kumar Ambapurameea8e562016-02-28 15:09:37 +0530202