Merge "target: msm8952: add support for hx8394d panel on msm8952"
diff --git a/app/aboot/aboot.c b/app/aboot/aboot.c
index 7ff5fae..df9a6be 100644
--- a/app/aboot/aboot.c
+++ b/app/aboot/aboot.c
@@ -76,6 +76,7 @@
 #include <wdog.h>
 #endif
 
+#include <reboot.h>
 #include "image_verify.h"
 #include "recovery.h"
 #include "bootimg.h"
@@ -122,14 +123,6 @@
 
 #define MAX_TAGS_SIZE   1024
 
-#define RECOVERY_HARD_RESET_MODE   0x01
-#define FASTBOOT_HARD_RESET_MODE   0x02
-#define RTC_HARD_RESET_MODE        0x03
-
-#define RECOVERY_MODE   0x77665502
-#define FASTBOOT_MODE   0x77665500
-#define ALARM_BOOT      0x77665503
-
 /* make 4096 as default size to ensure EFS,EXT4's erasing */
 #define DEFAULT_ERASE_SIZE  4096
 #define MAX_PANEL_BUF_SIZE 128
@@ -3180,7 +3173,6 @@
 void aboot_init(const struct app_descriptor *app)
 {
 	unsigned reboot_mode = 0;
-	unsigned hard_reboot_mode = 0;
 	bool boot_into_fastboot = false;
 
 	/* Setup page size information for nv storage */
@@ -3260,16 +3252,21 @@
 		boot_into_fastboot = true;
 	#endif
 
+#if USE_PON_REBOOT_REG
+	reboot_mode = check_hard_reboot_mode();
+#else
 	reboot_mode = check_reboot_mode();
-	hard_reboot_mode = check_hard_reboot_mode();
-	if (reboot_mode == RECOVERY_MODE ||
-		hard_reboot_mode == RECOVERY_HARD_RESET_MODE) {
+#endif
+	if (reboot_mode == RECOVERY_MODE)
+	{
 		boot_into_recovery = 1;
-	} else if(reboot_mode == FASTBOOT_MODE ||
-		hard_reboot_mode == FASTBOOT_HARD_RESET_MODE) {
+	}
+	else if(reboot_mode == FASTBOOT_MODE)
+	{
 		boot_into_fastboot = true;
-	} else if(reboot_mode == ALARM_BOOT ||
-		hard_reboot_mode == RTC_HARD_RESET_MODE) {
+	}
+	else if(reboot_mode == ALARM_BOOT)
+	{
 		boot_reason_alarm = true;
 	}
 
diff --git a/include/platform.h b/include/platform.h
index 50ef337..9c8e698 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -71,4 +71,5 @@
 uint32_t platform_get_max_periph();
 int platform_is_msm8996();
 uint64_t platform_get_ddr_start();
+bool platform_use_qmp_misc_settings();
 #endif
diff --git a/platform/msm8996/platform.c b/platform/msm8996/platform.c
index 090e81c..08c0025 100644
--- a/platform/msm8996/platform.c
+++ b/platform/msm8996/platform.c
@@ -222,3 +222,11 @@
 {
 	return ddr_start;
 }
+
+bool platform_use_qmp_misc_settings()
+{
+	if (board_soc_version() < 0x30000)
+		return true;
+
+	return false;
+}
diff --git a/platform/msm_shared/qmp_usb30_phy.c b/platform/msm_shared/qmp_usb30_phy.c
index 54a8831..91aed89 100644
--- a/platform/msm_shared/qmp_usb30_phy.c
+++ b/platform/msm_shared/qmp_usb30_phy.c
@@ -36,6 +36,7 @@
 #include <clock.h>
 #include <debug.h>
 #include <qtimer.h>
+#include <platform.h>
 
 #define HS_PHY_COMMON_CTRL             0xEC
 #define USE_CORECLK                    BIT(14)
@@ -64,15 +65,11 @@
 	{0x174, 0x30}, /* QSERDES_COM_CLK_SELECT */
 	{0x194, 0x06}, /* QSERDES_COM_CMN_CONFIG */
 	{0x19c, 0x01}, /* QSERDES_COM_SVS_MODE_CLK_SEL */
-	{0x178, 0x01}, /* QSERDES_COM_HSCLK_SEL */
+	{0x178, 0x00}, /* QSERDES_COM_HSCLK_SEL */
 	{0x70, 0x0F}, /* USB3PHY_QSERDES_COM_BG_TRIM */
 	{0x48, 0x0F}, /* USB3PHY_QSERDES_COM_PLL_IVCO */
 	{0x3C, 0x04}, /* QSERDES_COM_SYS_CLK_CTRL */
 
-	/* Res_code Settings */
-	{0xC4, 0x15}, /* USB3PHY_QSERDES_COM_RESCODE_DIV_NUM */
-	{0x1B8, 0x1F}, /* QSERDES_COM_CMN_MISC2 */
-
 	/* PLL & Loop filter settings */
 	{0xd0, 0x82}, /* QSERDES_COM_DEC_START_MODE0 */
 	{0xdc, 0x55}, /* QSERDES_COM_DIV_FRAC_START1_MODE0 */
@@ -134,6 +131,15 @@
 	{0x600, 0x00}, /* USB3_PHY_SW_RESET */
 };
 
+#if PLATFORM_USE_QMP_MISC
+struct qmp_reg qmp_misc_settings_rev2[] =
+{
+	{0x178, 0x01}, /* QSERDES_COM_HSCLK_SEL */
+	{0xC4, 0x15}, /* USB3PHY_QSERDES_COM_RESCODE_DIV_NUM */
+	{0x1B8, 0x1F}, /* QSERDES_COM_CMN_MISC2 */
+};
+#endif
+
 __WEAK uint32_t target_override_pll()
 {
 	return 0;
@@ -265,6 +271,11 @@
 		for (i = 0 ; i < qmp_reg_size; i++)
 			writel(qmp_settings_rev2[i].val, QMP_PHY_BASE + qmp_settings_rev2[i].off);
 
+#if PLATFORM_USE_QMP_MISC
+		if (platform_use_qmp_misc_settings())
+			for (i = 0; i < ARRAY_SIZE(qmp_misc_settings_rev2); i++)
+				writel(qmp_misc_settings_rev2[i].val, QMP_PHY_BASE + qmp_misc_settings_rev2[i].off);
+#endif
 		if (target_override_pll())
 		{
 			qmp_reg_size = sizeof(qmp_override_pll_rev2) / sizeof(struct qmp_reg);
diff --git a/platform/msm_shared/reboot.h b/platform/msm_shared/reboot.h
index c87f9d8..9ea23a8 100644
--- a/platform/msm_shared/reboot.h
+++ b/platform/msm_shared/reboot.h
@@ -26,9 +26,15 @@
  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
+#if USE_PON_REBOOT_REG
+#define RECOVERY_MODE     0x01
+#define FASTBOOT_MODE     0x02
+#define ALARM_BOOT        0x03
+#else
 #define FASTBOOT_MODE     0x77665500
 #define RECOVERY_MODE     0x77665502
 #define ALARM_BOOT        0x77665503
+#endif
 
 #define RTC_TRG           4
 #define PON_SOFT_RB_SPARE 0x88F
diff --git a/project/msm8996.mk b/project/msm8996.mk
index 4f6d1db..0484d6e 100644
--- a/project/msm8996.mk
+++ b/project/msm8996.mk
@@ -87,3 +87,7 @@
 ENABLE_REBOOT_MODULE := 1
 #fuse for Qusb tun2 config
 DEFINES += QFPROM_CORR_CALIB_ROW12_MSB=0x0007424C
+#Use misc settings for qmp
+DEFINES += PLATFORM_USE_QMP_MISC=1
+#Use PON register for reboot reason
+DEFINES += USE_PON_REBOOT_REG=1