blob: 28a404adf8f0d10f8a22768ac9e57d6ee64342a8 [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/... */
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010070#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
71#include <asm/io.h> /* For inb/outb/... */
72
73/* Module and version information */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +010074#define WATCHDOG_VERSION "1.17"
75#define WATCHDOG_DATE "12 Feb 2006"
Wim Van Sebroecka7122f92006-01-09 22:07:22 +010076#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
77#define WATCHDOG_NAME "pcwd"
78#define PFX WATCHDOG_NAME ": "
79#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
80#define WD_VER WATCHDOG_VERSION " (" WATCHDOG_DATE ")"
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
82/*
83 * It should be noted that PCWD_REVISION_B was removed because A and B
84 * are essentially the same types of card, with the exception that B
85 * has temperature reporting. Since I didn't receive a Rev.B card,
86 * the Rev.B card is not supported. (It's a good thing too, as they
87 * are no longer in production.)
88 */
89#define PCWD_REVISION_A 1
90#define PCWD_REVISION_C 2
91
92/*
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +010093 * These are the defines that describe the control status bits for the
94 * PCI-PC Watchdog card.
95*/
96/* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +010097#define WD_WDRST 0x01 /* Previously reset state */
98#define WD_T110 0x02 /* Temperature overheat sense */
99#define WD_HRTBT 0x04 /* Heartbeat sense */
100#define WD_RLY2 0x08 /* External relay triggered */
101#define WD_SRLY2 0x80 /* Software external relay triggered */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100102/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100103#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
104#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
105#define WD_REVC_TTRP 0x04 /* Temperature Trip status */
106#define WD_REVC_RL2A 0x08 /* Relay 2 activated by on-board processor */
107#define WD_REVC_RL1A 0x10 /* Relay 1 active */
108#define WD_REVC_R2DS 0x40 /* Relay 2 disable */
109#define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100110/* Port 2 : Control Status #2 */
111#define WD_WDIS 0x10 /* Watchdog Disabled */
112#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
113#define WD_SSEL 0x40 /* Watchdog Switch Select (1:SW1 <-> 0:SW2) */
114#define WD_WCMD 0x80 /* Watchdog Command Mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116/* max. time we give an ISA watchdog card to process a command */
117/* 500ms for each 4 bit response (according to spec.) */
118#define ISA_COMMAND_TIMEOUT 1000
119
120/* Watchdog's internal commands */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100121#define CMD_ISA_IDLE 0x00
122#define CMD_ISA_VERSION_INTEGER 0x01
123#define CMD_ISA_VERSION_TENTH 0x02
124#define CMD_ISA_VERSION_HUNDRETH 0x03
125#define CMD_ISA_VERSION_MINOR 0x04
126#define CMD_ISA_SWITCH_SETTINGS 0x05
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100127#define CMD_ISA_RESET_PC 0x06
128#define CMD_ISA_ARM_0 0x07
129#define CMD_ISA_ARM_30 0x08
130#define CMD_ISA_ARM_60 0x09
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100131#define CMD_ISA_DELAY_TIME_2SECS 0x0A
132#define CMD_ISA_DELAY_TIME_4SECS 0x0B
133#define CMD_ISA_DELAY_TIME_8SECS 0x0C
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100134#define CMD_ISA_RESET_RELAYS 0x0D
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/*
137 * We are using an kernel timer to do the pinging of the watchdog
138 * every ~500ms. We try to set the internal heartbeat of the
139 * watchdog to 2 ms.
140 */
141
142#define WDT_INTERVAL (HZ/2+1)
143
144/* We can only use 1 card due to the /dev/watchdog restriction */
145static int cards_found;
146
147/* internal variables */
148static atomic_t open_allowed = ATOMIC_INIT(1);
149static char expect_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static int temp_panic;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100151static struct { /* this is private data for each ISA-PC watchdog card */
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100152 char fw_ver_str[6]; /* The cards firmware version */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100153 int revision; /* The card's revision */
154 int supports_temp; /* Wether or not the card has a temperature device */
155 int command_mode; /* Wether or not the card is in command mode */
156 int boot_status; /* The card's boot status */
157 int io_addr; /* The cards I/O address */
158 spinlock_t io_lock; /* the lock for io operations */
159 struct timer_list timer; /* The timer that pings the watchdog */
160 unsigned long next_heartbeat; /* the next_heartbeat for the timer */
161} pcwd_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163/* module parameters */
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100164#define QUIET 0 /* Default */
165#define VERBOSE 1 /* Verbose */
166#define DEBUG 2 /* print fancy stuff too */
167static int debug = QUIET;
168module_param(debug, int, 0);
169MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#define WATCHDOG_HEARTBEAT 60 /* 60 sec default heartbeat */
172static int heartbeat = WATCHDOG_HEARTBEAT;
173module_param(heartbeat, int, 0);
174MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
175
Andrey Panin4bfdf372005-07-27 11:43:58 -0700176static int nowayout = WATCHDOG_NOWAYOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177module_param(nowayout, int, 0);
178MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
179
180/*
181 * Internal functions
182 */
183
184static int send_isa_command(int cmd)
185{
186 int i;
187 int control_status;
188 int port0, last_port0; /* Double read for stabilising */
189
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100190 if (debug >= DEBUG)
191 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
192 cmd);
193
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /* The WCMD bit must be 1 and the command is only 4 bits in size */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100195 control_status = (cmd & 0x0F) | WD_WCMD;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100196 outb_p(control_status, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 udelay(ISA_COMMAND_TIMEOUT);
198
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100199 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 for (i = 0; i < 25; ++i) {
201 last_port0 = port0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100202 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 if (port0 == last_port0)
205 break; /* Data is stable */
206
207 udelay (250);
208 }
209
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100210 if (debug >= DEBUG)
211 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
212 cmd, port0, last_port0);
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 return port0;
215}
216
217static int set_command_mode(void)
218{
219 int i, found=0, count=0;
220
221 /* Set the card into command mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100222 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 while ((!found) && (count < 3)) {
224 i = send_isa_command(CMD_ISA_IDLE);
225
226 if (i == 0x00)
227 found = 1;
228 else if (i == 0xF3) {
229 /* Card does not like what we've done to it */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100230 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 udelay(1200); /* Spec says wait 1ms */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100232 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 udelay(ISA_COMMAND_TIMEOUT);
234 }
235 count++;
236 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100237 spin_unlock(&pcwd_private.io_lock);
238 pcwd_private.command_mode = found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100240 if (debug >= DEBUG)
241 printk(KERN_DEBUG PFX "command_mode=%d\n",
242 pcwd_private.command_mode);
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return(found);
245}
246
247static void unset_command_mode(void)
248{
249 /* Set the card into normal mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100250 spin_lock(&pcwd_private.io_lock);
251 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100253 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100255 pcwd_private.command_mode = 0;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100256
257 if (debug >= DEBUG)
258 printk(KERN_DEBUG PFX "command_mode=%d\n",
259 pcwd_private.command_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260}
261
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100262static inline void pcwd_check_temperature_support(void)
263{
264 if (inb(pcwd_private.io_addr) != 0xF0)
265 pcwd_private.supports_temp = 1;
266}
267
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100268static inline void pcwd_get_firmware(void)
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100269{
270 int one, ten, hund, minor;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100271
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100272 sprintf(pcwd_private.fw_ver_str, "ERROR");
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100273
274 if (set_command_mode()) {
275 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
276 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
277 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
278 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100279 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100280 }
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100281 unset_command_mode();
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100282
283 return;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100284}
285
286static inline int pcwd_get_option_switches(void)
287{
288 int option_switches=0;
289
290 if (set_command_mode()) {
291 /* Get switch settings */
292 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
293 }
294
295 unset_command_mode();
296 return(option_switches);
297}
298
299static void pcwd_show_card_info(void)
300{
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100301 int option_switches;
302
303 /* Get some extra info from the hardware (in command/debug/diag mode) */
304 if (pcwd_private.revision == PCWD_REVISION_A)
305 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
306 else if (pcwd_private.revision == PCWD_REVISION_C) {
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100307 pcwd_get_firmware();
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100308 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 +0100309 pcwd_private.io_addr, pcwd_private.fw_ver_str);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100310 option_switches = pcwd_get_option_switches();
311 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
312 option_switches,
313 ((option_switches & 0x10) ? "ON" : "OFF"),
314 ((option_switches & 0x08) ? "ON" : "OFF"));
315
316 /* Reprogram internal heartbeat to 2 seconds */
317 if (set_command_mode()) {
318 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
319 unset_command_mode();
320 }
321 }
322
323 if (pcwd_private.supports_temp)
324 printk(KERN_INFO PFX "Temperature Option Detected\n");
325
326 if (pcwd_private.boot_status & WDIOF_CARDRESET)
327 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
328
329 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
330 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
331 printk(KERN_EMERG PFX "CPU Overheat\n");
332 }
333
334 if (pcwd_private.boot_status == 0)
335 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
336}
337
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338static void pcwd_timer_ping(unsigned long data)
339{
340 int wdrst_stat;
341
342 /* If we got a heartbeat pulse within the WDT_INTERVAL
343 * we agree to ping the WDT */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100344 if(time_before(jiffies, pcwd_private.next_heartbeat)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 /* Ping the watchdog */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100346 spin_lock(&pcwd_private.io_lock);
347 if (pcwd_private.revision == PCWD_REVISION_A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 /* Rev A cards are reset by setting the WD_WDRST bit in register 1 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100349 wdrst_stat = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 wdrst_stat &= 0x0F;
351 wdrst_stat |= WD_WDRST;
352
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100353 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 } else {
355 /* Re-trigger watchdog by writing to port 0 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100356 outb_p(0x00, pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 }
358
359 /* Re-set the timer interval */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100360 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100362 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 } else {
364 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
365 }
366}
367
368static int pcwd_start(void)
369{
370 int stat_reg;
371
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100372 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 /* Start the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100375 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 /* Enable the port */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100378 if (pcwd_private.revision == PCWD_REVISION_C) {
379 spin_lock(&pcwd_private.io_lock);
380 outb_p(0x00, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100382 stat_reg = inb_p(pcwd_private.io_addr + 2);
383 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100384 if (stat_reg & WD_WDIS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 printk(KERN_INFO PFX "Could not start watchdog\n");
386 return -EIO;
387 }
388 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100389
390 if (debug >= VERBOSE)
391 printk(KERN_DEBUG PFX "Watchdog started\n");
392
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 return 0;
394}
395
396static int pcwd_stop(void)
397{
398 int stat_reg;
399
400 /* Stop the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100401 del_timer(&pcwd_private.timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
403 /* Disable the board */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100404 if (pcwd_private.revision == PCWD_REVISION_C) {
405 spin_lock(&pcwd_private.io_lock);
406 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100408 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100410 stat_reg = inb_p(pcwd_private.io_addr + 2);
411 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100412 if ((stat_reg & WD_WDIS) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 printk(KERN_INFO PFX "Could not stop watchdog\n");
414 return -EIO;
415 }
416 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100417
418 if (debug >= VERBOSE)
419 printk(KERN_DEBUG PFX "Watchdog stopped\n");
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 return 0;
422}
423
424static int pcwd_keepalive(void)
425{
426 /* user land ping */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100427 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100428
429 if (debug >= DEBUG)
430 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return 0;
433}
434
435static int pcwd_set_heartbeat(int t)
436{
437 if ((t < 2) || (t > 7200)) /* arbitrary upper limit */
438 return -EINVAL;
439
440 heartbeat = t;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100441
442 if (debug >= VERBOSE)
443 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
444 heartbeat);
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 return 0;
447}
448
449static int pcwd_get_status(int *status)
450{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100451 int control_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
453 *status=0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100454 spin_lock(&pcwd_private.io_lock);
455 if (pcwd_private.revision == PCWD_REVISION_A)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 /* Rev A cards return status information from
457 * the base register, which is used for the
458 * temperature in other cards. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100459 control_status = inb(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 else {
461 /* Rev C cards return card status in the base
462 * address + 1 register. And use different bits
463 * to indicate a card initiated reset, and an
464 * over-temperature condition. And the reboot
465 * status can be reset. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100466 control_status = inb(pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100468 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100470 if (pcwd_private.revision == PCWD_REVISION_A) {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100471 if (control_status & WD_WDRST)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 *status |= WDIOF_CARDRESET;
473
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100474 if (control_status & WD_T110) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 *status |= WDIOF_OVERHEAT;
476 if (temp_panic) {
477 printk (KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600478 kernel_power_off();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100479 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481 }
482 } else {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100483 if (control_status & WD_REVC_WTRP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 *status |= WDIOF_CARDRESET;
485
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100486 if (control_status & WD_REVC_TTRP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 *status |= WDIOF_OVERHEAT;
488 if (temp_panic) {
489 printk (KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600490 kernel_power_off();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100491 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 }
493 }
494 }
495
496 return 0;
497}
498
499static int pcwd_clear_status(void)
500{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100501 int control_status;
502
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100503 if (pcwd_private.revision == PCWD_REVISION_C) {
504 spin_lock(&pcwd_private.io_lock);
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100505
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100506 if (debug >= VERBOSE)
507 printk(KERN_INFO PFX "clearing watchdog trip status\n");
508
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100509 control_status = inb_p(pcwd_private.io_addr + 1);
510
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100511 if (debug >= DEBUG) {
512 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
513 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
514 (control_status & WD_REVC_R2DS));
515 }
516
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100517 /* clear reset status & Keep Relay 2 disable state as it is */
518 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
519
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100520 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522 return 0;
523}
524
525static int pcwd_get_temperature(int *temperature)
526{
527 /* check that port 0 gives temperature info and no command results */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100528 if (pcwd_private.command_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 return -1;
530
531 *temperature = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100532 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 return -ENODEV;
534
535 /*
536 * Convert celsius to fahrenheit, since this was
537 * the decided 'standard' for this return value.
538 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100539 spin_lock(&pcwd_private.io_lock);
540 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
541 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100543 if (debug >= DEBUG) {
544 printk(KERN_DEBUG PFX "temperature is: %d F\n",
545 *temperature);
546 }
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 return 0;
549}
550
551/*
552 * /dev/watchdog handling
553 */
554
555static int pcwd_ioctl(struct inode *inode, struct file *file,
556 unsigned int cmd, unsigned long arg)
557{
558 int rv;
559 int status;
560 int temperature;
561 int new_heartbeat;
562 int __user *argp = (int __user *)arg;
563 static struct watchdog_info ident = {
564 .options = WDIOF_OVERHEAT |
565 WDIOF_CARDRESET |
566 WDIOF_KEEPALIVEPING |
567 WDIOF_SETTIMEOUT |
568 WDIOF_MAGICCLOSE,
569 .firmware_version = 1,
570 .identity = "PCWD",
571 };
572
573 switch(cmd) {
574 default:
575 return -ENOIOCTLCMD;
576
577 case WDIOC_GETSUPPORT:
578 if(copy_to_user(argp, &ident, sizeof(ident)))
579 return -EFAULT;
580 return 0;
581
582 case WDIOC_GETSTATUS:
583 pcwd_get_status(&status);
584 return put_user(status, argp);
585
586 case WDIOC_GETBOOTSTATUS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100587 return put_user(pcwd_private.boot_status, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
589 case WDIOC_GETTEMP:
590 if (pcwd_get_temperature(&temperature))
591 return -EFAULT;
592
593 return put_user(temperature, argp);
594
595 case WDIOC_SETOPTIONS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100596 if (pcwd_private.revision == PCWD_REVISION_C)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 {
598 if(copy_from_user(&rv, argp, sizeof(int)))
599 return -EFAULT;
600
601 if (rv & WDIOS_DISABLECARD)
602 {
603 return pcwd_stop();
604 }
605
606 if (rv & WDIOS_ENABLECARD)
607 {
608 return pcwd_start();
609 }
610
611 if (rv & WDIOS_TEMPPANIC)
612 {
613 temp_panic = 1;
614 }
615 }
616 return -EINVAL;
617
618 case WDIOC_KEEPALIVE:
619 pcwd_keepalive();
620 return 0;
621
622 case WDIOC_SETTIMEOUT:
623 if (get_user(new_heartbeat, argp))
624 return -EFAULT;
625
626 if (pcwd_set_heartbeat(new_heartbeat))
627 return -EINVAL;
628
629 pcwd_keepalive();
630 /* Fall */
631
632 case WDIOC_GETTIMEOUT:
633 return put_user(heartbeat, argp);
634 }
635
636 return 0;
637}
638
639static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
640 loff_t *ppos)
641{
642 if (len) {
643 if (!nowayout) {
644 size_t i;
645
646 /* In case it was set long ago */
647 expect_close = 0;
648
649 for (i = 0; i != len; i++) {
650 char c;
651
652 if (get_user(c, buf + i))
653 return -EFAULT;
654 if (c == 'V')
655 expect_close = 42;
656 }
657 }
658 pcwd_keepalive();
659 }
660 return len;
661}
662
663static int pcwd_open(struct inode *inode, struct file *file)
664{
665 if (!atomic_dec_and_test(&open_allowed) ) {
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100666 if (debug >= VERBOSE)
667 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 atomic_inc( &open_allowed );
669 return -EBUSY;
670 }
671
672 if (nowayout)
673 __module_get(THIS_MODULE);
674
675 /* Activate */
676 pcwd_start();
677 pcwd_keepalive();
678 return nonseekable_open(inode, file);
679}
680
681static int pcwd_close(struct inode *inode, struct file *file)
682{
683 if (expect_close == 42) {
684 pcwd_stop();
685 } else {
686 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
687 pcwd_keepalive();
688 }
689 expect_close = 0;
690 atomic_inc( &open_allowed );
691 return 0;
692}
693
694/*
695 * /dev/temperature handling
696 */
697
698static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
699 loff_t *ppos)
700{
701 int temperature;
702
703 if (pcwd_get_temperature(&temperature))
704 return -EFAULT;
705
706 if (copy_to_user(buf, &temperature, 1))
707 return -EFAULT;
708
709 return 1;
710}
711
712static int pcwd_temp_open(struct inode *inode, struct file *file)
713{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100714 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 return -ENODEV;
716
717 return nonseekable_open(inode, file);
718}
719
720static int pcwd_temp_close(struct inode *inode, struct file *file)
721{
722 return 0;
723}
724
725/*
726 * Notify system
727 */
728
729static int pcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
730{
731 if (code==SYS_DOWN || code==SYS_HALT) {
732 /* Turn the WDT off */
733 pcwd_stop();
734 }
735
736 return NOTIFY_DONE;
737}
738
739/*
740 * Kernel Interfaces
741 */
742
743static struct file_operations pcwd_fops = {
744 .owner = THIS_MODULE,
745 .llseek = no_llseek,
746 .write = pcwd_write,
747 .ioctl = pcwd_ioctl,
748 .open = pcwd_open,
749 .release = pcwd_close,
750};
751
752static struct miscdevice pcwd_miscdev = {
753 .minor = WATCHDOG_MINOR,
754 .name = "watchdog",
755 .fops = &pcwd_fops,
756};
757
758static struct file_operations pcwd_temp_fops = {
759 .owner = THIS_MODULE,
760 .llseek = no_llseek,
761 .read = pcwd_temp_read,
762 .open = pcwd_temp_open,
763 .release = pcwd_temp_close,
764};
765
766static struct miscdevice temp_miscdev = {
767 .minor = TEMP_MINOR,
768 .name = "temperature",
769 .fops = &pcwd_temp_fops,
770};
771
772static struct notifier_block pcwd_notifier = {
773 .notifier_call = pcwd_notify_sys,
774};
775
776/*
777 * Init & exit routines
778 */
779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780static inline int get_revision(void)
781{
782 int r = PCWD_REVISION_C;
783
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100784 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 /* REV A cards use only 2 io ports; test
786 * presumes a floating bus reads as 0xff. */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100787 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
788 (inb(pcwd_private.io_addr + 3) == 0xFF))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 r=PCWD_REVISION_A;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100790 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
792 return r;
793}
794
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795static int __devinit pcwatchdog_init(int base_addr)
796{
797 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 cards_found++;
800 if (cards_found == 1)
801 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
802
803 if (cards_found > 1) {
804 printk(KERN_ERR PFX "This driver only supports 1 device\n");
805 return -ENODEV;
806 }
807
808 if (base_addr == 0x0000) {
809 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
810 return -ENODEV;
811 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100812 pcwd_private.io_addr = base_addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 /* Check card's revision */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100815 pcwd_private.revision = get_revision();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100817 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100819 pcwd_private.io_addr);
820 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 return -EIO;
822 }
823
824 /* Initial variables */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100825 pcwd_private.supports_temp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 temp_panic = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100827 pcwd_private.boot_status = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828
829 /* get the boot_status */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100830 pcwd_get_status(&pcwd_private.boot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831
832 /* clear the "card caused reboot" flag */
833 pcwd_clear_status();
834
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100835 init_timer(&pcwd_private.timer);
836 pcwd_private.timer.function = pcwd_timer_ping;
837 pcwd_private.timer.data = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838
839 /* Disable the board */
840 pcwd_stop();
841
842 /* Check whether or not the card supports the temperature device */
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100843 pcwd_check_temperature_support();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100845 /* Show info about the card itself */
846 pcwd_show_card_info();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847
848 /* Check that the heartbeat value is within it's range ; if not reset to the default */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100849 if (pcwd_set_heartbeat(heartbeat)) {
850 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
851 printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
852 WATCHDOG_HEARTBEAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 }
854
855 ret = register_reboot_notifier(&pcwd_notifier);
856 if (ret) {
857 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
858 ret);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100859 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
860 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 return ret;
862 }
863
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100864 if (pcwd_private.supports_temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 ret = misc_register(&temp_miscdev);
866 if (ret) {
867 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
868 TEMP_MINOR, ret);
869 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100870 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
871 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 return ret;
873 }
874 }
875
876 ret = misc_register(&pcwd_miscdev);
877 if (ret) {
878 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
879 WATCHDOG_MINOR, ret);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100880 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 misc_deregister(&temp_miscdev);
882 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100883 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
884 pcwd_private.io_addr = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 return ret;
886 }
887
888 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
889 heartbeat, nowayout);
890
891 return 0;
892}
893
894static void __devexit pcwatchdog_exit(void)
895{
896 /* Disable the board */
897 if (!nowayout)
898 pcwd_stop();
899
900 /* Deregister */
901 misc_deregister(&pcwd_miscdev);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100902 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 misc_deregister(&temp_miscdev);
904 unregister_reboot_notifier(&pcwd_notifier);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100905 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
906 pcwd_private.io_addr = 0x0000;
Wim Van Sebroeckf1c3a052005-12-10 14:36:24 +0100907 cards_found--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908}
909
910/*
911 * The ISA cards have a heartbeat bit in one of the registers, which
912 * register is card dependent. The heartbeat bit is monitored, and if
913 * found, is considered proof that a Berkshire card has been found.
914 * The initial rate is once per second at board start up, then twice
915 * per second for normal operation.
916 */
917static int __init pcwd_checkcard(int base_addr)
918{
919 int port0, last_port0; /* Reg 0, in case it's REV A */
920 int port1, last_port1; /* Register 1 for REV C cards */
921 int i;
922 int retval;
923
924 if (!request_region (base_addr, 4, "PCWD")) {
925 printk (KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
926 return 0;
927 }
928
929 retval = 0;
930
931 port0 = inb_p(base_addr); /* For REV A boards */
932 port1 = inb_p(base_addr + 1); /* For REV C boards */
933 if (port0 != 0xff || port1 != 0xff) {
934 /* Not an 'ff' from a floating bus, so must be a card! */
935 for (i = 0; i < 4; ++i) {
936
937 msleep(500);
938
939 last_port0 = port0;
940 last_port1 = port1;
941
942 port0 = inb_p(base_addr);
943 port1 = inb_p(base_addr + 1);
944
945 /* Has either hearbeat bit changed? */
946 if ((port0 ^ last_port0) & WD_HRTBT ||
947 (port1 ^ last_port1) & WD_REVC_HRBT) {
948 retval = 1;
949 break;
950 }
951 }
952 }
953 release_region (base_addr, 4);
954
955 return retval;
956}
957
958/*
959 * These are the auto-probe addresses available.
960 *
961 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
962 * Revision A has an address range of 2 addresses, while Revision C has 4.
963 */
964static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
965
966static int __init pcwd_init_module(void)
967{
968 int i, found = 0;
969
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100970 spin_lock_init(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 for (i = 0; pcwd_ioports[i] != 0; i++) {
973 if (pcwd_checkcard(pcwd_ioports[i])) {
974 if (!(pcwatchdog_init(pcwd_ioports[i])))
975 found++;
976 }
977 }
978
979 if (!found) {
980 printk (KERN_INFO PFX "No card detected, or port not available\n");
981 return -ENODEV;
982 }
983
984 return 0;
985}
986
987static void __exit pcwd_cleanup_module(void)
988{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100989 if (pcwd_private.io_addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990 pcwatchdog_exit();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100991
992 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993}
994
995module_init(pcwd_init_module);
996module_exit(pcwd_cleanup_module);
997
998MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>");
999MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1000MODULE_LICENSE("GPL");
1001MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1002MODULE_ALIAS_MISCDEV(TEMP_MINOR);