blob: 01d9cda3ebc634309b604513c8877090e9276989
1 | /* |
2 | * Copyright (C) 2012 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 | |
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 <utils/Log.h> |
25 | |
26 | #include <hardware/hardware.h> |
27 | #include <hardware/power.h> |
28 | #define DEBUG 1 |
29 | |
30 | #define MP_GPU_CMD "/sys/class/mpgpu/mpgpucmd" |
31 | #define EARLY_SUSPEND_TRIGGER "/sys/power/early_suspend_trigger" |
32 | |
33 | struct private_power_module { |
34 | power_module_t base; |
35 | int gpuFp; |
36 | int suspendFp; |
37 | }; |
38 | |
39 | namespace android { |
40 | namespace amlogic { |
41 | |
42 | static void init (struct power_module *module) { |
43 | } |
44 | |
45 | static void setInteractive (struct power_module *module, int on) { |
46 | ALOGI("setInteractive ineractive:%s", (on==1)?"yes":"no"); |
47 | |
48 | struct private_power_module *pm = (struct private_power_module *) module; |
49 | if (pm->suspendFp < 0) { |
50 | pm->suspendFp = open(EARLY_SUSPEND_TRIGGER, O_RDWR, 0644); |
51 | if (pm->suspendFp < 0) { |
52 | ALOGE("open %s fail, %s", EARLY_SUSPEND_TRIGGER, strerror(errno)); |
53 | return; |
54 | } |
55 | } |
56 | |
57 | //resume |
58 | if (1 == on) { |
59 | write(pm->suspendFp, "0", 1); |
60 | } |
61 | else { |
62 | write(pm->suspendFp, "1", 1); |
63 | } |
64 | } |
65 | |
66 | static void powerHint(struct power_module *module, power_hint_t hint, void *data) { |
67 | |
68 | struct private_power_module *pm = (struct private_power_module *) module; |
69 | |
70 | const char *val = "preheat"; |
71 | static int bytes = 7; |
72 | |
73 | if (pm->gpuFp < 0) { |
74 | pm->gpuFp = open(MP_GPU_CMD, O_RDWR, 0644); |
75 | if (pm->gpuFp < 0) { |
76 | ALOGE("open %s fail, %s", MP_GPU_CMD, strerror(errno)); |
77 | return; |
78 | } |
79 | } |
80 | |
81 | switch (hint) { |
82 | case POWER_HINT_INTERACTION: |
83 | if (pm->gpuFp >= 0) { |
84 | int len = write(pm->gpuFp, val, bytes); |
85 | if (DEBUG) { |
86 | ALOGD("%s: write sucessfull, fd is %d\n", __FUNCTION__, pm->gpuFp); |
87 | } |
88 | |
89 | if (len != bytes) |
90 | ALOGE("write preheat faile"); |
91 | } |
92 | break; |
93 | |
94 | default: |
95 | break; |
96 | } |
97 | } |
98 | |
99 | /* |
100 | static void setFeature (struct power_module *module, feature_t feature, int state) { |
101 | |
102 | } |
103 | |
104 | static int getPlatformLowPowerStats (struct power_module *module, |
105 | power_state_platform_sleep_state_t *list) { |
106 | |
107 | ALOGI("getPlatformLowPowerStats"); |
108 | return 0; |
109 | } |
110 | |
111 | static ssize_t geNumberOfPlatformModes (struct power_module *module) { |
112 | return 0; |
113 | } |
114 | |
115 | static int getVoterList (struct power_module *module, size_t *voter) { |
116 | return 0; |
117 | } |
118 | */ |
119 | |
120 | } // namespace amlogic |
121 | } // namespace android |
122 | |
123 | |
124 | static struct hw_module_methods_t power_module_methods = { |
125 | .open = NULL, |
126 | }; |
127 | |
128 | struct private_power_module HAL_MODULE_INFO_SYM = { |
129 | .base = { |
130 | .common = { |
131 | .tag = HARDWARE_MODULE_TAG, |
132 | .module_api_version = POWER_MODULE_API_VERSION_0_2, |
133 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
134 | .id = POWER_HARDWARE_MODULE_ID, |
135 | .name = "AML Power HAL", |
136 | .author = "aml", |
137 | .methods = &power_module_methods, |
138 | }, |
139 | .init = android::amlogic::init, |
140 | .setInteractive = android::amlogic::setInteractive, |
141 | .powerHint = android::amlogic::powerHint, |
142 | //.setFeature = android::amlogic::setFeature, |
143 | //.get_platform_low_power_stats = android::amlogic::getPlatformLowPowerStats, |
144 | //.get_number_of_platform_modes = android::amlogic::geNumberOfPlatformModes, |
145 | //.get_voter_list = android::amlogic::getVoterList, |
146 | }, |
147 | .gpuFp = -1, |
148 | .suspendFp = -1, |
149 | }; |
150 |