dev: gcdb: add st7789H2 command mode panel file

Add changes to:
1. add panel header file to support SPI display on
st77889H2 panel
2. add SPI display init and power function
3. remove MIPI display macro to support SPI display.

Change-Id: I6b0af4832cd069b0dc90976715eedb220074e2fd
Signed-off-by: Wenjun Zhang <wjzhan@codeaurora.org>
diff --git a/dev/fbcon/fbcon.c b/dev/fbcon/fbcon.c
index 5bce3c2..adc5e29 100644
--- a/dev/fbcon/fbcon.c
+++ b/dev/fbcon/fbcon.c
@@ -2,7 +2,7 @@
  * Copyright (c) 2008, Google Inc.
  * All rights reserved.
  *
- * Copyright (c) 2009-2015, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2009-2015, 2018 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
@@ -504,7 +504,6 @@
 	image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) *
 			(config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2)));
 
-#if DISPLAY_TYPE_MIPI
 #if ENABLE_WBC
 	image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888);
 #else
@@ -518,13 +517,6 @@
 			SPLASH_IMAGE_WIDTH * bytes_per_bpp);
 		}
 	}
-	fbcon_flush();
-#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
-	if(is_cmd_mode_enabled())
-		mipi_dsi_cmd_mode_trigger();
-#endif
-
-#else
 
 	if (bytes_per_bpp == 2) {
 		for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
@@ -533,7 +525,12 @@
 			SPLASH_IMAGE_WIDTH * bytes_per_bpp);
 		}
 	}
+
 	fbcon_flush();
+
+#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
+	if(is_cmd_mode_enabled())
+		mipi_dsi_cmd_mode_trigger();
 #endif
 }
 
diff --git a/dev/gcdb/display/gcdb_display.c b/dev/gcdb/display/gcdb_display.c
index 945839c..9cde84a 100644
--- a/dev/gcdb/display/gcdb_display.c
+++ b/dev/gcdb/display/gcdb_display.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2018 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
@@ -486,6 +486,53 @@
 			~USE_DSI1_PLL_FLAG;
 }
 
+static int mdss_spi_bl_enable(uint8_t enable)
+{
+	int ret = NO_ERROR;
+
+	ret = panel_backlight_ctrl(enable);
+	if (ret)
+		dprintf(CRITICAL, "Backlight %s failed\n", enable ? "enable" : "disable");
+	return ret;
+}
+
+static int mdss_spi_panel_power(uint8_t enable, struct msm_panel_info *pinfo)
+{
+	int ret = NO_ERROR;
+
+	if (enable) {
+		ret = target_ldo_ctrl(enable, pinfo);
+		if (ret) {
+			dprintf(CRITICAL, "LDO control enable failed\n");
+			return ret;
+		}
+
+		/*Panel Reset*/
+		ret = target_panel_reset(enable,panelstruct.panelresetseq, &panel.panel_info);
+		if (ret) {
+			dprintf(CRITICAL, "panel reset failed\n");
+			return ret;
+		}
+		dprintf(INFO, "Panel power on done\n");
+	} else {
+		/*Disable panel and ldo*/
+		ret = target_panel_reset(enable, panelstruct.panelresetseq, &panel.panel_info);
+		if (ret) {
+			dprintf(CRITICAL, "panel reset disable failed \n");
+			return ret;
+		}
+
+		ret = target_ldo_ctrl(enable, pinfo);
+		if (ret) {
+			dprintf(CRITICAL, "panel reset disable failed \n");
+			return ret;
+		}
+		dprintf(INFO, "Panel power off done\n");
+	}
+
+	return ret;
+}
+
 static int update_dsi_display_config()
 {
 	int ret = NO_ERROR;
@@ -566,6 +613,18 @@
                 panel.power_func = mdss_edp_panel_power;
 		panel.bl_func = mdss_edp_bl_enable;
                 panel.fb.format = FB_FORMAT_RGB888;
+	} else if (pan_type == PANEL_TYPE_SPI) {
+		panel.panel_info.xres = panelstruct.panelres->panel_width;
+		panel.panel_info.yres = panelstruct.panelres->panel_height;
+		panel.panel_info.bpp = panelstruct.color->color_format;
+		panel.power_func = mdss_spi_panel_power;
+		panel.bl_func = mdss_spi_bl_enable;
+		panel.fb.base = base;
+		panel.fb.width = panel.panel_info.xres;
+		panel.fb.height = panel.panel_info.yres;
+		panel.fb.bpp = panel.panel_info.bpp;
+		panel.fb.format = FB_FORMAT_RGB565;
+		panel.panel_info.type = SPI_PANEL;
 	} else {
 		dprintf(CRITICAL, "Target panel init not found!\n");
 		ret = ERR_NOT_SUPPORTED;
diff --git a/dev/gcdb/display/include/panel.h b/dev/gcdb/display/include/panel.h
old mode 100755
new mode 100644
index 3a83bce..1c83c6d
--- a/dev/gcdb/display/include/panel.h
+++ b/dev/gcdb/display/include/panel.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2013-2016, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2013-2016, 2018, 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
@@ -48,7 +48,8 @@
 	PANEL_TYPE_UNKNOWN,
 	PANEL_TYPE_DSI,
 	PANEL_TYPE_EDP,
-	PANEL_TYPE_HDMI
+	PANEL_TYPE_HDMI,
+	PANEL_TYPE_SPI
 };
 
 /*---------------------------------------------------------------------------*/
diff --git a/dev/gcdb/display/include/panel_st7789v2_qvga_spi_cmd.h b/dev/gcdb/display/include/panel_st7789v2_qvga_spi_cmd.h
new file mode 100644
index 0000000..869f536
--- /dev/null
+++ b/dev/gcdb/display/include/panel_st7789v2_qvga_spi_cmd.h
@@ -0,0 +1,206 @@
+/* Copyright (c) 2017-2018, 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 "AS IS" AND ANY EXPRESS OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
+* 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.
+*/
+
+#ifndef _PANEL_ST7789v2_QVGA_SPI_CMD_H_
+#define _PANEL_ST7789v2_QVGA_SPI_CMD_H_
+/*---------------------------------------------------------------------------*/
+/* HEADER files                                                              */
+/*---------------------------------------------------------------------------*/
+#include "panel.h"
+
+/*---------------------------------------------------------------------------*/
+/* Panel configuration                                                       */
+/*---------------------------------------------------------------------------*/
+static struct panel_config st7789v2_qvga_cmd_panel_data = {
+	"qcom,mdss_spi_st7789v2_qvga_cmd", "spi:0:", "qcom,mdss-spi-panel",
+	10, 0, "DISPLAY_1", 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/*---------------------------------------------------------------------------*/
+/* Panel resolution                                                          */
+/*---------------------------------------------------------------------------*/
+static struct panel_resolution st7789v2_qvga_cmd_panel_res = {
+	240, 240, 79, 59, 60, 0, 7, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/*---------------------------------------------------------------------------*/
+/* Panel color information                                                   */
+/*---------------------------------------------------------------------------*/
+static struct color_info st7789v2_qvga_cmd_color = {
+	16, 0, 0xff, 0, 0, 0
+};
+
+/*---------------------------------------------------------------------------*/
+/* Panel on/off command information                                          */
+/*---------------------------------------------------------------------------*/
+static char st7789v2_qvga_cmd_on_cmd0[] = {
+	0x11,
+};
+
+static char st7789v2_qvga_cmd_on_cmd1[] = {
+	0x36, 0x00,
+};
+
+static char st7789v2_qvga_cmd_on_cmd2[] = {
+	0x3A, 0x05,
+};
+
+static char st7789v2_qvga_cmd_on_cmd3[] = {
+	0x35, 0x00,
+};
+
+static char st7789v2_qvga_cmd_on_cmd4[] = {
+	0xB2, 0x0C, 0x0C, 0x00,
+	0x33, 0x33,
+};
+
+static char st7789v2_qvga_cmd_on_cmd5[] = {
+	0xB7, 0x75,
+};
+
+static char st7789v2_qvga_cmd_on_cmd6[] = {
+	0xBB, 0x3D,
+};
+
+static char st7789v2_qvga_cmd_on_cmd7[] = {
+	0xC2, 0x01,
+};
+
+static char st7789v2_qvga_cmd_on_cmd8[] = {
+	0xC3, 0x19,
+};
+
+static char st7789v2_qvga_cmd_on_cmd9[] = {
+	0x04, 0x20,
+};
+
+static char st7789v2_qvga_cmd_on_cmd10[] = {
+	0xc6, 0x0F,
+};
+
+static char st7789v2_qvga_cmd_on_cmd11[] = {
+	0xD0, 0xA4, 0xA1,
+};
+
+static char st7789v2_qvga_cmd_on_cmd12[] = {
+	0xE0, 0x70, 0x04, 0x08,
+	0x09, 0x09, 0x05, 0x2A,
+	0x33, 0x41, 0x07, 0x13,
+	0x13, 0x29, 0x2F,
+};
+
+static char st7789v2_qvga_cmd_on_cmd13[] = {
+	0xE1, 0x70, 0x03, 0x09,
+	0x0A, 0x09, 0x06, 0x2B,
+	0x34, 0x41, 0x07, 0x12,
+	0x14, 0x28, 0x2E
+};
+
+static char st7789v2_qvga_cmd_on_cmd14[] = {
+	0x21,
+};
+
+static char st7789v2_qvga_cmd_on_cmd15[] = {
+	0x29,
+};
+
+static char st7789v2_qvga_cmd_on_cmd16[] = {
+	0x2A, 0x00, 0x00, 0x00, 0xEF
+};
+
+static char st7789v2_qvga_cmd_on_cmd17[] = {
+	0x2B, 0x00, 0x00, 0x00, 0xEF
+};
+
+static char st7789v2_qvga_cmd_on_cmd18[] = {
+	0x2c
+};
+
+static struct mdss_spi_cmd st7789v2_qvga_cmd_on_command[] = {
+	{0x01, st7789v2_qvga_cmd_on_cmd0, 0x78, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd1, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd2, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd3, 0x00, 0},
+	{0x06, st7789v2_qvga_cmd_on_cmd4, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd5, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd6, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd7, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd8, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd9, 0x00, 0},
+	{0x02, st7789v2_qvga_cmd_on_cmd10, 0x00, 0},
+	{0x03, st7789v2_qvga_cmd_on_cmd11, 0x00, 0},
+	{0x0F, st7789v2_qvga_cmd_on_cmd12, 0x00, 0},
+	{0x0F, st7789v2_qvga_cmd_on_cmd13, 0x00, 0},
+	{0x01, st7789v2_qvga_cmd_on_cmd14, 0x00, 0},
+	{0x01, st7789v2_qvga_cmd_on_cmd15, 0x78, 0},
+	{0x05, st7789v2_qvga_cmd_on_cmd16, 0x00, 0},
+	{0x05, st7789v2_qvga_cmd_on_cmd17, 0x00, 0},
+	{0x01, st7789v2_qvga_cmd_on_cmd18, 0x00, 0},
+};
+
+#define ST7789v2_QVGA_CMD_ON_COMMAND 19
+
+
+static char st7789v2_qvga_cmdoff_cmd0[] = {
+	0x28,
+};
+
+static char st7789v2_qvga_cmdoff_cmd1[] = {
+	0x10,
+};
+
+static struct mipi_dsi_cmd st7789v2_qvga_cmd_off_command[] = {
+	{0x1, st7789v2_qvga_cmdoff_cmd0, 0x20},
+	{0x1, st7789v2_qvga_cmdoff_cmd1, 0x20}
+};
+
+#define ST7789v2_QVGA_CMD_OFF_COMMAND 2
+
+/*---------------------------------------------------------------------------*/
+/* Panel reset sequence                                                      */
+/*---------------------------------------------------------------------------*/
+static struct panel_reset_sequence st7789v2_qvga_cmd_reset_seq = {
+	{1, 0, 1, }, {20, 2, 20, }, 2
+};
+
+/*---------------------------------------------------------------------------*/
+/* Backlight setting                                                         */
+/*---------------------------------------------------------------------------*/
+static struct backlight st7789v2_qvga_cmd_backlight = {
+	1, 1, 4095, 100, 1, "PMIC_8941"
+};
+
+static uint8_t st7789v2_signature_addr = 0x04;
+
+static uint8_t st7789v2_signature_len = 3;
+
+static uint8_t st7789v2_signature[] = {
+	0x85, 0x85, 0x52
+};
+
+#endif /* PANEL_ST7789v2_QVGA_SPI_CMD_H */
diff --git a/platform/msm_shared/include/msm_panel.h b/platform/msm_shared/include/msm_panel.h
index f458328..6ca84ac 100644
--- a/platform/msm_shared/include/msm_panel.h
+++ b/platform/msm_shared/include/msm_panel.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2012-2017, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2012-2018, 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
@@ -53,6 +53,7 @@
 #define LVDS_PANEL		11	/* LVDS */
 #define EDP_PANEL		12	/* EDP */
 #define QPIC_PANEL		13	/* QPIC */
+#define SPI_PANEL		14
 
 #define DISPLAY_UNKNOWN		0
 #define DISPLAY_1		1
@@ -92,6 +93,21 @@
 	uint32_t rev;
 };
 
+struct mdss_spi_cmd {
+	int size;
+	char *payload;
+	int wait;
+	uint8_t cmds_post_tg;
+};
+
+struct spi_panel_info {
+	int num_of_panel_cmds;
+	struct mdss_spi_cmd *panel_cmds;
+	uint8_t *signature_addr;
+	uint8_t *signature;
+	uint8_t *signature_len;
+};
+
 struct hdmi_panel_info {
 	uint32_t h_back_porch;
 	uint32_t h_front_porch;
@@ -411,6 +427,7 @@
 	struct lvds_panel_info lvds;
 	struct hdmi_panel_info hdmi;
 	struct edp_panel_info edp;
+	struct spi_panel_info spi;
 	struct dsi2HDMI_panel_info adv7533;
 	bool has_bridge_chip;
 
diff --git a/platform/msm_shared/include/splash.h b/platform/msm_shared/include/splash.h
index badb8d0..59147a0 100644
--- a/platform/msm_shared/include/splash.h
+++ b/platform/msm_shared/include/splash.h
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010,2014, The Linux Foundation. All rights reserved.
+/* Copyright (c) 2010,2014, 2018 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
@@ -30,9 +30,8 @@
 #ifndef __PLATFORM_SPLASH_H
 #define __PLATFORM_SPLASH_H
 
-#if (!DISPLAY_TYPE_MIPI)
-#define SPLASH_IMAGE_WIDTH     124
-#define SPLASH_IMAGE_HEIGHT    113
+#define SPLASH_IMAGE_WIDTH     113
+#define SPLASH_IMAGE_HEIGHT    124
 /* This image is (SPLASH_IMAGE_WIDTH x SPLASH_IMAGE_WIDTH) raw image */
 static char imageBuffer[] = {
 
@@ -3542,11 +3541,6 @@
 
 };
 
-#else
-
-#define SPLASH_IMAGE_WIDTH     113
-#define SPLASH_IMAGE_HEIGHT    124
-
 /* This image is 228x113 raw Image resembling QuIC logo*/
 
 static char imageBuffer_rgb888[] = {
@@ -15252,6 +15246,5 @@
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
 };
 #endif
-#endif
 
 #endif