Home | History | Annotate | Download | only in power
      1 /*
      2  * Copyright (C) 2017 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  * Based on the HiKeyPowerHAL
     17  */
     18 
     19 #include <pthread.h>
     20 #include <semaphore.h>
     21 #include <cutils/properties.h>
     22 
     23 #define LOG_TAG "VSoCPowerHAL"
     24 #include <utils/Log.h>
     25 
     26 #include <hardware/hardware.h>
     27 #include <hardware/power.h>
     28 #include "guest/libs/platform_support/api_level_fixes.h"
     29 
     30 struct vsoc_power_module {
     31     struct power_module base;
     32     pthread_mutex_t lock;
     33 };
     34 
     35 
     36 #if VSOC_PLATFORM_SDK_AFTER(N_MR1)
     37 
     38 static void vsoc_power_set_feature(struct power_module __unused *module,
     39                                   feature_t __unused hint,
     40                                   int __unused state) {
     41     return;
     42 }
     43 
     44 #elif VSOC_PLATFORM_SDK_AFTER(L)
     45 
     46 static void vsoc_power_set_feature(struct power_module __unused *module,
     47                                   power_hint_t __unused hint,
     48                                   int __unused state) {
     49     return;
     50 }
     51 
     52 #endif
     53 
     54 static void vsoc_power_hint(struct power_module __unused *module,
     55                            power_hint_t __unused hint,
     56                            void __unused *data) {
     57     return;
     58 }
     59 
     60 static void vsoc_power_set_interactive(struct power_module __unused *module,
     61                                       int __unused on) {
     62     return;
     63 }
     64 
     65 static  void vsoc_power_init(struct power_module __unused *module) {
     66     return;
     67 }
     68 
     69 
     70 /*
     71  * The power module wasn't opened at all in versions prior to 'O'. The module
     72  * pointer was reinterpretd as a device pointer. 'O' retains this behavior when
     73  * open is set to NULL. This code is using that mode.
     74  * For reference,
     75  * 'O': hardware/interfaces/power/1.0/default/Power.cpp
     76  * prior: frameworks/base/services/core/jni/com_android_server_power_PowerManagerService.cpp
     77  */
     78 static struct hw_module_methods_t power_module_methods = {
     79     VSOC_STATIC_INITIALIZER(open) NULL
     80 };
     81 
     82 
     83 struct vsoc_power_module HAL_MODULE_INFO_SYM = {
     84   VSOC_STATIC_INITIALIZER(base) {
     85     .common = {
     86         VSOC_STATIC_INITIALIZER(tag) HARDWARE_MODULE_TAG,
     87         VSOC_STATIC_INITIALIZER(module_api_version) POWER_MODULE_API_VERSION_0_2,
     88         VSOC_STATIC_INITIALIZER(hal_api_version) HARDWARE_HAL_API_VERSION,
     89         VSOC_STATIC_INITIALIZER(id) POWER_HARDWARE_MODULE_ID,
     90         VSOC_STATIC_INITIALIZER(name) "VSoC Power HAL",
     91         VSOC_STATIC_INITIALIZER(author) "The Android Open Source Project",
     92         VSOC_STATIC_INITIALIZER(methods) &power_module_methods,
     93     },
     94     VSOC_STATIC_INITIALIZER(init) vsoc_power_init,
     95     VSOC_STATIC_INITIALIZER(setInteractive) vsoc_power_set_interactive,
     96     VSOC_STATIC_INITIALIZER(powerHint) vsoc_power_hint,
     97     // Before L_MR1 we don't have setFeature
     98 #if VSOC_PLATFORM_SDK_AFTER(L)
     99     VSOC_STATIC_INITIALIZER(setFeature) vsoc_power_set_feature,
    100 #endif
    101   },
    102 
    103   VSOC_STATIC_INITIALIZER(lock) PTHREAD_MUTEX_INITIALIZER,
    104 };
    105 
    106