public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Igor Opaniuk <igor.opaniuk@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC 2/4] video: fsl_dcu_fb: add DM_VIDEO support
Date: Mon, 10 Jun 2019 14:47:50 +0300	[thread overview]
Message-ID: <20190610114752.29976-3-igor.opaniuk@gmail.com> (raw)
In-Reply-To: <20190610114752.29976-1-igor.opaniuk@gmail.com>

From: Igor Opaniuk <igor.opaniuk@toradex.com>

Extend the driver to build with DM_VIDEO enabled. DTS files
must additionally include 'u-boot,dm-pre-reloc' property in
soc and child nodes to enable driver binding to fsl_dcu_fb device.

Currently display timings aren't obtained from DT.

Signed-off-by: Igor Opaniuk <igor.opaniuk@toradex.com>
---
 board/toradex/colibri_vf/colibri_vf.c |   4 +-
 drivers/video/Kconfig                 |   2 +-
 drivers/video/fsl_dcu_fb.c            | 112 +++++++++++++++++++++-----
 3 files changed, 97 insertions(+), 21 deletions(-)

diff --git a/board/toradex/colibri_vf/colibri_vf.c b/board/toradex/colibri_vf/colibri_vf.c
index 9d63fbf3bd..dad754b31f 100644
--- a/board/toradex/colibri_vf/colibri_vf.c
+++ b/board/toradex/colibri_vf/colibri_vf.c
@@ -430,7 +430,9 @@ int checkboard(void)
 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
 int ft_board_setup(void *blob, bd_t *bd)
 {
+#ifndef CONFIG_DM_VIDEO
 	int ret = 0;
+#endif
 #ifdef CONFIG_FDT_FIXUP_PARTITIONS
 	static const struct node_info nodes[] = {
 		{ "fsl,vf610-nfc", MTD_DEV_TYPE_NAND, }, /* NAND flash */
@@ -440,7 +442,7 @@ int ft_board_setup(void *blob, bd_t *bd)
 	puts("   Updating MTD partitions...\n");
 	fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
 #endif
-#ifdef CONFIG_VIDEO_FSL_DCU_FB
+#if defined(CONFIG_VIDEO_FSL_DCU_FB) && !defined(CONFIG_DM_VIDEO)
 	ret = fsl_dcu_fixedfb_setup(blob);
 	if (ret)
 		return ret;
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index c3781b160d..261fa98517 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -484,7 +484,7 @@ config VIDEO_IVYBRIDGE_IGD
 
 config VIDEO_FSL_DCU_FB
 	bool "Enable Freescale Display Control Unit"
-	depends on VIDEO
+	depends on VIDEO || DM_VIDEO
 	help
 	 This enables support for Freescale Display Control Unit (DCU4)
 	 module found on Freescale Vybrid and QorIQ family of SoCs.
diff --git a/drivers/video/fsl_dcu_fb.c b/drivers/video/fsl_dcu_fb.c
index f789ec597d..add64b85b5 100644
--- a/drivers/video/fsl_dcu_fb.c
+++ b/drivers/video/fsl_dcu_fb.c
@@ -8,10 +8,12 @@
 
 #include <asm/io.h>
 #include <common.h>
+#include <dm.h>
 #include <fdt_support.h>
 #include <fsl_dcu_fb.h>
 #include <linux/fb.h>
 #include <malloc.h>
+#include <video.h>
 #include <video_fb.h>
 #include "videomodes.h"
 
@@ -219,8 +221,6 @@ struct dcu_reg {
 	u32 ctrldescl[DCU_LAYER_MAX_NUM][16];
 };
 
-static struct fb_info info;
-
 static void reset_total_layers(void)
 {
 	struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
@@ -302,7 +302,11 @@ int fsl_dcu_init(struct fb_info *fbinfo, unsigned int xres,
 {
 	struct dcu_reg *regs = (struct dcu_reg *)CONFIG_SYS_DCU_ADDR;
 	unsigned int div, mode;
-
+/*
+ * When DM_VIDEO is enabled reservation of framebuffer is done
+ * in advance during bind() call.
+ */
+#if !CONFIG_IS_ENABLED(DM_VIDEO)
 	fbinfo->screen_size = fbinfo->var.xres * fbinfo->var.yres *
 			     (fbinfo->var.bits_per_pixel / 8);
 
@@ -310,13 +314,13 @@ int fsl_dcu_init(struct fb_info *fbinfo, unsigned int xres,
 		fbinfo->screen_size = 0;
 		return -ENOMEM;
 	}
-
 	/* Reserve framebuffer at the end of memory */
 	gd->fb_base = gd->bd->bi_dram[0].start +
 			gd->bd->bi_dram[0].size - fbinfo->screen_size;
 	fbinfo->screen_base = (char *)gd->fb_base;
 
 	memset(fbinfo->screen_base, 0, fbinfo->screen_size);
+#endif
 
 	reset_total_layers();
 
@@ -429,6 +433,32 @@ int fsl_probe_common(struct fb_info *fbinfo, unsigned int *win_x,
 				 options + 8, fsl_dcu_mode_db);
 }
 
+#ifndef CONFIG_DM_VIDEO
+static struct fb_info info;
+
+#if defined(CONFIG_OF_BOARD_SETUP)
+int fsl_dcu_fixedfb_setup(void *blob)
+{
+	u64 start, size;
+	int ret;
+
+	start = gd->bd->bi_dram[0].start;
+	size = gd->bd->bi_dram[0].size - info.screen_size;
+
+	/*
+	 * Align size on section size (1 MiB).
+	 */
+	size &= 0xfff00000;
+	ret = fdt_fixup_memory_banks(blob, &start, &size, 1);
+	if (ret) {
+		eprintf("Cannot setup fb: Error reserving memory\n");
+		return ret;
+	}
+
+	return 0;
+}
+#endif
+
 void *video_hw_init(void)
 {
 	static GraphicDevice ctfb;
@@ -448,25 +478,69 @@ void *video_hw_init(void)
 	return &ctfb;
 }
 
-#if defined(CONFIG_OF_BOARD_SETUP)
-int fsl_dcu_fixedfb_setup(void *blob)
+#else /* ifndef CONFIG_DM_VIDEO */
+
+static int fsl_dcu_video_probe(struct udevice *dev)
 {
-	u64 start, size;
-	int ret;
+	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
+	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct fb_info fbinfo = { 0 };
+	unsigned int win_x;
+	unsigned int win_y;
+	u32 fb_start, fb_end;
+	int ret = 0;
+
+	fb_start = plat->base & ~(MMU_SECTION_SIZE - 1);
+	fb_end = plat->base + plat->size;
+	fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
+
+	fbinfo.screen_base = (char *)fb_start;
+	fbinfo.screen_size = plat->size;
+
+	ret = fsl_probe_common(&fbinfo, &win_x, &win_y);
+	if (ret < 0)
+		return ret;
 
-	start = gd->bd->bi_dram[0].start;
-	size = gd->bd->bi_dram[0].size - info.screen_size;
+	uc_priv->bpix = VIDEO_BPP32;
+	uc_priv->xsize = win_x;
+	uc_priv->ysize = win_y;
 
-	/*
-	 * Align size on section size (1 MiB).
-	 */
-	size &= 0xfff00000;
-	ret = fdt_fixup_memory_banks(blob, &start, &size, 1);
-	if (ret) {
-		eprintf("Cannot setup fb: Error reserving memory\n");
+	/* Enable dcache for the frame buffer */
+	mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
+					DCACHE_WRITEBACK);
+	video_set_flush_dcache(dev, true);
+	return ret;
+}
+
+static int fsl_dcu_video_bind(struct udevice *dev)
+{
+	struct video_uc_platdata *plat = dev_get_uclass_platdata(dev);
+	unsigned int win_x;
+	unsigned int win_y;
+	unsigned int depth = 0, freq = 0;
+	const char *options;
+	int ret = 0;
+
+	ret = video_get_video_mode(&win_x, &win_y, &depth, &freq, &options);
+	if (ret < 0)
 		return ret;
-	}
+
+	plat->size = win_x * win_y * 32;
 
 	return 0;
 }
-#endif
+
+static const struct udevice_id fsl_dcu_video_ids[] = {
+	{ .compatible = "fsl,vf610-dcu" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(fsl_dcu_video) = {
+	.name	= "fsl_dcu_video",
+	.id	= UCLASS_VIDEO,
+	.of_match = fsl_dcu_video_ids,
+	.bind	= fsl_dcu_video_bind,
+	.probe	= fsl_dcu_video_probe,
+	.flags	= DM_FLAG_PRE_RELOC,
+};
+#endif /* ifndef CONFIG_DM_VIDEO */
-- 
2.17.1

  parent reply	other threads:[~2019-06-10 11:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-10 11:47 [U-Boot] [RFC 0/4] Convert fsl_dcu_fb to DM_VIDEO Igor Opaniuk
2019-06-10 11:47 ` [U-Boot] [RFC 1/4] video: fsl_dcu_fb: refactor init functions Igor Opaniuk
2019-07-11 14:25   ` Igor Opaniuk
2019-07-11 15:16     ` Oleksandr Suvorov
2019-06-10 11:47 ` Igor Opaniuk [this message]
2019-07-11 14:26   ` [U-Boot] [RFC 2/4] video: fsl_dcu_fb: add DM_VIDEO support Igor Opaniuk
2019-07-12 13:32     ` Oleksandr Suvorov
2019-06-10 11:47 ` [U-Boot] [RFC 3/4] ARM: dts: colibri_vf: Add dcu0 node Igor Opaniuk
2019-07-11 14:26   ` Igor Opaniuk
2019-07-12 13:33     ` Oleksandr Suvorov
2019-06-10 11:47 ` [U-Boot] [RFC 4/4] colibri_vf: enable DM_VIDEO Igor Opaniuk
2019-07-11 14:26   ` Igor Opaniuk
2019-07-12 13:34     ` Oleksandr Suvorov
2019-07-11 14:25 ` [U-Boot] [RFC 0/4] Convert fsl_dcu_fb to DM_VIDEO Igor Opaniuk
2019-07-29  9:19 ` Anatolij Gustschin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190610114752.29976-3-igor.opaniuk@gmail.com \
    --to=igor.opaniuk@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox