Import 2.1.118
[davej-history.git] / drivers / char / acquirewdt.c
bloba9aa7671467ff5324c8ed845c12b23a03d5e2f42
1 /*
2 * Acquire Single Board Computer Watchdog Timer driver for Linux 2.1.x
4 * Based on wdt.c. Original copyright messages:
6 * (c) Copyright 1996 Alan Cox <alan@cymru.net>, All Rights Reserved.
7 * http://www.cymru.net
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
14 * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide
15 * warranty for any of this software. This material is provided
16 * "AS-IS" and at no charge.
18 * (c) Copyright 1995 Alan Cox <alan@lxorguk.ukuu.org.uk>
22 #include <linux/config.h>
23 #include <linux/module.h>
24 #include <linux/version.h>
25 #include <linux/types.h>
26 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/sched.h>
29 #include <linux/miscdevice.h>
30 #include <linux/watchdog.h>
31 #include <linux/malloc.h>
32 #include <linux/ioport.h>
33 #include <linux/fcntl.h>
34 #include <asm/io.h>
35 #include <asm/uaccess.h>
36 #include <asm/system.h>
37 #include <linux/notifier.h>
38 #include <linux/reboot.h>
39 #include <linux/init.h>
41 static int acq_is_open=0;
44 * You must set these - there is no sane way to probe for this board.
47 #define WDT_STOP 0x43
48 #define WDT_START 0x443
50 #define WD_TIMO (100*60) /* 1 minute */
54 * Kernel methods.
58 static void acq_ping(void)
60 /* Write a watchdog value */
61 inb_p(WDT_START);
64 static ssize_t acq_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
66 /* Can't seek (pwrite) on this device */
67 if (ppos != &file->f_pos)
68 return -ESPIPE;
70 if(count)
72 acq_ping();
73 return 1;
75 return 0;
78 static ssize_t acq_read(struct file *file, char *buf, size_t count, loff_t *ppos)
80 return -EINVAL;
85 static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
86 unsigned long arg)
88 static struct watchdog_info ident=
90 WDIOF_KEEPALIVEPING, 1, "Acquire WDT"
93 switch(cmd)
95 case WDIOC_GETSUPPORT:
96 if (copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
97 return -EFAULT;
98 break;
100 case WDIOC_GETSTATUS:
101 if (copy_to_user((int *)arg, &acq_is_open, sizeof(int)))
102 return -EFAULT;
103 break;
105 case WDIOC_KEEPALIVE:
106 acq_ping();
107 break;
109 default:
110 return -ENOIOCTLCMD;
112 return 0;
115 static int acq_open(struct inode *inode, struct file *file)
117 switch(MINOR(inode->i_rdev))
119 case WATCHDOG_MINOR:
120 if(acq_is_open)
121 return -EBUSY;
122 MOD_INC_USE_COUNT;
124 * Activate
127 acq_is_open=1;
128 inb_p(WDT_START);
129 return 0;
130 default:
131 return -ENODEV;
135 static int acq_close(struct inode *inode, struct file *file)
137 if(MINOR(inode->i_rdev)==WATCHDOG_MINOR)
139 #ifndef CONFIG_WATCHDOG_NOWAYOUT
140 inb_p(WDT_STOP);
141 #endif
142 acq_is_open=0;
144 MOD_DEC_USE_COUNT;
145 return 0;
149 * Notifier for system down
152 static int acq_notify_sys(struct notifier_block *this, unsigned long code,
153 void *unused)
155 if(code==SYS_DOWN || code==SYS_HALT)
157 /* Turn the card off */
158 inb_p(WDT_STOP);
160 return NOTIFY_DONE;
164 * Kernel Interfaces
168 static struct file_operations acq_fops = {
169 NULL,
170 acq_read,
171 acq_write,
172 NULL, /* No Readdir */
173 NULL, /* No Select */
174 acq_ioctl,
175 NULL, /* No mmap */
176 acq_open,
177 NULL, /* flush */
178 acq_close
181 static struct miscdevice acq_miscdev=
183 WATCHDOG_MINOR,
184 "watchdog",
185 &acq_fops
190 * The WDT card needs to learn about soft shutdowns in order to
191 * turn the timebomb registers off.
194 static struct notifier_block acq_notifier=
196 acq_notify_sys,
197 NULL,
201 #ifdef MODULE
203 #define acq_init init_module
205 void cleanup_module(void)
207 misc_deregister(&acq_miscdev);
208 unregister_reboot_notifier(&acq_notifier);
209 release_region(WDT_STOP,1);
210 release_region(WDT_START,1);
213 #endif
215 __initfunc(int acq_init(void))
217 printk("WDT driver for Acquire single board computer initialising.\n");
219 misc_register(&acq_miscdev);
220 request_region(WDT_STOP, 1, "Acquire WDT");
221 request_region(WDT_START, 1, "Acquire WDT");
222 unregister_reboot_notifier(&acq_notifier);
223 return 0;