linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [MPCore Watchdog]: Convert from misc_dev to dynamic device node.
@ 2011-06-14 23:29 Peter Fordham
  2011-06-14 23:48 ` Jamie Iles
  0 siblings, 1 reply; 14+ messages in thread
From: Peter Fordham @ 2011-06-14 23:29 UTC (permalink / raw)
  To: linux-arm-kernel

The current MPCore watchdog driver uses a misc_dev device node.
This patch changes it to use dynamically allocated device numbers.

---
 drivers/watchdog/mpcore_wdt.c |   48 +++++++++++++++++++++++++++++------------
 1 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/drivers/watchdog/mpcore_wdt.c b/drivers/watchdog/mpcore_wdt.c
index 2b4af22..f6afc20 100644
--- a/drivers/watchdog/mpcore_wdt.c
+++ b/drivers/watchdog/mpcore_wdt.c
@@ -32,6 +32,8 @@
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/cdev.h>
+#include <linux/device.h>

 #include <asm/smp_twd.h>

@@ -42,6 +44,9 @@ struct mpcore_wdt {
 	int		irq;
 	unsigned int	perturb;
 	char		expect_close;
+        struct cdev     cdev;
+        struct class    *class;
+        dev_t           number;
 };

 static struct platform_device *mpcore_wdt_dev;
@@ -318,12 +323,6 @@ static const struct file_operations mpcore_wdt_fops = {
 	.release	= mpcore_wdt_release,
 };

-static struct miscdevice mpcore_wdt_miscdev = {
-	.minor		= WATCHDOG_MINOR,
-	.name		= "watchdog",
-	.fops		= &mpcore_wdt_fops,
-};
-
 static int __devinit mpcore_wdt_probe(struct platform_device *dev)
 {
 	struct mpcore_wdt *wdt;
@@ -358,14 +357,15 @@ static int __devinit mpcore_wdt_probe(struct
platform_device *dev)
 		goto err_free;
 	}

-	mpcore_wdt_miscdev.parent = &dev->dev;
-	ret = misc_register(&mpcore_wdt_miscdev);
-	if (ret) {
+ 	ret = alloc_chrdev_region(&wdt->number, 0, 1, "mpcore_wdt");
+	if (ret < 0) {
 		dev_printk(KERN_ERR, wdt->dev,
-			"cannot register miscdev on minor=%d (err=%d)\n",
-							WATCHDOG_MINOR, ret);
+			"cannot register with dynamic device number (err=%d)\n", -ret);
 		goto err_misc;
 	}
+	dev_printk(KERN_INFO, wdt->dev, "using device number %d, %d",
MAJOR(wdt->number), MINOR(wdt->number));
+
+        cdev_init(&wdt->cdev, &mpcore_wdt_fops);

 	ret = request_irq(wdt->irq, mpcore_wdt_fire, IRQF_DISABLED,
 							"mpcore_wdt", wdt);
@@ -379,10 +379,24 @@ static int __devinit mpcore_wdt_probe(struct
platform_device *dev)
 	platform_set_drvdata(dev, wdt);
 	mpcore_wdt_dev = dev;

-	return 0;
+        ret = cdev_add(&wdt->cdev, wdt->number, 1);
+	if (ret < 0) {
+		dev_printk(KERN_ERR, wdt->dev, "failed to add character device\n");
+		goto err_cdev_add;
+	}

+        /* create /dev/watchdog
+         * we use udev to make the file
+         */
+        wdt->class = class_create(THIS_MODULE,"watchdog");
+        (void) device_create(wdt->class, wdt->dev,
wdt->number,NULL,"watchdog");
+
+        return 0;
+
+err_cdev_add:
+	free_irq(wdt->irq, wdt);
 err_irq:
-	misc_deregister(&mpcore_wdt_miscdev);
+        unregister_chrdev_region (wdt->number, 1);
 err_misc:
 	iounmap(wdt->base);
 err_free:
@@ -395,9 +409,15 @@ static int __devexit mpcore_wdt_remove(struct
platform_device *dev)
 {
 	struct mpcore_wdt *wdt = platform_get_drvdata(dev);

+        device_destroy(wdt->class,wdt->number);
+        class_unregister(wdt->class);
+        class_destroy(wdt->class);
+
+        cdev_del(&wdt->cdev);
+
 	platform_set_drvdata(dev, NULL);

-	misc_deregister(&mpcore_wdt_miscdev);
+        unregister_chrdev_region (wdt->number, 1);

 	mpcore_wdt_dev = NULL;

-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2011-06-17  7:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-14 23:29 [MPCore Watchdog]: Convert from misc_dev to dynamic device node Peter Fordham
2011-06-14 23:48 ` Jamie Iles
2011-06-15  0:19   ` Peter Fordham
2011-06-15  8:58     ` Jamie Iles
2011-06-15 18:57       ` Peter Fordham
2011-06-15 19:09         ` Jamie Iles
2011-06-15 19:36           ` Peter Fordham
2011-06-15 19:37             ` Peter Fordham
2011-06-15 19:36           ` Arnd Bergmann
2011-06-15 19:49             ` Peter Fordham
2011-06-15 20:03               ` Arnd Bergmann
2011-06-17  7:20             ` Wim Van Sebroeck
2011-06-17  7:17         ` Wim Van Sebroeck
2011-06-17  7:14       ` Wim Van Sebroeck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).