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