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>
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.
50 #define WDT_START 0x443
52 #define WD_TIMO (100*60) /* 1 minute */
60 static void acq_ping(void)
62 /* Write a watchdog value */
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
)
80 static ssize_t
acq_read(struct file
*file
, char *buf
, size_t count
, loff_t
*ppos
)
87 static int acq_ioctl(struct inode
*inode
, struct file
*file
, unsigned int cmd
,
90 static struct watchdog_info ident
=
92 WDIOF_KEEPALIVEPING
, 1, "Acquire WDT"
97 case WDIOC_GETSUPPORT
:
98 if (copy_to_user((struct watchdog_info
*)arg
, &ident
, sizeof(ident
)))
102 case WDIOC_GETSTATUS
:
103 if (copy_to_user((int *)arg
, &acq_is_open
, sizeof(int)))
107 case WDIOC_KEEPALIVE
:
117 static int acq_open(struct inode
*inode
, struct file
*file
)
119 switch(MINOR(inode
->i_rdev
))
122 spin_lock(&acq_lock
);
125 spin_unlock(&acq_lock
);
134 spin_unlock(&acq_lock
);
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
150 spin_unlock(&acq_lock
);
156 * Notifier for system down
159 static int acq_notify_sys(struct notifier_block
*this, unsigned long code
,
162 if(code
==SYS_DOWN
|| code
==SYS_HALT
)
164 /* Turn the card off */
175 static struct file_operations acq_fops
= {
184 static struct miscdevice acq_miscdev
=
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
=
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);
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
);