[patch 03/20] chardev: GPIO for SCx200: add a platform device so dev_dbg() works

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Add a platform-device, then use it for dev_dbg(), once, just to prove it works.

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

$ diffstat patch.platform-dev-2
scx200_gpio.c |   43 +++++++++++++++++++++++++++++++++++--------
1 files changed, 35 insertions(+), 8 deletions(-)

diff -ruNp -X dontdiff -X exclude-diffs ab-2/drivers/char/scx200_gpio.c ab-3/drivers/char/scx200_gpio.c
--- ab-2/drivers/char/scx200_gpio.c	2006-06-02 13:35:34.000000000 -0600
+++ ab-3/drivers/char/scx200_gpio.c	2006-06-02 13:35:48.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");
@@ -121,12 +126,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 {
@@ -134,29 +152,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_put(pdev);
	return rc;
}

@@ -164,6 +188,9 @@ static void __exit scx200_gpio_cleanup(v
{
	kfree(scx200_devices);
	unregister_chrdev_region(MKDEV(major, 0), num_devs);
+	platform_device_put(pdev);
+	platform_device_unregister(pdev);
+	/* kfree(pdev); */
}

module_init(scx200_gpio_init);



--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux