]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
033167c4 NK |
2 | /* |
3 | * Simplefb device tree support | |
4 | * | |
5 | * (C) Copyright 2015 | |
6 | * Stephen Warren <swarren@wwwdotorg.org> | |
033167c4 NK |
7 | */ |
8 | ||
d678a59d | 9 | #include <common.h> |
d08e42a8 | 10 | #include <dm.h> |
033167c4 | 11 | #include <fdt_support.h> |
401d1c4f | 12 | #include <asm/global_data.h> |
b08c8c48 | 13 | #include <linux/libfdt.h> |
d08e42a8 | 14 | #include <video.h> |
86281e47 DT |
15 | #include <spl.h> |
16 | #include <bloblist.h> | |
033167c4 NK |
17 | |
18 | DECLARE_GLOBAL_DATA_PTR; | |
19 | ||
fded97ad | 20 | static int fdt_simplefb_configure_node(void *blob, int off) |
033167c4 | 21 | { |
45261455 SG |
22 | int xsize, ysize; |
23 | int bpix; /* log2 of bits per pixel */ | |
24 | const char *name; | |
25 | ulong fb_base; | |
8a8d24bd | 26 | struct video_uc_plat *plat; |
d08e42a8 SG |
27 | struct video_priv *uc_priv; |
28 | struct udevice *dev; | |
29 | int ret; | |
45261455 | 30 | |
86281e47 DT |
31 | if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && spl_phase() > PHASE_SPL) { |
32 | struct video_handoff *ho; | |
33 | ||
34 | ho = bloblist_find(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho)); | |
35 | if (!ho) | |
36 | return log_msg_ret("Missing video bloblist", -ENOENT); | |
37 | ||
38 | xsize = ho->xsize; | |
39 | ysize = ho->ysize; | |
40 | bpix = ho->bpix; | |
41 | fb_base = ho->fb; | |
42 | } else { | |
43 | ret = uclass_first_device_err(UCLASS_VIDEO, &dev); | |
44 | if (ret) | |
45 | return ret; | |
46 | uc_priv = dev_get_uclass_priv(dev); | |
47 | plat = dev_get_uclass_plat(dev); | |
48 | xsize = uc_priv->xsize; | |
49 | ysize = uc_priv->ysize; | |
50 | bpix = uc_priv->bpix; | |
51 | fb_base = plat->base; | |
52 | } | |
53 | ||
45261455 SG |
54 | switch (bpix) { |
55 | case 4: /* VIDEO_BPP16 */ | |
56 | name = "r5g6b5"; | |
57 | break; | |
58 | case 5: /* VIDEO_BPP32 */ | |
59 | name = "a8r8g8b8"; | |
60 | break; | |
61 | default: | |
62 | return -EINVAL; | |
63 | } | |
64 | ||
65 | return fdt_setup_simplefb_node(blob, off, fb_base, xsize, ysize, | |
66 | xsize * (1 << bpix) / 8, name); | |
033167c4 NK |
67 | } |
68 | ||
fded97ad | 69 | int fdt_simplefb_add_node(void *blob) |
033167c4 NK |
70 | { |
71 | static const char compat[] = "simple-framebuffer"; | |
72 | static const char disabled[] = "disabled"; | |
73 | int off, ret; | |
74 | ||
75 | off = fdt_add_subnode(blob, 0, "framebuffer"); | |
76 | if (off < 0) | |
77 | return -1; | |
78 | ||
79 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); | |
80 | if (ret < 0) | |
81 | return -1; | |
82 | ||
83 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); | |
84 | if (ret < 0) | |
85 | return -1; | |
86 | ||
fded97ad | 87 | return fdt_simplefb_configure_node(blob, off); |
033167c4 NK |
88 | } |
89 | ||
b52d6de2 HS |
90 | /** |
91 | * fdt_simplefb_enable_existing_node() - enable simple-framebuffer DT node | |
92 | * | |
93 | * @blob: device-tree | |
94 | * Return: 0 on success, non-zero otherwise | |
95 | */ | |
96 | static int fdt_simplefb_enable_existing_node(void *blob) | |
033167c4 NK |
97 | { |
98 | int off; | |
99 | ||
100 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); | |
101 | if (off < 0) | |
102 | return -1; | |
103 | ||
fded97ad | 104 | return fdt_simplefb_configure_node(blob, off); |
033167c4 | 105 | } |
77debf61 | 106 | |
1f69cbe1 | 107 | #if IS_ENABLED(CONFIG_VIDEO) |
77debf61 PD |
108 | int fdt_simplefb_enable_and_mem_rsv(void *blob) |
109 | { | |
77debf61 PD |
110 | int ret; |
111 | ||
112 | /* nothing to do when video is not active */ | |
113 | if (!video_is_active()) | |
114 | return 0; | |
115 | ||
116 | ret = fdt_simplefb_enable_existing_node(blob); | |
117 | if (ret) | |
118 | return ret; | |
119 | ||
efe1ceec | 120 | return fdt_add_fb_mem_rsv(blob); |
77debf61 PD |
121 | } |
122 | #endif |