2 * MixCom Watchdog: A Simple Hardware Watchdog Device
3 * Based on Softdog driver by Alan Cox and PC Watchdog driver by Ken Hollis
5 * Author: Gergely Madarasz <gorgo@itc.hu>
7 * Copyright (c) 1999 ITConsult-Pro Co. <info@itc.hu>
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 * Version 0.1 (99/04/15):
17 * Version 0.2 (99/06/16):
18 * - added kernel timer watchdog ping after close
19 * since the hardware does not support watchdog shutdown
21 * Version 0.3 (99/06/21):
22 * - added WDIOC_GETSTATUS and WDIOC_GETSUPPORT ioctl calls
24 * Version 0.3.1 (99/06/22):
25 * - allow module removal while internal timer is active,
26 * print warning about probable reset
30 #define VERSION "0.3.1"
32 #include <linux/module.h>
33 #include <linux/config.h>
34 #include <linux/types.h>
35 #include <linux/kernel.h>
38 #include <linux/miscdevice.h>
39 #include <linux/ioport.h>
40 #include <linux/watchdog.h>
41 #include <linux/reboot.h>
42 #include <linux/init.h>
43 #include <asm/uaccess.h>
46 static int mixcomwd_ioports
[] = { 0x180, 0x280, 0x380, 0x000 };
48 #define MIXCOM_WATCHDOG_OFFSET 0xc10
49 #define MIXCOM_ID1 0x11
50 #define MIXCOM_ID2 0x13
52 static int mixcomwd_opened
;
53 static int mixcomwd_port
;
55 #ifndef CONFIG_WATCHDOG_NOWAYOUT
56 static int mixcomwd_timer_alive
;
57 static struct timer_list mixcomwd_timer
;
60 static void mixcomwd_ping(void)
62 outb_p(55,mixcomwd_port
+MIXCOM_WATCHDOG_OFFSET
);
66 #ifndef CONFIG_WATCHDOG_NOWAYOUT
67 static void mixcomwd_timerfun(unsigned long d
)
71 mod_timer(&mixcomwd_timer
,jiffies
+ 5*HZ
);
76 * Allow only one person to hold it open
79 static int mixcomwd_open(struct inode
*inode
, struct file
*file
)
81 if(test_and_set_bit(0,&mixcomwd_opened
)) {
86 #ifndef CONFIG_WATCHDOG_NOWAYOUT
87 if(mixcomwd_timer_alive
) {
88 del_timer(&mixcomwd_timer
);
89 mixcomwd_timer_alive
=0;
97 static int mixcomwd_release(struct inode
*inode
, struct file
*file
)
100 #ifndef CONFIG_WATCHDOG_NOWAYOUT
101 if(mixcomwd_timer_alive
) {
102 printk(KERN_ERR
"mixcomwd: release called while internal timer alive");
105 init_timer(&mixcomwd_timer
);
106 mixcomwd_timer
.expires
=jiffies
+ 5 * HZ
;
107 mixcomwd_timer
.function
=mixcomwd_timerfun
;
108 mixcomwd_timer
.data
=0;
109 mixcomwd_timer_alive
=1;
110 add_timer(&mixcomwd_timer
);
114 clear_bit(0,&mixcomwd_opened
);
119 static ssize_t
mixcomwd_write(struct file
*file
, const char *data
, size_t len
, loff_t
*ppos
)
121 if (ppos
!= &file
->f_pos
) {
133 static int mixcomwd_ioctl(struct inode
*inode
, struct file
*file
,
134 unsigned int cmd
, unsigned long arg
)
137 static struct watchdog_info ident
= {
138 WDIOF_KEEPALIVEPING
, 1, "MixCOM watchdog"
143 case WDIOC_GETSTATUS
:
144 status
=mixcomwd_opened
;
145 #ifndef CONFIG_WATCHDOG_NOWAYOUT
146 status
|=mixcomwd_timer_alive
;
148 if (copy_to_user((int *)arg
, &status
, sizeof(int))) {
152 case WDIOC_GETSUPPORT
:
153 if (copy_to_user((struct watchdog_info
*)arg
, &ident
,
158 case WDIOC_KEEPALIVE
:
167 static struct file_operations mixcomwd_fops
=
171 mixcomwd_write
, /* Write */
174 mixcomwd_ioctl
, /* Ioctl */
183 static struct miscdevice mixcomwd_miscdev
=
190 static int __init
mixcomwd_checkcard(int port
)
194 if(check_region(port
,1)) {
198 id
=inb_p(port
+ MIXCOM_WATCHDOG_OFFSET
) & 0x3f;
199 if(id
!=MIXCOM_ID1
&& id
!=MIXCOM_ID2
) {
206 void __init
mixcomwd_init(void)
211 for (i
= 0; mixcomwd_ioports
[i
] != 0; i
++) {
212 if (mixcomwd_checkcard(mixcomwd_ioports
[i
])) {
214 mixcomwd_port
= mixcomwd_ioports
[i
];
220 printk("mixcomwd: No card detected, or port not available.\n");
224 request_region(mixcomwd_port
+MIXCOM_WATCHDOG_OFFSET
,1,"MixCOM watchdog");
226 misc_register(&mixcomwd_miscdev
);
227 printk("MixCOM watchdog driver v%s, MixCOM card at 0x%3x\n",VERSION
,mixcomwd_port
);
231 int init_module(void)
237 void cleanup_module(void)
239 #ifndef CONFIG_WATCHDOG_NOWAYOUT
240 if(mixcomwd_timer_alive
) {
241 printk(KERN_WARNING
"mixcomwd: I quit now, hardware will"
242 " probably reboot!\n");
243 del_timer(&mixcomwd_timer
);
244 mixcomwd_timer_alive
=0;
247 release_region(mixcomwd_port
+MIXCOM_WATCHDOG_OFFSET
,1);
248 misc_deregister(&mixcomwd_miscdev
);