Merge tag 'tpm-master-28012025' of https://source.denx.de/u-boot/custodians/u-boot-tpm
[u-boot.git] / boot / fdt_simplefb.c
blob5822131767d19991a921c8d1eeb5da058a065f76
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Simplefb device tree support
5 * (C) Copyright 2015
6 * Stephen Warren <swarren@wwwdotorg.org>
7 */
9 #include <dm.h>
10 #include <fdt_support.h>
11 #include <asm/global_data.h>
12 #include <linux/libfdt.h>
13 #include <video.h>
14 #include <spl.h>
15 #include <bloblist.h>
17 DECLARE_GLOBAL_DATA_PTR;
19 static int fdt_simplefb_configure_node(void *blob, int off)
21 int xsize, ysize;
22 int bpix; /* log2 of bits per pixel */
23 const char *name;
24 ulong fb_base;
25 struct video_uc_plat *plat;
26 struct video_priv *uc_priv;
27 struct udevice *dev;
28 int ret;
30 if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && xpl_phase() > PHASE_SPL) {
31 struct video_handoff *ho;
33 ho = bloblist_find(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho));
34 if (!ho)
35 return log_msg_ret("Missing video bloblist", -ENOENT);
37 xsize = ho->xsize;
38 ysize = ho->ysize;
39 bpix = ho->bpix;
40 fb_base = ho->fb;
41 } else {
42 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
43 if (ret)
44 return ret;
45 uc_priv = dev_get_uclass_priv(dev);
46 plat = dev_get_uclass_plat(dev);
47 xsize = uc_priv->xsize;
48 ysize = uc_priv->ysize;
49 bpix = uc_priv->bpix;
50 fb_base = plat->base;
53 switch (bpix) {
54 case 4: /* VIDEO_BPP16 */
55 name = "r5g6b5";
56 break;
57 case 5: /* VIDEO_BPP32 */
58 name = "a8r8g8b8";
59 break;
60 default:
61 return -EINVAL;
64 return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
65 xsize * (1 << bpix) / 8, name);
68 int fdt_simplefb_add_node(void *blob)
70 static const char compat[] = "simple-framebuffer";
71 static const char disabled[] = "disabled";
72 int off, ret;
74 off = fdt_add_subnode(blob, 0, "framebuffer");
75 if (off < 0)
76 return -1;
78 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
79 if (ret < 0)
80 return -1;
82 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
83 if (ret < 0)
84 return -1;
86 return fdt_simplefb_configure_node(blob, off);
89 /**
90 * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node
92 * @blob: device-tree
93 * Return: 0 on success, non-zero otherwise
95 static int fdt_simplefb_enable_existing_node(void *blob)
97 int off;
99 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
100 if (off < 0)
101 return -1;
103 return fdt_simplefb_configure_node(blob, off);
106 int fdt_simplefb_enable_and_mem_rsv(void *blob)
108 int ret;
110 /* nothing to do when video is not active */
111 if (!video_is_active())
112 return 0;
114 ret = fdt_simplefb_enable_existing_node(blob);
115 if (ret)
116 return ret;
118 return fdt_add_fb_mem_rsv(blob);