blob: 6aaacff10dfa45291a9c242b343b788170c1b755 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass623d28f2016-01-18 19:52:15 -07002/*
3 * Copyright (c) 2015 Google, Inc
Simon Glass623d28f2016-01-18 19:52:15 -07004 */
5
Patrick Delaunay81313352021-04-27 11:02:19 +02006#define LOG_CATEGORY UCLASS_VIDEO
7
Simon Glass623d28f2016-01-18 19:52:15 -07008#include <common.h>
Simon Glass73c9c372020-07-02 21:12:20 -06009#include <console.h>
Simon Glass63334482019-11-14 12:57:39 -070010#include <cpu_func.h>
Simon Glass623d28f2016-01-18 19:52:15 -070011#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070013#include <malloc.h>
Simon Glass623d28f2016-01-18 19:52:15 -070014#include <mapmem.h>
15#include <stdio_dev.h>
16#include <video.h>
17#include <video_console.h>
Simon Glass274e0b02020-05-10 11:39:56 -060018#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060019#include <asm/global_data.h>
Simon Glass623d28f2016-01-18 19:52:15 -070020#include <dm/lists.h>
Michal Simek632e3d42020-12-14 08:47:52 +010021#include <dm/device_compat.h>
Simon Glass623d28f2016-01-18 19:52:15 -070022#include <dm/device-internal.h>
23#include <dm/uclass-internal.h>
24#ifdef CONFIG_SANDBOX
25#include <asm/sdl.h>
26#endif
27
28/*
29 * Theory of operation:
30 *
31 * Before relocation each device is bound. The driver for each device must
Simon Glassb75b15b2020-12-03 16:55:23 -070032 * set the @align and @size values in struct video_uc_plat. This
Simon Glass623d28f2016-01-18 19:52:15 -070033 * information represents the requires size and alignment of the frame buffer
34 * for the device. The values can be an over-estimate but cannot be too
35 * small. The actual values will be suppled (in the same manner) by the bind()
Pali Rohárf204fce2022-03-09 20:46:00 +010036 * method after relocation. Additionally driver can allocate frame buffer
37 * itself by setting plat->base.
Simon Glass623d28f2016-01-18 19:52:15 -070038 *
39 * This information is then picked up by video_reserve() which works out how
40 * much memory is needed for all devices. This is allocated between
41 * gd->video_bottom and gd->video_top.
42 *
43 * After relocation the same process occurs. The driver supplies the same
44 * @size and @align information and this time video_post_bind() checks that
45 * the drivers does not overflow the allocated memory.
46 *
47 * The frame buffer address is actually set (to plat->base) in
48 * video_post_probe(). This function also clears the frame buffer and
49 * allocates a suitable text console device. This can then be used to write
50 * text to the video device.
51 */
52DECLARE_GLOBAL_DATA_PTR;
53
Simon Glass951255d2020-07-02 21:12:32 -060054/**
55 * struct video_uc_priv - Information for the video uclass
56 *
57 * @video_ptr: Current allocation position of the video framebuffer pointer.
58 * While binding devices after relocation, this points to the next
59 * available address to use for a device's framebuffer. It starts at
60 * gd->video_top and works downwards, running out of space when it hits
61 * gd->video_bottom.
62 */
63struct video_uc_priv {
64 ulong video_ptr;
65};
66
Simon Glass2a006332022-10-06 08:36:03 -060067/** struct vid_rgb - Describes a video colour */
68struct vid_rgb {
69 u32 r;
70 u32 g;
71 u32 b;
72};
73
Simon Glass64635382016-01-21 19:44:52 -070074void video_set_flush_dcache(struct udevice *dev, bool flush)
75{
76 struct video_priv *priv = dev_get_uclass_priv(dev);
77
78 priv->flush_dcache = flush;
79}
80
Simon Glass623d28f2016-01-18 19:52:15 -070081static ulong alloc_fb(struct udevice *dev, ulong *addrp)
82{
Simon Glassb75b15b2020-12-03 16:55:23 -070083 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glass623d28f2016-01-18 19:52:15 -070084 ulong base, align, size;
85
Bin Meng755623d2016-10-09 04:14:17 -070086 if (!plat->size)
87 return 0;
88
Pali Rohárf204fce2022-03-09 20:46:00 +010089 /* Allow drivers to allocate the frame buffer themselves */
90 if (plat->base)
91 return 0;
92
Simon Glass623d28f2016-01-18 19:52:15 -070093 align = plat->align ? plat->align : 1 << 20;
94 base = *addrp - plat->size;
95 base &= ~(align - 1);
96 plat->base = base;
97 size = *addrp - base;
98 *addrp = base;
99
100 return size;
101}
102
103int video_reserve(ulong *addrp)
104{
105 struct udevice *dev;
106 ulong size;
107
108 gd->video_top = *addrp;
109 for (uclass_find_first_device(UCLASS_VIDEO, &dev);
110 dev;
111 uclass_find_next_device(&dev)) {
112 size = alloc_fb(dev, addrp);
113 debug("%s: Reserving %lx bytes at %lx for video device '%s'\n",
114 __func__, size, *addrp, dev->name);
115 }
Simon Glassc3d2f352020-07-02 21:12:33 -0600116
117 /* Allocate space for PCI video devices in case there were not bound */
118 if (*addrp == gd->video_top)
119 *addrp -= CONFIG_VIDEO_PCI_DEFAULT_FB_SIZE;
120
Simon Glass623d28f2016-01-18 19:52:15 -0700121 gd->video_bottom = *addrp;
Simon Glassb2b29612020-05-10 14:17:01 -0600122 gd->fb_base = *addrp;
Simon Glass623d28f2016-01-18 19:52:15 -0700123 debug("Video frame buffers from %lx to %lx\n", gd->video_bottom,
124 gd->video_top);
125
126 return 0;
127}
128
Simon Glass2baa6f82022-10-06 08:36:08 -0600129int video_fill(struct udevice *dev, u32 colour)
Simon Glass623d28f2016-01-18 19:52:15 -0700130{
131 struct video_priv *priv = dev_get_uclass_priv(dev);
Simon Glassf8ec6212020-07-02 21:12:22 -0600132 int ret;
Simon Glass623d28f2016-01-18 19:52:15 -0700133
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100134 switch (priv->bpix) {
Simon Glass05c17d62019-12-20 18:10:37 -0700135 case VIDEO_BPP16:
136 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
137 u16 *ppix = priv->fb;
138 u16 *end = priv->fb + priv->fb_size;
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100139
Simon Glass05c17d62019-12-20 18:10:37 -0700140 while (ppix < end)
Simon Glass2baa6f82022-10-06 08:36:08 -0600141 *ppix++ = colour;
Simon Glass05c17d62019-12-20 18:10:37 -0700142 break;
143 }
144 case VIDEO_BPP32:
145 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
146 u32 *ppix = priv->fb;
147 u32 *end = priv->fb + priv->fb_size;
Simon Glass623d28f2016-01-18 19:52:15 -0700148
Simon Glass05c17d62019-12-20 18:10:37 -0700149 while (ppix < end)
Simon Glass2baa6f82022-10-06 08:36:08 -0600150 *ppix++ = colour;
Simon Glass05c17d62019-12-20 18:10:37 -0700151 break;
152 }
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100153 default:
Simon Glass2baa6f82022-10-06 08:36:08 -0600154 memset(priv->fb, colour, priv->fb_size);
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100155 break;
Simon Glass623d28f2016-01-18 19:52:15 -0700156 }
Simon Glassf8ec6212020-07-02 21:12:22 -0600157 ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
158 if (ret)
159 return ret;
Simon Glass55343122018-10-01 12:22:26 -0600160
Michal Simeka1e136d2020-12-15 15:12:09 +0100161 return video_sync(dev, false);
Simon Glass623d28f2016-01-18 19:52:15 -0700162}
163
Simon Glass2baa6f82022-10-06 08:36:08 -0600164int video_clear(struct udevice *dev)
165{
166 struct video_priv *priv = dev_get_uclass_priv(dev);
167 int ret;
168
169 ret = video_fill(dev, priv->colour_bg);
170 if (ret)
171 return ret;
172
173 return 0;
174}
175
Simon Glass2a006332022-10-06 08:36:03 -0600176static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
177 { 0x00, 0x00, 0x00 }, /* black */
178 { 0xc0, 0x00, 0x00 }, /* red */
179 { 0x00, 0xc0, 0x00 }, /* green */
180 { 0xc0, 0x60, 0x00 }, /* brown */
181 { 0x00, 0x00, 0xc0 }, /* blue */
182 { 0xc0, 0x00, 0xc0 }, /* magenta */
183 { 0x00, 0xc0, 0xc0 }, /* cyan */
184 { 0xc0, 0xc0, 0xc0 }, /* light gray */
185 { 0x80, 0x80, 0x80 }, /* gray */
186 { 0xff, 0x00, 0x00 }, /* bright red */
187 { 0x00, 0xff, 0x00 }, /* bright green */
188 { 0xff, 0xff, 0x00 }, /* yellow */
189 { 0x00, 0x00, 0xff }, /* bright blue */
190 { 0xff, 0x00, 0xff }, /* bright magenta */
191 { 0x00, 0xff, 0xff }, /* bright cyan */
192 { 0xff, 0xff, 0xff }, /* white */
193};
194
195u32 video_index_to_colour(struct video_priv *priv, unsigned int idx)
196{
197 switch (priv->bpix) {
198 case VIDEO_BPP16:
Simon Glass95563f62023-02-05 17:55:32 -0700199 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
Simon Glass2a006332022-10-06 08:36:03 -0600200 return ((colours[idx].r >> 3) << 11) |
201 ((colours[idx].g >> 2) << 5) |
202 ((colours[idx].b >> 3) << 0);
203 }
204 break;
205 case VIDEO_BPP32:
Simon Glass76f908a2023-02-05 15:44:30 -0700206 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
Simon Glass2a006332022-10-06 08:36:03 -0600207 if (priv->format == VIDEO_X2R10G10B10)
208 return (colours[idx].r << 22) |
209 (colours[idx].g << 12) |
210 (colours[idx].b << 2);
211 else
212 return (colours[idx].r << 16) |
213 (colours[idx].g << 8) |
214 (colours[idx].b << 0);
215 }
216 break;
217 default:
218 break;
219 }
220
221 /*
222 * For unknown bit arrangements just support
223 * black and white.
224 */
225 if (idx)
226 return 0xffffff; /* white */
227
228 return 0x000000; /* black */
229}
230
Simon Glass2b063b82018-11-06 15:21:36 -0700231void video_set_default_colors(struct udevice *dev, bool invert)
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100232{
Simon Glass2b063b82018-11-06 15:21:36 -0700233 struct video_priv *priv = dev_get_uclass_priv(dev);
234 int fore, back;
235
Simon Glass05c17d62019-12-20 18:10:37 -0700236 if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
237 /* White is used when switching to bold, use light gray here */
238 fore = VID_LIGHT_GRAY;
239 back = VID_BLACK;
240 } else {
241 fore = VID_BLACK;
242 back = VID_WHITE;
243 }
Simon Glass2b063b82018-11-06 15:21:36 -0700244 if (invert) {
245 int temp;
246
247 temp = fore;
248 fore = back;
249 back = temp;
250 }
251 priv->fg_col_idx = fore;
Andre Przywara4ed5bc82019-03-23 01:29:56 +0000252 priv->bg_col_idx = back;
Simon Glass2a006332022-10-06 08:36:03 -0600253 priv->colour_fg = video_index_to_colour(priv, fore);
254 priv->colour_bg = video_index_to_colour(priv, back);
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100255}
256
Simon Glass623d28f2016-01-18 19:52:15 -0700257/* Flush video activity to the caches */
Michal Simek632e3d42020-12-14 08:47:52 +0100258int video_sync(struct udevice *vid, bool force)
Simon Glass623d28f2016-01-18 19:52:15 -0700259{
Michal Simek8ae95df2020-12-03 09:30:00 +0100260 struct video_ops *ops = video_get_ops(vid);
261 int ret;
262
263 if (ops && ops->video_sync) {
264 ret = ops->video_sync(vid);
265 if (ret)
266 return ret;
267 }
268
Simon Glass623d28f2016-01-18 19:52:15 -0700269 /*
270 * flush_dcache_range() is declared in common.h but it seems that some
271 * architectures do not actually implement it. Is there a way to find
272 * out whether it exists? For now, ARM is safe.
273 */
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400274#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Simon Glass623d28f2016-01-18 19:52:15 -0700275 struct video_priv *priv = dev_get_uclass_priv(vid);
276
277 if (priv->flush_dcache) {
278 flush_dcache_range((ulong)priv->fb,
Simon Glasseebc3fd2016-11-13 14:22:06 -0700279 ALIGN((ulong)priv->fb + priv->fb_size,
280 CONFIG_SYS_CACHELINE_SIZE));
Simon Glass623d28f2016-01-18 19:52:15 -0700281 }
282#elif defined(CONFIG_VIDEO_SANDBOX_SDL)
283 struct video_priv *priv = dev_get_uclass_priv(vid);
284 static ulong last_sync;
285
Simon Glassea113732022-02-28 15:13:48 -0700286 if (force || get_timer(last_sync) > 100) {
Simon Glass623d28f2016-01-18 19:52:15 -0700287 sandbox_sdl_sync(priv->fb);
288 last_sync = get_timer(0);
289 }
290#endif
Michal Simek632e3d42020-12-14 08:47:52 +0100291 return 0;
Simon Glass623d28f2016-01-18 19:52:15 -0700292}
293
294void video_sync_all(void)
295{
296 struct udevice *dev;
Michal Simek632e3d42020-12-14 08:47:52 +0100297 int ret;
Simon Glass623d28f2016-01-18 19:52:15 -0700298
299 for (uclass_find_first_device(UCLASS_VIDEO, &dev);
300 dev;
301 uclass_find_next_device(&dev)) {
Michal Simek632e3d42020-12-14 08:47:52 +0100302 if (device_active(dev)) {
303 ret = video_sync(dev, true);
304 if (ret)
305 dev_dbg(dev, "Video sync failed\n");
306 }
Simon Glass623d28f2016-01-18 19:52:15 -0700307 }
308}
309
Patrick Delaunayefcc84b2021-11-15 16:32:20 +0100310bool video_is_active(void)
311{
312 struct udevice *dev;
313
314 for (uclass_find_first_device(UCLASS_VIDEO, &dev);
315 dev;
316 uclass_find_next_device(&dev)) {
317 if (device_active(dev))
318 return true;
319 }
320
321 return false;
322}
323
Simon Glass623d28f2016-01-18 19:52:15 -0700324int video_get_xsize(struct udevice *dev)
325{
326 struct video_priv *priv = dev_get_uclass_priv(dev);
327
328 return priv->xsize;
329}
330
331int video_get_ysize(struct udevice *dev)
332{
333 struct video_priv *priv = dev_get_uclass_priv(dev);
334
335 return priv->ysize;
336}
337
Simon Glass73c9c372020-07-02 21:12:20 -0600338#ifdef CONFIG_VIDEO_COPY
339int video_sync_copy(struct udevice *dev, void *from, void *to)
340{
341 struct video_priv *priv = dev_get_uclass_priv(dev);
342
343 if (priv->copy_fb) {
344 long offset, size;
345
346 /* Find the offset of the first byte to copy */
347 if ((ulong)to > (ulong)from) {
348 size = to - from;
349 offset = from - priv->fb;
350 } else {
351 size = from - to;
352 offset = to - priv->fb;
353 }
354
355 /*
356 * Allow a bit of leeway for valid requests somewhere near the
357 * frame buffer
358 */
359 if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
360#ifdef DEBUG
Simon Glass78cdc5d2021-11-19 13:23:51 -0700361 char str[120];
Simon Glass73c9c372020-07-02 21:12:20 -0600362
363 snprintf(str, sizeof(str),
Simon Glass78cdc5d2021-11-19 13:23:51 -0700364 "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
Simon Glass73c9c372020-07-02 21:12:20 -0600365 priv->fb, from, to, offset);
366 console_puts_select_stderr(true, str);
367#endif
368 return -EFAULT;
369 }
370
371 /*
372 * Silently crop the memcpy. This allows callers to avoid doing
373 * this themselves. It is common for the end pointer to go a
374 * few lines after the end of the frame buffer, since most of
375 * the update algorithms terminate a line after their last write
376 */
377 if (offset + size > priv->fb_size) {
378 size = priv->fb_size - offset;
379 } else if (offset < 0) {
380 size += offset;
381 offset = 0;
382 }
383
384 memcpy(priv->copy_fb + offset, priv->fb + offset, size);
385 }
386
387 return 0;
388}
Simon Glass62b535e2021-01-13 20:29:46 -0700389
390int video_sync_copy_all(struct udevice *dev)
391{
392 struct video_priv *priv = dev_get_uclass_priv(dev);
393
394 video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
395
396 return 0;
397}
398
Simon Glass73c9c372020-07-02 21:12:20 -0600399#endif
400
Simon Glass87a3cd72021-11-19 13:24:03 -0700401#define SPLASH_DECL(_name) \
402 extern u8 __splash_ ## _name ## _begin[]; \
403 extern u8 __splash_ ## _name ## _end[]
404
405#define SPLASH_START(_name) __splash_ ## _name ## _begin
406
407SPLASH_DECL(u_boot_logo);
408
Simon Glass22477422022-10-06 08:36:09 -0600409void *video_get_u_boot_logo(void)
410{
411 return SPLASH_START(u_boot_logo);
412}
413
Simon Glass87a3cd72021-11-19 13:24:03 -0700414static int show_splash(struct udevice *dev)
415{
416 u8 *data = SPLASH_START(u_boot_logo);
417 int ret;
418
419 ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true);
420
421 return 0;
422}
423
Simon Glass70459902022-10-06 08:36:18 -0600424int video_default_font_height(struct udevice *dev)
425{
426 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
427
428 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
429 return IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
430 CONFIG_CONSOLE_TRUETYPE_SIZE);
431
432 return vc_priv->y_charsize;
433}
434
Simon Glass623d28f2016-01-18 19:52:15 -0700435/* Set up the display ready for use */
436static int video_post_probe(struct udevice *dev)
437{
Simon Glassb75b15b2020-12-03 16:55:23 -0700438 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glass623d28f2016-01-18 19:52:15 -0700439 struct video_priv *priv = dev_get_uclass_priv(dev);
440 char name[30], drv[15], *str;
Simon Glassb3a72b32016-01-14 18:10:48 -0700441 const char *drv_name = drv;
Simon Glass623d28f2016-01-18 19:52:15 -0700442 struct udevice *cons;
443 int ret;
444
445 /* Set up the line and display size */
446 priv->fb = map_sysmem(plat->base, plat->size);
Simon Glass7d186732018-11-29 15:08:52 -0700447 if (!priv->line_length)
448 priv->line_length = priv->xsize * VNBYTES(priv->bpix);
449
Simon Glass623d28f2016-01-18 19:52:15 -0700450 priv->fb_size = priv->line_length * priv->ysize;
451
Simon Glassb4928e52020-07-02 21:12:21 -0600452 if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_base)
453 priv->copy_fb = map_sysmem(plat->copy_base, plat->size);
454
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100455 /* Set up colors */
Simon Glass2b063b82018-11-06 15:21:36 -0700456 video_set_default_colors(dev, false);
Rob Clarkf1411882017-08-03 12:47:01 -0400457
458 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
459 video_clear(dev);
Simon Glass623d28f2016-01-18 19:52:15 -0700460
Simon Glass84c7fb32016-01-18 19:52:17 -0700461 /*
Simon Glassb3a72b32016-01-14 18:10:48 -0700462 * Create a text console device. For now we always do this, although
Simon Glass84c7fb32016-01-18 19:52:17 -0700463 * it might be useful to support only bitmap drawing on the device
Simon Glassb3a72b32016-01-14 18:10:48 -0700464 * for boards that don't need to display text. We create a TrueType
465 * console if enabled, a rotated console if the video driver requests
466 * it, otherwise a normal console.
467 *
468 * The console can be override by setting vidconsole_drv_name before
469 * probing this video driver, or in the probe() method.
470 *
471 * TrueType does not support rotation at present so fall back to the
472 * rotated console in that case.
Simon Glass84c7fb32016-01-18 19:52:17 -0700473 */
Simon Glassb3a72b32016-01-14 18:10:48 -0700474 if (!priv->rot && IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) {
Simon Glass2ef353e2016-01-14 18:10:42 -0700475 snprintf(name, sizeof(name), "%s.vidconsole_tt", dev->name);
476 strcpy(drv, "vidconsole_tt");
477 } else {
478 snprintf(name, sizeof(name), "%s.vidconsole%d", dev->name,
479 priv->rot);
480 snprintf(drv, sizeof(drv), "vidconsole%d", priv->rot);
481 }
482
Simon Glass84c7fb32016-01-18 19:52:17 -0700483 str = strdup(name);
484 if (!str)
485 return -ENOMEM;
Simon Glassb3a72b32016-01-14 18:10:48 -0700486 if (priv->vidconsole_drv_name)
487 drv_name = priv->vidconsole_drv_name;
488 ret = device_bind_driver(dev, drv_name, str, &cons);
Simon Glass84c7fb32016-01-18 19:52:17 -0700489 if (ret) {
490 debug("%s: Cannot bind console driver\n", __func__);
491 return ret;
492 }
Simon Glassb3a72b32016-01-14 18:10:48 -0700493
Simon Glass84c7fb32016-01-18 19:52:17 -0700494 ret = device_probe(cons);
495 if (ret) {
496 debug("%s: Cannot probe console driver\n", __func__);
497 return ret;
498 }
499
Fabio Estevamc15fa3b2022-03-28 16:40:36 -0300500 if (IS_ENABLED(CONFIG_VIDEO_LOGO) &&
501 !IS_ENABLED(CONFIG_SPLASH_SCREEN) && !plat->hide_logo) {
Simon Glass87a3cd72021-11-19 13:24:03 -0700502 ret = show_splash(dev);
503 if (ret) {
504 log_debug("Cannot show splash screen\n");
505 return ret;
506 }
507 }
508
Simon Glass623d28f2016-01-18 19:52:15 -0700509 return 0;
510};
511
512/* Post-relocation, allocate memory for the frame buffer */
513static int video_post_bind(struct udevice *dev)
514{
Simon Glass951255d2020-07-02 21:12:32 -0600515 struct video_uc_priv *uc_priv;
516 ulong addr;
Simon Glass623d28f2016-01-18 19:52:15 -0700517 ulong size;
518
519 /* Before relocation there is nothing to do here */
Tom Rini6985a722018-04-22 09:47:48 -0400520 if (!(gd->flags & GD_FLG_RELOC))
Simon Glass623d28f2016-01-18 19:52:15 -0700521 return 0;
Simon Glass951255d2020-07-02 21:12:32 -0600522
523 /* Set up the video pointer, if this is the first device */
Simon Glass95588622020-12-22 19:30:28 -0700524 uc_priv = uclass_get_priv(dev->uclass);
Simon Glass951255d2020-07-02 21:12:32 -0600525 if (!uc_priv->video_ptr)
526 uc_priv->video_ptr = gd->video_top;
527
528 /* Allocate framebuffer space for this device */
529 addr = uc_priv->video_ptr;
Simon Glass623d28f2016-01-18 19:52:15 -0700530 size = alloc_fb(dev, &addr);
531 if (addr < gd->video_bottom) {
Patrick Delaunayd1937182019-05-21 19:19:12 +0200532 /* Device tree node may need the 'u-boot,dm-pre-reloc' or
533 * 'u-boot,dm-pre-proper' tag
534 */
Simon Glass623d28f2016-01-18 19:52:15 -0700535 printf("Video device '%s' cannot allocate frame buffer memory -ensure the device is set up before relocation\n",
536 dev->name);
537 return -ENOSPC;
538 }
539 debug("%s: Claiming %lx bytes at %lx for video device '%s'\n",
540 __func__, size, addr, dev->name);
Simon Glass951255d2020-07-02 21:12:32 -0600541 uc_priv->video_ptr = addr;
Simon Glass623d28f2016-01-18 19:52:15 -0700542
543 return 0;
544}
545
546UCLASS_DRIVER(video) = {
547 .id = UCLASS_VIDEO,
548 .name = "video",
549 .flags = DM_UC_FLAG_SEQ_ALIAS,
550 .post_bind = video_post_bind,
Simon Glass623d28f2016-01-18 19:52:15 -0700551 .post_probe = video_post_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700552 .priv_auto = sizeof(struct video_uc_priv),
553 .per_device_auto = sizeof(struct video_priv),
Simon Glassb75b15b2020-12-03 16:55:23 -0700554 .per_device_plat_auto = sizeof(struct video_uc_plat),
Simon Glass623d28f2016-01-18 19:52:15 -0700555};