blob: 71d4c8fde903d1f3342f82a5527716728b4f67c5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nikita Kiryanov033167c2015-02-03 13:32:31 +02002/*
3 * Simplefb device tree support
4 *
5 * (C) Copyright 2015
6 * Stephen Warren <swarren@wwwdotorg.org>
Nikita Kiryanov033167c2015-02-03 13:32:31 +02007 */
8
9#include <common.h>
Simon Glassd08e42a2017-04-05 16:23:43 -060010#include <dm.h>
Nikita Kiryanov033167c2015-02-03 13:32:31 +020011#include <fdt_support.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090013#include <linux/libfdt.h>
Simon Glassd08e42a2017-04-05 16:23:43 -060014#include <video.h>
Nikita Kiryanov033167c2015-02-03 13:32:31 +020015
16DECLARE_GLOBAL_DATA_PTR;
17
Patrick Delaunayfded97a2021-11-15 16:32:19 +010018static int fdt_simplefb_configure_node(void *blob, int off)
Nikita Kiryanov033167c2015-02-03 13:32:31 +020019{
Simon Glass45261452017-04-05 16:23:42 -060020 int xsize, ysize;
21 int bpix; /* log2 of bits per pixel */
22 const char *name;
23 ulong fb_base;
Simon Glass8a8d24b2020-12-03 16:55:23 -070024 struct video_uc_plat *plat;
Simon Glassd08e42a2017-04-05 16:23:43 -060025 struct video_priv *uc_priv;
26 struct udevice *dev;
27 int ret;
Simon Glass45261452017-04-05 16:23:42 -060028
Simon Glassd08e42a2017-04-05 16:23:43 -060029 ret = uclass_first_device_err(UCLASS_VIDEO, &dev);
30 if (ret)
31 return ret;
32 uc_priv = dev_get_uclass_priv(dev);
Simon Glasscaa4daa2020-12-03 16:55:18 -070033 plat = dev_get_uclass_plat(dev);
Simon Glassd08e42a2017-04-05 16:23:43 -060034 xsize = uc_priv->xsize;
35 ysize = uc_priv->ysize;
36 bpix = uc_priv->bpix;
37 fb_base = plat->base;
Simon Glass45261452017-04-05 16:23:42 -060038 switch (bpix) {
39 case 4: /* VIDEO_BPP16 */
40 name = "r5g6b5";
41 break;
42 case 5: /* VIDEO_BPP32 */
43 name = "a8r8g8b8";
44 break;
45 default:
46 return -EINVAL;
47 }
48
49 return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize,
50 xsize * (1 << bpix) / 8, name);
Nikita Kiryanov033167c2015-02-03 13:32:31 +020051}
52
Patrick Delaunayfded97a2021-11-15 16:32:19 +010053int fdt_simplefb_add_node(void *blob)
Nikita Kiryanov033167c2015-02-03 13:32:31 +020054{
55 static const char compat[] = "simple-framebuffer";
56 static const char disabled[] = "disabled";
57 int off, ret;
58
59 off = fdt_add_subnode(blob, 0, "framebuffer");
60 if (off < 0)
61 return -1;
62
63 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
64 if (ret < 0)
65 return -1;
66
67 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
68 if (ret < 0)
69 return -1;
70
Patrick Delaunayfded97a2021-11-15 16:32:19 +010071 return fdt_simplefb_configure_node(blob, off);
Nikita Kiryanov033167c2015-02-03 13:32:31 +020072}
73
Patrick Delaunayfded97a2021-11-15 16:32:19 +010074int fdt_simplefb_enable_existing_node(void *blob)
Nikita Kiryanov033167c2015-02-03 13:32:31 +020075{
76 int off;
77
78 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
79 if (off < 0)
80 return -1;
81
Patrick Delaunayfded97a2021-11-15 16:32:19 +010082 return fdt_simplefb_configure_node(blob, off);
Nikita Kiryanov033167c2015-02-03 13:32:31 +020083}
Patrick Delaunay77debf62021-11-15 16:32:21 +010084
Simon Glassb86986c2022-10-18 07:46:31 -060085#if CONFIG_IS_ENABLED(VIDEO)
Patrick Delaunay77debf62021-11-15 16:32:21 +010086int fdt_simplefb_enable_and_mem_rsv(void *blob)
87{
88 struct fdt_memory mem;
89 int ret;
90
91 /* nothing to do when video is not active */
92 if (!video_is_active())
93 return 0;
94
95 ret = fdt_simplefb_enable_existing_node(blob);
96 if (ret)
97 return ret;
98
99 /* nothing to do when the frame buffer is not defined */
100 if (gd->video_bottom == gd->video_top)
101 return 0;
102
103 /* reserved with no-map tag the video buffer */
104 mem.start = gd->video_bottom;
105 mem.end = gd->video_top - 1;
106
107 return fdtdec_add_reserved_memory(blob, "framebuffer", &mem, NULL, 0, NULL,
108 FDTDEC_RESERVED_MEMORY_NO_MAP);
109}
110#endif