dts: msm_shared: Use QRD variant_id algorithm for device tree selection

QRD msm8226 needs to use platform_version to
distinguish betweeen hardware such as EVT versus
DVT board. Fill in board.target with variant_id
information for QRD device tree match.

Change-Id: Idd5479bb5e5bd5efe27f5527c42eb6c527c360e3
diff --git a/platform/msm_shared/board.c b/platform/msm_shared/board.c
index dcc750d..3e93888 100644
--- a/platform/msm_shared/board.c
+++ b/platform/msm_shared/board.c
@@ -103,6 +103,20 @@
 		board.platform_hw = board_info_v8.board_info_v3.hw_platform;
 		board.platform_subtype = board_info_v8.platform_subtype;
 
+		/*
+		* fill in board.target with variant_id information
+		*                 bit no |31  24 | 23   16| 15   8 |7         0|
+		*          board.target =|subtype| major  | minor  |hw_platform|
+		* Have QRD board.target =| OEM   | EVT/DVT|Reserved| QRD        |
+		*
+		*/
+		if (board_info_v8.board_info_v3.hw_platform == HW_PLATFORM_QRD) {
+			board.target = (((board_info_v8.platform_subtype & 0xff) << 24) |
+					(((board_info_v8.platform_version >> 16) & 0xff) << 16) |
+					((board_info_v8.platform_version & 0xff) << 8) |
+					((board_info_v8.board_info_v3.hw_platform & 0xff) << 0));
+		}
+
 		for (i = 0; i < SMEM_V8_SMEM_MAX_PMIC_DEVICES; i++) {
 			board.pmic_info[i].pmic_type = board_info_v8.pmic_info[i].pmic_type;
 			board.pmic_info[i].pmic_version = board_info_v8.pmic_info[i].pmic_version;
diff --git a/platform/msm_shared/dev_tree.c b/platform/msm_shared/dev_tree.c
index de5384b..651551f 100644
--- a/platform/msm_shared/dev_tree.c
+++ b/platform/msm_shared/dev_tree.c
@@ -134,6 +134,8 @@
 	return 0;
 }
 
+static int __dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info, uint32_t target_variant_id);
+
 /* Function to obtain the index information for the correct device tree
  *  based on the platform data.
  *  If a matching device tree is found, the information is returned in the
@@ -142,6 +144,25 @@
  */
 int dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info)
 {
+	uint32_t target_variant_id;
+
+	if(board_hardware_id() == HW_PLATFORM_QRD) {
+		target_variant_id = board_target_id();
+		if (__dev_tree_get_entry_info(table, dt_entry_info, target_variant_id) == 0) {
+			return 0;
+		}
+	}
+	/*
+	* for compatible with version 1 and version 2 dtbtool
+	* will compare the subtype inside the variant id
+	*/
+	target_variant_id = board_hardware_id() | ((board_hardware_subtype() & 0xff) << 24);
+
+	return __dev_tree_get_entry_info(table, dt_entry_info, target_variant_id);
+}
+
+static int __dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info, uint32_t target_variant_id)
+{
 	uint32_t i;
 	unsigned char *table_ptr;
 	struct dt_entry dt_entry_buf_1;
@@ -191,8 +212,7 @@
 		 * than or equal to actual hardware
 		 */
 		if((cur_dt_entry->platform_id == board_platform_id()) &&
-		   (cur_dt_entry->variant_id == board_hardware_id()) &&
-		   (cur_dt_entry->board_hw_subtype == board_hardware_subtype()))
+		   ((cur_dt_entry->variant_id | ((cur_dt_entry->board_hw_subtype & 0xff) << 24)) == target_variant_id))
 		{
 			if(cur_dt_entry->soc_rev == board_soc_version()) {
 				/* copy structure */
@@ -362,3 +382,4 @@
 
 	return ret;
 }
+
diff --git a/target/msm8226/init.c b/target/msm8226/init.c
index 026aa53..5bb4887 100644
--- a/target/msm8226/init.c
+++ b/target/msm8226/init.c
@@ -190,7 +190,9 @@
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/*
+	* already fill the board->target on board.c
+	*/
 }
 
 /* Detect the modem type */
diff --git a/target/msm8610/init.c b/target/msm8610/init.c
index 6537a4d..99b4726 100644
--- a/target/msm8610/init.c
+++ b/target/msm8610/init.c
@@ -131,7 +131,10 @@
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/*
+	* already fill the board->target on board.c
+	*/
+
 }
 
 /* Detect the modem type */