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