Steve Kondik | 40ea4d6 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 3 | * Copyright (c) 2014, The CyanogenMod Project |
Steve Kondik | 40ea4d6 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 4 | * |
| 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 | |
| 51 | static int display_hint_sent; |
| 52 | |
Steve Kondik | d9668ba | 2015-11-03 03:27:42 -0800 | [diff] [blame] | 53 | int get_number_of_profiles() { |
| 54 | return 3; |
| 55 | } |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 56 | |
| 57 | static int current_power_profile = PROFILE_BALANCED; |
| 58 | |
| 59 | static 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 Kondik | 5a31d99 | 2015-03-15 19:51:16 -0500 | [diff] [blame] | 72 | 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 Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 75 | perform_hint_action(DEFAULT_PROFILE_HINT_ID, |
Zhao Wei Liew | 50a1ce2 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 76 | resource_values, ARRAY_SIZE(resource_values)); |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 77 | ALOGD("%s: set performance mode", __func__); |
| 78 | } else if (profile == PROFILE_POWER_SAVE) { |
Steve Kondik | 5a31d99 | 2015-03-15 19:51:16 -0500 | [diff] [blame] | 79 | 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 Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 82 | perform_hint_action(DEFAULT_PROFILE_HINT_ID, |
Zhao Wei Liew | 50a1ce2 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 83 | resource_values, ARRAY_SIZE(resource_values)); |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 84 | ALOGD("%s: set powersave", __func__); |
| 85 | } |
| 86 | |
| 87 | current_power_profile = profile; |
| 88 | } |
| 89 | |
| 90 | extern void interaction(int duration, int num_args, int opt_list[]); |
| 91 | |
Steve Kondik | c534f6e | 2015-03-15 19:52:35 -0500 | [diff] [blame] | 92 | int power_hint_override(__attribute__((unused)) struct power_module *module, |
| 93 | power_hint_t hint, void *data) |
Steve Kondik | 40ea4d6 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 94 | { |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 95 | if (hint == POWER_HINT_SET_PROFILE) { |
Steve Kondik | d9668ba | 2015-11-03 03:27:42 -0800 | [diff] [blame] | 96 | set_power_profile(*(int32_t *)data); |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 97 | return HINT_HANDLED; |
Steve Kondik | 40ea4d6 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 98 | } |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 99 | |
| 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 Kondik | d9668ba | 2015-11-03 03:27:42 -0800 | [diff] [blame] | 106 | int duration = *(int32_t *)data / 1000; |
Steve Kondik | 28310b2 | 2015-03-15 19:56:13 -0500 | [diff] [blame] | 107 | int resources[] = { CPUS_ONLINE_MIN_2, 0x20F, 0x30F}; |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 108 | |
| 109 | if (duration > 0) |
Zhao Wei Liew | 50a1ce2 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 110 | interaction(duration, ARRAY_SIZE(resources), resources); |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 111 | return HINT_HANDLED; |
| 112 | } else if (hint == POWER_HINT_INTERACTION) { |
| 113 | int resources[] = {0x702, 0x20B, 0x30B}; |
| 114 | int duration = 3000; |
| 115 | |
Zhao Wei Liew | 50a1ce2 | 2016-06-26 11:37:59 +0800 | [diff] [blame] | 116 | interaction(duration, ARRAY_SIZE(resources), resources); |
Steve Kondik | 4ed36a9 | 2015-03-15 19:47:59 -0500 | [diff] [blame] | 117 | return HINT_HANDLED; |
| 118 | } |
| 119 | |
Steve Kondik | 40ea4d6 | 2014-03-27 22:00:00 -0700 | [diff] [blame] | 120 | return HINT_NONE; |
| 121 | } |