David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 1 | /* |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 2 | * Copyright (c) 2012-2019, The Linux Foundation. All rights reserved. |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 3 | * |
| 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 Verma | 2fd9c12 | 2018-04-29 14:08:30 +0530 | [diff] [blame] | 39 | #include <unistd.h> |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 40 | |
| 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 Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 47 | #include "hint-data.h" |
| 48 | #include "performance.h" |
| 49 | #include "power-common.h" |
| 50 | |
Ananth Raghavan Subramanian | 561cffc | 2018-12-05 12:08:33 -0800 | [diff] [blame] | 51 | static struct hint_handles handles[NUM_HINTS]; |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 52 | |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 53 | void power_init() |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 54 | { |
Ananth Raghavan Subramanian | 561cffc | 2018-12-05 12:08:33 -0800 | [diff] [blame] | 55 | ALOGI("Initing"); |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 56 | |
Ananth Raghavan Subramanian | 561cffc | 2018-12-05 12:08:33 -0800 | [diff] [blame] | 57 | for (int i=0; i<NUM_HINTS; i++) { |
| 58 | handles[i].handle = 0; |
| 59 | handles[i].ref_count = 0; |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 63 | int __attribute__ ((weak)) power_hint_override(power_hint_t hint, |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 64 | void *data) |
| 65 | { |
| 66 | return HINT_NONE; |
| 67 | } |
| 68 | |
| 69 | /* Declare function before use */ |
| 70 | void interaction(int duration, int num_args, int opt_list[]); |
| 71 | |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 72 | void power_hint(power_hint_t hint, void *data) |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 73 | { |
| 74 | /* Check if this hint has been overridden. */ |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 75 | if (power_hint_override(hint, data) == HINT_HANDLED) { |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 76 | /* The power_hint has been handled. We can skip the rest. */ |
| 77 | return; |
| 78 | } |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 79 | switch(hint) { |
| 80 | case POWER_HINT_VSYNC: |
| 81 | break; |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 82 | 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 Subramanian | 561cffc | 2018-12-05 12:08:33 -0800 | [diff] [blame] | 93 | //fall through below, hints will fail if not defined in powerhint.xml |
| 94 | case POWER_HINT_SUSTAINED_PERFORMANCE: |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 95 | case POWER_HINT_VIDEO_ENCODE: |
Ananth Raghavan Subramanian | 561cffc | 2018-12-05 12:08:33 -0800 | [diff] [blame] | 96 | 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 Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 111 | break; |
| 112 | } |
| 113 | } |
| 114 | |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 115 | int __attribute__ ((weak)) set_interactive_override(int on) |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 116 | { |
| 117 | return HINT_NONE; |
| 118 | } |
| 119 | |
Ananth Raghavan Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 120 | void set_interactive(int on) |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 121 | { |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 122 | 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 Subramanian | d39ec57 | 2018-09-08 19:47:41 -0700 | [diff] [blame] | 130 | if (set_interactive_override(on) == HINT_HANDLED) { |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 131 | return; |
| 132 | } |
| 133 | |
| 134 | ALOGI("Got set_interactive hint"); |
David Ng | ee7c4c5 | 2018-03-22 23:49:12 -0700 | [diff] [blame] | 135 | } |