fbdev driver and sysfs question.

4 messages, 3 authors, 2004-02-13 · open the first message on its own page

fbdev driver and sysfs question.

From: James Simmons <hidden>
Date: 2004-02-11 22:26:55

I attempted to port over the vesafb driver to show up in the sysfs tree.
Unfortunely it just hanges my box. From the code can someone tell me what 
I'm doing wrong?

--- linus-2.6/drivers/video/vesafb.c	2004-01-27 19:48:12.000000000 -0800
+++ fbdev-2.6/drivers/video/vesafb.c	2004-02-10 19:43:38.000000000 -0800
@@ -19,6 +19,7 @@
 #include <linux/fb.h>
 #include <linux/ioport.h>
 #include <linux/init.h>
+#include <linux/device.h>
 #ifdef __i386__
 #include <video/edid.h>
 #endif
@@ -47,7 +48,6 @@
 	.accel	= FB_ACCEL_NONE,
 };
 
-static struct fb_info fb_info;
 static u32 pseudo_palette[17];
 
 static int             inverse   = 0;
@@ -214,8 +214,10 @@
 	return 0;
 }
 
-int __init vesafb_init(void)
+static int __init vesafb_probe(struct device *_dev)
 {
+	struct platform_device *dev = to_platform_device(_dev);
+	struct fb_info *info;
 	int video_cmap_len;
 	int i;
 
@@ -251,8 +253,13 @@
 		   spaces our resource handlers simply don't know about */
 	}
 
-        fb_info.screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
-	if (!fb_info.screen_base) {
+	info = framebuffer_alloc(0, &dev->dev); 
+	if (!info)
+		return -ENOMEM;
+	dev_set_drvdata(&dev->dev, info);
+	
+        info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
+	if (!info->screen_base) {
 		release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len);
 		printk(KERN_ERR
 		       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
@@ -261,7 +268,7 @@
 	}
 
 	printk(KERN_INFO "vesafb: framebuffer at 0x%lx, mapped to 0x%p, size %dk\n",
-	       vesafb_fix.smem_start, fb_info.screen_base, vesafb_fix.smem_len/1024);
+	       vesafb_fix.smem_start, info->screen_base, vesafb_fix.smem_len/1024);
 	printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
 	       vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
 
@@ -358,22 +365,45 @@
 		}
 	}
 	
-	fb_info.fbops = &vesafb_ops;
-	fb_info.var = vesafb_defined;
-	fb_info.fix = vesafb_fix;
-	fb_info.pseudo_palette = pseudo_palette;
-	fb_info.flags = FBINFO_FLAG_DEFAULT;
+	info->fbops = &vesafb_ops;
+	info->var = vesafb_defined;
+	info->fix = vesafb_fix;
+	info->pseudo_palette = pseudo_palette;
+	info->flags = FBINFO_FLAG_DEFAULT;
 
-	fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
+	fb_alloc_cmap(&info->cmap, video_cmap_len, 0);
 
-	if (register_framebuffer(&fb_info)<0)
+	if (register_framebuffer(info) < 0)
 		return -EINVAL;
 
 	printk(KERN_INFO "fb%d: %s frame buffer device\n",
-	       fb_info.node, fb_info.fix.id);
+	       info->node, info->fix.id);
 	return 0;
 }
 
+static struct device_driver vesafb_driver = {
+	.name	= "VESA framebuffer",
+	.probe	= vesafb_probe,
+};
+
+static struct platform_device vesafb_device = {
+	.name	= "VESA framebuffer",
+	.id	= 0,
+};
+	
+int __init vesafb_init(void)
+{
+	int ret;
+
+	ret = driver_register(&vesafb_driver);
+	if (!ret) {
+		ret = platform_device_register(&vesafb_device);
+		if (ret)
+			driver_unregister(&vesafb_driver);
+	}
+	return ret;
+}
+
 /*
  * Overrides for Emacs so that we follow Linus's tabbing style.
  * ---------------------------------------------------------------------------

Re: fbdev driver and sysfs question.

From: Greg KH <hidden>
Date: 2004-02-11 22:52:48

On Wed, Feb 11, 2004 at 10:26:45PM +0000, James Simmons wrote:
I attempted to port over the vesafb driver to show up in the sysfs tree.
Unfortunely it just hanges my box. From the code can someone tell me what 
I'm doing wrong?


+static struct device_driver vesafb_driver = {
+	.name	= "VESA framebuffer",
+	.probe	= vesafb_probe,
+};
+
+static struct platform_device vesafb_device = {
+	.name	= "VESA framebuffer",
+	.id	= 0,
+};
No release function for this device?  Brave...
+int __init vesafb_init(void)
+{
+	int ret;
+
+	ret = driver_register(&vesafb_driver);
Woah, you are registering a driver that is associated with no bus?  

Where would this driver show up in the driver model?

What are you trying to achieve here?  


+	if (!ret) {
+		ret = platform_device_register(&vesafb_device);
What are you doing with this device?  It will work this way, but would
be nicer if you hook it up to something.  Can you have more than one
vesafb_device per system?

You also need to consider changing those .name fields to something that
looks sane in the sysfs tree.

thanks,

greg k-h


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

Re: fbdev driver and sysfs question.

From: <hidden>
Date: 2004-02-11 22:58:24

On Wed, Feb 11, 2004 at 10:26:45PM +0000, James Simmons wrote:
+	info = framebuffer_alloc(0, &dev->dev); 
+	if (!info)
+		return -ENOMEM;
+	dev_set_drvdata(&dev->dev, info);
+	
+        info->screen_base = ioremap(vesafb_fix.smem_start, vesafb_fix.smem_len);
+	if (!info->screen_base) {
 		release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len);
 		printk(KERN_ERR
 		       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
	Who will free info?
-	fb_alloc_cmap(&fb_info.cmap, video_cmap_len, 0);
+	fb_alloc_cmap(&info->cmap, video_cmap_len, 0);
 
-	if (register_framebuffer(&fb_info)<0)
+	if (register_framebuffer(info) < 0)
	Who will undo allocations?  BTW, that applies to the old code too -
even if fb_alloc_cmap() doesn't require any actions on cleanup, ioremap()
definitely does.
 		return -EINVAL;

-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click

Re: fbdev driver and sysfs question.

From: James Simmons <hidden>
Date: 2004-02-13 18:45:39

quoted
+	if (!info->screen_base) {
 		release_mem_region(vesafb_fix.smem_start, vesafb_fix.smem_len);
 		printk(KERN_ERR
 		       "vesafb: abort, cannot ioremap video memory 0x%x @ 0x%lx\n",
	Who will free info?
...
	Who will undo allocations?  BTW, that applies to the old code too -
even if fb_alloc_cmap() doesn't require any actions on cleanup, ioremap()
definitely does.
release_fb_info in fbsysfs.c. That happens in the struct class release 
function. Also the fb_dealloc_cmap is called. No ioremap is called tho 
since this is driver specific. So I have the ioremap and cleanup of it 
done in the dev.remove function. 

This makes sense since we could have one driver for the hardware with 
multiple framebuffers on board. One driver and two devices. 






-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help