blob: 5df3f9bf71828833988ad7298304b397cf810905
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 0 |
29 | |
30 | struct private_power_module { |
31 | power_module_t base; |
32 | int fp; |
33 | }; |
34 | |
35 | namespace android { |
36 | namespace amlogic { |
37 | |
38 | static void init (struct power_module *module) { |
39 | } |
40 | |
41 | static void setInteractive (struct power_module *module, int on) { |
42 | ALOGI("setInteractive"); |
43 | } |
44 | |
45 | static void powerHint(struct power_module *module, power_hint_t hint, void *data) { |
46 | |
47 | struct private_power_module *pm = (struct private_power_module *) module; |
48 | |
49 | const char *val = "preheat"; |
50 | static int bytes = 7; |
51 | |
52 | if (pm->fp == -1) { |
53 | pm->fp = open("/sys/class/mpgpu/mpgpucmd", O_RDWR, 0644); |
54 | if (DEBUG) { |
55 | ALOGD("open file /sys/class/mpgpu/mpgpucmd,fd is %d", pm->fp); |
56 | } |
57 | } |
58 | |
59 | switch (hint) { |
60 | case POWER_HINT_INTERACTION: |
61 | if (pm->fp >= 0) { |
62 | int len = write(pm->fp, val, bytes); |
63 | if (DEBUG) { |
64 | ALOGD("%s: write sucessfull, fd is %d\n", __FUNCTION__, pm->fp); |
65 | } |
66 | |
67 | if (len != bytes) |
68 | ALOGE("write preheat faile"); |
69 | } |
70 | break; |
71 | |
72 | default: |
73 | break; |
74 | } |
75 | } |
76 | |
77 | /* |
78 | static void setFeature (struct power_module *module, feature_t feature, int state) { |
79 | |
80 | } |
81 | |
82 | static int getPlatformLowPowerStats (struct power_module *module, |
83 | power_state_platform_sleep_state_t *list) { |
84 | |
85 | ALOGI("getPlatformLowPowerStats"); |
86 | return 0; |
87 | } |
88 | |
89 | static ssize_t geNumberOfPlatformModes (struct power_module *module) { |
90 | return 0; |
91 | } |
92 | |
93 | static int getVoterList (struct power_module *module, size_t *voter) { |
94 | return 0; |
95 | } |
96 | */ |
97 | |
98 | } // namespace amlogic |
99 | } // namespace android |
100 | |
101 | |
102 | static struct hw_module_methods_t power_module_methods = { |
103 | .open = NULL, |
104 | }; |
105 | |
106 | struct private_power_module HAL_MODULE_INFO_SYM = { |
107 | .base = { |
108 | .common = { |
109 | .tag = HARDWARE_MODULE_TAG, |
110 | .module_api_version = POWER_MODULE_API_VERSION_0_2, |
111 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
112 | .id = POWER_HARDWARE_MODULE_ID, |
113 | .name = "AML Power HAL", |
114 | .author = "aml", |
115 | .methods = &power_module_methods, |
116 | }, |
117 | .init = android::amlogic::init, |
118 | .setInteractive = android::amlogic::setInteractive, |
119 | .powerHint = android::amlogic::powerHint, |
120 | //.setFeature = android::amlogic::setFeature, |
121 | //.get_platform_low_power_stats = android::amlogic::getPlatformLowPowerStats, |
122 | //.get_number_of_platform_modes = android::amlogic::geNumberOfPlatformModes, |
123 | //.get_voter_list = android::amlogic::getVoterList, |
124 | }, |
125 | .fp = -1, |
126 | }; |
127 |