dev: gcdb: display: add support to swap DSI lanes to drive a panel

On CDP devices, some panels have the support for an adapter/interposer
card to swap the DSI controller/PHY that drive the panel. This is to
faciliate the usage of a different panel as secondary for dual DSI
use-cases. Add support to specify this using fastboot oem command.

Example:
fastboot oem command for default truly 1080p panel (driven by DSI-0):
fastboot oem select-display-panel truly_1080p_video

fastboot oem command when interposer card is used (driven by DSI-1):
fastboot oem select-display-panel truly_1080p_video:swap

Change-Id: Ia7871200949d2abc8a5d2d8e55ec9315fe5aa37e
diff --git a/dev/gcdb/display/gcdb_display.c b/dev/gcdb/display/gcdb_display.c
index 4aa95b0..6035ec3 100644
--- a/dev/gcdb/display/gcdb_display.c
+++ b/dev/gcdb/display/gcdb_display.c
@@ -408,6 +408,34 @@
 	return panelstruct;
 }
 
+static void mdss_dsi_check_swap_status(void)
+{
+	char *panel_dest, *dsi_controller;
+	struct oem_panel_data *oem_data = mdss_dsi_get_oem_data_ptr();
+
+	if (!oem_data->swap_dsi_ctrl)
+		return;
+
+	if (panelstruct.paneldata->panel_operating_mode &
+		(SPLIT_DISPLAY_FLAG | DUAL_DSI_FLAG)) {
+		dprintf(CRITICAL, "DSI swap invalid for split DSI panel!\n");
+		return;
+	}
+
+	/* Swap the panel destination and use appropriate PLL */
+	if (!strcmp(panelstruct.paneldata->panel_destination, "DISPLAY_1")) {
+		panel_dest = "DISPLAY_2";
+		dsi_controller = "dsi:1:";
+		panelstruct.paneldata->panel_operating_mode |= USE_DSI1_PLL_FLAG;
+	} else {
+		panel_dest = "DISPLAY_1";
+		dsi_controller = "dsi:0:";
+		panelstruct.paneldata->panel_operating_mode &= ~USE_DSI1_PLL_FLAG;
+	}
+	panelstruct.paneldata->panel_destination = panel_dest;
+	panelstruct.paneldata->panel_controller = dsi_controller;
+}
+
 static void mdss_dsi_set_pll_src(void)
 {
 	struct oem_panel_data *oem_data = mdss_dsi_get_oem_data_ptr();
@@ -460,6 +488,7 @@
 
 	if (pan_type == PANEL_TYPE_DSI) {
 		target_dsi_phy_config(&dsi_video_mode_phy_db);
+		mdss_dsi_check_swap_status();
 		mdss_dsi_set_pll_src();
 		if (dsi_panel_init(&(panel.panel_info), &panelstruct)) {
 			dprintf(CRITICAL, "DSI panel init failed!\n");
diff --git a/dev/gcdb/display/gcdb_display.h b/dev/gcdb/display/gcdb_display.h
index c71abbf..aaed691 100755
--- a/dev/gcdb/display/gcdb_display.h
+++ b/dev/gcdb/display/gcdb_display.h
@@ -72,6 +72,7 @@
 	char sec_panel[MAX_PANEL_ID_LEN];
 	bool cont_splash;
 	bool skip;
+	bool swap_dsi_ctrl;
 	uint32_t sim_mode;
 	char dsi_config[DSI_CFG_SIZE];
 	uint32_t dsi_pll_src;
diff --git a/dev/gcdb/display/gcdb_display_param.c b/dev/gcdb/display/gcdb_display_param.c
index 91ce12b..e236fa1 100644
--- a/dev/gcdb/display/gcdb_display_param.c
+++ b/dev/gcdb/display/gcdb_display_param.c
@@ -37,7 +37,8 @@
 #include "target/display.h"
 #include "fastboot_oem_display.h"
 
-struct oem_panel_data oem_data = {{'\0'}, {'\0'}, false, false, SIM_NONE, "single_dsi", DSI_PLL_DEFAULT};
+struct oem_panel_data oem_data = {{'\0'}, {'\0'}, false, false, false, SIM_NONE,
+	"single_dsi", DSI_PLL_DEFAULT};
 
 static int panel_name_to_dt_string(struct panel_lookup_list supp_panels[],
 			  uint32_t supp_panels_size,
@@ -195,6 +196,10 @@
 	ch = strstr((char *) panel_name, ":disable");
 	oem_data.cont_splash = ch ? false : true;
 
+	/* Interposer card to swap DSI0 and DSI1 lanes */
+	ch = strstr((char *) panel_name, ":swap");
+	oem_data.swap_dsi_ctrl = ch ? true : false;
+
 	/* DSI PLL source */
 	ch = strstr((char *) panel_name, ":pll0");
 	if (ch) {