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

[WATCHDOG] alim7101_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 c735310b
...@@ -51,7 +51,10 @@ ...@@ -51,7 +51,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) ")");
static void wdt_timer_ping(unsigned long); static void wdt_timer_ping(unsigned long);
static struct timer_list timer; static struct timer_list timer;
...@@ -111,7 +114,7 @@ static void wdt_change(int writeval) ...@@ -111,7 +114,7 @@ static void wdt_change(int writeval)
static void wdt_startup(void) static void wdt_startup(void)
{ {
next_heartbeat = jiffies + WDT_HEARTBEAT; next_heartbeat = jiffies + (timeout * HZ);
/* We must enable before we kick off the timer in case the timer /* We must enable before we kick off the timer in case the timer
occurs as we ping it */ occurs as we ping it */
...@@ -134,6 +137,12 @@ static void wdt_turnoff(void) ...@@ -134,6 +137,12 @@ static void wdt_turnoff(void)
printk(KERN_INFO PFX "Watchdog timer is now disabled...\n"); printk(KERN_INFO PFX "Watchdog timer is now disabled...\n");
} }
static void wdt_keepalive(void)
{
/* user land ping */
next_heartbeat = jiffies + (timeout * HZ);
}
/* /*
* /dev/watchdog handling * /dev/watchdog handling
*/ */
...@@ -163,7 +172,7 @@ static ssize_t fop_write(struct file * file, const char * buf, size_t count, lof ...@@ -163,7 +172,7 @@ static ssize_t fop_write(struct file * file, const char * buf, size_t count, lof
} }
} }
/* someone wrote to us, we should restart timer */ /* someone wrote to us, we should restart timer */
next_heartbeat = jiffies + WDT_HEARTBEAT; wdt_keepalive();
} }
return count; return count;
} }
...@@ -195,7 +204,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u ...@@ -195,7 +204,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
{ {
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 = "ALiM7101", .identity = "ALiM7101",
}; };
...@@ -208,7 +217,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u ...@@ -208,7 +217,7 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
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:
{ {
...@@ -229,6 +238,22 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u ...@@ -229,6 +238,22 @@ static int fop_ioctl(struct inode *inode, struct file *file, unsigned int cmd, u
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);
default: default:
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
...@@ -317,6 +342,13 @@ static int __init alim7101_wdt_init(void) ...@@ -317,6 +342,13 @@ static int __init alim7101_wdt_init(void)
return -EBUSY; return -EBUSY;
} }
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 = 1; timer.data = 1;
...@@ -335,8 +367,8 @@ static int __init alim7101_wdt_init(void) ...@@ -335,8 +367,8 @@ static int __init alim7101_wdt_init(void)
goto err_out_miscdev; goto err_out_miscdev;
} }
printk(KERN_INFO PFX "WDT driver for ALi M7101 initialised. (nowayout=%d)\n", printk(KERN_INFO PFX "WDT driver for ALi M7101 initialised. timeout=%d sec (nowayout=%d)\n",
nowayout); timeout, nowayout);
return 0; return 0;
err_out_miscdev: err_out_miscdev:
......
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