[PATCH] fb: make fb device a pure device

Sascha Hauer s.hauer at pengutronix.de
Tue Aug 6 09:55:05 EDT 2013


Makes the code simpler and makes the framebuffer layer independent
of initcalls.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 drivers/video/fb.c | 98 +++++++++++++++++++-----------------------------------
 1 file changed, 35 insertions(+), 63 deletions(-)

diff --git a/drivers/video/fb.c b/drivers/video/fb.c
index a4a8b00..420e4e3 100644
--- a/drivers/video/fb.c
+++ b/drivers/video/fb.c
@@ -1,4 +1,5 @@
 #include <common.h>
+#include <malloc.h>
 #include <fb.h>
 #include <errno.h>
 #include <command.h>
@@ -93,10 +94,31 @@ static struct file_operations fb_ops = {
 	.ioctl	= fb_ioctl,
 };
 
+static void fb_info(struct device_d *dev)
+{
+	struct fb_info *info = dev->priv;
+	int i;
+
+	if (!info->num_modes)
+		return;
+
+	printf("available modes:\n");
+
+	for (i = 0; i < info->num_modes; i++) {
+		struct fb_videomode *mode = &info->mode_list[i];
+
+		printf("%-10s %dx%d@%d\n", mode->name,
+				mode->xres, mode->yres, mode->refresh);
+	}
+
+	printf("\n");
+}
+
 int register_framebuffer(struct fb_info *info)
 {
 	int id = get_free_deviceid("fb");
 	struct device_d *dev;
+	int ret;
 
 	dev = &info->dev;
 
@@ -113,47 +135,13 @@ int register_framebuffer(struct fb_info *info)
 
 	dev->priv = info;
 	dev->id = id;
+	dev->info = fb_info;
 
 	sprintf(dev->name, "fb");
 
-	info->dev.bus = &fb_bus;
-	register_device(&info->dev);
-
-	return 0;
-}
-
-static void fb_info(struct device_d *dev)
-{
-	struct fb_info *info = dev->priv;
-	int i;
-
-	if (!info->num_modes)
-		return;
-
-	printf("available modes:\n");
-
-	for (i = 0; i < info->num_modes; i++) {
-		struct fb_videomode *mode = &info->mode_list[i];
-
-		printf("%-10s %dx%d@%d\n", mode->name,
-				mode->xres, mode->yres, mode->refresh);
-	}
-
-	printf("\n");
-}
-
-static struct driver_d fb_driver = {
-	.name  = "fb",
-};
-
-static int fb_match(struct device_d *dev, struct driver_d *drv)
-{
-	return 0;
-}
-
-static int fb_probe(struct device_d *dev)
-{
-	struct fb_info *info = dev->priv;
+	ret = register_device(&info->dev);
+	if (ret)
+		goto err_free;
 
 	dev_add_param_bool(dev, "enable", fb_enable_set, NULL,
 			&info->p_enable, info);
@@ -164,32 +152,16 @@ static int fb_probe(struct device_d *dev)
 		dev_set_param(dev, "mode_name", info->mode_list[0].name);
 	}
 
-	dev->info = fb_info;
-
-	return devfs_create(&info->cdev);
-}
-
-static void fb_remove(struct device_d *dev)
-{
-}
+	ret = devfs_create(&info->cdev);
+	if (ret)
+		goto err_unregister;
 
-struct bus_type fb_bus = {
-	.name = "fb",
-	.match = fb_match,
-	.probe = fb_probe,
-	.remove = fb_remove,
-};
+	return 0;
 
-static int fb_bus_init(void)
-{
-	return bus_register(&fb_bus);
-}
-pure_initcall(fb_bus_init);
+err_unregister:
+	unregister_device(&info->dev);
+err_free:
+	free(dev->resource);
 
-static int fb_init_driver(void)
-{
-	fb_driver.bus = &fb_bus;
-	register_driver(&fb_driver);
-	return 0;
+	return ret;
 }
-device_initcall(fb_init_driver);
-- 
1.8.4.rc1




More information about the barebox mailing list