3 * by Ken Hollis (khollis@bitgate.com)
5 * Permission granted from Simon Machell (smachell@berkprod.com)
6 * Written for the Linux Kernel, and GPLed by Ken Hollis
8 * 960107 Added request_region routines, modulized the whole thing.
9 * 960108 Fixed end-of-file pointer (Thanks to Dan Hollis), added
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
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
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/
52 #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/... */
69 #include <asm/uaccess.h> /* For copy_to_user/put_user/... */
70 #include <asm/io.h> /* For inb/outb/... */
72 /* Module and version information */
73 #define WATCHDOG_VERSION "1.18"
74 #define WATCHDOG_DATE "21 Jan 2007"
75 #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 ")"
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.)
88 #define PCWD_REVISION_A 1
89 #define PCWD_REVISION_C 2
92 * These are the defines that describe the control status bits for the
93 * PCI-PC Watchdog card.
95 /* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
96 #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 */
101 /* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
102 #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? */
109 /* 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 */
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
119 /* Watchdog's internal commands */
120 #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
126 #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
130 #define CMD_ISA_DELAY_TIME_2SECS 0x0A
131 #define CMD_ISA_DELAY_TIME_4SECS 0x0B
132 #define CMD_ISA_DELAY_TIME_8SECS 0x0C
133 #define CMD_ISA_RESET_RELAYS 0x0D
135 /* Watchdog's Dip Switch heartbeat values */
136 static const int heartbeat_tbl [] = {
137 20, /* OFF-OFF-OFF = 20 Sec */
138 40, /* OFF-OFF-ON = 40 Sec */
139 60, /* OFF-ON-OFF = 1 Min */
140 300, /* OFF-ON-ON = 5 Min */
141 600, /* ON-OFF-OFF = 10 Min */
142 1800, /* ON-OFF-ON = 30 Min */
143 3600, /* ON-ON-OFF = 1 Hour */
144 7200, /* ON-ON-ON = 2 hour */
148 * We are using an kernel timer to do the pinging of the watchdog
149 * every ~500ms. We try to set the internal heartbeat of the
153 #define WDT_INTERVAL (HZ/2+1)
155 /* We can only use 1 card due to the /dev/watchdog restriction */
156 static int cards_found;
158 /* internal variables */
159 static atomic_t open_allowed = ATOMIC_INIT(1);
160 static char expect_close;
161 static int temp_panic;
162 static struct { /* this is private data for each ISA-PC watchdog card */
163 char fw_ver_str[6]; /* The cards firmware version */
164 int revision; /* The card's revision */
165 int supports_temp; /* Wether or not the card has a temperature device */
166 int command_mode; /* Wether or not the card is in command mode */
167 int boot_status; /* The card's boot status */
168 int io_addr; /* The cards I/O address */
169 spinlock_t io_lock; /* the lock for io operations */
170 struct timer_list timer; /* The timer that pings the watchdog */
171 unsigned long next_heartbeat; /* the next_heartbeat for the timer */
174 /* module parameters */
175 #define QUIET 0 /* Default */
176 #define VERBOSE 1 /* Verbose */
177 #define DEBUG 2 /* print fancy stuff too */
178 static int debug = QUIET;
179 module_param(debug, int, 0);
180 MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
182 #define WATCHDOG_HEARTBEAT 0 /* default heartbeat = delay-time from dip-switches */
183 static int heartbeat = WATCHDOG_HEARTBEAT;
184 module_param(heartbeat, int, 0);
185 MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
187 static int nowayout = WATCHDOG_NOWAYOUT;
188 module_param(nowayout, int, 0);
189 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
195 static int send_isa_command(int cmd)
199 int port0, last_port0; /* Double read for stabilising */
202 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
205 /* The WCMD bit must be 1 and the command is only 4 bits in size */
206 control_status = (cmd & 0x0F) | WD_WCMD;
207 outb_p(control_status, pcwd_private.io_addr + 2);
208 udelay(ISA_COMMAND_TIMEOUT);
210 port0 = inb_p(pcwd_private.io_addr);
211 for (i = 0; i < 25; ++i) {
213 port0 = inb_p(pcwd_private.io_addr);
215 if (port0 == last_port0)
216 break; /* Data is stable */
222 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
223 cmd, port0, last_port0);
228 static int set_command_mode(void)
230 int i, found=0, count=0;
232 /* Set the card into command mode */
233 spin_lock(&pcwd_private.io_lock);
234 while ((!found) && (count < 3)) {
235 i = send_isa_command(CMD_ISA_IDLE);
239 else if (i == 0xF3) {
240 /* Card does not like what we've done to it */
241 outb_p(0x00, pcwd_private.io_addr + 2);
242 udelay(1200); /* Spec says wait 1ms */
243 outb_p(0x00, pcwd_private.io_addr + 2);
244 udelay(ISA_COMMAND_TIMEOUT);
248 spin_unlock(&pcwd_private.io_lock);
249 pcwd_private.command_mode = found;
252 printk(KERN_DEBUG PFX "command_mode=%d\n",
253 pcwd_private.command_mode);
258 static void unset_command_mode(void)
260 /* Set the card into normal mode */
261 spin_lock(&pcwd_private.io_lock);
262 outb_p(0x00, pcwd_private.io_addr + 2);
263 udelay(ISA_COMMAND_TIMEOUT);
264 spin_unlock(&pcwd_private.io_lock);
266 pcwd_private.command_mode = 0;
269 printk(KERN_DEBUG PFX "command_mode=%d\n",
270 pcwd_private.command_mode);
273 static inline void pcwd_check_temperature_support(void)
275 if (inb(pcwd_private.io_addr) != 0xF0)
276 pcwd_private.supports_temp = 1;
279 static inline void pcwd_get_firmware(void)
281 int one, ten, hund, minor;
283 strcpy(pcwd_private.fw_ver_str, "ERROR");
285 if (set_command_mode()) {
286 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
287 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
288 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
289 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
290 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
292 unset_command_mode();
297 static inline int pcwd_get_option_switches(void)
299 int option_switches=0;
301 if (set_command_mode()) {
302 /* Get switch settings */
303 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
306 unset_command_mode();
307 return(option_switches);
310 static void pcwd_show_card_info(void)
314 /* Get some extra info from the hardware (in command/debug/diag mode) */
315 if (pcwd_private.revision == PCWD_REVISION_A)
316 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
317 else if (pcwd_private.revision == PCWD_REVISION_C) {
319 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
320 pcwd_private.io_addr, pcwd_private.fw_ver_str);
321 option_switches = pcwd_get_option_switches();
322 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
324 ((option_switches & 0x10) ? "ON" : "OFF"),
325 ((option_switches & 0x08) ? "ON" : "OFF"));
327 /* Reprogram internal heartbeat to 2 seconds */
328 if (set_command_mode()) {
329 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
330 unset_command_mode();
334 if (pcwd_private.supports_temp)
335 printk(KERN_INFO PFX "Temperature Option Detected\n");
337 if (pcwd_private.boot_status & WDIOF_CARDRESET)
338 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
340 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
341 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
342 printk(KERN_EMERG PFX "CPU Overheat\n");
345 if (pcwd_private.boot_status == 0)
346 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
349 static void pcwd_timer_ping(unsigned long data)
353 /* If we got a heartbeat pulse within the WDT_INTERVAL
354 * we agree to ping the WDT */
355 if(time_before(jiffies, pcwd_private.next_heartbeat)) {
356 /* Ping the watchdog */
357 spin_lock(&pcwd_private.io_lock);
358 if (pcwd_private.revision == PCWD_REVISION_A) {
359 /* Rev A cards are reset by setting the WD_WDRST bit in register 1 */
360 wdrst_stat = inb_p(pcwd_private.io_addr);
362 wdrst_stat |= WD_WDRST;
364 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
366 /* Re-trigger watchdog by writing to port 0 */
367 outb_p(0x00, pcwd_private.io_addr);
370 /* Re-set the timer interval */
371 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
373 spin_unlock(&pcwd_private.io_lock);
375 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
379 static int pcwd_start(void)
383 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
385 /* Start the timer */
386 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
388 /* Enable the port */
389 if (pcwd_private.revision == PCWD_REVISION_C) {
390 spin_lock(&pcwd_private.io_lock);
391 outb_p(0x00, pcwd_private.io_addr + 3);
392 udelay(ISA_COMMAND_TIMEOUT);
393 stat_reg = inb_p(pcwd_private.io_addr + 2);
394 spin_unlock(&pcwd_private.io_lock);
395 if (stat_reg & WD_WDIS) {
396 printk(KERN_INFO PFX "Could not start watchdog\n");
401 if (debug >= VERBOSE)
402 printk(KERN_DEBUG PFX "Watchdog started\n");
407 static int pcwd_stop(void)
412 del_timer(&pcwd_private.timer);
414 /* Disable the board */
415 if (pcwd_private.revision == PCWD_REVISION_C) {
416 spin_lock(&pcwd_private.io_lock);
417 outb_p(0xA5, pcwd_private.io_addr + 3);
418 udelay(ISA_COMMAND_TIMEOUT);
419 outb_p(0xA5, pcwd_private.io_addr + 3);
420 udelay(ISA_COMMAND_TIMEOUT);
421 stat_reg = inb_p(pcwd_private.io_addr + 2);
422 spin_unlock(&pcwd_private.io_lock);
423 if ((stat_reg & WD_WDIS) == 0) {
424 printk(KERN_INFO PFX "Could not stop watchdog\n");
429 if (debug >= VERBOSE)
430 printk(KERN_DEBUG PFX "Watchdog stopped\n");
435 static int pcwd_keepalive(void)
438 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
441 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
446 static int pcwd_set_heartbeat(int t)
448 if ((t < 2) || (t > 7200)) /* arbitrary upper limit */
453 if (debug >= VERBOSE)
454 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
460 static int pcwd_get_status(int *status)
465 spin_lock(&pcwd_private.io_lock);
466 if (pcwd_private.revision == PCWD_REVISION_A)
467 /* Rev A cards return status information from
468 * the base register, which is used for the
469 * temperature in other cards. */
470 control_status = inb(pcwd_private.io_addr);
472 /* Rev C cards return card status in the base
473 * address + 1 register. And use different bits
474 * to indicate a card initiated reset, and an
475 * over-temperature condition. And the reboot
476 * status can be reset. */
477 control_status = inb(pcwd_private.io_addr + 1);
479 spin_unlock(&pcwd_private.io_lock);
481 if (pcwd_private.revision == PCWD_REVISION_A) {
482 if (control_status & WD_WDRST)
483 *status |= WDIOF_CARDRESET;
485 if (control_status & WD_T110) {
486 *status |= WDIOF_OVERHEAT;
488 printk (KERN_INFO PFX "Temperature overheat trip!\n");
490 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
494 if (control_status & WD_REVC_WTRP)
495 *status |= WDIOF_CARDRESET;
497 if (control_status & WD_REVC_TTRP) {
498 *status |= WDIOF_OVERHEAT;
500 printk (KERN_INFO PFX "Temperature overheat trip!\n");
502 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
510 static int pcwd_clear_status(void)
514 if (pcwd_private.revision == PCWD_REVISION_C) {
515 spin_lock(&pcwd_private.io_lock);
517 if (debug >= VERBOSE)
518 printk(KERN_INFO PFX "clearing watchdog trip status\n");
520 control_status = inb_p(pcwd_private.io_addr + 1);
522 if (debug >= DEBUG) {
523 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
524 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
525 (control_status & WD_REVC_R2DS));
528 /* clear reset status & Keep Relay 2 disable state as it is */
529 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
531 spin_unlock(&pcwd_private.io_lock);
536 static int pcwd_get_temperature(int *temperature)
538 /* check that port 0 gives temperature info and no command results */
539 if (pcwd_private.command_mode)
543 if (!pcwd_private.supports_temp)
547 * Convert celsius to fahrenheit, since this was
548 * the decided 'standard' for this return value.
550 spin_lock(&pcwd_private.io_lock);
551 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
552 spin_unlock(&pcwd_private.io_lock);
554 if (debug >= DEBUG) {
555 printk(KERN_DEBUG PFX "temperature is: %d F\n",
563 * /dev/watchdog handling
566 static int pcwd_ioctl(struct inode *inode, struct file *file,
567 unsigned int cmd, unsigned long arg)
573 int __user *argp = (int __user *)arg;
574 static struct watchdog_info ident = {
575 .options = WDIOF_OVERHEAT |
577 WDIOF_KEEPALIVEPING |
580 .firmware_version = 1,
588 case WDIOC_GETSUPPORT:
589 if(copy_to_user(argp, &ident, sizeof(ident)))
593 case WDIOC_GETSTATUS:
594 pcwd_get_status(&status);
595 return put_user(status, argp);
597 case WDIOC_GETBOOTSTATUS:
598 return put_user(pcwd_private.boot_status, argp);
601 if (pcwd_get_temperature(&temperature))
604 return put_user(temperature, argp);
606 case WDIOC_SETOPTIONS:
607 if (pcwd_private.revision == PCWD_REVISION_C)
609 if(copy_from_user(&rv, argp, sizeof(int)))
612 if (rv & WDIOS_DISABLECARD)
617 if (rv & WDIOS_ENABLECARD)
622 if (rv & WDIOS_TEMPPANIC)
629 case WDIOC_KEEPALIVE:
633 case WDIOC_SETTIMEOUT:
634 if (get_user(new_heartbeat, argp))
637 if (pcwd_set_heartbeat(new_heartbeat))
643 case WDIOC_GETTIMEOUT:
644 return put_user(heartbeat, argp);
650 static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
657 /* In case it was set long ago */
660 for (i = 0; i != len; i++) {
663 if (get_user(c, buf + i))
674 static int pcwd_open(struct inode *inode, struct file *file)
676 if (!atomic_dec_and_test(&open_allowed) ) {
677 if (debug >= VERBOSE)
678 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
679 atomic_inc( &open_allowed );
684 __module_get(THIS_MODULE);
689 return nonseekable_open(inode, file);
692 static int pcwd_close(struct inode *inode, struct file *file)
694 if (expect_close == 42) {
697 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
701 atomic_inc( &open_allowed );
706 * /dev/temperature handling
709 static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
714 if (pcwd_get_temperature(&temperature))
717 if (copy_to_user(buf, &temperature, 1))
723 static int pcwd_temp_open(struct inode *inode, struct file *file)
725 if (!pcwd_private.supports_temp)
728 return nonseekable_open(inode, file);
731 static int pcwd_temp_close(struct inode *inode, struct file *file)
740 static int pcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
742 if (code==SYS_DOWN || code==SYS_HALT) {
743 /* Turn the WDT off */
754 static const struct file_operations pcwd_fops = {
755 .owner = THIS_MODULE,
760 .release = pcwd_close,
763 static struct miscdevice pcwd_miscdev = {
764 .minor = WATCHDOG_MINOR,
769 static const struct file_operations pcwd_temp_fops = {
770 .owner = THIS_MODULE,
772 .read = pcwd_temp_read,
773 .open = pcwd_temp_open,
774 .release = pcwd_temp_close,
777 static struct miscdevice temp_miscdev = {
779 .name = "temperature",
780 .fops = &pcwd_temp_fops,
783 static struct notifier_block pcwd_notifier = {
784 .notifier_call = pcwd_notify_sys,
788 * Init & exit routines
791 static inline int get_revision(void)
793 int r = PCWD_REVISION_C;
795 spin_lock(&pcwd_private.io_lock);
796 /* REV A cards use only 2 io ports; test
797 * presumes a floating bus reads as 0xff. */
798 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
799 (inb(pcwd_private.io_addr + 3) == 0xFF))
801 spin_unlock(&pcwd_private.io_lock);
806 static int __devinit pcwatchdog_init(int base_addr)
811 if (cards_found == 1)
812 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
814 if (cards_found > 1) {
815 printk(KERN_ERR PFX "This driver only supports 1 device\n");
819 if (base_addr == 0x0000) {
820 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
823 pcwd_private.io_addr = base_addr;
825 /* Check card's revision */
826 pcwd_private.revision = get_revision();
828 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
829 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
830 pcwd_private.io_addr);
831 pcwd_private.io_addr = 0x0000;
835 /* Initial variables */
836 pcwd_private.supports_temp = 0;
838 pcwd_private.boot_status = 0x0000;
840 /* get the boot_status */
841 pcwd_get_status(&pcwd_private.boot_status);
843 /* clear the "card caused reboot" flag */
846 setup_timer(&pcwd_private.timer, pcwd_timer_ping, 0);
848 /* Disable the board */
851 /* Check whether or not the card supports the temperature device */
852 pcwd_check_temperature_support();
854 /* Show info about the card itself */
855 pcwd_show_card_info();
857 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */
859 heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)];
861 /* Check that the heartbeat value is within it's range ; if not reset to the default */
862 if (pcwd_set_heartbeat(heartbeat)) {
863 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
864 printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
868 ret = register_reboot_notifier(&pcwd_notifier);
870 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
872 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
873 pcwd_private.io_addr = 0x0000;
877 if (pcwd_private.supports_temp) {
878 ret = misc_register(&temp_miscdev);
880 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
882 unregister_reboot_notifier(&pcwd_notifier);
883 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
884 pcwd_private.io_addr = 0x0000;
889 ret = misc_register(&pcwd_miscdev);
891 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
892 WATCHDOG_MINOR, ret);
893 if (pcwd_private.supports_temp)
894 misc_deregister(&temp_miscdev);
895 unregister_reboot_notifier(&pcwd_notifier);
896 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
897 pcwd_private.io_addr = 0x0000;
901 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
902 heartbeat, nowayout);
907 static void __devexit pcwatchdog_exit(void)
909 /* Disable the board */
914 misc_deregister(&pcwd_miscdev);
915 if (pcwd_private.supports_temp)
916 misc_deregister(&temp_miscdev);
917 unregister_reboot_notifier(&pcwd_notifier);
918 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
919 pcwd_private.io_addr = 0x0000;
924 * The ISA cards have a heartbeat bit in one of the registers, which
925 * register is card dependent. The heartbeat bit is monitored, and if
926 * found, is considered proof that a Berkshire card has been found.
927 * The initial rate is once per second at board start up, then twice
928 * per second for normal operation.
930 static int __init pcwd_checkcard(int base_addr)
932 int port0, last_port0; /* Reg 0, in case it's REV A */
933 int port1, last_port1; /* Register 1 for REV C cards */
937 if (!request_region (base_addr, 4, "PCWD")) {
938 printk (KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
944 port0 = inb_p(base_addr); /* For REV A boards */
945 port1 = inb_p(base_addr + 1); /* For REV C boards */
946 if (port0 != 0xff || port1 != 0xff) {
947 /* Not an 'ff' from a floating bus, so must be a card! */
948 for (i = 0; i < 4; ++i) {
955 port0 = inb_p(base_addr);
956 port1 = inb_p(base_addr + 1);
958 /* Has either hearbeat bit changed? */
959 if ((port0 ^ last_port0) & WD_HRTBT ||
960 (port1 ^ last_port1) & WD_REVC_HRBT) {
966 release_region (base_addr, 4);
972 * These are the auto-probe addresses available.
974 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
975 * Revision A has an address range of 2 addresses, while Revision C has 4.
977 static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
979 static int __init pcwd_init_module(void)
983 spin_lock_init(&pcwd_private.io_lock);
985 for (i = 0; pcwd_ioports[i] != 0; i++) {
986 if (pcwd_checkcard(pcwd_ioports[i])) {
987 if (!(pcwatchdog_init(pcwd_ioports[i])))
993 printk (KERN_INFO PFX "No card detected, or port not available\n");
1000 static void __exit pcwd_cleanup_module(void)
1002 if (pcwd_private.io_addr)
1005 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
1008 module_init(pcwd_init_module);
1009 module_exit(pcwd_cleanup_module);
1011 MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>");
1012 MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1013 MODULE_LICENSE("GPL");
1014 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1015 MODULE_ALIAS_MISCDEV(TEMP_MINOR);