Portability cleanup as required by Linus.
[linux-2.6/linux-mips.git] / drivers / char / acquirewdt.c
blobeaa9e6bae6d6b779ebb1d8ef018a697848b312c1
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@redhat.com>, All Rights Reserved.
7 * http://www.redhat.com
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@redhat.com>
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>
40 #include <linux/spinlock.h>
42 static int acq_is_open=0;
43 static spinlock_t acq_lock;
46 * You must set these - there is no sane way to probe for this board.
49 #define WDT_STOP 0x43
50 #define WDT_START 0x443
52 #define WD_TIMO (100*60) /* 1 minute */
56 * Kernel methods.
60 static void acq_ping(void)
62 /* Write a watchdog value */
63 inb_p(WDT_START);
66 static ssize_t acq_write(struct file *file, const char *buf, size_t count, loff_t *ppos)
68 /* Can't seek (pwrite) on this device */
69 if (ppos != &file->f_pos)
70 return -ESPIPE;
72 if(count)
74 acq_ping();
75 return 1;
77 return 0;
80 static ssize_t acq_read(struct file *file, char *buf, size_t count, loff_t *ppos)
82 return -EINVAL;
87 static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
88 unsigned long arg)
90 static struct watchdog_info ident=
92 WDIOF_KEEPALIVEPING, 1, "Acquire WDT"
95 switch(cmd)
97 case WDIOC_GETSUPPORT:
98 if (copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
99 return -EFAULT;
100 break;
102 case WDIOC_GETSTATUS:
103 if (copy_to_user((int *)arg, &acq_is_open, sizeof(int)))
104 return -EFAULT;
105 break;
107 case WDIOC_KEEPALIVE:
108 acq_ping();
109 break;
111 default:
112 return -ENOIOCTLCMD;
114 return 0;
117 static int acq_open(struct inode *inode, struct file *file)
119 switch(MINOR(inode->i_rdev))
121 case WATCHDOG_MINOR:
122 spin_lock(&acq_lock);
123 if(acq_is_open)
125 spin_unlock(&acq_lock);
126 return -EBUSY;
129 * Activate
132 acq_is_open=1;
133 inb_p(WDT_START);
134 spin_unlock(&acq_lock);
135 return 0;
136 default:
137 return -ENODEV;
141 static int acq_close(struct inode *inode, struct file *file)
143 if(MINOR(inode->i_rdev)==WATCHDOG_MINOR)
145 spin_lock(&acq_lock);
146 #ifndef CONFIG_WATCHDOG_NOWAYOUT
147 inb_p(WDT_STOP);
148 #endif
149 acq_is_open=0;
150 spin_unlock(&acq_lock);
152 return 0;
156 * Notifier for system down
159 static int acq_notify_sys(struct notifier_block *this, unsigned long code,
160 void *unused)
162 if(code==SYS_DOWN || code==SYS_HALT)
164 /* Turn the card off */
165 inb_p(WDT_STOP);
167 return NOTIFY_DONE;
171 * Kernel Interfaces
175 static struct file_operations acq_fops = {
176 owner: THIS_MODULE,
177 read: acq_read,
178 write: acq_write,
179 ioctl: acq_ioctl,
180 open: acq_open,
181 release: acq_close,
184 static struct miscdevice acq_miscdev=
186 WATCHDOG_MINOR,
187 "watchdog",
188 &acq_fops
193 * The WDT card needs to learn about soft shutdowns in order to
194 * turn the timebomb registers off.
197 static struct notifier_block acq_notifier=
199 acq_notify_sys,
200 NULL,
204 #ifdef MODULE
206 #define acq_init init_module
208 void cleanup_module(void)
210 misc_deregister(&acq_miscdev);
211 unregister_reboot_notifier(&acq_notifier);
212 release_region(WDT_STOP,1);
213 release_region(WDT_START,1);
216 #endif
218 int __init acq_init(void)
220 printk("WDT driver for Acquire single board computer initialising.\n");
222 spin_lock_init(&acq_lock);
223 misc_register(&acq_miscdev);
224 request_region(WDT_STOP, 1, "Acquire WDT");
225 request_region(WDT_START, 1, "Acquire WDT");
226 register_reboot_notifier(&acq_notifier);
227 return 0;