Merge ../linux-2.6-watchdog-mm
[pandora-kernel.git] / drivers / char / watchdog / advantechwdt.c
index 216af0d..8121cc2 100644 (file)
@@ -35,8 +35,7 @@
 #include <linux/watchdog.h>
 #include <linux/fs.h>
 #include <linux/ioport.h>
-#include <linux/notifier.h>
-#include <linux/reboot.h>
+#include <linux/platform_device.h>
 #include <linux/init.h>
 
 #include <asm/io.h>
@@ -48,6 +47,7 @@
 #define WATCHDOG_NAME "Advantech WDT"
 #define WATCHDOG_TIMEOUT 60            /* 60 sec default timeout */
 
+static struct platform_device *advwdt_platform_device; /* the watchdog platform device */
 static unsigned long advwdt_is_open;
 static char adv_expect_close;
 
@@ -222,21 +222,6 @@ advwdt_close(struct inode *inode, struct file *file)
        return 0;
 }
 
-/*
- *     Notifier for system down
- */
-
-static int
-advwdt_notify_sys(struct notifier_block *this, unsigned long code,
-       void *unused)
-{
-       if (code == SYS_DOWN || code == SYS_HALT) {
-               /* Turn the WDT off */
-               advwdt_disable();
-       }
-       return NOTIFY_DONE;
-}
-
 /*
  *     Kernel Interfaces
  */
@@ -256,26 +241,15 @@ static struct miscdevice advwdt_miscdev = {
        .fops   = &advwdt_fops,
 };
 
-/*
- *     The WDT needs to learn about soft shutdowns in order to
- *     turn the timebomb registers off.
- */
-
-static struct notifier_block advwdt_notifier = {
-       .notifier_call = advwdt_notify_sys,
-};
-
 /*
  *     Init & exit routines
  */
 
-static int __init
-advwdt_init(void)
+static int __devinit
+advwdt_probe(struct platform_device *dev)
 {
        int ret;
 
-       printk(KERN_INFO "WDT driver for Advantech single board computer initialising.\n");
-
        if (wdt_stop != wdt_start) {
                if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
                        printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
@@ -299,18 +273,11 @@ advwdt_init(void)
                        timeout);
        }
 
-       ret = register_reboot_notifier(&advwdt_notifier);
-       if (ret != 0) {
-               printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
-                       ret);
-               goto unreg_regions;
-       }
-
        ret = misc_register(&advwdt_miscdev);
        if (ret != 0) {
                printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
                        WATCHDOG_MINOR, ret);
-               goto unreg_reboot;
+               goto unreg_regions;
        }
 
        printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
@@ -318,8 +285,6 @@ advwdt_init(void)
 
 out:
        return ret;
-unreg_reboot:
-       unregister_reboot_notifier(&advwdt_notifier);
 unreg_regions:
        release_region(wdt_start, 1);
 unreg_stop:
@@ -328,14 +293,64 @@ unreg_stop:
        goto out;
 }
 
-static void __exit
-advwdt_exit(void)
+static int __devexit
+advwdt_remove(struct platform_device *dev)
 {
        misc_deregister(&advwdt_miscdev);
-       unregister_reboot_notifier(&advwdt_notifier);
        release_region(wdt_start,1);
        if(wdt_stop != wdt_start)
                release_region(wdt_stop,1);
+
+       return 0;
+}
+
+static void
+advwdt_shutdown(struct platform_device *dev)
+{
+       /* Turn the WDT off if we have a soft shutdown */
+       advwdt_disable();
+}
+
+static struct platform_driver advwdt_driver = {
+       .probe          = advwdt_probe,
+       .remove         = __devexit_p(advwdt_remove),
+       .shutdown       = advwdt_shutdown,
+       .driver         = {
+               .owner  = THIS_MODULE,
+               .name   = DRV_NAME,
+       },
+};
+
+static int __init
+advwdt_init(void)
+{
+       int err;
+
+       printk(KERN_INFO "WDT driver for Advantech single board computer initialising.\n");
+
+       err = platform_driver_register(&advwdt_driver);
+       if (err)
+               return err;
+
+       advwdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0);
+       if (IS_ERR(advwdt_platform_device)) {
+               err = PTR_ERR(advwdt_platform_device);
+               goto unreg_platform_driver;
+       }
+
+       return 0;
+
+unreg_platform_driver:
+       platform_driver_unregister(&advwdt_driver);
+       return err;
+}
+
+static void __exit
+advwdt_exit(void)
+{
+       platform_device_unregister(advwdt_platform_device);
+       platform_driver_unregister(&advwdt_driver);
+       printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
 }
 
 module_init(advwdt_init);