1 // SPDX-License-Identifier: GPL-2.0+
3 * Simplefb device tree support
6 * Stephen Warren <swarren@wwwdotorg.org>
11 #include <fdt_support.h>
12 #include <asm/global_data.h>
13 #include <linux/libfdt.h>
16 DECLARE_GLOBAL_DATA_PTR;
18 static int fdt_simplefb_configure_node(void *blob, int off)
21 int bpix; /* log2 of bits per pixel */
24 struct video_uc_plat *plat;
25 struct video_priv *uc_priv;
29 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
32 uc_priv = dev_get_uclass_priv(dev);
33 plat = dev_get_uclass_plat(dev);
34 xsize = uc_priv->xsize;
35 ysize = uc_priv->ysize;
39 case 4: /* VIDEO_BPP16 */
42 case 5: /* VIDEO_BPP32 */
49 return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
50 xsize * (1 << bpix) / 8, name);
53 int fdt_simplefb_add_node(void *blob)
55 static const char compat[] = "simple-framebuffer";
56 static const char disabled[] = "disabled";
59 off = fdt_add_subnode(blob, 0, "framebuffer");
63 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
67 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
71 return fdt_simplefb_configure_node(blob, off);
75 * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node
78 * Return: 0 on success, non-zero otherwise
80 static int fdt_simplefb_enable_existing_node(void *blob)
84 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
88 return fdt_simplefb_configure_node(blob, off);
91 #if IS_ENABLED(CONFIG_VIDEO)
92 int fdt_simplefb_enable_and_mem_rsv(void *blob)
94 struct fdt_memory mem;
97 /* nothing to do when video is not active */
98 if (!video_is_active())
101 ret = fdt_simplefb_enable_existing_node(blob);
105 /* nothing to do when the frame buffer is not defined */
106 if (gd->video_bottom == gd->video_top)
109 /* reserved with no-map tag the video buffer */
110 mem.start = gd->video_bottom;
111 mem.end = gd->video_top - 1;
113 return fdtdec_add_reserved_memory(blob, "framebuffer", &mem, NULL, 0, NULL,
114 FDTDEC_RESERVED_MEMORY_NO_MAP);