thermal-hal: Add support to distinguish different hardward platforms

This change adds support to distinguish different hardware platforms
due to use differnet components.
This change also supports Ravelin QRD and IDP.

Change-Id: Ic0f241c2cf6687b7b819d9952169e502dc9e1da9
Signed-off-by: Minghao Zhang <quic_minghao@quicinc.com>
Signed-off-by: Gopala Krishna Nuthaki <quic_gnuthaki@quicinc.com>
diff --git a/thermalConfig.cpp b/thermalConfig.cpp
index 65a5192..5f92a9d 100644
--- a/thermalConfig.cpp
+++ b/thermalConfig.cpp
@@ -40,6 +40,7 @@
 #include <unordered_map>
 #include <android-base/logging.h>
 #include <aidl/android/hardware/thermal/BnThermal.h>
+#include <utility>
 
 #include "thermalData.h"
 #include "thermalConfig.h"
@@ -50,6 +51,7 @@
 namespace thermal {
 
 	constexpr std::string_view socIDPath("/sys/devices/soc0/soc_id");
+	constexpr std::string_view hwPlatformPath("/sys/devices/soc0/hw_platform");
 
 	std::vector<std::string> cpu_sensors_bengal =
 	{
@@ -1972,9 +1974,17 @@
 			115000,
 			true,
 		},
+		{
+			TemperatureType::SKIN,
+			{ "sys-therm-1" },
+			"skin",
+			55000,
+			95000,
+			true,
+		},
 	};
 
-	std::vector<struct target_therm_cfg>  ravelin_specific = {
+	std::vector<struct target_therm_cfg>  ravelin_specific_qrd = {
 		{
 			TemperatureType::BCL_CURRENT,
 			{ "pmi632-ibat-lvl0" },
@@ -1983,12 +1993,15 @@
 			7500,
 			true,
 		},
+	};
+
+	std::vector<struct target_therm_cfg>  ravelin_specific_idp = {
 		{
-			TemperatureType::SKIN,
-			{ "sys-therm-1" },
-			"skin",
-			55000,
-			95000,
+			TemperatureType::BCL_CURRENT,
+			{ "pm7250b-ibat-lvl0" },
+			"ibat",
+			6000,
+			7500,
 			true,
 		},
 	};
@@ -2121,9 +2134,6 @@
 		{537, parrot_specific}, //Netrani mobile
 		{583, parrot_specific}, //Netrani mobile without modem
 		{613, parrot_specific}, //Netrani APQ
-		{568, ravelin_specific}, //Clarence Mobile
-		{581, ravelin_specific}, //Clarence IOT
-		{582, ravelin_specific}, //Clarence IOT without modem
 		{591, waipio_specific}, //ukee
 	};
 
@@ -2137,18 +2147,37 @@
 		{405, true},
 	};
 
+	const std::unordered_multimap<int, std::pair<std::string,
+				std::vector<struct target_therm_cfg>>>
+		msm_platform_specific = {
+		{568, std::make_pair("QRD", ravelin_specific_qrd)},
+		{568, std::make_pair("IDP", ravelin_specific_idp)},
+	};
+
 	std::vector<struct target_therm_cfg> add_target_config(
-			int socID,
+			int socID, std::string hwPlatform,
 			std::vector<struct target_therm_cfg> conf)
 	{
 		std::vector<struct target_therm_cfg> targetConf;
 
-		if (msm_soc_specific.find(socID) == msm_soc_specific.end())
-			return conf;
-		targetConf = (msm_soc_specific.find(socID))->second;
-
-		conf.insert(conf.end(), targetConf.begin(),
+		if (msm_soc_specific.find(socID) != msm_soc_specific.end()) {
+			targetConf = (msm_soc_specific.find(socID))->second;
+			conf.insert(conf.end(), targetConf.begin(),
 					targetConf.end());
+		}
+
+		auto range = msm_platform_specific.equal_range(socID);
+		auto it = range.first;
+		for (; it != range.second; ++it) {
+			if (it->second.first != hwPlatform)
+				continue;
+
+			targetConf = it->second.second;
+			conf.insert(conf.end(), targetConf.begin(),
+					targetConf.end());
+			break;
+		}
+
 		return conf;
 	}
 
@@ -2162,11 +2191,18 @@
 		int ct = 0;
 		bool read_ok = false;
 
+		soc_id = 0;
 		do {
 			if (cmnInst.readFromFile(socIDPath, soc_val) <= 0) {
 				LOG(ERROR) <<"soc ID fetch error";
 				return;
 			}
+
+			if (cmnInst.readFromFile(hwPlatformPath, hw_platform) <= 0) {
+				LOG(ERROR) <<"hw Platform fetch error";
+				continue;
+			}
+
 			try {
 				soc_id = std::stoi(soc_val, nullptr, 0);
 				read_ok = true;
@@ -2175,8 +2211,7 @@
 				LOG(ERROR) <<"soc id stoi err:" << err.what()
 					<< " buf:" << soc_val;
 			}
-			ct++;
-		} while (!read_ok && ct < RETRY_CT);
+		} while (ct++ && !read_ok && ct < RETRY_CT);
 		if (soc_id <= 0) {
 			LOG(ERROR) << "Invalid soc ID: " << soc_id;
 			return;
@@ -2186,7 +2221,7 @@
 			LOG(ERROR) << "No config for soc ID: " << soc_id;
 			return;
 		}
-		thermalConfig = add_target_config(soc_id, it->second);
+		thermalConfig = add_target_config(soc_id, hw_platform, it->second);
 		for (it_vec = thermalConfig.begin();
 				it_vec != thermalConfig.end(); it_vec++) {
 			if (it_vec->type == TemperatureType::BCL_PERCENTAGE)
diff --git a/thermalConfig.h b/thermalConfig.h
index ae74111..c384e4c 100644
--- a/thermalConfig.h
+++ b/thermalConfig.h
@@ -59,6 +59,7 @@
 	private:
 		std::vector<struct target_therm_cfg> thermalConfig;
 		int soc_id;
+		std::string hw_platform;
 		ThermalCommon cmnInst;
 };