blob: 78a9f1ec497a8ecd18695cb849ca01c4d6a47c58 [file] [log] [blame]
Pawit Pornkitprasan5bff9ac2012-09-25 21:17:58 +07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 * Copyright (C) 2012 The CyanogenMod Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17#include <errno.h>
18#include <string.h>
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <fcntl.h>
22
23#define LOG_TAG "PowerHAL"
24#include <cutils/properties.h>
25#include <utils/Log.h>
26
27#include <hardware/hardware.h>
28#include <hardware/power.h>
29
30#define BOOSTPULSE_PATH "/sys/devices/system/cpu/cpufreq/ondemand/boostpulse"
Pawit Pornkitprasan5bff9ac2012-09-25 21:17:58 +070031
32struct s5pc110_power_module {
33 struct power_module base;
34 pthread_mutex_t lock;
35 int boostpulse_fd;
36 int boostpulse_warned;
Pawit Pornkitprasan5bff9ac2012-09-25 21:17:58 +070037};
38
Pawit Pornkitprasan5bff9ac2012-09-25 21:17:58 +070039static int boostpulse_open(struct s5pc110_power_module *s5pc110)
40{
41 char buf[80];
42
43 pthread_mutex_lock(&s5pc110->lock);
44
45 if (s5pc110->boostpulse_fd < 0) {
46 s5pc110->boostpulse_fd = open(BOOSTPULSE_PATH, O_WRONLY);
47
48 if (s5pc110->boostpulse_fd < 0) {
49 if (!s5pc110->boostpulse_warned) {
50 strerror_r(errno, buf, sizeof(buf));
51 ALOGE("Error opening %s: %s\n", BOOSTPULSE_PATH, buf);
52 s5pc110->boostpulse_warned = 1;
53 }
54 }
55 }
56
57 pthread_mutex_unlock(&s5pc110->lock);
58 return s5pc110->boostpulse_fd;
59}
60
61static void s5pc110_power_hint(struct power_module *module, power_hint_t hint,
62 void *data)
63{
64 struct s5pc110_power_module *s5pc110 = (struct s5pc110_power_module *) module;
65 char buf[80];
66 int len;
67 int duration = 1;
68
69 switch (hint) {
70 case POWER_HINT_INTERACTION:
71 case POWER_HINT_CPU_BOOST:
72 if (boostpulse_open(s5pc110) >= 0) {
73 if (data != NULL)
74 duration = (int) data;
75
76 snprintf(buf, sizeof(buf), "%d", duration);
77 len = write(s5pc110->boostpulse_fd, buf, strlen(buf));
78
79 if (len < 0) {
80 strerror_r(errno, buf, sizeof(buf));
81 ALOGE("Error writing to %s: %s\n", BOOSTPULSE_PATH, buf);
82 }
83 }
84 break;
85
86 case POWER_HINT_VSYNC:
87 break;
88
89 default:
90 break;
91 }
92}
93
94static void s5pc110_power_set_interactive(struct power_module *module, int on)
95{
Pawit Pornkitprasan76a153a2012-09-30 18:24:57 +070096 return;
Pawit Pornkitprasan5bff9ac2012-09-25 21:17:58 +070097}
98
99static void s5pc110_power_init(struct power_module *module)
100{
Pawit Pornkitprasan76a153a2012-09-30 18:24:57 +0700101 return;
Pawit Pornkitprasan5bff9ac2012-09-25 21:17:58 +0700102}
103
104static struct hw_module_methods_t power_module_methods = {
105 .open = NULL,
106};
107
108struct s5pc110_power_module HAL_MODULE_INFO_SYM = {
109 base: {
110 common: {
111 tag: HARDWARE_MODULE_TAG,
112 module_api_version: POWER_MODULE_API_VERSION_0_2,
113 hal_api_version: HARDWARE_HAL_API_VERSION,
114 id: POWER_HARDWARE_MODULE_ID,
115 name: "S5PC110 Power HAL",
116 author: "The Android Open Source Project",
117 methods: &power_module_methods,
118 },
119 init: s5pc110_power_init,
120 setInteractive: s5pc110_power_set_interactive,
121 powerHint: s5pc110_power_hint,
122 },
123
124 lock: PTHREAD_MUTEX_INITIALIZER,
125 boostpulse_fd: -1,
126 boostpulse_warned: 0,
127};