pass-hal: tm1: Add get_temp() of cpu h/w resource 57/172657/3
authorChanwoo Choi <cw00.choi@samsung.com>
Thu, 15 Mar 2018 00:16:30 +0000 (09:16 +0900)
committerChanwoo Choi <cw00.choi@samsung.com>
Thu, 15 Mar 2018 06:07:33 +0000 (15:07 +0900)
Add tm1_cpu_get_temp() which reads the temperature of CPU h/w resource.

Change-Id: If90e98f01d58eb816815ba62ed8030779e01dcf5
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
src/cpu/cpu.c

index 61064190271f369a195f672485fd84d1afe37b98..1a12f172cf96eba9d582e3497fe35111b62f6574 100644 (file)
@@ -27,6 +27,7 @@
 
 #define CPUFREQ_PMQOS_PATH_PREFIX              "/sys/devices/system/cpu/cpufreq/pmqos"
 #define CPUFREQ_PATH_PREFIX                    "/sys/devices/system/cpu/"
+#define TMU_PATH_PREFIX                                "/sys/class/sec/temperature/"
 
 #define CPUFREQ_CPU_ONLINE_MIN_NUM_PATH_SUFFIX "/cpu_online_min"
 #define CPUFREQ_CPU_ONLINE_MAX_NUM_PATH_SUFFIX "/cpu_online_max"
@@ -241,8 +242,34 @@ static struct pass_resource_hotplug_ops tm1_cpu_hotplug_ops = {
        .set_online_max_num = tm1_hotplug_set_online_max_num,
 };
 
+static int tm1_cpu_get_temp(char *res_thermal_name)
+{
+       char path[PATH_MAX];
+       char buf[PATH_MAX];
+       char *pos;
+       int temp = 0;
+       int ret;
+
+       if (!res_thermal_name)
+               return -EINVAL;
+
+       snprintf(path, PATH_MAX, "%s%s", TMU_PATH_PREFIX, res_thermal_name);
+
+       ret = sysfs_read_str(path, buf, sizeof(buf));
+       if (ret < 0)
+               return ret;
+
+       pos = strstr(buf, "temp:");
+       if (!pos || !(pos[5]))
+               return -EINVAL;
+       pos += 5;
+       temp = atoi(pos);
+
+       return temp;
+}
+
 static struct pass_resource_tmu_ops tm1_cpu_tmu_ops = {
-       .get_temp = NULL,
+       .get_temp = tm1_cpu_get_temp,
        .get_policy = NULL,
 };