blob: 034a19c794b9b2beff73c372bab26d4793ea390c [file] [log] [blame]
Rajashekar Adi380452d2017-12-04 11:40:36 +05301/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29
30
31#include <errno.h>
32#include <string.h>
33#include <sys/types.h>
34#include <sys/stat.h>
35#include <fcntl.h>
36#include <dlfcn.h>
37#include <stdlib.h>
Anurudh Kumar Tiwaribda84832018-06-12 10:42:35 +053038#include <pthread.h>
39#include <unistd.h>
Rajashekar Adi380452d2017-12-04 11:40:36 +053040
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"
47#include "metadata-defs.h"
48#include "hint-data.h"
49#include "performance.h"
50#include "power-common.h"
51
52static int display_fd;
53#define SYS_DISPLAY_PWR "/sys/kernel/hbtp/display_pwr"
54
55int set_interactive_override(struct power_module *module, int on)
56{
57 static const char *display_on = "1";
58 static const char *display_off = "0";
59 char err_buf[80];
60 static int init_interactive_hint = 0;
61 static int set_i_count = 0;
62 int rc = 0;
63
64 set_i_count ++;
65 ALOGI("Got set_interactive hint on= %d, count= %d\n", on, set_i_count);
66
67 if (init_interactive_hint == 0)
68 {
69 //First time the display is turned off
70 display_fd = TEMP_FAILURE_RETRY(open(SYS_DISPLAY_PWR, O_RDWR));
71 if (display_fd < 0) {
72 strerror_r(errno,err_buf,sizeof(err_buf));
73 ALOGE("Error opening %s: %s\n", SYS_DISPLAY_PWR, err_buf);
74 }
75 else
76 init_interactive_hint = 1;
77 }
78 else
79 if (!on ) {
80 /* Display off. */
81 rc = TEMP_FAILURE_RETRY(write(display_fd, display_off, strlen(display_off)));
82 if (rc < 0) {
83 strerror_r(errno,err_buf,sizeof(err_buf));
84 ALOGE("Error writing %s to %s: %s\n", display_off, SYS_DISPLAY_PWR, err_buf);
85 }
86 }
87 else {
88 /* Display on */
89 rc = TEMP_FAILURE_RETRY(write(display_fd, display_on, strlen(display_on)));
90 if (rc < 0) {
91 strerror_r(errno,err_buf,sizeof(err_buf));
92 ALOGE("Error writing %s to %s: %s\n", display_on, SYS_DISPLAY_PWR, err_buf);
93 }
94 }
95
96 return HINT_HANDLED; /* Don't excecute this code path, not in use */
97}
98
99