aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/brcm2708/patches-4.1/0151-bcm2835-camera-planar-packed-stride-length.patch
blob: 2681c34d1ee002b2b5ce9dc78113e2988f89a6ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
From 4e2638fe451b09fc2ba0a98b433f06b5a8986093 Mon Sep 17 00:00:00 2001
From: Garrett <g@floft.net>
Date: Thu, 2 Jul 2015 19:32:04 -0500
Subject: [PATCH 151/203] bcm2835 camera planar/packed stride length

Added a field to the mmal_fmt struct used to compute the bytes per line
when using a particular format. This results in the correct stride being
calculated even when the format is planar.

Signed-off-by: Garrett Wilson <g@floft.net>
---
 drivers/media/platform/bcm2835/bcm2835-camera.c | 26 +++++++++++++++++++------
 drivers/media/platform/bcm2835/mmal-common.h    |  1 +
 2 files changed, 21 insertions(+), 6 deletions(-)

--- a/drivers/media/platform/bcm2835/bcm2835-camera.c
+++ b/drivers/media/platform/bcm2835/bcm2835-camera.c
@@ -88,12 +88,13 @@ static const struct v4l2_fract
 /* video formats */
 static struct mmal_fmt formats[] = {
 	{
-	 .name = "4:2:0, packed YUV",
+	 .name = "4:2:0, planar, YUV",
 	 .fourcc = V4L2_PIX_FMT_YUV420,
 	 .flags = 0,
 	 .mmal = MMAL_ENCODING_I420,
 	 .depth = 12,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 1,
 	 },
 	{
 	 .name = "4:2:2, packed, YUYV",
@@ -102,6 +103,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_YUYV,
 	 .depth = 16,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 2,
 	 },
 	{
 	 .name = "RGB24 (LE)",
@@ -110,6 +112,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_BGR24,
 	 .depth = 24,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 3,
 	 },
 	{
 	 .name = "JPEG",
@@ -118,6 +121,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_JPEG,
 	 .depth = 8,
 	 .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
+	 .ybbp = 0,
 	 },
 	{
 	 .name = "H264",
@@ -126,6 +130,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_H264,
 	 .depth = 8,
 	 .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
+	 .ybbp = 0,
 	 },
 	{
 	 .name = "MJPEG",
@@ -134,6 +139,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_MJPEG,
 	 .depth = 8,
 	 .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
+	 .ybbp = 0,
 	 },
 	{
 	 .name = "4:2:2, packed, YVYU",
@@ -142,6 +148,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_YVYU,
 	 .depth = 16,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 2,
 	 },
 	{
 	 .name = "4:2:2, packed, VYUY",
@@ -150,6 +157,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_VYUY,
 	 .depth = 16,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 2,
 	 },
 	{
 	 .name = "4:2:2, packed, UYVY",
@@ -158,14 +166,16 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_UYVY,
 	 .depth = 16,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 2,
 	 },
 	{
-	 .name = "4:2:0, packed, NV12",
+	 .name = "4:2:0, planar, NV12",
 	 .fourcc = V4L2_PIX_FMT_NV12,
 	 .flags = 0,
 	 .mmal = MMAL_ENCODING_NV12,
 	 .depth = 12,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 1,
 	 },
 	{
 	 .name = "RGB24 (BE)",
@@ -174,22 +184,25 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_RGB24,
 	 .depth = 24,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 3,
 	 },
 	{
-	 .name = "4:2:0, packed YVU",
+	 .name = "4:2:0, planar, YVU",
 	 .fourcc = V4L2_PIX_FMT_YVU420,
 	 .flags = 0,
 	 .mmal = MMAL_ENCODING_YV12,
 	 .depth = 12,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 1,
 	 },
 	{
-	 .name = "4:2:0, packed, NV21",
+	 .name = "4:2:0, planar, NV21",
 	 .fourcc = V4L2_PIX_FMT_NV21,
 	 .flags = 0,
 	 .mmal = MMAL_ENCODING_NV21,
 	 .depth = 12,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 1,
 	 },
 	{
 	 .name = "RGB32 (BE)",
@@ -198,6 +211,7 @@ static struct mmal_fmt formats[] = {
 	 .mmal = MMAL_ENCODING_BGRA,
 	 .depth = 32,
 	 .mmal_component = MMAL_COMPONENT_CAMERA,
+	 .ybbp = 4,
 	 },
 };
 
@@ -771,7 +785,7 @@ static int vidioc_g_fbuf(struct file *fi
 	a->fmt.width = preview_port->es.video.width;
 	a->fmt.height = preview_port->es.video.height;
 	a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
-	a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
+	a->fmt.bytesperline = preview_port->es.video.width;
 	a->fmt.sizeimage = (preview_port->es.video.width *
 			       preview_port->es.video.height * 3)>>1;
 	a->fmt.colorspace = V4L2_COLORSPACE_SMPTE170M;
@@ -894,7 +908,7 @@ static int vidioc_try_fmt_vid_cap(struct
 
 	v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
 			      &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
-	f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
+	f->fmt.pix.bytesperline = f->fmt.pix.width * mfmt->ybbp;
 
 	/* Image buffer has to be padded to allow for alignment, even though
 	 * we then remove that padding before delivering the buffer.
--- a/drivers/media/platform/bcm2835/mmal-common.h
+++ b/drivers/media/platform/bcm2835/mmal-common.h
@@ -30,6 +30,7 @@ struct mmal_fmt {
 	u32   mmal;
 	int   depth;
 	u32   mmal_component;  /* MMAL component index to be used to encode */
+	u32   ybbp;            /* depth of first Y plane for planar formats */
 };
 
 /* buffer for one video frame */
dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
From d338b1299a0c452f5bb4ccedaf5bc48dcd60d02a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= <noralf@tronnes.org>
Date: Mon, 20 Jul 2015 12:20:59 +0200
Subject: [PATCH 137/222] fbdev: bcm2708: Use firmware API
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Use the new firmware API instead of the legacy mailbox API.

Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
---
 arch/arm/boot/dts/bcm2708_common.dtsi |   1 +
 drivers/video/fbdev/bcm2708_fb.c      | 273 +++++++++++++++++++---------------
 2 files changed, 152 insertions(+), 122 deletions(-)

--- a/arch/arm/boot/dts/bcm2708_common.dtsi
+++ b/arch/arm/boot/dts/bcm2708_common.dtsi
@@ -217,6 +217,7 @@
 
 		fb: fb {
 			compatible = "brcm,bcm2708-fb";
+			firmware = <&firmware>;
 			status = "disabled";
 		};
 
--- a/drivers/video/fbdev/bcm2708_fb.c
+++ b/drivers/video/fbdev/bcm2708_fb.c
@@ -25,7 +25,6 @@
 #include <linux/ioport.h>
 #include <linux/list.h>
 #include <linux/platform_data/dma-bcm2708.h>
-#include <linux/platform_data/mailbox-bcm2708.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
 #include <linux/printk.h>
@@ -34,6 +33,7 @@
 #include <asm/sizes.h>
 #include <linux/io.h>
 #include <linux/dma-mapping.h>
+#include <soc/bcm2835/raspberrypi-firmware.h>
 
 //#define BCM2708_FB_DEBUG
 #define MODULE_NAME "bcm2708_fb"
@@ -58,15 +58,19 @@ static u32 dma_busy_wait_threshold = 1<<
 module_param(dma_busy_wait_threshold, int, 0644);
 MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
 
-/* this data structure describes each frame buffer device we find */
-
-struct fbinfo_s {
-	u32 xres, yres, xres_virtual, yres_virtual;
-	u32 pitch, bpp;
+struct fb_alloc_tags {
+	struct rpi_firmware_property_tag_header tag1;
+	u32 xres, yres;
+	struct rpi_firmware_property_tag_header tag2;
+	u32 xres_virtual, yres_virtual;
+	struct rpi_firmware_property_tag_header tag3;
+	u32 bpp;
+	struct rpi_firmware_property_tag_header tag4;
 	u32 xoffset, yoffset;
-	u32 base;
-	u32 screen_size;
-	u16 cmap[256];
+	struct rpi_firmware_property_tag_header tag5;
+	u32 base, screen_size;
+	struct rpi_firmware_property_tag_header tag6;
+	u32 pitch;
 };
 
 struct bcm2708_fb_stats {
@@ -78,9 +82,9 @@ struct bcm2708_fb_stats {
 struct bcm2708_fb {
 	struct fb_info fb;
 	struct platform_device *dev;
-	struct fbinfo_s *info;
-	dma_addr_t dma;
+	struct rpi_firmware *fw;
 	u32 cmap[16];
+	u32 gpu_cmap[256];
 	int dma_chan;
 	int dma_irq;
 	void __iomem *dma_chan_base;
@@ -270,69 +274,71 @@ static int bcm2708_fb_check_var(struct f
 
 static int bcm2708_fb_set_par(struct fb_info *info)
 {
-	uint32_t val = 0;
 	struct bcm2708_fb *fb = to_bcm2708(info);
-	volatile struct fbinfo_s *fbinfo = fb->info;
-	fbinfo->xres = info->var.xres;
-	fbinfo->yres = info->var.yres;
-	fbinfo->xres_virtual = info->var.xres_virtual;
-	fbinfo->yres_virtual = info->var.yres_virtual;
-	fbinfo->bpp = info->var.bits_per_pixel;
-	fbinfo->xoffset = info->var.xoffset;
-	fbinfo->yoffset = info->var.yoffset;
-	fbinfo->base = 0;	/* filled in by VC */
-	fbinfo->pitch = 0;	/* filled in by VC */
+	struct fb_alloc_tags fbinfo = {
+		.tag1 = { RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT,
+			  8, 0, },
+			.xres = info->var.xres,
+			.yres = info->var.yres,
+		.tag2 = { RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT,
+			  8, 0, },
+			.xres_virtual = info->var.xres_virtual,
+			.yres_virtual = info->var.yres_virtual,
+		.tag3 = { RPI_FIRMWARE_FRAMEBUFFER_SET_DEPTH, 4, 0 },
+			.bpp = info->var.bits_per_pixel,
+		.tag4 = { RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET, 8, 0 },
+			.xoffset = info->var.xoffset,
+			.yoffset = info->var.yoffset,
+		.tag5 = { RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE, 8, 0 },
+			.base = 0,
+			.screen_size = 0,
+		.tag6 = { RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH, 4, 0 },
+			.pitch = 0,
+	};
+	int ret;
 
 	print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
 		info->var.xres, info->var.yres, info->var.xres_virtual,
 		info->var.yres_virtual, (int)info->screen_size,
 		info->var.bits_per_pixel);
 
-	/* ensure last write to fbinfo is visible to GPU */
-	wmb();
-
-	/* inform vc about new framebuffer */
-	bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
+	ret = rpi_firmware_property_list(fb->fw, &fbinfo, sizeof(fbinfo));
+	if (ret) {
+		dev_err(info->device,
+			"Failed to allocate GPU framebuffer (%d)\n", ret);
+		return ret;
+	}
 
-	/* TODO: replace fb driver with vchiq version */
-	/* wait for response */
-	bcm_mailbox_read(MBOX_CHAN_FB, &val);
-
-	/* ensure GPU writes are visible to us */
-	rmb();
-
-        if (val == 0) {
-		fb->fb.fix.line_length = fbinfo->pitch;
-
-		if (info->var.bits_per_pixel <= 8)
-			fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
-		else
-			fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
-
-		fb->fb_bus_address = fbinfo->base;
-		fbinfo->base &= ~0xc0000000;
-		fb->fb.fix.smem_start = fbinfo->base;
-		fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
-		fb->fb.screen_size = fbinfo->screen_size;
-		if (fb->fb.screen_base)
-			iounmap(fb->fb.screen_base);
-		fb->fb.screen_base =
-			(void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
-		if (!fb->fb.screen_base) {
-			/* the console may currently be locked */
-			console_trylock();
-			console_unlock();
-			pr_err("bcm2708_fb_set_par: Failed to set screen_base\n");
-			return -EIO;
-		}
+	if (info->var.bits_per_pixel <= 8)
+		fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
+	else
+		fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
+
+	fb->fb.fix.line_length = fbinfo.pitch;
+	fbinfo.base |= 0x40000000;
+	fb->fb_bus_address = fbinfo.base;
+	fbinfo.base &= ~0xc0000000;
+	fb->fb.fix.smem_start = fbinfo.base;
+	fb->fb.fix.smem_len = fbinfo.pitch * fbinfo.yres_virtual;
+	fb->fb.screen_size = fbinfo.screen_size;
+	if (fb->fb.screen_base)
+		iounmap(fb->fb.screen_base);
+	fb->fb.screen_base = ioremap_wc(fbinfo.base, fb->fb.screen_size);
+	if (!fb->fb.screen_base) {
+		/* the console may currently be locked */
+		console_trylock();
+		console_unlock();
+		dev_err(info->device, "Failed to set screen_base\n");
+		return -ENOMEM;
 	}
+
 	print_debug
-	    ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
+	    ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d\n",
 	     (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
-	     fbinfo->xres, fbinfo->yres, fbinfo->bpp,
-	     fbinfo->pitch, (int)fb->fb.screen_size, val);
+	     fbinfo.xres, fbinfo.yres, fbinfo.bpp,
+	     fbinfo.pitch, (int)fb->fb.screen_size);
 
-	return val;
+	return 0;
 }
 
 static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
@@ -352,15 +358,34 @@ static int bcm2708_fb_setcolreg(unsigned
 	/*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
 	if (fb->fb.var.bits_per_pixel <= 8) {
 		if (regno < 256) {
-			/* blue [0:4], green [5:10], red [11:15] */
-			fb->info->cmap[regno] = ((red   >> (16-5)) & 0x1f) << 11 |
-						((green >> (16-6)) & 0x3f) << 5 |
-						((blue  >> (16-5)) & 0x1f) << 0;
+			/* blue [23:16], green [15:8], red [7:0] */
+			fb->gpu_cmap[regno] = ((red   >> 8) & 0xff) << 0 |
+					      ((green >> 8) & 0xff) << 8 |
+					      ((blue  >> 8) & 0xff) << 16;
 		}
 		/* Hack: we need to tell GPU the palette has changed, but currently bcm2708_fb_set_par takes noticable time when called for every (256) colour */
 		/* So just call it for what looks like the last colour in a list for now. */
-		if (regno == 15 || regno == 255)
-			bcm2708_fb_set_par(info);
+		if (regno == 15 || regno == 255) {
+			struct packet {
+				u32 offset;
+				u32 length;
+				u32 cmap[256];
+			} *packet;
+			int ret;
+
+			packet = kmalloc(sizeof(*packet), GFP_KERNEL);
+			if (!packet)
+				return -ENOMEM;
+			packet->offset = 0;
+			packet->length = regno + 1;
+			memcpy(packet->cmap, fb->gpu_cmap, sizeof(packet->cmap));
+			ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
+						    packet, (2 + packet->length) * sizeof(u32));
+			if (ret || packet->offset)
+				dev_err(info->device, "Failed to set palette (%d,%u)\n",
+					ret, packet->offset);
+			kfree(packet);
+		}
         } else if (regno < 16) {
 		fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
 		    convert_bitfield(blue, &fb->fb.var.blue) |
@@ -372,27 +397,31 @@ static int bcm2708_fb_setcolreg(unsigned
 
 static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
 {
-	s32 result = -1;
-	u32 p[7];
-	if ( 	(blank_mode == FB_BLANK_NORMAL) ||
-		(blank_mode == FB_BLANK_UNBLANK)) {
-
-		p[0] = 28; //  size = sizeof u32 * length of p
-		p[1] = VCMSG_PROCESS_REQUEST; // process request
-		p[2] = VCMSG_SET_BLANK_SCREEN; // (the tag id)
-		p[3] = 4; // (size of the response buffer)
-		p[4] = 4; // (size of the request data)
-		p[5] = blank_mode;
-		p[6] = VCMSG_PROPERTY_END; // end tag
-
-		bcm_mailbox_property(&p, p[0]);
-
-		if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
-			result = 0;
-		else
-			pr_err("bcm2708_fb_blank(%d) returns=%d p[1]=0x%x\n", blank_mode, p[5], p[1]);
+	struct bcm2708_fb *fb = to_bcm2708(info);
+	u32 value;
+	int ret;
+
+	switch (blank_mode) {
+	case FB_BLANK_UNBLANK:
+		value = 0;
+		break;
+	case FB_BLANK_NORMAL:
+	case FB_BLANK_VSYNC_SUSPEND:
+	case FB_BLANK_HSYNC_SUSPEND:
+	case FB_BLANK_POWERDOWN:
+		value = 1;
+		break;
+	default:
+		return -EINVAL;
 	}
-	return result;
+
+	ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
+				    &value, sizeof(value));
+	if (ret)
+		dev_err(info->device, "bcm2708_fb_blank(%d) failed: %d\n",
+			blank_mode, ret);
+
+	return ret;
 }
 
 static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
@@ -408,25 +437,25 @@ static int bcm2708_fb_pan_display(struct
 
 static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
 {
-	s32 result = -1;
-	u32 p[7];
-	if (cmd == FBIO_WAITFORVSYNC) {
-		p[0] = 28; //  size = sizeof u32 * length of p
-		p[1] = VCMSG_PROCESS_REQUEST; // process request
-		p[2] = VCMSG_SET_VSYNC; // (the tag id)
-		p[3] = 4; // (size of the response buffer)
-		p[4] = 4; // (size of the request data)
-		p[5] = 0; // dummy
-		p[6] = VCMSG_PROPERTY_END; // end tag
-
-		bcm_mailbox_property(&p, p[0]);
-
-		if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
-			result = 0;
-		else
-			pr_err("bcm2708_fb_ioctl %x,%lx returns=%d p[1]=0x%x\n", cmd, arg, p[5], p[1]);
+	struct bcm2708_fb *fb = to_bcm2708(info);
+	u32 dummy = 0;
+	int ret;
+
+	switch (cmd) {
+	case FBIO_WAITFORVSYNC:
+		ret = rpi_firmware_property(fb->fw,
+					    RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC,
+					    &dummy, sizeof(dummy));
+		break;
+	default:
+		dev_err(info->device, "Unknown ioctl 0x%x\n", cmd);
+		return -EINVAL;
 	}
-	return result;
+
+	if (ret)
+		dev_err(info->device, "ioctl 0x%x failed (%d)\n", cmd, ret);
+
+	return ret;
 }
 static void bcm2708_fb_fillrect(struct fb_info *info,
 				const struct fb_fillrect *rect)
@@ -621,20 +650,7 @@ static struct fb_ops bcm2708_fb_ops = {
 static int bcm2708_fb_register(struct bcm2708_fb *fb)
 {
 	int ret;
-	dma_addr_t dma;
-	void *mem;
 
-	mem =
-	    dma_alloc_coherent(&fb->dev->dev, PAGE_ALIGN(sizeof(*fb->info)), &dma,
-			       GFP_KERNEL);
-
-	if (NULL == mem) {
-		pr_err(": unable to allocate fbinfo buffer\n");
-		ret = -ENOMEM;
-	} else {
-		fb->info = (struct fbinfo_s *)mem;
-		fb->dma = dma;
-	}
 	fb->fb.fbops = &bcm2708_fb_ops;
 	fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
 	fb->fb.pseudo_palette = fb->cmap;
@@ -693,9 +709,22 @@ out:
 
 static int bcm2708_fb_probe(struct platform_device *dev)
 {
+	struct device_node *fw_np;
+	struct rpi_firmware *fw;
 	struct bcm2708_fb *fb;
 	int ret;
 
+	fw_np = of_parse_phandle(dev->dev.of_node, "firmware", 0);
+/* Remove comment when booting without Device Tree is no longer supported
+	if (!fw_np) {
+		dev_err(&dev->dev, "Missing firmware node\n");
+		return -ENOENT;
+	}
+*/
+	fw = rpi_firmware_get(fw_np);
+	if (!fw)
+		return -EPROBE_DEFER;
+
 	fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
 	if (!fb) {
 		dev_err(&dev->dev,
@@ -704,6 +733,7 @@ static int bcm2708_fb_probe(struct platf
 		goto free_region;
 	}
 
+	fb->fw = fw;
 	bcm2708_fb_debugfs_init(fb);
 
 	fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
@@ -737,6 +767,7 @@ static int bcm2708_fb_probe(struct platf
 	       fb->dma_chan, fb->dma_chan_base);
 
 	fb->dev = dev;
+	fb->fb.device = &dev->dev;
 
 	ret = bcm2708_fb_register(fb);
 	if (ret == 0) {
@@ -769,8 +800,6 @@ static int bcm2708_fb_remove(struct plat
 	dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
 	bcm_dma_chan_free(fb->dma_chan);
 
-	dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
-			  fb->dma);
 	bcm2708_fb_debugfs_deinit(fb);
 
 	free_irq(fb->dma_irq, fb);