1 From 4bfcd159944e7387f701cceb85b26f6d6d17fbed 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 1 file changed, 324 insertions(+), 133 deletions(-)
11 --- a/drivers/video/fbdev/bcm2708_fb.c
12 +++ b/drivers/video/fbdev/bcm2708_fb.c
14 * linux/drivers/video/bcm2708_fb.c
16 * Copyright (C) 2010 Broadcom
17 + * Copyright (C) 2018 Raspberry Pi (Trading) Ltd
19 * This file is subject to the terms and conditions of the GNU General Public
20 * License. See the file COPYING in the main directory of this archive
22 * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
26 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/errno.h>
31 #include <linux/dma-mapping.h>
32 #include <soc/bcm2835/raspberrypi-firmware.h>
33 +#include <linux/mutex.h>
35 //#define BCM2708_FB_DEBUG
36 #define MODULE_NAME "bcm2708_fb"
37 @@ -79,64 +82,150 @@ struct bcm2708_fb_stats {
41 +struct vc4_display_settings_t {
49 + u32 virtual_width_offset;
50 + u32 virtual_height_offset;
51 + unsigned long fb_bus_address;
54 +struct bcm2708_fb_dev;
58 struct platform_device *dev;
59 - struct rpi_firmware *fw;
64 - void __iomem *dma_chan_base;
65 - void *cb_base; /* DMA control blocks */
66 - dma_addr_t cb_handle;
67 struct dentry *debugfs_dir;
68 - wait_queue_head_t dma_waitq;
69 - struct bcm2708_fb_stats stats;
70 + struct dentry *debugfs_subdir;
71 unsigned long fb_bus_address;
72 - bool disable_arm_alloc;
73 + struct { u32 base, length; } gpu;
74 + struct vc4_display_settings_t display_settings;
75 + struct debugfs_regset32 screeninfo_regset;
76 + struct bcm2708_fb_dev *fbdev;
77 unsigned int image_size;
82 +#define MAX_FRAMEBUFFERS 3
84 +struct bcm2708_fb_dev {
85 + int firmware_supports_multifb;
86 + /* Protects the DMA system from multiple FB access */
87 + struct mutex dma_mutex;
90 + void __iomem *dma_chan_base;
91 + wait_queue_head_t dma_waitq;
92 + bool disable_arm_alloc;
93 + struct bcm2708_fb_stats dma_stats;
94 + void *cb_base; /* DMA control blocks */
95 + dma_addr_t cb_handle;
98 + struct rpi_firmware *fw;
99 + struct bcm2708_fb displays[MAX_FRAMEBUFFERS];
102 #define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
104 static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
106 - debugfs_remove_recursive(fb->debugfs_dir);
107 - fb->debugfs_dir = NULL;
108 + debugfs_remove_recursive(fb->debugfs_subdir);
109 + fb->debugfs_subdir = NULL;
111 + fb->fbdev->instance_count--;
113 + if (!fb->fbdev->instance_count) {
114 + debugfs_remove_recursive(fb->debugfs_dir);
115 + fb->debugfs_dir = NULL;
119 static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
122 + struct bcm2708_fb_dev *fbdev = fb->fbdev;
124 static struct debugfs_reg32 stats_registers[] = {
127 - offsetof(struct bcm2708_fb_stats, dma_copies)
131 - offsetof(struct bcm2708_fb_stats, dma_irqs)
133 + {"dma_copies", offsetof(struct bcm2708_fb_stats, dma_copies)},
134 + {"dma_irqs", offsetof(struct bcm2708_fb_stats, dma_irqs)},
137 - fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
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_lookup(DRIVER_NAME, NULL);
150 + if (!fb->debugfs_dir)
151 + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
153 if (!fb->debugfs_dir) {
154 - pr_warn("%s: could not create debugfs entry\n",
156 + dev_warn(fb->fb.dev, "%s: could not create debugfs folder\n",
161 - fb->stats.regset.regs = stats_registers;
162 - fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
163 - fb->stats.regset.base = &fb->stats;
164 + snprintf(buf, sizeof(buf), "%u", fb->display_settings.display_num);
166 + fb->debugfs_subdir = debugfs_create_dir(buf, fb->debugfs_dir);
168 debugfs_create_regset32("stats", 0444, fb->debugfs_dir,
171 + if (!fb->debugfs_subdir) {
172 + dev_warn(fb->fb.dev, "%s: could not create debugfs entry %u\n",
173 + __func__, fb->display_settings.display_num);
177 + fbdev->dma_stats.regset.regs = stats_registers;
178 + fbdev->dma_stats.regset.nregs = ARRAY_SIZE(stats_registers);
179 + fbdev->dma_stats.regset.base = &fbdev->dma_stats;
181 + debugfs_create_regset32("dma_stats", 0444, fb->debugfs_subdir,
182 + &fbdev->dma_stats.regset);
184 + fb->screeninfo_regset.regs = screeninfo;
185 + fb->screeninfo_regset.nregs = ARRAY_SIZE(screeninfo);
186 + fb->screeninfo_regset.base = &fb->fb.var;
188 + debugfs_create_regset32("screeninfo", 0444, fb->debugfs_subdir,
189 + &fb->screeninfo_regset);
191 + fbdev->instance_count++;
196 +static void set_display_num(struct bcm2708_fb *fb)
198 + if (fb && fb->fbdev && fb->fbdev->firmware_supports_multifb) {
199 + u32 tmp = fb->display_settings.display_num;
201 + if (rpi_firmware_property(fb->fbdev->fw,
202 + RPI_FIRMWARE_FRAMEBUFFER_SET_DISPLAY_NUM,
205 + dev_warn_once(fb->fb.dev,
206 + "Set display number call failed. Old GPU firmware?");
210 static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
213 @@ -214,11 +303,11 @@ static int bcm2708_fb_check_var(struct f
214 struct fb_info *info)
216 /* info input, var output */
217 - print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n",
218 + print_debug("%s(%p) %ux%u (%ux%u), %ul, %u\n",
219 __func__, info, info->var.xres, info->var.yres,
220 info->var.xres_virtual, info->var.yres_virtual,
221 - (int)info->screen_size, info->var.bits_per_pixel);
222 - print_debug("%s(%p) %dx%d (%dx%d), %d\n", __func__, var, var->xres,
223 + info->screen_size, info->var.bits_per_pixel);
224 + print_debug("%s(%p) %ux%u (%ux%u), %u\n", __func__, var, var->xres,
225 var->yres, var->xres_virtual, var->yres_virtual,
226 var->bits_per_pixel);
228 @@ -281,17 +370,24 @@ static int bcm2708_fb_set_par(struct fb_
233 - print_debug("%s(%p) %dx%d (%dx%d), %d, %d\n", __func__, info,
234 + print_debug("%s(%p) %dx%d (%dx%d), %d, %d (display %d)\n", __func__,
236 info->var.xres, info->var.yres, info->var.xres_virtual,
237 info->var.yres_virtual, (int)info->screen_size,
238 - info->var.bits_per_pixel);
239 + info->var.bits_per_pixel, value);
241 + /* Need to set the display number to act on first
242 + * Cannot do it in the tag list because on older firmware the call
243 + * will fail and stop the rest of the list being executed.
244 + * We can ignore this call failing as the default at other end is 0
246 + set_display_num(fb);
248 /* Try allocating our own buffer. We can specify all the parameters */
249 image_size = ((info->var.xres * info->var.yres) *
250 info->var.bits_per_pixel) >> 3;
252 - if (!fb->disable_arm_alloc &&
253 + if (!fb->fbdev->disable_arm_alloc &&
254 (image_size != fb->image_size || !fb->dma_addr)) {
256 dma_free_coherent(info->device, fb->image_size,
257 @@ -306,7 +402,7 @@ static int bcm2708_fb_set_par(struct fb_
261 - fb->disable_arm_alloc = true;
262 + fb->fbdev->disable_arm_alloc = true;
264 fb->image_size = image_size;
266 @@ -317,7 +413,7 @@ static int bcm2708_fb_set_par(struct fb_
267 fbinfo.screen_size = image_size;
268 fbinfo.pitch = (info->var.xres * info->var.bits_per_pixel) >> 3;
270 - ret = rpi_firmware_property_list(fb->fw, &fbinfo,
271 + ret = rpi_firmware_property_list(fb->fbdev->fw, &fbinfo,
273 if (ret || fbinfo.base != fb->dma_addr) {
274 /* Firmware either failed, or assigned a different base
275 @@ -330,7 +426,7 @@ static int bcm2708_fb_set_par(struct fb_
279 - fb->disable_arm_alloc = true;
280 + fb->fbdev->disable_arm_alloc = true;
283 /* Our allocation failed - drop into the old scheme of
284 @@ -349,7 +445,7 @@ static int bcm2708_fb_set_par(struct fb_
285 fbinfo.tag6.tag = RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH;
288 - ret = rpi_firmware_property_list(fb->fw, &fbinfo,
289 + ret = rpi_firmware_property_list(fb->fbdev->fw, &fbinfo,
292 dev_err(info->device,
293 @@ -439,7 +535,10 @@ static int bcm2708_fb_setcolreg(unsigned
294 packet->length = regno + 1;
295 memcpy(packet->cmap, fb->gpu_cmap,
296 sizeof(packet->cmap));
297 - ret = rpi_firmware_property(fb->fw,
299 + set_display_num(fb);
301 + ret = rpi_firmware_property(fb->fbdev->fw,
302 RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
304 (2 + packet->length) * sizeof(u32));
305 @@ -478,8 +577,11 @@ static int bcm2708_fb_blank(int blank_mo
309 - ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
310 + set_display_num(fb);
312 + ret = rpi_firmware_property(fb->fbdev->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
313 &value, sizeof(value));
316 dev_err(info->device, "%s(%d) failed: %d\n", __func__,
318 @@ -496,12 +598,14 @@ static int bcm2708_fb_pan_display(struct
319 info->var.yoffset = var->yoffset;
320 result = bcm2708_fb_set_par(info);
322 - pr_err("%s(%d,%d) returns=%d\n", __func__, var->xoffset,
323 + pr_err("%s(%u,%u) returns=%d\n", __func__, var->xoffset,
324 var->yoffset, result);
328 static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
329 +static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd,
332 struct bcm2708_fb *fb = to_bcm2708(info);
334 @@ -509,7 +613,9 @@ static int bcm2708_ioctl(struct fb_info
337 case FBIO_WAITFORVSYNC:
338 - ret = rpi_firmware_property(fb->fw,
339 + set_display_num(fb);
341 + ret = rpi_firmware_property(fb->fbdev->fw,
342 RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC,
343 &dummy, sizeof(dummy));
345 @@ -526,23 +632,22 @@ static int bcm2708_ioctl(struct fb_info
346 static void bcm2708_fb_fillrect(struct fb_info *info,
347 const struct fb_fillrect *rect)
349 - /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
350 cfb_fillrect(info, rect);
353 /* A helper function for configuring dma control block */
354 static void set_dma_cb(struct bcm2708_dma_cb *cb,
370 cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
371 - BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
372 - BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
373 + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
374 + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
378 @@ -560,15 +665,19 @@ static void bcm2708_fb_copyarea(struct f
379 const struct fb_copyarea *region)
381 struct bcm2708_fb *fb = to_bcm2708(info);
382 - struct bcm2708_dma_cb *cb = fb->cb_base;
383 + struct bcm2708_fb_dev *fbdev = fb->fbdev;
384 + struct bcm2708_dma_cb *cb = fbdev->cb_base;
385 int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
387 /* Channel 0 supports larger bursts and is a bit faster */
388 - int burst_size = (fb->dma_chan == 0) ? 8 : 2;
389 + int burst_size = (fbdev->dma_chan == 0) ? 8 : 2;
390 int pixels = region->width * region->height;
392 - /* Fallback to cfb_copyarea() if we don't like something */
393 - if (bytes_per_pixel > 4 ||
394 + /* If DMA is currently in use (ie being used on another FB), then
395 + * rather than wait for it to finish, just use the cfb_copyarea
397 + if (!mutex_trylock(&fbdev->dma_mutex) ||
398 + bytes_per_pixel > 4 ||
399 info->var.xres * info->var.yres > 1920 * 1200 ||
400 region->width <= 0 || region->width > info->var.xres ||
401 region->height <= 0 || region->height > info->var.yres ||
402 @@ -595,8 +704,8 @@ static void bcm2708_fb_copyarea(struct f
403 * 1920x1200 resolution at 32bpp pixel depth.
406 - dma_addr_t control_block_pa = fb->cb_handle;
407 - dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
408 + dma_addr_t control_block_pa = fbdev->cb_handle;
409 + dma_addr_t scratchbuf = fbdev->cb_handle + 16 * 1024;
410 int scanline_size = bytes_per_pixel * region->width;
411 int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
413 @@ -646,10 +755,10 @@ static void bcm2708_fb_copyarea(struct f
415 set_dma_cb(cb, burst_size,
416 fb->fb_bus_address + dy * fb->fb.fix.line_length +
417 - bytes_per_pixel * region->dx,
418 + bytes_per_pixel * region->dx,
420 fb->fb_bus_address + sy * fb->fb.fix.line_length +
421 - bytes_per_pixel * region->sx,
422 + bytes_per_pixel * region->sx,
424 region->width * bytes_per_pixel,
426 @@ -659,32 +768,33 @@ static void bcm2708_fb_copyarea(struct f
429 if (pixels < dma_busy_wait_threshold) {
430 - bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
431 - bcm_dma_wait_idle(fb->dma_chan_base);
432 + bcm_dma_start(fbdev->dma_chan_base, fbdev->cb_handle);
433 + bcm_dma_wait_idle(fbdev->dma_chan_base);
435 - void __iomem *dma_chan = fb->dma_chan_base;
436 + void __iomem *local_dma_chan = fbdev->dma_chan_base;
438 cb->info |= BCM2708_DMA_INT_EN;
439 - bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
440 - while (bcm_dma_is_busy(dma_chan)) {
441 - wait_event_interruptible(fb->dma_waitq,
442 - !bcm_dma_is_busy(dma_chan));
443 + bcm_dma_start(fbdev->dma_chan_base, fbdev->cb_handle);
444 + while (bcm_dma_is_busy(local_dma_chan)) {
445 + wait_event_interruptible(fbdev->dma_waitq,
446 + !bcm_dma_is_busy(local_dma_chan));
448 - fb->stats.dma_irqs++;
449 + fbdev->dma_stats.dma_irqs++;
451 - fb->stats.dma_copies++;
452 + fbdev->dma_stats.dma_copies++;
454 + mutex_unlock(&fbdev->dma_mutex);
457 static void bcm2708_fb_imageblit(struct fb_info *info,
458 const struct fb_image *image)
460 - /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
461 cfb_imageblit(info, image);
464 static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
466 - struct bcm2708_fb *fb = cxt;
467 + struct bcm2708_fb_dev *fbdev = cxt;
469 /* FIXME: should read status register to check if this is
470 * actually interrupting us or not, in case this interrupt
471 @@ -694,9 +804,9 @@ static irqreturn_t bcm2708_fb_dma_irq(in
474 /* acknowledge the interrupt */
475 - writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
476 + writel(BCM2708_DMA_INT, fbdev->dma_chan_base + BCM2708_DMA_CS);
478 - wake_up(&fb->dma_waitq);
479 + wake_up(&fbdev->dma_waitq);
483 @@ -729,11 +839,23 @@ static int bcm2708_fb_register(struct bc
484 fb->fb.fix.ywrapstep = 0;
485 fb->fb.fix.accel = FB_ACCEL_NONE;
487 - fb->fb.var.xres = fbwidth;
488 - fb->fb.var.yres = fbheight;
489 - fb->fb.var.xres_virtual = fbwidth;
490 - fb->fb.var.yres_virtual = fbheight;
491 - fb->fb.var.bits_per_pixel = fbdepth;
492 + /* If we have data from the VC4 on FB's, use that, otherwise use the
493 + * module parameters
495 + if (fb->display_settings.width) {
496 + fb->fb.var.xres = fb->display_settings.width;
497 + fb->fb.var.yres = fb->display_settings.height;
498 + fb->fb.var.xres_virtual = fb->fb.var.xres;
499 + fb->fb.var.yres_virtual = fb->fb.var.yres;
500 + fb->fb.var.bits_per_pixel = fb->display_settings.depth;
502 + fb->fb.var.xres = fbwidth;
503 + fb->fb.var.yres = fbheight;
504 + fb->fb.var.xres_virtual = fbwidth;
505 + fb->fb.var.yres_virtual = fbheight;
506 + fb->fb.var.bits_per_pixel = fbdepth;
509 fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
510 fb->fb.var.activate = FB_ACTIVATE_NOW;
511 fb->fb.var.nonstd = 0;
512 @@ -749,26 +871,23 @@ static int bcm2708_fb_register(struct bc
513 fb->fb.monspecs.dclkmax = 100000000;
515 bcm2708_fb_set_bitfields(&fb->fb.var);
516 - init_waitqueue_head(&fb->dma_waitq);
519 * Allocate colourmap.
522 fb_set_var(&fb->fb, &fb->fb.var);
524 ret = bcm2708_fb_set_par(&fb->fb);
529 - print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n",
530 - fbwidth, fbheight, fbdepth, fbswap);
532 ret = register_framebuffer(&fb->fb);
533 - print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
538 - print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
539 + dev_warn(fb->fb.dev, "Unable to register framebuffer (%d)\n", ret);
543 @@ -777,10 +896,18 @@ static int bcm2708_fb_probe(struct platf
545 struct device_node *fw_np;
546 struct rpi_firmware *fw;
547 - struct bcm2708_fb *fb;
551 + struct bcm2708_fb_dev *fbdev;
552 + struct { u32 base, length; } gpu_mem;
554 + fbdev = devm_kzalloc(&dev->dev, sizeof(*fbdev), GFP_KERNEL);
559 fw_np = of_parse_phandle(dev->dev.of_node, "firmware", 0);
561 /* Remove comment when booting without Device Tree is no longer supported
563 * dev_err(&dev->dev, "Missing firmware node\n");
564 @@ -788,90 +915,154 @@ static int bcm2708_fb_probe(struct platf
567 fw = rpi_firmware_get(fw_np);
571 return -EPROBE_DEFER;
573 - fb = kzalloc(sizeof(*fb), GFP_KERNEL);
577 + ret = rpi_firmware_property(fw,
578 + RPI_FIRMWARE_FRAMEBUFFER_GET_NUM_DISPLAYS,
579 + &num_displays, sizeof(u32));
581 + /* If we fail to get the number of displays, or it returns 0, then
582 + * assume old firmware that doesn't have the mailbox call, so just
585 + if (ret || num_displays == 0) {
588 + "Unable to determine number of FB's. Assuming 1\n");
591 + fbdev->firmware_supports_multifb = 1;
594 + if (num_displays > MAX_FRAMEBUFFERS) {
595 + dev_warn(&dev->dev,
596 + "More displays reported from firmware than supported in driver (%u vs %u)",
597 + num_displays, MAX_FRAMEBUFFERS);
598 + num_displays = MAX_FRAMEBUFFERS;
602 - bcm2708_fb_debugfs_init(fb);
603 + dev_info(&dev->dev, "FB found %d display(s)\n", num_displays);
605 + /* Set up the DMA information. Note we have just one set of DMA
606 + * parameters to work with all the FB's so requires synchronising when
610 + mutex_init(&fbdev->dma_mutex);
612 - fb->cb_base = dma_alloc_wc(&dev->dev, SZ_64K,
613 - &fb->cb_handle, GFP_KERNEL);
614 - if (!fb->cb_base) {
615 + fbdev->cb_base = dma_alloc_wc(&dev->dev, SZ_64K,
618 + if (!fbdev->cb_base) {
619 dev_err(&dev->dev, "cannot allocate DMA CBs\n");
624 - pr_info("BCM2708FB: allocated DMA memory %pad\n", &fb->cb_handle);
626 ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
627 - &fb->dma_chan_base, &fb->dma_irq);
628 + &fbdev->dma_chan_base,
631 - dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
632 + dev_err(&dev->dev, "Couldn't allocate a DMA channel\n");
635 - fb->dma_chan = ret;
636 + fbdev->dma_chan = ret;
638 - ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
639 - 0, "bcm2708_fb dma", fb);
640 + ret = request_irq(fbdev->dma_irq, bcm2708_fb_dma_irq,
641 + 0, "bcm2708_fb DMA", fbdev);
643 - pr_err("%s: failed to request DMA irq\n", __func__);
645 + "Failed to request DMA irq\n");
649 - pr_info("BCM2708FB: allocated DMA channel %d\n", fb->dma_chan);
650 + rpi_firmware_property(fbdev->fw,
651 + RPI_FIRMWARE_GET_VC_MEMORY,
652 + &gpu_mem, sizeof(gpu_mem));
654 + for (i = 0; i < num_displays; i++) {
655 + struct bcm2708_fb *fb = &fbdev->displays[i];
657 + fb->display_settings.display_num = i;
659 + fb->fb.device = &dev->dev;
662 + fb->gpu.base = gpu_mem.base;
663 + fb->gpu.length = gpu_mem.length;
665 + if (fbdev->firmware_supports_multifb) {
666 + ret = rpi_firmware_property(fw,
667 + RPI_FIRMWARE_FRAMEBUFFER_GET_DISPLAY_SETTINGS,
668 + &fb->display_settings,
669 + GET_DISPLAY_SETTINGS_PAYLOAD_SIZE);
671 + memset(&fb->display_settings, 0,
672 + sizeof(fb->display_settings));
676 - fb->fb.device = &dev->dev;
677 + ret = bcm2708_fb_register(fb);
679 - /* failure here isn't fatal, but we'll fail in vc_mem_copy if
680 - * fb->gpu is not valid
682 - rpi_firmware_property(fb->fw, RPI_FIRMWARE_GET_VC_MEMORY, &fb->gpu,
685 + bcm2708_fb_debugfs_init(fb);
687 - ret = bcm2708_fb_register(fb);
689 - platform_set_drvdata(dev, fb);
691 + fbdev->num_displays++;
693 + dev_info(&dev->dev,
694 + "Registered framebuffer for display %u, size %ux%u\n",
695 + fb->display_settings.display_num,
699 + // Use this to flag if this FB entry is in use.
704 + // Did we actually successfully create any FB's?
705 + if (fbdev->num_displays) {
706 + init_waitqueue_head(&fbdev->dma_waitq);
707 + platform_set_drvdata(dev, fbdev);
712 - bcm_dma_chan_free(fb->dma_chan);
713 + bcm_dma_chan_free(fbdev->dma_chan);
715 - dma_free_wc(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
716 + dma_free_wc(&dev->dev, SZ_64K, fbdev->cb_base,
721 dev_err(&dev->dev, "probe failed, err %d\n", ret);
727 static int bcm2708_fb_remove(struct platform_device *dev)
729 - struct bcm2708_fb *fb = platform_get_drvdata(dev);
730 + struct bcm2708_fb_dev *fbdev = platform_get_drvdata(dev);
733 platform_set_drvdata(dev, NULL);
735 - if (fb->fb.screen_base)
736 - iounmap(fb->fb.screen_base);
737 - unregister_framebuffer(&fb->fb);
739 - dma_free_wc(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
740 - bcm_dma_chan_free(fb->dma_chan);
742 - bcm2708_fb_debugfs_deinit(fb);
743 + for (i = 0; i < fbdev->num_displays; i++) {
744 + if (fbdev->displays[i].fb.screen_base)
745 + iounmap(fbdev->displays[i].fb.screen_base);
747 + if (fbdev->displays[i].fbdev) {
748 + unregister_framebuffer(&fbdev->displays[i].fb);
749 + bcm2708_fb_debugfs_deinit(&fbdev->displays[i]);
753 - free_irq(fb->dma_irq, fb);
754 + dma_free_wc(&dev->dev, SZ_64K, fbdev->cb_base,
756 + bcm_dma_chan_free(fbdev->dma_chan);
757 + free_irq(fbdev->dma_irq, fbdev);
760 + mutex_destroy(&fbdev->dma_mutex);
764 @@ -886,10 +1077,10 @@ static struct platform_driver bcm2708_fb
765 .probe = bcm2708_fb_probe,
766 .remove = bcm2708_fb_remove,
768 - .name = DRIVER_NAME,
769 - .owner = THIS_MODULE,
770 - .of_match_table = bcm2708_fb_of_match_table,
772 + .name = DRIVER_NAME,
773 + .owner = THIS_MODULE,
774 + .of_match_table = bcm2708_fb_of_match_table,
778 static int __init bcm2708_fb_init(void)