Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2015 Google, Inc |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | b953ec2 | 2021-04-27 11:02:19 +0200 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_VIDEO |
| 7 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 8 | #include <common.h> |
Simon Glass | 9beac5d | 2020-07-02 21:12:20 -0600 | [diff] [blame] | 9 | #include <console.h> |
Simon Glass | 1eb69ae | 2019-11-14 12:57:39 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 11 | #include <dm.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 13 | #include <malloc.h> |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 14 | #include <mapmem.h> |
| 15 | #include <stdio_dev.h> |
| 16 | #include <video.h> |
| 17 | #include <video_console.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 18 | #include <asm/cache.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 20 | #include <dm/lists.h> |
Michal Simek | 9de731f | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 21 | #include <dm/device_compat.h> |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 22 | #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 Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 32 | * set the @align and @size values in struct video_uc_plat. This |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 33 | * 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ár | bd0df82 | 2022-03-09 20:46:00 +0100 | [diff] [blame] | 36 | * method after relocation. Additionally driver can allocate frame buffer |
| 37 | * itself by setting plat->base. |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 38 | * |
| 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 | */ |
| 52 | DECLARE_GLOBAL_DATA_PTR; |
| 53 | |
Simon Glass | 7812bbd | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 54 | /** |
| 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 | */ |
| 63 | struct video_uc_priv { |
| 64 | ulong video_ptr; |
| 65 | }; |
| 66 | |
Simon Glass | 68dcdc9 | 2016-01-21 19:44:52 -0700 | [diff] [blame] | 67 | void video_set_flush_dcache(struct udevice *dev, bool flush) |
| 68 | { |
| 69 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 70 | |
| 71 | priv->flush_dcache = flush; |
| 72 | } |
| 73 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 74 | static ulong alloc_fb(struct udevice *dev, ulong *addrp) |
| 75 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 76 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 77 | ulong base, align, size; |
| 78 | |
Bin Meng | 3968398 | 2016-10-09 04:14:17 -0700 | [diff] [blame] | 79 | if (!plat->size) |
| 80 | return 0; |
| 81 | |
Pali Rohár | bd0df82 | 2022-03-09 20:46:00 +0100 | [diff] [blame] | 82 | /* Allow drivers to allocate the frame buffer themselves */ |
| 83 | if (plat->base) |
| 84 | return 0; |
| 85 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 86 | align = plat->align ? plat->align : 1 << 20; |
| 87 | base = *addrp - plat->size; |
| 88 | base &= ~(align - 1); |
| 89 | plat->base = base; |
| 90 | size = *addrp - base; |
| 91 | *addrp = base; |
| 92 | |
| 93 | return size; |
| 94 | } |
| 95 | |
| 96 | int video_reserve(ulong *addrp) |
| 97 | { |
| 98 | struct udevice *dev; |
| 99 | ulong size; |
| 100 | |
| 101 | gd->video_top = *addrp; |
| 102 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 103 | dev; |
| 104 | uclass_find_next_device(&dev)) { |
| 105 | size = alloc_fb(dev, addrp); |
| 106 | debug("%s: Reserving %lx bytes at %lx for video device '%s'\n", |
| 107 | __func__, size, *addrp, dev->name); |
| 108 | } |
Simon Glass | 551ca0e | 2020-07-02 21:12:33 -0600 | [diff] [blame] | 109 | |
| 110 | /* Allocate space for PCI video devices in case there were not bound */ |
| 111 | if (*addrp == gd->video_top) |
| 112 | *addrp -= CONFIG_VIDEO_PCI_DEFAULT_FB_SIZE; |
| 113 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 114 | gd->video_bottom = *addrp; |
Simon Glass | aef43ea | 2020-05-10 14:17:01 -0600 | [diff] [blame] | 115 | gd->fb_base = *addrp; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 116 | debug("Video frame buffers from %lx to %lx\n", gd->video_bottom, |
| 117 | gd->video_top); |
| 118 | |
| 119 | return 0; |
| 120 | } |
| 121 | |
Simon Glass | c6ebd01 | 2018-10-01 12:22:26 -0600 | [diff] [blame] | 122 | int video_clear(struct udevice *dev) |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 123 | { |
| 124 | struct video_priv *priv = dev_get_uclass_priv(dev); |
Simon Glass | 138dfea | 2020-07-02 21:12:22 -0600 | [diff] [blame] | 125 | int ret; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 126 | |
Heinrich Schuchardt | d7a75d3 | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 127 | switch (priv->bpix) { |
Simon Glass | 0c20aaf | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 128 | case VIDEO_BPP16: |
| 129 | if (IS_ENABLED(CONFIG_VIDEO_BPP16)) { |
| 130 | u16 *ppix = priv->fb; |
| 131 | u16 *end = priv->fb + priv->fb_size; |
Heinrich Schuchardt | d7a75d3 | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 132 | |
Simon Glass | 0c20aaf | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 133 | while (ppix < end) |
| 134 | *ppix++ = priv->colour_bg; |
| 135 | break; |
| 136 | } |
| 137 | case VIDEO_BPP32: |
| 138 | if (IS_ENABLED(CONFIG_VIDEO_BPP32)) { |
| 139 | u32 *ppix = priv->fb; |
| 140 | u32 *end = priv->fb + priv->fb_size; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 141 | |
Simon Glass | 0c20aaf | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 142 | while (ppix < end) |
| 143 | *ppix++ = priv->colour_bg; |
| 144 | break; |
| 145 | } |
Heinrich Schuchardt | d7a75d3 | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 146 | default: |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 147 | memset(priv->fb, priv->colour_bg, priv->fb_size); |
Heinrich Schuchardt | d7a75d3 | 2018-02-08 21:47:10 +0100 | [diff] [blame] | 148 | break; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 149 | } |
Simon Glass | 138dfea | 2020-07-02 21:12:22 -0600 | [diff] [blame] | 150 | ret = video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size); |
| 151 | if (ret) |
| 152 | return ret; |
Simon Glass | c6ebd01 | 2018-10-01 12:22:26 -0600 | [diff] [blame] | 153 | |
Michal Simek | 5337663 | 2020-12-15 15:12:09 +0100 | [diff] [blame] | 154 | return video_sync(dev, false); |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Simon Glass | b9f210a | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 157 | void video_set_default_colors(struct udevice *dev, bool invert) |
Heinrich Schuchardt | 5c30fbb | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 158 | { |
Simon Glass | b9f210a | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 159 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 160 | int fore, back; |
| 161 | |
Simon Glass | 0c20aaf | 2019-12-20 18:10:37 -0700 | [diff] [blame] | 162 | if (CONFIG_IS_ENABLED(SYS_WHITE_ON_BLACK)) { |
| 163 | /* White is used when switching to bold, use light gray here */ |
| 164 | fore = VID_LIGHT_GRAY; |
| 165 | back = VID_BLACK; |
| 166 | } else { |
| 167 | fore = VID_BLACK; |
| 168 | back = VID_WHITE; |
| 169 | } |
Simon Glass | b9f210a | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 170 | if (invert) { |
| 171 | int temp; |
| 172 | |
| 173 | temp = fore; |
| 174 | fore = back; |
| 175 | back = temp; |
| 176 | } |
| 177 | priv->fg_col_idx = fore; |
Andre Przywara | eabb072 | 2019-03-23 01:29:56 +0000 | [diff] [blame] | 178 | priv->bg_col_idx = back; |
Simon Glass | b9f210a | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 179 | priv->colour_fg = vid_console_color(priv, fore); |
| 180 | priv->colour_bg = vid_console_color(priv, back); |
Heinrich Schuchardt | 5c30fbb | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 183 | /* Flush video activity to the caches */ |
Michal Simek | 9de731f | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 184 | int video_sync(struct udevice *vid, bool force) |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 185 | { |
Michal Simek | 9d69c2d | 2020-12-03 09:30:00 +0100 | [diff] [blame] | 186 | struct video_ops *ops = video_get_ops(vid); |
| 187 | int ret; |
| 188 | |
| 189 | if (ops && ops->video_sync) { |
| 190 | ret = ops->video_sync(vid); |
| 191 | if (ret) |
| 192 | return ret; |
| 193 | } |
| 194 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 195 | /* |
| 196 | * flush_dcache_range() is declared in common.h but it seems that some |
| 197 | * architectures do not actually implement it. Is there a way to find |
| 198 | * out whether it exists? For now, ARM is safe. |
| 199 | */ |
Trevor Woerner | 1001502 | 2019-05-03 09:41:00 -0400 | [diff] [blame] | 200 | #if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 201 | struct video_priv *priv = dev_get_uclass_priv(vid); |
| 202 | |
| 203 | if (priv->flush_dcache) { |
| 204 | flush_dcache_range((ulong)priv->fb, |
Simon Glass | 7981394 | 2016-11-13 14:22:06 -0700 | [diff] [blame] | 205 | ALIGN((ulong)priv->fb + priv->fb_size, |
| 206 | CONFIG_SYS_CACHELINE_SIZE)); |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 207 | } |
| 208 | #elif defined(CONFIG_VIDEO_SANDBOX_SDL) |
| 209 | struct video_priv *priv = dev_get_uclass_priv(vid); |
| 210 | static ulong last_sync; |
| 211 | |
Simon Glass | 7c19e4c | 2022-02-28 15:13:48 -0700 | [diff] [blame] | 212 | if (force || get_timer(last_sync) > 100) { |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 213 | sandbox_sdl_sync(priv->fb); |
| 214 | last_sync = get_timer(0); |
| 215 | } |
| 216 | #endif |
Michal Simek | 9de731f | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 217 | return 0; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | void video_sync_all(void) |
| 221 | { |
| 222 | struct udevice *dev; |
Michal Simek | 9de731f | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 223 | int ret; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 224 | |
| 225 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 226 | dev; |
| 227 | uclass_find_next_device(&dev)) { |
Michal Simek | 9de731f | 2020-12-14 08:47:52 +0100 | [diff] [blame] | 228 | if (device_active(dev)) { |
| 229 | ret = video_sync(dev, true); |
| 230 | if (ret) |
| 231 | dev_dbg(dev, "Video sync failed\n"); |
| 232 | } |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
Patrick Delaunay | 2e2e6d8 | 2021-11-15 16:32:20 +0100 | [diff] [blame] | 236 | bool video_is_active(void) |
| 237 | { |
| 238 | struct udevice *dev; |
| 239 | |
| 240 | for (uclass_find_first_device(UCLASS_VIDEO, &dev); |
| 241 | dev; |
| 242 | uclass_find_next_device(&dev)) { |
| 243 | if (device_active(dev)) |
| 244 | return true; |
| 245 | } |
| 246 | |
| 247 | return false; |
| 248 | } |
| 249 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 250 | int video_get_xsize(struct udevice *dev) |
| 251 | { |
| 252 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 253 | |
| 254 | return priv->xsize; |
| 255 | } |
| 256 | |
| 257 | int video_get_ysize(struct udevice *dev) |
| 258 | { |
| 259 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 260 | |
| 261 | return priv->ysize; |
| 262 | } |
| 263 | |
Simon Glass | 9beac5d | 2020-07-02 21:12:20 -0600 | [diff] [blame] | 264 | #ifdef CONFIG_VIDEO_COPY |
| 265 | int video_sync_copy(struct udevice *dev, void *from, void *to) |
| 266 | { |
| 267 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 268 | |
| 269 | if (priv->copy_fb) { |
| 270 | long offset, size; |
| 271 | |
| 272 | /* Find the offset of the first byte to copy */ |
| 273 | if ((ulong)to > (ulong)from) { |
| 274 | size = to - from; |
| 275 | offset = from - priv->fb; |
| 276 | } else { |
| 277 | size = from - to; |
| 278 | offset = to - priv->fb; |
| 279 | } |
| 280 | |
| 281 | /* |
| 282 | * Allow a bit of leeway for valid requests somewhere near the |
| 283 | * frame buffer |
| 284 | */ |
| 285 | if (offset < -priv->fb_size || offset > 2 * priv->fb_size) { |
| 286 | #ifdef DEBUG |
Simon Glass | 6a19e93 | 2021-11-19 13:23:51 -0700 | [diff] [blame] | 287 | char str[120]; |
Simon Glass | 9beac5d | 2020-07-02 21:12:20 -0600 | [diff] [blame] | 288 | |
| 289 | snprintf(str, sizeof(str), |
Simon Glass | 6a19e93 | 2021-11-19 13:23:51 -0700 | [diff] [blame] | 290 | "[** FAULT sync_copy fb=%p, from=%p, to=%p, offset=%lx]", |
Simon Glass | 9beac5d | 2020-07-02 21:12:20 -0600 | [diff] [blame] | 291 | priv->fb, from, to, offset); |
| 292 | console_puts_select_stderr(true, str); |
| 293 | #endif |
| 294 | return -EFAULT; |
| 295 | } |
| 296 | |
| 297 | /* |
| 298 | * Silently crop the memcpy. This allows callers to avoid doing |
| 299 | * this themselves. It is common for the end pointer to go a |
| 300 | * few lines after the end of the frame buffer, since most of |
| 301 | * the update algorithms terminate a line after their last write |
| 302 | */ |
| 303 | if (offset + size > priv->fb_size) { |
| 304 | size = priv->fb_size - offset; |
| 305 | } else if (offset < 0) { |
| 306 | size += offset; |
| 307 | offset = 0; |
| 308 | } |
| 309 | |
| 310 | memcpy(priv->copy_fb + offset, priv->fb + offset, size); |
| 311 | } |
| 312 | |
| 313 | return 0; |
| 314 | } |
Simon Glass | 7d70116 | 2021-01-13 20:29:46 -0700 | [diff] [blame] | 315 | |
| 316 | int video_sync_copy_all(struct udevice *dev) |
| 317 | { |
| 318 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 319 | |
| 320 | video_sync_copy(dev, priv->fb, priv->fb + priv->fb_size); |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
Simon Glass | 9beac5d | 2020-07-02 21:12:20 -0600 | [diff] [blame] | 325 | #endif |
| 326 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 327 | #define SPLASH_DECL(_name) \ |
| 328 | extern u8 __splash_ ## _name ## _begin[]; \ |
| 329 | extern u8 __splash_ ## _name ## _end[] |
| 330 | |
| 331 | #define SPLASH_START(_name) __splash_ ## _name ## _begin |
| 332 | |
| 333 | SPLASH_DECL(u_boot_logo); |
| 334 | |
| 335 | static int show_splash(struct udevice *dev) |
| 336 | { |
| 337 | u8 *data = SPLASH_START(u_boot_logo); |
| 338 | int ret; |
| 339 | |
| 340 | ret = video_bmp_display(dev, map_to_sysmem(data), -4, 4, true); |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 345 | /* Set up the display ready for use */ |
| 346 | static int video_post_probe(struct udevice *dev) |
| 347 | { |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 348 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 349 | struct video_priv *priv = dev_get_uclass_priv(dev); |
| 350 | char name[30], drv[15], *str; |
Simon Glass | 826f35f | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 351 | const char *drv_name = drv; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 352 | struct udevice *cons; |
| 353 | int ret; |
| 354 | |
| 355 | /* Set up the line and display size */ |
| 356 | priv->fb = map_sysmem(plat->base, plat->size); |
Simon Glass | 06696eb | 2018-11-29 15:08:52 -0700 | [diff] [blame] | 357 | if (!priv->line_length) |
| 358 | priv->line_length = priv->xsize * VNBYTES(priv->bpix); |
| 359 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 360 | priv->fb_size = priv->line_length * priv->ysize; |
| 361 | |
Simon Glass | 6efa809 | 2020-07-02 21:12:21 -0600 | [diff] [blame] | 362 | if (IS_ENABLED(CONFIG_VIDEO_COPY) && plat->copy_base) |
| 363 | priv->copy_fb = map_sysmem(plat->copy_base, plat->size); |
| 364 | |
Heinrich Schuchardt | 5c30fbb | 2018-02-08 21:47:11 +0100 | [diff] [blame] | 365 | /* Set up colors */ |
Simon Glass | b9f210a | 2018-11-06 15:21:36 -0700 | [diff] [blame] | 366 | video_set_default_colors(dev, false); |
Rob Clark | 8ef0535 | 2017-08-03 12:47:01 -0400 | [diff] [blame] | 367 | |
| 368 | if (!CONFIG_IS_ENABLED(NO_FB_CLEAR)) |
| 369 | video_clear(dev); |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 370 | |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 371 | /* |
Simon Glass | 826f35f | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 372 | * Create a text console device. For now we always do this, although |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 373 | * it might be useful to support only bitmap drawing on the device |
Simon Glass | 826f35f | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 374 | * for boards that don't need to display text. We create a TrueType |
| 375 | * console if enabled, a rotated console if the video driver requests |
| 376 | * it, otherwise a normal console. |
| 377 | * |
| 378 | * The console can be override by setting vidconsole_drv_name before |
| 379 | * probing this video driver, or in the probe() method. |
| 380 | * |
| 381 | * TrueType does not support rotation at present so fall back to the |
| 382 | * rotated console in that case. |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 383 | */ |
Simon Glass | 826f35f | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 384 | if (!priv->rot && IS_ENABLED(CONFIG_CONSOLE_TRUETYPE)) { |
Simon Glass | a29b012 | 2016-01-14 18:10:42 -0700 | [diff] [blame] | 385 | snprintf(name, sizeof(name), "%s.vidconsole_tt", dev->name); |
| 386 | strcpy(drv, "vidconsole_tt"); |
| 387 | } else { |
| 388 | snprintf(name, sizeof(name), "%s.vidconsole%d", dev->name, |
| 389 | priv->rot); |
| 390 | snprintf(drv, sizeof(drv), "vidconsole%d", priv->rot); |
| 391 | } |
| 392 | |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 393 | str = strdup(name); |
| 394 | if (!str) |
| 395 | return -ENOMEM; |
Simon Glass | 826f35f | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 396 | if (priv->vidconsole_drv_name) |
| 397 | drv_name = priv->vidconsole_drv_name; |
| 398 | ret = device_bind_driver(dev, drv_name, str, &cons); |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 399 | if (ret) { |
| 400 | debug("%s: Cannot bind console driver\n", __func__); |
| 401 | return ret; |
| 402 | } |
Simon Glass | 826f35f | 2016-01-14 18:10:48 -0700 | [diff] [blame] | 403 | |
Simon Glass | 8351076 | 2016-01-18 19:52:17 -0700 | [diff] [blame] | 404 | ret = device_probe(cons); |
| 405 | if (ret) { |
| 406 | debug("%s: Cannot probe console driver\n", __func__); |
| 407 | return ret; |
| 408 | } |
| 409 | |
Simon Glass | 84e63ab | 2021-11-19 13:24:03 -0700 | [diff] [blame] | 410 | if (IS_ENABLED(CONFIG_VIDEO_LOGO) && !plat->hide_logo) { |
| 411 | ret = show_splash(dev); |
| 412 | if (ret) { |
| 413 | log_debug("Cannot show splash screen\n"); |
| 414 | return ret; |
| 415 | } |
| 416 | } |
| 417 | |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 418 | return 0; |
| 419 | }; |
| 420 | |
| 421 | /* Post-relocation, allocate memory for the frame buffer */ |
| 422 | static int video_post_bind(struct udevice *dev) |
| 423 | { |
Simon Glass | 7812bbd | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 424 | struct video_uc_priv *uc_priv; |
| 425 | ulong addr; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 426 | ulong size; |
| 427 | |
| 428 | /* Before relocation there is nothing to do here */ |
Tom Rini | 7516418 | 2018-04-22 09:47:48 -0400 | [diff] [blame] | 429 | if (!(gd->flags & GD_FLG_RELOC)) |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 430 | return 0; |
Simon Glass | 7812bbd | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 431 | |
| 432 | /* Set up the video pointer, if this is the first device */ |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 433 | uc_priv = uclass_get_priv(dev->uclass); |
Simon Glass | 7812bbd | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 434 | if (!uc_priv->video_ptr) |
| 435 | uc_priv->video_ptr = gd->video_top; |
| 436 | |
| 437 | /* Allocate framebuffer space for this device */ |
| 438 | addr = uc_priv->video_ptr; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 439 | size = alloc_fb(dev, &addr); |
| 440 | if (addr < gd->video_bottom) { |
Patrick Delaunay | 6998974 | 2019-05-21 19:19:12 +0200 | [diff] [blame] | 441 | /* Device tree node may need the 'u-boot,dm-pre-reloc' or |
| 442 | * 'u-boot,dm-pre-proper' tag |
| 443 | */ |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 444 | printf("Video device '%s' cannot allocate frame buffer memory -ensure the device is set up before relocation\n", |
| 445 | dev->name); |
| 446 | return -ENOSPC; |
| 447 | } |
| 448 | debug("%s: Claiming %lx bytes at %lx for video device '%s'\n", |
| 449 | __func__, size, addr, dev->name); |
Simon Glass | 7812bbd | 2020-07-02 21:12:32 -0600 | [diff] [blame] | 450 | uc_priv->video_ptr = addr; |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | UCLASS_DRIVER(video) = { |
| 456 | .id = UCLASS_VIDEO, |
| 457 | .name = "video", |
| 458 | .flags = DM_UC_FLAG_SEQ_ALIAS, |
| 459 | .post_bind = video_post_bind, |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 460 | .post_probe = video_post_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 461 | .priv_auto = sizeof(struct video_uc_priv), |
| 462 | .per_device_auto = sizeof(struct video_priv), |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 463 | .per_device_plat_auto = sizeof(struct video_uc_plat), |
Simon Glass | 1acafc7 | 2016-01-18 19:52:15 -0700 | [diff] [blame] | 464 | }; |