Commit 1f1b84f0 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Indydog update

From: Ralf Baechle <ralf@linux-mips.org>

Forward port of the 2.4 driver with changes required for 2.6.
Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent fb9c90ba
...@@ -22,16 +22,11 @@ ...@@ -22,16 +22,11 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/moduleparam.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <asm/sgi/sgimc.h> #include <asm/sgi/mc.h>
#define PFX "indydog: " #define PFX "indydog: "
#define WATCHDOG_HEARTBEAT 60 static int indydog_alive;
static unsigned long indydog_alive;
static struct sgimc_misc_ctrl *mcmisc_regs;
static char expect_close;
#ifdef CONFIG_WATCHDOG_NOWAYOUT #ifdef CONFIG_WATCHDOG_NOWAYOUT
static int nowayout = 1; static int nowayout = 1;
...@@ -39,70 +34,67 @@ static int nowayout = 1; ...@@ -39,70 +34,67 @@ static int nowayout = 1;
static int nowayout = 0; static int nowayout = 0;
#endif #endif
#define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
module_param(nowayout, int, 0); module_param(nowayout, int, 0);
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
static void indydog_start(void) static void indydog_start(void)
{ {
u32 mc_ctrl0 = mcmisc_regs->cpuctrl0; u32 mc_ctrl0 = sgimc->cpuctrl0;
mc_ctrl0 |= SGIMC_CCTRL0_WDOG; mc_ctrl0 = sgimc->cpuctrl0 | SGIMC_CCTRL0_WDOG;
mcmisc_regs->cpuctrl0 = mc_ctrl0; sgimc->cpuctrl0 = mc_ctrl0;
printk(KERN_INFO PFX "Started watchdog timer.\n");
} }
static void indydog_stop(void) static void indydog_stop(void)
{ {
u32 mc_ctrl0 = mcmisc_regs->cpuctrl0; u32 mc_ctrl0 = sgimc->cpuctrl0;
mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG; mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG;
mcmisc_regs->cpuctrl0 = mc_ctrl0; sgimc->cpuctrl0 = mc_ctrl0;
printk(KERN_INFO PFX "Stopped watchdog timer.\n"); printk(KERN_INFO PFX "Stopped watchdog timer.\n");
} }
static void indydog_ping(void) static void indydog_ping(void)
{ {
mcmisc_regs->watchdogt = 0; sgimc->watchdogt = 0;
} }
/* /*
* Allow only one person to hold it open * Allow only one person to hold it open
*/ */
static int indydog_open(struct inode *inode, struct file *file) static int indydog_open(struct inode *inode, struct file *file)
{ {
if( test_and_set_bit(0,&indydog_alive) ) if (indydog_alive)
return -EBUSY; return -EBUSY;
if (nowayout) if (nowayout)
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
/* /* Activate timer */
* Activate timer
*/
indydog_start(); indydog_start();
indydog_ping(); indydog_ping();
indydog_alive = 1;
printk(KERN_INFO "Started watchdog timer.\n");
return 0; return 0;
} }
static int indydog_release(struct inode *inode, struct file *file) static int indydog_release(struct inode *inode, struct file *file)
{ {
/* /* Shut off the timer.
* Shut off the timer. * Lock it in if it's a module and we defined ...NOWAYOUT */
* Lock it in if it's a module and we set nowayout if (!nowayout) {
*/ u32 mc_ctrl0 = sgimc->cpuctrl0;
mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG;
if (expect_close == 42) { sgimc->cpuctrl0 = mc_ctrl0;
indydog_stop(); printk(KERN_INFO "Stopped watchdog timer.\n");
} else {
printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n");
indydog_ping();
} }
clear_bit(0,&indydog_alive); indydog_alive = 0;
expect_close = 0;
return 0; return 0;
} }
...@@ -114,21 +106,6 @@ static ssize_t indydog_write(struct file *file, const char *data, size_t len, lo ...@@ -114,21 +106,6 @@ static ssize_t indydog_write(struct file *file, const char *data, size_t len, lo
/* Refresh the timer. */ /* Refresh the timer. */
if (len) { if (len) {
if (!nowayout) {
size_t i;
/* In case it was set long ago */
expect_close = 0;
for (i = 0; i != len; i++) {
char c;
if (get_user(c, data + i))
return -EFAULT;
if (c == 'V')
expect_close = 42;
}
}
indydog_ping(); indydog_ping();
} }
return len; return len;
...@@ -149,7 +126,8 @@ static int indydog_ioctl(struct inode *inode, struct file *file, ...@@ -149,7 +126,8 @@ static int indydog_ioctl(struct inode *inode, struct file *file,
default: default:
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
case WDIOC_GETSUPPORT: case WDIOC_GETSUPPORT:
if(copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident))) if (copy_to_user((struct watchdog_info *)arg,
&ident, sizeof(ident)))
return -EFAULT; return -EFAULT;
return 0; return 0;
case WDIOC_GETSTATUS: case WDIOC_GETSTATUS:
...@@ -165,14 +143,12 @@ static int indydog_ioctl(struct inode *inode, struct file *file, ...@@ -165,14 +143,12 @@ static int indydog_ioctl(struct inode *inode, struct file *file,
if (get_user(options, (int *)arg)) if (get_user(options, (int *)arg))
return -EFAULT; return -EFAULT;
if (options & WDIOS_DISABLECARD) if (options & WDIOS_DISABLECARD) {
{
indydog_stop(); indydog_stop();
retval = 0; retval = 0;
} }
if (options & WDIOS_ENABLECARD) if (options & WDIOS_ENABLECARD) {
{
indydog_start(); indydog_start();
retval = 0; retval = 0;
} }
...@@ -184,10 +160,8 @@ static int indydog_ioctl(struct inode *inode, struct file *file, ...@@ -184,10 +160,8 @@ static int indydog_ioctl(struct inode *inode, struct file *file,
static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused) static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
{ {
if (code==SYS_DOWN || code==SYS_HALT) { if (code == SYS_DOWN || code == SYS_HALT)
/* Turn the WDT off */ indydog_stop(); /* Turn the WDT off */
indydog_stop();
}
return NOTIFY_DONE; return NOTIFY_DONE;
} }
...@@ -197,7 +171,7 @@ static struct file_operations indydog_fops = { ...@@ -197,7 +171,7 @@ static struct file_operations indydog_fops = {
.write = indydog_write, .write = indydog_write,
.ioctl = indydog_ioctl, .ioctl = indydog_ioctl,
.open = indydog_open, .open = indydog_open,
.release= indydog_release, .release = indydog_release,
}; };
static struct miscdevice indydog_miscdev = { static struct miscdevice indydog_miscdev = {
...@@ -210,14 +184,13 @@ static struct notifier_block indydog_notifier = { ...@@ -210,14 +184,13 @@ static struct notifier_block indydog_notifier = {
.notifier_call = indydog_notify_sys, .notifier_call = indydog_notify_sys,
}; };
static char banner[] __initdata = KERN_INFO PFX "Hardware Watchdog Timer for SGI IP22: 0.3\n"; static char banner[] __initdata =
KERN_INFO PFX "Hardware Watchdog Timer for SGI IP22: 0.3\n";
static int __init watchdog_init(void) static int __init watchdog_init(void)
{ {
int ret; int ret;
mcmisc_regs = (struct sgimc_misc_ctrl *)(KSEG1+0x1fa00000);
ret = register_reboot_notifier(&indydog_notifier); ret = register_reboot_notifier(&indydog_notifier);
if (ret) { if (ret) {
printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
......
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