blob: 6caea4ba0cc24e3965f769482b9a57e5ea1a990b [file] [log] [blame]
Aaron Klingb2b3dd02015-11-12 09:25:04 -06001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 * Copyright (c) 2012-2014, NVIDIA CORPORATION. All rights reserved.
4 * Copyright (C) 2015 The CyanogenMod Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef COMMON_POWER_HAL_H
20#define COMMON_POWER_HAL_H
21
22#include <hardware/hardware.h>
23#include <hardware/power.h>
24
25#include "powerhal_utils.h"
26#include "timeoutpoker.h"
27#include <semaphore.h>
28
29#define MAX_CHARS 32
30#define MAX_INPUT_DEV_COUNT 12
31#define MAX_USE_CASE_STRING_SIZE 80
32// This needs set to the largest power hint in the enum in hardware/power.h
BitO BSessiOn73289eb2016-11-21 12:29:40 +010033#define MAX_POWER_HINT_COUNT POWER_HINT_DISABLE_TOUCH
Aaron Klingb2b3dd02015-11-12 09:25:04 -060034
35#define DEFAULT_MIN_ONLINE_CPUS 2
36#define DEFAULT_MAX_ONLINE_CPUS 0
37#define DEFAULT_FREQ 700
38
39#define POWER_CAP_PROP "persist.sys.NV_PBC_PWR_LIMIT"
40#define SLEEP_INTERVAL_SECS 1
41
42//sys node control entry
43#define SYS_NODE_PRISM_ENABLE "/sys/devices/platform/host1x/tegradc.0/smartdimmer/enable"
44#define SYS_NODE_CPU0_MAX_FREQ "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
45
46//PMQOS control entry
47#define PMQOS_MAX_ONLINE_CPUS "/dev/max_online_cpus"
48#define PMQOS_MAX_CPU_FREQ "/dev/cpu_freq_max"
49#define PMQOS_CONSTRAINT_CPU_FREQ "/dev/constraint_cpu_freq"
50#define PMQOS_CONSTRAINT_GPU_FREQ "/dev/constraint_gpu_freq"
51#define PMQOS_CONSTRAINT_ONLINE_CPUS "/dev/constraint_online_cpus"
52
53//Default value to align with kernel pm qos
54#define PM_QOS_DEFAULT_VALUE -1
55
56#define PRISM_CONTROL_PROP "persist.sys.didim.enable"
57
58#define AFFINITY_DAEMON_CONTROL_PROP "persist.sys.ad.enable"
59
60#define PM_QOS_BOOST_PRIORITY 35
61#define PM_QOS_APP_PROFILE_PRIORITY 40
62
63struct input_dev_map {
64 int dev_id;
65 const char* dev_name;
66};
67
68typedef struct interactive_data {
69 const char *hispeed_freq;
70 const char *target_loads;
71 const char *above_hispeed_delay;
72 const char *timer_rate;
73 const char *boost_factor;
74 const char *min_sample_time;
75 const char *go_hispeed_load;
76} interactive_data_t;
77
78typedef int (*sendhints_fn_t)(uint32_t client_tag, ...);
79typedef void (*cancelhints_fn_t)(uint32_t usecase, uint32_t client_tag);
80
81struct powerhal_info {
82 TimeoutPoker* mTimeoutPoker;
83
84 int *available_frequencies;
85 int num_available_frequencies;
86
87 /* Maximum LP CPU frequency */
88 int lp_max_frequency;
89
90 int interaction_boost_frequency;
91 int animation_boost_frequency;
92
93 /* maximum frequency for the current cpufreq policy */
94 int cpu0_max_frequency;
95
96 bool ftrace_enable;
97
98 /* Number of devices requesting Power HAL service */
99 int input_cnt;
100
101 /* Holds input devices */
102 struct input_dev_map* input_devs;
103
104 /* Time last hint was sent - in usec */
105 uint64_t hint_time[MAX_POWER_HINT_COUNT];
106 uint64_t hint_interval[MAX_POWER_HINT_COUNT];
107
108 /* waiting condvar regular hints thread */
109 pthread_cond_t wait_cond;
110
111 /* waiting mutex regular hints thread */
112 pthread_mutex_t wait_mutex;
113
114 /* regular hints thread handle */
115 pthread_t regular_hints_thread;
116
117 /* regular hints thread handle */
118 bool exit_hints_thread;
119
120 /* Features on platform */
121 struct {
122 bool fan;
123 bool edp_mode;
124 bool volt_temp_mode;
125 } features;
126};
127
128/* Opens power hw module */
129void common_power_open(struct powerhal_info *pInfo);
130
131/* Power management setup action at startup.
132 * Such as to set default cpufreq parameters.
133 */
134void common_power_init(struct power_module *module, struct powerhal_info *pInfo);
135
136/* Power management action,
137 * upon the system entering interactive state and ready for interaction,
138 * often with UI devices
139 * OR
140 * non-interactive state the system appears asleep, displayi/touch usually turned off.
141*/
142void common_power_set_interactive(struct power_module *module,
143 struct powerhal_info *pInfo, int on);
144
145/* PowerHint called to pass hints on power requirements, which
146 * may result in adjustment of power/performance parameters of the
147 * cpufreq governor and other controls.
148*/
149void common_power_hint(struct power_module *module, struct powerhal_info *pInfo,
150 power_hint_t hint, void *data);
151
152#endif //COMMON_POWER_HAL_H
153