blob: 0e4b3dfa008422e400df033a240ddc970d0733a7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PC Watchdog Driver
3 * by Ken Hollis (khollis@bitgate.com)
4 *
5 * Permission granted from Simon Machell (73244.1270@compuserve.com)
6 * 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/config.h> /* For CONFIG_WATCHDOG_NOWAYOUT/... */
53#include <linux/module.h> /* For module specific items */
54#include <linux/moduleparam.h> /* For new moduleparam's */
55#include <linux/types.h> /* For standard types (like size_t) */
56#include <linux/errno.h> /* For the -ENODEV/... values */
57#include <linux/kernel.h> /* For printk/panic/... */
58#include <linux/delay.h> /* For mdelay function */
59#include <linux/timer.h> /* For timer related operations */
60#include <linux/jiffies.h> /* For jiffies stuff */
61#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
62#include <linux/watchdog.h> /* For the watchdog specific items */
63#include <linux/notifier.h> /* For notifier support */
64#include <linux/reboot.h> /* For reboot_notifier stuff */
65#include <linux/init.h> /* For __init/__exit/... */
66#include <linux/fs.h> /* For file operations */
67#include <linux/ioport.h> /* For io-port access */
68#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
Tim Schmielau4e57b682005-10-30 15:03:48 -080069#include <linux/sched.h> /* TASK_INTERRUPTIBLE, set_current_state() and friends */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010070#include <linux/slab.h> /* For kmalloc */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010072#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
73#include <asm/io.h> /* For inb/outb/... */
74
75/* Module and version information */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +010076#define WATCHDOG_VERSION "1.17"
77#define WATCHDOG_DATE "12 Feb 2006"
Wim Van Sebroecka7122f92006-01-09 22:07:22 +010078#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
79#define WATCHDOG_NAME "pcwd"
80#define PFX WATCHDOG_NAME ": "
81#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
82#define WD_VER WATCHDOG_VERSION " (" WATCHDOG_DATE ")"
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84/*
85 * It should be noted that PCWD_REVISION_B was removed because A and B
86 * are essentially the same types of card, with the exception that B
87 * has temperature reporting. Since I didn't receive a Rev.B card,
88 * the Rev.B card is not supported. (It's a good thing too, as they
89 * are no longer in production.)
90 */
91#define PCWD_REVISION_A 1
92#define PCWD_REVISION_C 2
93
94/*
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +010095 * These are the defines that describe the control status bits for the
96 * PCI-PC Watchdog card.
97*/
98/* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +010099#define WD_WDRST 0x01 /* Previously reset state */
100#define WD_T110 0x02 /* Temperature overheat sense */
101#define WD_HRTBT 0x04 /* Heartbeat sense */
102#define WD_RLY2 0x08 /* External relay triggered */
103#define WD_SRLY2 0x80 /* Software external relay triggered */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100104/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100105#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
106#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
107#define WD_REVC_TTRP 0x04 /* Temperature Trip status */
108#define WD_REVC_RL2A 0x08 /* Relay 2 activated by on-board processor */
109#define WD_REVC_RL1A 0x10 /* Relay 1 active */
110#define WD_REVC_R2DS 0x40 /* Relay 2 disable */
111#define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100112/* Port 2 : Control Status #2 */
113#define WD_WDIS 0x10 /* Watchdog Disabled */
114#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
115#define WD_SSEL 0x40 /* Watchdog Switch Select (1:SW1 <-> 0:SW2) */
116#define WD_WCMD 0x80 /* Watchdog Command Mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/* max. time we give an ISA watchdog card to process a command */
119/* 500ms for each 4 bit response (according to spec.) */
120#define ISA_COMMAND_TIMEOUT 1000
121
122/* Watchdog's internal commands */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100123#define CMD_ISA_IDLE 0x00
124#define CMD_ISA_VERSION_INTEGER 0x01
125#define CMD_ISA_VERSION_TENTH 0x02
126#define CMD_ISA_VERSION_HUNDRETH 0x03
127#define CMD_ISA_VERSION_MINOR 0x04
128#define CMD_ISA_SWITCH_SETTINGS 0x05
129#define CMD_ISA_DELAY_TIME_2SECS 0x0A
130#define CMD_ISA_DELAY_TIME_4SECS 0x0B
131#define CMD_ISA_DELAY_TIME_8SECS 0x0C
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/*
134 * We are using an kernel timer to do the pinging of the watchdog
135 * every ~500ms. We try to set the internal heartbeat of the
136 * watchdog to 2 ms.
137 */
138
139#define WDT_INTERVAL (HZ/2+1)
140
141/* We can only use 1 card due to the /dev/watchdog restriction */
142static int cards_found;
143
144/* internal variables */
145static atomic_t open_allowed = ATOMIC_INIT(1);
146static char expect_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147static int temp_panic;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100148static struct { /* this is private data for each ISA-PC watchdog card */
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100149 char fw_ver_str[6]; /* The cards firmware version */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100150 int revision; /* The card's revision */
151 int supports_temp; /* Wether or not the card has a temperature device */
152 int command_mode; /* Wether or not the card is in command mode */
153 int boot_status; /* The card's boot status */
154 int io_addr; /* The cards I/O address */
155 spinlock_t io_lock; /* the lock for io operations */
156 struct timer_list timer; /* The timer that pings the watchdog */
157 unsigned long next_heartbeat; /* the next_heartbeat for the timer */
158} pcwd_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
160/* module parameters */
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100161#define QUIET 0 /* Default */
162#define VERBOSE 1 /* Verbose */
163#define DEBUG 2 /* print fancy stuff too */
164static int debug = QUIET;
165module_param(debug, int, 0);
166MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat */
169static int heartbeat = WATCHDOG_HEARTBEAT;
170module_param(heartbeat, int, 0);
171MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
172
Andrey Panin4bfdf372005-07-27 11:43:58 -0700173static int nowayout = WATCHDOG_NOWAYOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174module_param(nowayout, int, 0);
175MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
176
177/*
178 * Internal functions
179 */
180
181static int send_isa_command(int cmd)
182{
183 int i;
184 int control_status;
185 int port0, last_port0; /* Double read for stabilising */
186
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100187 if (debug >= DEBUG)
188 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
189 cmd);
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 /* The WCMD bit must be 1 and the command is only 4 bits in size */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100192 control_status = (cmd & 0x0F) | WD_WCMD;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100193 outb_p(control_status, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 udelay(ISA_COMMAND_TIMEOUT);
195
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100196 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 for (i = 0; i < 25; ++i) {
198 last_port0 = port0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100199 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 if (port0 == last_port0)
202 break; /* Data is stable */
203
204 udelay (250);
205 }
206
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100207 if (debug >= DEBUG)
208 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
209 cmd, port0, last_port0);
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 return port0;
212}
213
214static int set_command_mode(void)
215{
216 int i, found=0, count=0;
217
218 /* Set the card into command mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100219 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 while ((!found) && (count < 3)) {
221 i = send_isa_command(CMD_ISA_IDLE);
222
223 if (i == 0x00)
224 found = 1;
225 else if (i == 0xF3) {
226 /* Card does not like what we've done to it */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100227 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 udelay(1200); /* Spec says wait 1ms */
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(ISA_COMMAND_TIMEOUT);
231 }
232 count++;
233 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100234 spin_unlock(&pcwd_private.io_lock);
235 pcwd_private.command_mode = found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100237 if (debug >= DEBUG)
238 printk(KERN_DEBUG PFX "command_mode=%d\n",
239 pcwd_private.command_mode);
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return(found);
242}
243
244static void unset_command_mode(void)
245{
246 /* Set the card into normal mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100247 spin_lock(&pcwd_private.io_lock);
248 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100250 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100252 pcwd_private.command_mode = 0;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100253
254 if (debug >= DEBUG)
255 printk(KERN_DEBUG PFX "command_mode=%d\n",
256 pcwd_private.command_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100259static inline void pcwd_check_temperature_support(void)
260{
261 if (inb(pcwd_private.io_addr) != 0xF0)
262 pcwd_private.supports_temp = 1;
263}
264
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100265static inline void pcwd_get_firmware(void)
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100266{
267 int one, ten, hund, minor;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100268
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100269 sprintf(pcwd_private.fw_ver_str, "ERROR");
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100270
271 if (set_command_mode()) {
272 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
273 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
274 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
275 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100276 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100277 }
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100278 unset_command_mode();
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100279
280 return;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100281}
282
283static inline int pcwd_get_option_switches(void)
284{
285 int option_switches=0;
286
287 if (set_command_mode()) {
288 /* Get switch settings */
289 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
290 }
291
292 unset_command_mode();
293 return(option_switches);
294}
295
296static void pcwd_show_card_info(void)
297{
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100298 int option_switches;
299
300 /* Get some extra info from the hardware (in command/debug/diag mode) */
301 if (pcwd_private.revision == PCWD_REVISION_A)
302 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
303 else if (pcwd_private.revision == PCWD_REVISION_C) {
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100304 pcwd_get_firmware();
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100305 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 +0100306 pcwd_private.io_addr, pcwd_private.fw_ver_str);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100307 option_switches = pcwd_get_option_switches();
308 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
309 option_switches,
310 ((option_switches & 0x10) ? "ON" : "OFF"),
311 ((option_switches & 0x08) ? "ON" : "OFF"));
312
313 /* Reprogram internal heartbeat to 2 seconds */
314 if (set_command_mode()) {
315 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
316 unset_command_mode();
317 }
318 }
319
320 if (pcwd_private.supports_temp)
321 printk(KERN_INFO PFX "Temperature Option Detected\n");
322
323 if (pcwd_private.boot_status & WDIOF_CARDRESET)
324 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
325
326 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
327 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
328 printk(KERN_EMERG PFX "CPU Overheat\n");
329 }
330
331 if (pcwd_private.boot_status == 0)
332 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
333}
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335static void pcwd_timer_ping(unsigned long data)
336{
337 int wdrst_stat;
338
339 /* If we got a heartbeat pulse within the WDT_INTERVAL
340 * we agree to ping the WDT */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100341 if(time_before(jiffies, pcwd_private.next_heartbeat)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 /* Ping the watchdog */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100343 spin_lock(&pcwd_private.io_lock);
344 if (pcwd_private.revision == PCWD_REVISION_A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /* Rev A cards are reset by setting the WD_WDRST bit in register 1 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100346 wdrst_stat = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 wdrst_stat &= 0x0F;
348 wdrst_stat |= WD_WDRST;
349
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100350 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 } else {
352 /* Re-trigger watchdog by writing to port 0 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100353 outb_p(0x00, pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 }
355
356 /* Re-set the timer interval */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100357 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100359 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 } else {
361 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
362 }
363}
364
365static int pcwd_start(void)
366{
367 int stat_reg;
368
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100369 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 /* Start the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100372 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 /* Enable the port */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100375 if (pcwd_private.revision == PCWD_REVISION_C) {
376 spin_lock(&pcwd_private.io_lock);
377 outb_p(0x00, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100379 stat_reg = inb_p(pcwd_private.io_addr + 2);
380 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100381 if (stat_reg & WD_WDIS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 printk(KERN_INFO PFX "Could not start watchdog\n");
383 return -EIO;
384 }
385 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100386
387 if (debug >= VERBOSE)
388 printk(KERN_DEBUG PFX "Watchdog started\n");
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 return 0;
391}
392
393static int pcwd_stop(void)
394{
395 int stat_reg;
396
397 /* Stop the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100398 del_timer(&pcwd_private.timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
400 /* Disable the board */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100401 if (pcwd_private.revision == PCWD_REVISION_C) {
402 spin_lock(&pcwd_private.io_lock);
403 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100405 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 stat_reg = inb_p(pcwd_private.io_addr + 2);
408 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100409 if ((stat_reg & WD_WDIS) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 printk(KERN_INFO PFX "Could not stop watchdog\n");
411 return -EIO;
412 }
413 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100414
415 if (debug >= VERBOSE)
416 printk(KERN_DEBUG PFX "Watchdog stopped\n");
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 return 0;
419}
420
421static int pcwd_keepalive(void)
422{
423 /* user land ping */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100424 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100425
426 if (debug >= DEBUG)
427 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return 0;
430}
431
432static int pcwd_set_heartbeat(int t)
433{
434 if ((t < 2) || (t > 7200)) /* arbitrary upper limit */
435 return -EINVAL;
436
437 heartbeat = t;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100438
439 if (debug >= VERBOSE)
440 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
441 heartbeat);
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return 0;
444}
445
446static int pcwd_get_status(int *status)
447{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100448 int control_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450 *status=0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100451 spin_lock(&pcwd_private.io_lock);
452 if (pcwd_private.revision == PCWD_REVISION_A)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 /* Rev A cards return status information from
454 * the base register, which is used for the
455 * temperature in other cards. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100456 control_status = inb(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 else {
458 /* Rev C cards return card status in the base
459 * address + 1 register. And use different bits
460 * to indicate a card initiated reset, and an
461 * over-temperature condition. And the reboot
462 * status can be reset. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100463 control_status = inb(pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100465 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100467 if (pcwd_private.revision == PCWD_REVISION_A) {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100468 if (control_status & WD_WDRST)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 *status |= WDIOF_CARDRESET;
470
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100471 if (control_status & WD_T110) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 *status |= WDIOF_OVERHEAT;
473 if (temp_panic) {
474 printk (KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600475 kernel_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477 }
478 } else {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100479 if (control_status & WD_REVC_WTRP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 *status |= WDIOF_CARDRESET;
481
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100482 if (control_status & WD_REVC_TTRP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 *status |= WDIOF_OVERHEAT;
484 if (temp_panic) {
485 printk (KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600486 kernel_power_off();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
488 }
489 }
490
491 return 0;
492}
493
494static int pcwd_clear_status(void)
495{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100496 int control_status;
497
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100498 if (pcwd_private.revision == PCWD_REVISION_C) {
499 spin_lock(&pcwd_private.io_lock);
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100500
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100501 if (debug >= VERBOSE)
502 printk(KERN_INFO PFX "clearing watchdog trip status\n");
503
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100504 control_status = inb_p(pcwd_private.io_addr + 1);
505
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100506 if (debug >= DEBUG) {
507 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
508 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
509 (control_status & WD_REVC_R2DS));
510 }
511
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100512 /* clear reset status & Keep Relay 2 disable state as it is */
513 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
514
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100515 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517 return 0;
518}
519
520static int pcwd_get_temperature(int *temperature)
521{
522 /* check that port 0 gives temperature info and no command results */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100523 if (pcwd_private.command_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return -1;
525
526 *temperature = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100527 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 return -ENODEV;
529
530 /*
531 * Convert celsius to fahrenheit, since this was
532 * the decided 'standard' for this return value.
533 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100534 spin_lock(&pcwd_private.io_lock);
535 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
536 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100538 if (debug >= DEBUG) {
539 printk(KERN_DEBUG PFX "temperature is: %d F\n",
540 *temperature);
541 }
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return 0;
544}
545
546/*
547 * /dev/watchdog handling
548 */
549
550static int pcwd_ioctl(struct inode *inode, struct file *file,
551 unsigned int cmd, unsigned long arg)
552{
553 int rv;
554 int status;
555 int temperature;
556 int new_heartbeat;
557 int __user *argp = (int __user *)arg;
558 static struct watchdog_info ident = {
559 .options = WDIOF_OVERHEAT |
560 WDIOF_CARDRESET |
561 WDIOF_KEEPALIVEPING |
562 WDIOF_SETTIMEOUT |
563 WDIOF_MAGICCLOSE,
564 .firmware_version = 1,
565 .identity = "PCWD",
566 };
567
568 switch(cmd) {
569 default:
570 return -ENOIOCTLCMD;
571
572 case WDIOC_GETSUPPORT:
573 if(copy_to_user(argp, &ident, sizeof(ident)))
574 return -EFAULT;
575 return 0;
576
577 case WDIOC_GETSTATUS:
578 pcwd_get_status(&status);
579 return put_user(status, argp);
580
581 case WDIOC_GETBOOTSTATUS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100582 return put_user(pcwd_private.boot_status, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584 case WDIOC_GETTEMP:
585 if (pcwd_get_temperature(&temperature))
586 return -EFAULT;
587
588 return put_user(temperature, argp);
589
590 case WDIOC_SETOPTIONS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100591 if (pcwd_private.revision == PCWD_REVISION_C)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 {
593 if(copy_from_user(&rv, argp, sizeof(int)))
594 return -EFAULT;
595
596 if (rv & WDIOS_DISABLECARD)
597 {
598 return pcwd_stop();
599 }
600
601 if (rv & WDIOS_ENABLECARD)
602 {
603 return pcwd_start();
604 }
605
606 if (rv & WDIOS_TEMPPANIC)
607 {
608 temp_panic = 1;
609 }
610 }
611 return -EINVAL;
612
613 case WDIOC_KEEPALIVE:
614 pcwd_keepalive();
615 return 0;
616
617 case WDIOC_SETTIMEOUT:
618 if (get_user(new_heartbeat, argp))
619 return -EFAULT;
620
621 if (pcwd_set_heartbeat(new_heartbeat))
622 return -EINVAL;
623
624 pcwd_keepalive();
625 /* Fall */
626
627 case WDIOC_GETTIMEOUT:
628 return put_user(heartbeat, argp);
629 }
630
631 return 0;
632}
633
634static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
635 loff_t *ppos)
636{
637 if (len) {
638 if (!nowayout) {
639 size_t i;
640
641 /* In case it was set long ago */
642 expect_close = 0;
643
644 for (i = 0; i != len; i++) {
645 char c;
646
647 if (get_user(c, buf + i))
648 return -EFAULT;
649 if (c == 'V')
650 expect_close = 42;
651 }
652 }
653 pcwd_keepalive();
654 }
655 return len;
656}
657
658static int pcwd_open(struct inode *inode, struct file *file)
659{
660 if (!atomic_dec_and_test(&open_allowed) ) {
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100661 if (debug >= VERBOSE)
662 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 atomic_inc( &open_allowed );
664 return -EBUSY;
665 }
666
667 if (nowayout)
668 __module_get(THIS_MODULE);
669
670 /* Activate */
671 pcwd_start();
672 pcwd_keepalive();
673 return nonseekable_open(inode, file);
674}
675
676static int pcwd_close(struct inode *inode, struct file *file)
677{
678 if (expect_close == 42) {
679 pcwd_stop();
680 } else {
681 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
682 pcwd_keepalive();
683 }
684 expect_close = 0;
685 atomic_inc( &open_allowed );
686 return 0;
687}
688
689/*
690 * /dev/temperature handling
691 */
692
693static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
694 loff_t *ppos)
695{
696 int temperature;
697
698 if (pcwd_get_temperature(&temperature))
699 return -EFAULT;
700
701 if (copy_to_user(buf, &temperature, 1))
702 return -EFAULT;
703
704 return 1;
705}
706
707static int pcwd_temp_open(struct inode *inode, struct file *file)
708{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100709 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 return -ENODEV;
711
712 return nonseekable_open(inode, file);
713}
714
715static int pcwd_temp_close(struct inode *inode, struct file *file)
716{
717 return 0;
718}
719
720/*
721 * Notify system
722 */
723
724static int pcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
725{
726 if (code==SYS_DOWN || code==SYS_HALT) {
727 /* Turn the WDT off */
728 pcwd_stop();
729 }
730
731 return NOTIFY_DONE;
732}
733
734/*
735 * Kernel Interfaces
736 */
737
738static struct file_operations pcwd_fops = {
739 .owner = THIS_MODULE,
740 .llseek = no_llseek,
741 .write = pcwd_write,
742 .ioctl = pcwd_ioctl,
743 .open = pcwd_open,
744 .release = pcwd_close,
745};
746
747static struct miscdevice pcwd_miscdev = {
748 .minor = WATCHDOG_MINOR,
749 .name = "watchdog",
750 .fops = &pcwd_fops,
751};
752
753static struct file_operations pcwd_temp_fops = {
754 .owner = THIS_MODULE,
755 .llseek = no_llseek,
756 .read = pcwd_temp_read,
757 .open = pcwd_temp_open,
758 .release = pcwd_temp_close,
759};
760
761static struct miscdevice temp_miscdev = {
762 .minor = TEMP_MINOR,
763 .name = "temperature",
764 .fops = &pcwd_temp_fops,
765};
766
767static struct notifier_block pcwd_notifier = {
768 .notifier_call = pcwd_notify_sys,
769};
770
771/*
772 * Init & exit routines
773 */
774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775static inline int get_revision(void)
776{
777 int r = PCWD_REVISION_C;
778
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100779 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 /* REV A cards use only 2 io ports; test
781 * presumes a floating bus reads as 0xff. */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100782 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
783 (inb(pcwd_private.io_addr + 3) == 0xFF))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 r=PCWD_REVISION_A;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100785 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 return r;
788}
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790static int __devinit pcwatchdog_init(int base_addr)
791{
792 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 cards_found++;
795 if (cards_found == 1)
796 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
797
798 if (cards_found > 1) {
799 printk(KERN_ERR PFX "This driver only supports 1 device\n");
800 return -ENODEV;
801 }
802
803 if (base_addr == 0x0000) {
804 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
805 return -ENODEV;
806 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100807 pcwd_private.io_addr = base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 /* Check card's revision */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100810 pcwd_private.revision = get_revision();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100812 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100814 pcwd_private.io_addr);
815 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 return -EIO;
817 }
818
819 /* Initial variables */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100820 pcwd_private.supports_temp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 temp_panic = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100822 pcwd_private.boot_status = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
824 /* get the boot_status */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100825 pcwd_get_status(&pcwd_private.boot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 /* clear the "card caused reboot" flag */
828 pcwd_clear_status();
829
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100830 init_timer(&pcwd_private.timer);
831 pcwd_private.timer.function = pcwd_timer_ping;
832 pcwd_private.timer.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
834 /* Disable the board */
835 pcwd_stop();
836
837 /* Check whether or not the card supports the temperature device */
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100838 pcwd_check_temperature_support();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100840 /* Show info about the card itself */
841 pcwd_show_card_info();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 /* Check that the heartbeat value is within it's range ; if not reset to the default */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100844 if (pcwd_set_heartbeat(heartbeat)) {
845 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
846 printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
847 WATCHDOG_HEARTBEAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 }
849
850 ret = register_reboot_notifier(&pcwd_notifier);
851 if (ret) {
852 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
853 ret);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100854 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
855 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 return ret;
857 }
858
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100859 if (pcwd_private.supports_temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 ret = misc_register(&temp_miscdev);
861 if (ret) {
862 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
863 TEMP_MINOR, ret);
864 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100865 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
866 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 return ret;
868 }
869 }
870
871 ret = misc_register(&pcwd_miscdev);
872 if (ret) {
873 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
874 WATCHDOG_MINOR, ret);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100875 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 misc_deregister(&temp_miscdev);
877 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100878 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
879 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 return ret;
881 }
882
883 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
884 heartbeat, nowayout);
885
886 return 0;
887}
888
889static void __devexit pcwatchdog_exit(void)
890{
891 /* Disable the board */
892 if (!nowayout)
893 pcwd_stop();
894
895 /* Deregister */
896 misc_deregister(&pcwd_miscdev);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100897 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 misc_deregister(&temp_miscdev);
899 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100900 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
901 pcwd_private.io_addr = 0x0000;
Wim Van Sebroeckf1c3a052005-12-10 14:36:24 +0100902 cards_found--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903}
904
905/*
906 * The ISA cards have a heartbeat bit in one of the registers, which
907 * register is card dependent. The heartbeat bit is monitored, and if
908 * found, is considered proof that a Berkshire card has been found.
909 * The initial rate is once per second at board start up, then twice
910 * per second for normal operation.
911 */
912static int __init pcwd_checkcard(int base_addr)
913{
914 int port0, last_port0; /* Reg 0, in case it's REV A */
915 int port1, last_port1; /* Register 1 for REV C cards */
916 int i;
917 int retval;
918
919 if (!request_region (base_addr, 4, "PCWD")) {
920 printk (KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
921 return 0;
922 }
923
924 retval = 0;
925
926 port0 = inb_p(base_addr); /* For REV A boards */
927 port1 = inb_p(base_addr + 1); /* For REV C boards */
928 if (port0 != 0xff || port1 != 0xff) {
929 /* Not an 'ff' from a floating bus, so must be a card! */
930 for (i = 0; i < 4; ++i) {
931
932 msleep(500);
933
934 last_port0 = port0;
935 last_port1 = port1;
936
937 port0 = inb_p(base_addr);
938 port1 = inb_p(base_addr + 1);
939
940 /* Has either hearbeat bit changed? */
941 if ((port0 ^ last_port0) & WD_HRTBT ||
942 (port1 ^ last_port1) & WD_REVC_HRBT) {
943 retval = 1;
944 break;
945 }
946 }
947 }
948 release_region (base_addr, 4);
949
950 return retval;
951}
952
953/*
954 * These are the auto-probe addresses available.
955 *
956 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
957 * Revision A has an address range of 2 addresses, while Revision C has 4.
958 */
959static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
960
961static int __init pcwd_init_module(void)
962{
963 int i, found = 0;
964
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100965 spin_lock_init(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 for (i = 0; pcwd_ioports[i] != 0; i++) {
968 if (pcwd_checkcard(pcwd_ioports[i])) {
969 if (!(pcwatchdog_init(pcwd_ioports[i])))
970 found++;
971 }
972 }
973
974 if (!found) {
975 printk (KERN_INFO PFX "No card detected, or port not available\n");
976 return -ENODEV;
977 }
978
979 return 0;
980}
981
982static void __exit pcwd_cleanup_module(void)
983{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100984 if (pcwd_private.io_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 pcwatchdog_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
988module_init(pcwd_init_module);
989module_exit(pcwd_cleanup_module);
990
991MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>");
992MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
993MODULE_LICENSE("GPL");
994MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
995MODULE_ALIAS_MISCDEV(TEMP_MINOR);