Merge 4e5dda45d661e25cc44399900aaa629537834153 on remote branch

Change-Id: I5a4456667c05d79d2e6f1e369a379384cee8bd63
diff --git a/thermalConfig.cpp b/thermalConfig.cpp
index 2295e5f..afe0c85 100644
--- a/thermalConfig.cpp
+++ b/thermalConfig.cpp
@@ -63,6 +63,7 @@
 #include <unordered_map>
 #include <android-base/logging.h>
 #include <android/hardware/thermal/2.0/IThermal.h>
+#include <utility>
 
 #include "thermalData.h"
 #include "thermalConfig.h"
@@ -73,6 +74,7 @@
 namespace V2_0 {
 namespace implementation {
 	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 =
 	{
@@ -1205,18 +1207,6 @@
 			95000,
 			true,
 		},
-	};
-
-	std::vector<struct target_therm_cfg>  ravelin_specific = {
-		{
-			TemperatureType::BCL_CURRENT,
-			{ "pmi632-ibat-lvl0" },
-			"ibat",
-			6000,
-			7500,
-			6000,
-			true,
-		},
 		{
 			TemperatureType::SKIN,
 			{ "sys-therm-1" },
@@ -1227,6 +1217,31 @@
 			true,
 		},
 	};
+
+	std::vector<struct target_therm_cfg>  ravelin_specific_qrd = {
+		{
+			TemperatureType::BCL_CURRENT,
+			{ "pmi632-ibat-lvl0" },
+			"ibat",
+			6000,
+			7500,
+			6000,
+			true,
+		},
+	};
+
+	std::vector<struct target_therm_cfg>  ravelin_specific_idp = {
+		{
+			TemperatureType::BCL_CURRENT,
+			{ "pm7250b-ibat-lvl0" },
+			"ibat",
+			6000,
+			7500,
+			6000,
+			true,
+		},
+	};
+
 	struct target_therm_cfg bat_conf = {
 		TemperatureType::BATTERY,
 		{ "battery" },
@@ -1335,24 +1350,40 @@
 		{583, parrot_specific}, //Netrani mobile without modem
 		{613, parrot_specific}, //Netrani APQ
 		{549, anorak_specific},
-		{568, ravelin_specific}, //Clarence Mobile
-		{581, ravelin_specific}, //Clarence IOT
-		{582, ravelin_specific}, //Clarence IOT without modem
 		{591, waipio_specific}, //ukee
 	};
 
+	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;
 	}
 
@@ -1365,11 +1396,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;
@@ -1378,8 +1416,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;
@@ -1389,7 +1426,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 07f3375..4614616 100644
--- a/thermalConfig.h
+++ b/thermalConfig.h
@@ -26,6 +26,38 @@
  * 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.
+ *
+ * Changes from Qualcomm Innovation Center are provided under the following license:
+ *
+ * Copyright (c) 2023, Qualcomm Innovation Center, Inc. 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 Qualcomm Innovation Center, Inc. nor the
+ *	  names of its contributors may be used to endorse or promote products
+ *	  derived from this software without specific prior written permission.
+ *
+ *
+ * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED
+ * BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
+ * AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER
+ * 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.
  */
 
 #ifndef THERMAL_THERMAL_CONFIG_H__
@@ -55,6 +87,7 @@
 	private:
 		std::vector<struct target_therm_cfg> thermalConfig;
 		int soc_id;
+		std::string hw_platform;
 		ThermalCommon cmnInst;
 };