blob: 452972db4faecaee6b3ccfd1e3e465f476fc83e5 [file] [log] [blame]
Steve Kondik40ea4d62014-03-27 22:00:00 -07001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
Steve Kondik4ed36a92015-03-15 19:47:59 -05003 * Copyright (c) 2014, The CyanogenMod Project
Steve Kondik40ea4d62014-03-27 22:00:00 -07004 *
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#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 "QCOM 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 display_hint_sent;
52
Steve Kondikd9668ba2015-11-03 03:27:42 -080053int get_number_of_profiles() {
54 return 3;
55}
Steve Kondik4ed36a92015-03-15 19:47:59 -050056
57static int current_power_profile = PROFILE_BALANCED;
58
59static void set_power_profile(int profile) {
60
61 if (profile == current_power_profile)
62 return;
63
64 ALOGV("%s: profile=%d", __func__, profile);
65
66 if (current_power_profile != PROFILE_BALANCED) {
67 undo_hint_action(DEFAULT_PROFILE_HINT_ID);
68 ALOGV("%s: hint undone", __func__);
69 }
70
71 if (profile == PROFILE_HIGH_PERFORMANCE) {
Steve Kondik5a31d992015-03-15 19:51:16 -050072 int resource_values[] = { CPUS_ONLINE_MIN_4,
73 CPU0_MIN_FREQ_TURBO_MAX, CPU1_MIN_FREQ_TURBO_MAX,
74 CPU2_MIN_FREQ_TURBO_MAX, CPU3_MIN_FREQ_TURBO_MAX };
Steve Kondik4ed36a92015-03-15 19:47:59 -050075 perform_hint_action(DEFAULT_PROFILE_HINT_ID,
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +080076 resource_values, ARRAY_SIZE(resource_values));
Steve Kondik4ed36a92015-03-15 19:47:59 -050077 ALOGD("%s: set performance mode", __func__);
78 } else if (profile == PROFILE_POWER_SAVE) {
Steve Kondik5a31d992015-03-15 19:51:16 -050079 int resource_values[] = { CPUS_ONLINE_MAX_LIMIT_2,
80 CPU0_MAX_FREQ_NONTURBO_MAX, CPU1_MAX_FREQ_NONTURBO_MAX,
81 CPU2_MAX_FREQ_NONTURBO_MAX, CPU3_MAX_FREQ_NONTURBO_MAX };
Steve Kondik4ed36a92015-03-15 19:47:59 -050082 perform_hint_action(DEFAULT_PROFILE_HINT_ID,
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +080083 resource_values, ARRAY_SIZE(resource_values));
Steve Kondik4ed36a92015-03-15 19:47:59 -050084 ALOGD("%s: set powersave", __func__);
85 }
86
87 current_power_profile = profile;
88}
89
90extern void interaction(int duration, int num_args, int opt_list[]);
91
Steve Kondikc534f6e2015-03-15 19:52:35 -050092int power_hint_override(__attribute__((unused)) struct power_module *module,
93 power_hint_t hint, void *data)
Steve Kondik40ea4d62014-03-27 22:00:00 -070094{
Steve Kondik4ed36a92015-03-15 19:47:59 -050095 if (hint == POWER_HINT_SET_PROFILE) {
Steve Kondikd9668ba2015-11-03 03:27:42 -080096 set_power_profile(*(int32_t *)data);
Steve Kondik4ed36a92015-03-15 19:47:59 -050097 return HINT_HANDLED;
Steve Kondik40ea4d62014-03-27 22:00:00 -070098 }
Steve Kondik4ed36a92015-03-15 19:47:59 -050099
100 // Skip other hints in custom power modes
101 if (current_power_profile != PROFILE_BALANCED) {
102 return HINT_HANDLED;
103 }
104
105 if (hint == POWER_HINT_CPU_BOOST) {
Steve Kondikd9668ba2015-11-03 03:27:42 -0800106 int duration = *(int32_t *)data / 1000;
Steve Kondik28310b22015-03-15 19:56:13 -0500107 int resources[] = { CPUS_ONLINE_MIN_2, 0x20F, 0x30F};
Steve Kondik4ed36a92015-03-15 19:47:59 -0500108
109 if (duration > 0)
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +0800110 interaction(duration, ARRAY_SIZE(resources), resources);
Steve Kondik4ed36a92015-03-15 19:47:59 -0500111 return HINT_HANDLED;
112 } else if (hint == POWER_HINT_INTERACTION) {
113 int resources[] = {0x702, 0x20B, 0x30B};
114 int duration = 3000;
115
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +0800116 interaction(duration, ARRAY_SIZE(resources), resources);
Steve Kondik4ed36a92015-03-15 19:47:59 -0500117 return HINT_HANDLED;
118 }
119
Steve Kondik40ea4d62014-03-27 22:00:00 -0700120 return HINT_NONE;
121}