msm: dcvs: Add thermal interfaces.

The algorithm needs thermal inputs for all the cores. Create members in
the internal core_info strucutre and platform data/device tree to pass
in the sensors they use.

Update the dcvs code to notify the temperature to TZ.

Signed-off-by: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
(cherry picked from commit fc7dca4c325725492af997fa282e07b9d03154d1)

Signed-off-by: Ram Kumar Chakravarthy Chebathini <rcheba@codeaurora.org>
(cherry picked from commit eb478c5b7b55ea8a57e0336e4cf9979be935b289)

Change-Id: I505903eb8b9779f2065aebfab5b3f2aefc874200
Signed-off-by: Sudhir Sharma <sudsha@codeaurora.org>
diff --git a/arch/arm/mach-msm/msm_dcvs.c b/arch/arm/mach-msm/msm_dcvs.c
index 9601b7e..0505d44 100644
--- a/arch/arm/mach-msm/msm_dcvs.c
+++ b/arch/arm/mach-msm/msm_dcvs.c
@@ -23,6 +23,7 @@
 #include <linux/spinlock.h>
 #include <linux/stringify.h>
 #include <linux/debugfs.h>
+#include <linux/msm_tsens.h>
 #include <asm/atomic.h>
 #include <asm/page.h>
 #include <mach/msm_dcvs.h>
@@ -97,13 +98,14 @@
 	/* track if kthread for change_freq is active */
 	int32_t change_freq_activated;
 	struct msm_dcvs_core_info *info;
+	int sensor;
 };
 
 static int msm_dcvs_debug;
 static int msm_dcvs_enabled = 1;
 module_param_named(enable, msm_dcvs_enabled, int, S_IRUGO | S_IWUSR | S_IWGRP);
 
-static struct dentry *debugfs_base;
+static struct dentry		*debugfs_base;
 
 static struct dcvs_core core_list[CORES_MAX];
 static DEFINE_MUTEX(core_list_lock);
@@ -240,6 +242,27 @@
 	return ret;
 }
 
+static int __msm_dcvs_report_temp(struct dcvs_core *core)
+{
+	struct msm_dcvs_core_info *info = core->info;
+	struct tsens_device tsens_dev;
+	int ret;
+	unsigned long temp = 0;
+
+	tsens_dev.sensor_num = core->sensor;
+	ret = tsens_get_temp(&tsens_dev, &temp);
+	if (!ret) {
+		tsens_dev.sensor_num = 0;
+		ret = tsens_get_temp(&tsens_dev, &temp);
+		if (!ret)
+			return -ENODEV;
+	}
+
+	ret = msm_dcvs_scm_set_power_params(core->handle, &info->power_param,
+			&info->freq_tbl[0], &core->coeffs);
+	return ret;
+}
+
 static int msm_dcvs_do_freq(void *data)
 {
 	struct dcvs_core *core = (struct dcvs_core *)data;
@@ -251,6 +274,7 @@
 	while (!kthread_should_stop()) {
 		mutex_lock(&core->lock);
 		__msm_dcvs_change_freq(core);
+		__msm_dcvs_report_temp(core);
 		mutex_unlock(&core->lock);
 
 		schedule();
@@ -571,7 +595,7 @@
 }
 
 int msm_dcvs_register_core(const char *core_name,
-		struct msm_dcvs_core_info *info)
+		struct msm_dcvs_core_info *info, int sensor)
 {
 	int ret = -EINVAL;
 	struct dcvs_core *core = NULL;
@@ -594,7 +618,10 @@
 	memcpy(&core->coeffs, &info->energy_coeffs,
 			sizeof(struct msm_dcvs_energy_curve_coeffs));
 
-	ret = msm_dcvs_scm_register_core(core->handle, &info->core_param);
+	pr_debug("registering core with sensor %d\n", sensor);
+	core->sensor = sensor;
+	ret = msm_dcvs_scm_register_core(core->handle,
+			&info->core_param);
 	if (ret)
 		goto bail;