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