Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | 8131335 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_VIDEO |
| 7 | |
Nikhil M Jain | f7ec531 | 2023-07-18 14:27:31 +0530 | [diff] [blame] | 8 | #include <bloblist.h> |
Simon Glass | 73c9c37 | 2020-07-02 21:12:20 -0600 | [diff] [blame] | 9 | #include <console.h> |
Simon Glass | 6333448 | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 11 | #include <cyclic.h> |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 12 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <malloc.h> |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 15 | #include <mapmem.h> |
Nikhil M Jain | f7ec531 | 2023-07-18 14:27:31 +0530 | [diff] [blame] | 16 | #include <spl.h> |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 17 | #include <stdio_dev.h> |
| 18 | #include <video.h> |
| 19 | #include <video_console.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 20 | #include <asm/cache.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 21 | #include <asm/global_data.h> |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 22 | #include <dm/lists.h> |
Michal Simek | 632e3d4 | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 23 | #include <dm/device_compat.h> |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 24 | #include <dm/device-internal.h> |
| 25 | #include <dm/uclass-internal.h> |
| 26 | #ifdef CONFIG_SANDBOX |
| 27 | #include <asm/sdl.h> |
| 28 | #endif |
| 29 | |
| 30 | /* |
| 31 | * Theory of operation: |
| 32 | * |
| 33 | * Before relocation each device is bound. The driver for each device must |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 34 | * set the @align and @size values in struct video_uc_plat. This |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 35 | * information represents the requires size and alignment of the frame buffer |
| 36 | * for the device. The values can be an over-estimate but cannot be too |
| 37 | * small. The actual values will be suppled (in the same manner) by the bind() |
Pali Rohár | f204fce | 2022-03-09 20:46:00 +0100 | [diff] [blame] | 38 | * method after relocation. Additionally driver can allocate frame buffer |
| 39 | * itself by setting plat->base. |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 40 | * |
| 41 | * This information is then picked up by video_reserve() which works out how |
| 42 | * much memory is needed for all devices. This is allocated between |
| 43 | * gd->video_bottom and gd->video_top. |
| 44 | * |
| 45 | * After relocation the same process occurs. The driver supplies the same |
| 46 | * @size and @align information and this time video_post_bind() checks that |
| 47 | * the drivers does not overflow the allocated memory. |
| 48 | * |
| 49 | * The frame buffer address is actually set (to plat->base) in |
| 50 | * video_post_probe(). This function also clears the frame buffer and |
| 51 | * allocates a suitable text console device. This can then be used to write |
| 52 | * text to the video device. |
| 53 | */ |
| 54 | DECLARE_GLOBAL_DATA_PTR; |
| 55 | |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 56 | struct cyclic_info; |
| 57 | |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 58 | /** |
| 59 | * struct video_uc_priv - Information for the video uclass |
| 60 | * |
| 61 | * @video_ptr: Current allocation position of the video framebuffer pointer. |
| 62 | * While binding devices after relocation, this points to the next |
| 63 | * available address to use for a device's framebuffer. It starts at |
| 64 | * gd->video_top and works downwards, running out of space when it hits |
| 65 | * gd->video_bottom. |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 66 | * @cyc: handle for cyclic-execution function, or NULL if none |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 67 | */ |
| 68 | struct video_uc_priv { |
| 69 | ulong video_ptr; |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 70 | bool cyc_active; |
| 71 | struct cyclic_info cyc; |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 72 | }; |
| 73 | |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 74 | /** struct vid_rgb - Describes a video colour */ |
| 75 | struct vid_rgb { |
| 76 | u32 r; |
| 77 | u32 g; |
| 78 | u32 b; |
| 79 | }; |
| 80 | |
Simon Glass | 6463538 | 2016-01-21 19:44:52 -0700 | [diff] [blame] | 81 | void video_set_flush_dcache(struct udevice *dev, bool flush) |
| 82 | { |
| 83 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 84 | |
| 85 | priv->flush_dcache = flush; |
| 86 | } |
| 87 | |
Simon Glass | df865d3 | 2023-03-10 12:47:17 -0800 | [diff] [blame] | 88 | static ulong alloc_fb_(ulong align, ulong size, ulong *addrp) |
| 89 | { |
| 90 | ulong base; |
| 91 | |
| 92 | align = align ? align : 1 << 20; |
| 93 | base = *addrp - size; |
| 94 | base &= ~(align - 1); |
| 95 | size = *addrp - base; |
| 96 | *addrp = base; |
| 97 | |
| 98 | return size; |
| 99 | } |
| 100 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 101 | static ulong alloc_fb(struct udevice *dev, ulong *addrp) |
| 102 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 103 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | df865d3 | 2023-03-10 12:47:17 -0800 | [diff] [blame] | 104 | ulong size; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 105 | |
Simon Glass | df865d3 | 2023-03-10 12:47:17 -0800 | [diff] [blame] | 106 | if (!plat->size) { |
| 107 | if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_size) { |
| 108 | size = alloc_fb_(plat->align, plat->copy_size, addrp); |
| 109 | plat->copy_base = *addrp; |
| 110 | return size; |
| 111 | } |
| 112 | |
Bin Meng | 755623d | 2016-10-09 04:14:17 -0700 | [diff] [blame] | 113 | return 0; |
Simon Glass | df865d3 | 2023-03-10 12:47:17 -0800 | [diff] [blame] | 114 | } |
Bin Meng | 755623d | 2016-10-09 04:14:17 -0700 | [diff] [blame] | 115 | |
Pali Rohár | f204fce | 2022-03-09 20:46:00 +0100 | [diff] [blame] | 116 | /* Allow drivers to allocate the frame buffer themselves */ |
| 117 | if (plat->base) |
| 118 | return 0; |
| 119 | |
Simon Glass | df865d3 | 2023-03-10 12:47:17 -0800 | [diff] [blame] | 120 | size = alloc_fb_(plat->align, plat->size, addrp); |
| 121 | plat->base = *addrp; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 122 | |
| 123 | return size; |
| 124 | } |
| 125 | |
| 126 | int video_reserve(ulong *addrp) |
| 127 | { |
| 128 | struct udevice *dev; |
| 129 | ulong size; |
| 130 | |
Simon Glass | d4dce4a | 2024-09-29 19:49:36 -0600 | [diff] [blame] | 131 | if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && xpl_phase() == PHASE_BOARD_F) |
Devarsh Thakkar | 2febd46 | 2023-12-05 21:25:20 +0530 | [diff] [blame] | 132 | return 0; |
| 133 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 134 | gd->video_top = *addrp; |
| 135 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 136 | dev; |
| 137 | uclass_find_next_device(&dev)) { |
| 138 | size = alloc_fb(dev, addrp); |
| 139 | debug("%s: Reserving %lx bytes at %lx for video device '%s'\n", |
| 140 | __func__, size, *addrp, dev->name); |
| 141 | } |
Simon Glass | c3d2f35 | 2020-07-02 21:12:33 -0600 | [diff] [blame] | 142 | |
| 143 | /* Allocate space for PCI video devices in case there were not bound */ |
| 144 | if (*addrp == gd->video_top) |
Nikhil M Jain | 9e3301d | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 145 | *addrp -= CONFIG_VAL(VIDEO_PCI_DEFAULT_FB_SIZE); |
Simon Glass | c3d2f35 | 2020-07-02 21:12:33 -0600 | [diff] [blame] | 146 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 147 | gd->video_bottom = *addrp; |
| 148 | debug("Video frame buffers from %lx to %lx\n", gd->video_bottom, |
| 149 | gd->video_top); |
| 150 | |
| 151 | return 0; |
| 152 | } |
| 153 | |
Simon Glass | 853e8d2 | 2024-08-21 10:18:55 -0600 | [diff] [blame] | 154 | ulong video_get_fb(void) |
| 155 | { |
| 156 | struct udevice *dev; |
| 157 | |
| 158 | uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 159 | if (dev) { |
| 160 | const struct video_uc_plat *uc_plat = dev_get_uclass_plat(dev); |
| 161 | |
| 162 | return uc_plat->base; |
| 163 | } |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
Simon Glass | 062673b | 2023-06-01 10:22:33 -0600 | [diff] [blame] | 168 | int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend, |
| 169 | int yend, u32 colour) |
| 170 | { |
| 171 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 172 | void *start, *line; |
| 173 | int pixels = xend - xstart; |
Alexander Graf | f88b6a2 | 2022-06-10 00:59:21 +0200 | [diff] [blame^] | 174 | int row, i; |
Simon Glass | 062673b | 2023-06-01 10:22:33 -0600 | [diff] [blame] | 175 | |
| 176 | start = priv->fb + ystart * priv->line_length; |
| 177 | start += xstart * VNBYTES(priv->bpix); |
| 178 | line = start; |
| 179 | for (row = ystart; row < yend; row++) { |
| 180 | switch (priv->bpix) { |
| 181 | case VIDEO_BPP8: { |
| 182 | u8 *dst = line; |
| 183 | |
| 184 | if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { |
| 185 | for (i = 0; i < pixels; i++) |
| 186 | *dst++ = colour; |
| 187 | } |
| 188 | break; |
| 189 | } |
| 190 | case VIDEO_BPP16: { |
| 191 | u16 *dst = line; |
| 192 | |
| 193 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { |
| 194 | for (i = 0; i < pixels; i++) |
| 195 | *dst++ = colour; |
| 196 | } |
| 197 | break; |
| 198 | } |
| 199 | case VIDEO_BPP32: { |
| 200 | u32 *dst = line; |
| 201 | |
| 202 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { |
| 203 | for (i = 0; i < pixels; i++) |
| 204 | *dst++ = colour; |
| 205 | } |
| 206 | break; |
| 207 | } |
| 208 | default: |
| 209 | return -ENOSYS; |
| 210 | } |
| 211 | line += priv->line_length; |
| 212 | } |
Simon Glass | 062673b | 2023-06-01 10:22:33 -0600 | [diff] [blame] | 213 | |
Alexander Graf | 3b2cc82 | 2022-06-10 00:59:16 +0200 | [diff] [blame] | 214 | video_damage(dev, xstart, ystart, xend - xstart, yend - ystart); |
| 215 | |
Simon Glass | 062673b | 2023-06-01 10:22:33 -0600 | [diff] [blame] | 216 | return 0; |
| 217 | } |
| 218 | |
Nikhil M Jain | 7683353 | 2023-07-18 14:27:30 +0530 | [diff] [blame] | 219 | int video_reserve_from_bloblist(struct video_handoff *ho) |
| 220 | { |
Devarsh Thakkar | 2febd46 | 2023-12-05 21:25:20 +0530 | [diff] [blame] | 221 | if (!ho->fb || ho->size == 0) |
| 222 | return -ENOENT; |
| 223 | |
Nikhil M Jain | 7683353 | 2023-07-18 14:27:30 +0530 | [diff] [blame] | 224 | gd->video_bottom = ho->fb; |
Nikhil M Jain | 7683353 | 2023-07-18 14:27:30 +0530 | [diff] [blame] | 225 | gd->video_top = ho->fb + ho->size; |
Devarsh Thakkar | 2febd46 | 2023-12-05 21:25:20 +0530 | [diff] [blame] | 226 | debug("%s: Reserving %lx bytes at %08x as per bloblist received\n", |
| 227 | __func__, (unsigned long)ho->size, (u32)ho->fb); |
Nikhil M Jain | 7683353 | 2023-07-18 14:27:30 +0530 | [diff] [blame] | 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
Simon Glass | 2baa6f8 | 2022-10-06 08:36:08 -0600 | [diff] [blame] | 232 | int video_fill(struct udevice *dev, u32 colour) |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 233 | { |
| 234 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 235 | |
Heinrich Schuchardt | 5e4947e | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 236 | switch (priv->bpix) { |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 237 | case VIDEO_BPP16: |
Nikhil M Jain | 9e3301d | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 238 | if (CONFIG_IS_ENABLED(VIDEO_BPP16)) { |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 239 | u16 *ppix = priv->fb; |
| 240 | u16 *end = priv->fb + priv->fb_size; |
Heinrich Schuchardt | 5e4947e | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 241 | |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 242 | while (ppix < end) |
Simon Glass | 2baa6f8 | 2022-10-06 08:36:08 -0600 | [diff] [blame] | 243 | *ppix++ = colour; |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 244 | break; |
| 245 | } |
Andre Przywara | 0cff09f | 2025-03-27 15:33:05 +0000 | [diff] [blame] | 246 | fallthrough; |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 247 | case VIDEO_BPP32: |
Nikhil M Jain | 9e3301d | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 248 | if (CONFIG_IS_ENABLED(VIDEO_BPP32)) { |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 249 | u32 *ppix = priv->fb; |
| 250 | u32 *end = priv->fb + priv->fb_size; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 251 | |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 252 | while (ppix < end) |
Simon Glass | 2baa6f8 | 2022-10-06 08:36:08 -0600 | [diff] [blame] | 253 | *ppix++ = colour; |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 254 | break; |
| 255 | } |
Andre Przywara | 0cff09f | 2025-03-27 15:33:05 +0000 | [diff] [blame] | 256 | fallthrough; |
Heinrich Schuchardt | 5e4947e | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 257 | default: |
Simon Glass | 2baa6f8 | 2022-10-06 08:36:08 -0600 | [diff] [blame] | 258 | memset(priv->fb, colour, priv->fb_size); |
Heinrich Schuchardt | 5e4947e | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 259 | break; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 260 | } |
Simon Glass | 5534312 | 2018-10-01 12:22:26 -0600 | [diff] [blame] | 261 | |
Alexander Graf | 3b2cc82 | 2022-06-10 00:59:16 +0200 | [diff] [blame] | 262 | video_damage(dev, 0, 0, priv->xsize, priv->ysize); |
| 263 | |
Michal Simek | a1e136d | 2020-12-15 15:12:09 +0100 | [diff] [blame] | 264 | return video_sync(dev, false); |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Simon Glass | 2baa6f8 | 2022-10-06 08:36:08 -0600 | [diff] [blame] | 267 | int video_clear(struct udevice *dev) |
| 268 | { |
| 269 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 270 | int ret; |
| 271 | |
| 272 | ret = video_fill(dev, priv->colour_bg); |
| 273 | if (ret) |
| 274 | return ret; |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 279 | static const struct vid_rgb colours[VID_COLOUR_COUNT] = { |
| 280 | { 0x00, 0x00, 0x00 }, /* black */ |
| 281 | { 0xc0, 0x00, 0x00 }, /* red */ |
| 282 | { 0x00, 0xc0, 0x00 }, /* green */ |
| 283 | { 0xc0, 0x60, 0x00 }, /* brown */ |
| 284 | { 0x00, 0x00, 0xc0 }, /* blue */ |
| 285 | { 0xc0, 0x00, 0xc0 }, /* magenta */ |
| 286 | { 0x00, 0xc0, 0xc0 }, /* cyan */ |
| 287 | { 0xc0, 0xc0, 0xc0 }, /* light gray */ |
| 288 | { 0x80, 0x80, 0x80 }, /* gray */ |
| 289 | { 0xff, 0x00, 0x00 }, /* bright red */ |
| 290 | { 0x00, 0xff, 0x00 }, /* bright green */ |
| 291 | { 0xff, 0xff, 0x00 }, /* yellow */ |
| 292 | { 0x00, 0x00, 0xff }, /* bright blue */ |
| 293 | { 0xff, 0x00, 0xff }, /* bright magenta */ |
| 294 | { 0x00, 0xff, 0xff }, /* bright cyan */ |
| 295 | { 0xff, 0xff, 0xff }, /* white */ |
Simon Glass | bda3adc | 2024-10-14 16:31:53 -0600 | [diff] [blame] | 296 | |
| 297 | /* an extra one for menus */ |
| 298 | { 0x40, 0x40, 0x40 }, /* dark gray */ |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 299 | }; |
| 300 | |
Simon Glass | d17a624 | 2023-06-01 10:22:48 -0600 | [diff] [blame] | 301 | u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx) |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 302 | { |
| 303 | switch (priv->bpix) { |
| 304 | case VIDEO_BPP16: |
Nikhil M Jain | 9e3301d | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 305 | if (CONFIG_IS_ENABLED(VIDEO_BPP16)) { |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 306 | return ((colours[idx].r >> 3) << 11) | |
| 307 | ((colours[idx].g >> 2) << 5) | |
| 308 | ((colours[idx].b >> 3) << 0); |
| 309 | } |
| 310 | break; |
| 311 | case VIDEO_BPP32: |
Nikhil M Jain | 9e3301d | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 312 | if (CONFIG_IS_ENABLED(VIDEO_BPP32)) { |
Michal Simek | 985eac8 | 2023-05-17 10:42:07 +0200 | [diff] [blame] | 313 | switch (priv->format) { |
| 314 | case VIDEO_X2R10G10B10: |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 315 | return (colours[idx].r << 22) | |
| 316 | (colours[idx].g << 12) | |
| 317 | (colours[idx].b << 2); |
Michal Simek | 985eac8 | 2023-05-17 10:42:07 +0200 | [diff] [blame] | 318 | case VIDEO_RGBA8888: |
| 319 | return (colours[idx].r << 24) | |
| 320 | (colours[idx].g << 16) | |
| 321 | (colours[idx].b << 8) | 0xff; |
| 322 | default: |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 323 | return (colours[idx].r << 16) | |
| 324 | (colours[idx].g << 8) | |
| 325 | (colours[idx].b << 0); |
Michal Simek | 985eac8 | 2023-05-17 10:42:07 +0200 | [diff] [blame] | 326 | } |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 327 | } |
| 328 | break; |
| 329 | default: |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * For unknown bit arrangements just support |
| 335 | * black and white. |
| 336 | */ |
| 337 | if (idx) |
| 338 | return 0xffffff; /* white */ |
| 339 | |
| 340 | return 0x000000; /* black */ |
| 341 | } |
| 342 | |
Simon Glass | 2b063b8 | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 343 | void video_set_default_colors(struct udevice *dev, bool invert) |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 344 | { |
Simon Glass | 2b063b8 | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 345 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 346 | int fore, back; |
| 347 | |
Simon Glass | 05c17d6 | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 348 | if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) { |
| 349 | /* White is used when switching to bold, use light gray here */ |
| 350 | fore = VID_LIGHT_GRAY; |
| 351 | back = VID_BLACK; |
| 352 | } else { |
| 353 | fore = VID_BLACK; |
| 354 | back = VID_WHITE; |
| 355 | } |
Simon Glass | 2b063b8 | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 356 | if (invert) { |
| 357 | int temp; |
| 358 | |
| 359 | temp = fore; |
| 360 | fore = back; |
| 361 | back = temp; |
| 362 | } |
| 363 | priv->fg_col_idx = fore; |
Andre Przywara | 4ed5bc8 | 2019-03-23 01:29:56 +0000 | [diff] [blame] | 364 | priv->bg_col_idx = back; |
Simon Glass | 2a00633 | 2022-10-06 08:36:03 -0600 | [diff] [blame] | 365 | priv->colour_fg = video_index_to_colour(priv, fore); |
| 366 | priv->colour_bg = video_index_to_colour(priv, back); |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Alexander Graf | db75775 | 2022-06-10 00:59:15 +0200 | [diff] [blame] | 369 | /* Notify about changes in the frame buffer */ |
| 370 | #ifdef CONFIG_VIDEO_DAMAGE |
| 371 | void video_damage(struct udevice *vid, int x, int y, int width, int height) |
| 372 | { |
| 373 | struct video_priv *priv = dev_get_uclass_priv(vid); |
| 374 | int xend = x + width; |
| 375 | int yend = y + height; |
| 376 | |
| 377 | if (x > priv->xsize) |
| 378 | return; |
| 379 | |
| 380 | if (y > priv->ysize) |
| 381 | return; |
| 382 | |
| 383 | if (xend > priv->xsize) |
| 384 | xend = priv->xsize; |
| 385 | |
| 386 | if (yend > priv->ysize) |
| 387 | yend = priv->ysize; |
| 388 | |
| 389 | /* Span a rectangle across all old and new damage */ |
| 390 | priv->damage.xstart = min(x, priv->damage.xstart); |
| 391 | priv->damage.ystart = min(y, priv->damage.ystart); |
| 392 | priv->damage.xend = max(xend, priv->damage.xend); |
| 393 | priv->damage.yend = max(yend, priv->damage.yend); |
| 394 | } |
| 395 | #endif |
| 396 | |
Alexander Graf | 2b978f2 | 2022-06-10 00:59:20 +0200 | [diff] [blame] | 397 | #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
| 398 | static void video_flush_dcache(struct udevice *vid, bool use_copy) |
| 399 | { |
| 400 | struct video_priv *priv = dev_get_uclass_priv(vid); |
| 401 | ulong fb = use_copy ? (ulong)priv->copy_fb : (ulong)priv->fb; |
| 402 | |
| 403 | if (!priv->flush_dcache) |
| 404 | return; |
| 405 | |
| 406 | if (!IS_ENABLED(CONFIG_VIDEO_DAMAGE)) { |
| 407 | flush_dcache_range(fb, ALIGN(fb + priv->fb_size, |
| 408 | CONFIG_SYS_CACHELINE_SIZE)); |
| 409 | |
| 410 | return; |
| 411 | } |
| 412 | |
| 413 | if (priv->damage.xend && priv->damage.yend) { |
| 414 | int lstart = priv->damage.xstart * VNBYTES(priv->bpix); |
| 415 | int lend = priv->damage.xend * VNBYTES(priv->bpix); |
| 416 | int y; |
| 417 | |
| 418 | for (y = priv->damage.ystart; y < priv->damage.yend; y++) { |
| 419 | ulong start = fb + (y * priv->line_length) + lstart; |
| 420 | ulong end = start + lend - lstart; |
| 421 | |
| 422 | start = ALIGN_DOWN(start, CONFIG_SYS_CACHELINE_SIZE); |
| 423 | end = ALIGN(end, CONFIG_SYS_CACHELINE_SIZE); |
| 424 | |
| 425 | flush_dcache_range(start, end); |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | #endif |
| 430 | |
Alexander Graf | f88b6a2 | 2022-06-10 00:59:21 +0200 | [diff] [blame^] | 431 | static void video_flush_copy(struct udevice *vid) |
| 432 | { |
| 433 | struct video_priv *priv = dev_get_uclass_priv(vid); |
| 434 | |
| 435 | if (!priv->copy_fb) |
| 436 | return; |
| 437 | |
| 438 | if (priv->damage.xend && priv->damage.yend) { |
| 439 | int lstart = priv->damage.xstart * VNBYTES(priv->bpix); |
| 440 | int lend = priv->damage.xend * VNBYTES(priv->bpix); |
| 441 | int y; |
| 442 | |
| 443 | for (y = priv->damage.ystart; y < priv->damage.yend; y++) { |
| 444 | ulong offset = (y * priv->line_length) + lstart; |
| 445 | ulong len = lend - lstart; |
| 446 | |
| 447 | memcpy(priv->copy_fb + offset, priv->fb + offset, len); |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 452 | /* Flush video activity to the caches */ |
Michal Simek | 632e3d4 | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 453 | int video_sync(struct udevice *vid, bool force) |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 454 | { |
Simon Glass | 7f6280f | 2024-07-31 08:44:09 -0600 | [diff] [blame] | 455 | struct video_priv *priv = dev_get_uclass_priv(vid); |
Michal Simek | 8ae95df | 2020-12-03 09:30:00 +0100 | [diff] [blame] | 456 | struct video_ops *ops = video_get_ops(vid); |
| 457 | int ret; |
| 458 | |
Alexander Graf | f88b6a2 | 2022-06-10 00:59:21 +0200 | [diff] [blame^] | 459 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) |
| 460 | video_flush_copy(vid); |
| 461 | |
Michal Simek | 8ae95df | 2020-12-03 09:30:00 +0100 | [diff] [blame] | 462 | if (ops && ops->video_sync) { |
| 463 | ret = ops->video_sync(vid); |
| 464 | if (ret) |
| 465 | return ret; |
| 466 | } |
| 467 | |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 468 | if (CONFIG_IS_ENABLED(CYCLIC) && !force && |
| 469 | get_timer(priv->last_sync) < CONFIG_VIDEO_SYNC_MS) |
| 470 | return 0; |
| 471 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 472 | /* |
| 473 | * flush_dcache_range() is declared in common.h but it seems that some |
| 474 | * architectures do not actually implement it. Is there a way to find |
| 475 | * out whether it exists? For now, ARM is safe. |
| 476 | */ |
Trevor Woerner | 43ec7e0 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 477 | #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Alexander Graf | 2b978f2 | 2022-06-10 00:59:20 +0200 | [diff] [blame] | 478 | video_flush_dcache(vid, false); |
| 479 | |
| 480 | if (IS_ENABLED(CONFIG_VIDEO_COPY)) |
| 481 | video_flush_dcache(vid, true); |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 482 | #elif defined(CONFIG_VIDEO_SANDBOX_SDL) |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 483 | sandbox_sdl_sync(priv->fb); |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 484 | #endif |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 485 | priv->last_sync = get_timer(0); |
| 486 | |
Alexander Graf | db75775 | 2022-06-10 00:59:15 +0200 | [diff] [blame] | 487 | if (IS_ENABLED(CONFIG_VIDEO_DAMAGE)) { |
| 488 | priv->damage.xstart = priv->xsize; |
| 489 | priv->damage.ystart = priv->ysize; |
| 490 | priv->damage.xend = 0; |
| 491 | priv->damage.yend = 0; |
| 492 | } |
| 493 | |
Michal Simek | 632e3d4 | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 494 | return 0; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | void video_sync_all(void) |
| 498 | { |
| 499 | struct udevice *dev; |
Michal Simek | 632e3d4 | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 500 | int ret; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 501 | |
| 502 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 503 | dev; |
| 504 | uclass_find_next_device(&dev)) { |
Michal Simek | 632e3d4 | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 505 | if (device_active(dev)) { |
| 506 | ret = video_sync(dev, true); |
| 507 | if (ret) |
| 508 | dev_dbg(dev, "Video sync failed\n"); |
| 509 | } |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Patrick Delaunay | efcc84b | 2021-11-15 16:32:20 +0100 | [diff] [blame] | 513 | bool video_is_active(void) |
| 514 | { |
| 515 | struct udevice *dev; |
| 516 | |
Devarsh Thakkar | 42e4106 | 2024-02-22 18:38:09 +0530 | [diff] [blame] | 517 | /* Assume video to be active if SPL passed video hand-off to U-boot */ |
Simon Glass | d4dce4a | 2024-09-29 19:49:36 -0600 | [diff] [blame] | 518 | if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && xpl_phase() > PHASE_SPL) |
Devarsh Thakkar | 42e4106 | 2024-02-22 18:38:09 +0530 | [diff] [blame] | 519 | return true; |
| 520 | |
Patrick Delaunay | efcc84b | 2021-11-15 16:32:20 +0100 | [diff] [blame] | 521 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 522 | dev; |
| 523 | uclass_find_next_device(&dev)) { |
| 524 | if (device_active(dev)) |
| 525 | return true; |
| 526 | } |
| 527 | |
| 528 | return false; |
| 529 | } |
| 530 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 531 | int video_get_xsize(struct udevice *dev) |
| 532 | { |
| 533 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 534 | |
| 535 | return priv->xsize; |
| 536 | } |
| 537 | |
| 538 | int video_get_ysize(struct udevice *dev) |
| 539 | { |
| 540 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 541 | |
| 542 | return priv->ysize; |
| 543 | } |
| 544 | |
Simon Glass | 87a3cd7 | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 545 | #define SPLASH_DECL(_name) \ |
| 546 | extern u8 __splash_ ## _name ## _begin[]; \ |
| 547 | extern u8 __splash_ ## _name ## _end[] |
| 548 | |
| 549 | #define SPLASH_START(_name) __splash_ ## _name ## _begin |
| 550 | |
| 551 | SPLASH_DECL(u_boot_logo); |
| 552 | |
Simon Glass | 2247742 | 2022-10-06 08:36:09 -0600 | [diff] [blame] | 553 | void *video_get_u_boot_logo(void) |
| 554 | { |
| 555 | return SPLASH_START(u_boot_logo); |
| 556 | } |
| 557 | |
Simon Glass | 87a3cd7 | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 558 | static int show_splash(struct udevice *dev) |
| 559 | { |
| 560 | u8 *data = SPLASH_START(u_boot_logo); |
| 561 | int ret; |
| 562 | |
| 563 | ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true); |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
Simon Glass | 7045990 | 2022-10-06 08:36:18 -0600 | [diff] [blame] | 568 | int video_default_font_height(struct udevice *dev) |
| 569 | { |
| 570 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); |
| 571 | |
| 572 | if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) |
| 573 | return IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE, |
| 574 | CONFIG_CONSOLE_TRUETYPE_SIZE); |
| 575 | |
| 576 | return vc_priv->y_charsize; |
| 577 | } |
| 578 | |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 579 | static void video_idle(struct cyclic_info *cyc) |
| 580 | { |
| 581 | video_sync_all(); |
| 582 | } |
| 583 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 584 | /* Set up the display ready for use */ |
| 585 | static int video_post_probe(struct udevice *dev) |
| 586 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 587 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 588 | struct video_uc_priv *uc_priv = uclass_get_priv(dev->uclass); |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 589 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 590 | char name[30], drv[15], *str; |
Simon Glass | b3a72b3 | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 591 | const char *drv_name = drv; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 592 | struct udevice *cons; |
| 593 | int ret; |
| 594 | |
| 595 | /* Set up the line and display size */ |
| 596 | priv->fb = map_sysmem(plat->base, plat->size); |
Simon Glass | 7d18673 | 2018-11-29 15:08:52 -0700 | [diff] [blame] | 597 | if (!priv->line_length) |
| 598 | priv->line_length = priv->xsize * VNBYTES(priv->bpix); |
| 599 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 600 | priv->fb_size = priv->line_length * priv->ysize; |
| 601 | |
Devarsh Thakkar | f5254cc | 2023-12-05 21:25:21 +0530 | [diff] [blame] | 602 | /* |
| 603 | * Set up video handoff fields for passing video blob to next stage |
| 604 | * NOTE: |
| 605 | * This assumes that reserved video memory only uses a single framebuffer |
| 606 | */ |
Simon Glass | d4dce4a | 2024-09-29 19:49:36 -0600 | [diff] [blame] | 607 | if (xpl_phase() == PHASE_SPL && CONFIG_IS_ENABLED(BLOBLIST)) { |
Devarsh Thakkar | f5254cc | 2023-12-05 21:25:21 +0530 | [diff] [blame] | 608 | struct video_handoff *ho; |
| 609 | |
| 610 | ho = bloblist_add(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho), 0); |
| 611 | if (!ho) |
| 612 | return log_msg_ret("blf", -ENOENT); |
| 613 | ho->fb = gd->video_bottom; |
| 614 | /* Fill aligned size here as calculated in video_reserve() */ |
| 615 | ho->size = gd->video_top - gd->video_bottom; |
| 616 | ho->xsize = priv->xsize; |
| 617 | ho->ysize = priv->ysize; |
| 618 | ho->line_length = priv->line_length; |
| 619 | ho->bpix = priv->bpix; |
Simon Glass | 30aaa9b | 2025-01-10 17:00:19 -0700 | [diff] [blame] | 620 | ho->format = priv->format; |
Devarsh Thakkar | f5254cc | 2023-12-05 21:25:21 +0530 | [diff] [blame] | 621 | } |
| 622 | |
Simon Glass | b4928e5 | 2020-07-02 21:12:21 -0600 | [diff] [blame] | 623 | if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_base) |
| 624 | priv->copy_fb = map_sysmem(plat->copy_base, plat->size); |
| 625 | |
Heinrich Schuchardt | 290e1d8 | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 626 | /* Set up colors */ |
Simon Glass | 2b063b8 | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 627 | video_set_default_colors(dev, false); |
Rob Clark | f141188 | 2017-08-03 12:47:01 -0400 | [diff] [blame] | 628 | |
| 629 | if (!CONFIG_IS_ENABLED(NO_FB_CLEAR)) |
| 630 | video_clear(dev); |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 631 | |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 632 | /* |
Simon Glass | b3a72b3 | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 633 | * Create a text console device. For now we always do this, although |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 634 | * it might be useful to support only bitmap drawing on the device |
Simon Glass | b3a72b3 | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 635 | * for boards that don't need to display text. We create a TrueType |
| 636 | * console if enabled, a rotated console if the video driver requests |
| 637 | * it, otherwise a normal console. |
| 638 | * |
| 639 | * The console can be override by setting vidconsole_drv_name before |
| 640 | * probing this video driver, or in the probe() method. |
| 641 | * |
| 642 | * TrueType does not support rotation at present so fall back to the |
| 643 | * rotated console in that case. |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 644 | */ |
Simon Glass | b3a72b3 | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 645 | if (!priv->rot && IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) { |
Simon Glass | 2ef353e | 2016-01-14 18:10:42 -0700 | [diff] [blame] | 646 | snprintf(name, sizeof(name), "%s.vidconsole_tt", dev->name); |
| 647 | strcpy(drv, "vidconsole_tt"); |
| 648 | } else { |
| 649 | snprintf(name, sizeof(name), "%s.vidconsole%d", dev->name, |
| 650 | priv->rot); |
| 651 | snprintf(drv, sizeof(drv), "vidconsole%d", priv->rot); |
| 652 | } |
| 653 | |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 654 | str = strdup(name); |
| 655 | if (!str) |
| 656 | return -ENOMEM; |
Simon Glass | b3a72b3 | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 657 | if (priv->vidconsole_drv_name) |
| 658 | drv_name = priv->vidconsole_drv_name; |
| 659 | ret = device_bind_driver(dev, drv_name, str, &cons); |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 660 | if (ret) { |
| 661 | debug("%s: Cannot bind console driver\n", __func__); |
| 662 | return ret; |
| 663 | } |
Simon Glass | b3a72b3 | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 664 | |
Simon Glass | 84c7fb3 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 665 | ret = device_probe(cons); |
| 666 | if (ret) { |
| 667 | debug("%s: Cannot probe console driver\n", __func__); |
| 668 | return ret; |
| 669 | } |
| 670 | |
Nikhil M Jain | 9e3301d | 2023-04-20 17:41:08 +0530 | [diff] [blame] | 671 | if (CONFIG_IS_ENABLED(VIDEO_LOGO) && |
| 672 | !CONFIG_IS_ENABLED(SPLASH_SCREEN) && !plat->hide_logo) { |
Simon Glass | 87a3cd7 | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 673 | ret = show_splash(dev); |
| 674 | if (ret) { |
| 675 | log_debug("Cannot show splash screen\n"); |
| 676 | return ret; |
| 677 | } |
| 678 | } |
| 679 | |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 680 | /* register cyclic as soon as the first video device is probed */ |
| 681 | if (CONFIG_IS_ENABLED(CYCLIC) && (gd->flags && GD_FLG_RELOC) && |
| 682 | !uc_priv->cyc_active) { |
| 683 | uint ms = CONFIG_IF_ENABLED_INT(CYCLIC, VIDEO_SYNC_CYCLIC_MS); |
| 684 | |
| 685 | cyclic_register(&uc_priv->cyc, video_idle, ms * 1000, |
| 686 | "video_init"); |
| 687 | uc_priv->cyc_active = true; |
| 688 | } |
| 689 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 690 | return 0; |
| 691 | }; |
| 692 | |
| 693 | /* Post-relocation, allocate memory for the frame buffer */ |
| 694 | static int video_post_bind(struct udevice *dev) |
| 695 | { |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 696 | struct video_uc_priv *uc_priv; |
| 697 | ulong addr; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 698 | ulong size; |
| 699 | |
| 700 | /* Before relocation there is nothing to do here */ |
Tom Rini | 6985a72 | 2018-04-22 09:47:48 -0400 | [diff] [blame] | 701 | if (!(gd->flags & GD_FLG_RELOC)) |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 702 | return 0; |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 703 | |
| 704 | /* Set up the video pointer, if this is the first device */ |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 705 | uc_priv = uclass_get_priv(dev->uclass); |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 706 | if (!uc_priv->video_ptr) |
| 707 | uc_priv->video_ptr = gd->video_top; |
| 708 | |
| 709 | /* Allocate framebuffer space for this device */ |
| 710 | addr = uc_priv->video_ptr; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 711 | size = alloc_fb(dev, &addr); |
| 712 | if (addr < gd->video_bottom) { |
Bin Meng | acbafdd | 2023-07-23 12:40:24 +0800 | [diff] [blame] | 713 | /* |
| 714 | * Device tree node may need the 'bootph-all' or |
Simon Glass | fc1aa35 | 2023-02-13 08:56:34 -0700 | [diff] [blame] | 715 | * 'bootph-some-ram' tag |
Patrick Delaunay | d193718 | 2019-05-21 19:19:12 +0200 | [diff] [blame] | 716 | */ |
Bin Meng | acbafdd | 2023-07-23 12:40:24 +0800 | [diff] [blame] | 717 | printf("Video device '%s' cannot allocate frame buffer memory " |
| 718 | "- ensure the device is set up before relocation\n", |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 719 | dev->name); |
| 720 | return -ENOSPC; |
| 721 | } |
| 722 | debug("%s: Claiming %lx bytes at %lx for video device '%s'\n", |
| 723 | __func__, size, addr, dev->name); |
Simon Glass | 951255d | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 724 | uc_priv->video_ptr = addr; |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 725 | |
| 726 | return 0; |
| 727 | } |
| 728 | |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 729 | __maybe_unused static int video_destroy(struct uclass *uc) |
| 730 | { |
| 731 | struct video_uc_priv *uc_priv = uclass_get_priv(uc); |
| 732 | |
| 733 | if (uc_priv->cyc_active) { |
| 734 | cyclic_unregister(&uc_priv->cyc); |
| 735 | uc_priv->cyc_active = false; |
| 736 | } |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 741 | UCLASS_DRIVER(video) = { |
| 742 | .id = UCLASS_VIDEO, |
| 743 | .name = "video", |
| 744 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 745 | .post_bind = video_post_bind, |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 746 | .post_probe = video_post_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 747 | .priv_auto = sizeof(struct video_uc_priv), |
| 748 | .per_device_auto = sizeof(struct video_priv), |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 749 | .per_device_plat_auto = sizeof(struct video_uc_plat), |
Simon Glass | e0337a5 | 2024-07-31 08:44:10 -0600 | [diff] [blame] | 750 | CONFIG_IS_ENABLED(CYCLIC, (.destroy = video_destroy, )) |
Simon Glass | 623d28f | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 751 | }; |