--- linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c.orig 2005-03-22 17:18:01.000000000 +0100 +++ linux/arch/mips/au1000/mtx-1/mtx-1_watchdog.c 2005-07-06 12:10:06.000000000 +0200 @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -115,6 +116,8 @@ //---------[ File Functions ]----------------- +static char restart_after_close; + static int mtx1wd_open (struct inode *inode, struct file *file) { if (MINOR(inode->i_rdev)!=WATCHDOG_MINOR) return -ENODEV; @@ -134,6 +137,10 @@ static int mtx1wd_release (struct inode *inode, struct file *file) { if (MINOR(inode->i_rdev)==WATCHDOG_MINOR) { + + if (restart_after_close) + start_wd_timer (); + } MOD_DEC_USE_COUNT; return 0; @@ -141,22 +148,53 @@ static ssize_t mtx1wd_write (struct file *file, const char *buf, size_t count, loff_t *ppos) { - if (ppos!=&file->f_pos) - return -ESPIPE; - if (count) { mtx1_trigger_wd (); - return 1; + + if (count > 0) { + char buffer[10]; + int n = (count>9)?9:count; + + if (copy_from_user (&buffer, buf, n)) + return -EFAULT; + buffer[n]=0; + + if (count >= 4 && strncmp("auto", buffer, 4)==0) + restart_after_close = 1; + + else if (count >= 6 && strncmp("manual", buffer, 6)==0) + restart_after_close = 0; + + return n; } return 0; } +static ssize_t mtx1wd_read (struct file *file, char *buf, size_t count, loff_t *ppos) +{ + char * state = restart_after_close ? "auto\n" : "manual\n"; + int n = strlen(state)+1; + + if (file->f_pos >= n) + return 0; + + if (count < n) + return -EINVAL; + + if(copy_to_user(buf, state, n)) + return -EFAULT; + + file->f_pos += n; + + return n; +} + static struct file_operations mtx1wd_fops = { .owner = THIS_MODULE, .llseek = NULL, - .read = NULL, + .read = mtx1wd_read, .write = mtx1wd_write, .readdir = NULL, .poll = NULL, @@ -194,6 +232,8 @@ { printk("MTX-1 watchdog driver\n"); + restart_after_close = 0; + mtx1_enable_wd (); //-- trigger it for the first time.