blob: 95e874b770b28c446cf81c37250a7f29153c2125 [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 Glassdf865d32023-03-10 12:47:17 -080081static ulong alloc_fb_(ulong align, ulong size, ulong *addrp)
82{
83 ulong base;
84
85 align = align ? align : 1 << 20;
86 base = *addrp - size;
87 base &= ~(align - 1);
88 size = *addrp - base;
89 *addrp = base;
90
91 return size;
92}
93
Simon Glass623d28f2016-01-18 19:52:15 -070094static ulong alloc_fb(struct udevice *dev, ulong *addrp)
95{
Simon Glassb75b15b2020-12-03 16:55:23 -070096 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glassdf865d32023-03-10 12:47:17 -080097 ulong size;
Simon Glass623d28f2016-01-18 19:52:15 -070098
Simon Glassdf865d32023-03-10 12:47:17 -080099 if (!plat->size) {
100 if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_size) {
101 size = alloc_fb_(plat->align, plat->copy_size, addrp);
102 plat->copy_base = *addrp;
103 return size;
104 }
105
Bin Meng755623d2016-10-09 04:14:17 -0700106 return 0;
Simon Glassdf865d32023-03-10 12:47:17 -0800107 }
Bin Meng755623d2016-10-09 04:14:17 -0700108
Pali Rohárf204fce2022-03-09 20:46:00 +0100109 /* Allow drivers to allocate the frame buffer themselves */
110 if (plat->base)
111 return 0;
112
Simon Glassdf865d32023-03-10 12:47:17 -0800113 size = alloc_fb_(plat->align, plat->size, addrp);
114 plat->base = *addrp;
Simon Glass623d28f2016-01-18 19:52:15 -0700115
116 return size;
117}
118
119int video_reserve(ulong *addrp)
120{
121 struct udevice *dev;
122 ulong size;
123
124 gd->video_top = *addrp;
125 for (uclass_find_first_device(UCLASS_VIDEO, &dev);
126 dev;
127 uclass_find_next_device(&dev)) {
128 size = alloc_fb(dev, addrp);
129 debug("%s: Reserving %lx bytes at %lx for video device '%s'\n",
130 __func__, size, *addrp, dev->name);
131 }
Simon Glassc3d2f352020-07-02 21:12:33 -0600132
133 /* Allocate space for PCI video devices in case there were not bound */
134 if (*addrp == gd->video_top)
Nikhil M Jain9e3301d2023-04-20 17:41:08 +0530135 *addrp -= CONFIG_VAL(VIDEO_PCI_DEFAULT_FB_SIZE);
Simon Glassc3d2f352020-07-02 21:12:33 -0600136
Simon Glass623d28f2016-01-18 19:52:15 -0700137 gd->video_bottom = *addrp;
Simon Glassb2b29612020-05-10 14:17:01 -0600138 gd->fb_base = *addrp;
Simon Glass623d28f2016-01-18 19:52:15 -0700139 debug("Video frame buffers from %lx to %lx\n", gd->video_bottom,
140 gd->video_top);
141
142 return 0;
143}
144
Simon Glass062673b2023-06-01 10:22:33 -0600145int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend,
146 int yend, u32 colour)
147{
148 struct video_priv *priv = dev_get_uclass_priv(dev);
149 void *start, *line;
150 int pixels = xend - xstart;
151 int row, i, ret;
152
153 start = priv->fb + ystart * priv->line_length;
154 start += xstart * VNBYTES(priv->bpix);
155 line = start;
156 for (row = ystart; row < yend; row++) {
157 switch (priv->bpix) {
158 case VIDEO_BPP8: {
159 u8 *dst = line;
160
161 if (IS_ENABLED(CONFIG_VIDEO_BPP8)) {
162 for (i = 0; i < pixels; i++)
163 *dst++ = colour;
164 }
165 break;
166 }
167 case VIDEO_BPP16: {
168 u16 *dst = line;
169
170 if (IS_ENABLED(CONFIG_VIDEO_BPP16)) {
171 for (i = 0; i < pixels; i++)
172 *dst++ = colour;
173 }
174 break;
175 }
176 case VIDEO_BPP32: {
177 u32 *dst = line;
178
179 if (IS_ENABLED(CONFIG_VIDEO_BPP32)) {
180 for (i = 0; i < pixels; i++)
181 *dst++ = colour;
182 }
183 break;
184 }
185 default:
186 return -ENOSYS;
187 }
188 line += priv->line_length;
189 }
190 ret = video_sync_copy(dev, start, line);
191 if (ret)
192 return ret;
193
194 return 0;
195}
196
Simon Glass2baa6f82022-10-06 08:36:08 -0600197int video_fill(struct udevice *dev, u32 colour)
Simon Glass623d28f2016-01-18 19:52:15 -0700198{
199 struct video_priv *priv = dev_get_uclass_priv(dev);
Simon Glassf8ec6212020-07-02 21:12:22 -0600200 int ret;
Simon Glass623d28f2016-01-18 19:52:15 -0700201
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100202 switch (priv->bpix) {
Simon Glass05c17d62019-12-20 18:10:37 -0700203 case VIDEO_BPP16:
Nikhil M Jain9e3301d2023-04-20 17:41:08 +0530204 if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
Simon Glass05c17d62019-12-20 18:10:37 -0700205 u16 *ppix = priv->fb;
206 u16 *end = priv->fb + priv->fb_size;
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100207
Simon Glass05c17d62019-12-20 18:10:37 -0700208 while (ppix < end)
Simon Glass2baa6f82022-10-06 08:36:08 -0600209 *ppix++ = colour;
Simon Glass05c17d62019-12-20 18:10:37 -0700210 break;
211 }
212 case VIDEO_BPP32:
Nikhil M Jain9e3301d2023-04-20 17:41:08 +0530213 if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
Simon Glass05c17d62019-12-20 18:10:37 -0700214 u32 *ppix = priv->fb;
215 u32 *end = priv->fb + priv->fb_size;
Simon Glass623d28f2016-01-18 19:52:15 -0700216
Simon Glass05c17d62019-12-20 18:10:37 -0700217 while (ppix < end)
Simon Glass2baa6f82022-10-06 08:36:08 -0600218 *ppix++ = colour;
Simon Glass05c17d62019-12-20 18:10:37 -0700219 break;
220 }
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100221 default:
Simon Glass2baa6f82022-10-06 08:36:08 -0600222 memset(priv->fb, colour, priv->fb_size);
Heinrich Schuchardt5e4947e2018-02-08 21:47:10 +0100223 break;
Simon Glass623d28f2016-01-18 19:52:15 -0700224 }
Simon Glassf8ec6212020-07-02 21:12:22 -0600225 ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
226 if (ret)
227 return ret;
Simon Glass55343122018-10-01 12:22:26 -0600228
Michal Simeka1e136d2020-12-15 15:12:09 +0100229 return video_sync(dev, false);
Simon Glass623d28f2016-01-18 19:52:15 -0700230}
231
Simon Glass2baa6f82022-10-06 08:36:08 -0600232int video_clear(struct udevice *dev)
233{
234 struct video_priv *priv = dev_get_uclass_priv(dev);
235 int ret;
236
237 ret = video_fill(dev, priv->colour_bg);
238 if (ret)
239 return ret;
240
241 return 0;
242}
243
Simon Glass2a006332022-10-06 08:36:03 -0600244static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
245 { 0x00, 0x00, 0x00 }, /* black */
246 { 0xc0, 0x00, 0x00 }, /* red */
247 { 0x00, 0xc0, 0x00 }, /* green */
248 { 0xc0, 0x60, 0x00 }, /* brown */
249 { 0x00, 0x00, 0xc0 }, /* blue */
250 { 0xc0, 0x00, 0xc0 }, /* magenta */
251 { 0x00, 0xc0, 0xc0 }, /* cyan */
252 { 0xc0, 0xc0, 0xc0 }, /* light gray */
253 { 0x80, 0x80, 0x80 }, /* gray */
254 { 0xff, 0x00, 0x00 }, /* bright red */
255 { 0x00, 0xff, 0x00 }, /* bright green */
256 { 0xff, 0xff, 0x00 }, /* yellow */
257 { 0x00, 0x00, 0xff }, /* bright blue */
258 { 0xff, 0x00, 0xff }, /* bright magenta */
259 { 0x00, 0xff, 0xff }, /* bright cyan */
260 { 0xff, 0xff, 0xff }, /* white */
261};
262
Simon Glassd17a6242023-06-01 10:22:48 -0600263u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx)
Simon Glass2a006332022-10-06 08:36:03 -0600264{
265 switch (priv->bpix) {
266 case VIDEO_BPP16:
Nikhil M Jain9e3301d2023-04-20 17:41:08 +0530267 if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
Simon Glass2a006332022-10-06 08:36:03 -0600268 return ((colours[idx].r >> 3) << 11) |
269 ((colours[idx].g >> 2) << 5) |
270 ((colours[idx].b >> 3) << 0);
271 }
272 break;
273 case VIDEO_BPP32:
Nikhil M Jain9e3301d2023-04-20 17:41:08 +0530274 if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
Michal Simek985eac82023-05-17 10:42:07 +0200275 switch (priv->format) {
276 case VIDEO_X2R10G10B10:
Simon Glass2a006332022-10-06 08:36:03 -0600277 return (colours[idx].r << 22) |
278 (colours[idx].g << 12) |
279 (colours[idx].b << 2);
Michal Simek985eac82023-05-17 10:42:07 +0200280 case VIDEO_RGBA8888:
281 return (colours[idx].r << 24) |
282 (colours[idx].g << 16) |
283 (colours[idx].b << 8) | 0xff;
284 default:
Simon Glass2a006332022-10-06 08:36:03 -0600285 return (colours[idx].r << 16) |
286 (colours[idx].g << 8) |
287 (colours[idx].b << 0);
Michal Simek985eac82023-05-17 10:42:07 +0200288 }
Simon Glass2a006332022-10-06 08:36:03 -0600289 }
290 break;
291 default:
292 break;
293 }
294
295 /*
296 * For unknown bit arrangements just support
297 * black and white.
298 */
299 if (idx)
300 return 0xffffff; /* white */
301
302 return 0x000000; /* black */
303}
304
Simon Glass2b063b82018-11-06 15:21:36 -0700305void video_set_default_colors(struct udevice *dev, bool invert)
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100306{
Simon Glass2b063b82018-11-06 15:21:36 -0700307 struct video_priv *priv = dev_get_uclass_priv(dev);
308 int fore, back;
309
Simon Glass05c17d62019-12-20 18:10:37 -0700310 if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) {
311 /* White is used when switching to bold, use light gray here */
312 fore = VID_LIGHT_GRAY;
313 back = VID_BLACK;
314 } else {
315 fore = VID_BLACK;
316 back = VID_WHITE;
317 }
Simon Glass2b063b82018-11-06 15:21:36 -0700318 if (invert) {
319 int temp;
320
321 temp = fore;
322 fore = back;
323 back = temp;
324 }
325 priv->fg_col_idx = fore;
Andre Przywara4ed5bc82019-03-23 01:29:56 +0000326 priv->bg_col_idx = back;
Simon Glass2a006332022-10-06 08:36:03 -0600327 priv->colour_fg = video_index_to_colour(priv, fore);
328 priv->colour_bg = video_index_to_colour(priv, back);
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100329}
330
Simon Glass623d28f2016-01-18 19:52:15 -0700331/* Flush video activity to the caches */
Michal Simek632e3d42020-12-14 08:47:52 +0100332int video_sync(struct udevice *vid, bool force)
Simon Glass623d28f2016-01-18 19:52:15 -0700333{
Michal Simek8ae95df2020-12-03 09:30:00 +0100334 struct video_ops *ops = video_get_ops(vid);
335 int ret;
336
337 if (ops && ops->video_sync) {
338 ret = ops->video_sync(vid);
339 if (ret)
340 return ret;
341 }
342
Simon Glass623d28f2016-01-18 19:52:15 -0700343 /*
344 * flush_dcache_range() is declared in common.h but it seems that some
345 * architectures do not actually implement it. Is there a way to find
346 * out whether it exists? For now, ARM is safe.
347 */
Trevor Woerner43ec7e02019-05-03 09:41:00 -0400348#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Simon Glass623d28f2016-01-18 19:52:15 -0700349 struct video_priv *priv = dev_get_uclass_priv(vid);
350
351 if (priv->flush_dcache) {
352 flush_dcache_range((ulong)priv->fb,
Simon Glasseebc3fd2016-11-13 14:22:06 -0700353 ALIGN((ulong)priv->fb + priv->fb_size,
354 CONFIG_SYS_CACHELINE_SIZE));
Simon Glass623d28f2016-01-18 19:52:15 -0700355 }
356#elif defined(CONFIG_VIDEO_SANDBOX_SDL)
357 struct video_priv *priv = dev_get_uclass_priv(vid);
358 static ulong last_sync;
359
Simon Glassea113732022-02-28 15:13:48 -0700360 if (force || get_timer(last_sync) > 100) {
Simon Glass623d28f2016-01-18 19:52:15 -0700361 sandbox_sdl_sync(priv->fb);
362 last_sync = get_timer(0);
363 }
364#endif
Michal Simek632e3d42020-12-14 08:47:52 +0100365 return 0;
Simon Glass623d28f2016-01-18 19:52:15 -0700366}
367
368void video_sync_all(void)
369{
370 struct udevice *dev;
Michal Simek632e3d42020-12-14 08:47:52 +0100371 int ret;
Simon Glass623d28f2016-01-18 19:52:15 -0700372
373 for (uclass_find_first_device(UCLASS_VIDEO, &dev);
374 dev;
375 uclass_find_next_device(&dev)) {
Michal Simek632e3d42020-12-14 08:47:52 +0100376 if (device_active(dev)) {
377 ret = video_sync(dev, true);
378 if (ret)
379 dev_dbg(dev, "Video sync failed\n");
380 }
Simon Glass623d28f2016-01-18 19:52:15 -0700381 }
382}
383
Patrick Delaunayefcc84b2021-11-15 16:32:20 +0100384bool video_is_active(void)
385{
386 struct udevice *dev;
387
388 for (uclass_find_first_device(UCLASS_VIDEO, &dev);
389 dev;
390 uclass_find_next_device(&dev)) {
391 if (device_active(dev))
392 return true;
393 }
394
395 return false;
396}
397
Simon Glass623d28f2016-01-18 19:52:15 -0700398int video_get_xsize(struct udevice *dev)
399{
400 struct video_priv *priv = dev_get_uclass_priv(dev);
401
402 return priv->xsize;
403}
404
405int video_get_ysize(struct udevice *dev)
406{
407 struct video_priv *priv = dev_get_uclass_priv(dev);
408
409 return priv->ysize;
410}
411
Simon Glass73c9c372020-07-02 21:12:20 -0600412#ifdef CONFIG_VIDEO_COPY
413int video_sync_copy(struct udevice *dev, void *from, void *to)
414{
415 struct video_priv *priv = dev_get_uclass_priv(dev);
416
417 if (priv->copy_fb) {
418 long offset, size;
419
420 /* Find the offset of the first byte to copy */
421 if ((ulong)to > (ulong)from) {
422 size = to - from;
423 offset = from - priv->fb;
424 } else {
425 size = from - to;
426 offset = to - priv->fb;
427 }
428
429 /*
430 * Allow a bit of leeway for valid requests somewhere near the
431 * frame buffer
432 */
433 if (offset < -priv->fb_size || offset > 2 * priv->fb_size) {
434#ifdef DEBUG
Simon Glass78cdc5d2021-11-19 13:23:51 -0700435 char str[120];
Simon Glass73c9c372020-07-02 21:12:20 -0600436
437 snprintf(str, sizeof(str),
Simon Glass78cdc5d2021-11-19 13:23:51 -0700438 "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]",
Simon Glass73c9c372020-07-02 21:12:20 -0600439 priv->fb, from, to, offset);
440 console_puts_select_stderr(true, str);
441#endif
442 return -EFAULT;
443 }
444
445 /*
446 * Silently crop the memcpy. This allows callers to avoid doing
447 * this themselves. It is common for the end pointer to go a
448 * few lines after the end of the frame buffer, since most of
449 * the update algorithms terminate a line after their last write
450 */
451 if (offset + size > priv->fb_size) {
452 size = priv->fb_size - offset;
453 } else if (offset < 0) {
454 size += offset;
455 offset = 0;
456 }
457
458 memcpy(priv->copy_fb + offset, priv->fb + offset, size);
459 }
460
461 return 0;
462}
Simon Glass62b535e2021-01-13 20:29:46 -0700463
464int video_sync_copy_all(struct udevice *dev)
465{
466 struct video_priv *priv = dev_get_uclass_priv(dev);
467
468 video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size);
469
470 return 0;
471}
472
Simon Glass73c9c372020-07-02 21:12:20 -0600473#endif
474
Simon Glass87a3cd72021-11-19 13:24:03 -0700475#define SPLASH_DECL(_name) \
476 extern u8 __splash_ ## _name ## _begin[]; \
477 extern u8 __splash_ ## _name ## _end[]
478
479#define SPLASH_START(_name) __splash_ ## _name ## _begin
480
481SPLASH_DECL(u_boot_logo);
482
Simon Glass22477422022-10-06 08:36:09 -0600483void *video_get_u_boot_logo(void)
484{
485 return SPLASH_START(u_boot_logo);
486}
487
Simon Glass87a3cd72021-11-19 13:24:03 -0700488static int show_splash(struct udevice *dev)
489{
490 u8 *data = SPLASH_START(u_boot_logo);
491 int ret;
492
493 ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true);
494
495 return 0;
496}
497
Simon Glass70459902022-10-06 08:36:18 -0600498int video_default_font_height(struct udevice *dev)
499{
500 struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
501
502 if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE))
503 return IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE,
504 CONFIG_CONSOLE_TRUETYPE_SIZE);
505
506 return vc_priv->y_charsize;
507}
508
Simon Glass623d28f2016-01-18 19:52:15 -0700509/* Set up the display ready for use */
510static int video_post_probe(struct udevice *dev)
511{
Simon Glassb75b15b2020-12-03 16:55:23 -0700512 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glass623d28f2016-01-18 19:52:15 -0700513 struct video_priv *priv = dev_get_uclass_priv(dev);
514 char name[30], drv[15], *str;
Simon Glassb3a72b32016-01-14 18:10:48 -0700515 const char *drv_name = drv;
Simon Glass623d28f2016-01-18 19:52:15 -0700516 struct udevice *cons;
517 int ret;
518
519 /* Set up the line and display size */
520 priv->fb = map_sysmem(plat->base, plat->size);
Simon Glass7d186732018-11-29 15:08:52 -0700521 if (!priv->line_length)
522 priv->line_length = priv->xsize * VNBYTES(priv->bpix);
523
Simon Glass623d28f2016-01-18 19:52:15 -0700524 priv->fb_size = priv->line_length * priv->ysize;
525
Simon Glassb4928e52020-07-02 21:12:21 -0600526 if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_base)
527 priv->copy_fb = map_sysmem(plat->copy_base, plat->size);
528
Heinrich Schuchardt290e1d82018-02-08 21:47:11 +0100529 /* Set up colors */
Simon Glass2b063b82018-11-06 15:21:36 -0700530 video_set_default_colors(dev, false);
Rob Clarkf1411882017-08-03 12:47:01 -0400531
532 if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
533 video_clear(dev);
Simon Glass623d28f2016-01-18 19:52:15 -0700534
Simon Glass84c7fb32016-01-18 19:52:17 -0700535 /*
Simon Glassb3a72b32016-01-14 18:10:48 -0700536 * Create a text console device. For now we always do this, although
Simon Glass84c7fb32016-01-18 19:52:17 -0700537 * it might be useful to support only bitmap drawing on the device
Simon Glassb3a72b32016-01-14 18:10:48 -0700538 * for boards that don't need to display text. We create a TrueType
539 * console if enabled, a rotated console if the video driver requests
540 * it, otherwise a normal console.
541 *
542 * The console can be override by setting vidconsole_drv_name before
543 * probing this video driver, or in the probe() method.
544 *
545 * TrueType does not support rotation at present so fall back to the
546 * rotated console in that case.
Simon Glass84c7fb32016-01-18 19:52:17 -0700547 */
Simon Glassb3a72b32016-01-14 18:10:48 -0700548 if (!priv->rot && IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) {
Simon Glass2ef353e2016-01-14 18:10:42 -0700549 snprintf(name, sizeof(name), "%s.vidconsole_tt", dev->name);
550 strcpy(drv, "vidconsole_tt");
551 } else {
552 snprintf(name, sizeof(name), "%s.vidconsole%d", dev->name,
553 priv->rot);
554 snprintf(drv, sizeof(drv), "vidconsole%d", priv->rot);
555 }
556
Simon Glass84c7fb32016-01-18 19:52:17 -0700557 str = strdup(name);
558 if (!str)
559 return -ENOMEM;
Simon Glassb3a72b32016-01-14 18:10:48 -0700560 if (priv->vidconsole_drv_name)
561 drv_name = priv->vidconsole_drv_name;
562 ret = device_bind_driver(dev, drv_name, str, &cons);
Simon Glass84c7fb32016-01-18 19:52:17 -0700563 if (ret) {
564 debug("%s: Cannot bind console driver\n", __func__);
565 return ret;
566 }
Simon Glassb3a72b32016-01-14 18:10:48 -0700567
Simon Glass84c7fb32016-01-18 19:52:17 -0700568 ret = device_probe(cons);
569 if (ret) {
570 debug("%s: Cannot probe console driver\n", __func__);
571 return ret;
572 }
573
Nikhil M Jain9e3301d2023-04-20 17:41:08 +0530574 if (CONFIG_IS_ENABLED(VIDEO_LOGO) &&
575 !CONFIG_IS_ENABLED(SPLASH_SCREEN) && !plat->hide_logo) {
Simon Glass87a3cd72021-11-19 13:24:03 -0700576 ret = show_splash(dev);
577 if (ret) {
578 log_debug("Cannot show splash screen\n");
579 return ret;
580 }
581 }
582
Simon Glass623d28f2016-01-18 19:52:15 -0700583 return 0;
584};
585
586/* Post-relocation, allocate memory for the frame buffer */
587static int video_post_bind(struct udevice *dev)
588{
Simon Glass951255d2020-07-02 21:12:32 -0600589 struct video_uc_priv *uc_priv;
590 ulong addr;
Simon Glass623d28f2016-01-18 19:52:15 -0700591 ulong size;
592
593 /* Before relocation there is nothing to do here */
Tom Rini6985a722018-04-22 09:47:48 -0400594 if (!(gd->flags & GD_FLG_RELOC))
Simon Glass623d28f2016-01-18 19:52:15 -0700595 return 0;
Simon Glass951255d2020-07-02 21:12:32 -0600596
597 /* Set up the video pointer, if this is the first device */
Simon Glass95588622020-12-22 19:30:28 -0700598 uc_priv = uclass_get_priv(dev->uclass);
Simon Glass951255d2020-07-02 21:12:32 -0600599 if (!uc_priv->video_ptr)
600 uc_priv->video_ptr = gd->video_top;
601
602 /* Allocate framebuffer space for this device */
603 addr = uc_priv->video_ptr;
Simon Glass623d28f2016-01-18 19:52:15 -0700604 size = alloc_fb(dev, &addr);
605 if (addr < gd->video_bottom) {
Simon Glassfc1aa352023-02-13 08:56:34 -0700606 /* Device tree node may need the 'bootph-all' or
607 * 'bootph-some-ram' tag
Patrick Delaunayd1937182019-05-21 19:19:12 +0200608 */
Simon Glass623d28f2016-01-18 19:52:15 -0700609 printf("Video device '%s' cannot allocate frame buffer memory -ensure the device is set up before relocation\n",
610 dev->name);
611 return -ENOSPC;
612 }
613 debug("%s: Claiming %lx bytes at %lx for video device '%s'\n",
614 __func__, size, addr, dev->name);
Simon Glass951255d2020-07-02 21:12:32 -0600615 uc_priv->video_ptr = addr;
Simon Glass623d28f2016-01-18 19:52:15 -0700616
617 return 0;
618}
619
620UCLASS_DRIVER(video) = {
621 .id = UCLASS_VIDEO,
622 .name = "video",
623 .flags = DM_UC_FLAG_SEQ_ALIAS,
624 .post_bind = video_post_bind,
Simon Glass623d28f2016-01-18 19:52:15 -0700625 .post_probe = video_post_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700626 .priv_auto = sizeof(struct video_uc_priv),
627 .per_device_auto = sizeof(struct video_priv),
Simon Glassb75b15b2020-12-03 16:55:23 -0700628 .per_device_plat_auto = sizeof(struct video_uc_plat),
Simon Glass623d28f2016-01-18 19:52:15 -0700629};