blob: 0b1c3629cf8f8f441a1490d757297d9f694a92cc [file] [log] [blame]
David Ngee7c4c52018-03-22 23:49:12 -07001/*
2 * Copyright (c) 2015-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#define LOG_NIDEBUG 0
30
31#include <errno.h>
32#include <string.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <fcntl.h>
36#include <dlfcn.h>
37#include <stdlib.h>
38
39#define LOG_TAG "QTI PowerHAL"
40#include <utils/Log.h>
41#include <hardware/hardware.h>
42#include <hardware/power.h>
43
44#include "utils.h"
45#include "metadata-defs.h"
46#include "hint-data.h"
47#include "performance.h"
48#include "power-common.h"
49
50pthread_mutex_t camera_hint_mutex = PTHREAD_MUTEX_INITIALIZER;
51static int display_hint_sent;
52static int camera_hint_ref_count;
53
54static int process_video_encode_hint(void *metadata)
55{
56 char governor[80];
57 struct video_encode_metadata_t video_encode_metadata;
58
59 if (get_scaling_governor(governor, sizeof(governor)) == -1) {
60 ALOGE("Can't obtain scaling governor.");
61
62 return HINT_NONE;
63 }
64
65 /* Initialize encode metadata struct fields */
66 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
67 video_encode_metadata.state = -1;
68 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
69
70 if (metadata) {
71 if (parse_video_encode_metadata((char *)metadata, &video_encode_metadata) ==
72 -1) {
73 ALOGE("Error occurred while parsing metadata.");
74 return HINT_NONE;
75 }
76 } else {
77 return HINT_NONE;
78 }
79
80 if (video_encode_metadata.state == 1) {
81 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
82 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
83 /* 1. cpufreq params
84 * -above_hispeed_delay for LVT - 40ms
85 * -go hispeed load for LVT - 95
86 * -hispeed freq for LVT - 556 MHz
87 * -target load for LVT - 90
88 * -above hispeed delay for sLVT - 40ms
89 * -go hispeed load for sLVT - 95
90 * -hispeed freq for sLVT - 806 MHz
91 * -target load for sLVT - 90
92 * 2. bus DCVS set to V2 config:
93 * -low power ceil mpbs - 2500
94 * -low power io percent - 50
95 * 3. hysteresis optimization
96 * -bus dcvs hysteresis tuning
97 * -sample_ms of 10 ms
98 * -sLVT hispeed freq to 806MHz
99 */
100 int resource_values[] = {0x41400000, 0x4, 0x41410000, 0x5F, 0x41414000, 0x326,
101 0x41420000, 0x5A, 0x41400100, 0x4, 0x41410100, 0x5F, 0x41414100, 0x22C, 0x41420100, 0x5A,
102 0x41810000, 0x9C4, 0x41814000, 0x32, 0x4180C000, 0x0, 0x41820000, 0xA};
103
104 pthread_mutex_lock(&camera_hint_mutex);
105 camera_hint_ref_count++;
106 if (camera_hint_ref_count == 1) {
107 perform_hint_action(video_encode_metadata.hint_id,
108 resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
109 }
110 pthread_mutex_unlock(&camera_hint_mutex);
111 ALOGI("Video Encode hint start");
112 return HINT_HANDLED;
113 }
114 } else if (video_encode_metadata.state == 0) {
115 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
116 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
117 pthread_mutex_lock(&camera_hint_mutex);
118 camera_hint_ref_count--;
119 if (!camera_hint_ref_count) {
120 undo_hint_action(video_encode_metadata.hint_id);
121 }
122 pthread_mutex_unlock(&camera_hint_mutex);
123
124 ALOGI("Video Encode hint stop");
125 return HINT_HANDLED;
126 }
127 }
128 return HINT_NONE;
129}
130
131int power_hint_override(struct power_module *module, power_hint_t hint, void *data)
132{
133 int ret_val = HINT_NONE;
134 switch(hint) {
135 case POWER_HINT_VIDEO_ENCODE:
136 ret_val = process_video_encode_hint(data);
137 break;
138 default:
139 break;
140 }
141 return ret_val;
142}
143
144int set_interactive_override(struct power_module *module, int on)
145{
146 return HINT_HANDLED; /* Don't excecute this code path, not in use */
147 char governor[80];
148
149 if (get_scaling_governor(governor, sizeof(governor)) == -1) {
150 ALOGE("Can't obtain scaling governor.");
151
152 return HINT_NONE;
153 }
154
155 if (!on) {
156 /* Display off */
157 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
158 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
159 int resource_values[] = {}; /* dummy node */
160 if (!display_hint_sent) {
161 perform_hint_action(DISPLAY_STATE_HINT_ID,
162 resource_values, sizeof(resource_values)/sizeof(resource_values[0]));
163 display_hint_sent = 1;
164 ALOGI("Display Off hint start");
165 return HINT_HANDLED;
166 }
167 }
168 } else {
169 /* Display on */
170 if ((strncmp(governor, INTERACTIVE_GOVERNOR, strlen(INTERACTIVE_GOVERNOR)) == 0) &&
171 (strlen(governor) == strlen(INTERACTIVE_GOVERNOR))) {
172 undo_hint_action(DISPLAY_STATE_HINT_ID);
173 display_hint_sent = 0;
174 ALOGI("Display Off hint stop");
175 return HINT_HANDLED;
176 }
177 }
178 return HINT_NONE;
179}