From 828beb45bd7f9739a819d21f55b891f2e45550fc Mon Sep 17 00:00:00 2001 From: Aaron Lindsay Date: Sat, 6 Oct 2012 18:54:37 -0400 Subject: [PATCH] Raspberry Pi VideoCore: Wait for framebuffer address if not available Sometimes the VideoCore does not immediately provide the framebuffer address, even after it has returned success via a mailbox read. --- drivers/bcm2835_videocore.c | 38 ++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/drivers/bcm2835_videocore.c b/drivers/bcm2835_videocore.c index 8cbda3c..460cc37 100644 --- a/drivers/bcm2835_videocore.c +++ b/drivers/bcm2835_videocore.c @@ -25,16 +25,16 @@ #include struct bcm2835_config { - uint32 width; - uint32 height; - uint32 vwidth; - uint32 vheight; - uint32 pitch; - uint32 color_depth; - uint32 xoffset; - uint32 yoffset; - uint32 fb_base_addr; - uint32 size; + volatile uint32 width; + volatile uint32 height; + volatile uint32 vwidth; + volatile uint32 vheight; + volatile uint32 pitch; + volatile uint32 color_depth; + volatile uint32 xoffset; + volatile uint32 yoffset; + volatile uint32 fb_base_addr; + volatile uint32 size; }; #define MAILBOX_BUFFER_SIZE (32*4*2) @@ -75,11 +75,27 @@ int bcm2835_videocore_init(struct fb *f, unsigned int color_depth) { mailbox_write(MBOX_FB, (uint32)cfg); result = mailbox_read(MBOX_FB); - if (result || !cfg->fb_base_addr) { + if (result) { print("Error: did not request a proper framebuffer\n"); return -1; } + if (!cfg->fb_base_addr) { + int i; + print("BCM2835 VideoCore returned success from framebuffer " + "setup mailbox call, but framebuffer address is " + "not yet available. Waiting...\n"); + for (i = 0; i < 1<<30 && !cfg->fb_base_addr; i++); + + if (!cfg->fb_base_addr) { + + print("Error: VideoCore did not provide framebuffer " + "base address.\n"); + return -1; + } + print("VideoCore provided framebuffer base address after %d loops.\n", i); + } + f->device = &bcm2835_fb_device; f->device->fbaddr = (void*)cfg->fb_base_addr; f->width = cfg->width;