Merge "target: project: msm8916: Add macro for PON register"
diff --git a/dev/gcdb/display/gcdb_display_param.c b/dev/gcdb/display/gcdb_display_param.c
index ce98cf0..fcf0953 100644
--- a/dev/gcdb/display/gcdb_display_param.c
+++ b/dev/gcdb/display/gcdb_display_param.c
@@ -290,6 +290,11 @@
 								panel_mode;
 			slave_panel_node =
 				panelstruct.paneldata->slave_panel_node_id;
+		} else if (oem_data.sec_panel &&
+			strcmp(oem_data.sec_panel, "")) {
+			dsi_id = SIM_DSI_ID;
+			panel_node = NO_PANEL_CONFIG;
+			panel_mode = 0;
 		} else {
 			if (target_is_edp())
 				default_str = "0:edp:";
@@ -322,7 +327,7 @@
 		return false;
 	}
 
-	if (oem_data.sec_panel) {
+	if (oem_data.sec_panel && strcmp(oem_data.sec_panel, "")) {
 		if (panel_mode & (DUAL_DSI_FLAG | SPLIT_DISPLAY_FLAG |
 			DST_SPLIT_FLAG)) {
 			dprintf(CRITICAL, "Invalid config: Primary panel is"
diff --git a/include/target.h b/include/target.h
index 84e93c0..b7f92a2 100644
--- a/include/target.h
+++ b/include/target.h
@@ -86,4 +86,5 @@
 void target_crypto_init_params(void);
 int target_cont_splash_screen(void);
 bool target_build_variant_user();
+void pmic_reset_configure(uint8_t reset_type);
 #endif
diff --git a/platform/mdmfermium/platform.c b/platform/mdmfermium/platform.c
index 7d05f04..3ca23a0 100644
--- a/platform/mdmfermium/platform.c
+++ b/platform/mdmfermium/platform.c
@@ -37,9 +37,11 @@
 
 void platform_early_init(void)
 {
+	board_init();
+	platform_clock_init();
 	qgic_init();
 	qtimer_init();
-//	scm_init();
+	scm_init();
 }
 
 void platform_init(void)
@@ -50,6 +52,7 @@
 void platform_uninit(void)
 {
 	qtimer_uninit();
+	qpic_nand_uninit();
 }
 
 uint32_t platform_get_sclk_count(void)
diff --git a/platform/msm_shared/include/scm.h b/platform/msm_shared/include/scm.h
index 002847f..0bd7eda 100644
--- a/platform/msm_shared/include/scm.h
+++ b/platform/msm_shared/include/scm.h
@@ -465,4 +465,5 @@
 int scm_device_enter_dload();
 int scm_call2_atomic(uint32_t svc, uint32_t cmd, uint32_t arg1, uint32_t arg2);
 uint32_t scm_io_write(uint32_t address, uint32_t val);
+int is_scm_call_available(uint32_t svc_id, uint32_t cmd_id);
 #endif
diff --git a/platform/msm_shared/mipi_dsi.c b/platform/msm_shared/mipi_dsi.c
index f7115c1..06c4804 100644
--- a/platform/msm_shared/mipi_dsi.c
+++ b/platform/msm_shared/mipi_dsi.c
@@ -389,6 +389,14 @@
 			tmp |= BIT(28);
 			writel(tmp, mipi->sctl_base + LANE_CTL);
 		}
+
+		if ((mipi->mode == DSI_CMD_MODE) &&
+				(readl(mipi->sctl_base) >= DSI_HW_REV_103)) {
+			uint32_t tmp;
+			tmp = readl(mipi->sctl_base + 0x01b8);
+			tmp |= BIT(16); /* enable burst mode */
+			writel(tmp, mipi->sctl_base + 0x01b8);
+		}
 	}
 
 	writel(0x0001, mipi->ctl_base + SOFT_RESET);
@@ -414,6 +422,14 @@
 		writel(tmp, mipi->ctl_base + LANE_CTL);
 	}
 
+	if ((mipi->mode == DSI_CMD_MODE) &&
+			(readl(mipi->ctl_base) >= DSI_HW_REV_103)) {
+		uint32_t tmp;
+		tmp = readl(mipi->ctl_base + 0x01b8);
+		tmp |= BIT(16); /* enable burst mode */
+		writel(tmp, mipi->ctl_base + 0x01b8);
+	}
+
 	if ((mipi->mode == DSI_VIDEO_MODE) && mipi->tx_eot_append)
 		writel(0x1, mipi->ctl_base + EOT_PACKET_CTRL);
 
diff --git a/platform/msm_shared/reboot.c b/platform/msm_shared/reboot.c
index fb29ab5..2fe514e 100644
--- a/platform/msm_shared/reboot.c
+++ b/platform/msm_shared/reboot.c
@@ -31,22 +31,12 @@
 #include <reg.h>
 #include <target.h>
 #include <platform.h>
-#include <uart_dm.h>
-#include <mmc.h>
-#include <dev/keys.h>
-#include <spmi_v2.h>
 #include <pm8x41.h>
-#include <board.h>
-#include <baseband.h>
-#include <hsusb.h>
+#include <pm8x41_hw.h>
 #include <scm.h>
-#include <platform/gpio.h>
-#include <platform/irqs.h>
-#include <platform/clock.h>
-#include <crypto5_wrapper.h>
-#include <partition_parser.h>
 #include <stdlib.h>
 #include <reboot.h>
+#include <qtimer.h>
 
 #if USER_FORCE_RESET_SUPPORT
 /* Return 1 if it is a force resin triggered by user. */
@@ -84,9 +74,9 @@
 	/* Read reboot reason and scrub it
 	 * Bit-5, bit-6 and bit-7 of SOFT_RB_SPARE for hard reset reason
 	 */
-	value = pm8x41_reg_read(PON_SOFT_RB_SPARE);
+	value = REG_READ(PON_SOFT_RB_SPARE);
 	hard_restart_reason = value >> 5;
-	pm8x41_reg_write(PON_SOFT_RB_SPARE, value & 0x1f);
+	REG_WRITE(PON_SOFT_RB_SPARE, value & 0x1f);
 
 	return hard_restart_reason;
 }
@@ -109,7 +99,10 @@
 void reboot_device(unsigned reboot_reason)
 {
 	uint8_t reset_type = 0;
-	uint32_t ret = 0;
+	int ret = 0;
+#if USE_PON_REBOOT_REG
+	uint8_t value;
+#endif
 
 	/* Need to clear the SW_RESET_ENTRY register and
 	 * write to the BOOT_MISC_REG for known reset cases
@@ -117,21 +110,35 @@
 	if(reboot_reason != DLOAD)
 		scm_dload_mode(NORMAL_MODE);
 
+#if USE_PON_REBOOT_REG
+	value = REG_READ(PON_SOFT_RB_SPARE);
+	value |= ((reboot_reason << 5) & 0xff);
+	REG_WRITE(PON_SOFT_RB_SPARE, value);
+#else
 	writel(reboot_reason, RESTART_REASON_ADDR);
-
-	/* For Reboot-bootloader and Dload cases do a warm reset
-	 * For Reboot cases do a hard reset
+#endif
+	/* For Dload cases do a warm reset
+	 * For other cases do a hard reset
 	 */
-	if((reboot_reason == FASTBOOT_MODE) || (reboot_reason == DLOAD) || (reboot_reason == RECOVERY_MODE))
+#if USE_PON_REBOOT_REG
+	if(reboot_reason == DLOAD)
+#else
+	if(reboot_reason == FASTBOOT_MODE || (reboot_reason == DLOAD) || (reboot_reason == RECOVERY_MODE))
+#endif
 		reset_type = PON_PSHOLD_WARM_RESET;
 	else
 		reset_type = PON_PSHOLD_HARD_RESET;
 
-	pm8x41_reset_configure(reset_type);
+	pmic_reset_configure(reset_type);
 
-	ret = scm_halt_pmic_arbiter();
-	if (ret)
-		dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
+	/* Force spmi shutdown to avoid spmi lock up on some pmics */
+	ret = is_scm_call_available(SCM_SVC_PWR, SCM_IO_DISABLE_PMIC_ARBITER);
+	if ( ret > 0)
+	{
+		ret = scm_halt_pmic_arbiter();
+		if (ret)
+			dprintf(CRITICAL , "Failed to halt pmic arbiter: %d\n", ret);
+	}
 
 	/* Drop PS_HOLD for MSM */
 	writel(0x00, MPM2_MPM_PS_HOLD);
@@ -141,3 +148,19 @@
 	dprintf(CRITICAL, "Rebooting failed\n");
 }
 
+void shutdown_device()
+{
+	dprintf(CRITICAL, "Going down for shutdown.\n");
+
+	/* Configure PMIC for shutdown. */
+	pmic_reset_configure(PON_PSHOLD_SHUTDOWN);
+
+	/* Drop PS_HOLD for MSM */
+	writel(0x00, MPM2_MPM_PS_HOLD);
+
+	mdelay(5000);
+
+	dprintf(CRITICAL, "Shutdown failed\n");
+
+	ASSERT(0);
+}
diff --git a/platform/msm_shared/reboot.h b/platform/msm_shared/reboot.h
index 7156c01..c87f9d8 100644
--- a/platform/msm_shared/reboot.h
+++ b/platform/msm_shared/reboot.h
@@ -29,6 +29,7 @@
 #define FASTBOOT_MODE     0x77665500
 #define RECOVERY_MODE     0x77665502
 #define ALARM_BOOT        0x77665503
+
 #define RTC_TRG           4
 #define PON_SOFT_RB_SPARE 0x88F
 
@@ -44,3 +45,4 @@
 uint32_t check_alarm_boot(void);
 
 void reboot_device(unsigned reboot_reason);
+void shutdown_device();
diff --git a/platform/msm_shared/rules.mk b/platform/msm_shared/rules.mk
index eacc445..944384e 100644
--- a/platform/msm_shared/rules.mk
+++ b/platform/msm_shared/rules.mk
@@ -521,6 +521,7 @@
 			$(LOCAL_DIR)/spmi.o \
 			$(LOCAL_DIR)/bam.o \
 			$(LOCAL_DIR)/qpic_nand.o \
+			$(LOCAL_DIR)/flash-ubi.o \
 			$(LOCAL_DIR)/scm.o \
 			$(LOCAL_DIR)/dev_tree.o
 endif
@@ -616,10 +617,11 @@
 	OBJS += $(LOCAL_DIR)/partial_goods.o
 endif
 
-ifeq ($(ENABLE_RPMB_SUPPORT), 1)
-include platform/msm_shared/rpmb/rules.mk
-endif
 
 ifeq ($(ENABLE_REBOOT_MODULE), 1)
 	OBJS += $(LOCAL_DIR)/reboot.o
 endif
+
+ifeq ($(ENABLE_RPMB_SUPPORT), 1)
+include platform/msm_shared/rpmb/rules.mk
+endif
diff --git a/platform/msm_shared/scm.c b/platform/msm_shared/scm.c
index bccdb3d..2dda14e 100644
--- a/platform/msm_shared/scm.c
+++ b/platform/msm_shared/scm.c
@@ -62,7 +62,7 @@
 	return scm_arm_support;
 }
 
-static int is_scm_call_available(uint32_t svc_id, uint32_t cmd_id)
+int is_scm_call_available(uint32_t svc_id, uint32_t cmd_id)
 {
 	int ret;
 	scmcall_arg scm_arg = {0};
diff --git a/project/mdmfermium.mk b/project/mdmfermium.mk
index 970594c..8a7b5f5 100644
--- a/project/mdmfermium.mk
+++ b/project/mdmfermium.mk
@@ -13,7 +13,9 @@
 endif
 
 DEFINES += WITH_DEBUG_UART=1
+DEFINES += WITH_DEBUG_LOG_BUF=1
 DEFINES += DEVICE_TREE=1
+DEFINES += CONTIGUOUS_MEMORY=1
 
 DEFINES += BAM_V170=1
 #Disable thumb mode
diff --git a/project/msm8909.mk b/project/msm8909.mk
index 64805e9..b7094e6 100644
--- a/project/msm8909.mk
+++ b/project/msm8909.mk
@@ -72,3 +72,5 @@
 
 #Enable the external reboot functions
 ENABLE_REBOOT_MODULE := 1
+#Use PON register for reboot reason
+DEFINES += USE_PON_REBOOT_REG=1
diff --git a/project/msm8996.mk b/project/msm8996.mk
index 2669b56..e885f30 100644
--- a/project/msm8996.mk
+++ b/project/msm8996.mk
@@ -82,3 +82,6 @@
 
 #SCM call before entering DLOAD mode
 DEFINES += PLATFORM_USE_SCM_DLOAD=1
+
+#Enable the external reboot functions
+ENABLE_REBOOT_MODULE := 1
diff --git a/target/mdmfermium/init.c b/target/mdmfermium/init.c
index 7e32f52..8c58278 100644
--- a/target/mdmfermium/init.c
+++ b/target/mdmfermium/init.c
@@ -165,8 +165,8 @@
 	qpic_nand_init(&config);
 
 	ptable_init(&flash_ptable);
-	//smem_ptable_init();
-	//smem_add_modem_partitions(&flash_ptable);
+	smem_ptable_init();
+	smem_add_modem_partitions(&flash_ptable);
 
 	update_ptable_names();
 	flash_set_ptable(&flash_ptable);
@@ -241,7 +241,7 @@
 	uint32_t val;
 
 	/* Select and enable external configuration with USB PHY */
-	//ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
+	ulpi_write(ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT, ULPI_MISC_A_SET);
 
 	/* Enable sess_vld */
 	val = readl(USB_GENCONFIG_2) | GEN2_SESS_VLD_CTRL_EN;
diff --git a/target/msm8909/init.c b/target/msm8909/init.c
index 72506f3..b115bf8 100644
--- a/target/msm8909/init.c
+++ b/target/msm8909/init.c
@@ -390,21 +390,6 @@
 	return LINUX_MACHTYPE_UNKNOWN;
 }
 
-/* Configure PMIC and Drop PS_HOLD for shutdown */
-void shutdown_device()
-{
-	dprintf(CRITICAL, "Going down for shutdown.\n");
-
-	/* Configure PMIC for shutdown */
-	pm8x41_reset_configure(PON_PSHOLD_SHUTDOWN);
-
-	/* Drop PS_HOLD for MSM */
-	writel(0x00, MPM2_MPM_PS_HOLD);
-
-	mdelay(5000);
-
-}
-
 /* Detect the target type */
 void target_detect(struct board_data *board)
 {
@@ -703,3 +688,8 @@
 {
 	return board_hlos_subtype();
 }
+
+void pmic_reset_configure(uint8_t reset_type)
+{
+	pm8x41_reset_configure(reset_type);
+}
diff --git a/target/msm8996/init.c b/target/msm8996/init.c
index e9e8eea..e6cfeed 100644
--- a/target/msm8996/init.c
+++ b/target/msm8996/init.c
@@ -363,42 +363,6 @@
 	}
 }
 
-unsigned check_reboot_mode(void)
-{
-	uint32_t restart_reason = 0;
-	uint32_t restart_reason_addr;
-
-	restart_reason_addr = RESTART_REASON_ADDR;
-
-	/* Read reboot reason and scrub it */
-	restart_reason = readl(restart_reason_addr);
-	writel(0x00, restart_reason_addr);
-
-	return restart_reason;
-}
-
-void reboot_device(unsigned reboot_reason)
-{
-	uint8_t reset_type = 0;
-
-	/* Write the reboot reason */
-	writel(reboot_reason, RESTART_REASON_ADDR);
-
-	if(reboot_reason)
-		reset_type = PON_PSHOLD_WARM_RESET;
-	else
-		reset_type = PON_PSHOLD_HARD_RESET;
-
-	pm8994_reset_configure(reset_type);
-
-	/* Drop PS_HOLD for MSM */
-	writel(0x00, MPM2_MPM_PS_HOLD);
-
-	mdelay(5000);
-
-	dprintf(CRITICAL, "Rebooting failed\n");
-}
-
 int emmc_recovery_init(void)
 {
 	return _emmc_recovery_init();
@@ -503,19 +467,7 @@
 	return ret;
 }
 
-void shutdown_device()
+void pmic_reset_configure(uint8_t reset_type)
 {
-	dprintf(CRITICAL, "Going down for shutdown.\n");
-
-	/* Configure PMIC for shutdown. */
-	pm8994_reset_configure(PON_PSHOLD_SHUTDOWN);
-
-	/* Drop PS_HOLD for MSM */
-	writel(0x00, MPM2_MPM_PS_HOLD);
-
-	mdelay(5000);
-
-	dprintf(CRITICAL, "Shutdown failed\n");
-
-	ASSERT(0);
+	pm8994_reset_configure(reset_type);
 }