Merge "dev: gcdb: extend fastboot oem support for dual DSI cases"
diff --git a/dev/gcdb/display/include/panel_nt35597_wqxga_dualdsi_cmd.h b/dev/gcdb/display/include/panel_nt35597_wqxga_dualdsi_cmd.h
index b2bf27f..b01752a 100644
--- a/dev/gcdb/display/include/panel_nt35597_wqxga_dualdsi_cmd.h
+++ b/dev/gcdb/display/include/panel_nt35597_wqxga_dualdsi_cmd.h
@@ -230,7 +230,7 @@
 /* Panel timing                                                              */
 /*---------------------------------------------------------------------------*/
 static const uint32_t nt35597_wqxga_dualdsi_cmd_timings[] = {
-	0xe2, 0x36, 0x24, 0x00, 0x66, 0x6a, 0x28, 0x38,  0x2a, 0x03, 0x04, 0x00
+	0xd5, 0x32, 0x22, 0x00, 0x60, 0x64, 0x26, 0x36, 0x29, 0x03, 0x04, 0x00
 };
 
 static const uint32_t nt35597_wqxga_dualdsi_thulium_cmd_timings[] = {
diff --git a/dev/pmic/pm8x41/include/pm8x41_hw.h b/dev/pmic/pm8x41/include/pm8x41_hw.h
index 0a8e2e8..2bae818 100644
--- a/dev/pmic/pm8x41/include/pm8x41_hw.h
+++ b/dev/pmic/pm8x41/include/pm8x41_hw.h
@@ -94,6 +94,9 @@
 /* USB Peripheral registers */
 #define SMBCHGL_USB_ICL_STS_2                 0x1309
 
+/* PMI8950 slave id */
+#define PMI8950_SLAVE_ID 0x20000
+
 /* USB Peripheral register bits */
 #define USBIN_ACTIVE_PWR_SRC                  BIT(0)
 #define DCIN_ACTIVE_PWR_SRC                   BIT(1)
diff --git a/dev/pmic/pm8x41/pm8x41.c b/dev/pmic/pm8x41/pm8x41.c
index 6733656..0a43bff 100644
--- a/dev/pmic/pm8x41/pm8x41.c
+++ b/dev/pmic/pm8x41/pm8x41.c
@@ -545,7 +545,7 @@
 {
 	uint8_t pon_reason = 0;
 
-	pon_reason = REG_READ(SMBCHGL_USB_ICL_STS_2);
+	pon_reason = REG_READ(SMBCHGL_USB_ICL_STS_2|PMI8950_SLAVE_ID);
 	/* check usbin/dcin status on pmi and set the corresponding bits for pon */
 	pon_reason = (pon_reason & (USBIN_ACTIVE_PWR_SRC|DCIN_ACTIVE_PWR_SRC)) << 3 ;
 	pon_reason |= REG_READ(PON_PON_REASON1);
diff --git a/target/mdm9640/init.c b/target/mdm9640/init.c
index 567ccde..2d2bb4b 100644
--- a/target/mdm9640/init.c
+++ b/target/mdm9640/init.c
@@ -84,7 +84,7 @@
 #define LAST_NAND_PTN_LEN_PATTERN                     0xFFFFFFFF
 
 #define EXT4_CMDLINE  " rootwait rootfstype=ext4 root=/dev/mmcblk0p"
-#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read ubi.fm_autoconvert=1"
+#define UBI_CMDLINE " rootfstype=ubifs rootflags=bulk_read"
 
 struct qpic_nand_init_config config;
 
@@ -135,6 +135,8 @@
 {
 	dprintf(INFO, "target_init()\n");
 
+	pmic_info_populate();
+
 	spmi_init(PMIC_ARB_CHANNEL_NUM, PMIC_ARB_OWNER_ID);
 
 	if (platform_boot_dev_isemmc()) {
diff --git a/target/msm8952/include/target/display.h b/target/msm8952/include/target/display.h
index 5c02765..87cbc3a 100644
--- a/target/msm8952/include/target/display.h
+++ b/target/msm8952/include/target/display.h
@@ -91,8 +91,6 @@
 #define MIPI_VSYNC_BACK_PORCH_LINES  3
 #define MIPI_VSYNC_FRONT_PORCH_LINES 9
 
-#endif
-
 /*---------------------------------------------------------------------------*/
 /* Functions		                                                     */
 /*---------------------------------------------------------------------------*/
@@ -104,3 +102,6 @@
 int target_display_get_base_offset(uint32_t base);
 void target_force_cont_splash_disable(uint8_t override);
 uint8_t target_panel_auto_detect_enabled();
+uint32_t oem_panel_max_auto_detect_panels();
+
+#endif
diff --git a/target/msm8952/init.c b/target/msm8952/init.c
index 99550f5..e1a61c4 100644
--- a/target/msm8952/init.c
+++ b/target/msm8952/init.c
@@ -503,6 +503,23 @@
         splash_override = override;
 }
 
+uint8_t target_panel_auto_detect_enabled()
+{
+	uint8_t ret = 0;
+
+	switch(board_hardware_id())
+	{
+		case HW_PLATFORM_QRD:
+			ret = platform_is_msm8956() ? 1 : 0;
+			break;
+		case HW_PLATFORM_SURF:
+		case HW_PLATFORM_MTP:
+		default:
+			ret = 0;
+	}
+	return ret;
+}
+
 /* Do any target specific intialization needed before entering fastboot mode */
 void target_fastboot_init(void)
 {
diff --git a/target/msm8952/oem_panel.c b/target/msm8952/oem_panel.c
index b64ac32..603f990 100644
--- a/target/msm8952/oem_panel.c
+++ b/target/msm8952/oem_panel.c
@@ -49,6 +49,7 @@
 #include "include/panel_sharp_1080p_cmd.h"
 #include "include/panel_nt35597_wqxga_dualdsi_video.h"
 #include "include/panel_nt35597_wqxga_dualdsi_cmd.h"
+#include "include/panel_hx8399a_1080p_video.h"
 
 /*---------------------------------------------------------------------------*/
 /* static panel selection variable                                           */
@@ -60,6 +61,7 @@
 	SHARP_1080P_CMD_PANEL,
 	NT35597_WQXGA_DUALDSI_VIDEO_PANEL,
 	NT35597_WQXGA_DUALDSI_CMD_PANEL,
+	HX8399A_1080P_VIDEO_PANEL,
 	UNKNOWN_PANEL
 };
 
@@ -77,6 +79,8 @@
 	{"sharp_1080p_cmd", SHARP_1080P_CMD_PANEL},
 	{"nt35597_wqxga_dualdsi_video", NT35597_WQXGA_DUALDSI_VIDEO_PANEL},
 	{"nt35597_wqxga_dualdsi_cmd", NT35597_WQXGA_DUALDSI_CMD_PANEL},
+	{"otm1906c_1080p_cmd", OTM1906C_1080P_CMD_PANEL},
+	{"hx8399a_1080p_video", HX8399A_1080P_VIDEO_PANEL},
 };
 
 static uint32_t panel_id;
@@ -198,6 +202,31 @@
 			otm1906c_1080p_cmd_timings, TIMING_SIZE);
 		pinfo->mipi.signature = OTM1906C_1080P_CMD_SIGNATURE;
 		break;
+	case HX8399A_1080P_VIDEO_PANEL:
+		panelstruct->paneldata    = &hx8399a_1080p_video_panel_data;
+		panelstruct->panelres     = &hx8399a_1080p_video_panel_res;
+		panelstruct->color        = &hx8399a_1080p_video_color;
+		panelstruct->videopanel   = &hx8399a_1080p_video_video_panel;
+		panelstruct->commandpanel = &hx8399a_1080p_video_command_panel;
+		panelstruct->state        = &hx8399a_1080p_video_state;
+		panelstruct->laneconfig   = &hx8399a_1080p_video_lane_config;
+		panelstruct->paneltiminginfo
+			= &hx8399a_1080p_video_timing_info;
+		panelstruct->panelresetseq
+					 = &hx8399a_1080p_video_reset_seq;
+		panelstruct->backlightinfo = &hx8399a_1080p_video_backlight;
+		pinfo->mipi.panel_on_cmds
+			= hx8399a_1080p_video_on_command;
+		pinfo->mipi.num_of_panel_on_cmds
+			= HX8399A_1080P_VIDEO_ON_COMMAND;
+		pinfo->mipi.panel_off_cmds
+			= hx8399a_1080p_video_off_command;
+		pinfo->mipi.num_of_panel_off_cmds
+			= HX8399A_1080P_VIDEO_OFF_COMMAND;
+		memcpy(phy_db->timing,
+			hx8399a_1080p_video_timings, TIMING_SIZE);
+		pinfo->mipi.signature = HX8399A_1080P_VIDEO_SIGNATURE;
+		break;
 	case SHARP_1080P_CMD_PANEL:
 		panelstruct->paneldata    = &sharp_1080p_cmd_panel_data;
 		panelstruct->panelres     = &sharp_1080p_cmd_panel_res;
@@ -268,6 +297,9 @@
 		panelstruct->laneconfig   = &nt35597_wqxga_dualdsi_cmd_lane_config;
 		panelstruct->paneltiminginfo
 			= &nt35597_wqxga_dualdsi_cmd_timing_info;
+		/* Clkout timings are different for this panel on 8956 */
+		panelstruct->paneltiminginfo->tclk_post = 0x2b;
+		panelstruct->paneltiminginfo->tclk_pre = 0x28;
 		panelstruct->panelresetseq
 					 = &nt35597_wqxga_dualdsi_cmd_reset_seq;
 		panelstruct->backlightinfo = &nt35597_wqxga_dualdsi_cmd_backlight;
@@ -302,6 +334,15 @@
 	return pan_type;
 }
 
+#define DISPLAY_MAX_PANEL_DETECTION 2
+static uint32_t auto_pan_loop = 0;
+
+uint32_t oem_panel_max_auto_detect_panels()
+{
+	return target_panel_auto_detect_enabled() ?
+		DISPLAY_MAX_PANEL_DETECTION : 0;
+}
+
 int oem_panel_select(const char *panel_name, struct panel_struct *panelstruct,
 			struct msm_panel_info *pinfo,
 			struct mdss_dsi_phy_ctrl *phy_db)
@@ -341,6 +382,24 @@
 		break;
 	case HW_PLATFORM_QRD:
 		panel_id = OTM1906C_1080P_CMD_PANEL;
+
+		/* QRD EVT1 uses OTM1906C, and EVT2 uses HX8399A */
+		if (platform_is_msm8956()) {
+			switch (auto_pan_loop) {
+				case 0:
+					panel_id = HX8399A_1080P_VIDEO_PANEL;
+					break;
+				case 1:
+					panel_id = OTM1906C_1080P_CMD_PANEL;
+					break;
+				default:
+					panel_id = UNKNOWN_PANEL;
+					dprintf(CRITICAL, "Unknown panel\n");
+					return PANEL_TYPE_UNKNOWN;
+			}
+			auto_pan_loop++;
+		}
+
 		break;
 	default:
 		dprintf(CRITICAL, "Display not enabled for %d HW type\n",
diff --git a/target/msm8952/target_display.c b/target/msm8952/target_display.c
index e89beb5..adc5815 100644
--- a/target/msm8952/target_display.c
+++ b/target/msm8952/target_display.c
@@ -522,6 +522,8 @@
 void target_display_init(const char *panel_name)
 {
 	struct oem_panel_data oem;
+	int32_t ret = 0;
+	uint32_t panel_loop = 0;
 
 	set_panel_cmd_string(panel_name);
 	oem = mdss_dsi_get_oem_data();
@@ -535,10 +537,16 @@
 		return;
 	}
 
-	if (gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR)) {
-		target_force_cont_splash_disable(true);
-		msm_display_off();
-	}
+	do {
+		target_force_cont_splash_disable(false);
+		ret = gcdb_display_init(oem.panel, MDP_REV_50, (void *)MIPI_FB_ADDR);
+		if (!ret || ret == ERR_NOT_SUPPORTED) {
+			break;
+		} else {
+			target_force_cont_splash_disable(true);
+			msm_display_off();
+		}
+	} while (++panel_loop <= oem_panel_max_auto_detect_panels());
 
 	if (!oem.cont_splash) {
 		dprintf(INFO, "Forcing continuous splash disable\n");