mxcmmc: decrease minimum frequency to make MMC cards work
[safe/jmp/linux-2.6] / drivers / watchdog / ib700wdt.c
index 9eb9537..4bef3dd 100644 (file)
@@ -11,8 +11,8 @@
  *     Based on acquirewdt.c which is based on wdt.c.
  *     Original copyright messages:
  *
- *     (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
- *                             http://www.redhat.com
+ *     (c) Copyright 1996 Alan Cox <alan@lxorguk.ukuu.org.uk>,
+ *                                             All Rights Reserved.
  *
  *     This program is free software; you can redistribute it and/or
  *     modify it under the terms of the GNU General Public License
@@ -23,7 +23,7 @@
  *     warranty for any of this software. This material is provided
  *     "AS-IS" and at no charge.
  *
- *     (c) Copyright 1995    Alan Cox <alan@redhat.com>
+ *     (c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com>
  *          Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT
@@ -91,32 +91,16 @@ static char expect_close;
  *
  */
 
-static int wd_times[] = {
-       30,     /* 0x0 */
-       28,     /* 0x1 */
-       26,     /* 0x2 */
-       24,     /* 0x3 */
-       22,     /* 0x4 */
-       20,     /* 0x5 */
-       18,     /* 0x6 */
-       16,     /* 0x7 */
-       14,     /* 0x8 */
-       12,     /* 0x9 */
-       10,     /* 0xA */
-       8,      /* 0xB */
-       6,      /* 0xC */
-       4,      /* 0xD */
-       2,      /* 0xE */
-       0,      /* 0xF */
-};
-
 #define WDT_STOP 0x441
 #define WDT_START 0x443
 
 /* Default timeout */
-#define WD_TIMO 0              /* 30 seconds +/- 20%, from table */
-
-static int wd_margin = WD_TIMO;
+#define WATCHDOG_TIMEOUT 30            /* 30 seconds +/- 20% */
+static int timeout = WATCHDOG_TIMEOUT; /* in seconds */
+module_param(timeout, int, 0);
+MODULE_PARM_DESC(timeout,
+       "Watchdog timeout in seconds. 0<= timeout <=30, default="
+               __MODULE_STRING(WATCHDOG_TIMEOUT) ".");
 
 static int nowayout = WATCHDOG_NOWAYOUT;
 module_param(nowayout, int, 0);
@@ -129,9 +113,10 @@ MODULE_PARM_DESC(nowayout,
  *     Watchdog Operations
  */
 
-static void
-ibwdt_ping(void)
+static void ibwdt_ping(void)
 {
+       int wd_margin = 15 - ((timeout + 1) / 2);
+
        spin_lock(&ibwdt_lock);
 
        /* Write a watchdog value */
@@ -140,26 +125,19 @@ ibwdt_ping(void)
        spin_unlock(&ibwdt_lock);
 }
 
-static void
-ibwdt_disable(void)
+static void ibwdt_disable(void)
 {
        spin_lock(&ibwdt_lock);
        outb_p(0, WDT_STOP);
        spin_unlock(&ibwdt_lock);
 }
 
-static int
-ibwdt_set_heartbeat(int t)
+static int ibwdt_set_heartbeat(int t)
 {
-       int i;
-
-       if ((t < 0) || (t > 30))
+       if (t < 0 || t > 30)
                return -EINVAL;
 
-       for (i = 0x0F; i > -1; i--)
-               if (wd_times[i] > t)
-                       break;
-       wd_margin = i;
+       timeout = t;
        return 0;
 }
 
@@ -213,21 +191,6 @@ static long ibwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case WDIOC_GETBOOTSTATUS:
                return put_user(0, p);
 
-       case WDIOC_KEEPALIVE:
-               ibwdt_ping();
-               break;
-
-       case WDIOC_SETTIMEOUT:
-               if (get_user(new_margin, p))
-                       return -EFAULT;
-               if (ibwdt_set_heartbeat(new_margin))
-                       return -EINVAL;
-               ibwdt_ping();
-               /* Fall */
-
-       case WDIOC_GETTIMEOUT:
-               return put_user(wd_times[wd_margin], p);
-
        case WDIOC_SETOPTIONS:
        {
                int options, retval = -EINVAL;
@@ -245,6 +208,21 @@ static long ibwdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                }
                return retval;
        }
+       case WDIOC_KEEPALIVE:
+               ibwdt_ping();
+               break;
+
+       case WDIOC_SETTIMEOUT:
+               if (get_user(new_margin, p))
+                       return -EFAULT;
+               if (ibwdt_set_heartbeat(new_margin))
+                       return -EINVAL;
+               ibwdt_ping();
+               /* Fall */
+
+       case WDIOC_GETTIMEOUT:
+               return put_user(timeout, p);
+
        default:
                return -ENOTTY;
        }
@@ -263,8 +241,7 @@ static int ibwdt_open(struct inode *inode, struct file *file)
        return nonseekable_open(inode, file);
 }
 
-static int
-ibwdt_close(struct inode *inode, struct file *file)
+static int ibwdt_close(struct inode *inode, struct file *file)
 {
        if (expect_close == 42) {
                ibwdt_disable();
@@ -321,6 +298,14 @@ static int __devinit ibwdt_probe(struct platform_device *dev)
                goto out_nostartreg;
        }
 
+       /* Check that the heartbeat value is within it's range ;
+        * if not reset to the default */
+       if (ibwdt_set_heartbeat(timeout)) {
+               ibwdt_set_heartbeat(WATCHDOG_TIMEOUT);
+               printk(KERN_INFO PFX
+                       "timeout value must be 0<=x<=30, using %d\n", timeout);
+       }
+
        res = misc_register(&ibwdt_miscdev);
        if (res) {
                printk(KERN_ERR PFX "failed to register misc device\n");