Aaron Kling | b2b3dd0 | 2015-11-12 09:25:04 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * Copyright (c) 2012-2014, NVIDIA CORPORATION. All rights reserved. |
| 4 | * Copyright (C) 2015 The CyanogenMod Project |
| 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 | |
| 18 | #include "powerhal.h" |
| 19 | |
| 20 | #ifdef ENABLE_SATA_STANDBY_MODE |
| 21 | #include "tegra_sata_hal.h" |
| 22 | |
| 23 | #define FOSTER_E_HDD "/dev/block/sda" |
| 24 | #define HDD_STANDBY_TIMEOUT 60 |
| 25 | #endif |
| 26 | |
| 27 | static struct powerhal_info *pInfo; |
| 28 | static struct input_dev_map input_devs[] = { |
| 29 | {-1, "raydium_ts\n"}, |
| 30 | {-1, "touch\n"}, |
| 31 | {-1, "touch_fusion\n"} |
| 32 | }; |
| 33 | |
| 34 | static void shield_power_init(struct power_module *module) |
| 35 | { |
| 36 | if (!pInfo) |
| 37 | pInfo = (powerhal_info*)malloc(sizeof(powerhal_info)); |
| 38 | pInfo->input_devs = input_devs; |
| 39 | pInfo->input_cnt = sizeof(input_devs)/sizeof(struct input_dev_map); |
| 40 | |
| 41 | common_power_init(module, pInfo); |
| 42 | } |
| 43 | |
| 44 | static void shield_power_set_interactive(struct power_module *module, int on) |
| 45 | { |
| 46 | int error = 0; |
| 47 | |
| 48 | common_power_set_interactive(module, pInfo, on); |
| 49 | |
| 50 | #ifdef ENABLE_SATA_STANDBY_MODE |
| 51 | if (!access(FOSTER_E_HDD, F_OK)) { |
| 52 | /* |
| 53 | * Turn-off Foster HDD at display off |
| 54 | */ |
| 55 | ALOGI("HAL: Display is %s, set HDD to %s standby mode.", on?"on":"off", on?"disable":"enter"); |
| 56 | if (on) { |
| 57 | error = hdd_disable_standby_timer(); |
| 58 | if (error) |
| 59 | ALOGE("HAL: Failed to set standby timer, error: %d", error); |
| 60 | } |
| 61 | else { |
| 62 | error = hdd_set_standby_timer(HDD_STANDBY_TIMEOUT); |
| 63 | if (error) |
| 64 | ALOGE("HAL: Failed to set standby timer, error: %d", error); |
| 65 | } |
| 66 | } |
| 67 | #endif |
| 68 | } |
| 69 | |
| 70 | static void shield_power_hint(struct power_module *module, power_hint_t hint, |
| 71 | void *data) |
| 72 | { |
| 73 | common_power_hint(module, pInfo, hint, data); |
| 74 | } |
| 75 | |
| 76 | static int shield_power_open(__attribute__ ((unused)) const hw_module_t *module, const char *name, |
| 77 | __attribute__ ((unused)) hw_device_t **device) |
| 78 | { |
| 79 | if (strcmp(name, POWER_HARDWARE_MODULE_ID)) |
| 80 | return -EINVAL; |
| 81 | |
| 82 | if (!pInfo) { |
| 83 | pInfo = (powerhal_info*)calloc(1, sizeof(powerhal_info)); |
| 84 | |
| 85 | common_power_open(pInfo); |
| 86 | } |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | static void shield_set_feature(__attribute__ ((unused)) struct power_module *module, feature_t feature, __attribute__ ((unused)) int state) |
| 92 | { |
| 93 | switch (feature) { |
| 94 | case POWER_FEATURE_DOUBLE_TAP_TO_WAKE: |
| 95 | ALOGW("Double tap to wake is not supported\n"); |
| 96 | break; |
| 97 | default: |
| 98 | ALOGW("Error setting the feature, it doesn't exist %d\n", feature); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static struct hw_module_methods_t power_module_methods = { |
| 104 | open: shield_power_open, |
| 105 | }; |
| 106 | |
| 107 | struct power_module HAL_MODULE_INFO_SYM = { |
| 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: "Shield Power HAL", |
| 114 | author: "The CyanogenMod Project", |
| 115 | methods: &power_module_methods, |
| 116 | dso: NULL, |
| 117 | reserved: {0}, |
| 118 | }, |
| 119 | |
| 120 | init: shield_power_init, |
| 121 | setInteractive: shield_power_set_interactive, |
| 122 | powerHint: shield_power_hint, |
| 123 | setFeature: shield_set_feature, |
| 124 | }; |