1 From 4dcb742bde0e0d11386035d9069ca23e6abc28af Mon Sep 17 00:00:00 2001
2 From: James Hughes <james.hughes@raspberrypi.org>
3 Date: Thu, 14 Mar 2019 13:27:54 +0000
4 Subject: [PATCH] Pulled in the multi frame buffer support from the Pi3
8 drivers/video/fbdev/bcm2708_fb.c | 467 +++++++++++++++------
9 include/soc/bcm2835/raspberrypi-firmware.h | 13 +
10 2 files changed, 343 insertions(+), 137 deletions(-)
12 --- a/drivers/video/fbdev/bcm2708_fb.c
13 +++ b/drivers/video/fbdev/bcm2708_fb.c
15 * linux/drivers/video/bcm2708_fb.c
17 * Copyright (C) 2010 Broadcom
18 + * Copyright (C) 2018 Raspberry Pi (Trading) Ltd
20 * This file is subject to the terms and conditions of the GNU General Public
21 * License. See the file COPYING in the main directory of this archive
23 * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/errno.h>
32 #include <linux/dma-mapping.h>
33 #include <soc/bcm2835/raspberrypi-firmware.h>
34 +#include <linux/mutex.h>
36 //#define BCM2708_FB_DEBUG
37 #define MODULE_NAME "bcm2708_fb"
38 @@ -79,65 +82,139 @@ struct bcm2708_fb_stats {
42 +struct vc4_display_settings_t {
50 + u32 virtual_width_offset;
51 + u32 virtual_height_offset;
52 + unsigned long fb_bus_address;
55 +struct bcm2708_fb_dev;
59 struct platform_device *dev;
60 - struct rpi_firmware *fw;
65 - void __iomem *dma_chan_base;
66 - void *cb_base; /* DMA control blocks */
67 - dma_addr_t cb_handle;
68 struct dentry *debugfs_dir;
69 - wait_queue_head_t dma_waitq;
70 - struct bcm2708_fb_stats stats;
71 + struct dentry *debugfs_subdir;
72 unsigned long fb_bus_address;
73 - bool disable_arm_alloc;
74 + struct { u32 base, length; } gpu;
75 + struct vc4_display_settings_t display_settings;
76 + struct debugfs_regset32 screeninfo_regset;
77 + struct bcm2708_fb_dev *fbdev;
78 unsigned int image_size;
83 +#define MAX_FRAMEBUFFERS 3
85 +struct bcm2708_fb_dev {
86 + int firmware_supports_multifb;
87 + /* Protects the DMA system from multiple FB access */
88 + struct mutex dma_mutex;
91 + void __iomem *dma_chan_base;
92 + wait_queue_head_t dma_waitq;
93 + bool disable_arm_alloc;
94 + struct bcm2708_fb_stats dma_stats;
95 + void *cb_base; /* DMA control blocks */
96 + dma_addr_t cb_handle;
99 + struct rpi_firmware *fw;
100 + struct bcm2708_fb displays[MAX_FRAMEBUFFERS];
103 #define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
105 static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
107 - debugfs_remove_recursive(fb->debugfs_dir);
108 - fb->debugfs_dir = NULL;
109 + debugfs_remove_recursive(fb->debugfs_subdir);
110 + fb->debugfs_subdir = NULL;
112 + fb->fbdev->instance_count--;
114 + if (!fb->fbdev->instance_count) {
115 + debugfs_remove_recursive(fb->debugfs_dir);
116 + fb->debugfs_dir = NULL;
120 static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
123 + struct bcm2708_fb_dev *fbdev = fb->fbdev;
125 static struct debugfs_reg32 stats_registers[] = {
128 - offsetof(struct bcm2708_fb_stats, dma_copies)
132 - offsetof(struct bcm2708_fb_stats, dma_irqs)
134 + {"dma_copies", offsetof(struct bcm2708_fb_stats, dma_copies)},
135 + {"dma_irqs", offsetof(struct bcm2708_fb_stats, dma_irqs)},
138 + static struct debugfs_reg32 screeninfo[] = {
139 + {"width", offsetof(struct fb_var_screeninfo, xres)},
140 + {"height", offsetof(struct fb_var_screeninfo, yres)},
141 + {"bpp", offsetof(struct fb_var_screeninfo, bits_per_pixel)},
142 + {"xres_virtual", offsetof(struct fb_var_screeninfo, xres_virtual)},
143 + {"yres_virtual", offsetof(struct fb_var_screeninfo, yres_virtual)},
144 + {"xoffset", offsetof(struct fb_var_screeninfo, xoffset)},
145 + {"yoffset", offsetof(struct fb_var_screeninfo, yoffset)},
148 - fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
149 + fb->debugfs_dir = debugfs_lookup(DRIVER_NAME, NULL);
151 + if (!fb->debugfs_dir)
152 + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
154 if (!fb->debugfs_dir) {
155 - pr_warn("%s: could not create debugfs entry\n",
157 + dev_warn(fb->fb.dev, "%s: could not create debugfs folder\n",
162 - fb->stats.regset.regs = stats_registers;
163 - fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
164 - fb->stats.regset.base = &fb->stats;
166 - if (!debugfs_create_regset32("stats", 0444, fb->debugfs_dir,
167 - &fb->stats.regset)) {
168 - pr_warn("%s: could not create statistics registers\n",
170 + snprintf(buf, sizeof(buf), "%u", fb->display_settings.display_num);
172 + fb->debugfs_subdir = debugfs_create_dir(buf, fb->debugfs_dir);
174 + if (!fb->debugfs_subdir) {
175 + dev_warn(fb->fb.dev, "%s: could not create debugfs entry %u\n",
176 + __func__, fb->display_settings.display_num);
180 + fbdev->dma_stats.regset.regs = stats_registers;
181 + fbdev->dma_stats.regset.nregs = ARRAY_SIZE(stats_registers);
182 + fbdev->dma_stats.regset.base = &fbdev->dma_stats;
184 + if (!debugfs_create_regset32("dma_stats", 0444, fb->debugfs_subdir,
185 + &fbdev->dma_stats.regset)) {
186 + dev_warn(fb->fb.dev, "%s: could not create statistics registers\n",
191 + fb->screeninfo_regset.regs = screeninfo;
192 + fb->screeninfo_regset.nregs = ARRAY_SIZE(screeninfo);
193 + fb->screeninfo_regset.base = &fb->fb.var;
195 + if (!debugfs_create_regset32("screeninfo", 0444, fb->debugfs_subdir,
196 + &fb->screeninfo_regset)) {
197 + dev_warn(fb->fb.dev,
198 + "%s: could not create dimensions registers\n",
203 + fbdev->instance_count++;
208 @@ -145,6 +222,20 @@ fail:
212 +static void set_display_num(struct bcm2708_fb *fb)
214 + if (fb && fb->fbdev && fb->fbdev->firmware_supports_multifb) {
215 + u32 tmp = fb->display_settings.display_num;
217 + if (rpi_firmware_property(fb->fbdev->fw,
218 + RPI_FIRMWARE_FRAMEBUFFER_SET_DISPLAY_NUM,
221 + dev_warn_once(fb->fb.dev,
222 + "Set display number call failed. Old GPU firmware?");
226 static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
229 @@ -222,11 +313,11 @@ static int bcm2708_fb_check_var(struct f
230 struct fb_info *info)
232 /* info input, var output */
233 - print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n",
234 + print_debug("%s(%p) %ux%u (%ux%u), %ul, %u\n",
235 __func__, info, info->var.xres, info->var.yres,
236 info->var.xres_virtual, info->var.yres_virtual,
237 - (int)info->screen_size, info->var.bits_per_pixel);
238 - print_debug("%s(%p) %dx%d (%dx%d), %d\n", __func__, var, var->xres,
239 + info->screen_size, info->var.bits_per_pixel);
240 + print_debug("%s(%p) %ux%u (%ux%u), %u\n", __func__, var, var->xres,
241 var->yres, var->xres_virtual, var->yres_virtual,
242 var->bits_per_pixel);
244 @@ -289,17 +380,24 @@ static int bcm2708_fb_set_par(struct fb_
249 - print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n", __func__, info,
250 + print_debug("%s(%p) %dx%d (%dx%d), %d, %d (display %d)\n", __func__,
252 info->var.xres, info->var.yres, info->var.xres_virtual,
253 info->var.yres_virtual, (int)info->screen_size,
254 - info->var.bits_per_pixel);
255 + info->var.bits_per_pixel, value);
257 + /* Need to set the display number to act on first
258 + * Cannot do it in the tag list because on older firmware the call
259 + * will fail and stop the rest of the list being executed.
260 + * We can ignore this call failing as the default at other end is 0
262 + set_display_num(fb);
264 /* Try allocating our own buffer. We can specify all the parameters */
265 image_size = ((info->var.xres * info->var.yres) *
266 info->var.bits_per_pixel) >> 3;
268 - if (!fb->disable_arm_alloc &&
269 + if (!fb->fbdev->disable_arm_alloc &&
270 (image_size != fb->image_size || !fb->dma_addr)) {
272 dma_free_coherent(info->device, fb->image_size,
273 @@ -314,7 +412,7 @@ static int bcm2708_fb_set_par(struct fb_
277 - fb->disable_arm_alloc = true;
278 + fb->fbdev->disable_arm_alloc = true;
280 fb->image_size = image_size;
282 @@ -325,7 +423,7 @@ static int bcm2708_fb_set_par(struct fb_
283 fbinfo.screen_size = image_size;
284 fbinfo.pitch = (info->var.xres * info->var.bits_per_pixel) >> 3;
286 - ret = rpi_firmware_property_list(fb->fw, &fbinfo,
287 + ret = rpi_firmware_property_list(fb->fbdev->fw, &fbinfo,
289 if (ret || fbinfo.base != fb->dma_addr) {
290 /* Firmware either failed, or assigned a different base
291 @@ -338,7 +436,7 @@ static int bcm2708_fb_set_par(struct fb_
295 - fb->disable_arm_alloc = true;
296 + fb->fbdev->disable_arm_alloc = true;
299 /* Our allocation failed - drop into the old scheme of
300 @@ -357,7 +455,7 @@ static int bcm2708_fb_set_par(struct fb_
301 fbinfo.tag6.tag = RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH;
304 - ret = rpi_firmware_property_list(fb->fw, &fbinfo,
305 + ret = rpi_firmware_property_list(fb->fbdev->fw, &fbinfo,
308 dev_err(info->device,
309 @@ -447,7 +545,10 @@ static int bcm2708_fb_setcolreg(unsigned
310 packet->length = regno + 1;
311 memcpy(packet->cmap, fb->gpu_cmap,
312 sizeof(packet->cmap));
313 - ret = rpi_firmware_property(fb->fw,
315 + set_display_num(fb);
317 + ret = rpi_firmware_property(fb->fbdev->fw,
318 RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
320 (2 + packet->length) * sizeof(u32));
321 @@ -486,8 +587,11 @@ static int bcm2708_fb_blank(int blank_mo
325 - ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
326 + set_display_num(fb);
328 + ret = rpi_firmware_property(fb->fbdev->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
329 &value, sizeof(value));
332 dev_err(info->device, "%s(%d) failed: %d\n", __func__,
334 @@ -504,12 +608,14 @@ static int bcm2708_fb_pan_display(struct
335 info->var.yoffset = var->yoffset;
336 result = bcm2708_fb_set_par(info);
338 - pr_err("%s(%d,%d) returns=%d\n", __func__, var->xoffset,
339 + pr_err("%s(%u,%u) returns=%d\n", __func__, var->xoffset,
340 var->yoffset, result);
344 static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
345 +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd,
348 struct bcm2708_fb *fb = to_bcm2708(info);
350 @@ -517,7 +623,9 @@ static int bcm2708_ioctl(struct fb_info
353 case FBIO_WAITFORVSYNC:
354 - ret = rpi_firmware_property(fb->fw,
355 + set_display_num(fb);
357 + ret = rpi_firmware_property(fb->fbdev->fw,
358 RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC,
359 &dummy, sizeof(dummy));
361 @@ -534,23 +642,22 @@ static int bcm2708_ioctl(struct fb_info
362 static void bcm2708_fb_fillrect(struct fb_info *info,
363 const struct fb_fillrect *rect)
365 - /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
366 cfb_fillrect(info, rect);
369 /* A helper function for configuring dma control block */
370 static void set_dma_cb(struct bcm2708_dma_cb *cb,
386 cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
387 - BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
388 - BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
389 + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
390 + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
394 @@ -568,15 +675,19 @@ static void bcm2708_fb_copyarea(struct f
395 const struct fb_copyarea *region)
397 struct bcm2708_fb *fb = to_bcm2708(info);
398 - struct bcm2708_dma_cb *cb = fb->cb_base;
399 + struct bcm2708_fb_dev *fbdev = fb->fbdev;
400 + struct bcm2708_dma_cb *cb = fbdev->cb_base;
401 int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
403 /* Channel 0 supports larger bursts and is a bit faster */
404 - int burst_size = (fb->dma_chan == 0) ? 8 : 2;
405 + int burst_size = (fbdev->dma_chan == 0) ? 8 : 2;
406 int pixels = region->width * region->height;
408 - /* Fallback to cfb_copyarea() if we don't like something */
409 - if (bytes_per_pixel > 4 ||
410 + /* If DMA is currently in use (ie being used on another FB), then
411 + * rather than wait for it to finish, just use the cfb_copyarea
413 + if (!mutex_trylock(&fbdev->dma_mutex) ||
414 + bytes_per_pixel > 4 ||
415 info->var.xres * info->var.yres > 1920 * 1200 ||
416 region->width <= 0 || region->width > info->var.xres ||
417 region->height <= 0 || region->height > info->var.yres ||
418 @@ -603,8 +714,8 @@ static void bcm2708_fb_copyarea(struct f
419 * 1920x1200 resolution at 32bpp pixel depth.
422 - dma_addr_t control_block_pa = fb->cb_handle;
423 - dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
424 + dma_addr_t control_block_pa = fbdev->cb_handle;
425 + dma_addr_t scratchbuf = fbdev->cb_handle + 16 * 1024;
426 int scanline_size = bytes_per_pixel * region->width;
427 int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
429 @@ -654,10 +765,10 @@ static void bcm2708_fb_copyarea(struct f
431 set_dma_cb(cb, burst_size,
432 fb->fb_bus_address + dy * fb->fb.fix.line_length +
433 - bytes_per_pixel * region->dx,
434 + bytes_per_pixel * region->dx,
436 fb->fb_bus_address + sy * fb->fb.fix.line_length +
437 - bytes_per_pixel * region->sx,
438 + bytes_per_pixel * region->sx,
440 region->width * bytes_per_pixel,
442 @@ -667,32 +778,33 @@ static void bcm2708_fb_copyarea(struct f
445 if (pixels < dma_busy_wait_threshold) {
446 - bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
447 - bcm_dma_wait_idle(fb->dma_chan_base);
448 + bcm_dma_start(fbdev->dma_chan_base, fbdev->cb_handle);
449 + bcm_dma_wait_idle(fbdev->dma_chan_base);
451 - void __iomem *dma_chan = fb->dma_chan_base;
452 + void __iomem *local_dma_chan = fbdev->dma_chan_base;
454 cb->info |= BCM2708_DMA_INT_EN;
455 - bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
456 - while (bcm_dma_is_busy(dma_chan)) {
457 - wait_event_interruptible(fb->dma_waitq,
458 - !bcm_dma_is_busy(dma_chan));
459 + bcm_dma_start(fbdev->dma_chan_base, fbdev->cb_handle);
460 + while (bcm_dma_is_busy(local_dma_chan)) {
461 + wait_event_interruptible(fbdev->dma_waitq,
462 + !bcm_dma_is_busy(local_dma_chan));
464 - fb->stats.dma_irqs++;
465 + fbdev->dma_stats.dma_irqs++;
467 - fb->stats.dma_copies++;
468 + fbdev->dma_stats.dma_copies++;
470 + mutex_unlock(&fbdev->dma_mutex);
473 static void bcm2708_fb_imageblit(struct fb_info *info,
474 const struct fb_image *image)
476 - /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
477 cfb_imageblit(info, image);
480 static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
482 - struct bcm2708_fb *fb = cxt;
483 + struct bcm2708_fb_dev *fbdev = cxt;
485 /* FIXME: should read status register to check if this is
486 * actually interrupting us or not, in case this interrupt
487 @@ -702,9 +814,9 @@ static irqreturn_t bcm2708_fb_dma_irq(in
490 /* acknowledge the interrupt */
491 - writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
492 + writel(BCM2708_DMA_INT, fbdev->dma_chan_base + BCM2708_DMA_CS);
494 - wake_up(&fb->dma_waitq);
495 + wake_up(&fbdev->dma_waitq);
499 @@ -737,11 +849,23 @@ static int bcm2708_fb_register(struct bc
500 fb->fb.fix.ywrapstep = 0;
501 fb->fb.fix.accel = FB_ACCEL_NONE;
503 - fb->fb.var.xres = fbwidth;
504 - fb->fb.var.yres = fbheight;
505 - fb->fb.var.xres_virtual = fbwidth;
506 - fb->fb.var.yres_virtual = fbheight;
507 - fb->fb.var.bits_per_pixel = fbdepth;
508 + /* If we have data from the VC4 on FB's, use that, otherwise use the
509 + * module parameters
511 + if (fb->display_settings.width) {
512 + fb->fb.var.xres = fb->display_settings.width;
513 + fb->fb.var.yres = fb->display_settings.height;
514 + fb->fb.var.xres_virtual = fb->fb.var.xres;
515 + fb->fb.var.yres_virtual = fb->fb.var.yres;
516 + fb->fb.var.bits_per_pixel = fb->display_settings.depth;
518 + fb->fb.var.xres = fbwidth;
519 + fb->fb.var.yres = fbheight;
520 + fb->fb.var.xres_virtual = fbwidth;
521 + fb->fb.var.yres_virtual = fbheight;
522 + fb->fb.var.bits_per_pixel = fbdepth;
525 fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
526 fb->fb.var.activate = FB_ACTIVATE_NOW;
527 fb->fb.var.nonstd = 0;
528 @@ -757,26 +881,23 @@ static int bcm2708_fb_register(struct bc
529 fb->fb.monspecs.dclkmax = 100000000;
531 bcm2708_fb_set_bitfields(&fb->fb.var);
532 - init_waitqueue_head(&fb->dma_waitq);
535 * Allocate colourmap.
538 fb_set_var(&fb->fb, &fb->fb.var);
540 ret = bcm2708_fb_set_par(&fb->fb);
545 - print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n",
546 - fbwidth, fbheight, fbdepth, fbswap);
548 ret = register_framebuffer(&fb->fb);
549 - print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
554 - print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
555 + dev_warn(fb->fb.dev, "Unable to register framebuffer (%d)\n", ret);
559 @@ -785,10 +906,18 @@ static int bcm2708_fb_probe(struct platf
561 struct device_node *fw_np;
562 struct rpi_firmware *fw;
563 - struct bcm2708_fb *fb;
567 + struct bcm2708_fb_dev *fbdev;
568 + struct { u32 base, length; } gpu_mem;
570 + fbdev = devm_kzalloc(&dev->dev, sizeof(*fbdev), GFP_KERNEL);
575 fw_np = of_parse_phandle(dev->dev.of_node, "firmware", 0);
577 /* Remove comment when booting without Device Tree is no longer supported
579 * dev_err(&dev->dev, "Missing firmware node\n");
580 @@ -796,90 +925,154 @@ static int bcm2708_fb_probe(struct platf
583 fw = rpi_firmware_get(fw_np);
587 return -EPROBE_DEFER;
589 - fb = kzalloc(sizeof(*fb), GFP_KERNEL);
593 + ret = rpi_firmware_property(fw,
594 + RPI_FIRMWARE_FRAMEBUFFER_GET_NUM_DISPLAYS,
595 + &num_displays, sizeof(u32));
597 + /* If we fail to get the number of displays, or it returns 0, then
598 + * assume old firmware that doesn't have the mailbox call, so just
601 + if (ret || num_displays == 0) {
604 + "Unable to determine number of FB's. Assuming 1\n");
607 + fbdev->firmware_supports_multifb = 1;
610 + if (num_displays > MAX_FRAMEBUFFERS) {
611 + dev_warn(&dev->dev,
612 + "More displays reported from firmware than supported in driver (%u vs %u)",
613 + num_displays, MAX_FRAMEBUFFERS);
614 + num_displays = MAX_FRAMEBUFFERS;
618 - bcm2708_fb_debugfs_init(fb);
619 + dev_info(&dev->dev, "FB found %d display(s)\n", num_displays);
621 + /* Set up the DMA information. Note we have just one set of DMA
622 + * parameters to work with all the FB's so requires synchronising when
626 + mutex_init(&fbdev->dma_mutex);
628 - fb->cb_base = dma_alloc_wc(&dev->dev, SZ_64K,
629 - &fb->cb_handle, GFP_KERNEL);
630 - if (!fb->cb_base) {
631 + fbdev->cb_base = dma_alloc_wc(&dev->dev, SZ_64K,
634 + if (!fbdev->cb_base) {
635 dev_err(&dev->dev, "cannot allocate DMA CBs\n");
640 - pr_info("BCM2708FB: allocated DMA memory %pad\n", &fb->cb_handle);
642 ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
643 - &fb->dma_chan_base, &fb->dma_irq);
644 + &fbdev->dma_chan_base,
647 - dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
648 + dev_err(&dev->dev, "Couldn't allocate a DMA channel\n");
651 - fb->dma_chan = ret;
652 + fbdev->dma_chan = ret;
654 - ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
655 - 0, "bcm2708_fb dma", fb);
656 + ret = request_irq(fbdev->dma_irq, bcm2708_fb_dma_irq,
657 + 0, "bcm2708_fb DMA", fbdev);
659 - pr_err("%s: failed to request DMA irq\n", __func__);
661 + "Failed to request DMA irq\n");
665 - pr_info("BCM2708FB: allocated DMA channel %d\n", fb->dma_chan);
666 + rpi_firmware_property(fbdev->fw,
667 + RPI_FIRMWARE_GET_VC_MEMORY,
668 + &gpu_mem, sizeof(gpu_mem));
670 + for (i = 0; i < num_displays; i++) {
671 + struct bcm2708_fb *fb = &fbdev->displays[i];
673 + fb->display_settings.display_num = i;
675 + fb->fb.device = &dev->dev;
678 + fb->gpu.base = gpu_mem.base;
679 + fb->gpu.length = gpu_mem.length;
681 + if (fbdev->firmware_supports_multifb) {
682 + ret = rpi_firmware_property(fw,
683 + RPI_FIRMWARE_FRAMEBUFFER_GET_DISPLAY_SETTINGS,
684 + &fb->display_settings,
685 + GET_DISPLAY_SETTINGS_PAYLOAD_SIZE);
687 + memset(&fb->display_settings, 0,
688 + sizeof(fb->display_settings));
691 + ret = bcm2708_fb_register(fb);
694 - fb->fb.device = &dev->dev;
696 + bcm2708_fb_debugfs_init(fb);
698 - /* failure here isn't fatal, but we'll fail in vc_mem_copy if
699 - * fb->gpu is not valid
701 - rpi_firmware_property(fb->fw, RPI_FIRMWARE_GET_VC_MEMORY, &fb->gpu,
703 + fbdev->num_displays++;
705 - ret = bcm2708_fb_register(fb);
707 - platform_set_drvdata(dev, fb);
709 + dev_info(&dev->dev,
710 + "Registered framebuffer for display %u, size %ux%u\n",
711 + fb->display_settings.display_num,
715 + // Use this to flag if this FB entry is in use.
720 + // Did we actually successfully create any FB's?
721 + if (fbdev->num_displays) {
722 + init_waitqueue_head(&fbdev->dma_waitq);
723 + platform_set_drvdata(dev, fbdev);
728 - bcm_dma_chan_free(fb->dma_chan);
729 + bcm_dma_chan_free(fbdev->dma_chan);
731 - dma_free_wc(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
732 + dma_free_wc(&dev->dev, SZ_64K, fbdev->cb_base,
737 dev_err(&dev->dev, "probe failed, err %d\n", ret);
743 static int bcm2708_fb_remove(struct platform_device *dev)
745 - struct bcm2708_fb *fb = platform_get_drvdata(dev);
746 + struct bcm2708_fb_dev *fbdev = platform_get_drvdata(dev);
749 platform_set_drvdata(dev, NULL);
751 - if (fb->fb.screen_base)
752 - iounmap(fb->fb.screen_base);
753 - unregister_framebuffer(&fb->fb);
755 - dma_free_wc(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
756 - bcm_dma_chan_free(fb->dma_chan);
758 - bcm2708_fb_debugfs_deinit(fb);
759 + for (i = 0; i < fbdev->num_displays; i++) {
760 + if (fbdev->displays[i].fb.screen_base)
761 + iounmap(fbdev->displays[i].fb.screen_base);
763 + if (fbdev->displays[i].fbdev) {
764 + unregister_framebuffer(&fbdev->displays[i].fb);
765 + bcm2708_fb_debugfs_deinit(&fbdev->displays[i]);
769 - free_irq(fb->dma_irq, fb);
770 + dma_free_wc(&dev->dev, SZ_64K, fbdev->cb_base,
772 + bcm_dma_chan_free(fbdev->dma_chan);
773 + free_irq(fbdev->dma_irq, fbdev);
776 + mutex_destroy(&fbdev->dma_mutex);
780 @@ -894,10 +1087,10 @@ static struct platform_driver bcm2708_fb
781 .probe = bcm2708_fb_probe,
782 .remove = bcm2708_fb_remove,
784 - .name = DRIVER_NAME,
785 - .owner = THIS_MODULE,
786 - .of_match_table = bcm2708_fb_of_match_table,
788 + .name = DRIVER_NAME,
789 + .owner = THIS_MODULE,
790 + .of_match_table = bcm2708_fb_of_match_table,
794 static int __init bcm2708_fb_init(void)
795 --- a/include/soc/bcm2835/raspberrypi-firmware.h
796 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
797 @@ -106,9 +106,15 @@ enum rpi_firmware_property_tag {
798 RPI_FIRMWARE_FRAMEBUFFER_GET_VIRTUAL_OFFSET = 0x00040009,
799 RPI_FIRMWARE_FRAMEBUFFER_GET_OVERSCAN = 0x0004000a,
800 RPI_FIRMWARE_FRAMEBUFFER_GET_PALETTE = 0x0004000b,
801 + RPI_FIRMWARE_FRAMEBUFFER_GET_LAYER = 0x0004000c,
802 + RPI_FIRMWARE_FRAMEBUFFER_GET_TRANSFORM = 0x0004000d,
803 + RPI_FIRMWARE_FRAMEBUFFER_GET_VSYNC = 0x0004000e,
804 RPI_FIRMWARE_FRAMEBUFFER_GET_TOUCHBUF = 0x0004000f,
805 RPI_FIRMWARE_FRAMEBUFFER_GET_GPIOVIRTBUF = 0x00040010,
806 RPI_FIRMWARE_FRAMEBUFFER_RELEASE = 0x00048001,
807 + RPI_FIRMWARE_FRAMEBUFFER_SET_DISPLAY_NUM = 0x00048013,
808 + RPI_FIRMWARE_FRAMEBUFFER_GET_NUM_DISPLAYS = 0x00040013,
809 + RPI_FIRMWARE_FRAMEBUFFER_GET_DISPLAY_SETTINGS = 0x00040014,
810 RPI_FIRMWARE_FRAMEBUFFER_TEST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
811 RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
812 RPI_FIRMWARE_FRAMEBUFFER_TEST_DEPTH = 0x00044005,
813 @@ -117,6 +123,8 @@ enum rpi_firmware_property_tag {
814 RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_OFFSET = 0x00044009,
815 RPI_FIRMWARE_FRAMEBUFFER_TEST_OVERSCAN = 0x0004400a,
816 RPI_FIRMWARE_FRAMEBUFFER_TEST_PALETTE = 0x0004400b,
817 + RPI_FIRMWARE_FRAMEBUFFER_TEST_LAYER = 0x0004400c,
818 + RPI_FIRMWARE_FRAMEBUFFER_TEST_TRANSFORM = 0x0004400d,
819 RPI_FIRMWARE_FRAMEBUFFER_TEST_VSYNC = 0x0004400e,
820 RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
821 RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
822 @@ -127,9 +135,12 @@ enum rpi_firmware_property_tag {
823 RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET = 0x00048009,
824 RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN = 0x0004800a,
825 RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE = 0x0004800b,
827 RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF = 0x0004801f,
828 RPI_FIRMWARE_FRAMEBUFFER_SET_GPIOVIRTBUF = 0x00048020,
829 RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC = 0x0004800e,
830 + RPI_FIRMWARE_FRAMEBUFFER_SET_LAYER = 0x0004800c,
831 + RPI_FIRMWARE_FRAMEBUFFER_SET_TRANSFORM = 0x0004800d,
832 RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT = 0x0004800f,
834 RPI_FIRMWARE_VCHIQ_INIT = 0x00048010,
835 @@ -138,6 +149,8 @@ enum rpi_firmware_property_tag {
836 RPI_FIRMWARE_GET_DMA_CHANNELS = 0x00060001,
839 +#define GET_DISPLAY_SETTINGS_PAYLOAD_SIZE 64
841 #if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE)
842 int rpi_firmware_property(struct rpi_firmware *fw,
843 u32 tag, void *data, size_t len);