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