power.c revision b59998fa25f217ba651f6f5a4f1ddcdb0d24b42d
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 <sys/socket.h> 21#include <sys/un.h> 22#include <fcntl.h> 23#include <dlfcn.h> 24 25#define LOG_TAG "PowerHAL" 26#include <utils/Log.h> 27 28#include <hardware/hardware.h> 29#include <hardware/power.h> 30#define TOUCHBOOST_SOCKET "/dev/socket/mpdecision/touchboost" 31 32static int client_sockfd; 33static struct sockaddr_un client_addr; 34 35static void power_init(struct power_module *module) 36{ 37 ALOGI("%s", __func__); 38 client_sockfd = socket(PF_UNIX, SOCK_DGRAM, 0); 39 if (client_sockfd < 0) { 40 ALOGE("%s: failed to open: %s", __func__, strerror(errno)); 41 return; 42 } 43 memset(&client_addr, 0, sizeof(struct sockaddr_un)); 44 client_addr.sun_family = AF_UNIX; 45 snprintf(client_addr.sun_path, UNIX_PATH_MAX, TOUCHBOOST_SOCKET); 46} 47 48static void touch_boost() 49{ 50 int rc; 51 52 if (client_sockfd < 0) { 53 ALOGE("%s: touchboost socket not created", __func__); 54 return; 55 } 56 57 rc = sendto(client_sockfd, "1", 1, 0, (const struct sockaddr *)&client_addr, sizeof(struct sockaddr_un)); 58 if (rc < 0) { 59 ALOGE("%s: failed to send: %s", __func__, strerror(errno)); 60 } 61} 62 63static void power_set_interactive(struct power_module *module, int on) 64{ 65 ALOGV("%s %s", __func__, (on ? "ON" : "OFF")); 66 if (on) 67 touch_boost(); 68} 69 70static void power_hint(struct power_module *module, power_hint_t hint, 71 void *data) { 72 switch (hint) { 73 case POWER_HINT_INTERACTION: 74 ALOGV("POWER_HINT_INTERACTION"); 75 touch_boost(); 76 break; 77#if 0 78 case POWER_HINT_VSYNC: 79 ALOGV("POWER_HINT_VSYNC %s", (data ? "ON" : "OFF")); 80 break; 81#endif 82 default: 83 break; 84 } 85} 86 87static struct hw_module_methods_t power_module_methods = { 88 .open = NULL, 89}; 90 91struct power_module HAL_MODULE_INFO_SYM = { 92 .common = { 93 .tag = HARDWARE_MODULE_TAG, 94 .module_api_version = POWER_MODULE_API_VERSION_0_2, 95 .hal_api_version = HARDWARE_HAL_API_VERSION, 96 .id = POWER_HARDWARE_MODULE_ID, 97 .name = "Qualcomm Power HAL", 98 .author = "The Android Open Source Project", 99 .methods = &power_module_methods, 100 }, 101 102 .init = power_init, 103 .setInteractive = power_set_interactive, 104 .powerHint = power_hint, 105}; 106