2 * IndyDog 0.3 A Hardware Watchdog Device for SGI IP22
4 * (c) Copyright 2002 Guido Guenther <agx@sigxcpu.org>, All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
11 * based on softdog.c by Alan Cox <alan@redhat.com>
14 #include <linux/module.h>
15 #include <linux/config.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
20 #include <linux/miscdevice.h>
21 #include <linux/watchdog.h>
22 #include <linux/notifier.h>
23 #include <linux/reboot.h>
24 #include <linux/init.h>
25 #include <linux/moduleparam.h>
26 #include <asm/uaccess.h>
27 #include <asm/sgi/sgimc.h>
29 #define PFX "indydog: "
30 #define WATCHDOG_HEARTBEAT 60
32 static unsigned long indydog_alive;
33 static struct sgimc_misc_ctrl *mcmisc_regs;
34 static char expect_close;
36 #ifdef CONFIG_WATCHDOG_NOWAYOUT
37 static int nowayout = 1;
39 static int nowayout = 0;
42 module_param(nowayout, int, 0);
43 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
45 static void indydog_start(void)
47 u32 mc_ctrl0 = mcmisc_regs->cpuctrl0;
49 mc_ctrl0 |= SGIMC_CCTRL0_WDOG;
50 mcmisc_regs->cpuctrl0 = mc_ctrl0;
52 printk(KERN_INFO PFX "Started watchdog timer.\n");
55 static void indydog_stop(void)
57 u32 mc_ctrl0 = mcmisc_regs->cpuctrl0;
59 mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG;
60 mcmisc_regs->cpuctrl0 = mc_ctrl0;
62 printk(KERN_INFO PFX "Stopped watchdog timer.\n");
65 static void indydog_ping(void)
67 mcmisc_regs->watchdogt = 0;
71 * Allow only one person to hold it open
74 static int indydog_open(struct inode *inode, struct file *file)
76 if( test_and_set_bit(0,&indydog_alive) )
80 __module_get(THIS_MODULE);
91 static int indydog_release(struct inode *inode, struct file *file)
95 * Lock it in if it's a module and we set nowayout
98 if (expect_close == 42) {
101 printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n");
104 clear_bit(0,&indydog_alive);
109 static ssize_t indydog_write(struct file *file, const char *data, size_t len, loff_t *ppos)
111 /* Can't seek (pwrite) on this device */
112 if (ppos != &file->f_pos)
115 /* Refresh the timer. */
120 /* In case it was set long ago */
123 for (i = 0; i != len; i++) {
126 if (get_user(c, data + i))
137 static int indydog_ioctl(struct inode *inode, struct file *file,
138 unsigned int cmd, unsigned long arg)
140 int options, retval = -EINVAL;
141 static struct watchdog_info ident = {
142 .options = WDIOF_KEEPALIVEPING |
144 .firmware_version = 0,
145 .identity = "Hardware Watchdog for SGI IP22",
151 case WDIOC_GETSUPPORT:
152 if(copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
155 case WDIOC_GETSTATUS:
156 case WDIOC_GETBOOTSTATUS:
157 return put_user(0,(int *)arg);
158 case WDIOC_KEEPALIVE:
161 case WDIOC_GETTIMEOUT:
162 return put_user(WATCHDOG_TIMEOUT,(int *)arg);
163 case WDIOC_SETOPTIONS:
165 if (get_user(options, (int *)arg))
168 if (options & WDIOS_DISABLECARD)
174 if (options & WDIOS_ENABLECARD)
185 static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
187 if (code==SYS_DOWN || code==SYS_HALT) {
188 /* Turn the WDT off */
195 static struct file_operations indydog_fops = {
196 .owner = THIS_MODULE,
197 .write = indydog_write,
198 .ioctl = indydog_ioctl,
199 .open = indydog_open,
200 .release= indydog_release,
203 static struct miscdevice indydog_miscdev = {
204 .minor = WATCHDOG_MINOR,
206 .fops = &indydog_fops,
209 static struct notifier_block indydog_notifier = {
210 .notifier_call = indydog_notify_sys,
213 static char banner[] __initdata = KERN_INFO PFX "Hardware Watchdog Timer for SGI IP22: 0.3\n";
215 static int __init watchdog_init(void)
219 mcmisc_regs = (struct sgimc_misc_ctrl *)(KSEG1+0x1fa00000);
221 ret = register_reboot_notifier(&indydog_notifier);
223 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
228 ret = misc_register(&indydog_miscdev);
230 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
231 WATCHDOG_MINOR, ret);
232 unregister_reboot_notifier(&indydog_notifier);
241 static void __exit watchdog_exit(void)
243 misc_deregister(&indydog_miscdev);
244 unregister_reboot_notifier(&indydog_notifier);
247 module_init(watchdog_init);
248 module_exit(watchdog_exit);
250 MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
251 MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22");
252 MODULE_LICENSE("GPL");
253 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);