Merge "dev: pmic: Add power key detection support"
diff --git a/platform/mdm9x35/include/platform/iomap.h b/platform/mdm9x35/include/platform/iomap.h
index cf84ee7..81fd263 100755
--- a/platform/mdm9x35/include/platform/iomap.h
+++ b/platform/mdm9x35/include/platform/iomap.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -55,6 +55,9 @@
 #define MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL    0xFC4A3000
 #define MPM2_MPM_PS_HOLD                     0xFC4AB000
 
+#define BS_INFO_OFFSET            (0x6B0)
+#define BS_INFO_ADDR              (MSM_SHARED_IMEM_BASE + BS_INFO_OFFSET)
+
 #define SPMI_BASE                 0xFC4C0000
 #define SPMI_GENI_BASE            (SPMI_BASE + 0xA000)
 #define SPMI_PIC_BASE             (SPMI_BASE + 0xB000)
diff --git a/platform/mdm9x35/platform.c b/platform/mdm9x35/platform.c
index cab35c5..3604205 100755
--- a/platform/mdm9x35/platform.c
+++ b/platform/mdm9x35/platform.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -110,6 +110,16 @@
 	return 0;
 }
 
+uint32_t platform_get_sclk_count(void)
+{
+	return readl(MPM2_MPM_SLEEP_TIMETICK_COUNT_VAL);
+}
+
+addr_t get_bs_info_addr()
+{
+	return ((addr_t)BS_INFO_ADDR);
+}
+
 void platform_init_mmu_mappings(void)
 {
 	struct smem_ram_ptable *ram_ptable;
diff --git a/platform/msm_shared/board.c b/platform/msm_shared/board.c
index 3e93888..161a2ea 100644
--- a/platform/msm_shared/board.c
+++ b/platform/msm_shared/board.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -104,18 +104,15 @@
 		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));
-		}
+		 * fill in board.target with variant_id information
+		 * bit no         |31  24 | 23   16            | 15   8             |7         0|
+		 * board.target = |subtype| plat_hw_ver major  | plat_hw_ver minor  |hw_platform|
+		 *
+		 */
+		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));
 
 		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;
diff --git a/platform/msm_shared/dev_tree.c b/platform/msm_shared/dev_tree.c
index ef81891..11eb736 100644
--- a/platform/msm_shared/dev_tree.c
+++ b/platform/msm_shared/dev_tree.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -391,14 +391,35 @@
 
 static int platform_dt_match(struct dt_entry *cur_dt_entry, uint32_t target_variant_id, uint32_t subtype_mask)
 {
-	/* 1. must match the platform_id, hardware_id, platform_version
+	/*
+	 * 1. Check if cur_dt_entry has platform_hw_version major & minor present?
+	 * 2. If present, calculate cur_dt_target_id for the current platform as:
+	 * 3. bit no |31  24 | 23   16| 15   8 |7         0|
+	 * 4.        |subtype| major  | minor  |hw_platform|
+	 */
+	uint32_t cur_dt_target_id ;
+
+	/*
+	 * if variant_id has platform_hw_ver has major = 0xff and minor = 0xff,
+	 * ignore the major & minor versions from the DTB entry
+	 */
+	if ((cur_dt_entry->variant_id & 0xffff00) == 0xffff00)
+		cur_dt_target_id  = (cur_dt_entry->variant_id & 0xff0000ff) | (target_variant_id & 0xffff00);
+	/*
+	 * We have a valid platform_hw_version major & minor numbers in the board-id, so
+	 * use the board-id from the DTB.
+	 * Note: For some QRD platforms the format used is qcom, board-id = <0xMVmVPT 0xPS>
+	 * where: MV: platform major ver, mV: platform minor ver, PT: platform type
+	 * PS: platform subtype, so we need to put PS @ bit 24-31 to be backward compatible.
+	 */
+	else
+		cur_dt_target_id = cur_dt_entry->variant_id | ((cur_dt_entry->board_hw_subtype & subtype_mask & 0xff) << 24);
+
+	/* 1. must match the platform_id, platform_hw_id, platform_version
 	*  2. soc rev number equal then return 0
 	*  3. dt soc rev number less than cdt return -1
 	*  4. otherwise return 1
 	*/
-	uint32_t cur_dt_target_id ;
-
-	cur_dt_target_id  = cur_dt_entry->variant_id | ((cur_dt_entry->board_hw_subtype & subtype_mask & 0xff) << 24);
 
 	if((cur_dt_entry->platform_id == board_platform_id()) &&
 		(cur_dt_target_id == target_variant_id)) {
@@ -491,17 +512,17 @@
 	}
 
 	if (found != 0) {
-		dprintf(INFO, "Using DTB entry %u/%08x/%u/%u for device %u/%08x/%u/%u\n",
+		dprintf(INFO, "Using DTB entry %u/%08x/0x%08x/%u for device %u/%08x/0x%08x/%u\n",
 				dt_entry_info->platform_id, dt_entry_info->soc_rev,
 				dt_entry_info->variant_id, dt_entry_info->board_hw_subtype,
 				board_platform_id(), board_soc_version(),
-				board_hardware_id(), board_hardware_subtype());
+				board_target_id(), board_hardware_subtype());
 		return 0;
 	}
 
-	dprintf(CRITICAL, "ERROR: Unable to find suitable device tree for device (%u/0x%08x/%u/%u)\n",
+	dprintf(CRITICAL, "ERROR: Unable to find suitable device tree for device (%u/0x%08x/0x%08x/%u)\n",
 			board_platform_id(), board_soc_version(),
-			board_hardware_id(), board_hardware_subtype());
+			board_target_id(), board_hardware_subtype());
 	return -1;
 }
 
@@ -515,16 +536,15 @@
 {
 	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, 0xff) == 0) {
-			return 0;
-		}
+	target_variant_id = board_target_id();
+	if (__dev_tree_get_entry_info(table, dt_entry_info, target_variant_id, 0xff) == 0) {
+		return 0;
 	}
+
 	/*
-	* for compatible with version 1 and version 2 dtbtool
-	* will compare the subtype inside the variant id
-	*/
+	 * 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);
 	if (__dev_tree_get_entry_info(table, dt_entry_info, target_variant_id, 0xff) == 0) {
 		return 0;
@@ -792,20 +812,24 @@
 		return ret;
 	}
 
-	/* Adding the initrd-start to the chosen node */
-	ret = fdt_setprop_u32(fdt, offset, "linux,initrd-start", (uint32_t)ramdisk);
-	if (ret)
-	{
-		dprintf(CRITICAL, "ERROR: Cannot update chosen node [linux,initrd-start]\n");
-		return ret;
-	}
+	if (ramdisk_size) {
+		/* Adding the initrd-start to the chosen node */
+		ret = fdt_setprop_u32(fdt, offset, "linux,initrd-start",
+				      (uint32_t)ramdisk);
+		if (ret)
+		{
+			dprintf(CRITICAL, "ERROR: Cannot update chosen node [linux,initrd-start]\n");
+			return ret;
+		}
 
-	/* Adding the initrd-end to the chosen node */
-	ret = fdt_setprop_u32(fdt, offset, "linux,initrd-end", ((uint32_t)ramdisk + ramdisk_size));
-	if (ret)
-	{
-		dprintf(CRITICAL, "ERROR: Cannot update chosen node [linux,initrd-end]\n");
-		return ret;
+		/* Adding the initrd-end to the chosen node */
+		ret = fdt_setprop_u32(fdt, offset, "linux,initrd-end",
+				      ((uint32_t)ramdisk + ramdisk_size));
+		if (ret)
+		{
+			dprintf(CRITICAL, "ERROR: Cannot update chosen node [linux,initrd-end]\n");
+			return ret;
+		}
 	}
 
 	fdt_pack(fdt);
diff --git a/target/apq8084/init.c b/target/apq8084/init.c
index f2f1f7b..4a8c577 100644
--- a/target/apq8084/init.c
+++ b/target/apq8084/init.c
@@ -402,7 +402,7 @@
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/* This is alreay filled as part of board.c */
 }
 
 void set_cdp_baseband(struct board_data *board)
diff --git a/target/fsm9900/init.c b/target/fsm9900/init.c
index ae2f91b..f728909 100644
--- a/target/fsm9900/init.c
+++ b/target/fsm9900/init.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -312,7 +312,7 @@
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/* This property is filled as part of board.c */
 }
 
 /* Detect the modem type */
diff --git a/target/mdm9625/init.c b/target/mdm9625/init.c
index 77f7331..2298ff1 100644
--- a/target/mdm9625/init.c
+++ b/target/mdm9625/init.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -179,8 +179,7 @@
 /* Identify the current target */
 void target_detect(struct board_data *board)
 {
-	/* Not used. set to unknown */
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/* This property is filled as part of board.c */
 }
 
 unsigned board_machtype(void)
diff --git a/target/mdm9635/init.c b/target/mdm9635/init.c
index 89e17ad..e882b95 100644
--- a/target/mdm9635/init.c
+++ b/target/mdm9635/init.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -186,8 +186,7 @@
 /* Identify the current target */
 void target_detect(struct board_data *board)
 {
-	/* Not used. set to unknown */
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/* This property is filled as part of board.c */
 }
 
 unsigned board_machtype(void)
diff --git a/target/mpq8092/init.c b/target/mpq8092/init.c
index 1ac2c80..997a599 100644
--- a/target/mpq8092/init.c
+++ b/target/mpq8092/init.c
@@ -262,7 +262,7 @@
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/* This property is filled as part of board.c */
 }
 
 void target_baseband_detect(struct board_data *board)
diff --git a/target/msm8974/init.c b/target/msm8974/init.c
index 848307a..d60d477 100644
--- a/target/msm8974/init.c
+++ b/target/msm8974/init.c
@@ -402,7 +402,7 @@
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
-	board->target = LINUX_MACHTYPE_UNKNOWN;
+	/* This property is filled in board.c */
 }
 
 /* Detect the modem type */