[WATCHDOG] wdt_pci: fix printk and variable type
[safe/jmp/linux-2.6] / drivers / watchdog / ar7_wdt.c
index cdaab8c..2e94b71 100644 (file)
 #include <linux/errno.h>
 #include <linux/init.h>
 #include <linux/miscdevice.h>
+#include <linux/platform_device.h>
 #include <linux/watchdog.h>
-#include <linux/notifier.h>
-#include <linux/reboot.h>
 #include <linux/fs.h>
 #include <linux/ioport.h>
 #include <linux/io.h>
 #include <linux/uaccess.h>
 
 #include <asm/addrspace.h>
-#include <asm/ar7/ar7.h>
+#include <asm/mach-ar7/ar7.h>
 
 #define DRVNAME "ar7_wdt"
 #define LONGNAME "TI AR7 Watchdog Timer"
@@ -69,30 +68,17 @@ struct ar7_wdt {
        u32 prescale;
 };
 
-static struct semaphore open_semaphore;
+static unsigned long wdt_is_open;
+static spinlock_t wdt_lock;
 static unsigned expect_close;
 
 /* XXX currently fixed, allows max margin ~68.72 secs */
 #define prescale_value 0xffff
 
-/* Offset of the WDT registers */
-static unsigned long ar7_regs_wdt;
+/* Resource of the WDT registers */
+static struct resource *ar7_regs_wdt;
 /* Pointer to the remapped WDT IO space */
 static struct ar7_wdt *ar7_wdt;
-static void ar7_wdt_get_regs(void)
-{
-       u16 chip_id = ar7_chip_id();
-       switch (chip_id) {
-       case AR7_CHIP_7100:
-       case AR7_CHIP_7200:
-               ar7_regs_wdt = AR7_REGS_WDT;
-               break;
-       default:
-               ar7_regs_wdt = UR8_REGS_WDT;
-               break;
-       }
-}
-
 
 static void ar7_wdt_kick(u32 value)
 {
@@ -154,8 +140,10 @@ static void ar7_wdt_update_margin(int new_margin)
        u32 change;
 
        change = new_margin * (ar7_vbus_freq() / prescale_value);
-       if (change < 1) change = 1;
-       if (change > 0xffff) change = 0xffff;
+       if (change < 1)
+               change = 1;
+       if (change > 0xffff)
+               change = 0xffff;
        ar7_wdt_change(change);
        margin = change * prescale_value / ar7_vbus_freq();
        printk(KERN_INFO DRVNAME
@@ -179,7 +167,7 @@ static void ar7_wdt_disable_wdt(void)
 static int ar7_wdt_open(struct inode *inode, struct file *file)
 {
        /* only allow one at a time */
-       if (down_trylock(&open_semaphore))
+       if (test_and_set_bit(0, &wdt_is_open))
                return -EBUSY;
        ar7_wdt_enable_wdt();
        expect_close = 0;
@@ -195,26 +183,10 @@ static int ar7_wdt_release(struct inode *inode, struct file *file)
                "will not disable the watchdog timer\n");
        else if (!nowayout)
                ar7_wdt_disable_wdt();
-
-       up(&open_semaphore);
-
+       clear_bit(0, &wdt_is_open);
        return 0;
 }
 
-static int ar7_wdt_notify_sys(struct notifier_block *this,
-                             unsigned long code, void *unused)
-{
-       if (code == SYS_HALT || code == SYS_POWER_OFF)
-               if (!nowayout)
-                       ar7_wdt_disable_wdt();
-
-       return NOTIFY_DONE;
-}
-
-static struct notifier_block ar7_wdt_notifier = {
-       .notifier_call = ar7_wdt_notify_sys
-};
-
 static ssize_t ar7_wdt_write(struct file *file, const char *data,
                             size_t len, loff_t *ppos)
 {
@@ -222,12 +194,14 @@ static ssize_t ar7_wdt_write(struct file *file, const char *data,
        if (len) {
                size_t i;
 
+               spin_lock(&wdt_lock);
                ar7_wdt_kick(1);
+               spin_unlock(&wdt_lock);
 
                expect_close = 0;
                for (i = 0; i < len; ++i) {
                        char c;
-                       if (get_user(c, data+i))
+                       if (get_user(c, data + i))
                                return -EFAULT;
                        if (c == 'V')
                                expect_close = 1;
@@ -237,19 +211,18 @@ static ssize_t ar7_wdt_write(struct file *file, const char *data,
        return len;
 }
 
-static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
-                        unsigned int cmd, unsigned long arg)
+static long ar7_wdt_ioctl(struct file *file,
+                                       unsigned int cmd, unsigned long arg)
 {
        static struct watchdog_info ident = {
                .identity = LONGNAME,
                .firmware_version = 1,
-               .options = (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING),
+               .options = (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING |
+                                               WDIOF_MAGICCLOSE),
        };
        int new_margin;
 
        switch (cmd) {
-       default:
-               return -ENOTTY;
        case WDIOC_GETSUPPORT:
                if (copy_to_user((struct watchdog_info *)arg, &ident,
                                sizeof(ident)))
@@ -269,20 +242,24 @@ static int ar7_wdt_ioctl(struct inode *inode, struct file *file,
                if (new_margin < 1)
                        return -EINVAL;
 
+               spin_lock(&wdt_lock);
                ar7_wdt_update_margin(new_margin);
                ar7_wdt_kick(1);
+               spin_unlock(&wdt_lock);
 
        case WDIOC_GETTIMEOUT:
                if (put_user(margin, (int *)arg))
                        return -EFAULT;
                return 0;
+       default:
+               return -ENOTTY;
        }
 }
 
-static struct file_operations ar7_wdt_fops = {
+static const struct file_operations ar7_wdt_fops = {
        .owner          = THIS_MODULE,
        .write          = ar7_wdt_write,
-       .ioctl          = ar7_wdt_ioctl,
+       .unlocked_ioctl = ar7_wdt_ioctl,
        .open           = ar7_wdt_open,
        .release        = ar7_wdt_release,
 };
@@ -293,56 +270,86 @@ static struct miscdevice ar7_wdt_miscdev = {
        .fops           = &ar7_wdt_fops,
 };
 
-static int __init ar7_wdt_init(void)
+static int __devinit ar7_wdt_probe(struct platform_device *pdev)
 {
        int rc;
 
-       ar7_wdt_get_regs();
+       spin_lock_init(&wdt_lock);
 
-       if (!request_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt),
-                                                       LONGNAME)) {
+       ar7_regs_wdt =
+               platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
+       if (!ar7_regs_wdt) {
+               printk(KERN_ERR DRVNAME ": could not get registers resource\n");
+               rc = -ENODEV;
+               goto out;
+       }
+
+       if (!request_mem_region(ar7_regs_wdt->start,
+                               resource_size(ar7_regs_wdt), LONGNAME)) {
                printk(KERN_WARNING DRVNAME ": watchdog I/O region busy\n");
-               return -EBUSY;
+               rc = -EBUSY;
+               goto out;
        }
 
-       ar7_wdt = (struct ar7_wdt *)
-                       ioremap(ar7_regs_wdt, sizeof(struct ar7_wdt));
+       ar7_wdt = ioremap(ar7_regs_wdt->start, resource_size(ar7_regs_wdt));
+       if (!ar7_wdt) {
+               printk(KERN_ERR DRVNAME ": could not ioremap registers\n");
+               rc = -ENXIO;
+               goto out_mem_region;
+       }
 
        ar7_wdt_disable_wdt();
        ar7_wdt_prescale(prescale_value);
        ar7_wdt_update_margin(margin);
 
-       sema_init(&open_semaphore, 1);
-
-       rc = register_reboot_notifier(&ar7_wdt_notifier);
-       if (rc) {
-               printk(KERN_ERR DRVNAME
-                       ": unable to register reboot notifier\n");
-               goto out_alloc;
-       }
-
        rc = misc_register(&ar7_wdt_miscdev);
        if (rc) {
                printk(KERN_ERR DRVNAME ": unable to register misc device\n");
-               goto out_register;
+               goto out_alloc;
        }
        goto out;
 
-out_register:
-       unregister_reboot_notifier(&ar7_wdt_notifier);
 out_alloc:
        iounmap(ar7_wdt);
-       release_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt));
+out_mem_region:
+       release_mem_region(ar7_regs_wdt->start, resource_size(ar7_regs_wdt));
 out:
        return rc;
 }
 
-static void __exit ar7_wdt_cleanup(void)
+static int __devexit ar7_wdt_remove(struct platform_device *pdev)
 {
        misc_deregister(&ar7_wdt_miscdev);
-       unregister_reboot_notifier(&ar7_wdt_notifier);
        iounmap(ar7_wdt);
-       release_mem_region(ar7_regs_wdt, sizeof(struct ar7_wdt));
+       release_mem_region(ar7_regs_wdt->start, resource_size(ar7_regs_wdt));
+
+       return 0;
+}
+
+static void ar7_wdt_shutdown(struct platform_device *pdev)
+{
+       if (!nowayout)
+               ar7_wdt_disable_wdt();
+}
+
+static struct platform_driver ar7_wdt_driver = {
+       .probe = ar7_wdt_probe,
+       .remove = __devexit_p(ar7_wdt_remove),
+       .shutdown = ar7_wdt_shutdown,
+       .driver = {
+               .owner = THIS_MODULE,
+               .name = "ar7_wdt",
+       },
+};
+
+static int __init ar7_wdt_init(void)
+{
+       return platform_driver_register(&ar7_wdt_driver);
+}
+
+static void __exit ar7_wdt_cleanup(void)
+{
+       platform_driver_unregister(&ar7_wdt_driver);
 }
 
 module_init(ar7_wdt_init);