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/moduleparam.h>
16 #include <linux/config.h>
17 #include <linux/types.h>
18 #include <linux/kernel.h>
21 #include <linux/miscdevice.h>
22 #include <linux/watchdog.h>
23 #include <linux/notifier.h>
24 #include <linux/reboot.h>
25 #include <linux/init.h>
26 #include <asm/uaccess.h>
27 #include <asm/sgi/mc.h>
29 #define PFX "indydog: "
30 static int indydog_alive;
32 #define WATCHDOG_TIMEOUT 30 /* 30 sec default timeout */
34 static int nowayout = WATCHDOG_NOWAYOUT;
35 module_param(nowayout, int, 0);
36 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
38 static void indydog_start(void)
40 u32 mc_ctrl0 = sgimc->cpuctrl0;
42 mc_ctrl0 = sgimc->cpuctrl0 | SGIMC_CCTRL0_WDOG;
43 sgimc->cpuctrl0 = mc_ctrl0;
46 static void indydog_stop(void)
48 u32 mc_ctrl0 = sgimc->cpuctrl0;
50 mc_ctrl0 &= ~SGIMC_CCTRL0_WDOG;
51 sgimc->cpuctrl0 = mc_ctrl0;
53 printk(KERN_INFO PFX "Stopped watchdog timer.\n");
56 static void indydog_ping(void)
62 * Allow only one person to hold it open
64 static int indydog_open(struct inode *inode, struct file *file)
70 __module_get(THIS_MODULE);
77 printk(KERN_INFO "Started watchdog timer.\n");
79 return nonseekable_open(inode, file);
82 static int indydog_release(struct inode *inode, struct file *file)
84 /* Shut off the timer.
85 * Lock it in if it's a module and we defined ...NOWAYOUT */
87 indydog_stop(); /* Turn the WDT off */
94 static ssize_t indydog_write(struct file *file, const char *data, size_t len, loff_t *ppos)
96 /* Refresh the timer. */
103 static int indydog_ioctl(struct inode *inode, struct file *file,
104 unsigned int cmd, unsigned long arg)
106 int options, retval = -EINVAL;
107 static struct watchdog_info ident = {
108 .options = WDIOF_KEEPALIVEPING |
110 .firmware_version = 0,
111 .identity = "Hardware Watchdog for SGI IP22",
117 case WDIOC_GETSUPPORT:
118 if (copy_to_user((struct watchdog_info *)arg,
119 &ident, sizeof(ident)))
122 case WDIOC_GETSTATUS:
123 case WDIOC_GETBOOTSTATUS:
124 return put_user(0,(int *)arg);
125 case WDIOC_KEEPALIVE:
128 case WDIOC_GETTIMEOUT:
129 return put_user(WATCHDOG_TIMEOUT,(int *)arg);
130 case WDIOC_SETOPTIONS:
132 if (get_user(options, (int *)arg))
135 if (options & WDIOS_DISABLECARD) {
140 if (options & WDIOS_ENABLECARD) {
150 static int indydog_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
152 if (code == SYS_DOWN || code == SYS_HALT)
153 indydog_stop(); /* Turn the WDT off */
158 static struct file_operations indydog_fops = {
159 .owner = THIS_MODULE,
161 .write = indydog_write,
162 .ioctl = indydog_ioctl,
163 .open = indydog_open,
164 .release = indydog_release,
167 static struct miscdevice indydog_miscdev = {
168 .minor = WATCHDOG_MINOR,
170 .fops = &indydog_fops,
173 static struct notifier_block indydog_notifier = {
174 .notifier_call = indydog_notify_sys,
177 static char banner[] __initdata =
178 KERN_INFO PFX "Hardware Watchdog Timer for SGI IP22: 0.3\n";
180 static int __init watchdog_init(void)
184 ret = register_reboot_notifier(&indydog_notifier);
186 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
191 ret = misc_register(&indydog_miscdev);
193 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
194 WATCHDOG_MINOR, ret);
195 unregister_reboot_notifier(&indydog_notifier);
204 static void __exit watchdog_exit(void)
206 misc_deregister(&indydog_miscdev);
207 unregister_reboot_notifier(&indydog_notifier);
210 module_init(watchdog_init);
211 module_exit(watchdog_exit);
213 MODULE_AUTHOR("Guido Guenther <agx@sigxcpu.org>");
214 MODULE_DESCRIPTION("Hardware Watchdog Device for SGI IP22");
215 MODULE_LICENSE("GPL");
216 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);