[U-Boot] [PATCH 06/17] sunxi: video: Prepare for lcd support

Hans de Goede hdegoede at redhat.com
Wed Dec 24 20:06:18 CET 2014


Refactor sunxi_mode_set into a bunch of helpers, and make it do a switch
case on sunxi_display.monitor to decide what to do.

Also rename sunxi_lcdc_mode_set to sunxi_lcdc_tcon1_mode_set, as it sets the
timings for tcon1, and for lcd support we need a similar function operating
on tcon0.

Signed-off-by: Hans de Goede <hdegoede at redhat.com>
---
 drivers/video/sunxi_display.c | 102 +++++++++++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 32 deletions(-)

diff --git a/drivers/video/sunxi_display.c b/drivers/video/sunxi_display.c
index 83ee360..1dfde11 100644
--- a/drivers/video/sunxi_display.c
+++ b/drivers/video/sunxi_display.c
@@ -310,6 +310,15 @@ static void sunxi_composer_mode_set(const struct ctfb_res_modes *mode,
 	setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_LAYER0_ENABLE);
 }
 
+static void sunxi_composer_enable(void)
+{
+	struct sunxi_de_be_reg * const de_be =
+		(struct sunxi_de_be_reg *)SUNXI_DE_BE0_BASE;
+
+	setbits_le32(&de_be->reg_ctrl, SUNXI_DE_BE_REG_CTRL_LOAD_REGS);
+	setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_START);
+}
+
 /*
  * LCDC, what allwinner calls a CRTC, so timing controller and serializer.
  */
@@ -400,8 +409,16 @@ static void sunxi_lcdc_init(void)
 	writel(0xffffffff, &lcdc->tcon1_io_tristate);
 }
 
-static void sunxi_lcdc_mode_set(const struct ctfb_res_modes *mode,
-				int *clk_div, int *clk_double)
+static void sunxi_lcdc_enable(void)
+{
+	struct sunxi_lcdc_reg * const lcdc =
+		(struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE;
+
+	setbits_le32(&lcdc->ctrl, SUNXI_LCDC_CTRL_TCON_ENABLE);
+}
+
+static void sunxi_lcdc_tcon1_mode_set(const struct ctfb_res_modes *mode,
+				      int *clk_div, int *clk_double)
 {
 	struct sunxi_lcdc_reg * const lcdc =
 		(struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE;
@@ -549,6 +566,15 @@ static void sunxi_hdmi_mode_set(const struct ctfb_res_modes *mode,
 		setbits_le32(&hdmi->video_polarity, SUNXI_HDMI_VIDEO_POL_VER);
 }
 
+static void sunxi_hdmi_enable(void)
+{
+	struct sunxi_hdmi_reg * const hdmi =
+		(struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE;
+
+	udelay(100);
+	setbits_le32(&hdmi->video_ctrl, SUNXI_HDMI_VIDEO_CTRL_ENABLE);
+}
+
 static void sunxi_engines_init(void)
 {
 	sunxi_composer_init();
@@ -561,25 +587,26 @@ static void sunxi_engines_init(void)
 static void sunxi_mode_set(const struct ctfb_res_modes *mode,
 			   unsigned int address)
 {
-	struct sunxi_de_be_reg * const de_be =
-		(struct sunxi_de_be_reg *)SUNXI_DE_BE0_BASE;
-	struct sunxi_lcdc_reg * const lcdc =
-		(struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE;
-	struct sunxi_hdmi_reg * const hdmi =
-		(struct sunxi_hdmi_reg *)SUNXI_HDMI_BASE;
-	int clk_div, clk_double;
-
-	sunxi_composer_mode_set(mode, address);
-	sunxi_lcdc_mode_set(mode, &clk_div, &clk_double);
-	sunxi_hdmi_mode_set(mode, clk_div, clk_double);
-
-	setbits_le32(&de_be->reg_ctrl, SUNXI_DE_BE_REG_CTRL_LOAD_REGS);
-	setbits_le32(&de_be->mode, SUNXI_DE_BE_MODE_START);
-	setbits_le32(&lcdc->ctrl, SUNXI_LCDC_CTRL_TCON_ENABLE);
-
-	udelay(100);
-
-	setbits_le32(&hdmi->video_ctrl, SUNXI_HDMI_VIDEO_CTRL_ENABLE);
+	switch (sunxi_display.monitor) {
+	case sunxi_monitor_none:
+		break;
+	case sunxi_monitor_dvi:
+	case sunxi_monitor_hdmi: {
+		int clk_div, clk_double;
+		sunxi_composer_mode_set(mode, address);
+		sunxi_lcdc_tcon1_mode_set(mode, &clk_div, &clk_double);
+		sunxi_hdmi_mode_set(mode, clk_div, clk_double);
+		sunxi_composer_enable();
+		sunxi_lcdc_enable();
+		sunxi_hdmi_enable();
+		}
+		break;
+	case sunxi_monitor_lcd:
+		/* TODO */
+		break;
+	case sunxi_monitor_vga:
+		break;
+	}
 }
 
 void *video_hw_init(void)
@@ -615,19 +642,30 @@ void *video_hw_init(void)
 		printf("Unknown monitor: '%s', falling back to '%s'\n",
 		       mon, mon_desc[sunxi_display.monitor]);
 
-	/* Always call hdp_detect, as it also enables various clocks, etc. */
-	ret = sunxi_hdmi_hpd_detect();
-	if (hpd && !ret) {
-		sunxi_hdmi_shutdown();
+	switch (sunxi_display.monitor) {
+	case sunxi_monitor_none:
 		return NULL;
-	}
-	if (ret)
-		printf("HDMI connected: ");
+	case sunxi_monitor_dvi:
+	case sunxi_monitor_hdmi:
+		/* Always call hdp_detect, as it also enables clocks, etc. */
+		ret = sunxi_hdmi_hpd_detect();
+		if (ret) {
+			printf("HDMI connected: ");
+			if (edid && sunxi_hdmi_edid_get_mode(&edid_mode) == 0)
+				mode = &edid_mode;
+			break;
+		}
+		if (!hpd)
+			break; /* User has requested to ignore hpd */
 
-	/* Check edid if requested and we've a cable plugged in */
-	if (edid && ret) {
-		if (sunxi_hdmi_edid_get_mode(&edid_mode) == 0)
-			mode = &edid_mode;
+		sunxi_hdmi_shutdown();
+		return NULL;
+	case sunxi_monitor_lcd:
+		printf("LCD not supported on this board\n");
+		return NULL;
+	case sunxi_monitor_vga:
+		printf("VGA not supported on this board\n");
+		return NULL;
 	}
 
 	if (mode->vmode != FB_VMODE_NONINTERLACED) {
-- 
2.1.0



More information about the U-Boot mailing list