]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
1acafc73 SG |
2 | /* |
3 | * Copyright (c) 2015 Google, Inc | |
1acafc73 SG |
4 | */ |
5 | ||
b953ec2b PD |
6 | #define LOG_CATEGORY UCLASS_VIDEO |
7 | ||
d678a59d | 8 | #include <common.h> |
5bc610a7 | 9 | #include <bloblist.h> |
9beac5da | 10 | #include <console.h> |
1eb69ae4 | 11 | #include <cpu_func.h> |
1acafc73 | 12 | #include <dm.h> |
f7ae49fc | 13 | #include <log.h> |
336d4615 | 14 | #include <malloc.h> |
1acafc73 | 15 | #include <mapmem.h> |
5bc610a7 | 16 | #include <spl.h> |
1acafc73 SG |
17 | #include <stdio_dev.h> |
18 | #include <video.h> | |
19 | #include <video_console.h> | |
90526e9f | 20 | #include <asm/cache.h> |
401d1c4f | 21 | #include <asm/global_data.h> |
1acafc73 | 22 | #include <dm/lists.h> |
9de731f2 | 23 | #include <dm/device_compat.h> |
1acafc73 SG |
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 | |
8a8d24bd | 34 | * set the @align and @size values in struct video_uc_plat. This |
1acafc73 SG |
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() | |
bd0df823 T |
38 | * method after relocation. Additionally driver can allocate frame buffer |
39 | * itself by setting plat->base. | |
1acafc73 SG |
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 | ||
7812bbdc SG |
56 | /** |
57 | * struct video_uc_priv - Information for the video uclass | |
58 | * | |
59 | * @video_ptr: Current allocation position of the video framebuffer pointer. | |
60 | * While binding devices after relocation, this points to the next | |
61 | * available address to use for a device's framebuffer. It starts at | |
62 | * gd->video_top and works downwards, running out of space when it hits | |
63 | * gd->video_bottom. | |
64 | */ | |
65 | struct video_uc_priv { | |
66 | ulong video_ptr; | |
67 | }; | |
68 | ||
a032e4b5 SG |
69 | /** struct vid_rgb - Describes a video colour */ |
70 | struct vid_rgb { | |
71 | u32 r; | |
72 | u32 g; | |
73 | u32 b; | |
74 | }; | |
75 | ||
68dcdc99 SG |
76 | void video_set_flush_dcache(struct udevice *dev, bool flush) |
77 | { | |
78 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
79 | ||
80 | priv->flush_dcache = flush; | |
81 | } | |
82 | ||
315e3679 SG |
83 | static ulong alloc_fb_(ulong align, ulong size, ulong *addrp) |
84 | { | |
85 | ulong base; | |
86 | ||
87 | align = align ? align : 1 << 20; | |
88 | base = *addrp - size; | |
89 | base &= ~(align - 1); | |
90 | size = *addrp - base; | |
91 | *addrp = base; | |
92 | ||
93 | return size; | |
94 | } | |
95 | ||
1acafc73 SG |
96 | static ulong alloc_fb(struct udevice *dev, ulong *addrp) |
97 | { | |
8a8d24bd | 98 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
315e3679 SG |
99 | ulong size; |
100 | ||
101 | if (!plat->size) { | |
102 | if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_size) { | |
103 | size = alloc_fb_(plat->align, plat->copy_size, addrp); | |
104 | plat->copy_base = *addrp; | |
105 | return size; | |
106 | } | |
1acafc73 | 107 | |
3968398e | 108 | return 0; |
315e3679 | 109 | } |
3968398e | 110 | |
bd0df823 T |
111 | /* Allow drivers to allocate the frame buffer themselves */ |
112 | if (plat->base) | |
113 | return 0; | |
114 | ||
315e3679 SG |
115 | size = alloc_fb_(plat->align, plat->size, addrp); |
116 | plat->base = *addrp; | |
1acafc73 SG |
117 | |
118 | return size; | |
119 | } | |
120 | ||
121 | int video_reserve(ulong *addrp) | |
122 | { | |
123 | struct udevice *dev; | |
124 | ulong size; | |
125 | ||
eefe23c1 DT |
126 | if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && spl_phase() == PHASE_BOARD_F) |
127 | return 0; | |
128 | ||
1acafc73 SG |
129 | gd->video_top = *addrp; |
130 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); | |
131 | dev; | |
132 | uclass_find_next_device(&dev)) { | |
133 | size = alloc_fb(dev, addrp); | |
134 | debug("%s: Reserving %lx bytes at %lx for video device '%s'\n", | |
135 | __func__, size, *addrp, dev->name); | |
136 | } | |
551ca0e6 SG |
137 | |
138 | /* Allocate space for PCI video devices in case there were not bound */ | |
139 | if (*addrp == gd->video_top) | |
86fbee60 | 140 | *addrp -= CONFIG_VAL(VIDEO_PCI_DEFAULT_FB_SIZE); |
551ca0e6 | 141 | |
1acafc73 | 142 | gd->video_bottom = *addrp; |
aef43ea0 | 143 | gd->fb_base = *addrp; |
1acafc73 SG |
144 | debug("Video frame buffers from %lx to %lx\n", gd->video_bottom, |
145 | gd->video_top); | |
146 | ||
147 | return 0; | |
148 | } | |
149 | ||
0ab4f91a SG |
150 | int video_fill_part(struct udevice *dev, int xstart, int ystart, int xend, |
151 | int yend, u32 colour) | |
152 | { | |
153 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
154 | void *start, *line; | |
155 | int pixels = xend - xstart; | |
156 | int row, i, ret; | |
157 | ||
158 | start = priv->fb + ystart * priv->line_length; | |
159 | start += xstart * VNBYTES(priv->bpix); | |
160 | line = start; | |
161 | for (row = ystart; row < yend; row++) { | |
162 | switch (priv->bpix) { | |
163 | case VIDEO_BPP8: { | |
164 | u8 *dst = line; | |
165 | ||
166 | if (IS_ENABLED(CONFIG_VIDEO_BPP8)) { | |
167 | for (i = 0; i < pixels; i++) | |
168 | *dst++ = colour; | |
169 | } | |
170 | break; | |
171 | } | |
172 | case VIDEO_BPP16: { | |
173 | u16 *dst = line; | |
174 | ||
175 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { | |
176 | for (i = 0; i < pixels; i++) | |
177 | *dst++ = colour; | |
178 | } | |
179 | break; | |
180 | } | |
181 | case VIDEO_BPP32: { | |
182 | u32 *dst = line; | |
183 | ||
184 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { | |
185 | for (i = 0; i < pixels; i++) | |
186 | *dst++ = colour; | |
187 | } | |
188 | break; | |
189 | } | |
190 | default: | |
191 | return -ENOSYS; | |
192 | } | |
193 | line += priv->line_length; | |
194 | } | |
195 | ret = video_sync_copy(dev, start, line); | |
196 | if (ret) | |
197 | return ret; | |
198 | ||
199 | return 0; | |
200 | } | |
201 | ||
ccd21ee5 NJ |
202 | int video_reserve_from_bloblist(struct video_handoff *ho) |
203 | { | |
eefe23c1 DT |
204 | if (!ho->fb || ho->size == 0) |
205 | return -ENOENT; | |
206 | ||
ccd21ee5 NJ |
207 | gd->video_bottom = ho->fb; |
208 | gd->fb_base = ho->fb; | |
209 | gd->video_top = ho->fb + ho->size; | |
eefe23c1 DT |
210 | debug("%s: Reserving %lx bytes at %08x as per bloblist received\n", |
211 | __func__, (unsigned long)ho->size, (u32)ho->fb); | |
ccd21ee5 NJ |
212 | |
213 | return 0; | |
214 | } | |
215 | ||
50d562c0 | 216 | int video_fill(struct udevice *dev, u32 colour) |
1acafc73 SG |
217 | { |
218 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
138dfea8 | 219 | int ret; |
1acafc73 | 220 | |
d7a75d3c | 221 | switch (priv->bpix) { |
0c20aafe | 222 | case VIDEO_BPP16: |
86fbee60 | 223 | if (CONFIG_IS_ENABLED(VIDEO_BPP16)) { |
0c20aafe SG |
224 | u16 *ppix = priv->fb; |
225 | u16 *end = priv->fb + priv->fb_size; | |
226 | ||
227 | while (ppix < end) | |
50d562c0 | 228 | *ppix++ = colour; |
0c20aafe SG |
229 | break; |
230 | } | |
231 | case VIDEO_BPP32: | |
86fbee60 | 232 | if (CONFIG_IS_ENABLED(VIDEO_BPP32)) { |
0c20aafe SG |
233 | u32 *ppix = priv->fb; |
234 | u32 *end = priv->fb + priv->fb_size; | |
235 | ||
236 | while (ppix < end) | |
50d562c0 | 237 | *ppix++ = colour; |
0c20aafe SG |
238 | break; |
239 | } | |
d7a75d3c | 240 | default: |
50d562c0 | 241 | memset(priv->fb, colour, priv->fb_size); |
d7a75d3c | 242 | break; |
1acafc73 | 243 | } |
138dfea8 SG |
244 | ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size); |
245 | if (ret) | |
246 | return ret; | |
c6ebd011 | 247 | |
5337663e | 248 | return video_sync(dev, false); |
1acafc73 SG |
249 | } |
250 | ||
50d562c0 SG |
251 | int video_clear(struct udevice *dev) |
252 | { | |
253 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
254 | int ret; | |
255 | ||
256 | ret = video_fill(dev, priv->colour_bg); | |
257 | if (ret) | |
258 | return ret; | |
259 | ||
260 | return 0; | |
261 | } | |
262 | ||
a032e4b5 SG |
263 | static const struct vid_rgb colours[VID_COLOUR_COUNT] = { |
264 | { 0x00, 0x00, 0x00 }, /* black */ | |
265 | { 0xc0, 0x00, 0x00 }, /* red */ | |
266 | { 0x00, 0xc0, 0x00 }, /* green */ | |
267 | { 0xc0, 0x60, 0x00 }, /* brown */ | |
268 | { 0x00, 0x00, 0xc0 }, /* blue */ | |
269 | { 0xc0, 0x00, 0xc0 }, /* magenta */ | |
270 | { 0x00, 0xc0, 0xc0 }, /* cyan */ | |
271 | { 0xc0, 0xc0, 0xc0 }, /* light gray */ | |
272 | { 0x80, 0x80, 0x80 }, /* gray */ | |
273 | { 0xff, 0x00, 0x00 }, /* bright red */ | |
274 | { 0x00, 0xff, 0x00 }, /* bright green */ | |
275 | { 0xff, 0xff, 0x00 }, /* yellow */ | |
276 | { 0x00, 0x00, 0xff }, /* bright blue */ | |
277 | { 0xff, 0x00, 0xff }, /* bright magenta */ | |
278 | { 0x00, 0xff, 0xff }, /* bright cyan */ | |
279 | { 0xff, 0xff, 0xff }, /* white */ | |
280 | }; | |
281 | ||
2d6ee92c | 282 | u32 video_index_to_colour(struct video_priv *priv, enum colour_idx idx) |
a032e4b5 SG |
283 | { |
284 | switch (priv->bpix) { | |
285 | case VIDEO_BPP16: | |
86fbee60 | 286 | if (CONFIG_IS_ENABLED(VIDEO_BPP16)) { |
a032e4b5 SG |
287 | return ((colours[idx].r >> 3) << 11) | |
288 | ((colours[idx].g >> 2) << 5) | | |
289 | ((colours[idx].b >> 3) << 0); | |
290 | } | |
291 | break; | |
292 | case VIDEO_BPP32: | |
86fbee60 | 293 | if (CONFIG_IS_ENABLED(VIDEO_BPP32)) { |
e9500ba9 MS |
294 | switch (priv->format) { |
295 | case VIDEO_X2R10G10B10: | |
a032e4b5 SG |
296 | return (colours[idx].r << 22) | |
297 | (colours[idx].g << 12) | | |
298 | (colours[idx].b << 2); | |
e9500ba9 MS |
299 | case VIDEO_RGBA8888: |
300 | return (colours[idx].r << 24) | | |
301 | (colours[idx].g << 16) | | |
302 | (colours[idx].b << 8) | 0xff; | |
303 | default: | |
a032e4b5 SG |
304 | return (colours[idx].r << 16) | |
305 | (colours[idx].g << 8) | | |
306 | (colours[idx].b << 0); | |
e9500ba9 | 307 | } |
a032e4b5 SG |
308 | } |
309 | break; | |
310 | default: | |
311 | break; | |
312 | } | |
313 | ||
314 | /* | |
315 | * For unknown bit arrangements just support | |
316 | * black and white. | |
317 | */ | |
318 | if (idx) | |
319 | return 0xffffff; /* white */ | |
320 | ||
321 | return 0x000000; /* black */ | |
322 | } | |
323 | ||
b9f210a3 | 324 | void video_set_default_colors(struct udevice *dev, bool invert) |
5c30fbb8 | 325 | { |
b9f210a3 SG |
326 | struct video_priv *priv = dev_get_uclass_priv(dev); |
327 | int fore, back; | |
328 | ||
0c20aafe SG |
329 | if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) { |
330 | /* White is used when switching to bold, use light gray here */ | |
331 | fore = VID_LIGHT_GRAY; | |
332 | back = VID_BLACK; | |
333 | } else { | |
334 | fore = VID_BLACK; | |
335 | back = VID_WHITE; | |
336 | } | |
b9f210a3 SG |
337 | if (invert) { |
338 | int temp; | |
339 | ||
340 | temp = fore; | |
341 | fore = back; | |
342 | back = temp; | |
343 | } | |
344 | priv->fg_col_idx = fore; | |
eabb0725 | 345 | priv->bg_col_idx = back; |
a032e4b5 SG |
346 | priv->colour_fg = video_index_to_colour(priv, fore); |
347 | priv->colour_bg = video_index_to_colour(priv, back); | |
5c30fbb8 HS |
348 | } |
349 | ||
1acafc73 | 350 | /* Flush video activity to the caches */ |
9de731f2 | 351 | int video_sync(struct udevice *vid, bool force) |
1acafc73 | 352 | { |
9d69c2d9 MS |
353 | struct video_ops *ops = video_get_ops(vid); |
354 | int ret; | |
355 | ||
356 | if (ops && ops->video_sync) { | |
357 | ret = ops->video_sync(vid); | |
358 | if (ret) | |
359 | return ret; | |
360 | } | |
361 | ||
1acafc73 SG |
362 | /* |
363 | * flush_dcache_range() is declared in common.h but it seems that some | |
364 | * architectures do not actually implement it. Is there a way to find | |
365 | * out whether it exists? For now, ARM is safe. | |
366 | */ | |
10015025 | 367 | #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
1acafc73 SG |
368 | struct video_priv *priv = dev_get_uclass_priv(vid); |
369 | ||
370 | if (priv->flush_dcache) { | |
371 | flush_dcache_range((ulong)priv->fb, | |
7981394e SG |
372 | ALIGN((ulong)priv->fb + priv->fb_size, |
373 | CONFIG_SYS_CACHELINE_SIZE)); | |
1acafc73 SG |
374 | } |
375 | #elif defined(CONFIG_VIDEO_SANDBOX_SDL) | |
376 | struct video_priv *priv = dev_get_uclass_priv(vid); | |
377 | static ulong last_sync; | |
378 | ||
7c19e4cb | 379 | if (force || get_timer(last_sync) > 100) { |
1acafc73 SG |
380 | sandbox_sdl_sync(priv->fb); |
381 | last_sync = get_timer(0); | |
382 | } | |
383 | #endif | |
9de731f2 | 384 | return 0; |
1acafc73 SG |
385 | } |
386 | ||
387 | void video_sync_all(void) | |
388 | { | |
389 | struct udevice *dev; | |
9de731f2 | 390 | int ret; |
1acafc73 SG |
391 | |
392 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); | |
393 | dev; | |
394 | uclass_find_next_device(&dev)) { | |
9de731f2 MS |
395 | if (device_active(dev)) { |
396 | ret = video_sync(dev, true); | |
397 | if (ret) | |
398 | dev_dbg(dev, "Video sync failed\n"); | |
399 | } | |
1acafc73 SG |
400 | } |
401 | } | |
402 | ||
2e2e6d8c PD |
403 | bool video_is_active(void) |
404 | { | |
405 | struct udevice *dev; | |
406 | ||
4ac7ffb6 DT |
407 | /* Assume video to be active if SPL passed video hand-off to U-boot */ |
408 | if (IS_ENABLED(CONFIG_SPL_VIDEO_HANDOFF) && spl_phase() > PHASE_SPL) | |
409 | return true; | |
410 | ||
2e2e6d8c PD |
411 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
412 | dev; | |
413 | uclass_find_next_device(&dev)) { | |
414 | if (device_active(dev)) | |
415 | return true; | |
416 | } | |
417 | ||
418 | return false; | |
419 | } | |
420 | ||
1acafc73 SG |
421 | int video_get_xsize(struct udevice *dev) |
422 | { | |
423 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
424 | ||
425 | return priv->xsize; | |
426 | } | |
427 | ||
428 | int video_get_ysize(struct udevice *dev) | |
429 | { | |
430 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
431 | ||
432 | return priv->ysize; | |
433 | } | |
434 | ||
9beac5da SG |
435 | #ifdef CONFIG_VIDEO_COPY |
436 | int video_sync_copy(struct udevice *dev, void *from, void *to) | |
437 | { | |
438 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
439 | ||
440 | if (priv->copy_fb) { | |
441 | long offset, size; | |
442 | ||
443 | /* Find the offset of the first byte to copy */ | |
444 | if ((ulong)to > (ulong)from) { | |
445 | size = to - from; | |
446 | offset = from - priv->fb; | |
447 | } else { | |
448 | size = from - to; | |
449 | offset = to - priv->fb; | |
450 | } | |
451 | ||
452 | /* | |
453 | * Allow a bit of leeway for valid requests somewhere near the | |
454 | * frame buffer | |
455 | */ | |
456 | if (offset < -priv->fb_size || offset > 2 * priv->fb_size) { | |
457 | #ifdef DEBUG | |
6a19e938 | 458 | char str[120]; |
9beac5da SG |
459 | |
460 | snprintf(str, sizeof(str), | |
6a19e938 | 461 | "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]", |
9beac5da SG |
462 | priv->fb, from, to, offset); |
463 | console_puts_select_stderr(true, str); | |
464 | #endif | |
465 | return -EFAULT; | |
466 | } | |
467 | ||
468 | /* | |
469 | * Silently crop the memcpy. This allows callers to avoid doing | |
470 | * this themselves. It is common for the end pointer to go a | |
471 | * few lines after the end of the frame buffer, since most of | |
472 | * the update algorithms terminate a line after their last write | |
473 | */ | |
474 | if (offset + size > priv->fb_size) { | |
475 | size = priv->fb_size - offset; | |
476 | } else if (offset < 0) { | |
477 | size += offset; | |
478 | offset = 0; | |
479 | } | |
480 | ||
481 | memcpy(priv->copy_fb + offset, priv->fb + offset, size); | |
482 | } | |
483 | ||
484 | return 0; | |
485 | } | |
7d70116f SG |
486 | |
487 | int video_sync_copy_all(struct udevice *dev) | |
488 | { | |
489 | struct video_priv *priv = dev_get_uclass_priv(dev); | |
490 | ||
491 | video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size); | |
492 | ||
493 | return 0; | |
494 | } | |
495 | ||
9beac5da SG |
496 | #endif |
497 | ||
84e63abf SG |
498 | #define SPLASH_DECL(_name) \ |
499 | extern u8 __splash_ ## _name ## _begin[]; \ | |
500 | extern u8 __splash_ ## _name ## _end[] | |
501 | ||
502 | #define SPLASH_START(_name) __splash_ ## _name ## _begin | |
503 | ||
504 | SPLASH_DECL(u_boot_logo); | |
505 | ||
0d389018 SG |
506 | void *video_get_u_boot_logo(void) |
507 | { | |
508 | return SPLASH_START(u_boot_logo); | |
509 | } | |
510 | ||
84e63abf SG |
511 | static int show_splash(struct udevice *dev) |
512 | { | |
513 | u8 *data = SPLASH_START(u_boot_logo); | |
514 | int ret; | |
515 | ||
516 | ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true); | |
517 | ||
518 | return 0; | |
519 | } | |
520 | ||
c830e285 SG |
521 | int video_default_font_height(struct udevice *dev) |
522 | { | |
523 | struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev); | |
524 | ||
525 | if (IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) | |
526 | return IF_ENABLED_INT(CONFIG_CONSOLE_TRUETYPE, | |
527 | CONFIG_CONSOLE_TRUETYPE_SIZE); | |
528 | ||
529 | return vc_priv->y_charsize; | |
530 | } | |
531 | ||
1acafc73 SG |
532 | /* Set up the display ready for use */ |
533 | static int video_post_probe(struct udevice *dev) | |
534 | { | |
8a8d24bd | 535 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
1acafc73 SG |
536 | struct video_priv *priv = dev_get_uclass_priv(dev); |
537 | char name[30], drv[15], *str; | |
826f35f9 | 538 | const char *drv_name = drv; |
1acafc73 SG |
539 | struct udevice *cons; |
540 | int ret; | |
541 | ||
542 | /* Set up the line and display size */ | |
543 | priv->fb = map_sysmem(plat->base, plat->size); | |
06696ebe SG |
544 | if (!priv->line_length) |
545 | priv->line_length = priv->xsize * VNBYTES(priv->bpix); | |
546 | ||
1acafc73 SG |
547 | priv->fb_size = priv->line_length * priv->ysize; |
548 | ||
b30414f0 DT |
549 | /* |
550 | * Set up video handoff fields for passing video blob to next stage | |
551 | * NOTE: | |
552 | * This assumes that reserved video memory only uses a single framebuffer | |
553 | */ | |
554 | if (spl_phase() == PHASE_SPL && CONFIG_IS_ENABLED(BLOBLIST)) { | |
555 | struct video_handoff *ho; | |
556 | ||
557 | ho = bloblist_add(BLOBLISTT_U_BOOT_VIDEO, sizeof(*ho), 0); | |
558 | if (!ho) | |
559 | return log_msg_ret("blf", -ENOENT); | |
560 | ho->fb = gd->video_bottom; | |
561 | /* Fill aligned size here as calculated in video_reserve() */ | |
562 | ho->size = gd->video_top - gd->video_bottom; | |
563 | ho->xsize = priv->xsize; | |
564 | ho->ysize = priv->ysize; | |
565 | ho->line_length = priv->line_length; | |
566 | ho->bpix = priv->bpix; | |
567 | } | |
568 | ||
6efa809d SG |
569 | if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_base) |
570 | priv->copy_fb = map_sysmem(plat->copy_base, plat->size); | |
571 | ||
5c30fbb8 | 572 | /* Set up colors */ |
b9f210a3 | 573 | video_set_default_colors(dev, false); |
8ef05352 RC |
574 | |
575 | if (!CONFIG_IS_ENABLED(NO_FB_CLEAR)) | |
576 | video_clear(dev); | |
1acafc73 | 577 | |
83510766 | 578 | /* |
826f35f9 | 579 | * Create a text console device. For now we always do this, although |
83510766 | 580 | * it might be useful to support only bitmap drawing on the device |
826f35f9 SG |
581 | * for boards that don't need to display text. We create a TrueType |
582 | * console if enabled, a rotated console if the video driver requests | |
583 | * it, otherwise a normal console. | |
584 | * | |
585 | * The console can be override by setting vidconsole_drv_name before | |
586 | * probing this video driver, or in the probe() method. | |
587 | * | |
588 | * TrueType does not support rotation at present so fall back to the | |
589 | * rotated console in that case. | |
83510766 | 590 | */ |
826f35f9 | 591 | if (!priv->rot && IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) { |
a29b0120 SG |
592 | snprintf(name, sizeof(name), "%s.vidconsole_tt", dev->name); |
593 | strcpy(drv, "vidconsole_tt"); | |
594 | } else { | |
595 | snprintf(name, sizeof(name), "%s.vidconsole%d", dev->name, | |
596 | priv->rot); | |
597 | snprintf(drv, sizeof(drv), "vidconsole%d", priv->rot); | |
598 | } | |
599 | ||
83510766 SG |
600 | str = strdup(name); |
601 | if (!str) | |
602 | return -ENOMEM; | |
826f35f9 SG |
603 | if (priv->vidconsole_drv_name) |
604 | drv_name = priv->vidconsole_drv_name; | |
605 | ret = device_bind_driver(dev, drv_name, str, &cons); | |
83510766 SG |
606 | if (ret) { |
607 | debug("%s: Cannot bind console driver\n", __func__); | |
608 | return ret; | |
609 | } | |
826f35f9 | 610 | |
83510766 SG |
611 | ret = device_probe(cons); |
612 | if (ret) { | |
613 | debug("%s: Cannot probe console driver\n", __func__); | |
614 | return ret; | |
615 | } | |
616 | ||
86fbee60 NJ |
617 | if (CONFIG_IS_ENABLED(VIDEO_LOGO) && |
618 | !CONFIG_IS_ENABLED(SPLASH_SCREEN) && !plat->hide_logo) { | |
84e63abf SG |
619 | ret = show_splash(dev); |
620 | if (ret) { | |
621 | log_debug("Cannot show splash screen\n"); | |
622 | return ret; | |
623 | } | |
624 | } | |
625 | ||
1acafc73 SG |
626 | return 0; |
627 | }; | |
628 | ||
629 | /* Post-relocation, allocate memory for the frame buffer */ | |
630 | static int video_post_bind(struct udevice *dev) | |
631 | { | |
7812bbdc SG |
632 | struct video_uc_priv *uc_priv; |
633 | ulong addr; | |
1acafc73 SG |
634 | ulong size; |
635 | ||
636 | /* Before relocation there is nothing to do here */ | |
75164181 | 637 | if (!(gd->flags & GD_FLG_RELOC)) |
1acafc73 | 638 | return 0; |
7812bbdc SG |
639 | |
640 | /* Set up the video pointer, if this is the first device */ | |
0fd3d911 | 641 | uc_priv = uclass_get_priv(dev->uclass); |
7812bbdc SG |
642 | if (!uc_priv->video_ptr) |
643 | uc_priv->video_ptr = gd->video_top; | |
644 | ||
645 | /* Allocate framebuffer space for this device */ | |
646 | addr = uc_priv->video_ptr; | |
1acafc73 SG |
647 | size = alloc_fb(dev, &addr); |
648 | if (addr < gd->video_bottom) { | |
08ece5b3 BM |
649 | /* |
650 | * Device tree node may need the 'bootph-all' or | |
e316fbab | 651 | * 'bootph-some-ram' tag |
69989749 | 652 | */ |
08ece5b3 BM |
653 | printf("Video device '%s' cannot allocate frame buffer memory " |
654 | "- ensure the device is set up before relocation\n", | |
1acafc73 SG |
655 | dev->name); |
656 | return -ENOSPC; | |
657 | } | |
658 | debug("%s: Claiming %lx bytes at %lx for video device '%s'\n", | |
659 | __func__, size, addr, dev->name); | |
7812bbdc | 660 | uc_priv->video_ptr = addr; |
1acafc73 SG |
661 | |
662 | return 0; | |
663 | } | |
664 | ||
665 | UCLASS_DRIVER(video) = { | |
666 | .id = UCLASS_VIDEO, | |
667 | .name = "video", | |
668 | .flags = DM_UC_FLAG_SEQ_ALIAS, | |
669 | .post_bind = video_post_bind, | |
1acafc73 | 670 | .post_probe = video_post_probe, |
41575d8e SG |
671 | .priv_auto = sizeof(struct video_uc_priv), |
672 | .per_device_auto = sizeof(struct video_priv), | |
8a8d24bd | 673 | .per_device_plat_auto = sizeof(struct video_uc_plat), |
1acafc73 | 674 | }; |