watchdog: nowayout is bool
[linux-2.6.git] / drivers / watchdog / txx9wdt.c
index 57cefef..d02804c 100644 (file)
@@ -7,13 +7,15 @@
  * it under the terms of the GNU General Public License version 2 as
  * published by the Free Software Foundation.
  */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/types.h>
 #include <linux/miscdevice.h>
 #include <linux/watchdog.h>
 #include <linux/fs.h>
-#include <linux/reboot.h>
 #include <linux/init.h>
 #include <linux/uaccess.h>
 #include <linux/platform_device.h>
@@ -31,8 +33,8 @@ MODULE_PARM_DESC(timeout,
        "(0<timeout<((2^" __MODULE_STRING(TXX9_TIMER_BITS) ")/(IMCLK/256)), "
        "default=" __MODULE_STRING(TIMER_MARGIN) ")");
 
-static int nowayout = WATCHDOG_NOWAYOUT;
-module_param(nowayout, int, 0);
+static bool nowayout = WATCHDOG_NOWAYOUT;
+module_param(nowayout, bool, 0);
 MODULE_PARM_DESC(nowayout,
        "Watchdog cannot be stopped once started "
        "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
@@ -45,27 +47,34 @@ static unsigned long txx9wdt_alive;
 static int expect_close;
 static struct txx9_tmr_reg __iomem *txx9wdt_reg;
 static struct clk *txx9_imclk;
+static DEFINE_SPINLOCK(txx9_lock);
 
 static void txx9wdt_ping(void)
 {
+       spin_lock(&txx9_lock);
        __raw_writel(TXx9_TMWTMR_TWIE | TXx9_TMWTMR_TWC, &txx9wdt_reg->wtmr);
+       spin_unlock(&txx9_lock);
 }
 
 static void txx9wdt_start(void)
 {
+       spin_lock(&txx9_lock);
        __raw_writel(WD_TIMER_CLK * timeout, &txx9wdt_reg->cpra);
        __raw_writel(WD_TIMER_CCD, &txx9wdt_reg->ccdr);
        __raw_writel(0, &txx9wdt_reg->tisr);    /* clear pending interrupt */
        __raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
                     &txx9wdt_reg->tcr);
        __raw_writel(TXx9_TMWTMR_TWIE | TXx9_TMWTMR_TWC, &txx9wdt_reg->wtmr);
+       spin_unlock(&txx9_lock);
 }
 
 static void txx9wdt_stop(void)
 {
+       spin_lock(&txx9_lock);
        __raw_writel(TXx9_TMWTMR_WDIS, &txx9wdt_reg->wtmr);
        __raw_writel(__raw_readl(&txx9wdt_reg->tcr) & ~TXx9_TMTCR_TCE,
                     &txx9wdt_reg->tcr);
+       spin_unlock(&txx9_lock);
 }
 
 static int txx9wdt_open(struct inode *inode, struct file *file)
@@ -90,8 +99,7 @@ static int txx9wdt_release(struct inode *inode, struct file *file)
        if (expect_close)
                txx9wdt_stop();
        else {
-               printk(KERN_CRIT "txx9wdt: "
-                      "Unexpected close, not stopping watchdog!\n");
+               pr_crit("Unexpected close, not stopping watchdog!\n");
                txx9wdt_ping();
        }
        clear_bit(0, &txx9wdt_alive);
@@ -120,13 +128,13 @@ static ssize_t txx9wdt_write(struct file *file, const char __user *data,
        return len;
 }
 
-static int txx9wdt_ioctl(struct inode *inode, struct file *file,
-       unsigned int cmd, unsigned long arg)
+static long txx9wdt_ioctl(struct file *file, unsigned int cmd,
+                                                       unsigned long arg)
 {
        void __user *argp = (void __user *)arg;
        int __user *p = argp;
        int new_timeout;
-       static struct watchdog_info ident = {
+       static const struct watchdog_info ident = {
                .options =              WDIOF_SETTIMEOUT |
                                        WDIOF_KEEPALIVEPING |
                                        WDIOF_MAGICCLOSE,
@@ -135,8 +143,6 @@ static int txx9wdt_ioctl(struct inode *inode, struct file *file,
        };
 
        switch (cmd) {
-       default:
-               return -ENOTTY;
        case WDIOC_GETSUPPORT:
                return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
        case WDIOC_GETSTATUS:
@@ -156,34 +162,24 @@ static int txx9wdt_ioctl(struct inode *inode, struct file *file,
                /* Fall */
        case WDIOC_GETTIMEOUT:
                return put_user(timeout, p);
+       default:
+               return -ENOTTY;
        }
 }
 
-static int txx9wdt_notify_sys(struct notifier_block *this, unsigned long code,
-       void *unused)
-{
-       if (code == SYS_DOWN || code == SYS_HALT)
-               txx9wdt_stop();
-       return NOTIFY_DONE;
-}
-
 static const struct file_operations txx9wdt_fops = {
-       .owner =        THIS_MODULE,
-       .llseek =       no_llseek,
-       .write =        txx9wdt_write,
-       .ioctl =        txx9wdt_ioctl,
-       .open =         txx9wdt_open,
-       .release =      txx9wdt_release,
+       .owner          =       THIS_MODULE,
+       .llseek         =       no_llseek,
+       .write          =       txx9wdt_write,
+       .unlocked_ioctl =       txx9wdt_ioctl,
+       .open           =       txx9wdt_open,
+       .release        =       txx9wdt_release,
 };
 
 static struct miscdevice txx9wdt_miscdev = {
-       .minor =        WATCHDOG_MINOR,
-       .name =         "watchdog",
-       .fops =         &txx9wdt_fops,
-};
-
-static struct notifier_block txx9wdt_notifier = {
-       .notifier_call = txx9wdt_notify_sys
+       .minor  =       WATCHDOG_MINOR,
+       .name   =       "watchdog",
+       .fops   =       &txx9wdt_fops,
 };
 
 static int __init txx9wdt_probe(struct platform_device *dev)
@@ -207,28 +203,20 @@ static int __init txx9wdt_probe(struct platform_device *dev)
        res = platform_get_resource(dev, IORESOURCE_MEM, 0);
        if (!res)
                goto exit_busy;
-       if (!devm_request_mem_region(&dev->dev,
-                                    res->start, res->end - res->start + 1,
+       if (!devm_request_mem_region(&dev->dev, res->start, resource_size(res),
                                     "txx9wdt"))
                goto exit_busy;
-       txx9wdt_reg = devm_ioremap(&dev->dev,
-                                  res->start, res->end - res->start + 1);
+       txx9wdt_reg = devm_ioremap(&dev->dev, res->start, resource_size(res));
        if (!txx9wdt_reg)
                goto exit_busy;
 
-       ret = register_reboot_notifier(&txx9wdt_notifier);
-       if (ret)
-               goto exit;
-
        ret = misc_register(&txx9wdt_miscdev);
        if (ret) {
-               unregister_reboot_notifier(&txx9wdt_notifier);
                goto exit;
        }
 
-       printk(KERN_INFO "Hardware Watchdog Timer for TXx9: "
-              "timeout=%d sec (max %ld) (nowayout= %d)\n",
-              timeout, WD_MAX_TIMEOUT, nowayout);
+       pr_info("Hardware Watchdog Timer: timeout=%d sec (max %ld) (nowayout= %d)\n",
+               timeout, WD_MAX_TIMEOUT, nowayout);
 
        return 0;
 exit_busy:
@@ -244,14 +232,19 @@ exit:
 static int __exit txx9wdt_remove(struct platform_device *dev)
 {
        misc_deregister(&txx9wdt_miscdev);
-       unregister_reboot_notifier(&txx9wdt_notifier);
        clk_disable(txx9_imclk);
        clk_put(txx9_imclk);
        return 0;
 }
 
+static void txx9wdt_shutdown(struct platform_device *dev)
+{
+       txx9wdt_stop();
+}
+
 static struct platform_driver txx9wdt_driver = {
        .remove = __exit_p(txx9wdt_remove),
+       .shutdown = txx9wdt_shutdown,
        .driver = {
                .name = "txx9wdt",
                .owner = THIS_MODULE,