Commit e5eec631 authored by Wim Van Sebroeck's avatar Wim Van Sebroeck

[WATCHDOG] sc520_wdt.c patch3

added WDIOC_SETTIMEOUT and WDIOC_GETTIMEOUT ioctls
made timeout (the emulated heartbeat) a module_param
made the keepalive ping an internal subroutine
parent c31c9522
...@@ -31,11 +31,14 @@ ...@@ -31,11 +31,14 @@
* - Add KERN_* tags to printks * - Add KERN_* tags to printks
* - fix possible wdt_is_open race * - fix possible wdt_is_open race
* - Report proper capabilities in watchdog_info * - Report proper capabilities in watchdog_info
* - Add WDIOC_{GETSTATUS, GETBOOTSTATUS, SETOPTIONS} ioctls * - Add WDIOC_{GETSTATUS, GETBOOTSTATUS, SETTIMEOUT,
* GETTIMEOUT, SETOPTIONS} ioctls
* 09/8 - 2003 Changes by Wim Van Sebroeck <wim@iguana.be> * 09/8 - 2003 Changes by Wim Van Sebroeck <wim@iguana.be>
* - cleanup of trailing spaces * - cleanup of trailing spaces
* - added extra printk's for startup problems * - added extra printk's for startup problems
* - use module_param * - use module_param
* - made timeout (the emulated heartbeat) a module_param
* - made the keepalive ping an internal subroutine
* *
* This WDT driver is different from most other Linux WDT * This WDT driver is different from most other Linux WDT
* drivers in that the driver will ping the watchdog by itself, * drivers in that the driver will ping the watchdog by itself,
...@@ -75,7 +78,10 @@ ...@@ -75,7 +78,10 @@
* char to /dev/watchdog every 30 seconds. * char to /dev/watchdog every 30 seconds.
*/ */
#define WDT_HEARTBEAT (HZ * 30) #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
static int timeout = WATCHDOG_TIMEOUT; /* in seconds, will be multiplied by HZ to get seconds to wait for a ping */
module_param(timeout, int, 0);
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. (1<=timeout<=3600, default=" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");
/* /*
* AMD Elan SC520 timeout value is 492us times a power of 2 (0-7) * AMD Elan SC520 timeout value is 492us times a power of 2 (0-7)
...@@ -164,7 +170,7 @@ static void wdt_config(int writeval) ...@@ -164,7 +170,7 @@ static void wdt_config(int writeval)
static void wdt_startup(void) static void wdt_startup(void)
{ {
next_heartbeat = jiffies + WDT_HEARTBEAT; next_heartbeat = jiffies + (timeout * HZ);
/* Start the timer */ /* Start the timer */
timer.expires = jiffies + WDT_INTERVAL; timer.expires = jiffies + WDT_INTERVAL;
...@@ -184,6 +190,11 @@ static void wdt_turnoff(void) ...@@ -184,6 +190,11 @@ static void wdt_turnoff(void)
} }
} }
static void wdt_keepalive(void)
{
/* user land ping */
next_heartbeat = jiffies + (timeout * HZ);
}
/* /*
* /dev/watchdog handling * /dev/watchdog handling
...@@ -217,7 +228,7 @@ static ssize_t fop_write(struct file * file, const char * buf, size_t count, lof ...@@ -217,7 +228,7 @@ static ssize_t fop_write(struct file * file, const char * buf, size_t count, lof
} }
/* Well, anyhow someone wrote to us, we should return that favour */ /* Well, anyhow someone wrote to us, we should return that favour */
next_heartbeat = jiffies + WDT_HEARTBEAT; wdt_keepalive();
} }
return count; return count;
} }
...@@ -253,7 +264,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, ...@@ -253,7 +264,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
{ {
static struct watchdog_info ident= static struct watchdog_info ident=
{ {
.options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,
.firmware_version = 1, .firmware_version = 1,
.identity = "SC520", .identity = "SC520",
}; };
...@@ -268,7 +279,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, ...@@ -268,7 +279,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
case WDIOC_GETBOOTSTATUS: case WDIOC_GETBOOTSTATUS:
return put_user(0, (int *)arg); return put_user(0, (int *)arg);
case WDIOC_KEEPALIVE: case WDIOC_KEEPALIVE:
next_heartbeat = jiffies + WDT_HEARTBEAT; wdt_keepalive();
return 0; return 0;
case WDIOC_SETOPTIONS: case WDIOC_SETOPTIONS:
{ {
...@@ -289,6 +300,22 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, ...@@ -289,6 +300,22 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
return retval; return retval;
} }
case WDIOC_SETTIMEOUT:
{
int new_timeout;
if(get_user(new_timeout, (int *)arg))
return -EFAULT;
if(new_timeout < 1 || new_timeout > 3600) /* arbitrary upper limit */
return -EINVAL;
timeout = new_timeout;
wdt_keepalive();
/* Fall through */
}
case WDIOC_GETTIMEOUT:
return put_user(timeout, (int *)arg);
} }
} }
...@@ -348,6 +375,13 @@ static int __init sc520_wdt_init(void) ...@@ -348,6 +375,13 @@ static int __init sc520_wdt_init(void)
spin_lock_init(&wdt_spinlock); spin_lock_init(&wdt_spinlock);
if(timeout < 1 || timeout > 3600) /* arbitrary upper limit */
{
timeout = WATCHDOG_TIMEOUT;
printk(KERN_INFO PFX "timeout value must be 1<=x<=3600, using %d\n",
timeout);
}
init_timer(&timer); init_timer(&timer);
timer.function = wdt_timer_ping; timer.function = wdt_timer_ping;
timer.data = 0; timer.data = 0;
...@@ -389,8 +423,8 @@ static int __init sc520_wdt_init(void) ...@@ -389,8 +423,8 @@ static int __init sc520_wdt_init(void)
wdtmrctl = (__u16 *)((char *)wdtmrctl + OFFS_WDTMRCTL); wdtmrctl = (__u16 *)((char *)wdtmrctl + OFFS_WDTMRCTL);
wdtmrctl = ioremap((unsigned long)wdtmrctl, 2); wdtmrctl = ioremap((unsigned long)wdtmrctl, 2);
printk(KERN_INFO PFX "WDT driver for SC520 initialised. (nowayout=%d)\n", printk(KERN_INFO PFX "WDT driver for SC520 initialised. timeout=%d sec (nowayout=%d)\n",
nowayout); timeout,nowayout);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment