blob: 8251d8378d2eb8ade9fcffaddd991ae0dcee7613 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PC Watchdog Driver
3 * by Ken Hollis (khollis@bitgate.com)
4 *
Wim Van Sebroeckf9146f22007-01-09 22:38:54 +01005 * Permission granted from Simon Machell (smachell@berkprod.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Written for the Linux Kernel, and GPLed by Ken Hollis
7 *
8 * 960107 Added request_region routines, modulized the whole thing.
9 * 960108 Fixed end-of-file pointer (Thanks to Dan Hollis), added
10 * WD_TIMEOUT define.
11 * 960216 Added eof marker on the file, and changed verbose messages.
12 * 960716 Made functional and cosmetic changes to the source for
13 * inclusion in Linux 2.0.x kernels, thanks to Alan Cox.
14 * 960717 Removed read/seek routines, replaced with ioctl. Also, added
15 * check_region command due to Alan's suggestion.
16 * 960821 Made changes to compile in newer 2.0.x kernels. Added
17 * "cold reboot sense" entry.
18 * 960825 Made a few changes to code, deleted some defines and made
19 * typedefs to replace them. Made heartbeat reset only available
20 * via ioctl, and removed the write routine.
21 * 960828 Added new items for PC Watchdog Rev.C card.
22 * 960829 Changed around all of the IOCTLs, added new features,
23 * added watchdog disable/re-enable routines. Added firmware
24 * version reporting. Added read routine for temperature.
25 * Removed some extra defines, added an autodetect Revision
26 * routine.
27 * 961006 Revised some documentation, fixed some cosmetic bugs. Made
28 * drivers to panic the system if it's overheating at bootup.
29 * 961118 Changed some verbiage on some of the output, tidied up
30 * code bits, and added compatibility to 2.1.x.
31 * 970912 Enabled board on open and disable on close.
32 * 971107 Took account of recent VFS changes (broke read).
33 * 971210 Disable board on initialisation in case board already ticking.
34 * 971222 Changed open/close for temperature handling
35 * Michael Meskes <meskes@debian.org>.
36 * 980112 Used minor numbers from include/linux/miscdevice.h
37 * 990403 Clear reset status after reading control status register in
38 * pcwd_showprevstate(). [Marc Boucher <marc@mbsi.ca>]
39 * 990605 Made changes to code to support Firmware 1.22a, added
40 * fairly useless proc entry.
41 * 990610 removed said useless proc code for the merge <alan>
42 * 000403 Removed last traces of proc code. <davej>
43 * 011214 Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
44 * Added timeout module option to override default
45 */
46
47/*
48 * A bells and whistles driver is available from http://www.pcwd.de/
49 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
50 */
51
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010052#include <linux/module.h> /* For module specific items */
53#include <linux/moduleparam.h> /* For new moduleparam's */
54#include <linux/types.h> /* For standard types (like size_t) */
55#include <linux/errno.h> /* For the -ENODEV/... values */
56#include <linux/kernel.h> /* For printk/panic/... */
57#include <linux/delay.h> /* For mdelay function */
58#include <linux/timer.h> /* For timer related operations */
59#include <linux/jiffies.h> /* For jiffies stuff */
60#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
61#include <linux/watchdog.h> /* For the watchdog specific items */
62#include <linux/notifier.h> /* For notifier support */
63#include <linux/reboot.h> /* For reboot_notifier stuff */
64#include <linux/init.h> /* For __init/__exit/... */
65#include <linux/fs.h> /* For file operations */
66#include <linux/ioport.h> /* For io-port access */
67#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010069#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
70#include <asm/io.h> /* For inb/outb/... */
71
72/* Module and version information */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +010073#define WATCHDOG_VERSION "1.17"
74#define WATCHDOG_DATE "12 Feb 2006"
Wim Van Sebroecka7122f92006-01-09 22:07:22 +010075#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
76#define WATCHDOG_NAME "pcwd"
77#define PFX WATCHDOG_NAME ": "
78#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
79#define WD_VER WATCHDOG_VERSION " (" WATCHDOG_DATE ")"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81/*
82 * It should be noted that PCWD_REVISION_B was removed because A and B
83 * are essentially the same types of card, with the exception that B
84 * has temperature reporting. Since I didn't receive a Rev.B card,
85 * the Rev.B card is not supported. (It's a good thing too, as they
86 * are no longer in production.)
87 */
88#define PCWD_REVISION_A 1
89#define PCWD_REVISION_C 2
90
91/*
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +010092 * These are the defines that describe the control status bits for the
93 * PCI-PC Watchdog card.
94*/
95/* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +010096#define WD_WDRST 0x01 /* Previously reset state */
97#define WD_T110 0x02 /* Temperature overheat sense */
98#define WD_HRTBT 0x04 /* Heartbeat sense */
99#define WD_RLY2 0x08 /* External relay triggered */
100#define WD_SRLY2 0x80 /* Software external relay triggered */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100101/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100102#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
103#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
104#define WD_REVC_TTRP 0x04 /* Temperature Trip status */
105#define WD_REVC_RL2A 0x08 /* Relay 2 activated by on-board processor */
106#define WD_REVC_RL1A 0x10 /* Relay 1 active */
107#define WD_REVC_R2DS 0x40 /* Relay 2 disable */
108#define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100109/* Port 2 : Control Status #2 */
110#define WD_WDIS 0x10 /* Watchdog Disabled */
111#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
112#define WD_SSEL 0x40 /* Watchdog Switch Select (1:SW1 <-> 0:SW2) */
113#define WD_WCMD 0x80 /* Watchdog Command Mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115/* max. time we give an ISA watchdog card to process a command */
116/* 500ms for each 4 bit response (according to spec.) */
117#define ISA_COMMAND_TIMEOUT 1000
118
119/* Watchdog's internal commands */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100120#define CMD_ISA_IDLE 0x00
121#define CMD_ISA_VERSION_INTEGER 0x01
122#define CMD_ISA_VERSION_TENTH 0x02
123#define CMD_ISA_VERSION_HUNDRETH 0x03
124#define CMD_ISA_VERSION_MINOR 0x04
125#define CMD_ISA_SWITCH_SETTINGS 0x05
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100126#define CMD_ISA_RESET_PC 0x06
127#define CMD_ISA_ARM_0 0x07
128#define CMD_ISA_ARM_30 0x08
129#define CMD_ISA_ARM_60 0x09
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100130#define CMD_ISA_DELAY_TIME_2SECS 0x0A
131#define CMD_ISA_DELAY_TIME_4SECS 0x0B
132#define CMD_ISA_DELAY_TIME_8SECS 0x0C
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100133#define CMD_ISA_RESET_RELAYS 0x0D
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135/*
136 * We are using an kernel timer to do the pinging of the watchdog
137 * every ~500ms. We try to set the internal heartbeat of the
138 * watchdog to 2 ms.
139 */
140
141#define WDT_INTERVAL (HZ/2+1)
142
143/* We can only use 1 card due to the /dev/watchdog restriction */
144static int cards_found;
145
146/* internal variables */
147static atomic_t open_allowed = ATOMIC_INIT(1);
148static char expect_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149static int temp_panic;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100150static struct { /* this is private data for each ISA-PC watchdog card */
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100151 char fw_ver_str[6]; /* The cards firmware version */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100152 int revision; /* The card's revision */
153 int supports_temp; /* Wether or not the card has a temperature device */
154 int command_mode; /* Wether or not the card is in command mode */
155 int boot_status; /* The card's boot status */
156 int io_addr; /* The cards I/O address */
157 spinlock_t io_lock; /* the lock for io operations */
158 struct timer_list timer; /* The timer that pings the watchdog */
159 unsigned long next_heartbeat; /* the next_heartbeat for the timer */
160} pcwd_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162/* module parameters */
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100163#define QUIET 0 /* Default */
164#define VERBOSE 1 /* Verbose */
165#define DEBUG 2 /* print fancy stuff too */
166static int debug = QUIET;
167module_param(debug, int, 0);
168MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat */
171static int heartbeat = WATCHDOG_HEARTBEAT;
172module_param(heartbeat, int, 0);
173MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
174
Andrey Panin4bfdf372005-07-27 11:43:58 -0700175static int nowayout = WATCHDOG_NOWAYOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176module_param(nowayout, int, 0);
177MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
178
179/*
180 * Internal functions
181 */
182
183static int send_isa_command(int cmd)
184{
185 int i;
186 int control_status;
187 int port0, last_port0; /* Double read for stabilising */
188
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100189 if (debug >= DEBUG)
190 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
191 cmd);
192
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 /* The WCMD bit must be 1 and the command is only 4 bits in size */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100194 control_status = (cmd & 0x0F) | WD_WCMD;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100195 outb_p(control_status, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 udelay(ISA_COMMAND_TIMEOUT);
197
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100198 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 for (i = 0; i < 25; ++i) {
200 last_port0 = port0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100201 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if (port0 == last_port0)
204 break; /* Data is stable */
205
206 udelay (250);
207 }
208
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100209 if (debug >= DEBUG)
210 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
211 cmd, port0, last_port0);
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 return port0;
214}
215
216static int set_command_mode(void)
217{
218 int i, found=0, count=0;
219
220 /* Set the card into command mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100221 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 while ((!found) && (count < 3)) {
223 i = send_isa_command(CMD_ISA_IDLE);
224
225 if (i == 0x00)
226 found = 1;
227 else if (i == 0xF3) {
228 /* Card does not like what we've done to it */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100229 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 udelay(1200); /* Spec says wait 1ms */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100231 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 udelay(ISA_COMMAND_TIMEOUT);
233 }
234 count++;
235 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100236 spin_unlock(&pcwd_private.io_lock);
237 pcwd_private.command_mode = found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100239 if (debug >= DEBUG)
240 printk(KERN_DEBUG PFX "command_mode=%d\n",
241 pcwd_private.command_mode);
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 return(found);
244}
245
246static void unset_command_mode(void)
247{
248 /* Set the card into normal mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100249 spin_lock(&pcwd_private.io_lock);
250 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100252 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100254 pcwd_private.command_mode = 0;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100255
256 if (debug >= DEBUG)
257 printk(KERN_DEBUG PFX "command_mode=%d\n",
258 pcwd_private.command_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100261static inline void pcwd_check_temperature_support(void)
262{
263 if (inb(pcwd_private.io_addr) != 0xF0)
264 pcwd_private.supports_temp = 1;
265}
266
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100267static inline void pcwd_get_firmware(void)
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100268{
269 int one, ten, hund, minor;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100270
Wim Van Sebroeck6bbc20b2006-03-02 20:05:16 +0100271 strcpy(pcwd_private.fw_ver_str, "ERROR");
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100272
273 if (set_command_mode()) {
274 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
275 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
276 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
277 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100278 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100279 }
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100280 unset_command_mode();
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100281
282 return;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100283}
284
285static inline int pcwd_get_option_switches(void)
286{
287 int option_switches=0;
288
289 if (set_command_mode()) {
290 /* Get switch settings */
291 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
292 }
293
294 unset_command_mode();
295 return(option_switches);
296}
297
298static void pcwd_show_card_info(void)
299{
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100300 int option_switches;
301
302 /* Get some extra info from the hardware (in command/debug/diag mode) */
303 if (pcwd_private.revision == PCWD_REVISION_A)
304 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
305 else if (pcwd_private.revision == PCWD_REVISION_C) {
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100306 pcwd_get_firmware();
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100307 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100308 pcwd_private.io_addr, pcwd_private.fw_ver_str);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100309 option_switches = pcwd_get_option_switches();
310 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
311 option_switches,
312 ((option_switches & 0x10) ? "ON" : "OFF"),
313 ((option_switches & 0x08) ? "ON" : "OFF"));
314
315 /* Reprogram internal heartbeat to 2 seconds */
316 if (set_command_mode()) {
317 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
318 unset_command_mode();
319 }
320 }
321
322 if (pcwd_private.supports_temp)
323 printk(KERN_INFO PFX "Temperature Option Detected\n");
324
325 if (pcwd_private.boot_status & WDIOF_CARDRESET)
326 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
327
328 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
329 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
330 printk(KERN_EMERG PFX "CPU Overheat\n");
331 }
332
333 if (pcwd_private.boot_status == 0)
334 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
335}
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337static void pcwd_timer_ping(unsigned long data)
338{
339 int wdrst_stat;
340
341 /* If we got a heartbeat pulse within the WDT_INTERVAL
342 * we agree to ping the WDT */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100343 if(time_before(jiffies, pcwd_private.next_heartbeat)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 /* Ping the watchdog */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100345 spin_lock(&pcwd_private.io_lock);
346 if (pcwd_private.revision == PCWD_REVISION_A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* Rev A cards are reset by setting the WD_WDRST bit in register 1 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100348 wdrst_stat = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 wdrst_stat &= 0x0F;
350 wdrst_stat |= WD_WDRST;
351
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100352 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 } else {
354 /* Re-trigger watchdog by writing to port 0 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100355 outb_p(0x00, pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 /* Re-set the timer interval */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100359 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100361 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 } else {
363 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
364 }
365}
366
367static int pcwd_start(void)
368{
369 int stat_reg;
370
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100371 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373 /* Start the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100374 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 /* Enable the port */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100377 if (pcwd_private.revision == PCWD_REVISION_C) {
378 spin_lock(&pcwd_private.io_lock);
379 outb_p(0x00, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100381 stat_reg = inb_p(pcwd_private.io_addr + 2);
382 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100383 if (stat_reg & WD_WDIS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 printk(KERN_INFO PFX "Could not start watchdog\n");
385 return -EIO;
386 }
387 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100388
389 if (debug >= VERBOSE)
390 printk(KERN_DEBUG PFX "Watchdog started\n");
391
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 return 0;
393}
394
395static int pcwd_stop(void)
396{
397 int stat_reg;
398
399 /* Stop the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100400 del_timer(&pcwd_private.timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402 /* Disable the board */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100403 if (pcwd_private.revision == PCWD_REVISION_C) {
404 spin_lock(&pcwd_private.io_lock);
405 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100407 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100409 stat_reg = inb_p(pcwd_private.io_addr + 2);
410 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100411 if ((stat_reg & WD_WDIS) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 printk(KERN_INFO PFX "Could not stop watchdog\n");
413 return -EIO;
414 }
415 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100416
417 if (debug >= VERBOSE)
418 printk(KERN_DEBUG PFX "Watchdog stopped\n");
419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return 0;
421}
422
423static int pcwd_keepalive(void)
424{
425 /* user land ping */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100426 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100427
428 if (debug >= DEBUG)
429 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 return 0;
432}
433
434static int pcwd_set_heartbeat(int t)
435{
436 if ((t < 2) || (t > 7200)) /* arbitrary upper limit */
437 return -EINVAL;
438
439 heartbeat = t;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100440
441 if (debug >= VERBOSE)
442 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
443 heartbeat);
444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 return 0;
446}
447
448static int pcwd_get_status(int *status)
449{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100450 int control_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452 *status=0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100453 spin_lock(&pcwd_private.io_lock);
454 if (pcwd_private.revision == PCWD_REVISION_A)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 /* Rev A cards return status information from
456 * the base register, which is used for the
457 * temperature in other cards. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100458 control_status = inb(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 else {
460 /* Rev C cards return card status in the base
461 * address + 1 register. And use different bits
462 * to indicate a card initiated reset, and an
463 * over-temperature condition. And the reboot
464 * status can be reset. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100465 control_status = inb(pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100467 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100469 if (pcwd_private.revision == PCWD_REVISION_A) {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100470 if (control_status & WD_WDRST)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 *status |= WDIOF_CARDRESET;
472
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100473 if (control_status & WD_T110) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 *status |= WDIOF_OVERHEAT;
475 if (temp_panic) {
476 printk (KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600477 kernel_power_off();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100478 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480 }
481 } else {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100482 if (control_status & WD_REVC_WTRP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 *status |= WDIOF_CARDRESET;
484
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100485 if (control_status & WD_REVC_TTRP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 *status |= WDIOF_OVERHEAT;
487 if (temp_panic) {
488 printk (KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600489 kernel_power_off();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100490 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492 }
493 }
494
495 return 0;
496}
497
498static int pcwd_clear_status(void)
499{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100500 int control_status;
501
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100502 if (pcwd_private.revision == PCWD_REVISION_C) {
503 spin_lock(&pcwd_private.io_lock);
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100504
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100505 if (debug >= VERBOSE)
506 printk(KERN_INFO PFX "clearing watchdog trip status\n");
507
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100508 control_status = inb_p(pcwd_private.io_addr + 1);
509
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100510 if (debug >= DEBUG) {
511 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
512 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
513 (control_status & WD_REVC_R2DS));
514 }
515
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100516 /* clear reset status & Keep Relay 2 disable state as it is */
517 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
518
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100519 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521 return 0;
522}
523
524static int pcwd_get_temperature(int *temperature)
525{
526 /* check that port 0 gives temperature info and no command results */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100527 if (pcwd_private.command_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return -1;
529
530 *temperature = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100531 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 return -ENODEV;
533
534 /*
535 * Convert celsius to fahrenheit, since this was
536 * the decided 'standard' for this return value.
537 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100538 spin_lock(&pcwd_private.io_lock);
539 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
540 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100542 if (debug >= DEBUG) {
543 printk(KERN_DEBUG PFX "temperature is: %d F\n",
544 *temperature);
545 }
546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return 0;
548}
549
550/*
551 * /dev/watchdog handling
552 */
553
554static int pcwd_ioctl(struct inode *inode, struct file *file,
555 unsigned int cmd, unsigned long arg)
556{
557 int rv;
558 int status;
559 int temperature;
560 int new_heartbeat;
561 int __user *argp = (int __user *)arg;
562 static struct watchdog_info ident = {
563 .options = WDIOF_OVERHEAT |
564 WDIOF_CARDRESET |
565 WDIOF_KEEPALIVEPING |
566 WDIOF_SETTIMEOUT |
567 WDIOF_MAGICCLOSE,
568 .firmware_version = 1,
569 .identity = "PCWD",
570 };
571
572 switch(cmd) {
573 default:
Samuel Tardieu795b89d2006-09-09 17:34:31 +0200574 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 case WDIOC_GETSUPPORT:
577 if(copy_to_user(argp, &ident, sizeof(ident)))
578 return -EFAULT;
579 return 0;
580
581 case WDIOC_GETSTATUS:
582 pcwd_get_status(&status);
583 return put_user(status, argp);
584
585 case WDIOC_GETBOOTSTATUS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100586 return put_user(pcwd_private.boot_status, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 case WDIOC_GETTEMP:
589 if (pcwd_get_temperature(&temperature))
590 return -EFAULT;
591
592 return put_user(temperature, argp);
593
594 case WDIOC_SETOPTIONS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100595 if (pcwd_private.revision == PCWD_REVISION_C)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 {
597 if(copy_from_user(&rv, argp, sizeof(int)))
598 return -EFAULT;
599
600 if (rv & WDIOS_DISABLECARD)
601 {
602 return pcwd_stop();
603 }
604
605 if (rv & WDIOS_ENABLECARD)
606 {
607 return pcwd_start();
608 }
609
610 if (rv & WDIOS_TEMPPANIC)
611 {
612 temp_panic = 1;
613 }
614 }
615 return -EINVAL;
616
617 case WDIOC_KEEPALIVE:
618 pcwd_keepalive();
619 return 0;
620
621 case WDIOC_SETTIMEOUT:
622 if (get_user(new_heartbeat, argp))
623 return -EFAULT;
624
625 if (pcwd_set_heartbeat(new_heartbeat))
626 return -EINVAL;
627
628 pcwd_keepalive();
629 /* Fall */
630
631 case WDIOC_GETTIMEOUT:
632 return put_user(heartbeat, argp);
633 }
634
635 return 0;
636}
637
638static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
639 loff_t *ppos)
640{
641 if (len) {
642 if (!nowayout) {
643 size_t i;
644
645 /* In case it was set long ago */
646 expect_close = 0;
647
648 for (i = 0; i != len; i++) {
649 char c;
650
651 if (get_user(c, buf + i))
652 return -EFAULT;
653 if (c == 'V')
654 expect_close = 42;
655 }
656 }
657 pcwd_keepalive();
658 }
659 return len;
660}
661
662static int pcwd_open(struct inode *inode, struct file *file)
663{
664 if (!atomic_dec_and_test(&open_allowed) ) {
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100665 if (debug >= VERBOSE)
666 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 atomic_inc( &open_allowed );
668 return -EBUSY;
669 }
670
671 if (nowayout)
672 __module_get(THIS_MODULE);
673
674 /* Activate */
675 pcwd_start();
676 pcwd_keepalive();
677 return nonseekable_open(inode, file);
678}
679
680static int pcwd_close(struct inode *inode, struct file *file)
681{
682 if (expect_close == 42) {
683 pcwd_stop();
684 } else {
685 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
686 pcwd_keepalive();
687 }
688 expect_close = 0;
689 atomic_inc( &open_allowed );
690 return 0;
691}
692
693/*
694 * /dev/temperature handling
695 */
696
697static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
698 loff_t *ppos)
699{
700 int temperature;
701
702 if (pcwd_get_temperature(&temperature))
703 return -EFAULT;
704
705 if (copy_to_user(buf, &temperature, 1))
706 return -EFAULT;
707
708 return 1;
709}
710
711static int pcwd_temp_open(struct inode *inode, struct file *file)
712{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100713 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return -ENODEV;
715
716 return nonseekable_open(inode, file);
717}
718
719static int pcwd_temp_close(struct inode *inode, struct file *file)
720{
721 return 0;
722}
723
724/*
725 * Notify system
726 */
727
728static int pcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
729{
730 if (code==SYS_DOWN || code==SYS_HALT) {
731 /* Turn the WDT off */
732 pcwd_stop();
733 }
734
735 return NOTIFY_DONE;
736}
737
738/*
739 * Kernel Interfaces
740 */
741
Arjan van de Ven62322d22006-07-03 00:24:21 -0700742static const struct file_operations pcwd_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 .owner = THIS_MODULE,
744 .llseek = no_llseek,
745 .write = pcwd_write,
746 .ioctl = pcwd_ioctl,
747 .open = pcwd_open,
748 .release = pcwd_close,
749};
750
751static struct miscdevice pcwd_miscdev = {
752 .minor = WATCHDOG_MINOR,
753 .name = "watchdog",
754 .fops = &pcwd_fops,
755};
756
Arjan van de Ven62322d22006-07-03 00:24:21 -0700757static const struct file_operations pcwd_temp_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 .owner = THIS_MODULE,
759 .llseek = no_llseek,
760 .read = pcwd_temp_read,
761 .open = pcwd_temp_open,
762 .release = pcwd_temp_close,
763};
764
765static struct miscdevice temp_miscdev = {
766 .minor = TEMP_MINOR,
767 .name = "temperature",
768 .fops = &pcwd_temp_fops,
769};
770
771static struct notifier_block pcwd_notifier = {
772 .notifier_call = pcwd_notify_sys,
773};
774
775/*
776 * Init & exit routines
777 */
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779static inline int get_revision(void)
780{
781 int r = PCWD_REVISION_C;
782
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100783 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 /* REV A cards use only 2 io ports; test
785 * presumes a floating bus reads as 0xff. */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100786 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
787 (inb(pcwd_private.io_addr + 3) == 0xFF))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 r=PCWD_REVISION_A;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100789 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
791 return r;
792}
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794static int __devinit pcwatchdog_init(int base_addr)
795{
796 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798 cards_found++;
799 if (cards_found == 1)
800 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
801
802 if (cards_found > 1) {
803 printk(KERN_ERR PFX "This driver only supports 1 device\n");
804 return -ENODEV;
805 }
806
807 if (base_addr == 0x0000) {
808 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
809 return -ENODEV;
810 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100811 pcwd_private.io_addr = base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 /* Check card's revision */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100814 pcwd_private.revision = get_revision();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100816 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100818 pcwd_private.io_addr);
819 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return -EIO;
821 }
822
823 /* Initial variables */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100824 pcwd_private.supports_temp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 temp_panic = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100826 pcwd_private.boot_status = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 /* get the boot_status */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100829 pcwd_get_status(&pcwd_private.boot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830
831 /* clear the "card caused reboot" flag */
832 pcwd_clear_status();
833
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100834 init_timer(&pcwd_private.timer);
835 pcwd_private.timer.function = pcwd_timer_ping;
836 pcwd_private.timer.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837
838 /* Disable the board */
839 pcwd_stop();
840
841 /* Check whether or not the card supports the temperature device */
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100842 pcwd_check_temperature_support();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100844 /* Show info about the card itself */
845 pcwd_show_card_info();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846
847 /* Check that the heartbeat value is within it's range ; if not reset to the default */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100848 if (pcwd_set_heartbeat(heartbeat)) {
849 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
850 printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
851 WATCHDOG_HEARTBEAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853
854 ret = register_reboot_notifier(&pcwd_notifier);
855 if (ret) {
856 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
857 ret);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100858 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
859 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 return ret;
861 }
862
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100863 if (pcwd_private.supports_temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 ret = misc_register(&temp_miscdev);
865 if (ret) {
866 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
867 TEMP_MINOR, ret);
868 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100869 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
870 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 return ret;
872 }
873 }
874
875 ret = misc_register(&pcwd_miscdev);
876 if (ret) {
877 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
878 WATCHDOG_MINOR, ret);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100879 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 misc_deregister(&temp_miscdev);
881 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100882 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
883 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 return ret;
885 }
886
887 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
888 heartbeat, nowayout);
889
890 return 0;
891}
892
893static void __devexit pcwatchdog_exit(void)
894{
895 /* Disable the board */
896 if (!nowayout)
897 pcwd_stop();
898
899 /* Deregister */
900 misc_deregister(&pcwd_miscdev);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100901 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 misc_deregister(&temp_miscdev);
903 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100904 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
905 pcwd_private.io_addr = 0x0000;
Wim Van Sebroeckf1c3a052005-12-10 14:36:24 +0100906 cards_found--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907}
908
909/*
910 * The ISA cards have a heartbeat bit in one of the registers, which
911 * register is card dependent. The heartbeat bit is monitored, and if
912 * found, is considered proof that a Berkshire card has been found.
913 * The initial rate is once per second at board start up, then twice
914 * per second for normal operation.
915 */
916static int __init pcwd_checkcard(int base_addr)
917{
918 int port0, last_port0; /* Reg 0, in case it's REV A */
919 int port1, last_port1; /* Register 1 for REV C cards */
920 int i;
921 int retval;
922
923 if (!request_region (base_addr, 4, "PCWD")) {
924 printk (KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
925 return 0;
926 }
927
928 retval = 0;
929
930 port0 = inb_p(base_addr); /* For REV A boards */
931 port1 = inb_p(base_addr + 1); /* For REV C boards */
932 if (port0 != 0xff || port1 != 0xff) {
933 /* Not an 'ff' from a floating bus, so must be a card! */
934 for (i = 0; i < 4; ++i) {
935
936 msleep(500);
937
938 last_port0 = port0;
939 last_port1 = port1;
940
941 port0 = inb_p(base_addr);
942 port1 = inb_p(base_addr + 1);
943
944 /* Has either hearbeat bit changed? */
945 if ((port0 ^ last_port0) & WD_HRTBT ||
946 (port1 ^ last_port1) & WD_REVC_HRBT) {
947 retval = 1;
948 break;
949 }
950 }
951 }
952 release_region (base_addr, 4);
953
954 return retval;
955}
956
957/*
958 * These are the auto-probe addresses available.
959 *
960 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
961 * Revision A has an address range of 2 addresses, while Revision C has 4.
962 */
963static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
964
965static int __init pcwd_init_module(void)
966{
967 int i, found = 0;
968
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100969 spin_lock_init(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 for (i = 0; pcwd_ioports[i] != 0; i++) {
972 if (pcwd_checkcard(pcwd_ioports[i])) {
973 if (!(pcwatchdog_init(pcwd_ioports[i])))
974 found++;
975 }
976 }
977
978 if (!found) {
979 printk (KERN_INFO PFX "No card detected, or port not available\n");
980 return -ENODEV;
981 }
982
983 return 0;
984}
985
986static void __exit pcwd_cleanup_module(void)
987{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100988 if (pcwd_private.io_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 pcwatchdog_exit();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100990
991 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992}
993
994module_init(pcwd_init_module);
995module_exit(pcwd_cleanup_module);
996
997MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>");
998MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
999MODULE_LICENSE("GPL");
1000MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1001MODULE_ALIAS_MISCDEV(TEMP_MINOR);