blob: 88d6d2e7a85f3950b7e7d50c5e5a7e334ee11e11 [file] [log] [blame]
Christopher N. Hessede5e3c62015-12-21 21:28:23 +01001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Copyright (C) 2014-2015 Andreas Schneider <asn@cryptomilk.org>
Christopher N. Hessef05f9022017-01-16 22:49:06 +01005 * Copyright (C) 2014-2017 Christopher N. Hesse <raymanfx@gmail.com>
Christopher N. Hessede5e3c62015-12-21 21:28:23 +01006 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Christopher N. Hesse3360b092016-07-11 15:48:35 +020020#include <ctype.h>
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010021#include <dirent.h>
22#include <errno.h>
23#include <fcntl.h>
24#include <malloc.h>
25#include <stdbool.h>
Christopher N. Hessee1434192016-11-18 18:56:17 +010026#include <stdlib.h>
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010027#include <string.h>
28#include <unistd.h>
29
30#include <sys/types.h>
31#include <sys/stat.h>
32
33#define LOG_TAG "SamsungPowerHAL"
34/* #define LOG_NDEBUG 0 */
35#include <utils/Log.h>
36
37#include <hardware/hardware.h>
38#include <hardware/power.h>
Christopher N. Hesse12263502016-12-07 12:18:20 +010039#include <liblights/samsung_lights_helper.h>
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010040
Christopher N. Hesse4139d852016-12-07 12:21:44 +010041#include "samsung_power.h"
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010042
Christopher N. Hesse81f714d2017-03-12 17:11:04 +010043#define BOOST_PATH CPU0_INTERACTIVE_PATH "/boost"
44#define BOOSTPULSE_PATH CPU0_INTERACTIVE_PATH "/boostpulse"
Christopher N. Hesse63b5bd72017-05-29 20:45:14 +020045#define CPU0_IO_IS_BUSY_PATH CPU0_INTERACTIVE_PATH "/io_is_busy"
46#define CPU4_IO_IS_BUSY_PATH CPU4_INTERACTIVE_PATH "/io_is_busy"
Christopher N. Hesse81f714d2017-03-12 17:11:04 +010047#define CPU0_HISPEED_FREQ_PATH CPU0_INTERACTIVE_PATH "/hispeed_freq"
48#define CPU4_HISPEED_FREQ_PATH CPU4_INTERACTIVE_PATH "/hispeed_freq"
49
50#define CPU0_MAX_FREQ_PATH CPU0_SYSFS_PATH "/cpufreq/scaling_max_freq"
51#define CPU4_MAX_FREQ_PATH CPU4_SYSFS_PATH "/cpufreq/scaling_max_freq"
52
Christopher N. Hessed9106e92017-03-04 01:05:14 +010053#define ARRAY_SIZE(a) sizeof(a) / sizeof(a[0])
54
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010055struct samsung_power_module {
56 struct power_module base;
57 pthread_mutex_t lock;
58 int boostpulse_fd;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010059 char cpu0_hispeed_freq[10];
60 char cpu0_max_freq[10];
61 char cpu4_hispeed_freq[10];
62 char cpu4_max_freq[10];
63 char* touchscreen_power_path;
64 char* touchkey_power_path;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010065};
66
Andreas Schneiderf15d7f42016-02-03 10:43:47 +010067enum power_profile_e {
68 PROFILE_POWER_SAVE = 0,
69 PROFILE_BALANCED,
Christopher N. Hesse58f2ca02017-01-17 00:01:15 +010070 PROFILE_HIGH_PERFORMANCE,
71 PROFILE_MAX
Andreas Schneiderf15d7f42016-02-03 10:43:47 +010072};
Christopher N. Hesseccd970d2017-01-25 22:41:05 +010073
Andreas Schneiderf15d7f42016-02-03 10:43:47 +010074static enum power_profile_e current_power_profile = PROFILE_BALANCED;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010075
76/**********************************************************
77 *** HELPER FUNCTIONS
78 **********************************************************/
79
80static int sysfs_read(char *path, char *s, int num_bytes)
81{
82 char errno_str[64];
83 int len;
84 int ret = 0;
85 int fd;
86
87 fd = open(path, O_RDONLY);
88 if (fd < 0) {
89 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +010090 ALOGE("Error opening %s: %s", path, errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010091
92 return -1;
93 }
94
95 len = read(fd, s, num_bytes - 1);
96 if (len < 0) {
97 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +010098 ALOGE("Error reading from %s: %s", path, errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +010099
100 ret = -1;
101 } else {
102 s[len] = '\0';
103 }
104
105 close(fd);
106
107 return ret;
108}
109
110static void sysfs_write(const char *path, char *s)
111{
112 char errno_str[64];
113 int len;
114 int fd;
115
116 fd = open(path, O_WRONLY);
117 if (fd < 0) {
118 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100119 ALOGE("Error opening %s: %s", path, errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100120 return;
121 }
122
123 len = write(fd, s, strlen(s));
124 if (len < 0) {
125 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100126 ALOGE("Error writing to %s: %s", path, errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100127 }
128
129 close(fd);
130}
131
Christopher N. Hesse5fada9b2017-01-16 23:39:48 +0100132static void boost(int32_t duration_us)
133{
134 int fd;
135
136 if (duration_us <= 0)
137 return;
138
139 fd = open(BOOST_PATH, O_WRONLY);
140 if (fd < 0) {
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100141 ALOGE("Error opening %s", BOOST_PATH);
Christopher N. Hesse5fada9b2017-01-16 23:39:48 +0100142 return;
143 }
144
145 write(fd, "1", 1);
146 usleep(duration_us);
147 write(fd, "0", 1);
148
149 close(fd);
150}
151
Christopher N. Hessef21fbdb2017-03-04 01:41:58 +0100152static void boostpulse_open(struct samsung_power_module *samsung_pwr)
153{
154 samsung_pwr->boostpulse_fd = open(BOOSTPULSE_PATH, O_WRONLY);
155 if (samsung_pwr->boostpulse_fd < 0) {
156 ALOGE("Error opening %s: %s\n", BOOSTPULSE_PATH, strerror(errno));
157 }
158}
159
160static void send_boostpulse(int boostpulse_fd)
161{
162 int len;
163
164 if (boostpulse_fd < 0) {
165 return;
166 }
167
168 len = write(boostpulse_fd, "1", 1);
169 if (len < 0) {
170 ALOGE("Error writing to %s: %s", BOOSTPULSE_PATH, strerror(errno));
171 }
172}
173
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100174/**********************************************************
175 *** POWER FUNCTIONS
176 **********************************************************/
177
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100178static void set_power_profile(struct samsung_power_module *samsung_pwr,
Christopher N. Hesse58f2ca02017-01-17 00:01:15 +0100179 int profile)
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100180{
181 int rc;
182 struct stat sb;
183
Christopher N. Hesse58f2ca02017-01-17 00:01:15 +0100184 if (profile < 0 || profile >= PROFILE_MAX) {
185 return;
186 }
187
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100188 if (current_power_profile == profile) {
189 return;
190 }
191
192 ALOGV("%s: profile=%d", __func__, profile);
193
194 switch (profile) {
195 case PROFILE_POWER_SAVE:
Martin Bouchet4bf8a792017-03-28 04:00:04 -0300196 // Grab value set by init.*.rc
197 sysfs_read(CPU0_HISPEED_FREQ_PATH, samsung_pwr->cpu0_hispeed_freq,
198 sizeof(samsung_pwr->cpu0_hispeed_freq));
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100199 // Limit to hispeed freq
200 sysfs_write(CPU0_MAX_FREQ_PATH, samsung_pwr->cpu0_hispeed_freq);
201 rc = stat(CPU4_MAX_FREQ_PATH, &sb);
202 if (rc == 0) {
Martin Bouchet4bf8a792017-03-28 04:00:04 -0300203 sysfs_read(CPU4_HISPEED_FREQ_PATH, samsung_pwr->cpu4_hispeed_freq,
204 sizeof(samsung_pwr->cpu4_hispeed_freq));
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100205 sysfs_write(CPU4_MAX_FREQ_PATH, samsung_pwr->cpu4_hispeed_freq);
206 }
Christopher N. Hessef05f9022017-01-16 22:49:06 +0100207 ALOGV("%s: set powersave mode", __func__);
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100208 break;
209 case PROFILE_BALANCED:
210 // Restore normal max freq
211 sysfs_write(CPU0_MAX_FREQ_PATH, samsung_pwr->cpu0_max_freq);
212 rc = stat(CPU4_MAX_FREQ_PATH, &sb);
213 if (rc == 0) {
214 sysfs_write(CPU4_MAX_FREQ_PATH, samsung_pwr->cpu4_max_freq);
215 }
Christopher N. Hessef05f9022017-01-16 22:49:06 +0100216 ALOGV("%s: set balanced mode", __func__);
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100217 break;
218 case PROFILE_HIGH_PERFORMANCE:
219 // Restore normal max freq
220 sysfs_write(CPU0_MAX_FREQ_PATH, samsung_pwr->cpu0_max_freq);
221 rc = stat(CPU4_MAX_FREQ_PATH, &sb);
222 if (rc == 0) {
223 sysfs_write(CPU4_MAX_FREQ_PATH, samsung_pwr->cpu4_max_freq);
224 }
Christopher N. Hessef05f9022017-01-16 22:49:06 +0100225 ALOGV("%s: set performance mode", __func__);
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100226 break;
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100227 default:
228 ALOGW("%s: Unknown power profile: %d", __func__, profile);
229 return;
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100230 }
231
232 current_power_profile = profile;
233}
234
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100235static void find_input_nodes(struct samsung_power_module *samsung_pwr, char *dir)
236{
237 const char filename[] = "name";
238 char errno_str[64];
239 struct dirent *de;
240 char file_content[20];
241 char *path = NULL;
242 char *node_path = NULL;
243 size_t pathsize;
244 size_t node_pathsize;
245 DIR *d;
246
247 d = opendir(dir);
248 if (d == NULL) {
249 return;
250 }
251
252 while ((de = readdir(d)) != NULL) {
253 if (strncmp(filename, de->d_name, sizeof(filename)) == 0) {
254 pathsize = strlen(dir) + strlen(de->d_name) + 2;
255 node_pathsize = strlen(dir) + strlen("enabled") + 2;
256
257 path = malloc(pathsize);
258 node_path = malloc(node_pathsize);
259 if (path == NULL || node_path == NULL) {
260 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100261 ALOGE("Out of memory: %s", errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100262 return;
263 }
264
265 snprintf(path, pathsize, "%s/%s", dir, filename);
266 sysfs_read(path, file_content, sizeof(file_content));
267
268 snprintf(node_path, node_pathsize, "%s/%s", dir, "enabled");
269
270 if (strncmp(file_content, "sec_touchkey", 12) == 0) {
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100271 ALOGV("%s: found touchkey path: %s", __func__, node_path);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100272 samsung_pwr->touchkey_power_path = malloc(node_pathsize);
273 if (samsung_pwr->touchkey_power_path == NULL) {
274 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100275 ALOGE("Out of memory: %s", errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100276 return;
277 }
Christopher N. Hesse22da3132016-02-01 12:36:54 +0100278 snprintf(samsung_pwr->touchkey_power_path, node_pathsize,
279 "%s", node_path);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100280 }
281
282 if (strncmp(file_content, "sec_touchscreen", 15) == 0) {
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100283 ALOGV("%s: found touchscreen path: %s", __func__, node_path);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100284 samsung_pwr->touchscreen_power_path = malloc(node_pathsize);
285 if (samsung_pwr->touchscreen_power_path == NULL) {
286 strerror_r(errno, errno_str, sizeof(errno_str));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100287 ALOGE("Out of memory: %s", errno_str);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100288 return;
289 }
Christopher N. Hesse22da3132016-02-01 12:36:54 +0100290 snprintf(samsung_pwr->touchscreen_power_path, node_pathsize,
291 "%s", node_path);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100292 }
293 }
294 }
295
296 if (path)
297 free(path);
298 if (node_path)
299 free(node_path);
300 closedir(d);
301}
302
303/**********************************************************
304 *** INIT FUNCTIONS
305 **********************************************************/
306
307static void init_cpufreqs(struct samsung_power_module *samsung_pwr)
308{
309 int rc;
310 struct stat sb;
311
312 sysfs_read(CPU0_HISPEED_FREQ_PATH, samsung_pwr->cpu0_hispeed_freq,
313 sizeof(samsung_pwr->cpu0_hispeed_freq));
314 sysfs_read(CPU0_MAX_FREQ_PATH, samsung_pwr->cpu0_max_freq,
315 sizeof(samsung_pwr->cpu0_max_freq));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100316 ALOGV("%s: CPU 0 hispeed freq: %s", __func__, samsung_pwr->cpu0_hispeed_freq);
317 ALOGV("%s: CPU 0 max freq: %s", __func__, samsung_pwr->cpu0_max_freq);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100318
319 rc = stat(CPU4_HISPEED_FREQ_PATH, &sb);
320 if (rc == 0) {
321 sysfs_read(CPU4_HISPEED_FREQ_PATH, samsung_pwr->cpu4_hispeed_freq,
322 sizeof(samsung_pwr->cpu4_hispeed_freq));
323 sysfs_read(CPU4_MAX_FREQ_PATH, samsung_pwr->cpu4_max_freq,
324 sizeof(samsung_pwr->cpu4_max_freq));
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100325 ALOGV("%s: CPU 4 hispeed freq: %s", __func__, samsung_pwr->cpu4_hispeed_freq);
326 ALOGV("%s: CPU 4 max freq: %s", __func__, samsung_pwr->cpu4_max_freq);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100327 }
328}
329
330static void init_touch_input_power_path(struct samsung_power_module *samsung_pwr)
331{
332 char dir[1024];
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100333 uint32_t i;
334
335 for (i = 0; i < 20; i++) {
336 snprintf(dir, sizeof(dir), "/sys/class/input/input%d", i);
337 find_input_nodes(samsung_pwr, dir);
338 }
339}
340
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100341static void samsung_power_init(struct power_module *module)
342{
343 struct samsung_power_module *samsung_pwr = (struct samsung_power_module *) module;
344
345 init_cpufreqs(samsung_pwr);
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100346
347 boostpulse_open(samsung_pwr);
348
Christopher N. Hesse65c65bd2017-03-07 23:01:12 +0100349 samsung_pwr->touchscreen_power_path = NULL;
350 samsung_pwr->touchkey_power_path = NULL;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100351 init_touch_input_power_path(samsung_pwr);
352}
353
Christopher N. Hessef6296722017-01-16 22:47:11 +0100354/**********************************************************
355 *** API FUNCTIONS
356 ***
357 *** Refer to power.h for documentation.
358 **********************************************************/
359
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100360static void samsung_power_set_interactive(struct power_module *module, int on)
361{
362 struct samsung_power_module *samsung_pwr = (struct samsung_power_module *) module;
363 struct stat sb;
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100364 int panel_brightness;
365 char button_state[2];
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100366 int rc;
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100367 static bool touchkeys_blocked = false;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100368
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100369 ALOGV("power_set_interactive: %d", on);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100370
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100371 /*
372 * Do not disable any input devices if the screen is on but we are in a non-interactive
373 * state.
374 */
Christopher N. Hesse3360b092016-07-11 15:48:35 +0200375 if (!on) {
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100376 panel_brightness = get_cur_panel_brightness();
377 if (panel_brightness < 0) {
378 ALOGE("%s: Failed to read panel brightness", __func__);
379 } else if (panel_brightness > 0) {
Christopher N. Hesse3360b092016-07-11 15:48:35 +0200380 ALOGV("%s: Moving to non-interactive state, but screen is still on,"
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100381 " not disabling input devices", __func__);
Christopher N. Hesse3360b092016-07-11 15:48:35 +0200382 goto out;
383 }
384 }
385
Paul Keith5e4fbe02017-04-21 21:34:17 -0500386 /* Sanity check the touchscreen path */
387 if (samsung_pwr->touchscreen_power_path) {
388 sysfs_write(samsung_pwr->touchscreen_power_path, on ? "1" : "0");
389 }
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100390
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100391 /* Bail out if the device does not have touchkeys */
392 if (samsung_pwr->touchkey_power_path == NULL) {
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100393 goto out;
394 }
395
396 if (!on) {
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100397 rc = sysfs_read(samsung_pwr->touchkey_power_path, button_state, ARRAY_SIZE(button_state));
398 if (rc < 0) {
399 ALOGE("%s: Failed to read touchkey state", __func__);
400 goto out;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100401 }
Christopher N. Hessed9106e92017-03-04 01:05:14 +0100402 /*
403 * If button_state is 0, the keys have been disabled by another component
404 * (for example cmhw), which means we don't want them to be enabled when resuming
405 * from suspend.
406 */
407 if (button_state[0] == '0') {
408 touchkeys_blocked = true;
409 } else {
410 touchkeys_blocked = false;
411 }
412 }
413
414 if (!touchkeys_blocked) {
415 sysfs_write(samsung_pwr->touchkey_power_path, on ? "1" : "0");
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100416 }
417
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100418out:
Christopher N. Hesse63b5bd72017-05-29 20:45:14 +0200419 sysfs_write(CPU0_IO_IS_BUSY_PATH, on ? "1" : "0");
420 rc = stat(CPU4_IO_IS_BUSY_PATH, &sb);
421 if (rc == 0) {
422 sysfs_write(CPU4_IO_IS_BUSY_PATH, on ? "1" : "0");
423 }
424
Christopher N. Hesse354f7132017-03-04 01:06:22 +0100425 ALOGV("power_set_interactive: %d done", on);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100426}
427
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100428static void samsung_power_hint(struct power_module *module,
429 power_hint_t hint,
430 void *data)
431{
432 struct samsung_power_module *samsung_pwr = (struct samsung_power_module *) module;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100433 int len;
434
Christopher N. Hesse15b63092017-03-12 17:04:53 +0100435 /* Bail out if low-power mode is active */
Christopher N. Hesse5eca5aa2017-04-26 21:42:10 +0200436 if (current_power_profile == PROFILE_POWER_SAVE && hint != POWER_HINT_LOW_POWER
437 && hint != POWER_HINT_SET_PROFILE) {
Christopher N. Hesse15b63092017-03-12 17:04:53 +0100438 ALOGW("%s: PROFILE_POWER_SAVE active, ignoring hint %d", __func__, hint);
439 return;
440 }
441
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100442 switch (hint) {
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100443 case POWER_HINT_VSYNC:
444 ALOGV("%s: POWER_HINT_VSYNC", __func__);
445 break;
446 case POWER_HINT_INTERACTION:
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100447 ALOGV("%s: POWER_HINT_INTERACTION", __func__);
Christopher N. Hessef21fbdb2017-03-04 01:41:58 +0100448 send_boostpulse(samsung_pwr->boostpulse_fd);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100449 break;
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100450 case POWER_HINT_LOW_POWER:
451 ALOGV("%s: POWER_HINT_LOW_POWER", __func__);
Christopher N. Hesse3fa2b692017-04-05 18:52:48 +0200452 set_power_profile(samsung_pwr, data ? PROFILE_POWER_SAVE : PROFILE_BALANCED);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100453 break;
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100454 case POWER_HINT_LAUNCH:
Christopher N. Hesse3fa2b692017-04-05 18:52:48 +0200455 ALOGV("%s: POWER_HINT_LAUNCH", __func__);
456 send_boostpulse(samsung_pwr->boostpulse_fd);
457 break;
Christopher N. Hesse5fada9b2017-01-16 23:39:48 +0100458 case POWER_HINT_CPU_BOOST:
Christopher N. Hesse3fa2b692017-04-05 18:52:48 +0200459 ALOGV("%s: POWER_HINT_CPU_BOOST", __func__);
Christopher N. Hesse5fada9b2017-01-16 23:39:48 +0100460 boost((*(int32_t *)data));
461 break;
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100462 case POWER_HINT_SET_PROFILE:
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100463 ALOGV("%s: POWER_HINT_SET_PROFILE", __func__);
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100464 int profile = *((intptr_t *)data);
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100465 set_power_profile(samsung_pwr, profile);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100466 break;
Christopher N. Hessef9b8e832017-01-17 00:04:45 +0100467 case POWER_HINT_DISABLE_TOUCH:
468 ALOGV("%s: POWER_HINT_DISABLE_TOUCH", __func__);
Christopher N. Hesse3fa2b692017-04-05 18:52:48 +0200469 sysfs_write(samsung_pwr->touchscreen_power_path, data ? "0" : "1");
Christopher N. Hessef9b8e832017-01-17 00:04:45 +0100470 break;
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100471 default:
Christopher N. Hesse2981f792017-03-12 17:08:47 +0100472 ALOGW("%s: Unknown power hint: %d", __func__, hint);
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100473 break;
474 }
475}
476
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100477static int samsung_get_feature(struct power_module *module __unused,
478 feature_t feature)
479{
480 if (feature == POWER_FEATURE_SUPPORTED_PROFILES) {
Christopher N. Hesse58f2ca02017-01-17 00:01:15 +0100481 return PROFILE_MAX;
Andreas Schneiderf15d7f42016-02-03 10:43:47 +0100482 }
483
484 return -1;
485}
486
Christopher N. Hesse1c474662016-11-18 18:59:06 +0100487static void samsung_set_feature(struct power_module *module, feature_t feature, int state __unused)
Christopher N. Hessee480d892016-06-22 23:04:39 +0200488{
489 struct samsung_power_module *samsung_pwr = (struct samsung_power_module *) module;
490
491 switch (feature) {
ishantvivek987dcca2016-11-21 06:05:47 +0000492#ifdef TARGET_TAP_TO_WAKE_NODE
Christopher N. Hessee480d892016-06-22 23:04:39 +0200493 case POWER_FEATURE_DOUBLE_TAP_TO_WAKE:
494 ALOGV("%s: %s double tap to wake", __func__, state ? "enabling" : "disabling");
ishantvivek987dcca2016-11-21 06:05:47 +0000495 sysfs_write(TARGET_TAP_TO_WAKE_NODE, state > 0 ? "1" : "0");
Christopher N. Hessee480d892016-06-22 23:04:39 +0200496 break;
497#endif
498 default:
499 break;
500 }
501}
502
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100503static struct hw_module_methods_t power_module_methods = {
504 .open = NULL,
505};
506
507struct samsung_power_module HAL_MODULE_INFO_SYM = {
508 .base = {
509 .common = {
510 .tag = HARDWARE_MODULE_TAG,
511 .module_api_version = POWER_MODULE_API_VERSION_0_2,
512 .hal_api_version = HARDWARE_HAL_API_VERSION,
513 .id = POWER_HARDWARE_MODULE_ID,
514 .name = "Samsung Power HAL",
Christopher N. Hesseaa75be42017-01-16 22:47:59 +0100515 .author = "The LineageOS Project",
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100516 .methods = &power_module_methods,
517 },
518
519 .init = samsung_power_init,
520 .setInteractive = samsung_power_set_interactive,
521 .powerHint = samsung_power_hint,
Christopher N. Hessee480d892016-06-22 23:04:39 +0200522 .getFeature = samsung_get_feature,
523 .setFeature = samsung_set_feature
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100524 },
525
526 .lock = PTHREAD_MUTEX_INITIALIZER,
527 .boostpulse_fd = -1,
Christopher N. Hessede5e3c62015-12-21 21:28:23 +0100528};