Home | History | Annotate | Download | only in hardware
      1 /*
      2  * Copyright (C) 2016 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 #ifndef ANDROID_INCLUDE_HARDWARE_THERMAL_H
     18 #define ANDROID_INCLUDE_HARDWARE_THERMAL_H
     19 
     20 #include <stdbool.h>
     21 #include <stdint.h>
     22 #include <sys/cdefs.h>
     23 #include <sys/types.h>
     24 
     25 #include <hardware/hardware.h>
     26 
     27 __BEGIN_DECLS
     28 
     29 #define THERMAL_HARDWARE_MODULE_API_VERSION_0_1 HARDWARE_MODULE_API_VERSION(0, 1)
     30 
     31 #define THERMAL_HARDWARE_MODULE_ID "thermal"
     32 
     33 // This value is returned if a desired temperature is not available.
     34 #define UNKNOWN_TEMPERATURE -FLT_MAX
     35 
     36 /** Device temperature types. Must be kept in sync with
     37  * framework/base/core/java/android/os/HardwarePropertiesManager.java
     38  */
     39 enum temperature_type {
     40     DEVICE_TEMPERATURE_UNKNOWN  = -1,
     41     DEVICE_TEMPERATURE_CPU      = 0,
     42     DEVICE_TEMPERATURE_GPU      = 1,
     43     DEVICE_TEMPERATURE_BATTERY  = 2,
     44     DEVICE_TEMPERATURE_SKIN     = 3
     45 };
     46 
     47 enum cooling_type {
     48     /** Fan cooling device speed in RPM. */
     49     FAN_RPM                     = 0,
     50 };
     51 
     52 typedef struct {
     53   /**
     54    * This temperature's type.
     55    */
     56   enum temperature_type type;
     57 
     58   /**
     59    * Name of this temperature.
     60    * All temperatures of the same "type" must have a different "name".
     61    */
     62   const char *name;
     63 
     64   /**
     65    * Current temperature in Celsius. If not available set by HAL to
     66    * UNKNOWN_TEMPERATURE.
     67    * Current temperature can be in any units if
     68    * type=DEVICE_TEMPERATURE_UNKNOWN.
     69    */
     70   float current_value;
     71 
     72   /**
     73    * Throttling temperature constant for this temperature.
     74    * If not available, set by HAL to UNKNOWN_TEMPERATURE.
     75    */
     76   float throttling_threshold;
     77 
     78   /**
     79    * Shutdown temperature constant for this temperature.
     80    * If not available, set by HAL to UNKNOWN_TEMPERATURE.
     81    */
     82   float shutdown_threshold;
     83 
     84   /**
     85    * Threshold temperature above which the VR mode clockrate minimums cannot
     86    * be maintained for this device.
     87    * If not available, set by HAL to UNKNOWN_TEMPERATURE.
     88    */
     89   float vr_throttling_threshold;
     90 } temperature_t;
     91 
     92 typedef struct {
     93     /**
     94      * This cooling device type.
     95      */
     96     enum cooling_type type;
     97 
     98     /**
     99      * Name of this cooling device.
    100      * All cooling devices of the same "type" must have a different "name".
    101      */
    102     const char *name;
    103 
    104     /**
    105      * Current cooling device value. Units depend on cooling device "type".
    106      */
    107     float current_value;
    108 } cooling_device_t;
    109 
    110 typedef struct {
    111     /**
    112      * Name of this CPU.
    113      * All CPUs must have a different "name".
    114      */
    115     const char *name;
    116 
    117     /**
    118      * Active time since the last boot in ms.
    119      */
    120     uint64_t active;
    121 
    122     /**
    123      * Total time since the last boot in ms.
    124      */
    125     uint64_t total;
    126 
    127     /**
    128      * Is set to true when a core is online.
    129      * If the core is offline, all other members except |name| should be ignored.
    130      */
    131     bool is_online;
    132 } cpu_usage_t;
    133 
    134 typedef struct thermal_module {
    135     struct hw_module_t common;
    136 
    137     /*
    138      * (*getTemperatures) is called to get temperatures in Celsius.
    139      *
    140      * @param list If NULL, this method only returns number of temperatures
    141      *     and caller should allocate a temperature_t array with that number
    142      *     of elements.
    143      *     Caller is responsible for allocating temperature_t array |list| of
    144      *     large enough size (not less than returned number of temperatures).
    145      *     If |list| is not NULL and this method returns non-negative value,
    146      *     it's filled with the current temperatures. If the resulting
    147      *     temperature list is longer than |size| elements, the remaining
    148      *     temperatures are discarded and not stored, but counted for the value
    149      *     returned by this method.
    150      *     The order of temperatures of built-in devices (such as CPUs, GPUs and
    151      *     etc.) in the |list| is kept the same regardless the number of calls
    152      *     to this method even if they go offline, if these devices exist on
    153      *     boot. The method always returns and never removes such temperatures.
    154      * @param size The capacity of |list|, in elements, if |list| is not NULL.
    155      *
    156      * @return number of temperatures or negative value -errno on error.
    157      *
    158      */
    159     ssize_t (*getTemperatures)(struct thermal_module *module, temperature_t *list, size_t size);
    160 
    161     /*
    162      * (*getCpuUsages) is called to get CPU usage information of each core:
    163      *     active and total times in ms since first boot.
    164      *
    165      * @param list If NULL, this method only returns number of cores and caller
    166      *     should allocate a cpu_usage_t array with that number of elements.
    167      *     Caller is responsible for allocating cpu_usage_t array |list| of
    168      *     large enough size (not less than returned number of CPUs).
    169      *     If |list| is not NULL and this method returns non-negative value,
    170      *     it's filled with the current CPU usages.
    171      *     The order of CPUs in the |list| is kept the same regardless the
    172      *     number of calls to this method.
    173      *
    174      * @return constant number of CPUs or negative value -errno on error.
    175      *
    176      */
    177     ssize_t (*getCpuUsages)(struct thermal_module *module, cpu_usage_t *list);
    178 
    179     /*
    180      * (*getCoolingDevices) is called to get the cooling devices information.
    181      *
    182      * @param list If NULL, this method only returns number of cooling devices
    183      *     and caller should allocate a cooling_device_t array with that number
    184      *     of elements.
    185      *     Caller is responsible for allocating cooling_device_t array |list| of
    186      *     large enough size (not less than returned number of cooling devices).
    187      *     If |list| is not NULL and this method returns non-negative value,
    188      *     it's filled with the current cooling device information. If the
    189      *     resulting cooling device list is longer than |size| elements, the
    190      *     remaining cooling device informations are discarded and not stored,
    191      *     but counted for the value returned by this method.
    192      *     The order of built-in coolling devices in the |list| is kept the same
    193      *     regardless the number of calls to this method even if they go
    194      *     offline, if these devices exist on boot. The method always returns
    195      *     and never removes from the list such coolling devices.
    196      * @param size The capacity of |list|, in elements, if |list| is not NULL.
    197      *
    198      * @return number of cooling devices or negative value -errno on error.
    199      *
    200      */
    201     ssize_t (*getCoolingDevices)(struct thermal_module *module, cooling_device_t *list,
    202                                  size_t size);
    203 
    204 } thermal_module_t;
    205 
    206 __END_DECLS
    207 
    208 #endif  // ANDROID_INCLUDE_HARDWARE_THERMAL_H
    209