blob: 0101bea634af8f790ac5a215643b502b80bf7822 [file] [log] [blame]
David Ngee7c4c52018-03-22 23:49:12 -07001/*
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -07002 * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved.
David Ngee7c4c52018-03-22 23:49:12 -07003 *
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>
Vinay Verma2fd9c122018-04-29 14:08:30 +053039#include <unistd.h>
David Ngee7c4c52018-03-22 23:49:12 -070040
41#define LOG_TAG "QTI PowerHAL"
42#include <utils/Log.h>
43#include <hardware/hardware.h>
44#include <hardware/power.h>
45
46#include "utils.h"
David Ngee7c4c52018-03-22 23:49:12 -070047#include "hint-data.h"
48#include "performance.h"
49#include "power-common.h"
50
Ananth Raghavan Subramanian561cffc2018-12-05 12:08:33 -080051static struct hint_handles handles[NUM_HINTS];
David Ngee7c4c52018-03-22 23:49:12 -070052
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070053void power_init()
David Ngee7c4c52018-03-22 23:49:12 -070054{
Ananth Raghavan Subramanian561cffc2018-12-05 12:08:33 -080055 ALOGI("Initing");
David Ngee7c4c52018-03-22 23:49:12 -070056
Ananth Raghavan Subramanian561cffc2018-12-05 12:08:33 -080057 for (int i=0; i<NUM_HINTS; i++) {
58 handles[i].handle = 0;
59 handles[i].ref_count = 0;
David Ngee7c4c52018-03-22 23:49:12 -070060 }
61}
62
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070063int __attribute__ ((weak)) power_hint_override(power_hint_t hint,
David Ngee7c4c52018-03-22 23:49:12 -070064 void *data)
65{
66 return HINT_NONE;
67}
68
69/* Declare function before use */
70void interaction(int duration, int num_args, int opt_list[]);
71
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070072void power_hint(power_hint_t hint, void *data)
David Ngee7c4c52018-03-22 23:49:12 -070073{
74 /* Check if this hint has been overridden. */
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -070075 if (power_hint_override(hint, data) == HINT_HANDLED) {
David Ngee7c4c52018-03-22 23:49:12 -070076 /* The power_hint has been handled. We can skip the rest. */
77 return;
78 }
David Ngee7c4c52018-03-22 23:49:12 -070079 switch(hint) {
80 case POWER_HINT_VSYNC:
81 break;
David Ngee7c4c52018-03-22 23:49:12 -070082 case POWER_HINT_VR_MODE:
83 ALOGI("VR mode power hint not handled in power_hint_override");
84 break;
85 case POWER_HINT_INTERACTION:
86 {
87 int resources[] = {0x702, 0x20F, 0x30F};
88 int duration = 3000;
89
90 interaction(duration, sizeof(resources)/sizeof(resources[0]), resources);
91 }
92 break;
Ananth Raghavan Subramanian561cffc2018-12-05 12:08:33 -080093 //fall through below, hints will fail if not defined in powerhint.xml
94 case POWER_HINT_SUSTAINED_PERFORMANCE:
David Ngee7c4c52018-03-22 23:49:12 -070095 case POWER_HINT_VIDEO_ENCODE:
Ananth Raghavan Subramanian561cffc2018-12-05 12:08:33 -080096 if (data) {
97 if (handles[hint].ref_count == 0)
98 handles[hint].handle = perf_hint_enable((AOSP_DELTA + hint), 0);
99
100 if (handles[hint].handle > 0)
101 handles[hint].ref_count++;
102 }
103 else
104 if (handles[hint].handle > 0)
105 if (--handles[hint].ref_count == 0) {
106 release_request(handles[hint].handle);
107 handles[hint].handle = 0;
108 }
109 else
110 ALOGE("Lock for hint: %X was not acquired, cannot be released", hint);
David Ngee7c4c52018-03-22 23:49:12 -0700111 break;
112 }
113}
114
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -0700115int __attribute__ ((weak)) set_interactive_override(int on)
David Ngee7c4c52018-03-22 23:49:12 -0700116{
117 return HINT_NONE;
118}
119
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -0700120void set_interactive(int on)
David Ngee7c4c52018-03-22 23:49:12 -0700121{
David Ngee7c4c52018-03-22 23:49:12 -0700122 if (!on) {
123 /* Send Display OFF hint to perf HAL */
124 perf_hint_enable(VENDOR_HINT_DISPLAY_OFF, 0);
125 } else {
126 /* Send Display ON hint to perf HAL */
127 perf_hint_enable(VENDOR_HINT_DISPLAY_ON, 0);
128 }
129
Ananth Raghavan Subramaniand39ec572018-09-08 19:47:41 -0700130 if (set_interactive_override(on) == HINT_HANDLED) {
David Ngee7c4c52018-03-22 23:49:12 -0700131 return;
132 }
133
134 ALOGI("Got set_interactive hint");
David Ngee7c4c52018-03-22 23:49:12 -0700135}