summaryrefslogtreecommitdiffstats
path: root/thermal-8998.c
diff options
context:
space:
mode:
authorManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>2018-08-24 12:34:45 +0530
committerManaf Meethalavalappu Pallikunhi <manafm@codeaurora.org>2018-09-07 14:39:06 +0530
commit24ab2c825f3d2fc41c519d5d8ba25e86e39b65d0 (patch)
tree3b1701e9f6e1230d314a01ef2c8ab0e19fe83ec5 /thermal-8998.c
parent34f922d74a2e0bc81815785c49e7c8598a628647 (diff)
downloadandroid_hardware_qcom_thermal-24ab2c825f3d2fc41c519d5d8ba25e86e39b65d0.tar.gz
android_hardware_qcom_thermal-24ab2c825f3d2fc41c519d5d8ba25e86e39b65d0.tar.bz2
android_hardware_qcom_thermal-24ab2c825f3d2fc41c519d5d8ba25e86e39b65d0.zip
thermal-hal: Re-arch thermal HAL implementation
Re-design thermal HAL server side implementation to accomodate below features. -Use sensor names and get thermal zone ids on the fly using sensor names. -Generalize APIs implementation and remove repeated code implementation in target specific files. -Minimize target specific configuration and avoid target specific file going forward. Change-Id: Ib61c591d60d17aaeac0eb84ec9b3a4775173a416
Diffstat (limited to 'thermal-8998.c')
-rw-r--r--thermal-8998.c223
1 files changed, 65 insertions, 158 deletions
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);
}