Ananth Raghavan Subramanian | f976fa0 | 2017-05-18 20:46:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, The Linux Foundation. All rights reserved. |
| 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 | |
| 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 "QTI 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_fd; |
| 52 | #define SYS_DISPLAY_PWR "/sys/kernel/hbtp/display_pwr" |
| 53 | |
Bhargav Upperla | e31cdff | 2017-08-15 12:22:49 -0700 | [diff] [blame] | 54 | /* Declare function before use */ |
| 55 | void interaction(int duration, int num_args, int opt_list[]); |
| 56 | |
Rashed Abdel-Tawab | 01ae247 | 2017-12-31 01:21:40 +0200 | [diff] [blame] | 57 | int power_hint_override(power_hint_t hint, void *data) |
Bhargav Upperla | e31cdff | 2017-08-15 12:22:49 -0700 | [diff] [blame] | 58 | { |
| 59 | int ret_val = HINT_NONE; |
| 60 | switch(hint) { |
| 61 | case POWER_HINT_INTERACTION: |
| 62 | { |
| 63 | int resources[] = {0x40800100, 0x553}; |
| 64 | int duration = 100; |
| 65 | interaction(duration, sizeof(resources)/sizeof(resources[0]), resources); |
| 66 | ret_val = HINT_HANDLED; |
| 67 | } |
| 68 | break; |
| 69 | default: |
| 70 | break; |
| 71 | } |
| 72 | return ret_val; |
| 73 | } |
| 74 | |
Rashed Abdel-Tawab | 01ae247 | 2017-12-31 01:21:40 +0200 | [diff] [blame] | 75 | int set_interactive_override(int on) |
Ananth Raghavan Subramanian | f976fa0 | 2017-05-18 20:46:03 -0700 | [diff] [blame] | 76 | { |
| 77 | static const char *display_on = "1"; |
| 78 | static const char *display_off = "0"; |
| 79 | char err_buf[80]; |
| 80 | static int init_interactive_hint = 0; |
| 81 | static int set_i_count = 0; |
| 82 | int rc = 0; |
| 83 | |
| 84 | set_i_count ++; |
| 85 | ALOGI("Got set_interactive hint on= %d, count= %d\n", on, set_i_count); |
| 86 | |
| 87 | if (init_interactive_hint == 0) |
| 88 | { |
| 89 | //First time the display is turned off |
| 90 | display_fd = TEMP_FAILURE_RETRY(open(SYS_DISPLAY_PWR, O_RDWR)); |
| 91 | if (display_fd < 0) { |
| 92 | strerror_r(errno,err_buf,sizeof(err_buf)); |
| 93 | ALOGE("Error opening %s: %s\n", SYS_DISPLAY_PWR, err_buf); |
| 94 | } |
| 95 | else |
| 96 | init_interactive_hint = 1; |
| 97 | } |
| 98 | else |
| 99 | if (!on ) { |
| 100 | /* Display off. */ |
| 101 | rc = TEMP_FAILURE_RETRY(write(display_fd, display_off, strlen(display_off))); |
| 102 | if (rc < 0) { |
| 103 | strerror_r(errno,err_buf,sizeof(err_buf)); |
| 104 | ALOGE("Error writing %s to %s: %s\n", display_off, SYS_DISPLAY_PWR, err_buf); |
| 105 | } |
| 106 | } |
| 107 | else { |
| 108 | /* Display on */ |
| 109 | rc = TEMP_FAILURE_RETRY(write(display_fd, display_on, strlen(display_on))); |
| 110 | if (rc < 0) { |
| 111 | strerror_r(errno,err_buf,sizeof(err_buf)); |
| 112 | ALOGE("Error writing %s to %s: %s\n", display_on, SYS_DISPLAY_PWR, err_buf); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return HINT_HANDLED; /* Don't excecute this code path, not in use */ |
| 117 | } |