diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2019-02-09 02:14:47 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-02-09 02:14:47 +0000 |
commit | 94e2b811935ac8cbdad260372cd0a5b079cd8a78 (patch) | |
tree | 0acbeef32c4d63865f72a65e815b35c8d7eb4ac3 | |
parent | db1b1d8342ea8bff3b9c043de2079e6e052543d6 (diff) | |
parent | 7064284e8f6f947e5eadd007e136594725520904 (diff) | |
download | thermal-94e2b811935ac8cbdad260372cd0a5b079cd8a78.tar.gz |
Snap for 5180536 from 7064284e8f6f947e5eadd007e136594725520904 to pi-platform-release
Change-Id: I4ded11f209cdc642acbc8e0ab0d30e3a1a08243d
-rw-r--r-- | Android.mk | 17 | ||||
-rw-r--r-- | thermal-845.c | 228 | ||||
-rw-r--r-- | thermal-8998.c | 223 | ||||
-rw-r--r-- | thermal-default.c | 36 | ||||
-rw-r--r-- | thermal_common.c | 385 | ||||
-rw-r--r-- | thermal_common.h | 66 | ||||
-rw-r--r-- | thermal_target.c | 510 |
7 files changed, 1100 insertions, 365 deletions
@@ -20,20 +20,15 @@ LOCAL_MODULE := thermal.$(TARGET_BOARD_PLATFORM) LOCAL_MODULE_RELATIVE_PATH := hw LOCAL_PROPRIETARY_MODULE := true -ifeq ($(call is-board-platform-in-list,msm8998), true) LOCAL_SRC_FILES := thermal.c -LOCAL_SRC_FILES += thermal-8998.c -SUPPORT_THERMAL_HAL:=1 -endif +LOCAL_SRC_FILES += thermal_common.c -ifeq ($(call is-board-platform-in-list,sdm845), true) -LOCAL_SRC_FILES := thermal.c +ifeq ($(call is-board-platform-in-list,msm8998), true) +LOCAL_SRC_FILES += thermal-8998.c +else ifeq ($(call is-board-platform-in-list,sdm845), true) LOCAL_SRC_FILES += thermal-845.c -SUPPORT_THERMAL_HAL:=1 -endif - -ifeq ($(SUPPORT_THERMAL_HAL),) -LOCAL_SRC_FILES := thermal-default.c +else +LOCAL_SRC_FILES += thermal_target.c endif LOCAL_HEADER_LIBRARIES := libutils_headers libhardware_headers diff --git a/thermal-845.c b/thermal-845.c index a6a9e3e..59925b5 100644 --- a/thermal-845.c +++ b/thermal-845.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. * Not a contribution * Copyright (C) 2016 The Android Open Source Project * @@ -16,177 +16,85 @@ * limitations under the License. */ -#include <ctype.h> -#include <errno.h> -#include <inttypes.h> -#include <stdlib.h> -#include <string.h> #define LOG_TAG "ThermalHAL-845" #include <utils/Log.h> #include <hardware/hardware.h> #include <hardware/thermal.h> - -#define MAX_LENGTH 50 - -#define TEMPERATURE_FILE_FORMAT "/sys/class/thermal/thermal_zone%d/temp" - -#define BATTERY_SENSOR_NUM 60 -#define GPU_SENSOR_NUM 11 -#define SKIN_SENSOR_NUM 56 - -const int CPU_SENSORS[] = {1, 2, 3, 4, 7, 8, 9,10}; - -#define CPU_NUM (sizeof(CPU_SENSORS) / sizeof(int)) -// Sum of CPU_NUM + 3 for GPU, BATTERY, and SKIN. -#define TEMPERATURE_NUM (CPU_NUM + 3) - -//therm-reset-temp -#define CPU_SHUTDOWN_THRESHOLD 115 -//limit-temp -#define CPU_THROTTLING_THRESHOLD 60 -#define BATTERY_SHUTDOWN_THRESHOLD 60 -//must match thermal-engine.conf -#define SKIN_THROTTLING_THRESHOLD 44 -#define SKIN_SHUTDOWN_THRESHOLD 70 -#define VR_THROTTLED_BELOW_MIN 58 - -#define GPU_LABEL "GPU" -#define BATTERY_LABEL "battery" -#define SKIN_LABEL "skin" - -const char *CPU_LABEL[] = {"CPU0", "CPU1", "CPU2", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7"}; - -const char *get_cpu_label(unsigned int cpu_num) { - ALOGD("Entering %s",__func__); - if(cpu_num >= CPU_NUM) - return NULL; - - return CPU_LABEL[cpu_num]; -} - -size_t get_num_cpus() { - ALOGD("Entering %s",__func__); - return CPU_NUM; -} - -/** - * Reads device temperature. - * - * @param sensor_num Number of sensor file with temperature. - * @param type Device temperature type. - * @param name Device temperature name. - * @param mult Multiplier used to translate temperature to Celsius. - * @param throttling_threshold Throttling threshold for the temperature. - * @param shutdown_threshold Shutdown threshold for the temperature. - * @param out Pointer to temperature_t structure that will be filled with current - * values. - * - * @return 0 on success or negative value -errno on error. - */ -static ssize_t read_temperature(int sensor_num, int type, const char *name, float mult, - float throttling_threshold, float shutdown_threshold, float vr_throttling_threshold, - temperature_t *out) { - ALOGD("Entering %s",__func__); - FILE *file; - char file_name[MAX_LENGTH]; - float temp; - - snprintf(file_name, sizeof(file_name), TEMPERATURE_FILE_FORMAT, sensor_num); - file = fopen(file_name, "r"); - if (file == NULL) { - ALOGE("%s: failed to open: %s", __func__, strerror(errno)); - return -errno; +#include "thermal_common.h" + +static char *cpu_sensors_845[] = +{ + "cpu0-silver-usr", + "cpu1-silver-usr", + "cpu2-silver-usr", + "cpu3-silver-usr", + "cpu0-gold-usr", + "cpu1-gold-usr", + "cpu2-gold-usr", + "cpu3-gold-usr", +}; + +static char *misc_sensors_845[] = +{ + "gpu0-usr", + "battery", + "xo-therm-adc" +}; + +static struct target_therm_cfg sensor_cfg_845[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_845, + .sens_cnt = ARRAY_SIZE(cpu_sensors_845), + .mult = 0.001, + .throt_thresh = 60, + .shutdwn_thresh = 115, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_845[0], + .sens_cnt = 1, + .mult = 0.001, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_845[1], + .sens_cnt = 1, + .mult = 0.001, + .shutdwn_thresh = 60, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_845[2], + .sens_cnt = 1, + .mult = 0.001, + .throt_thresh = 44, + .shutdwn_thresh = 70, + .vr_thresh = 58, + .label = "skin", } - if (1 != fscanf(file, "%f", &temp)) { - fclose(file); - ALOGE("%s: failed to read a float: %s", __func__, strerror(errno)); - return errno ? -errno : -EIO; - } - - fclose(file); - - (*out) = (temperature_t) { - .type = type, - .name = name, - .current_value = temp * mult, - .throttling_threshold = throttling_threshold, - .shutdown_threshold = shutdown_threshold, - .vr_throttling_threshold = vr_throttling_threshold - }; - - return 0; -} - -static ssize_t get_cpu_temperatures(temperature_t *list, size_t size) { - ALOGD("Entering %s",__func__); - size_t cpu; - for (cpu = 0; cpu < CPU_NUM; cpu++) { - if (cpu >= size) { - break; - } - // tsens_tz_sensor[4,6,9,11]: temperature in decidegrees Celsius. - ssize_t result = read_temperature(CPU_SENSORS[cpu], DEVICE_TEMPERATURE_CPU, CPU_LABEL[cpu], - 0.001, CPU_THROTTLING_THRESHOLD, CPU_SHUTDOWN_THRESHOLD, UNKNOWN_TEMPERATURE, - &list[cpu]); - if (result != 0) { - return result; - } - } - - return cpu; -} +}; ssize_t get_temperatures(thermal_module_t *module, temperature_t *list, size_t size) { ALOGD("Entering %s",__func__); - ssize_t result = 0; - size_t current_index = 0; - - if (list == NULL) { - return TEMPERATURE_NUM; - } - - result = get_cpu_temperatures(list, size); - if (result < 0) { - return result; - } - current_index += result; - - // GPU temperature. - if (current_index < size) { - // tsens_tz_sensor14: temperature in millidegrees Celsius. - result = read_temperature(GPU_SENSOR_NUM, DEVICE_TEMPERATURE_GPU, GPU_LABEL, 0.001, - UNKNOWN_TEMPERATURE, UNKNOWN_TEMPERATURE, UNKNOWN_TEMPERATURE, - &list[current_index]); - if (result < 0) { - return result; + static int thermal_sens_size; + + if (!thermal_sens_size) { + thermal_sens_size = thermal_zone_init(sensor_cfg_845, + ARRAY_SIZE(sensor_cfg_845)); + if (thermal_sens_size <= 0) { + ALOGE("thermal sensor initialization is failed\n"); + thermal_sens_size = 0; + return 0; } - current_index++; } - // Battery temperature. - if (current_index < size) { - // tsens_tz_sensor29: battery: temperature in millidegrees Celsius. - result = read_temperature(BATTERY_SENSOR_NUM, DEVICE_TEMPERATURE_BATTERY, BATTERY_LABEL, - 0.001, UNKNOWN_TEMPERATURE, BATTERY_SHUTDOWN_THRESHOLD, UNKNOWN_TEMPERATURE, - &list[current_index]); - if (result < 0) { - return result; - } - current_index++; - } + if (list == NULL) + return thermal_sens_size; - // Skin temperature. - if (current_index < size) { - // tsens_tz_sensor24: temperature in millidegrees Celsius. - result = read_temperature(SKIN_SENSOR_NUM, DEVICE_TEMPERATURE_SKIN, SKIN_LABEL, .001, - SKIN_THROTTLING_THRESHOLD, SKIN_SHUTDOWN_THRESHOLD, VR_THROTTLED_BELOW_MIN, - &list[current_index]); - if (result < 0) { - return result; - } - current_index++; - } - return TEMPERATURE_NUM; + return get_temperature_for_all(list, size); } diff --git a/thermal-8998.c b/thermal-8998.c index a43159b..94bf375 100644 --- a/thermal-8998.c +++ b/thermal-8998.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, The Linux Foundation. All rights reserved. + * Copyright (c) 2017-2018 The Linux Foundation. All rights reserved. * Not a contribution * Copyright (C) 2016 The Android Open Source Project * @@ -16,178 +16,85 @@ * limitations under the License. */ -#include <ctype.h> -#include <errno.h> -#include <inttypes.h> -#include <stdlib.h> -#include <string.h> #define LOG_TAG "ThermalHAL-8998" #include <utils/Log.h> #include <hardware/hardware.h> #include <hardware/thermal.h> +#include "thermal_common.h" -#define MAX_LENGTH 50 - -#define TEMPERATURE_FILE_FORMAT "/sys/class/thermal/thermal_zone%d/temp" - -#define BATTERY_SENSOR_NUM 0 -#define GPU_SENSOR_NUM 17 -#define SKIN_SENSOR_NUM 5 - -const int CPU_SENSORS[] = {8, 9, 10, 11, 12, 13, 14,15}; - -#define CPU_NUM (sizeof(CPU_SENSORS) / sizeof(int)) -// Sum of CPU_NUM + 3 for GPU, BATTERY, and SKIN. -#define TEMPERATURE_NUM (CPU_NUM + 3) - -//therm-reset-temp -#define CPU_SHUTDOWN_THRESHOLD 115 -//limit-temp -#define CPU_THROTTLING_THRESHOLD 60 -#define BATTERY_SHUTDOWN_THRESHOLD 60 -//must match thermal-engine.conf -#define SKIN_THROTTLING_THRESHOLD 44 -#define SKIN_SHUTDOWN_THRESHOLD 70 -#define VR_THROTTLED_BELOW_MIN 58 - -#define GPU_LABEL "GPU" -#define BATTERY_LABEL "battery" -#define SKIN_LABEL "skin" - -const char *CPU_LABEL[] = {"CPU0", "CPU1", "CPU2", "CPU3", "CPU4", "CPU5", "CPU6", "CPU7"}; - -const char *get_cpu_label(unsigned int cpu_num) { - - if(cpu_num >= CPU_NUM) - return NULL; - - return CPU_LABEL[cpu_num]; -} - -size_t get_num_cpus() { - return CPU_NUM; -} - -/** - * Reads device temperature. - * - * @param sensor_num Number of sensor file with temperature. - * @param type Device temperature type. - * @param name Device temperature name. - * @param mult Multiplier used to translate temperature to Celsius. - * @param throttling_threshold Throttling threshold for the temperature. - * @param shutdown_threshold Shutdown threshold for the temperature. - * @param out Pointer to temperature_t structure that will be filled with current - * values. - * - * @return 0 on success or negative value -errno on error. - */ -static ssize_t read_temperature(int sensor_num, int type, const char *name, float mult, - float throttling_threshold, float shutdown_threshold, float vr_throttling_threshold, - temperature_t *out) +static char *cpu_sensors_8998[] = { - ALOGD("Entering %s",__func__); - FILE *file; - char file_name[MAX_LENGTH]; - float temp; - - snprintf(file_name, sizeof(file_name), TEMPERATURE_FILE_FORMAT, sensor_num); - file = fopen(file_name, "r"); - if (file == NULL) { - ALOGE("%s: failed to open: %s", __func__, strerror(errno)); - return -errno; - } - if (1 != fscanf(file, "%f", &temp)) { - fclose(file); - ALOGE("%s: failed to read a float: %s", __func__, strerror(errno)); - return errno ? -errno : -EIO; - } - - fclose(file); - - (*out) = (temperature_t) { - .type = type, - .name = name, - .current_value = temp * mult, - .throttling_threshold = throttling_threshold, - .shutdown_threshold = shutdown_threshold, - .vr_throttling_threshold = vr_throttling_threshold - }; - - return 0; -} - -static ssize_t get_cpu_temperatures(temperature_t *list, size_t size) + "tsens_tz_sensor1", + "tsens_tz_sensor2", + "tsens_tz_sensor3", + "tsens_tz_sensor4", + "tsens_tz_sensor7", + "tsens_tz_sensor8", + "tsens_tz_sensor9", + "tsens_tz_sensor10", +}; + +static char *misc_sensors_8998[] = { - ALOGD("Entering %s",__func__); - size_t cpu; - for (cpu = 0; cpu < CPU_NUM; cpu++) { - if (cpu >= size) { - break; - } - // tsens_tz_sensor[4,6,9,11]: temperature in decidegrees Celsius. - ssize_t result = read_temperature(CPU_SENSORS[cpu], DEVICE_TEMPERATURE_CPU, CPU_LABEL[cpu], - 0.1, CPU_THROTTLING_THRESHOLD, CPU_SHUTDOWN_THRESHOLD, UNKNOWN_TEMPERATURE, - &list[cpu]); - if (result != 0) { - return result; - } + "tsens_tz_sensor12", + "battery", + "quiet_therm" +}; + +static struct target_therm_cfg sensor_cfg_8998[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_8998, + .sens_cnt = ARRAY_SIZE(cpu_sensors_8998), + .mult = 0.1, + .throt_thresh = 60, + .shutdwn_thresh = 115, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_8998[0], + .sens_cnt = 1, + .mult = 0.1, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_8998[1], + .sens_cnt = 1, + .mult = 0.001, + .shutdwn_thresh = 60, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_8998[2], + .sens_cnt = 1, + .mult = 1.0, + .throt_thresh = 44, + .shutdwn_thresh = 70, + .vr_thresh = 58, + .label = "skin", } - - return cpu; -} +}; ssize_t get_temperatures(thermal_module_t *module, temperature_t *list, size_t size) { ALOGD("Entering %s",__func__); - ssize_t result = 0; - size_t current_index = 0; - - if (list == NULL) { - return TEMPERATURE_NUM; - } - - result = get_cpu_temperatures(list, size); - if (result < 0) { - return result; - } - current_index += result; - - // GPU temperature. - if (current_index < size) { - // tsens_tz_sensor14: temperature in decidegrees Celsius. - result = read_temperature(GPU_SENSOR_NUM, DEVICE_TEMPERATURE_GPU, GPU_LABEL, 0.1, - UNKNOWN_TEMPERATURE, UNKNOWN_TEMPERATURE, UNKNOWN_TEMPERATURE, - &list[current_index]); - if (result < 0) { - return result; + static int thermal_sens_size; + + if (!thermal_sens_size) { + thermal_sens_size = thermal_zone_init(sensor_cfg_8998, + ARRAY_SIZE(sensor_cfg_8998)); + if (thermal_sens_size <= 0) { + ALOGE("thermal sensor initialization is failed\n"); + thermal_sens_size = 0; + return 0; } - current_index++; } - // Battery temperature. - if (current_index < size) { - // tsens_tz_sensor29: battery: temperature in millidegrees Celsius. - result = read_temperature(BATTERY_SENSOR_NUM, DEVICE_TEMPERATURE_BATTERY, BATTERY_LABEL, - 0.001, UNKNOWN_TEMPERATURE, BATTERY_SHUTDOWN_THRESHOLD, UNKNOWN_TEMPERATURE, - &list[current_index]); - if (result < 0) { - return result; - } - current_index++; - } + if (list == NULL) + return thermal_sens_size; - // Skin temperature. - if (current_index < size) { - // tsens_tz_sensor24: temperature in Celsius. - result = read_temperature(SKIN_SENSOR_NUM, DEVICE_TEMPERATURE_SKIN, SKIN_LABEL, 1., - SKIN_THROTTLING_THRESHOLD, SKIN_SHUTDOWN_THRESHOLD, VR_THROTTLED_BELOW_MIN, - &list[current_index]); - if (result < 0) { - return result; - } - current_index++; - } - return TEMPERATURE_NUM; + return get_temperature_for_all(list, size); } diff --git a/thermal-default.c b/thermal-default.c deleted file mode 100644 index d5202a7..0000000 --- a/thermal-default.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2017, The Linux Foundation. All rights reserved. - * Not a contribution - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include <hardware/hardware.h> -#include <hardware/thermal.h> - -static struct hw_module_methods_t thermal_module_methods = { - .open = NULL, -}; - -thermal_module_t HAL_MODULE_INFO_SYM = { - .common = { - .tag = HARDWARE_MODULE_TAG, - .module_api_version = THERMAL_HARDWARE_MODULE_API_VERSION_0_1, - .hal_api_version = HARDWARE_HAL_API_VERSION, - .id = THERMAL_HARDWARE_MODULE_ID, - .name = "Default Thermal HAL", - .author = "The Android Open Source Project", - .methods = &thermal_module_methods, - }, -}; diff --git a/thermal_common.c b/thermal_common.c new file mode 100644 index 0000000..9374929 --- /dev/null +++ b/thermal_common.c @@ -0,0 +1,385 @@ +/* + * Copyright (c) 2018, The Linux Foundation. All rights reserved. + * Not a contribution + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <dirent.h> + +#define LOG_TAG "ThermalHAL-UTIL" +#include <utils/Log.h> + +#include <hardware/hardware.h> +#include <hardware/thermal.h> +#include "thermal_common.h" + +#define MAX_LENGTH 50 +#define MAX_PATH (256) +#define CPU_LABEL "CPU%d" +#define THERMAL_SYSFS "/sys/devices/virtual/thermal" +#define TZ_DIR_NAME "thermal_zone" +#define TZ_DIR_FMT "thermal_zone%d" +#define THERMAL_TYPE "/sys/devices/virtual/thermal/%s/type" +#define TEMPERATURE_FILE_FORMAT "/sys/class/thermal/thermal_zone%d/temp" + +static char **cpu_label; +static struct vendor_temperature *sensors; +static unsigned int sensor_cnt; + +/** + * Get number of cpus of target. + * + * @return number of cpus on success or 0 on error. + */ +size_t get_num_cpus() { + ALOGD("Entering %s",__func__); + static int ncpus; + + if (!ncpus) { + ncpus = (int)sysconf(_SC_NPROCESSORS_CONF); + if (ncpus < 1) + ALOGE("%s: Error retrieving number of cores", __func__); + } + return ncpus; +} + +/** + * Get cpu label for a given cpu. + * + * @param cpu_num: cpu number. + * + * @return cpu label string on success or NULL on error. + */ +const char *get_cpu_label(unsigned int cpu_num) { + ALOGD("Entering %s",__func__); + unsigned int cpu = 0; + + if (cpu_label == NULL) { + cpu_label= (char**)calloc(get_num_cpus(), sizeof(char *)); + if (!cpu_label) + return NULL; + for(cpu = 0; cpu < get_num_cpus(); cpu++) { + cpu_label[cpu] = (char *)calloc(sizeof("CPUN"), sizeof(char)); + if(!cpu_label[cpu]) + return NULL; + snprintf(cpu_label[cpu], sizeof("CPUN"), CPU_LABEL, cpu); + } + } + if(cpu_num >= get_num_cpus()) + return NULL; + + return cpu_label[cpu_num]; +} + +/** + * Read data from a target sysfs file. + * + * @param path: Absolute path for a file to be read. + * @param buf: Char buffer to store data from file. + * @param count: Size of data buffer. + * + * @return number of bytes read on success or negative value on error. + */ +int read_line_from_file(const char *path, char *buf, size_t count) +{ + char * fgets_ret; + FILE * fd; + int rv; + + fd = fopen(path, "r"); + if (fd == NULL) + return -1; + + fgets_ret = fgets(buf, (int)count, fd); + if (NULL != fgets_ret) { + rv = (int)strlen(buf); + } else { + rv = ferror(fd); + } + + fclose(fd); + + return rv; +} + +/** + * Function to get thermal zone id from sensor name. + * + * @param sensor_name: Name of sensor. + * + * @return positive integer on success or negative value on error. + */ +static int get_tzn(const char *sensor_name) +{ + DIR *tdir = NULL; + struct dirent *tdirent = NULL; + int found = -1; + int tzn = 0; + char name[MAX_PATH] = {0}; + char cwd[MAX_PATH] = {0}; + int ret = 0; + + if (!getcwd(cwd, sizeof(cwd))) + return found; + + /* Change dir to read the entries. Doesnt work otherwise */ + ret = chdir(THERMAL_SYSFS); + if (ret) { + ALOGE("Unable to change to %s\n", THERMAL_SYSFS); + return found; + } + tdir = opendir(THERMAL_SYSFS); + if (!tdir) { + ALOGE("Unable to open %s\n", THERMAL_SYSFS); + return found; + } + + while ((tdirent = readdir(tdir))) { + char buf[50]; + struct dirent *tzdirent; + DIR *tzdir = NULL; + + if (strncmp(tdirent->d_name, TZ_DIR_NAME, + strlen(TZ_DIR_NAME)) != 0) + continue; + + tzdir = opendir(tdirent->d_name); + if (!tzdir) + continue; + while ((tzdirent = readdir(tzdir))) { + if (strcmp(tzdirent->d_name, "type")) + continue; + snprintf(name, MAX_PATH, THERMAL_TYPE, + tdirent->d_name); + ret = read_line_from_file(name, buf, sizeof(buf)); + if (ret <= 0) { + ALOGE("%s: sensor name read error for tz:%s\n", + __func__, tdirent->d_name); + break; + } + if (buf[ret - 1] == '\n') + buf[ret - 1] = '\0'; + else + buf[ret] = '\0'; + + if (!strcmp(buf, sensor_name)) { + found = 1; + break; + } + } + closedir(tzdir); + if (found == 1) + break; + } + + if (found == 1) { + sscanf(tdirent->d_name, TZ_DIR_FMT, &tzn); + ALOGD("Sensor %s found at tz: %d\n", + sensor_name, tzn); + found = tzn; + } + + closedir(tdir); + /* Restore current working dir */ + ret = chdir(cwd); + + return found; +} + +/** + * Helper function for sensor intialization. + * + * @param v_sen_t: pointer to a sensor static config. + * @param sensor: pointer to a sensor vendor_temperature structure. + * @param type: Type of sensor ie cpu, battery, gpu, skin etc. + * @param sens_idx: Index for sensor of same type. + * + * @return 0 on success or negative value -errno on error. + */ +static int initialize_sensor(struct target_therm_cfg *v_sen_t, + struct vendor_temperature *sensor, + enum temperature_type type, + int sens_idx) +{ + if (v_sen_t == NULL || sensor == NULL || + sens_idx < 0) { + ALOGE("%s:Invalid input, sens_idx%d\n", __func__, sens_idx); + return -1; + } + + sensor->tzn = get_tzn(v_sen_t->sensor_list[sens_idx]); + if (sensor->tzn < 0) { + ALOGE("No thermal zone for sensor: %s, ret:%d\n", + v_sen_t->sensor_list[sens_idx], sensor->tzn); + return -1; + } + if (type == DEVICE_TEMPERATURE_CPU) + sensor->t.name = get_cpu_label(sens_idx); + else + sensor->t.name = v_sen_t->label; + + sensor->t.type = v_sen_t->type; + sensor->mult = v_sen_t->mult; + + if (v_sen_t->throt_thresh != 0) + sensor->t.throttling_threshold = v_sen_t->throt_thresh; + else + sensor->t.throttling_threshold = UNKNOWN_TEMPERATURE; + + if (v_sen_t->shutdwn_thresh != 0) + sensor->t.shutdown_threshold = v_sen_t->shutdwn_thresh; + else + sensor->t.shutdown_threshold = UNKNOWN_TEMPERATURE; + + if (v_sen_t->vr_thresh != 0) + sensor->t.vr_throttling_threshold = v_sen_t->vr_thresh; + else + sensor->t.vr_throttling_threshold = UNKNOWN_TEMPERATURE; + + return 0; +} + +/** + * Initialize all sensors. + * + * @param v_sen_t: Base pointer to array of target specific sensor configs. + * @param cfg_cnt: Number of set of config for a given target. + * + * @return number of sensor on success or negative value or zero on error. + */ +int thermal_zone_init(struct target_therm_cfg *v_sen_t, int cfg_cnt) +{ + unsigned int idx = 0, cpu = 0; + int j = 0; + + if (sensors != NULL && sensor_cnt != 0) + return sensor_cnt; + + if (v_sen_t == NULL || cfg_cnt == 0) { + ALOGE("%s:Invalid input\n", __func__); + return -1; + } + sensors = calloc(get_num_cpus() + cfg_cnt - 1, + sizeof(struct vendor_temperature)); + + for (j = 0, idx = 0; j < cfg_cnt && + idx < (get_num_cpus() + cfg_cnt - 1); j++) { + if (v_sen_t[j].type == DEVICE_TEMPERATURE_CPU) { + /* Initialize cpu thermal zone id */ + for (cpu = 0; cpu < get_num_cpus() && + idx < (get_num_cpus() + cfg_cnt - 1); cpu++, idx++) { + if (initialize_sensor(&v_sen_t[j], &sensors[idx], + v_sen_t[j].type, cpu)) { + free(sensors); + return -1; + } + } + } else { + /* Initialize misc thermal zone id */ + if (initialize_sensor(&v_sen_t[j], &sensors[idx], + v_sen_t[j].type, 0)) { + free(sensors); + return -1; + } + idx++; + } + } + sensor_cnt = idx; + + return sensor_cnt; +} + +/** + * Reads sensor temperature. + * + * @param sensor_num: thermal zone id for the sensor to be read + * @param type: Device temperature type. + * @param name: Device temperature name. + * @param mult: Multiplier used to translate temperature to Celsius. + * @param throttling_threshold: Throttling threshold for the sensor. + * @param shutdown_threshold: Shutdown threshold for the sensor. + * @param out: Pointer to temperature_t structure that will be filled with + * temperature values. + * + * @return 0 on success or negative value -errno on error. + */ +static ssize_t read_temperature(int sensor_num, int type, const char *name, + float mult, float throttling_threshold, float shutdown_threshold, + float vr_throttling_threshold, + temperature_t *out) { + ALOGD("Entering %s",__func__); + char file_name[MAX_LENGTH]; + float temp; + char buf[16] = {0}; + int ret = 0; + + snprintf(file_name, sizeof(file_name), TEMPERATURE_FILE_FORMAT, sensor_num); + ret = read_line_from_file(file_name, buf, sizeof(buf)); + if (ret <= 0) { + ALOGE("Temperature read error: %d for sensor[%d]:%s\n", + ret, sensor_num, name); + return -1; + } + temp = atof(buf); + + (*out) = (temperature_t) { + .type = type, + .name = name, + .current_value = temp * mult, + .throttling_threshold = throttling_threshold, + .shutdown_threshold = shutdown_threshold, + .vr_throttling_threshold = vr_throttling_threshold + }; + + return 0; +} + +/** + * Reads all sensor temperature. + * + * @param list: Base pointer to array of temperature_t structure that will be + * filled with temperature values. + * @param size: Number of sensor temperature needs to be filled in list. + * + * @return number of sensor data filled on success or 0 or negative value + * -errno on error. + */ +ssize_t get_temperature_for_all(temperature_t *list, size_t size) +{ + ALOGD("Entering %s",__func__); + size_t idx; + + if (sensors == NULL) { + ALOGE("No sensor configured\n"); + return 0; + } + + for (idx = 0; idx < sensor_cnt && idx < size; idx++) { + ssize_t result = read_temperature(sensors[idx].tzn, sensors[idx].t.type, + sensors[idx].t.name, sensors[idx].mult, + sensors[idx].t.throttling_threshold, + sensors[idx].t.shutdown_threshold, + sensors[idx].t.vr_throttling_threshold, + &list[idx]); + if (result != 0) + return result; + } + return idx; +} + diff --git a/thermal_common.h b/thermal_common.h new file mode 100644 index 0000000..d67661a --- /dev/null +++ b/thermal_common.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <hardware/thermal.h> +#define ARRAY_SIZE(x) (int)(sizeof(x)/sizeof(x[0])) + +enum therm_msm_id { + THERM_MSM_UNKNOWN = 0, + THERM_MSM_8953, + THERM_SDM_660, + THERM_SDM_630, + THERM_SDM_710, + THERM_QCS_605, + THERM_SDM_632, + THERM_SDM_439, + THERM_MSMNILE, +}; + +struct target_therm_cfg { + enum temperature_type type; + char **sensor_list; + uint8_t sens_cnt; + char *label; + float mult; + int throt_thresh; + int shutdwn_thresh; + int vr_thresh; +}; + +struct vendor_temperature { + int tzn; + float mult; + temperature_t t; +}; + + +int read_line_from_file(const char *path, char *buf, size_t count); +size_t get_num_cpus(); +const char *get_cpu_label(unsigned int cpu_num); +int thermal_zone_init(struct target_therm_cfg *v_sen_t, int cfg_cnt); +ssize_t get_temperature_for_all(temperature_t *list, size_t size); diff --git a/thermal_target.c b/thermal_target.c new file mode 100644 index 0000000..cce237e --- /dev/null +++ b/thermal_target.c @@ -0,0 +1,510 @@ +/* Copyright (c) 2018, The Linux Foundation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * * Neither the name of The Linux Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + + * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN + * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#define LOG_TAG "ThermalHAL-TARGET" +#include <utils/Log.h> + +#include <hardware/hardware.h> +#include <hardware/thermal.h> +#include <stdlib.h> +#include "thermal_common.h" + +#define SYSFS_PLATFORMID "/sys/devices/soc0/soc_id" +#define SOC_INFO_NAME_LEN 15 + +struct therm_msm_soc_type { + enum therm_msm_id msm_id; + int soc_id; +}; + +static struct therm_msm_soc_type msm_soc_table[] = { + {THERM_MSM_8953, 293}, + {THERM_MSM_8953, 304}, + {THERM_MSM_8953, 338}, + {THERM_MSM_8953, 351}, + {THERM_SDM_660, 317}, + {THERM_SDM_660, 324}, + {THERM_SDM_660, 325}, + {THERM_SDM_660, 326}, + {THERM_SDM_660, 345}, + {THERM_SDM_660, 346}, + {THERM_SDM_630, 318}, + {THERM_SDM_630, 327}, + {THERM_SDM_630, 385}, + {THERM_SDM_710, 336}, + {THERM_SDM_710, 337}, + {THERM_QCS_605, 347}, + {THERM_SDM_632, 349}, + {THERM_SDM_632, 350}, + {THERM_SDM_439, 353}, + {THERM_SDM_439, 354}, + {THERM_SDM_439, 363}, + {THERM_SDM_439, 364}, + {THERM_MSMNILE, 339}, + {THERM_MSMNILE, 362}, + {THERM_MSMNILE, 367}, +}; + +static char *cpu_sensors_msmnile[] = +{ + "cpu-0-0-usr", + "cpu-0-1-usr", + "cpu-0-2-usr", + "cpu-0-3-usr", + "cpu-1-0-usr", + "cpu-1-1-usr", + "cpu-1-2-usr", + "cpu-1-3-usr", +}; + +static char *misc_sensors_msmnile[] = +{ + "gpuss-0-usr", + "battery", + "xo-therm" +}; + +static struct target_therm_cfg sensor_cfg_msmnile[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_msmnile, + .sens_cnt = ARRAY_SIZE(cpu_sensors_msmnile), + .mult = 0.001, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_msmnile[0], + .sens_cnt = 1, + .mult = 0.001, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_msmnile[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_msmnile[2], + .sens_cnt = 1, + .mult = 0.001, + .label = "skin", + } +}; + +static char *cpu_sensors_660[] = +{ + "tsens_tz_sensor1", + "tsens_tz_sensor1", + "tsens_tz_sensor1", + "tsens_tz_sensor1", + "tsens_tz_sensor3", + "tsens_tz_sensor4", + "tsens_tz_sensor5", + "tsens_tz_sensor6", +}; + +static char *misc_sensors_660[] = +{ + "tsens_tz_sensor8", + "battery", + "xo_therm" +}; + +static struct target_therm_cfg sensor_cfg_660[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_660, + .sens_cnt = ARRAY_SIZE(cpu_sensors_660), + .mult = 0.1, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_660[0], + .sens_cnt = 1, + .mult = 0.1, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_660[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_660[2], + .sens_cnt = 1, + .mult = 1, + .label = "skin", + } +}; + +static char *cpu_sensors_630[] = +{ + "tsens_tz_sensor3", + "tsens_tz_sensor4", + "tsens_tz_sensor5", + "tsens_tz_sensor6", + "tsens_tz_sensor7", + "tsens_tz_sensor7", + "tsens_tz_sensor7", + "tsens_tz_sensor7", +}; + +static struct target_therm_cfg sensor_cfg_630[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_630, + .sens_cnt = ARRAY_SIZE(cpu_sensors_630), + .mult = 0.1, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_660[0], + .sens_cnt = 1, + .mult = 0.1, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_660[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_660[2], + .sens_cnt = 1, + .mult = 1, + .label = "skin", + } +}; + +static char *cpu_sensors_8953[] = +{ + "tsens_tz_sensor9", + "tsens_tz_sensor10", + "tsens_tz_sensor11", + "tsens_tz_sensor12", + "tsens_tz_sensor4", + "tsens_tz_sensor5", + "tsens_tz_sensor6", + "tsens_tz_sensor7", +}; + +static char *misc_sensors_8953[] = +{ + "tsens_tz_sensor15", + "battery", + "xo_therm" +}; + +static struct target_therm_cfg sensor_cfg_8953[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_8953, + .sens_cnt = ARRAY_SIZE(cpu_sensors_8953), + .mult = 0.1, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_8953[0], + .sens_cnt = 1, + .mult = 0.1, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_8953[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_8953[2], + .sens_cnt = 1, + .mult = 1, + .label = "skin", + } +}; + + +static char *cpu_sensors_710[] = +{ + "cpu0-silver-usr", + "cpu1-silver-usr", + "cpu2-silver-usr", + "cpu3-silver-usr", + "cpu4-silver-usr", + "cpu5-silver-usr", + "cpu0-gold-usr", + "cpu1-gold-usr", +}; + +static char *misc_sensors_710[] = +{ + "gpu0-usr", + "battery", + "xo-therm-adc" +}; + +static struct target_therm_cfg sensor_cfg_710[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_710, + .sens_cnt = ARRAY_SIZE(cpu_sensors_710), + .mult = 0.001, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_710[0], + .sens_cnt = 1, + .mult = 0.001, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_710[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_710[2], + .sens_cnt = 1, + .mult = 0.001, + .label = "skin", + } +}; + +static char *cpu_sensors_632[] = +{ + "cpuss0-usr", + "cpuss0-usr", + "cpuss0-usr", + "cpuss0-usr", + "apc1-cpu0-usr", + "apc1-cpu1-usr", + "apc1-cpu2-usr", + "apc1-cpu3-usr", +}; + +static char *misc_sensors_632[] = +{ + "gpu0-usr", + "battery", + "quiet-therm-adc" +}; + +static struct target_therm_cfg sensor_cfg_632[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_632, + .sens_cnt = ARRAY_SIZE(cpu_sensors_632), + .mult = 0.001, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_632[0], + .sens_cnt = 1, + .mult = 0.001, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_632[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_632[2], + .sens_cnt = 1, + .mult = 0.001, + .label = "skin", + } +}; + +static char *cpu_sensors_439[] = +{ + "apc1-cpu0-usr", + "apc1-cpu1-usr", + "apc1-cpu2-usr", + "apc1-cpu3-usr", + "cpuss0-usr", + "cpuss0-usr", + "cpuss0-usr", + "cpuss0-usr", +}; + +static char *misc_sensors_439[] = +{ + "gpu-usr", + "battery", + "quiet-therm-adc" +}; + +static struct target_therm_cfg sensor_cfg_439[] = { + { + .type = DEVICE_TEMPERATURE_CPU, + .sensor_list = cpu_sensors_439, + .sens_cnt = ARRAY_SIZE(cpu_sensors_439), + .mult = 0.001, + }, + { + .type = DEVICE_TEMPERATURE_GPU, + .sensor_list = &misc_sensors_439[0], + .sens_cnt = 1, + .mult = 0.001, + .label = "GPU", + }, + { + .type = DEVICE_TEMPERATURE_BATTERY, + .sensor_list = &misc_sensors_439[1], + .sens_cnt = 1, + .mult = 0.001, + .label = "battery", + }, + { + .type = DEVICE_TEMPERATURE_SKIN, + .sensor_list = &misc_sensors_439[2], + .sens_cnt = 1, + .mult = 0.001, + .label = "skin", + } +}; + +static int get_soc_info(char *buf) +{ + int ret = 0; + + ret = read_line_from_file(SYSFS_PLATFORMID, buf, SOC_INFO_NAME_LEN); + if (ret < 0) { + ALOGE("Error getting platform_id %d", ret); + return ret; + } + if (ret && buf[ret - 1] == '\n') + buf[ret - 1] = '\0'; + + return ret; +} + +enum therm_msm_id therm_get_soc_id(void) +{ + static enum therm_msm_id msm_id; + int soc_id = -1; + + if (!msm_id) { + int idx; + char buf[SOC_INFO_NAME_LEN]; + + if (get_soc_info(buf) <= 0) + return msm_id; + + soc_id = atoi(buf); + for (idx = 0; idx < ARRAY_SIZE(msm_soc_table); idx++) { + if (soc_id == msm_soc_table[idx].soc_id) { + msm_id = msm_soc_table[idx].msm_id; + break; + } + } + if (!msm_id) + ALOGE("Unknown target identified with soc id %d\n", soc_id); + } + + return msm_id; +} + +ssize_t get_temperatures(thermal_module_t *module, temperature_t *list, size_t size) { + ALOGD("Entering %s",__func__); + static int thermal_sens_size; + + if (!thermal_sens_size) { + struct target_therm_cfg *cfg = NULL; + size_t num_cfg = 0; + + switch (therm_get_soc_id()) { + case THERM_MSM_8953: + cfg = sensor_cfg_8953; + num_cfg = ARRAY_SIZE(sensor_cfg_8953); + break; + case THERM_SDM_660: + cfg = sensor_cfg_660; + num_cfg = ARRAY_SIZE(sensor_cfg_660); + break; + case THERM_SDM_630: + cfg = sensor_cfg_630; + num_cfg = ARRAY_SIZE(sensor_cfg_630); + break; + case THERM_SDM_710: + case THERM_QCS_605: + cfg = sensor_cfg_710; + num_cfg = ARRAY_SIZE(sensor_cfg_710); + break; + case THERM_SDM_632: + cfg = sensor_cfg_632; + num_cfg = ARRAY_SIZE(sensor_cfg_632); + break; + case THERM_SDM_439: + cfg = sensor_cfg_439; + num_cfg = ARRAY_SIZE(sensor_cfg_439); + break; + case THERM_MSMNILE: + cfg = sensor_cfg_msmnile; + num_cfg = ARRAY_SIZE(sensor_cfg_msmnile); + break; + default: + cfg = NULL; + num_cfg = 0; + break; + } + if (cfg == NULL || num_cfg == 0) { + ALOGE("No target specific sensor config\n"); + return 0; + } + thermal_sens_size = thermal_zone_init(cfg, num_cfg); + if (thermal_sens_size <= 0) { + ALOGE("thermal sensor initialization is failed\n"); + thermal_sens_size = 0; + return 0; + } + } + + if (list == NULL) + return thermal_sens_size; + + return get_temperature_for_all(list, size); +} |