summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>2018-09-03 18:04:03 +0530
committerManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>2018-09-07 14:42:16 +0530
commit3cd560ff0b230d8054460c5a77db3d0ef49f4632 (patch)
tree1882e24903a09586e5e41d7d9f4afa3e3b80e3cc
parent24ab2c825f3d2fc41c519d5d8ba25e86e39b65d0 (diff)
downloadthermal-3cd560ff0b230d8054460c5a77db3d0ef49f4632.tar.gz
thermal-hal: Update get temperature API support for legacy targets
Add support for get temperature API support for legcay targets including SDM710, QCS605, SDM660, SDM630, MSM8953, SDM632, SDM439 etc. There are targets which are binary compatible, but uses different sensor configuration. Enable soc id based platform detection and use different sensor configuration. Change-Id: I2537476c07887f9131c33b352f5ffd3a4bc0dd31
-rw-r--r--Android.mk17
-rw-r--r--thermal-default.c36
-rw-r--r--thermal_common.c2
-rw-r--r--thermal_common.h13
-rw-r--r--thermal_target.c454
5 files changed, 473 insertions, 49 deletions
diff --git a/Android.mk b/Android.mk
index 797e5b2..1a14500 100644
--- a/Android.mk
+++ b/Android.mk
@@ -20,22 +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
LOCAL_SRC_FILES += thermal_common.c
-SUPPORT_THERMAL_HAL:=1
-endif
-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
-LOCAL_SRC_FILES += thermal_common.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-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
index 803b0a1..9374929 100644
--- a/thermal_common.c
+++ b/thermal_common.c
@@ -96,7 +96,7 @@ const char *get_cpu_label(unsigned int cpu_num) {
*
* @return number of bytes read on success or negative value on error.
*/
-static int read_line_from_file(const char *path, char *buf, size_t count)
+int read_line_from_file(const char *path, char *buf, size_t count)
{
char * fgets_ret;
FILE * fd;
diff --git a/thermal_common.h b/thermal_common.h
index 4137322..5a07804 100644
--- a/thermal_common.h
+++ b/thermal_common.h
@@ -29,6 +29,17 @@
#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,
+};
+
struct target_therm_cfg {
enum temperature_type type;
char **sensor_list;
@@ -46,6 +57,8 @@ struct vendor_temperature {
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);
diff --git a/thermal_target.c b/thermal_target.c
new file mode 100644
index 0000000..493fe83
--- /dev/null
+++ b/thermal_target.c
@@ -0,0 +1,454 @@
+/* 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},
+};
+
+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;
+ 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);
+}