Merge "target: msm8610: Support GCDB for 8x10 target"
diff --git a/target/msm8610/include/target/display.h b/target/msm8610/include/target/display.h
index 4c8bd15..9f9f609 100644
--- a/target/msm8610/include/target/display.h
+++ b/target/msm8610/include/target/display.h
@@ -29,6 +29,78 @@
 
 #ifndef _TARGET_MSM8610_DISPLAY_H
 #define _TARGET_MSM8610_DISPLAY_H
+/*---------------------------------------------------------------------------*/
+/* HEADER files                                                              */
+/*---------------------------------------------------------------------------*/
+#include <display_resource.h>
+
+/*---------------------------------------------------------------------------*/
+/* GPIO configuration                                                        */
+/*---------------------------------------------------------------------------*/
+static struct gpio_pin reset_gpio = {
+  "msmgpio", 41, 3, 1, 0, 1
+};
+
+static struct gpio_pin enable_gpio = {
+  0, 0, 0, 0, 0, 0
+};
+
+static struct gpio_pin te_gpio = {
+  "msmgpio", 12, 0, 2, 0, 1
+};
+
+static struct gpio_pin pwm_gpio = {
+  0, 0, 0, 0, 0, 0
+};
+
+static struct gpio_pin mode_gpio = {
+  "msmgpio", 7, 3, 1, 0, 1
+};
+
+
+/*---------------------------------------------------------------------------*/
+/* Supply configuration                                                      */
+/*---------------------------------------------------------------------------*/
+static struct ldo_entry ldo_entry_array[] = {
+{ "vddio", 14, 0, 1800000, 100000, 100, 0, 0, 0, 0},
+{ "vdda", 19, 0, 2850000, 100000, 100, 0, 0, 0, 0},
+};
+
+#define TOTAL_LDO_DEFINED 2
+
+/*---------------------------------------------------------------------------*/
+/* Target Physical configuration                                             */
+/*---------------------------------------------------------------------------*/
+
+static const uint32_t panel_strength_ctrl[] = {
+  0xff, 0x06
+};
+
+static const char panel_bist_ctrl[] = {
+  0x03, 0x03, 0x00, 0x00, 0x0f, 0x00
+};
+
+static const uint32_t panel_regulator_settings[] = {
+  0x02, 0x08, 0x05, 0x00, 0x20, 0x03, 0x00
+};
+
+static const char panel_lane_config[] = {
+	0x80, 0x45, 0x00, 0x00, 0x00, 0x01, 0x66, 0x00, 0x00,
+	0x80, 0x45, 0x00, 0x00, 0x00, 0x01, 0x66, 0x00, 0x00,
+	0x80, 0x45, 0x00, 0x00, 0x00, 0x01, 0x66, 0x00, 0x00,
+	0x80, 0x45, 0x00, 0x00, 0x00, 0x01, 0x66, 0x00, 0x00,
+	0x40, 0x67, 0x00, 0x00, 0x00, 0x01, 0x88, 0x00, 0x00
+};
+
+static const uint32_t panel_physical_ctrl[] = {
+  0x7f, 0x00, 0x00, 0x00
+};
+
+/*---------------------------------------------------------------------------*/
+/* Other Configuration                                                       */
+/*---------------------------------------------------------------------------*/
+
+#define msm8610_DSI_FEATURE_ENABLE 0
 
 #define MIPI_FB_ADDR  0x0D200000
 
diff --git a/target/msm8610/oem_panel.c b/target/msm8610/oem_panel.c
new file mode 100755
index 0000000..eabd70d
--- /dev/null
+++ b/target/msm8610/oem_panel.c
@@ -0,0 +1,144 @@
+/* Copyright (c) 2013, 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 met:
+ *  * Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  * Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  * Neither the name of The Linux Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <debug.h>
+#include <err.h>
+#include <smem.h>
+#include <msm_panel.h>
+#include <board.h>
+#include <mipi_dsi.h>
+
+#include "include/panel.h"
+#include "panel_display.h"
+
+/*---------------------------------------------------------------------------*/
+/* GCDB Panel Database                                                       */
+/*---------------------------------------------------------------------------*/
+#include "include/panel_truly_wvga_cmd.h"
+#include "include/panel_truly_wvga_video.h"
+
+/*---------------------------------------------------------------------------*/
+/* static panel selection variable                                           */
+/*---------------------------------------------------------------------------*/
+enum {
+TRULY_WVGA_CMD_PANEL,
+TRULY_WVGA_VIDEO_PANEL,
+};
+
+static uint32_t panel_id;
+
+int oem_panel_rotation()
+{
+	/* OEM can keep there panel spefic on instructions in this
+	function */
+	return NO_ERROR;
+}
+
+
+int oem_panel_on()
+{
+	/* OEM can keep there panel spefic on instructions in this
+	function */
+	return NO_ERROR;
+}
+
+int oem_panel_off()
+{
+	/* OEM can keep there panel spefic off instructions in this
+	function */
+	return NO_ERROR;
+}
+
+static bool init_panel_data(struct panel_struct *panelstruct,
+			struct msm_panel_info *pinfo,
+			struct mdss_dsi_phy_ctrl *phy_db)
+{
+	switch (panel_id) {
+	case TRULY_WVGA_CMD_PANEL:
+		panelstruct->paneldata    = &truly_wvga_cmd_panel_data;
+		panelstruct->panelres     = &truly_wvga_cmd_panel_res;
+		panelstruct->color        = &truly_wvga_cmd_color;
+		panelstruct->videopanel   = &truly_wvga_cmd_video_panel;
+		panelstruct->commandpanel = &truly_wvga_cmd_command_panel;
+		panelstruct->state        = &truly_wvga_cmd_state;
+		panelstruct->laneconfig   = &truly_wvga_cmd_lane_config;
+		panelstruct->paneltiminginfo
+					 = &truly_wvga_cmd_timing_info;
+		panelstruct->backlightinfo = &truly_wvga_cmd_backlight;
+		pinfo->mipi.panel_cmds
+					= truly_wvga_cmd_on_command;
+		pinfo->mipi.num_of_panel_cmds
+					= TRULY_WVGA_CMD_ON_COMMAND;
+		memcpy(phy_db->timing,
+			truly_wvga_cmd_timings, TIMING_SIZE);
+		break;
+	case TRULY_WVGA_VIDEO_PANEL:
+		panelstruct->paneldata    = &truly_wvga_video_panel_data;
+		panelstruct->panelres     = &truly_wvga_video_panel_res;
+		panelstruct->color        = &truly_wvga_video_color;
+		panelstruct->videopanel   = &truly_wvga_video_video_panel;
+		panelstruct->commandpanel = &truly_wvga_video_command_panel;
+		panelstruct->state        = &truly_wvga_video_state;
+		panelstruct->laneconfig   = &truly_wvga_video_lane_config;
+		panelstruct->paneltiminginfo
+					 = &truly_wvga_video_timing_info;
+		panelstruct->backlightinfo = &truly_wvga_video_backlight;
+		pinfo->mipi.panel_cmds
+					= truly_wvga_video_on_command;
+		pinfo->mipi.num_of_panel_cmds
+					= TRULY_WVGA_VIDEO_ON_COMMAND;
+		memcpy(phy_db->timing,
+				truly_wvga_video_timings, TIMING_SIZE);
+		break;
+	default:
+		dprintf(CRITICAL, "Panel ID not detected %d\n", panel_id);
+		return false;
+	}
+	return true;
+}
+
+bool oem_panel_select(struct panel_struct *panelstruct,
+			struct msm_panel_info *pinfo,
+			struct mdss_dsi_phy_ctrl *phy_db)
+{
+	uint32_t hw_id = board_hardware_id();
+
+	switch (hw_id) {
+	case HW_PLATFORM_QRD:
+	case HW_PLATFORM_MTP:
+	case HW_PLATFORM_SURF:
+		panel_id = TRULY_WVGA_VIDEO_PANEL;
+		break;
+	default:
+		dprintf(CRITICAL, "Display not enabled for %d HW type\n", hw_id);
+		return false;
+	}
+
+	return init_panel_data(panelstruct, pinfo, phy_db);
+}
diff --git a/target/msm8610/rules.mk b/target/msm8610/rules.mk
index 92c669f..909e673 100644
--- a/target/msm8610/rules.mk
+++ b/target/msm8610/rules.mk
@@ -1,6 +1,7 @@
 LOCAL_DIR := $(GET_LOCAL_DIR)
 
 INCLUDES += -I$(LOCAL_DIR)/include -I$(LK_TOP_DIR)/platform/msm_shared
+INCLUDES += -I$(LK_TOP_DIR)/dev/gcdb/display -I$(LK_TOP_DIR)/dev/gcdb/display/include
 
 PLATFORM := msm8610
 
@@ -23,6 +24,7 @@
 	lib/ptable \
 	dev/pmic/pm8x41 \
 	dev/panel/msm \
+	dev/gcdb/display \
 	lib/libfdt
 
 DEFINES += \
@@ -38,4 +40,5 @@
 OBJS += \
     $(LOCAL_DIR)/init.o \
     $(LOCAL_DIR)/meminfo.o \
-    $(LOCAL_DIR)/target_display.o
+    $(LOCAL_DIR)/target_display.o \
+    $(LOCAL_DIR)/oem_panel.o
diff --git a/target/msm8610/target_display.c b/target/msm8610/target_display.c
index 6e6f412..3610413 100644
--- a/target/msm8610/target_display.c
+++ b/target/msm8610/target_display.c
@@ -29,7 +29,9 @@
 
 #include <debug.h>
 #include <smem.h>
+#include <err.h>
 #include <msm_panel.h>
+#include <mipi_dsi.h>
 #include <pm8x41.h>
 #include <pm8x41_wled.h>
 #include <board.h>
@@ -37,21 +39,20 @@
 #include <platform/iomap.h>
 #include <target/display.h>
 
-static struct msm_fb_panel_data panel;
-static uint8_t display_enable;
+#include "include/panel.h"
+#include "include/display_resource.h"
 
-extern int msm_display_init(struct msm_fb_panel_data *pdata);
-extern int msm_display_off();
-extern void dsi_phy_init(struct msm_panel_info *pinfo);
+#define MODE_GPIO_STATE_ENABLE 1
 
-static int msm8610_backlight(uint8_t enable)
+#define MODE_GPIO_STATE_DISABLE 2
+
+int target_backlight_ctrl(uint8_t enable)
 {
 	struct pm8x41_mpp mpp;
 	mpp.base = PM8x41_MMP3_BASE;
 	mpp.mode = MPP_HIGH;
 	mpp.vin = MPP_VIN3;
-	if (enable)
- {
+	if (enable) {
 		pm8x41_config_output_mpp(&mpp);
 		pm8x41_enable_mpp(&mpp, MPP_ENABLE);
 	} else {
@@ -62,41 +63,18 @@
 	return 0;
 }
 
-void dsi_calc_clk_rate(uint32_t *dsiclk_rate, uint32_t *byteclk_rate)
+int target_panel_clock(uint8_t enable, struct msm_panel_info *pinfo)
 {
-	uint32_t hbp, hfp, vbp, vfp, hspw, vspw, width, height;
-	uint32_t bitclk_rate;
-	int frame_rate, lanes;
+	struct mdss_dsi_pll_config *pll_data;
+	dprintf(SPEW, "target_panel_clock\n");
 
-	width = panel.panel_info.xres;
-	height = panel.panel_info.yres;
-	hbp = panel.panel_info.lcdc.h_back_porch;
-	hfp = panel.panel_info.lcdc.h_front_porch;
-	hspw = panel.panel_info.lcdc.h_pulse_width;
-	vbp = panel.panel_info.lcdc.v_back_porch;
-	vfp = panel.panel_info.lcdc.v_front_porch;
-	vspw = panel.panel_info.lcdc.v_pulse_width;
-	lanes = panel.panel_info.mipi.num_of_lanes;
-	frame_rate = panel.panel_info.mipi.frame_rate;
+	pll_data = pinfo->mipi.dsi_pll_config;
 
-	bitclk_rate = (width + hbp + hfp + hspw) * (height + vbp + vfp + vspw);
-	bitclk_rate *= frame_rate;
-	bitclk_rate *= panel.panel_info.bpp;
-	bitclk_rate /= lanes;
-
-	*byteclk_rate = bitclk_rate / 8;
-	*dsiclk_rate = *byteclk_rate * lanes;
-}
-
-static int msm8610_mdss_dsi_panel_clock(uint8_t enable)
-{
-	uint32_t dsiclk_rate, byteclk_rate;
-
-	if (enable)
-	{
+	if (enable) {
 		mdp_clock_enable();
-		dsi_calc_clk_rate(&dsiclk_rate, &byteclk_rate);
-		dsi_clock_enable(dsiclk_rate, byteclk_rate);
+		dsi_clock_enable(
+			pll_data->byte_clock * pinfo->mipi.num_of_lanes,
+			pll_data->byte_clock);
 	} else if(!target_cont_splash_screen()) {
 		dsi_clock_disable();
 		mdp_clock_disable();
@@ -105,115 +83,72 @@
 	return 0;
 }
 
-static void msm8610_mdss_mipi_panel_reset(int enable)
+int target_panel_reset(uint8_t enable, struct panel_reset_sequence *resetseq,
+						struct msm_panel_info *pinfo)
 {
 	dprintf(SPEW, "msm8610_mdss_mipi_panel_reset, enable = %d\n", enable);
 
-	if (enable)
-	{
-		gpio_tlmm_config(41, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA, GPIO_DISABLE);
-		gpio_tlmm_config(7, 0, GPIO_OUTPUT, GPIO_NO_PULL, GPIO_8MA, GPIO_DISABLE);
+	if (enable) {
+		gpio_tlmm_config(reset_gpio.pin_id, 0,
+				reset_gpio.pin_direction, reset_gpio.pin_pull,
+				reset_gpio.pin_strength, reset_gpio.pin_state);
+
+		gpio_tlmm_config(mode_gpio.pin_id, 0,
+				mode_gpio.pin_direction, mode_gpio.pin_pull,
+				mode_gpio.pin_strength, mode_gpio.pin_state);
 
 		/* reset */
-		gpio_set(41, 2);
-		mdelay(20);
-		gpio_set(41, 0);
-		udelay(20);
-		gpio_set(41, 2);
-		mdelay(20);
+		gpio_set(reset_gpio.pin_id, resetseq->pin_state[0]);
+		mdelay(resetseq->sleep[0]);
+		gpio_set(reset_gpio.pin_id, resetseq->pin_state[1]);
+		mdelay(resetseq->sleep[1]);
+		gpio_set(reset_gpio.pin_id, resetseq->pin_state[2]);
+		mdelay(resetseq->sleep[2]);
 
-		if (panel.panel_info.type == MIPI_VIDEO_PANEL)
-			gpio_set(7, 2);
-		else if (panel.panel_info.type == MIPI_CMD_PANEL)
-			gpio_set(7, 0);
+		if (pinfo->mipi.mode_gpio_state == MODE_GPIO_STATE_ENABLE)
+			gpio_set(mode_gpio.pin_id, 2);
+		else if (pinfo->mipi.mode_gpio_state == MODE_GPIO_STATE_DISABLE)
+			gpio_set(mode_gpio.pin_id, 0);
 	} else if(!target_cont_splash_screen()) {
-		gpio_set(7, 0);
-		gpio_set(41, 0);
+		gpio_set(reset_gpio.pin_id, 0);
+		gpio_set(mode_gpio.pin_id, 0);
 	}
-	return;
+	return 0;
 }
 
-static int msm8610_mipi_panel_power(uint8_t enable)
+int target_ldo_ctrl(uint8_t enable)
 {
-	int ret;
-	struct pm8x41_ldo ldo14 = LDO(PM8x41_LDO14, PLDO_TYPE);
-	struct pm8x41_ldo ldo19 = LDO(PM8x41_LDO19, PLDO_TYPE);
+	uint32_t ldocounter = 0;
+	uint32_t pm8x41_ldo_base = 0x13F00;
 
-	dprintf(SPEW, "msm8610_mipi_panel_power, enable = %d\n", enable);
-	if (enable)
-	{
-		/* backlight */
-		msm8610_backlight(enable);
+	while (ldocounter < TOTAL_LDO_DEFINED) {
+		struct pm8x41_ldo ldo_entry = LDO((pm8x41_ldo_base +
+			0x100 * ldo_entry_array[ldocounter].ldo_id),
+			ldo_entry_array[ldocounter].ldo_type);
 
-		/* regulators */
-		pm8x41_ldo_set_voltage(&ldo14, 1800000);
-		pm8x41_ldo_control(&ldo14, enable);
-		pm8x41_ldo_set_voltage(&ldo19, 2850000);
-		pm8x41_ldo_control(&ldo19, enable);
+		dprintf(SPEW, "Setting %s\n",
+				ldo_entry_array[ldocounter].ldo_id);
 
-		/* reset */
-		msm8610_mdss_mipi_panel_reset(enable);
-	} else if(!target_cont_splash_screen()) {
-		msm8610_backlight(0);
-		msm8610_mdss_mipi_panel_reset(enable);
-
-		pm8x41_ldo_control(&ldo19, enable);
-		pm8x41_ldo_control(&ldo14, enable);
+		/* Set voltage during power on */
+		if (enable) {
+			pm8x41_ldo_set_voltage(&ldo_entry,
+					ldo_entry_array[ldocounter].ldo_voltage);
+			pm8x41_ldo_control(&ldo_entry, enable);
+		} else if(!target_cont_splash_screen()) {
+			pm8x41_ldo_control(&ldo_entry, enable);
+		}
+		ldocounter++;
 	}
+
 	return 0;
 }
 
 void display_init(void)
 {
-	uint32_t hw_id = board_hardware_id();
-	uint32_t platform_subtype = board_hardware_subtype();
-
-	dprintf(SPEW, "display_init(),target_id=%d.\n", hw_id);
-	dprintf(SPEW, "display_init(),platform_subtype=%d.\n",
-		platform_subtype);
-
-	switch (hw_id) {
-	case HW_PLATFORM_QRD:
-		if ((0 == platform_subtype) || (1 == platform_subtype))
-			mipi_hx8379a_video_wvga_init(&(panel.panel_info));
-		else if (3 == platform_subtype)
-			mipi_otm8018b_video_wvga_init(&(panel.panel_info));
-
-		break;
-	case HW_PLATFORM_MTP:
-		if (0 == platform_subtype)
-			mipi_truly_video_wvga_init(&(panel.panel_info));
-		else
-			mipi_nt35590_video_720p_init(&(panel.panel_info));
-		break;
-	case HW_PLATFORM_SURF:
-		mipi_truly_video_wvga_init(&(panel.panel_info));
-		break;
-	default:
-		return;
-	};
-
-	panel.clk_func = msm8610_mdss_dsi_panel_clock;
-	panel.power_func = msm8610_mipi_panel_power;
-	panel.fb.base = MIPI_FB_ADDR;
-	panel.fb.width =  panel.panel_info.xres;
-	panel.fb.height =  panel.panel_info.yres;
-	panel.fb.stride =  panel.panel_info.xres;
-	panel.fb.bpp =	panel.panel_info.bpp;
-	panel.fb.format = FB_FORMAT_RGB888;
-	panel.mdp_rev = MDP_REV_304;
-
-	if (msm_display_init(&panel))
-	{
-		dprintf(CRITICAL, "Display init failed!\n");
-		return;
-	}
-
-	display_enable = 1;
+	gcdb_display_init(MDP_REV_304, MIPI_FB_ADDR);
 }
 
 void display_shutdown(void)
 {
-	if (display_enable)
-		msm_display_off();
+	gcdb_display_shutdown();
 }