blob: f9a3ddb62bcc4bf63b8b88314537847521dc0df9 [file] [log] [blame]
John Stultz7266c5f2016-06-09 14:18:57 -07001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Based on the FlounderPowerHAL
17 */
18
19#include <dirent.h>
20#include <errno.h>
21#include <string.h>
22#include <sys/types.h>
23#include <sys/stat.h>
24#include <fcntl.h>
25#include <unistd.h>
26#include <stdlib.h>
27#include <stdbool.h>
John Stultz4c1a82b2016-08-18 14:49:01 -070028#include <pthread.h>
29#include <semaphore.h>
John Stultz7266c5f2016-06-09 14:18:57 -070030#include <cutils/properties.h>
31//#define LOG_NDEBUG 0
32
33#define LOG_TAG "HiKeyPowerHAL"
vishal7d9fede2018-06-05 12:43:23 +053034#include <log/log.h>
John Stultz7266c5f2016-06-09 14:18:57 -070035
36#include <hardware/hardware.h>
37#include <hardware/power.h>
38
John Stultz17e11242017-03-14 18:14:24 -070039#define SCHEDTUNE_BOOST_PATH "/dev/stune/top-app/schedtune.boost"
John Stultz0e785a22017-05-23 13:01:56 -070040#define SCHEDTUNE_BOOST_VAL_PROP "ro.config.schetune.touchboost.value"
41#define SCHEDTUNE_BOOST_TIME_PROP "ro.config.schetune.touchboost.time_ns"
42
43#define SCHEDTUNE_BOOST_VAL_DEFAULT "40"
44
45char schedtune_boost_norm[PROPERTY_VALUE_MAX] = "10";
46char schedtune_boost_interactive[PROPERTY_VALUE_MAX] = SCHEDTUNE_BOOST_VAL_DEFAULT;
47long long schedtune_boost_time_ns = 1000000000LL;
48
Leo Yanf0e78bf2017-11-28 22:01:58 +080049#define DEVFREQ_DDR_MIN_FREQ_PATH_PROP \
50 "ro.config.devfreq.ddr.min_freq.path"
51#define DEVFREQ_DDR_MIN_FREQ_BOOST_PROP \
52 "ro.config.devfreq.ddr.min_freq.boost"
53
54char devfreq_ddr_min_path[PROPERTY_VALUE_MAX];
55char devfreq_ddr_min_orig[PROPERTY_VALUE_MAX];
56char devfreq_ddr_min_boost[PROPERTY_VALUE_MAX];
57
58#define DEVFREQ_GPU_MIN_FREQ_PATH_PROP \
59 "ro.config.devfreq.gpu.min_freq.path"
60#define DEVFREQ_GPU_MIN_FREQ_BOOST_PROP \
61 "ro.config.devfreq.gpu.min_freq.boost"
62
63char devfreq_gpu_min_path[PROPERTY_VALUE_MAX];
64char devfreq_gpu_min_orig[PROPERTY_VALUE_MAX];
65char devfreq_gpu_min_boost[PROPERTY_VALUE_MAX];
66
John Stultz127e1cc2016-08-18 12:20:40 -070067#define INTERACTIVE_BOOSTPULSE_PATH "/sys/devices/system/cpu/cpufreq/interactive/boostpulse"
68#define INTERACTIVE_IO_IS_BUSY_PATH "/sys/devices/system/cpu/cpufreq/interactive/io_is_busy"
John Stultz7266c5f2016-06-09 14:18:57 -070069
70struct hikey_power_module {
71 struct power_module base;
72 pthread_mutex_t lock;
John Stultz4c1a82b2016-08-18 14:49:01 -070073 /* interactive gov boost values */
John Stultz7266c5f2016-06-09 14:18:57 -070074 int boostpulse_fd;
75 int boostpulse_warned;
John Stultz4c1a82b2016-08-18 14:49:01 -070076 /* EAS schedtune values */
77 int schedtune_boost_fd;
78 long long deboost_time;
79 sem_t signal_lock;
John Stultz7266c5f2016-06-09 14:18:57 -070080};
81
John Stultzed771732017-05-23 17:39:53 -070082
John Stultz7266c5f2016-06-09 14:18:57 -070083static bool low_power_mode = false;
84
John Stultzed771732017-05-23 17:39:53 -070085
86#define CPUFREQ_CLUST_MAX_FREQ_PATH_PROP "ro.config.cpufreq.max_freq.cluster"
87#define CPUFREQ_CLUST_LOW_POWER_MAX_FREQ_PROP "ro.config.cpufreq.low_power_max.cluster"
88#define CPUFREQ_CLUST0_MAX_FREQ_PATH_DEFAULT "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq"
89
90#define NR_CLUSTERS 4
91static int max_clusters = 1;
92static struct hikey_cpufreq_t {
93 char path[PROPERTY_VALUE_MAX];
94 char normal_max[PROPERTY_VALUE_MAX];
95 char low_power_max[PROPERTY_VALUE_MAX];
96} hikey_cpufreq_clusters[NR_CLUSTERS];
John Stultz7266c5f2016-06-09 14:18:57 -070097
John Stultze150ab32016-08-18 14:04:34 -070098#define container_of(addr, struct_name, field_name) \
99 ((struct_name *)((char *)(addr) - offsetof(struct_name, field_name)))
100
101
Dmitry Shmidtcc147582016-11-07 13:13:34 -0800102static int sysfs_write(const char *path, char *s)
John Stultz7266c5f2016-06-09 14:18:57 -0700103{
104 char buf[80];
105 int len;
106 int fd = open(path, O_WRONLY);
107
108 if (fd < 0) {
109 strerror_r(errno, buf, sizeof(buf));
110 ALOGE("Error opening %s: %s\n", path, buf);
Dmitry Shmidtcc147582016-11-07 13:13:34 -0800111 return fd;
John Stultz7266c5f2016-06-09 14:18:57 -0700112 }
113
114 len = write(fd, s, strlen(s));
115 if (len < 0) {
116 strerror_r(errno, buf, sizeof(buf));
117 ALOGE("Error writing to %s: %s\n", path, buf);
118 }
119
120 close(fd);
Dmitry Shmidtcc147582016-11-07 13:13:34 -0800121 return len;
John Stultz7266c5f2016-06-09 14:18:57 -0700122}
123
John Stultzed771732017-05-23 17:39:53 -0700124static int sysfs_read(const char *path, char *s, int slen)
125{
126 int len;
127 int fd = open(path, O_RDONLY);
128
129 if (fd < 0) {
130 ALOGE("Error opening %s\n", path);
131 return fd;
132 }
133
134 len = read(fd, s, slen);
135 if (len < 0) {
136 ALOGE("Error reading %s\n", path);
137 }
138
139 close(fd);
140 return len;
141}
142
John Stultz4c1a82b2016-08-18 14:49:01 -0700143#define NSEC_PER_SEC 1000000000LL
144static long long gettime_ns(void)
145{
146 struct timespec ts;
147
148 clock_gettime(CLOCK_MONOTONIC, &ts);
149 return ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
150}
151
152static void nanosleep_ns(long long ns)
153{
154 struct timespec ts;
155 ts.tv_sec = ns/NSEC_PER_SEC;
156 ts.tv_nsec = ns%NSEC_PER_SEC;
157 nanosleep(&ts, NULL);
158}
159
John Stultzc5793712016-08-18 14:00:49 -0700160/*[interactive cpufreq gov funcs]*********************************************/
John Stultze150ab32016-08-18 14:04:34 -0700161static void interactive_power_init(struct hikey_power_module __unused *hikey)
John Stultz7266c5f2016-06-09 14:18:57 -0700162{
Dmitry Shmidtcc147582016-11-07 13:13:34 -0800163 if (sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/timer_rate",
164 "20000") < 0)
165 return;
John Stultz7266c5f2016-06-09 14:18:57 -0700166 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/timer_slack",
167 "20000");
168 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/min_sample_time",
169 "80000");
170 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/hispeed_freq",
171 "1200000");
172 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/go_hispeed_load",
173 "99");
174 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/target_loads",
175 "65 729000:75 960000:85");
176 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/above_hispeed_delay",
177 "20000");
178 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/boostpulse_duration",
179 "1000000");
180 sysfs_write("/sys/devices/system/cpu/cpufreq/interactive/io_is_busy", "0");
181
John Stultz7266c5f2016-06-09 14:18:57 -0700182}
183
John Stultz5e1546b2016-08-18 11:56:31 -0700184static int interactive_boostpulse(struct hikey_power_module *hikey)
185{
186 char buf[80];
187 int len;
188
John Stultz64b54ca2016-08-18 15:01:33 -0700189 if (hikey->boostpulse_fd < 0)
John Stultz127e1cc2016-08-18 12:20:40 -0700190 hikey->boostpulse_fd = open(INTERACTIVE_BOOSTPULSE_PATH, O_WRONLY);
John Stultz5e1546b2016-08-18 11:56:31 -0700191
John Stultz64b54ca2016-08-18 15:01:33 -0700192 if (hikey->boostpulse_fd < 0) {
193 if (!hikey->boostpulse_warned) {
John Stultz5e1546b2016-08-18 11:56:31 -0700194 strerror_r(errno, buf, sizeof(buf));
John Stultz127e1cc2016-08-18 12:20:40 -0700195 ALOGE("Error opening %s: %s\n", INTERACTIVE_BOOSTPULSE_PATH,
John Stultz64b54ca2016-08-18 15:01:33 -0700196 buf);
197 hikey->boostpulse_warned = 1;
John Stultz5e1546b2016-08-18 11:56:31 -0700198 }
John Stultz64b54ca2016-08-18 15:01:33 -0700199 return hikey->boostpulse_fd;
200 }
201
202 len = write(hikey->boostpulse_fd, "1", 1);
203 if (len < 0) {
204 strerror_r(errno, buf, sizeof(buf));
205 ALOGE("Error writing to %s: %s\n",
John Stultz127e1cc2016-08-18 12:20:40 -0700206 INTERACTIVE_BOOSTPULSE_PATH, buf);
John Stultz64b54ca2016-08-18 15:01:33 -0700207 return -1;
John Stultz5e1546b2016-08-18 11:56:31 -0700208 }
209 return 0;
210}
211
Leo Yanf0e78bf2017-11-28 22:01:58 +0800212static void
213hikey_devfreq_set_interactive(struct hikey_power_module __unused *hikey, int on)
214{
215 if (!on || low_power_mode) {
216 if (devfreq_ddr_min_path[0] != '\0')
217 sysfs_write(devfreq_ddr_min_path, devfreq_ddr_min_orig);
218
219 if (devfreq_gpu_min_path[0] != '\0')
220 sysfs_write(devfreq_gpu_min_path, devfreq_gpu_min_orig);
221 } else {
222 if (devfreq_ddr_min_path[0] != '\0')
223 sysfs_write(devfreq_ddr_min_path, devfreq_ddr_min_boost);
224
225 if (devfreq_gpu_min_path[0] != '\0')
226 sysfs_write(devfreq_gpu_min_path, devfreq_gpu_min_boost);
227 }
228}
229
230static void hikey_devfreq_init(struct hikey_power_module __unused *hikey)
231{
232 property_get(DEVFREQ_DDR_MIN_FREQ_PATH_PROP, devfreq_ddr_min_path, "");
233 if (devfreq_ddr_min_path[0] != '\0') {
234 sysfs_read(devfreq_ddr_min_path, devfreq_ddr_min_orig,
235 PROPERTY_VALUE_MAX);
236 property_get(DEVFREQ_DDR_MIN_FREQ_BOOST_PROP,
237 devfreq_ddr_min_boost, "");
238 }
239
240 property_get(DEVFREQ_GPU_MIN_FREQ_PATH_PROP, devfreq_gpu_min_path, "");
241 if (devfreq_gpu_min_path[0] != '\0') {
242 sysfs_read(devfreq_gpu_min_path, devfreq_gpu_min_orig,
243 PROPERTY_VALUE_MAX);
244 property_get(DEVFREQ_GPU_MIN_FREQ_BOOST_PROP,
245 devfreq_gpu_min_boost, "");
246 }
247}
248
John Stultz4c1a82b2016-08-18 14:49:01 -0700249/*[schedtune functions]*******************************************************/
John Stultzc5793712016-08-18 14:00:49 -0700250
John Stultz4c1a82b2016-08-18 14:49:01 -0700251int schedtune_sysfs_boost(struct hikey_power_module *hikey, char* booststr)
252{
253 char buf[80];
254 int len;
255
256 if (hikey->schedtune_boost_fd < 0)
257 return hikey->schedtune_boost_fd;
258
John Stultz0e785a22017-05-23 13:01:56 -0700259 len = write(hikey->schedtune_boost_fd, booststr, strlen(booststr));
John Stultz4c1a82b2016-08-18 14:49:01 -0700260 if (len < 0) {
261 strerror_r(errno, buf, sizeof(buf));
262 ALOGE("Error writing to %s: %s\n", SCHEDTUNE_BOOST_PATH, buf);
263 }
264 return len;
265}
266
267static void* schedtune_deboost_thread(void* arg)
268{
269 struct hikey_power_module *hikey = (struct hikey_power_module *)arg;
270
271 while(1) {
272 sem_wait(&hikey->signal_lock);
273 while(1) {
274 long long now, sleeptime = 0;
275
276 pthread_mutex_lock(&hikey->lock);
277 now = gettime_ns();
278 if (hikey->deboost_time > now) {
279 sleeptime = hikey->deboost_time - now;
280 pthread_mutex_unlock(&hikey->lock);
281 nanosleep_ns(sleeptime);
282 continue;
283 }
284
John Stultz0e785a22017-05-23 13:01:56 -0700285 schedtune_sysfs_boost(hikey, schedtune_boost_norm);
Leo Yanf0e78bf2017-11-28 22:01:58 +0800286 hikey_devfreq_set_interactive(hikey, 0);
John Stultz4c1a82b2016-08-18 14:49:01 -0700287 hikey->deboost_time = 0;
288 pthread_mutex_unlock(&hikey->lock);
289 break;
290 }
291 }
292 return NULL;
293}
294
295static int schedtune_boost(struct hikey_power_module *hikey)
296{
297 long long now;
298
299 if (hikey->schedtune_boost_fd < 0)
300 return hikey->schedtune_boost_fd;
301
302 now = gettime_ns();
303 if (!hikey->deboost_time) {
John Stultz0e785a22017-05-23 13:01:56 -0700304 schedtune_sysfs_boost(hikey, schedtune_boost_interactive);
Leo Yanf0e78bf2017-11-28 22:01:58 +0800305 hikey_devfreq_set_interactive(hikey, 1);
John Stultz4c1a82b2016-08-18 14:49:01 -0700306 sem_post(&hikey->signal_lock);
307 }
John Stultz0e785a22017-05-23 13:01:56 -0700308 hikey->deboost_time = now + schedtune_boost_time_ns;
John Stultz4c1a82b2016-08-18 14:49:01 -0700309
310 return 0;
311}
312
313static void schedtune_power_init(struct hikey_power_module *hikey)
314{
315 char buf[50];
316 pthread_t tid;
317
John Stultz4c1a82b2016-08-18 14:49:01 -0700318 hikey->deboost_time = 0;
319 sem_init(&hikey->signal_lock, 0, 1);
320
John Stultz0e785a22017-05-23 13:01:56 -0700321 hikey->schedtune_boost_fd = open(SCHEDTUNE_BOOST_PATH, O_RDWR);
John Stultz4c1a82b2016-08-18 14:49:01 -0700322 if (hikey->schedtune_boost_fd < 0) {
323 strerror_r(errno, buf, sizeof(buf));
324 ALOGE("Error opening %s: %s\n", SCHEDTUNE_BOOST_PATH, buf);
John Stultz0e785a22017-05-23 13:01:56 -0700325 return;
John Stultz4c1a82b2016-08-18 14:49:01 -0700326 }
327
John Stultz0e785a22017-05-23 13:01:56 -0700328 schedtune_boost_time_ns = property_get_int64(SCHEDTUNE_BOOST_TIME_PROP,
329 1000000000LL);
330 property_get(SCHEDTUNE_BOOST_VAL_PROP, schedtune_boost_interactive,
331 SCHEDTUNE_BOOST_VAL_DEFAULT);
332
333 if (hikey->schedtune_boost_fd >= 0) {
334 size_t len = read(hikey->schedtune_boost_fd, schedtune_boost_norm,
335 PROPERTY_VALUE_MAX);
336 if (len <= 0)
337 ALOGE("Error reading normal boost value\n");
338 else if (schedtune_boost_norm[len] == '\n')
339 schedtune_boost_norm[len] = '\0';
340
341 }
342
343 ALOGV("Starting with schedtune boost norm: %s touchboost: %s and boosttime: %lld\n",
344 schedtune_boost_norm, schedtune_boost_interactive, schedtune_boost_time_ns);
345
John Stultz4c1a82b2016-08-18 14:49:01 -0700346 pthread_create(&tid, NULL, schedtune_deboost_thread, hikey);
347}
348
349/*[generic functions]*********************************************************/
John Stultzed771732017-05-23 17:39:53 -0700350
351static void hikey_cpufreq_set_interactive(struct power_module __unused *module, int on)
352{
353 int i;
354
355 /*
356 * Lower maximum frequency when screen is off.
357 */
358 for (i=0; i < max_clusters; i++) {
359 if ((!on || low_power_mode) && hikey_cpufreq_clusters[i].low_power_max[0] != '\0')
360 sysfs_write(hikey_cpufreq_clusters[i].path, hikey_cpufreq_clusters[i].low_power_max);
361 else
362 sysfs_write(hikey_cpufreq_clusters[i].path, hikey_cpufreq_clusters[i].normal_max);
363 }
364 sysfs_write(INTERACTIVE_IO_IS_BUSY_PATH, on ? "1" : "0");
365}
366
367
Dmitry Shmidtb4db15e2017-10-24 16:02:26 -0700368static void hikey_cpufreq_init(struct hikey_power_module __unused *hikey)
John Stultzed771732017-05-23 17:39:53 -0700369{
370 char buf[128];
371 int len, i;
372
373 for (i=0; i < NR_CLUSTERS; i++) {
374 sprintf(buf,"%s%d", CPUFREQ_CLUST_MAX_FREQ_PATH_PROP, i);
375 property_get(buf, hikey_cpufreq_clusters[i].path, "");
376
377 if (hikey_cpufreq_clusters[i].path[0] == '\0') {
378 if (i == 0) {
379 /* In case no property was set, pick cpu0's cluster */
380 strncpy(hikey_cpufreq_clusters[i].path,
381 CPUFREQ_CLUST0_MAX_FREQ_PATH_DEFAULT,
382 PROPERTY_VALUE_MAX);
383 } else
384 break;
385 }
386 sprintf(buf,"%s%d", CPUFREQ_CLUST_LOW_POWER_MAX_FREQ_PROP, i);
387 property_get(buf, hikey_cpufreq_clusters[i].low_power_max, "");
388 len = sysfs_read(hikey_cpufreq_clusters[i].path,
389 hikey_cpufreq_clusters[i].normal_max,
390 PROPERTY_VALUE_MAX);
391 ALOGV("Cluster: %d path: %s low: %s norm: %s\n", i,
392 hikey_cpufreq_clusters[i].path,
393 hikey_cpufreq_clusters[i].low_power_max,
394 hikey_cpufreq_clusters[i].normal_max);
395 }
396 max_clusters = i;
397}
398
John Stultzc5793712016-08-18 14:00:49 -0700399static void hikey_power_init(struct power_module __unused *module)
400{
John Stultze150ab32016-08-18 14:04:34 -0700401 struct hikey_power_module *hikey = container_of(module,
402 struct hikey_power_module, base);
John Stultzed771732017-05-23 17:39:53 -0700403 hikey_cpufreq_init(hikey);
Leo Yanf0e78bf2017-11-28 22:01:58 +0800404 hikey_devfreq_init(hikey);
John Stultze150ab32016-08-18 14:04:34 -0700405 interactive_power_init(hikey);
John Stultz4c1a82b2016-08-18 14:49:01 -0700406 schedtune_power_init(hikey);
407}
408
409static void hikey_hint_interaction(struct hikey_power_module *mod)
410{
411 /* Try interactive cpufreq boosting first */
412 if(!interactive_boostpulse(mod))
413 return;
414 /* Then try EAS schedtune boosting */
415 if(!schedtune_boost(mod))
416 return;
John Stultzc5793712016-08-18 14:00:49 -0700417}
418
John Stultz7266c5f2016-06-09 14:18:57 -0700419static void hikey_power_hint(struct power_module *module, power_hint_t hint,
420 void *data)
421{
John Stultze150ab32016-08-18 14:04:34 -0700422 struct hikey_power_module *hikey = container_of(module,
423 struct hikey_power_module, base);
John Stultz7266c5f2016-06-09 14:18:57 -0700424
425 pthread_mutex_lock(&hikey->lock);
426 switch (hint) {
427 case POWER_HINT_INTERACTION:
John Stultz4c1a82b2016-08-18 14:49:01 -0700428 hikey_hint_interaction(hikey);
John Stultz7266c5f2016-06-09 14:18:57 -0700429 break;
430
431 case POWER_HINT_VSYNC:
432 break;
433
434 case POWER_HINT_LOW_POWER:
John Stultz7266c5f2016-06-09 14:18:57 -0700435 low_power_mode = data;
John Stultzed771732017-05-23 17:39:53 -0700436 hikey_cpufreq_set_interactive(module, 1);
John Stultz7266c5f2016-06-09 14:18:57 -0700437 break;
438
439 default:
440 break;
441 }
442 pthread_mutex_unlock(&hikey->lock);
443}
444
Leo Yan0bf3fb22017-12-14 11:24:02 +0800445static void set_feature(struct power_module __unused *module,
446 feature_t feature, int state)
John Stultzab1f6a72016-08-18 12:28:55 -0700447{
John Stultzab1f6a72016-08-18 12:28:55 -0700448 switch (feature) {
449 default:
Dmitry Shmidt0ea8f4d2016-11-07 12:55:16 -0800450 ALOGW("Error setting the feature %d and state %d, it doesn't exist\n",
451 feature, state);
John Stultzab1f6a72016-08-18 12:28:55 -0700452 break;
453 }
454}
455
Dmitry Shmidt0ea8f4d2016-11-07 12:55:16 -0800456static int power_open(const hw_module_t* __unused module, const char* name,
Ruchi Kandoi96c621c2016-11-03 12:46:10 -0700457 hw_device_t** device)
458{
459 int retval = 0; /* 0 is ok; -1 is error */
460 ALOGD("%s: enter; name=%s", __FUNCTION__, name);
461
462 if (strcmp(name, POWER_HARDWARE_MODULE_ID) == 0) {
John Stultz5af9bdc2017-11-02 21:23:22 -0700463 struct hikey_power_module *dev = (struct hikey_power_module *)calloc(1,
464 sizeof(struct hikey_power_module));
Ruchi Kandoi96c621c2016-11-03 12:46:10 -0700465
466 if (dev) {
467 /* Common hw_device_t fields */
John Stultz5af9bdc2017-11-02 21:23:22 -0700468 dev->base.common.tag = HARDWARE_DEVICE_TAG;
469 dev->base.common.module_api_version = POWER_MODULE_API_VERSION_0_5;
470 dev->base.common.hal_api_version = HARDWARE_HAL_API_VERSION;
Ruchi Kandoi96c621c2016-11-03 12:46:10 -0700471
John Stultz5af9bdc2017-11-02 21:23:22 -0700472 dev->base.init = hikey_power_init;
473 dev->base.powerHint = hikey_power_hint;
474 dev->base.setInteractive = hikey_cpufreq_set_interactive;
475 dev->base.setFeature = set_feature;
Ruchi Kandoi96c621c2016-11-03 12:46:10 -0700476
John Stultz5af9bdc2017-11-02 21:23:22 -0700477 pthread_mutex_init(&dev->lock, NULL);
478 dev->boostpulse_fd = -1;
479 dev->boostpulse_warned = 0;
480
481 *device = (hw_device_t*)&dev->base;
Ruchi Kandoi96c621c2016-11-03 12:46:10 -0700482 } else
483 retval = -ENOMEM;
484 } else {
485 retval = -EINVAL;
486 }
487
488 ALOGD("%s: exit %d", __FUNCTION__, retval);
489 return retval;
490}
491
John Stultz7266c5f2016-06-09 14:18:57 -0700492static struct hw_module_methods_t power_module_methods = {
Ruchi Kandoi96c621c2016-11-03 12:46:10 -0700493 .open = power_open,
John Stultz7266c5f2016-06-09 14:18:57 -0700494};
495
496struct hikey_power_module HAL_MODULE_INFO_SYM = {
Dmitry Shmidt0ea8f4d2016-11-07 12:55:16 -0800497 .base = {
498 .common = {
499 .tag = HARDWARE_MODULE_TAG,
500 .module_api_version = POWER_MODULE_API_VERSION_0_2,
501 .hal_api_version = HARDWARE_HAL_API_VERSION,
502 .id = POWER_HARDWARE_MODULE_ID,
503 .name = "HiKey Power HAL",
504 .author = "The Android Open Source Project",
505 .methods = &power_module_methods,
John Stultz7266c5f2016-06-09 14:18:57 -0700506 },
John Stultz7266c5f2016-06-09 14:18:57 -0700507 },
John Stultz7266c5f2016-06-09 14:18:57 -0700508};