Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 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 | #include <errno.h> |
| 17 | #include <string.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <sys/stat.h> |
| 20 | #include <fcntl.h> |
| 21 | |
| 22 | #define LOG_TAG "Legacy PowerHAL" |
| 23 | #include <utils/Log.h> |
| 24 | |
| 25 | #include <hardware/hardware.h> |
| 26 | #include <hardware/power.h> |
| 27 | |
| 28 | /* |
| 29 | * This module implements the legacy interface for requesting early |
| 30 | * suspend and late resume |
| 31 | */ |
| 32 | |
| 33 | #define LEGACY_SYS_POWER_STATE "/sys/power/state" |
| 34 | |
| 35 | static int sPowerStatefd; |
| 36 | static const char *pwr_states[] = { "mem", "on" }; |
| 37 | |
| 38 | static void power_init(struct power_module *module) |
| 39 | { |
| 40 | char buf[80]; |
| 41 | |
| 42 | sPowerStatefd = open(LEGACY_SYS_POWER_STATE, O_RDWR); |
| 43 | |
| 44 | if (sPowerStatefd < 0) { |
| 45 | strerror_r(errno, buf, sizeof(buf)); |
| 46 | ALOGE("Error opening %s: %s\n", LEGACY_SYS_POWER_STATE, buf); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | static void power_set_interactive(struct power_module *module, int on) |
| 51 | { |
| 52 | char buf[80]; |
| 53 | int len; |
| 54 | |
| 55 | len = write(sPowerStatefd, pwr_states[!!on], strlen(pwr_states[!!on])); |
| 56 | if (len < 0) { |
| 57 | strerror_r(errno, buf, sizeof(buf)); |
| 58 | ALOGE("Error writing to %s: %s\n", LEGACY_SYS_POWER_STATE, buf); |
| 59 | } |
| 60 | } |
| 61 | |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 62 | static void power_hint(struct power_module *module, power_hint_t hint, |
| 63 | void *data) { |
| 64 | switch (hint) { |
| 65 | default: |
| 66 | break; |
| 67 | } |
| 68 | } |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 69 | |
| 70 | static struct hw_module_methods_t power_module_methods = { |
| 71 | .open = NULL, |
| 72 | }; |
| 73 | |
| 74 | struct power_module HAL_MODULE_INFO_SYM = { |
| 75 | .common = { |
| 76 | .tag = HARDWARE_MODULE_TAG, |
Mathias Agopian | 5cb1de8 | 2012-04-26 19:49:40 -0700 | [diff] [blame^] | 77 | .module_api_version = POWER_MODULE_API_VERSION_0_2, |
| 78 | .hal_api_version = HARDWARE_HAL_API_VERSION, |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 79 | .id = POWER_HARDWARE_MODULE_ID, |
| 80 | .name = "Default Power HAL", |
| 81 | .author = "The Android Open Source Project", |
| 82 | .methods = &power_module_methods, |
| 83 | }, |
| 84 | |
| 85 | .init = power_init, |
| 86 | .setInteractive = power_set_interactive, |
Todd Poynor | 2f143fb | 2012-04-24 13:39:15 -0700 | [diff] [blame] | 87 | .powerHint = power_hint, |
Todd Poynor | c82792c | 2012-01-10 00:32:42 -0800 | [diff] [blame] | 88 | }; |