1 From 4ac7128970e15d83ef3c2a65e65ca9ee4096c9d1 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 | 457 +++++++++++++++------
9 include/soc/bcm2835/raspberrypi-firmware.h | 13 +
10 2 files changed, 337 insertions(+), 133 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,64 +82,150 @@ 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 - fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
139 + static struct debugfs_reg32 screeninfo[] = {
140 + {"width", offsetof(struct fb_var_screeninfo, xres)},
141 + {"height", offsetof(struct fb_var_screeninfo, yres)},
142 + {"bpp", offsetof(struct fb_var_screeninfo, bits_per_pixel)},
143 + {"xres_virtual", offsetof(struct fb_var_screeninfo, xres_virtual)},
144 + {"yres_virtual", offsetof(struct fb_var_screeninfo, yres_virtual)},
145 + {"xoffset", offsetof(struct fb_var_screeninfo, xoffset)},
146 + {"yoffset", offsetof(struct fb_var_screeninfo, yoffset)},
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;
165 + snprintf(buf, sizeof(buf), "%u", fb->display_settings.display_num);
167 + fb->debugfs_subdir = debugfs_create_dir(buf, fb->debugfs_dir);
169 debugfs_create_regset32("stats", 0444, fb->debugfs_dir,
172 + if (!fb->debugfs_subdir) {
173 + dev_warn(fb->fb.dev, "%s: could not create debugfs entry %u\n",
174 + __func__, fb->display_settings.display_num);
178 + fbdev->dma_stats.regset.regs = stats_registers;
179 + fbdev->dma_stats.regset.nregs = ARRAY_SIZE(stats_registers);
180 + fbdev->dma_stats.regset.base = &fbdev->dma_stats;
182 + debugfs_create_regset32("dma_stats", 0444, fb->debugfs_subdir,
183 + &fbdev->dma_stats.regset);
185 + fb->screeninfo_regset.regs = screeninfo;
186 + fb->screeninfo_regset.nregs = ARRAY_SIZE(screeninfo);
187 + fb->screeninfo_regset.base = &fb->fb.var;
189 + debugfs_create_regset32("screeninfo", 0444, fb->debugfs_subdir,
190 + &fb->screeninfo_regset);
192 + fbdev->instance_count++;
197 +static void set_display_num(struct bcm2708_fb *fb)
199 + if (fb && fb->fbdev && fb->fbdev->firmware_supports_multifb) {
200 + u32 tmp = fb->display_settings.display_num;
202 + if (rpi_firmware_property(fb->fbdev->fw,
203 + RPI_FIRMWARE_FRAMEBUFFER_SET_DISPLAY_NUM,
206 + dev_warn_once(fb->fb.dev,
207 + "Set display number call failed. Old GPU firmware?");
211 static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
214 @@ -214,11 +303,11 @@ static int bcm2708_fb_check_var(struct f
215 struct fb_info *info)
217 /* info input, var output */
218 - print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n",
219 + print_debug("%s(%p) %ux%u (%ux%u), %ul, %u\n",
220 __func__, info, info->var.xres, info->var.yres,
221 info->var.xres_virtual, info->var.yres_virtual,
222 - (int)info->screen_size, info->var.bits_per_pixel);
223 - print_debug("%s(%p) %dx%d (%dx%d), %d\n", __func__, var, var->xres,
224 + info->screen_size, info->var.bits_per_pixel);
225 + print_debug("%s(%p) %ux%u (%ux%u), %u\n", __func__, var, var->xres,
226 var->yres, var->xres_virtual, var->yres_virtual,
227 var->bits_per_pixel);
229 @@ -281,17 +370,24 @@ static int bcm2708_fb_set_par(struct fb_
234 - print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n", __func__, info,
235 + print_debug("%s(%p) %dx%d (%dx%d), %d, %d (display %d)\n", __func__,
237 info->var.xres, info->var.yres, info->var.xres_virtual,
238 info->var.yres_virtual, (int)info->screen_size,
239 - info->var.bits_per_pixel);
240 + info->var.bits_per_pixel, value);
242 + /* Need to set the display number to act on first
243 + * Cannot do it in the tag list because on older firmware the call
244 + * will fail and stop the rest of the list being executed.
245 + * We can ignore this call failing as the default at other end is 0
247 + set_display_num(fb);
249 /* Try allocating our own buffer. We can specify all the parameters */
250 image_size = ((info->var.xres * info->var.yres) *
251 info->var.bits_per_pixel) >> 3;
253 - if (!fb->disable_arm_alloc &&
254 + if (!fb->fbdev->disable_arm_alloc &&
255 (image_size != fb->image_size || !fb->dma_addr)) {
257 dma_free_coherent(info->device, fb->image_size,
258 @@ -306,7 +402,7 @@ static int bcm2708_fb_set_par(struct fb_
262 - fb->disable_arm_alloc = true;
263 + fb->fbdev->disable_arm_alloc = true;
265 fb->image_size = image_size;
267 @@ -317,7 +413,7 @@ static int bcm2708_fb_set_par(struct fb_
268 fbinfo.screen_size = image_size;
269 fbinfo.pitch = (info->var.xres * info->var.bits_per_pixel) >> 3;
271 - ret = rpi_firmware_property_list(fb->fw, &fbinfo,
272 + ret = rpi_firmware_property_list(fb->fbdev->fw, &fbinfo,
274 if (ret || fbinfo.base != fb->dma_addr) {
275 /* Firmware either failed, or assigned a different base
276 @@ -330,7 +426,7 @@ static int bcm2708_fb_set_par(struct fb_
280 - fb->disable_arm_alloc = true;
281 + fb->fbdev->disable_arm_alloc = true;
284 /* Our allocation failed - drop into the old scheme of
285 @@ -349,7 +445,7 @@ static int bcm2708_fb_set_par(struct fb_
286 fbinfo.tag6.tag = RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH;
289 - ret = rpi_firmware_property_list(fb->fw, &fbinfo,
290 + ret = rpi_firmware_property_list(fb->fbdev->fw, &fbinfo,
293 dev_err(info->device,
294 @@ -439,7 +535,10 @@ static int bcm2708_fb_setcolreg(unsigned
295 packet->length = regno + 1;
296 memcpy(packet->cmap, fb->gpu_cmap,
297 sizeof(packet->cmap));
298 - ret = rpi_firmware_property(fb->fw,
300 + set_display_num(fb);
302 + ret = rpi_firmware_property(fb->fbdev->fw,
303 RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
305 (2 + packet->length) * sizeof(u32));
306 @@ -478,8 +577,11 @@ static int bcm2708_fb_blank(int blank_mo
310 - ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
311 + set_display_num(fb);
313 + ret = rpi_firmware_property(fb->fbdev->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
314 &value, sizeof(value));
317 dev_err(info->device, "%s(%d) failed: %d\n", __func__,
319 @@ -496,12 +598,14 @@ static int bcm2708_fb_pan_display(struct
320 info->var.yoffset = var->yoffset;
321 result = bcm2708_fb_set_par(info);
323 - pr_err("%s(%d,%d) returns=%d\n", __func__, var->xoffset,
324 + pr_err("%s(%u,%u) returns=%d\n", __func__, var->xoffset,
325 var->yoffset, result);
329 static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
330 +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd,
333 struct bcm2708_fb *fb = to_bcm2708(info);
335 @@ -509,7 +613,9 @@ static int bcm2708_ioctl(struct fb_info
338 case FBIO_WAITFORVSYNC:
339 - ret = rpi_firmware_property(fb->fw,
340 + set_display_num(fb);
342 + ret = rpi_firmware_property(fb->fbdev->fw,
343 RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC,
344 &dummy, sizeof(dummy));
346 @@ -526,23 +632,22 @@ static int bcm2708_ioctl(struct fb_info
347 static void bcm2708_fb_fillrect(struct fb_info *info,
348 const struct fb_fillrect *rect)
350 - /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
351 cfb_fillrect(info, rect);
354 /* A helper function for configuring dma control block */
355 static void set_dma_cb(struct bcm2708_dma_cb *cb,
371 cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
372 - BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
373 - BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
374 + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
375 + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
379 @@ -560,15 +665,19 @@ static void bcm2708_fb_copyarea(struct f
380 const struct fb_copyarea *region)
382 struct bcm2708_fb *fb = to_bcm2708(info);
383 - struct bcm2708_dma_cb *cb = fb->cb_base;
384 + struct bcm2708_fb_dev *fbdev = fb->fbdev;
385 + struct bcm2708_dma_cb *cb = fbdev->cb_base;
386 int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
388 /* Channel 0 supports larger bursts and is a bit faster */
389 - int burst_size = (fb->dma_chan == 0) ? 8 : 2;
390 + int burst_size = (fbdev->dma_chan == 0) ? 8 : 2;
391 int pixels = region->width * region->height;
393 - /* Fallback to cfb_copyarea() if we don't like something */
394 - if (bytes_per_pixel > 4 ||
395 + /* If DMA is currently in use (ie being used on another FB), then
396 + * rather than wait for it to finish, just use the cfb_copyarea
398 + if (!mutex_trylock(&fbdev->dma_mutex) ||
399 + bytes_per_pixel > 4 ||
400 info->var.xres * info->var.yres > 1920 * 1200 ||
401 region->width <= 0 || region->width > info->var.xres ||
402 region->height <= 0 || region->height > info->var.yres ||
403 @@ -595,8 +704,8 @@ static void bcm2708_fb_copyarea(struct f
404 * 1920x1200 resolution at 32bpp pixel depth.
407 - dma_addr_t control_block_pa = fb->cb_handle;
408 - dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
409 + dma_addr_t control_block_pa = fbdev->cb_handle;
410 + dma_addr_t scratchbuf = fbdev->cb_handle + 16 * 1024;
411 int scanline_size = bytes_per_pixel * region->width;
412 int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
414 @@ -646,10 +755,10 @@ static void bcm2708_fb_copyarea(struct f
416 set_dma_cb(cb, burst_size,
417 fb->fb_bus_address + dy * fb->fb.fix.line_length +
418 - bytes_per_pixel * region->dx,
419 + bytes_per_pixel * region->dx,
421 fb->fb_bus_address + sy * fb->fb.fix.line_length +
422 - bytes_per_pixel * region->sx,
423 + bytes_per_pixel * region->sx,
425 region->width * bytes_per_pixel,
427 @@ -659,32 +768,33 @@ static void bcm2708_fb_copyarea(struct f
430 if (pixels < dma_busy_wait_threshold) {
431 - bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
432 - bcm_dma_wait_idle(fb->dma_chan_base);
433 + bcm_dma_start(fbdev->dma_chan_base, fbdev->cb_handle);
434 + bcm_dma_wait_idle(fbdev->dma_chan_base);
436 - void __iomem *dma_chan = fb->dma_chan_base;
437 + void __iomem *local_dma_chan = fbdev->dma_chan_base;
439 cb->info |= BCM2708_DMA_INT_EN;
440 - bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
441 - while (bcm_dma_is_busy(dma_chan)) {
442 - wait_event_interruptible(fb->dma_waitq,
443 - !bcm_dma_is_busy(dma_chan));
444 + bcm_dma_start(fbdev->dma_chan_base, fbdev->cb_handle);
445 + while (bcm_dma_is_busy(local_dma_chan)) {
446 + wait_event_interruptible(fbdev->dma_waitq,
447 + !bcm_dma_is_busy(local_dma_chan));
449 - fb->stats.dma_irqs++;
450 + fbdev->dma_stats.dma_irqs++;
452 - fb->stats.dma_copies++;
453 + fbdev->dma_stats.dma_copies++;
455 + mutex_unlock(&fbdev->dma_mutex);
458 static void bcm2708_fb_imageblit(struct fb_info *info,
459 const struct fb_image *image)
461 - /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
462 cfb_imageblit(info, image);
465 static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
467 - struct bcm2708_fb *fb = cxt;
468 + struct bcm2708_fb_dev *fbdev = cxt;
470 /* FIXME: should read status register to check if this is
471 * actually interrupting us or not, in case this interrupt
472 @@ -694,9 +804,9 @@ static irqreturn_t bcm2708_fb_dma_irq(in
475 /* acknowledge the interrupt */
476 - writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
477 + writel(BCM2708_DMA_INT, fbdev->dma_chan_base + BCM2708_DMA_CS);
479 - wake_up(&fb->dma_waitq);
480 + wake_up(&fbdev->dma_waitq);
484 @@ -729,11 +839,23 @@ static int bcm2708_fb_register(struct bc
485 fb->fb.fix.ywrapstep = 0;
486 fb->fb.fix.accel = FB_ACCEL_NONE;
488 - fb->fb.var.xres = fbwidth;
489 - fb->fb.var.yres = fbheight;
490 - fb->fb.var.xres_virtual = fbwidth;
491 - fb->fb.var.yres_virtual = fbheight;
492 - fb->fb.var.bits_per_pixel = fbdepth;
493 + /* If we have data from the VC4 on FB's, use that, otherwise use the
494 + * module parameters
496 + if (fb->display_settings.width) {
497 + fb->fb.var.xres = fb->display_settings.width;
498 + fb->fb.var.yres = fb->display_settings.height;
499 + fb->fb.var.xres_virtual = fb->fb.var.xres;
500 + fb->fb.var.yres_virtual = fb->fb.var.yres;
501 + fb->fb.var.bits_per_pixel = fb->display_settings.depth;
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;
510 fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
511 fb->fb.var.activate = FB_ACTIVATE_NOW;
512 fb->fb.var.nonstd = 0;
513 @@ -749,26 +871,23 @@ static int bcm2708_fb_register(struct bc
514 fb->fb.monspecs.dclkmax = 100000000;
516 bcm2708_fb_set_bitfields(&fb->fb.var);
517 - init_waitqueue_head(&fb->dma_waitq);
520 * Allocate colourmap.
523 fb_set_var(&fb->fb, &fb->fb.var);
525 ret = bcm2708_fb_set_par(&fb->fb);
530 - print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n",
531 - fbwidth, fbheight, fbdepth, fbswap);
533 ret = register_framebuffer(&fb->fb);
534 - print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
539 - print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
540 + dev_warn(fb->fb.dev, "Unable to register framebuffer (%d)\n", ret);
544 @@ -777,10 +896,18 @@ static int bcm2708_fb_probe(struct platf
546 struct device_node *fw_np;
547 struct rpi_firmware *fw;
548 - struct bcm2708_fb *fb;
552 + struct bcm2708_fb_dev *fbdev;
553 + struct { u32 base, length; } gpu_mem;
555 + fbdev = devm_kzalloc(&dev->dev, sizeof(*fbdev), GFP_KERNEL);
560 fw_np = of_parse_phandle(dev->dev.of_node, "firmware", 0);
562 /* Remove comment when booting without Device Tree is no longer supported
564 * dev_err(&dev->dev, "Missing firmware node\n");
565 @@ -788,90 +915,154 @@ static int bcm2708_fb_probe(struct platf
568 fw = rpi_firmware_get(fw_np);
572 return -EPROBE_DEFER;
574 - fb = kzalloc(sizeof(*fb), GFP_KERNEL);
578 + ret = rpi_firmware_property(fw,
579 + RPI_FIRMWARE_FRAMEBUFFER_GET_NUM_DISPLAYS,
580 + &num_displays, sizeof(u32));
582 + /* If we fail to get the number of displays, or it returns 0, then
583 + * assume old firmware that doesn't have the mailbox call, so just
586 + if (ret || num_displays == 0) {
589 + "Unable to determine number of FB's. Assuming 1\n");
592 + fbdev->firmware_supports_multifb = 1;
595 + if (num_displays > MAX_FRAMEBUFFERS) {
596 + dev_warn(&dev->dev,
597 + "More displays reported from firmware than supported in driver (%u vs %u)",
598 + num_displays, MAX_FRAMEBUFFERS);
599 + num_displays = MAX_FRAMEBUFFERS;
603 - bcm2708_fb_debugfs_init(fb);
604 + dev_info(&dev->dev, "FB found %d display(s)\n", num_displays);
606 + /* Set up the DMA information. Note we have just one set of DMA
607 + * parameters to work with all the FB's so requires synchronising when
611 + mutex_init(&fbdev->dma_mutex);
613 - fb->cb_base = dma_alloc_wc(&dev->dev, SZ_64K,
614 - &fb->cb_handle, GFP_KERNEL);
615 - if (!fb->cb_base) {
616 + fbdev->cb_base = dma_alloc_wc(&dev->dev, SZ_64K,
619 + if (!fbdev->cb_base) {
620 dev_err(&dev->dev, "cannot allocate DMA CBs\n");
625 - pr_info("BCM2708FB: allocated DMA memory %pad\n", &fb->cb_handle);
627 ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
628 - &fb->dma_chan_base, &fb->dma_irq);
629 + &fbdev->dma_chan_base,
632 - dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
633 + dev_err(&dev->dev, "Couldn't allocate a DMA channel\n");
636 - fb->dma_chan = ret;
637 + fbdev->dma_chan = ret;
639 - ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
640 - 0, "bcm2708_fb dma", fb);
641 + ret = request_irq(fbdev->dma_irq, bcm2708_fb_dma_irq,
642 + 0, "bcm2708_fb DMA", fbdev);
644 - pr_err("%s: failed to request DMA irq\n", __func__);
646 + "Failed to request DMA irq\n");
650 - pr_info("BCM2708FB: allocated DMA channel %d\n", fb->dma_chan);
651 + rpi_firmware_property(fbdev->fw,
652 + RPI_FIRMWARE_GET_VC_MEMORY,
653 + &gpu_mem, sizeof(gpu_mem));
655 + for (i = 0; i < num_displays; i++) {
656 + struct bcm2708_fb *fb = &fbdev->displays[i];
658 + fb->display_settings.display_num = i;
660 + fb->fb.device = &dev->dev;
663 + fb->gpu.base = gpu_mem.base;
664 + fb->gpu.length = gpu_mem.length;
666 + if (fbdev->firmware_supports_multifb) {
667 + ret = rpi_firmware_property(fw,
668 + RPI_FIRMWARE_FRAMEBUFFER_GET_DISPLAY_SETTINGS,
669 + &fb->display_settings,
670 + GET_DISPLAY_SETTINGS_PAYLOAD_SIZE);
672 + memset(&fb->display_settings, 0,
673 + sizeof(fb->display_settings));
677 - fb->fb.device = &dev->dev;
678 + ret = bcm2708_fb_register(fb);
680 - /* failure here isn't fatal, but we'll fail in vc_mem_copy if
681 - * fb->gpu is not valid
683 - rpi_firmware_property(fb->fw, RPI_FIRMWARE_GET_VC_MEMORY, &fb->gpu,
686 + bcm2708_fb_debugfs_init(fb);
688 - ret = bcm2708_fb_register(fb);
690 - platform_set_drvdata(dev, fb);
692 + fbdev->num_displays++;
694 + dev_info(&dev->dev,
695 + "Registered framebuffer for display %u, size %ux%u\n",
696 + fb->display_settings.display_num,
700 + // Use this to flag if this FB entry is in use.
705 + // Did we actually successfully create any FB's?
706 + if (fbdev->num_displays) {
707 + init_waitqueue_head(&fbdev->dma_waitq);
708 + platform_set_drvdata(dev, fbdev);
713 - bcm_dma_chan_free(fb->dma_chan);
714 + bcm_dma_chan_free(fbdev->dma_chan);
716 - dma_free_wc(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
717 + dma_free_wc(&dev->dev, SZ_64K, fbdev->cb_base,
722 dev_err(&dev->dev, "probe failed, err %d\n", ret);
728 static int bcm2708_fb_remove(struct platform_device *dev)
730 - struct bcm2708_fb *fb = platform_get_drvdata(dev);
731 + struct bcm2708_fb_dev *fbdev = platform_get_drvdata(dev);
734 platform_set_drvdata(dev, NULL);
736 - if (fb->fb.screen_base)
737 - iounmap(fb->fb.screen_base);
738 - unregister_framebuffer(&fb->fb);
740 - dma_free_wc(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
741 - bcm_dma_chan_free(fb->dma_chan);
743 - bcm2708_fb_debugfs_deinit(fb);
744 + for (i = 0; i < fbdev->num_displays; i++) {
745 + if (fbdev->displays[i].fb.screen_base)
746 + iounmap(fbdev->displays[i].fb.screen_base);
748 + if (fbdev->displays[i].fbdev) {
749 + unregister_framebuffer(&fbdev->displays[i].fb);
750 + bcm2708_fb_debugfs_deinit(&fbdev->displays[i]);
754 - free_irq(fb->dma_irq, fb);
755 + dma_free_wc(&dev->dev, SZ_64K, fbdev->cb_base,
757 + bcm_dma_chan_free(fbdev->dma_chan);
758 + free_irq(fbdev->dma_irq, fbdev);
761 + mutex_destroy(&fbdev->dma_mutex);
765 @@ -886,10 +1077,10 @@ static struct platform_driver bcm2708_fb
766 .probe = bcm2708_fb_probe,
767 .remove = bcm2708_fb_remove,
769 - .name = DRIVER_NAME,
770 - .owner = THIS_MODULE,
771 - .of_match_table = bcm2708_fb_of_match_table,
773 + .name = DRIVER_NAME,
774 + .owner = THIS_MODULE,
775 + .of_match_table = bcm2708_fb_of_match_table,
779 static int __init bcm2708_fb_init(void)
780 --- a/include/soc/bcm2835/raspberrypi-firmware.h
781 +++ b/include/soc/bcm2835/raspberrypi-firmware.h
782 @@ -106,9 +106,15 @@ enum rpi_firmware_property_tag {
783 RPI_FIRMWARE_FRAMEBUFFER_GET_VIRTUAL_OFFSET = 0x00040009,
784 RPI_FIRMWARE_FRAMEBUFFER_GET_OVERSCAN = 0x0004000a,
785 RPI_FIRMWARE_FRAMEBUFFER_GET_PALETTE = 0x0004000b,
786 + RPI_FIRMWARE_FRAMEBUFFER_GET_LAYER = 0x0004000c,
787 + RPI_FIRMWARE_FRAMEBUFFER_GET_TRANSFORM = 0x0004000d,
788 + RPI_FIRMWARE_FRAMEBUFFER_GET_VSYNC = 0x0004000e,
789 RPI_FIRMWARE_FRAMEBUFFER_GET_TOUCHBUF = 0x0004000f,
790 RPI_FIRMWARE_FRAMEBUFFER_GET_GPIOVIRTBUF = 0x00040010,
791 RPI_FIRMWARE_FRAMEBUFFER_RELEASE = 0x00048001,
792 + RPI_FIRMWARE_FRAMEBUFFER_SET_DISPLAY_NUM = 0x00048013,
793 + RPI_FIRMWARE_FRAMEBUFFER_GET_NUM_DISPLAYS = 0x00040013,
794 + RPI_FIRMWARE_FRAMEBUFFER_GET_DISPLAY_SETTINGS = 0x00040014,
795 RPI_FIRMWARE_FRAMEBUFFER_TEST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
796 RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
797 RPI_FIRMWARE_FRAMEBUFFER_TEST_DEPTH = 0x00044005,
798 @@ -117,6 +123,8 @@ enum rpi_firmware_property_tag {
799 RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_OFFSET = 0x00044009,
800 RPI_FIRMWARE_FRAMEBUFFER_TEST_OVERSCAN = 0x0004400a,
801 RPI_FIRMWARE_FRAMEBUFFER_TEST_PALETTE = 0x0004400b,
802 + RPI_FIRMWARE_FRAMEBUFFER_TEST_LAYER = 0x0004400c,
803 + RPI_FIRMWARE_FRAMEBUFFER_TEST_TRANSFORM = 0x0004400d,
804 RPI_FIRMWARE_FRAMEBUFFER_TEST_VSYNC = 0x0004400e,
805 RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
806 RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
807 @@ -127,9 +135,12 @@ enum rpi_firmware_property_tag {
808 RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET = 0x00048009,
809 RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN = 0x0004800a,
810 RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE = 0x0004800b,
812 RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF = 0x0004801f,
813 RPI_FIRMWARE_FRAMEBUFFER_SET_GPIOVIRTBUF = 0x00048020,
814 RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC = 0x0004800e,
815 + RPI_FIRMWARE_FRAMEBUFFER_SET_LAYER = 0x0004800c,
816 + RPI_FIRMWARE_FRAMEBUFFER_SET_TRANSFORM = 0x0004800d,
817 RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT = 0x0004800f,
819 RPI_FIRMWARE_VCHIQ_INIT = 0x00048010,
820 @@ -138,6 +149,8 @@ enum rpi_firmware_property_tag {
821 RPI_FIRMWARE_GET_DMA_CHANNELS = 0x00060001,
824 +#define GET_DISPLAY_SETTINGS_PAYLOAD_SIZE 64
826 #if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE)
827 int rpi_firmware_property(struct rpi_firmware *fw,
828 u32 tag, void *data, size_t len);