blob: 27a8d259f48124e537c675d67f331119e156efd1 [file] [log] [blame]
Ananth Raghavan Subramanian32e093d2018-04-04 14:28:46 -07001/*
2 * Copyright (c) 2018, 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#define LOG_NIDEBUG 0
32
33#include <errno.h>
34#include <sys/types.h>
35#include <sys/stat.h>
36#include <fcntl.h>
Bhavana Prabhakarf8ba14b2018-06-18 15:03:56 -070037#include <unistd.h>
Ananth Raghavan Subramanian32e093d2018-04-04 14:28:46 -070038#include <dlfcn.h>
Ananth Raghavan Subramanian32e093d2018-04-04 14:28:46 -070039#include <string.h>
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 "power-common.h"
47
48static int display_fd;
49#define SYS_DISPLAY_PWR "/sys/kernel/hbtp/display_pwr"
50
51int set_interactive_override(struct power_module *module, int on)
52{
53 static const char *display_on = "1";
54 static const char *display_off = "0";
55 char err_buf[80];
56 static int init_interactive_hint = 0;
57 static int set_i_count = 0;
58 int rc = 0;
59
60 set_i_count ++;
61 ALOGI("Got set_interactive hint on= %d, count= %d\n", on, set_i_count);
62
63 if (init_interactive_hint == 0)
64 {
65 //First time the display is turned off
66 display_fd = TEMP_FAILURE_RETRY(open(SYS_DISPLAY_PWR, O_RDWR));
67 if (display_fd < 0) {
68 strerror_r(errno,err_buf,sizeof(err_buf));
69 ALOGE("Error opening %s: %s\n", SYS_DISPLAY_PWR, err_buf);
70 }
71 else
72 init_interactive_hint = 1;
73 }
74 else
75 if (!on ) {
76 /* Display off. */
77 rc = TEMP_FAILURE_RETRY(write(display_fd, display_off, strlen(display_off)));
78 if (rc < 0) {
79 strerror_r(errno,err_buf,sizeof(err_buf));
80 ALOGE("Error writing %s to %s: %s\n", display_off, SYS_DISPLAY_PWR, err_buf);
81 }
82 }
83 else {
84 /* Display on */
85 rc = TEMP_FAILURE_RETRY(write(display_fd, display_on, strlen(display_on)));
86 if (rc < 0) {
87 strerror_r(errno,err_buf,sizeof(err_buf));
88 ALOGE("Error writing %s to %s: %s\n", display_on, SYS_DISPLAY_PWR, err_buf);
89 }
90 }
91
92 return HINT_HANDLED;
93}
94
Bhargav Upperla472e5762018-05-01 12:29:10 -070095void interaction(int duration, int num_args, int opt_list[]);
96
97int power_hint_override(struct power_module *module, power_hint_t hint, void *data)
98{
99 int ret_val = HINT_NONE;
100 switch(hint) {
101 case POWER_HINT_INTERACTION:
102 {
103 int resources[] = {0x40800100, 0x514};
104 int duration = 100;
105 interaction(duration, sizeof(resources)/sizeof(resources[0]), resources);
106 ret_val = HINT_HANDLED;
107 }
108 default:
109 break;
110 }
111 return ret_val;
112}