Skip to contentSkip to conversation

simple framebuffer driver with RPi support

PATCH Superseded Andre Heider 3 participants 12 messages Oct 24, 2013 – Oct 25, 2013

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover simple framebuffer driver with RPi support

This set adds a common simple framebuffer driver for platforms which choose to support it. RPi support is part of this set.

The driver serves two functions:
* a framebuffer driver for barebox
* pass an active framebuffer configuration to a loaded kernel

For the latter to work the loaded kernel has to be CONFIG_FB_SIMPLE enabled.

Depending on the configured video mode, the RPi video hardware sets up a framebuffer with noncontiguous horizonal lines. Patch 1, 2 and 3 prepare common fb and gui code to support that.

Patch 4 is the driver itself, patch 6 adds support for simplefb to RPi.

Patch 5 just adds a missing field on a fb related mbox response.

Thanks,
Andre

Andre Heider (6):
fb: add a stride value to struct fb_info
gui: convert graphic utils to respect the stride value
gui: convert the bmp renderer to respect the stride value
video: add a simple framebuffer driver
ARM: bcm2835: add missing mbox overscan response field
ARM: rpi: add support for simplefb

 arch/arm/boards/raspberry-pi/rpi.c        |  84 +++++++++++
 arch/arm/mach-bcm2835/include/mach/mbox.h |   1 +
 drivers/video/Kconfig                     |  12 ++
 drivers/video/Makefile                    |   1 +
 drivers/video/fb.c                        |  11 +-
 drivers/video/simplefb.c                  | 224 ++++++++++++++++++++++++++++++
 include/fb.h                              |   1 +
 include/video/simplefb.h                  |  21 +++
 lib/gui/bmp.c                             |   8 +-
 lib/gui/graphic_utils.c                   |  10 +-
 10 files changed, 362 insertions(+), 11 deletions(-)
 create mode 100644 drivers/video/simplefb.c
 create mode 100644 include/video/simplefb.h
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#1 lore raw

PATCH 1/6 fb: add a stride value to struct fb_info

Add support for framebuffers with noncontiguous horizontal lines.

Video drivers can set this value if the hardware requires it. In case a driver does not set it, the current value of xres * (bpp / 8) is used instead.

---
 drivers/video/fb.c | 11 +++++++++--
 include/fb.h       |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/video/fb.c +9 -2
index 420e4e3..e80fab9 100644
@@ -72,12 +72,16 @@ static int fb_setup_mode(struct device_d *dev, struct param_d *param,
 
 	info->xres = info->mode->xres;
 	info->yres = info->mode->yres;
+	info->stride = 0;
 
 	ret = info->fbops->fb_activate_var(info);
 
+	if (!info->stride)
+		info->stride = info->xres * (info->bits_per_pixel >> 3);
+
 	if (!ret) {
 		dev->resource[0].start = (resource_size_t)info->screen_base;
-		info->cdev.size = info->xres * info->yres * (info->bits_per_pixel >> 3);
+		info->cdev.size = info->stride * info->yres;
 		dev->resource[0].end = dev->resource[0].start + info->cdev.size - 1;
 		dev_param_set_generic(dev, param, val);
 	} else
@@ -122,9 +126,12 @@ int register_framebuffer(struct fb_info *info)
 
 	dev = &info->dev;
 
+	if (!info->stride)
+		info->stride = info->xres * (info->bits_per_pixel >> 3);
+
 	info->cdev.ops = &fb_ops;
 	info->cdev.name = asprintf("fb%d", id);
-	info->cdev.size = info->xres * info->yres * (info->bits_per_pixel >> 3);
+	info->cdev.size = info->stride * info->yres;
 	info->cdev.dev = dev;
 	info->cdev.priv = info;
 	dev->resource = xzalloc(sizeof(struct resource));
include/fb.h +1 -0
index df4ba8e..ba46954 100644
@@ -94,6 +94,7 @@ struct fb_info {
 	u32 xres;			/* visible resolution		*/
 	u32 yres;
 	u32 bits_per_pixel;		/* guess what			*/
+	u32 stride;			/* number of bytes in each line	*/
 
 	u32 grayscale;			/* != 0 Graylevels instead of colors */
 
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#5 lore raw

PATCH 2/6 gui: convert graphic utils to respect the stride value

In reply to Andre Heider
---
 lib/gui/graphic_utils.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
lib/gui/graphic_utils.c +5 -5
index 95687df..9d80fe4 100644
@@ -167,18 +167,18 @@ void rgba_blend(struct fb_info *info, struct image *img, void* buf, int height,
 {
 	unsigned char *adr;
 	int x, y;
-	int xres;
+	int stride;
 	int img_byte_per_pixel = 3;
 	void *image;
 
 	if (is_rgba)
 		img_byte_per_pixel++;
 
-	xres = info->xres;
+	stride = info->stride;
 
 	for (y = 0; y < height; y++) {
-		adr = buf + ((y + starty) * xres + startx) *
-				(info->bits_per_pixel >> 3);
+		adr = buf + (y + starty) * stride +
+				startx * (info->bits_per_pixel >> 3);
 		image = img->data + (y * img->width *img_byte_per_pixel);
 
 		for (x = 0; x < width; x++) {
@@ -219,7 +219,7 @@ int fb_open(const char * fbdev, struct screen *sc, bool offscreen)
 	sc->s.y = 0;
 	sc->s.width = sc->info.xres;
 	sc->s.height = sc->info.yres;
-	sc->fbsize = sc->s.width * sc->s.height * (sc->info.bits_per_pixel >> 3);
+	sc->fbsize = sc->info.stride * sc->s.height;
 
 	if (offscreen) {
 		/* Don't fail if malloc fails, just continue rendering directly
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 3/6 gui: convert the bmp renderer to respect the stride value

In reply to Andre Heider
---
 lib/gui/bmp.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
lib/gui/bmp.c +4 -4
index 6bf8cd0..bb4de12 100644
@@ -78,8 +78,8 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
 			image = (char *)bmp +
 					le32_to_cpu(bmp->header.data_offset);
 			image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3);
-			adr = buf + ((y + starty) * sc->s.width + startx) *
-					(sc->info.bits_per_pixel >> 3);
+			adr = buf + (y + starty) * sc->info.stride +
+					startx * (sc->info.bits_per_pixel >> 3);
 			for (x = 0; x < width; x++) {
 				int pixel;
 
@@ -100,8 +100,8 @@ static int bmp_renderer(struct screen *sc, struct surface *s, struct image *img)
 			image = (char *)bmp +
 					le32_to_cpu(bmp->header.data_offset);
 			image += (img->height - y - 1) * img->width * (bits_per_pixel >> 3);
-			adr = buf + ((y + starty) * sc->s.width + startx) *
-					(sc->info.bits_per_pixel >> 3);
+			adr = buf + (y + starty) * sc->info.stride +
+					startx * (sc->info.bits_per_pixel >> 3);
 			for (x = 0; x < width; x++) {
 				char *pixel;
 
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 4/6 video: add a simple framebuffer driver

In reply to Andre Heider

This architecture independend driver implements a framebuffer driver based on a raw memory region that may be rendered to.

It is the counterpart of the kernel driver with the same name.

Platforms can configure display devices to scan out from such a memory region and set it up with a single function call.
Doing so provides a framebuffer driver for barebox and a configuration of the corresponding kernel driver through device tree.

---
 drivers/video/Kconfig    |  12 +++
 drivers/video/Makefile   |   1 +
 drivers/video/simplefb.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++
 include/video/simplefb.h |  21 +++++
 4 files changed, 258 insertions(+)
 create mode 100644 drivers/video/simplefb.c
 create mode 100644 include/video/simplefb.h
drivers/video/Kconfig +12 -0
index 0639d9c..9afa7e8 100644
@@ -71,4 +71,16 @@ config DRIVER_VIDEO_PXA
 	  Add support for the frame buffer device found on the PXA270
 	  CPU.
 
+config DRIVER_VIDEO_SIMPLEFB
+	bool "Simple framebuffer support"
+	depends on OFTREE
+	depends on ARCH_BCM2835
+	help
+	  Say Y if you want support for a simple frame-buffer.
+
+	  This driver provides the framebuffer configuration to the kernel
+	  through device tree.
+
+	  The corresponding kernel driver has to be enabled to use this feature.
+
 endif
drivers/video/Makefile +1 -0
index 67169d1..0da7c2b 100644
@@ -9,3 +9,4 @@ obj-$(CONFIG_DRIVER_VIDEO_S3C24XX) += s3c24xx.o
 obj-$(CONFIG_DRIVER_VIDEO_PXA) += pxa.o
 obj-$(CONFIG_DRIVER_VIDEO_SDL) += sdl.o
 obj-$(CONFIG_DRIVER_VIDEO_OMAP) += omap.o
+obj-$(CONFIG_DRIVER_VIDEO_SIMPLEFB) += simplefb.o
drivers/video/simplefb.c new file +224 -0

224 lines not on this page · raw message

include/video/simplefb.h new file +21 -0
new file mode 100644
index 0000000..5949046
@@ -0,0 +1,21 @@
+/*
+ * SimpleFB driver
+ *
+ * Copyright (C) 2013 Andre Heider
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#ifndef SIMPLEFB_H
+#define SIMPLEFB_H
+
+enum simplefb_format {
+	SIMPLEFB_R5G6B5
+};
+
+struct device_d *add_simplefb_device(u32 width, u32 height, u32 stride,
+					enum simplefb_format format,
+					resource_size_t start,
+					resource_size_t size);
+
+#endif
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 5/6 ARM: bcm2835: add missing mbox overscan response field

In reply to Andre Heider

Add the missing "right" field to struct bcm2835_mbox_tag_overscan.

---
 arch/arm/mach-bcm2835/include/mach/mbox.h | 1 +
 1 file changed, 1 insertion(+)
arch/arm/mach-bcm2835/include/mach/mbox.h +1 -0
index 6c36389..fb8a9bf 100644
@@ -355,6 +355,7 @@ struct bcm2835_mbox_tag_overscan {
 			u32 top;
 			u32 bottom;
 			u32 left;
+			u32 right;
 		} resp;
 	} body;
 };
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 6/6 ARM: rpi: add support for simplefb

In reply to Andre Heider

Setup a framebuffer using the mailbox driver and register it as simplefb.

---
 arch/arm/boards/raspberry-pi/rpi.c | 84 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
arch/arm/boards/raspberry-pi/rpi.c +84 -0
index 06c43f3..3e9d62b 100644
@@ -22,6 +22,7 @@
 #include <envfs.h>
 #include <asm/armlinux.h>
 #include <generated/mach-types.h>
+#include <video/simplefb.h>
 
 #include <mach/core.h>
 #include <mach/mbox.h>
@@ -38,6 +39,25 @@ struct msg_get_clock_rate {
 	u32 end_tag;
 };
 
+struct msg_fb_query {
+	struct bcm2835_mbox_hdr hdr;
+	struct bcm2835_mbox_tag_physical_w_h physical_w_h;
+	u32 end_tag;
+};
+
+struct msg_fb_setup {
+	struct bcm2835_mbox_hdr hdr;
+	struct bcm2835_mbox_tag_physical_w_h physical_w_h;
+	struct bcm2835_mbox_tag_virtual_w_h virtual_w_h;
+	struct bcm2835_mbox_tag_depth depth;
+	struct bcm2835_mbox_tag_pixel_order pixel_order;
+	struct bcm2835_mbox_tag_alpha_mode alpha_mode;
+	struct bcm2835_mbox_tag_virtual_offset virtual_offset;
+	struct bcm2835_mbox_tag_allocate_buffer allocate_buffer;
+	struct bcm2835_mbox_tag_pitch pitch;
+	u32 end_tag;
+};
+
 static int rpi_get_arm_mem(u32 *size)
 {
 	BCM2835_MBOX_STACK_ALIGN(struct msg_get_arm_mem, msg);
@@ -79,6 +99,69 @@ static int rpi_register_clkdev(u32 clock_id, const char *name)
 	return 0;
 }
 
+#ifdef CONFIG_DRIVER_VIDEO_SIMPLEFB
+static int rpi_fb_init(void)
+{
+	BCM2835_MBOX_STACK_ALIGN(struct msg_fb_query, msg_query);
+	BCM2835_MBOX_STACK_ALIGN(struct msg_fb_setup, msg_setup);
+	u32 w, h, stride, fb_address, fb_size;
+	int ret;
+
+	BCM2835_MBOX_INIT_HDR(msg_query);
+	BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_query->physical_w_h,
+					GET_PHYSICAL_W_H);
+	ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_query->hdr);
+	if (ret) {
+		printf("could not query display resolution\n");
+		return ret;
+	}
+
+	w = msg_query->physical_w_h.body.resp.width;
+	h = msg_query->physical_w_h.body.resp.height;
+
+	BCM2835_MBOX_INIT_HDR(msg_setup);
+	BCM2835_MBOX_INIT_TAG(&msg_setup->physical_w_h, SET_PHYSICAL_W_H);
+	msg_setup->physical_w_h.body.req.width = w;
+	msg_setup->physical_w_h.body.req.height = h;
+	BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_w_h, SET_VIRTUAL_W_H);
+	msg_setup->virtual_w_h.body.req.width = w;
+	msg_setup->virtual_w_h.body.req.height = h;
+	BCM2835_MBOX_INIT_TAG(&msg_setup->depth, SET_DEPTH);
+	msg_setup->depth.body.req.bpp = 16;
+	BCM2835_MBOX_INIT_TAG(&msg_setup->pixel_order, SET_PIXEL_ORDER);
+	msg_setup->pixel_order.body.req.order = BCM2835_MBOX_PIXEL_ORDER_BGR;
+	BCM2835_MBOX_INIT_TAG(&msg_setup->alpha_mode, SET_ALPHA_MODE);
+	msg_setup->alpha_mode.body.req.alpha = BCM2835_MBOX_ALPHA_MODE_IGNORED;
+	BCM2835_MBOX_INIT_TAG(&msg_setup->virtual_offset, SET_VIRTUAL_OFFSET);
+	msg_setup->virtual_offset.body.req.x = 0;
+	msg_setup->virtual_offset.body.req.y = 0;
+	BCM2835_MBOX_INIT_TAG(&msg_setup->allocate_buffer, ALLOCATE_BUFFER);
+	msg_setup->allocate_buffer.body.req.alignment = 0x100;
+	BCM2835_MBOX_INIT_TAG_NO_REQ(&msg_setup->pitch, GET_PITCH);
+
+	ret = bcm2835_mbox_call_prop(BCM2835_MBOX_PROP_CHAN, &msg_setup->hdr);
+	if (ret) {
+		printf("could not configure display\n");
+		return ret;
+	}
+
+	w = msg_setup->physical_w_h.body.resp.width;
+	h = msg_setup->physical_w_h.body.resp.height;
+	stride = msg_setup->pitch.body.resp.pitch;
+	fb_address = msg_setup->allocate_buffer.body.resp.fb_address;
+	fb_size = msg_setup->allocate_buffer.body.resp.fb_size;
+
+	add_simplefb_device(w, h, stride, SIMPLEFB_R5G6B5, fb_address, fb_size);
+
+	return 0;
+}
+#else
+static inline int rpi_fb_init(void)
+{
+	return -ENODEV;
+}
+#endif
+
 static int rpi_mem_init(void)
 {
 	u32 size = 0;
@@ -141,6 +224,7 @@ static int rpi_devices_init(void)
 {
 	armlinux_set_architecture(MACH_TYPE_BCM2708);
 	armlinux_set_bootparams((void *)(0x00000100));
+	rpi_fb_init();
 	rpi_env_init();
 	return 0;
 }
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw
In reply to Andre Heider
Quoted 6 lines · Andre Heider

This set adds a common simple framebuffer driver for platforms which choose to support it. RPi support is part of this set.

The driver serves two functions:
* a framebuffer driver for barebox
* pass an active framebuffer configuration to a loaded kernel

Pondering over this again, this is probably the wrong approach. There's no need for a distinct simplefb driver for barebox, bcm2835 can have its own fb driver like everyone else, and the simplefb configuration for the kernel can be done independent of the fb barebox driver in use...

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#2 lore raw

Re: [PATCH 1/6] fb: add a stride value to struct fb_info

In reply to Andre Heider
Quoted 5 lines · Andre Heider

Add support for framebuffers with noncontiguous horizontal lines.

Video drivers can set this value if the hardware requires it. In case a driver does not set it, the current value of xres * (bpp / 8) is used instead.

we never use this in linux ever

so do not do this in barebox either

Best Regards,
J.

Quoted 63 lines
---
 drivers/video/fb.c | 11 +++++++++--
 include/fb.h       |  1 +
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/video/fb.c +9 -2
index 420e4e3..e80fab9 100644
@@ -72,12 +72,16 @@ static int fb_setup_mode(struct device_d *dev, struct param_d *param,
 
 	info->xres = info->mode->xres;
 	info->yres = info->mode->yres;
+	info->stride = 0;
 
 	ret = info->fbops->fb_activate_var(info);
 
+	if (!info->stride)
+		info->stride = info->xres * (info->bits_per_pixel >> 3);
+
 	if (!ret) {
 		dev->resource[0].start = (resource_size_t)info->screen_base;
-		info->cdev.size = info->xres * info->yres * (info->bits_per_pixel >> 3);
+		info->cdev.size = info->stride * info->yres;
 		dev->resource[0].end = dev->resource[0].start + info->cdev.size - 1;
 		dev_param_set_generic(dev, param, val);
 	} else
@@ -122,9 +126,12 @@ int register_framebuffer(struct fb_info *info)
 
 	dev = &info->dev;
 
+	if (!info->stride)
+		info->stride = info->xres * (info->bits_per_pixel >> 3);
+
 	info->cdev.ops = &fb_ops;
 	info->cdev.name = asprintf("fb%d", id);
-	info->cdev.size = info->xres * info->yres * (info->bits_per_pixel >> 3);
+	info->cdev.size = info->stride * info->yres;
 	info->cdev.dev = dev;
 	info->cdev.priv = info;
 	dev->resource = xzalloc(sizeof(struct resource));
include/fb.h +1 -0
index df4ba8e..ba46954 100644
@@ -94,6 +94,7 @@ struct fb_info {
 	u32 xres;			/* visible resolution		*/
 	u32 yres;
 	u32 bits_per_pixel;		/* guess what			*/
+	u32 stride;			/* number of bytes in each line	*/
 
 	u32 grayscale;			/* != 0 Graylevels instead of colors */
 
Signature · 7 lines
1.8.3.2


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#3 lore raw

Re: [PATCH 1/6] fb: add a stride value to struct fb_info

Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Andre Heider

Add support for framebuffers with noncontiguous horizontal lines.

Video drivers can set this value if the hardware requires it. In case a driver does not set it, the current value of xres * (bpp / 8) is used instead.

we never use this in linux ever

so do not do this in barebox either

I assume you mean the provided fallback value?
And consequently converting all drivers to set the introduced stride value themselves?

In that case, I considered doing that. I just don't have the hardware to test all the drivers that's going to touch.

Thanks,
Andre

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#4 lore raw

Re: [PATCH 1/6] fb: add a stride value to struct fb_info

In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines · Andre Heider

Add support for framebuffers with noncontiguous horizontal lines.

Video drivers can set this value if the hardware requires it. In case a driver does not set it, the current value of xres * (bpp / 8) is used instead.

we never use this in linux ever

so do not do this in barebox either

Liunux has this value aswell. It's just called line_length there. As we mostly resemble the fbdev API we should name it like this in barebox aswell.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw
In reply to Andre Heider
Quoted 11 lines · Andre Heider
Quoted 6 lines · Andre Heider

This set adds a common simple framebuffer driver for platforms which choose to support it. RPi support is part of this set.

The driver serves two functions:
* a framebuffer driver for barebox
* pass an active framebuffer configuration to a loaded kernel

Pondering over this again, this is probably the wrong approach. There's no need for a distinct simplefb driver for barebox, bcm2835 can have its own fb driver like everyone else,

Right,

Quoted 2 lines

and the simplefb configuration for the
kernel can be done independent of the fb barebox driver in use...

Yes.

I think we should have an option whether a framebuffer should be kept enabled when starting a kernel. If yes, then we have to resever the memory for the framebuffer and create the simplefb node. If not, we have to disable the framebuffer.

Sascha

Signature · 9 lines
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox