blob: 0e5b82f6fbecafda023cfe44757458ea930b0a4d [file] [log] [blame]
Steve Kondik40ea4d62014-03-27 22:00:00 -07001/*
2 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
Steve Kondik54173c72015-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 Kondik54173c72015-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 Kondikd3b0b552015-03-15 19:51:16 -050072 int resource_values[] = { CPUS_ONLINE_MIN_2,
73 CPU0_MIN_FREQ_TURBO_MAX, CPU1_MIN_FREQ_TURBO_MAX };
Steve Kondik54173c72015-03-15 19:47:59 -050074 perform_hint_action(DEFAULT_PROFILE_HINT_ID,
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +080075 resource_values, ARRAY_SIZE(resource_values));
Steve Kondik54173c72015-03-15 19:47:59 -050076 ALOGD("%s: set performance mode", __func__);
77 } else if (profile == PROFILE_POWER_SAVE) {
Steve Kondikd3b0b552015-03-15 19:51:16 -050078 int resource_values[] = { CPUS_ONLINE_MAX_LIMIT_2,
79 CPU0_MAX_FREQ_NONTURBO_MAX, CPU1_MAX_FREQ_NONTURBO_MAX };
Steve Kondik54173c72015-03-15 19:47:59 -050080 perform_hint_action(DEFAULT_PROFILE_HINT_ID,
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +080081 resource_values, ARRAY_SIZE(resource_values));
Steve Kondik54173c72015-03-15 19:47:59 -050082 ALOGD("%s: set powersave", __func__);
83 }
84
85 current_power_profile = profile;
86}
87
88extern void interaction(int duration, int num_args, int opt_list[]);
89
Steve Kondik20913b82015-03-15 19:52:35 -050090int power_hint_override(__attribute__((unused)) struct power_module *module,
91 power_hint_t hint, void *data)
Steve Kondik40ea4d62014-03-27 22:00:00 -070092{
Steve Kondik54173c72015-03-15 19:47:59 -050093 if (hint == POWER_HINT_SET_PROFILE) {
Steve Kondikd9668ba2015-11-03 03:27:42 -080094 set_power_profile(*(int32_t *)data);
Steve Kondik54173c72015-03-15 19:47:59 -050095 return HINT_HANDLED;
Steve Kondik40ea4d62014-03-27 22:00:00 -070096 }
Steve Kondik54173c72015-03-15 19:47:59 -050097
98 // Skip other hints in custom power modes
99 if (current_power_profile != PROFILE_BALANCED) {
100 return HINT_HANDLED;
101 }
102
103 if (hint == POWER_HINT_CPU_BOOST) {
Steve Kondikd9668ba2015-11-03 03:27:42 -0800104 int duration = *(int32_t *)data / 1000;
Steve Kondikf5833782015-03-15 19:56:13 -0500105 int resources[] = { CPUS_ONLINE_MIN_2, 0x20F, 0x30F};
Steve Kondik54173c72015-03-15 19:47:59 -0500106
107 if (duration > 0)
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +0800108 interaction(duration, ARRAY_SIZE(resources), resources);
Steve Kondik54173c72015-03-15 19:47:59 -0500109 return HINT_HANDLED;
110 } else if (hint == POWER_HINT_INTERACTION) {
111 int resources[] = {0x702, 0x20B, 0x30B};
112 int duration = 3000;
113
Zhao Wei Liew50a1ce22016-06-26 11:37:59 +0800114 interaction(duration, ARRAY_SIZE(resources), resources);
Steve Kondik54173c72015-03-15 19:47:59 -0500115 return HINT_HANDLED;
116 }
117
Steve Kondik40ea4d62014-03-27 22:00:00 -0700118 return HINT_NONE;
119}