logo       

[patch 04/19] chardev: pc8736x_gpio - use a platform device in scx200_gpio: msg#00013

Subject: [patch 04/19] chardev: pc8736x_gpio - use a platform device in scx200_gpio
GPIO SUPPORT FOR SCx200 & PC8736x

This patch-set reworks the 2.4 vintage scx200_gpio driver for modern
2.6, and refactors GPIO support to reuse it in a new driver for the
GPIO on PC-8736x chips.

04/19. patch.platform-dev:

Add a platform-device, use it for dev_dbg() once.  Comment in source
asks: should I export-gpl the pci-device available in scx200, and use
it instead of getting my own platform/isa device ?

Signed-off-by:  Jim Cromie <jim.cromie@xxxxxxxxx>

diffstat patch.platform-dev
scx200_gpio.c |   41 +++++++++++++++++++++++++++++++++--------
1 files changed, 33 insertions(+), 8 deletions(-)


diff -ruNp -X dontdiff -X exclude-diffs an-3/drivers/char/scx200_gpio.c 
an-4/drivers/char/scx200_gpio.c
--- an-3/drivers/char/scx200_gpio.c     2006-05-29 16:27:23.000000000 -0600
+++ an-4/drivers/char/scx200_gpio.c     2006-05-29 16:34:35.000000000 -0600
@@ -6,11 +6,13 @@
   Copyright (c) 2001,2002 Christer Weinigel <wingel@xxxxxxxxxxxxxxx> */

#include <linux/config.h>
+#include <linux/device.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/init.h>
+#include <linux/platform_device.h>
#include <asm/uaccess.h>
#include <asm/io.h>

@@ -20,6 +22,9 @@
#include <linux/scx200_gpio.h>

#define NAME "scx200_gpio"
+#define DEVNAME NAME
+
+static struct platform_device *pdev;

MODULE_AUTHOR("Christer Weinigel <wingel@xxxxxxxxxxxxxxx>");
MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver");
@@ -122,12 +127,25 @@ static int __init scx200_gpio_init(void)
        int rc, i;
        dev_t dev = MKDEV(major, 0);

-       printk(KERN_DEBUG NAME ": NatSemi SCx200 GPIO Driver\n");
-
        if (!scx200_gpio_present()) {
                printk(KERN_ERR NAME ": no SCx200 gpio present\n");
                return -ENODEV;
        }
+
+       /* should I export-gpl the pci-device available in scx200,
+          and use it instead of getting my own platform/isa device ?
+       */
+       pdev = platform_device_alloc(DEVNAME, 0);
+       if (!pdev)
+               return -ENOMEM;
+
+       rc = platform_device_add(pdev);
+       if (rc) {
+               platform_device_put(pdev);
+               kfree(pdev);
+               return -ENODEV;
+ } +
        if (major)
                rc = register_chrdev_region(dev, num_devs, "scx200_gpio");
        else {
@@ -135,29 +153,35 @@ static int __init scx200_gpio_init(void)
                major = MAJOR(dev);
        }
        if (rc < 0) {
-               printk(KERN_ERR NAME ": SCx200 chrdev_region failure %d\n", rc);
-               return rc;
+               dev_err(&pdev->dev, "SCx200 chrdev_region failure %d\n", rc);
+               goto undo_platform_dev_reg;
+               return -ENODEV;
        }
        scx200_devices = kzalloc(num_devs * sizeof(struct cdev), GFP_KERNEL);
        if (!scx200_devices) {
                rc = -ENOMEM;
-               goto fail_malloc;
+               goto undo_chrdev_reg;
        }
        for (i = 0; i < num_devs; i++) {
                struct cdev *cdev = &scx200_devices[i];
                cdev_init(cdev, &scx200_gpio_fops);
                cdev->owner = THIS_MODULE;
-               cdev->ops = &scx200_gpio_fops;
                rc = cdev_add(cdev, MKDEV(major, i), 1);
                /* Fail gracefully if need be */
                if (rc)
                        printk(KERN_ERR NAME "Error %d on minor %d", rc, i);
        }

-       return 0;               /* succeed */
+       dev_info(&pdev->dev, "NatSemi SCx200 GPIO driver initialized\n");
+       return 0;

-      fail_malloc:
+       // what about chrdev cleanup ?
+       // undo_malloc:
+       kfree(scx200_devices);
+undo_chrdev_reg:
        unregister_chrdev_region(dev, num_devs);
+undo_platform_dev_reg:
+       platform_device_del(pdev);
        return rc;
}

@@ -165,6 +189,7 @@ static void __exit scx200_gpio_cleanup(v
{
        kfree(scx200_devices);
        unregister_chrdev_region(MKDEV(major, 0), num_devs);
+       platform_device_unregister(pdev);
}

module_init(scx200_gpio_init);


<Prev in Thread] Current Thread [Next in Thread>