2 * IB700 Single Board Computer WDT driver for Linux 2.4.x
4 * (c) Copyright 2001 Charles Howes <chowes@vsol.net>
6 * Based on advantechwdt.c which is based on acquirewdt.c which
9 * (c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl>
11 * Based on acquirewdt.c which is based on wdt.c.
12 * Original copyright messages:
14 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
15 * http://www.redhat.com
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version
20 * 2 of the License, or (at your option) any later version.
22 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
23 * warranty for any of this software. This material is provided
24 * "AS-IS" and at no charge.
26 * (c) Copyright 1995 Alan Cox <alan@redhat.com>
30 #include <linux/config.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/types.h>
34 #include <linux/errno.h>
35 #include <linux/kernel.h>
36 #include <linux/sched.h>
37 #include <linux/miscdevice.h>
38 #include <linux/watchdog.h>
39 #include <linux/slab.h>
40 #include <linux/ioport.h>
41 #include <linux/fcntl.h>
43 #include <asm/uaccess.h>
44 #include <asm/system.h>
45 #include <linux/notifier.h>
46 #include <linux/reboot.h>
47 #include <linux/init.h>
48 #include <linux/spinlock.h>
49 #include <linux/smp_lock.h>
51 static int ibwdt_is_open;
52 static spinlock_t ibwdt_lock;
53 static int expect_close = 0;
57 * Watchdog Timer Configuration
59 * The function of the watchdog timer is to reset the system
60 * automatically and is defined at I/O port 0443H. To enable the
61 * watchdog timer and allow the system to reset, write I/O port 0443H.
62 * To disable the timer, write I/O port 0441H for the system to stop the
63 * watchdog function. The timer has a tolerance of 20% for its
66 * The following describes how the timer should be programmed.
69 * MOV AX,000FH (Choose the values from 0 to F)
74 * MOV AX,000FH (Any value is fine.)
78 * Watchdog timer control table:
79 * Level Value Time/sec | Level Value Time/sec
91 static int wd_times[] = {
110 #define WDT_STOP 0x441
111 #define WDT_START 0x443
113 /* Default timeout */
114 #define WD_TIMO 0 /* 30 seconds +/- 20%, from table */
116 static int wd_margin = WD_TIMO;
118 #ifdef CONFIG_WATCHDOG_NOWAYOUT
119 static int nowayout = 1;
121 static int nowayout = 0;
124 MODULE_PARM(nowayout,"i");
125 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
135 /* Write a watchdog value */
136 outb_p(wd_times[wd_margin], WDT_START);
140 ibwdt_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
142 /* Can't seek (pwrite) on this device */
143 if (ppos != &file->f_pos)
150 /* In case it was set long ago */
153 for (i = 0; i != count; i++) {
155 if (get_user(c, buf + i))
168 ibwdt_read(struct file *file, char *buf, size_t count, loff_t *ppos)
174 ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
179 static struct watchdog_info ident = {
180 WDIOF_KEEPALIVEPING |
187 case WDIOC_GETSUPPORT:
188 if (copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
192 case WDIOC_GETSTATUS:
193 if (copy_to_user((int *)arg, &ibwdt_is_open, sizeof(int)))
197 case WDIOC_KEEPALIVE:
201 case WDIOC_SETTIMEOUT:
202 if (get_user(new_margin, (int *)arg))
204 if ((new_margin < 0) || (new_margin > 30))
206 for (i = 0x0F; i > -1; i--)
207 if (wd_times[i] > new_margin)
213 case WDIOC_GETTIMEOUT:
214 return put_user(wd_times[wd_margin], (int *)arg);
224 ibwdt_open(struct inode *inode, struct file *file)
226 switch (MINOR(inode->i_rdev)) {
228 spin_lock(&ibwdt_lock);
230 spin_unlock(&ibwdt_lock);
239 spin_unlock(&ibwdt_lock);
247 ibwdt_close(struct inode *inode, struct file *file)
250 if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) {
251 spin_lock(&ibwdt_lock);
253 outb_p(wd_times[wd_margin], WDT_STOP);
255 printk(KERN_CRIT "WDT device closed unexpectedly. WDT will not stop!\n");
258 spin_unlock(&ibwdt_lock);
265 * Notifier for system down
269 ibwdt_notify_sys(struct notifier_block *this, unsigned long code,
272 if (code == SYS_DOWN || code == SYS_HALT) {
273 /* Turn the WDT off */
274 outb_p(wd_times[wd_margin], WDT_STOP);
283 static struct file_operations ibwdt_fops = {
289 release: ibwdt_close,
292 static struct miscdevice ibwdt_miscdev = {
299 * The WDT needs to learn about soft shutdowns in order to
300 * turn the timebomb registers off.
303 static struct notifier_block ibwdt_notifier = {
312 printk("WDT driver for IB700 single board computer initialising.\n");
314 spin_lock_init(&ibwdt_lock);
315 misc_register(&ibwdt_miscdev);
316 #if WDT_START != WDT_STOP
317 request_region(WDT_STOP, 1, "IB700 WDT");
319 request_region(WDT_START, 1, "IB700 WDT");
320 register_reboot_notifier(&ibwdt_notifier);
327 misc_deregister(&ibwdt_miscdev);
328 unregister_reboot_notifier(&ibwdt_notifier);
329 #if WDT_START != WDT_STOP
330 release_region(WDT_STOP,1);
332 release_region(WDT_START,1);
335 module_init(ibwdt_init);
336 module_exit(ibwdt_exit);
338 MODULE_AUTHOR("Charles Howes <chowes@vsol.net>");
339 MODULE_DESCRIPTION("IB700 SBC watchdog driver");
340 MODULE_LICENSE("GPL");
342 /* end of ib700wdt.c */