blob: 0a9ef37f837f529044418a31807528ecc7fde205 [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.
Michael Bestas47636f62018-05-25 21:30:28 +03003 * Copyright (C) 2018 The LineageOS Project
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +05304 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 * * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
14 * * Neither the name of The Linux Foundation nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#define LOG_NIDEBUG 0
32
33#include <errno.h>
34#include <string.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <fcntl.h>
38#include <dlfcn.h>
39#include <stdlib.h>
40
Michael Bestas1add9ac2018-03-25 22:56:44 +030041#define LOG_TAG "QCOM PowerHAL"
Ethan Chena42f4a82018-03-01 21:31:15 -080042#include <log/log.h>
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053043#include <hardware/hardware.h>
44#include <hardware/power.h>
45
46#include "utils.h"
47#include "metadata-defs.h"
48#include "hint-data.h"
49#include "performance.h"
50#include "power-common.h"
51
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +053052#define MIN_VAL(X,Y) ((X>Y)?(Y):(X))
53
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053054static int video_encode_hint_sent;
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053055
Zhao Wei Liew6fe52522016-07-19 19:57:06 +080056/**
57 * If target is SDM630:
58 * return true
59 * else:
60 * return false
61 */
62static bool is_target_SDM630(void)
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053063{
Zhao Wei Liew6fe52522016-07-19 19:57:06 +080064 static bool is_SDM630 = false;
65 int soc_id;
66
67 soc_id = get_soc_id();
68 if (soc_id == 318 || soc_id == 327)
69 is_SDM630 = true;
70
71 return is_SDM630;
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053072}
73
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053074static void process_video_encode_hint(void *metadata)
75{
76 char governor[80];
77 int resource_values[20];
78 int num_resources;
79 struct video_encode_metadata_t video_encode_metadata;
80
Michael Bestas47636f62018-05-25 21:30:28 +030081 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) {
82 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) {
83 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) {
84 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) {
85 ALOGE("Can't obtain scaling governor.");
86 return;
87 }
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053088 }
Michael Bestas47636f62018-05-25 21:30:28 +030089 }
90 }
91
92 if (!metadata) {
93 return;
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +053094 }
95
96 /* Initialize encode metadata struct fields. */
97 memset(&video_encode_metadata, 0, sizeof(struct video_encode_metadata_t));
98 video_encode_metadata.state = -1;
99 video_encode_metadata.hint_id = DEFAULT_VIDEO_ENCODE_HINT_ID;
100
Michael Bestas47636f62018-05-25 21:30:28 +0300101 if (parse_video_encode_metadata((char *)metadata,
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530102 &video_encode_metadata) == -1) {
Michael Bestas47636f62018-05-25 21:30:28 +0300103 ALOGE("Error occurred while parsing metadata.");
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530104 return;
105 }
106
107 if (video_encode_metadata.state == 1) {
Ethan Chen4b4acdf2018-03-01 21:41:04 -0800108 if (is_interactive_governor(governor)) {
Michael Bestas47636f62018-05-25 21:30:28 +0300109 if (is_target_SDM630()) {
110 /*
111 1. CPUfreq params
112 - hispeed freq for big - 1113Mhz
113 - go hispeed load for big - 95
114 - above_hispeed_delay for big - 40ms
115 - target loads - 95
116 - nr_run - 5
117 2. BusDCVS V2 params
118 - Sample_ms of 10ms
119 */
120 int res[] = {
121 HISPEED_FREQ_BIG, 0x459,
122 GO_HISPEED_LOAD_BIG, 0x5F,
123 ABOVE_HISPEED_DELAY_BIG, 0x4,
124 TARGET_LOADS_BIG, 0x5F,
dianlujitao5eb472d2018-09-06 21:43:14 +0800125 SCHED_SPILL_NR_RUN, 0X5,
Michael Bestas47636f62018-05-25 21:30:28 +0300126 CPUBW_HWMON_SAMPLE_MS, 0xA
127 };
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530128 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Zhao Wei Liewd4fe61e2016-06-26 11:37:59 +0800129 num_resources = ARRAY_SIZE(res);
Michael Bestas47636f62018-05-25 21:30:28 +0300130 } else {
131 /*
132 1. CPUfreq params
133 - hispeed freq for little - 902Mhz
134 - go hispeed load for little - 95
135 - above_hispeed_delay for little - 40ms
136 2. BusDCVS V2 params
137 - Sample_ms of 10ms
138 */
139 int res[] = {
140 HISPEED_FREQ_LITTLE, 0x386,
141 GO_HISPEED_LOAD_LITTLE, 0x5F,
142 ABOVE_HISPEED_DELAY_LITTLE, 0x4,
143 CPUBW_HWMON_SAMPLE_MS, 0xA
144 };
Nikhil Kumar Kansal839d56f2017-04-18 15:50:25 +0530145 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
Zhao Wei Liewd4fe61e2016-06-26 11:37:59 +0800146 num_resources = ARRAY_SIZE(res);
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530147 }
Michael Bestas50a6e282018-05-25 21:33:46 +0300148 if (!video_encode_hint_sent) {
149 perform_hint_action(video_encode_metadata.hint_id,
150 resource_values, num_resources);
151 video_encode_hint_sent = 1;
152 }
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530153 }
154 } else if (video_encode_metadata.state == 0) {
Ethan Chen4b4acdf2018-03-01 21:41:04 -0800155 if (is_interactive_governor(governor)) {
Michael Bestas50a6e282018-05-25 21:33:46 +0300156 undo_hint_action(video_encode_metadata.hint_id);
157 video_encode_hint_sent = 0;
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530158 }
159 }
Michael Bestas47636f62018-05-25 21:30:28 +0300160}
161
162int power_hint_override(power_hint_t hint, void *data)
163{
164 switch (hint) {
165 case POWER_HINT_VSYNC:
166 break;
167 case POWER_HINT_VIDEO_ENCODE:
168 process_video_encode_hint(data);
169 return HINT_HANDLED;
170 default:
171 break;
172 }
173 return HINT_NONE;
174}
175
176int set_interactive_override(int on)
177{
178 char governor[80];
179 int resource_values[20];
180 int num_resources;
181
182 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU0) == -1) {
183 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU1) == -1) {
184 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU2) == -1) {
185 if (get_scaling_governor_check_cores(governor, sizeof(governor), CPU3) == -1) {
186 ALOGE("Can't obtain scaling governor.");
187 return HINT_NONE;
188 }
189 }
190 }
191 }
192
193 if (!on) {
194 /* Display off. */
195 if (is_interactive_governor(governor)) {
196 if (is_target_SDM630()) {
197 /*
198 1. CPUfreq params
199 - hispeed freq for big - 1113Mhz
200 - go hispeed load for big - 95
201 - above_hispeed_delay for big - 40ms
202 2. BusDCVS V2 params
203 - Sample_ms of 10ms
204 */
205 int res[] = {
206 HISPEED_FREQ_BIG, 0x459,
207 GO_HISPEED_LOAD_BIG, 0x5F,
208 ABOVE_HISPEED_DELAY_BIG, 0x4,
209 CPUBW_HWMON_SAMPLE_MS, 0xA
210 };
211 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
212 num_resources = ARRAY_SIZE(res);
213 } else {
214 /*
215 1. CPUfreq params
216 - hispeed freq for little - 902Mhz
217 - go hispeed load for little - 95
218 - above_hispeed_delay for little - 40ms
219 2. BusDCVS V2 params
220 - Sample_ms of 10ms
221 3. Sched group upmigrate - 500
222 */
223 int res[] = {
224 HISPEED_FREQ_LITTLE, 0x386,
225 GO_HISPEED_LOAD_LITTLE, 0x5F,
226 ABOVE_HISPEED_DELAY_LITTLE, 0x4,
227 CPUBW_HWMON_SAMPLE_MS, 0xA,
228 SCHED_GROUP_UP_MIGRATE, 0x1F4
229 };
230 memcpy(resource_values, res, MIN_VAL(sizeof(resource_values), sizeof(res)));
231 num_resources = ARRAY_SIZE(res);
232
233 }
234 perform_hint_action(DISPLAY_STATE_HINT_ID,
235 resource_values, num_resources);
236 }
237 } else {
238 /* Display on. */
239 if (is_interactive_governor(governor)) {
240 undo_hint_action(DISPLAY_STATE_HINT_ID);
241 }
242 }
243 return HINT_HANDLED;
Vara Prasad A V S G9b7a7582017-04-07 17:32:37 +0530244}