blob: 5822131767d19991a921c8d1eeb5da058a065f76 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +02002/*
3 * Simplefb device tree support
4 *
5 * (C) Copyright 2015
6 * Stephen Warren <swarren@wwwdotorg.org>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +02007 */
8
Simon Glass55a63072017-04-05 16:23:43 -06009#include <dm.h>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020010#include <fdt_support.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060011#include <asm/global_data.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090012#include <linux/libfdt.h>
Simon Glass55a63072017-04-05 16:23:43 -060013#include <video.h>
Devarsh Thakkar0fbb81b2024-02-22 18:38:08 +053014#include <spl.h>
15#include <bloblist.h>
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020016
17DECLARE_GLOBAL_DATA_PTR;
18
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010019static int fdt_simplefb_configure_node(void *blob, int off)
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020020{
Simon Glassd2ed4332017-04-05 16:23:42 -060021 int xsize, ysize;
22 int bpix; /* log2 of bits per pixel */
23 const char *name;
24 ulong fb_base;
Simon Glassb75b15b2020-12-03 16:55:23 -070025 struct video_uc_plat *plat;
Simon Glass55a63072017-04-05 16:23:43 -060026 struct video_priv *uc_priv;
27 struct udevice *dev;
28 int ret;
Simon Glassd2ed4332017-04-05 16:23:42 -060029
Simon Glassd4dce4a2024-09-29 19:49:36 -060030 if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && xpl_phase() > PHASE_SPL) {
Devarsh Thakkar0fbb81b2024-02-22 18:38:08 +053031 struct video_handoff *ho;
32
33 ho = bloblist_find(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho));
34 if (!ho)
35 return log_msg_ret("Missing video bloblist", -ENOENT);
36
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;
51 }
52
Simon Glassd2ed4332017-04-05 16:23:42 -060053 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;
62 }
63
64 return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
65 xsize * (1 << bpix) / 8, name);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020066}
67
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010068int fdt_simplefb_add_node(void *blob)
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020069{
70 static const char compat[] = "simple-framebuffer";
71 static const char disabled[] = "disabled";
72 int off, ret;
73
74 off = fdt_add_subnode(blob, 0, "framebuffer");
75 if (off < 0)
76 return -1;
77
78 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
79 if (ret < 0)
80 return -1;
81
82 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
83 if (ret < 0)
84 return -1;
85
Patrick Delaunaye7e69a52021-11-15 16:32:19 +010086 return fdt_simplefb_configure_node(blob, off);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020087}
88
Heinrich Schuchardtadcd00a2023-04-03 20:46:50 +020089/**
90 * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node
91 *
92 * @blob: device-tree
93 * Return: 0 on success, non-zero otherwise
94 */
95static int fdt_simplefb_enable_existing_node(void *blob)
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +020096{
97 int off;
98
99 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
100 if (off < 0)
101 return -1;
102
Patrick Delaunaye7e69a52021-11-15 16:32:19 +0100103 return fdt_simplefb_configure_node(blob, off);
Nikita Kiryanovb071e4c2015-02-03 13:32:31 +0200104}
Patrick Delaunay774aecc2021-11-15 16:32:21 +0100105
Patrick Delaunay774aecc2021-11-15 16:32:21 +0100106int fdt_simplefb_enable_and_mem_rsv(void *blob)
107{
Patrick Delaunay774aecc2021-11-15 16:32:21 +0100108 int ret;
109
110 /* nothing to do when video is not active */
111 if (!video_is_active())
112 return 0;
113
114 ret = fdt_simplefb_enable_existing_node(blob);
115 if (ret)
116 return ret;
117
Devarsh Thakkar31199892024-02-22 18:38:10 +0530118 return fdt_add_fb_mem_rsv(blob);
Patrick Delaunay774aecc2021-11-15 16:32:21 +0100119}