1 From b436501db9136833c1e213d6efdb3b1c6e711bf1 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= <noralf@tronnes.org>
3 Date: Mon, 20 Jul 2015 12:20:59 +0200
4 Subject: [PATCH 137/148] fbdev: bcm2708: Use firmware API
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 Use the new firmware API instead of the legacy mailbox API.
11 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
13 arch/arm/boot/dts/bcm2708_common.dtsi | 1 +
14 drivers/video/fbdev/bcm2708_fb.c | 273 +++++++++++++++++++---------------
15 2 files changed, 152 insertions(+), 122 deletions(-)
17 --- a/arch/arm/boot/dts/bcm2708_common.dtsi
18 +++ b/arch/arm/boot/dts/bcm2708_common.dtsi
22 compatible = "brcm,bcm2708-fb";
23 + firmware = <&firmware>;
27 --- a/drivers/video/fbdev/bcm2708_fb.c
28 +++ b/drivers/video/fbdev/bcm2708_fb.c
30 #include <linux/ioport.h>
31 #include <linux/list.h>
32 #include <linux/platform_data/dma-bcm2708.h>
33 -#include <linux/platform_data/mailbox-bcm2708.h>
34 #include <linux/platform_device.h>
35 #include <linux/clk.h>
36 #include <linux/printk.h>
38 #include <asm/sizes.h>
40 #include <linux/dma-mapping.h>
41 +#include <soc/bcm2835/raspberrypi-firmware.h>
43 //#define BCM2708_FB_DEBUG
44 #define MODULE_NAME "bcm2708_fb"
45 @@ -58,15 +58,19 @@ static u32 dma_busy_wait_threshold = 1<<
46 module_param(dma_busy_wait_threshold, int, 0644);
47 MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
49 -/* this data structure describes each frame buffer device we find */
52 - u32 xres, yres, xres_virtual, yres_virtual;
54 +struct fb_alloc_tags {
55 + struct rpi_firmware_property_tag_header tag1;
57 + struct rpi_firmware_property_tag_header tag2;
58 + u32 xres_virtual, yres_virtual;
59 + struct rpi_firmware_property_tag_header tag3;
61 + struct rpi_firmware_property_tag_header tag4;
66 + struct rpi_firmware_property_tag_header tag5;
67 + u32 base, screen_size;
68 + struct rpi_firmware_property_tag_header tag6;
72 struct bcm2708_fb_stats {
73 @@ -78,9 +82,9 @@ struct bcm2708_fb_stats {
76 struct platform_device *dev;
77 - struct fbinfo_s *info;
79 + struct rpi_firmware *fw;
84 void __iomem *dma_chan_base;
85 @@ -270,69 +274,71 @@ static int bcm2708_fb_check_var(struct f
87 static int bcm2708_fb_set_par(struct fb_info *info)
90 struct bcm2708_fb *fb = to_bcm2708(info);
91 - volatile struct fbinfo_s *fbinfo = fb->info;
92 - fbinfo->xres = info->var.xres;
93 - fbinfo->yres = info->var.yres;
94 - fbinfo->xres_virtual = info->var.xres_virtual;
95 - fbinfo->yres_virtual = info->var.yres_virtual;
96 - fbinfo->bpp = info->var.bits_per_pixel;
97 - fbinfo->xoffset = info->var.xoffset;
98 - fbinfo->yoffset = info->var.yoffset;
99 - fbinfo->base = 0; /* filled in by VC */
100 - fbinfo->pitch = 0; /* filled in by VC */
101 + struct fb_alloc_tags fbinfo = {
102 + .tag1 = { RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT,
104 + .xres = info->var.xres,
105 + .yres = info->var.yres,
106 + .tag2 = { RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT,
108 + .xres_virtual = info->var.xres_virtual,
109 + .yres_virtual = info->var.yres_virtual,
110 + .tag3 = { RPI_FIRMWARE_FRAMEBUFFER_SET_DEPTH, 4, 0 },
111 + .bpp = info->var.bits_per_pixel,
112 + .tag4 = { RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET, 8, 0 },
113 + .xoffset = info->var.xoffset,
114 + .yoffset = info->var.yoffset,
115 + .tag5 = { RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE, 8, 0 },
118 + .tag6 = { RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH, 4, 0 },
123 print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
124 info->var.xres, info->var.yres, info->var.xres_virtual,
125 info->var.yres_virtual, (int)info->screen_size,
126 info->var.bits_per_pixel);
128 - /* ensure last write to fbinfo is visible to GPU */
131 - /* inform vc about new framebuffer */
132 - bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
133 + ret = rpi_firmware_property_list(fb->fw, &fbinfo, sizeof(fbinfo));
135 + dev_err(info->device,
136 + "Failed to allocate GPU framebuffer (%d)\n", ret);
140 - /* TODO: replace fb driver with vchiq version */
141 - /* wait for response */
142 - bcm_mailbox_read(MBOX_CHAN_FB, &val);
144 - /* ensure GPU writes are visible to us */
148 - fb->fb.fix.line_length = fbinfo->pitch;
150 - if (info->var.bits_per_pixel <= 8)
151 - fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
153 - fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
155 - fb->fb_bus_address = fbinfo->base;
156 - fbinfo->base &= ~0xc0000000;
157 - fb->fb.fix.smem_start = fbinfo->base;
158 - fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
159 - fb->fb.screen_size = fbinfo->screen_size;
160 - if (fb->fb.screen_base)
161 - iounmap(fb->fb.screen_base);
162 - fb->fb.screen_base =
163 - (void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
164 - if (!fb->fb.screen_base) {
165 - /* the console may currently be locked */
168 - pr_err("bcm2708_fb_set_par: Failed to set screen_base\n");
171 + if (info->var.bits_per_pixel <= 8)
172 + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
174 + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
176 + fb->fb.fix.line_length = fbinfo.pitch;
177 + fbinfo.base |= 0x40000000;
178 + fb->fb_bus_address = fbinfo.base;
179 + fbinfo.base &= ~0xc0000000;
180 + fb->fb.fix.smem_start = fbinfo.base;
181 + fb->fb.fix.smem_len = fbinfo.pitch * fbinfo.yres_virtual;
182 + fb->fb.screen_size = fbinfo.screen_size;
183 + if (fb->fb.screen_base)
184 + iounmap(fb->fb.screen_base);
185 + fb->fb.screen_base = ioremap_wc(fbinfo.base, fb->fb.screen_size);
186 + if (!fb->fb.screen_base) {
187 + /* the console may currently be locked */
190 + dev_err(info->device, "Failed to set screen_base\n");
195 - ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
196 + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d\n",
197 (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
198 - fbinfo->xres, fbinfo->yres, fbinfo->bpp,
199 - fbinfo->pitch, (int)fb->fb.screen_size, val);
200 + fbinfo.xres, fbinfo.yres, fbinfo.bpp,
201 + fbinfo.pitch, (int)fb->fb.screen_size);
207 static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
208 @@ -352,15 +358,34 @@ static int bcm2708_fb_setcolreg(unsigned
209 /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
210 if (fb->fb.var.bits_per_pixel <= 8) {
212 - /* blue [0:4], green [5:10], red [11:15] */
213 - fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
214 - ((green >> (16-6)) & 0x3f) << 5 |
215 - ((blue >> (16-5)) & 0x1f) << 0;
216 + /* blue [23:16], green [15:8], red [7:0] */
217 + fb->gpu_cmap[regno] = ((red >> 8) & 0xff) << 0 |
218 + ((green >> 8) & 0xff) << 8 |
219 + ((blue >> 8) & 0xff) << 16;
221 /* 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 */
222 /* So just call it for what looks like the last colour in a list for now. */
223 - if (regno == 15 || regno == 255)
224 - bcm2708_fb_set_par(info);
225 + if (regno == 15 || regno == 255) {
233 + packet = kmalloc(sizeof(*packet), GFP_KERNEL);
236 + packet->offset = 0;
237 + packet->length = regno + 1;
238 + memcpy(packet->cmap, fb->gpu_cmap, sizeof(packet->cmap));
239 + ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE,
240 + packet, (2 + packet->length) * sizeof(u32));
241 + if (ret || packet->offset)
242 + dev_err(info->device, "Failed to set palette (%d,%u)\n",
243 + ret, packet->offset);
246 } else if (regno < 16) {
247 fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
248 convert_bitfield(blue, &fb->fb.var.blue) |
249 @@ -372,27 +397,31 @@ static int bcm2708_fb_setcolreg(unsigned
251 static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
255 - if ( (blank_mode == FB_BLANK_NORMAL) ||
256 - (blank_mode == FB_BLANK_UNBLANK)) {
258 - p[0] = 28; // size = sizeof u32 * length of p
259 - p[1] = VCMSG_PROCESS_REQUEST; // process request
260 - p[2] = VCMSG_SET_BLANK_SCREEN; // (the tag id)
261 - p[3] = 4; // (size of the response buffer)
262 - p[4] = 4; // (size of the request data)
264 - p[6] = VCMSG_PROPERTY_END; // end tag
266 - bcm_mailbox_property(&p, p[0]);
268 - if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
271 - pr_err("bcm2708_fb_blank(%d) returns=%d p[1]=0x%x\n", blank_mode, p[5], p[1]);
272 + struct bcm2708_fb *fb = to_bcm2708(info);
276 + switch (blank_mode) {
277 + case FB_BLANK_UNBLANK:
280 + case FB_BLANK_NORMAL:
281 + case FB_BLANK_VSYNC_SUSPEND:
282 + case FB_BLANK_HSYNC_SUSPEND:
283 + case FB_BLANK_POWERDOWN:
291 + ret = rpi_firmware_property(fb->fw, RPI_FIRMWARE_FRAMEBUFFER_BLANK,
292 + &value, sizeof(value));
294 + dev_err(info->device, "bcm2708_fb_blank(%d) failed: %d\n",
300 static int bcm2708_fb_pan_display(struct fb_var_screeninfo *var, struct fb_info *info)
301 @@ -408,25 +437,25 @@ static int bcm2708_fb_pan_display(struct
303 static int bcm2708_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg)
307 - if (cmd == FBIO_WAITFORVSYNC) {
308 - p[0] = 28; // size = sizeof u32 * length of p
309 - p[1] = VCMSG_PROCESS_REQUEST; // process request
310 - p[2] = VCMSG_SET_VSYNC; // (the tag id)
311 - p[3] = 4; // (size of the response buffer)
312 - p[4] = 4; // (size of the request data)
314 - p[6] = VCMSG_PROPERTY_END; // end tag
316 - bcm_mailbox_property(&p, p[0]);
318 - if ( p[1] == VCMSG_REQUEST_SUCCESSFUL )
321 - pr_err("bcm2708_fb_ioctl %x,%lx returns=%d p[1]=0x%x\n", cmd, arg, p[5], p[1]);
322 + struct bcm2708_fb *fb = to_bcm2708(info);
327 + case FBIO_WAITFORVSYNC:
328 + ret = rpi_firmware_property(fb->fw,
329 + RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC,
330 + &dummy, sizeof(dummy));
333 + dev_err(info->device, "Unknown ioctl 0x%x\n", cmd);
339 + dev_err(info->device, "ioctl 0x%x failed (%d)\n", cmd, ret);
343 static void bcm2708_fb_fillrect(struct fb_info *info,
344 const struct fb_fillrect *rect)
345 @@ -621,20 +650,7 @@ static struct fb_ops bcm2708_fb_ops = {
346 static int bcm2708_fb_register(struct bcm2708_fb *fb)
353 - dma_alloc_coherent(&fb->dev->dev, PAGE_ALIGN(sizeof(*fb->info)), &dma,
357 - pr_err(": unable to allocate fbinfo buffer\n");
360 - fb->info = (struct fbinfo_s *)mem;
363 fb->fb.fbops = &bcm2708_fb_ops;
364 fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
365 fb->fb.pseudo_palette = fb->cmap;
366 @@ -693,9 +709,22 @@ out:
368 static int bcm2708_fb_probe(struct platform_device *dev)
370 + struct device_node *fw_np;
371 + struct rpi_firmware *fw;
372 struct bcm2708_fb *fb;
375 + fw_np = of_parse_phandle(dev->dev.of_node, "firmware", 0);
376 +/* Remove comment when booting without Device Tree is no longer supported
378 + dev_err(&dev->dev, "Missing firmware node\n");
382 + fw = rpi_firmware_get(fw_np);
384 + return -EPROBE_DEFER;
386 fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
389 @@ -704,6 +733,7 @@ static int bcm2708_fb_probe(struct platf
394 bcm2708_fb_debugfs_init(fb);
396 fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
397 @@ -737,6 +767,7 @@ static int bcm2708_fb_probe(struct platf
398 fb->dma_chan, fb->dma_chan_base);
401 + fb->fb.device = &dev->dev;
403 ret = bcm2708_fb_register(fb);
405 @@ -769,8 +800,6 @@ static int bcm2708_fb_remove(struct plat
406 dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
407 bcm_dma_chan_free(fb->dma_chan);
409 - dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
411 bcm2708_fb_debugfs_deinit(fb);
413 free_irq(fb->dma_irq, fb);