2 * ICP Wafer 5823 Single Board Computer WDT driver
3 * http://www.icpamerica.com/wafer_5823.php
4 * May also work on other similar models
6 * (c) Copyright 2002 Justin Cormack <justin@street-vision.com>
10 * Based on advantechwdt.c which is based on wdt.c.
11 * Original copyright messages:
13 * (c) Copyright 1996-1997 Alan Cox <alan@redhat.com>, All Rights Reserved.
14 * http://www.redhat.com
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
21 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
22 * warranty for any of this software. This material is provided
23 * "AS-IS" and at no charge.
25 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/miscdevice.h>
32 #include <linux/watchdog.h>
34 #include <linux/ioport.h>
35 #include <linux/notifier.h>
36 #include <linux/reboot.h>
37 #include <linux/init.h>
38 #include <linux/spinlock.h>
40 #include <linux/uaccess.h>
42 #define WATCHDOG_NAME "Wafer 5823 WDT"
43 #define PFX WATCHDOG_NAME ": "
44 #define WD_TIMO 60 /* 60 sec default timeout */
46 static unsigned long wafwdt_is_open;
47 static char expect_close;
48 static DEFINE_SPINLOCK(wafwdt_lock);
51 * You must set these - there is no sane way to probe for this board.
53 * To enable, write the timeout value in seconds (1 to 255) to I/O
54 * port WDT_START, then read the port to start the watchdog. To pat
55 * the dog, read port WDT_STOP to stop the timer, then read WDT_START
56 * to restart it again.
59 static int wdt_stop = 0x843;
60 static int wdt_start = 0x443;
62 static int timeout = WD_TIMO; /* in seconds */
63 module_param(timeout, int, 0);
64 MODULE_PARM_DESC(timeout,
65 "Watchdog timeout in seconds. 1 <= timeout <= 255, default="
66 __MODULE_STRING(WD_TIMO) ".");
68 static int nowayout = WATCHDOG_NOWAYOUT;
69 module_param(nowayout, int, 0);
70 MODULE_PARM_DESC(nowayout,
71 "Watchdog cannot be stopped once started (default="
72 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
74 static void wafwdt_ping(void)
77 spin_lock(&wafwdt_lock);
80 spin_unlock(&wafwdt_lock);
83 static void wafwdt_start(void)
85 /* start up watchdog */
86 outb_p(timeout, wdt_start);
97 static ssize_t wafwdt_write(struct file *file, const char __user *buf,
98 size_t count, loff_t *ppos)
100 /* See if we got the magic character 'V' and reload the timer */
105 /* In case it was set long ago */
108 /* scan to see whether or not we got the magic
110 for (i = 0; i != count; i++) {
112 if (get_user(c, buf + i))
118 /* Well, anyhow someone wrote to us, we should
119 return that favour */
125 static long wafwdt_ioctl(struct file *file, unsigned int cmd,
129 void __user *argp = (void __user *)arg;
130 int __user *p = argp;
131 static const struct watchdog_info ident = {
132 .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT |
134 .firmware_version = 1,
135 .identity = "Wafer 5823 WDT",
139 case WDIOC_GETSUPPORT:
140 if (copy_to_user(argp, &ident, sizeof(ident)))
144 case WDIOC_GETSTATUS:
145 case WDIOC_GETBOOTSTATUS:
146 return put_user(0, p);
148 case WDIOC_SETOPTIONS:
150 int options, retval = -EINVAL;
152 if (get_user(options, p))
155 if (options & WDIOS_DISABLECARD) {
160 if (options & WDIOS_ENABLECARD) {
168 case WDIOC_KEEPALIVE:
172 case WDIOC_SETTIMEOUT:
173 if (get_user(new_timeout, p))
175 if ((new_timeout < 1) || (new_timeout > 255))
177 timeout = new_timeout;
181 case WDIOC_GETTIMEOUT:
182 return put_user(timeout, p);
190 static int wafwdt_open(struct inode *inode, struct file *file)
192 if (test_and_set_bit(0, &wafwdt_is_open))
199 return nonseekable_open(inode, file);
203 wafwdt_close(struct inode *inode, struct file *file)
205 if (expect_close == 42)
209 "WDT device closed unexpectedly. WDT will not stop!\n");
212 clear_bit(0, &wafwdt_is_open);
218 * Notifier for system down
221 static int wafwdt_notify_sys(struct notifier_block *this, unsigned long code,
224 if (code == SYS_DOWN || code == SYS_HALT)
233 static const struct file_operations wafwdt_fops = {
234 .owner = THIS_MODULE,
236 .write = wafwdt_write,
237 .unlocked_ioctl = wafwdt_ioctl,
239 .release = wafwdt_close,
242 static struct miscdevice wafwdt_miscdev = {
243 .minor = WATCHDOG_MINOR,
245 .fops = &wafwdt_fops,
249 * The WDT needs to learn about soft shutdowns in order to
250 * turn the timebomb registers off.
253 static struct notifier_block wafwdt_notifier = {
254 .notifier_call = wafwdt_notify_sys,
257 static int __init wafwdt_init(void)
262 "WDT driver for Wafer 5823 single board computer initialising.\n");
264 if (timeout < 1 || timeout > 255) {
267 "timeout value must be 1 <= x <= 255, using %d\n",
271 if (wdt_stop != wdt_start) {
272 if (!request_region(wdt_stop, 1, "Wafer 5823 WDT")) {
274 "I/O address 0x%04x already in use\n",
281 if (!request_region(wdt_start, 1, "Wafer 5823 WDT")) {
282 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
288 ret = register_reboot_notifier(&wafwdt_notifier);
291 "cannot register reboot notifier (err=%d)\n", ret);
295 ret = misc_register(&wafwdt_miscdev);
298 "cannot register miscdev on minor=%d (err=%d)\n",
299 WATCHDOG_MINOR, ret);
303 printk(KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n",
308 unregister_reboot_notifier(&wafwdt_notifier);
310 release_region(wdt_start, 1);
312 if (wdt_stop != wdt_start)
313 release_region(wdt_stop, 1);
318 static void __exit wafwdt_exit(void)
320 misc_deregister(&wafwdt_miscdev);
321 unregister_reboot_notifier(&wafwdt_notifier);
322 if (wdt_stop != wdt_start)
323 release_region(wdt_stop, 1);
324 release_region(wdt_start, 1);
327 module_init(wafwdt_init);
328 module_exit(wafwdt_exit);
330 MODULE_AUTHOR("Justin Cormack");
331 MODULE_DESCRIPTION("ICP Wafer 5823 Single Board Computer WDT driver");
332 MODULE_LICENSE("GPL");
333 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
335 /* end of wafer5823wdt.c */