[U-Boot] [PATCH 5/6] sunxi: video: Add simplefb support

Hans de Goede
2014-11-14T16:54:47Z

From: Luc Verhaegen <libv@skynet.be>

Add simplefb support, note this depends on the kernel having support for
the clocks property which has recently been added to the simplefb devicetree
binding.

Signed-off-by: Luc Verhaegen <libv@skynet.be>
[hdegoede at redhat.com: Use pre-populated simplefb node under /chosen as
disussed on the devicetree list]
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
arch/arm/include/asm/arch-sunxi/display.h | 4 ++
board/sunxi/board.c | 11 ++++++
drivers/video/sunxi_display.c | 66 +++++++++++++++++++++++++++++++
include/configs/sunxi-common.h | 8 ++++
4 files changed, 89 insertions(+)

diff --git a/arch/arm/include/asm/arch-sunxi/display.h b/arch/arm/include/asm/arch-sunxi/display.h
index 8ac7d1b..e38a401 100644
--- a/arch/arm/include/asm/arch-sunxi/display.h
+++ b/arch/arm/include/asm/arch-sunxi/display.h
@@ -195,4 +195,8 @@ struct sunxi_hdmi_reg {
#define SUNXI_HDMI_PLL_DBG0_PLL3 (0 << 21)
#define SUNXI_HDMI_PLL_DBG0_PLL7 (1 << 21)

+#ifdef CONFIG_VIDEO_DT_SIMPLEFB
+void sunxi_simplefb_setup(void *blob);
+#endif
+
#endif /* _SUNXI_DISPLAY_H */
diff --git a/board/sunxi/board.c b/board/sunxi/board.c
index e6ec5b8..d4530e8 100644
--- a/board/sunxi/board.c
+++ b/board/sunxi/board.c
@@ -24,6 +24,7 @@
#endif
#include <asm/arch/clock.h>
#include <asm/arch/cpu.h>
+#include <asm/arch/display.h>
#include <asm/arch/dram.h>
#include <asm/arch/gpio.h>
#include <asm/arch/mmc.h>
@@ -237,3 +238,13 @@ int misc_init_r(void)
return 0;
}
#endif
+
+#ifdef CONFIG_OF_BOARD_SETUP
+void
+ft_board_setup(void *blob, bd_t *bd)
+{
+#ifdef CONFIG_VIDEO_DT_SIMPLEFB
+ sunxi_simplefb_setup(blob);
+#endif
+}
+#endif /* CONFIG_OF_BOARD_SETUP */
diff --git a/drivers/video/sunxi_display.c b/drivers/video/sunxi_display.c
index 1058771..a47f575 100644
--- a/drivers/video/sunxi_display.c
+++ b/drivers/video/sunxi_display.c
@@ -13,6 +13,7 @@
#include <asm/arch/display.h>
#include <asm/global_data.h>
#include <asm/io.h>
+#include <fdtdec.h>
#include <linux/fb.h>
#include <video_fb.h>

@@ -416,3 +417,68 @@ video_hw_init(void)

return graphic_device;
}
+
+/*
+ * Simplefb support.
+ */
+#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_VIDEO_DT_SIMPLEFB)
+void
+sunxi_simplefb_setup(void *blob)
+{
+ static GraphicDevice *graphic_device = &sunxi_display.graphic_device;
+ const char *node = "/chosen/framebuffer0-hdmi";
+ const char *format = "x8r8g8b8";
+ const char *okay = "okay";
+ char name[32];
+ fdt32_t cells[2];
+ int offset, stride, ret;
+
+ if (!sunxi_display.enabled)
+ return;
+
+ offset = fdt_path_offset(blob, node);
+ if (offset < 0) {
+ eprintf("Cannot setup simplefb: %s node not found\n", node);
+ return;
+ }
+
+ snprintf(name, sizeof(name), "framebuffer@%08lx", gd->fb_base);
+ ret = fdt_set_name(blob, offset, name);
+ if (ret < 0)
+ goto error;
+
+ cells[0] = cpu_to_fdt32(gd->fb_base);
+ cells[1] = cpu_to_fdt32(CONFIG_SUNXI_FB_SIZE);
+ ret = fdt_setprop(blob, offset, "reg", cells, sizeof(cells[0]) * 2);
+ if (ret < 0)
+ goto error;
+
+ cells[0] = cpu_to_fdt32(graphic_device->winSizeX);
+ ret = fdt_setprop(blob, offset, "width", cells, sizeof(cells[0]));
+ if (ret < 0)
+ goto error;
+
+ cells[0] = cpu_to_fdt32(graphic_device->winSizeY);
+ ret = fdt_setprop(blob, offset, "height", cells, sizeof(cells[0]));
+ if (ret < 0)
+ goto error;
+
+ stride = graphic_device->winSizeX * graphic_device->gdfBytesPP;
+ cells[0] = cpu_to_fdt32(stride);
+ ret = fdt_setprop(blob, offset, "stride", cells, sizeof(cells[0]));
+ if (ret < 0)
+ goto error;
+
+ ret = fdt_setprop(blob, offset, "format", format, strlen(format) + 1);
+ if (ret < 0)
+ goto error;
+
+ ret = fdt_setprop(blob, offset, "status", okay, strlen(okay) + 1);
+ if (ret < 0)
+ goto error;
+
+ return;
+error:
+ eprintf("Cannot setup simplefb: Error setting properties\n");
+}
+#endif /* CONFIG_OF_BOARD_SETUP && CONFIG_VIDEO_DT_SIMPLEFB */
diff --git a/include/configs/sunxi-common.h b/include/configs/sunxi-common.h
index 532fdb7..d7d8571 100644
--- a/include/configs/sunxi-common.h
+++ b/include/configs/sunxi-common.h
@@ -204,6 +204,9 @@
*/
#define CONFIG_SUNXI_FB_SIZE (8 << 20)

+/* Do we want to initialize a simple FB? */
+#define CONFIG_VIDEO_DT_SIMPLEFB
+
#define CONFIG_VIDEO_SUNXI

#define CONFIG_CFB_CONSOLE
@@ -219,6 +222,11 @@

#define CONFIG_SYS_MEM_TOP_HIDE ((CONFIG_SUNXI_FB_SIZE + 0xFFF) & ~0xFFF)

+/* To be able to hook simplefb into dt */
+#ifdef CONFIG_VIDEO_DT_SIMPLEFB
+#define CONFIG_OF_BOARD_SETUP
+#endif
+
#endif /* CONFIG_VIDEO */

/* Ethernet support */
--
2.1.0