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
44 * CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
45 * Added timeout module option to override default
49 * A bells and whistles driver is available from http://www.pcwd.de/
50 * More info available at http://www.berkprod.com/ or
51 * http://www.pcwatchdog.com/
54 #include <linux/module.h> /* For module specific items */
55 #include <linux/moduleparam.h> /* For new moduleparam's */
56 #include <linux/types.h> /* For standard types (like size_t) */
57 #include <linux/errno.h> /* For the -ENODEV/... values */
58 #include <linux/kernel.h> /* For printk/panic/... */
59 #include <linux/delay.h> /* For mdelay function */
60 #include <linux/timer.h> /* For timer related operations */
61 #include <linux/jiffies.h> /* For jiffies stuff */
62 #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
63 #include <linux/watchdog.h> /* For the watchdog specific items */
64 #include <linux/reboot.h> /* For kernel_power_off() */
65 #include <linux/init.h> /* For __init/__exit/... */
66 #include <linux/fs.h> /* For file operations */
67 #include <linux/isa.h> /* For isa devices */
68 #include <linux/ioport.h> /* For io-port access */
69 #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
70 #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
71 #include <linux/io.h> /* For inb/outb/... */
73 /* Module and version information */
74 #define WATCHDOG_VERSION "1.20"
75 #define WATCHDOG_DATE "18 Feb 2007"
76 #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 ")"
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.)
89 #define PCWD_REVISION_A 1
90 #define PCWD_REVISION_C 2
93 * These are the auto-probe addresses available.
95 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
96 * Revision A has an address range of 2 addresses, while Revision C has 4.
98 #define PCWD_ISA_NR_CARDS 3
99 static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
102 * These are the defines that describe the control status bits for the
103 * PCI-PC Watchdog card.
105 /* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
106 #define WD_WDRST 0x01 /* Previously reset state */
107 #define WD_T110 0x02 /* Temperature overheat sense */
108 #define WD_HRTBT 0x04 /* Heartbeat sense */
109 #define WD_RLY2 0x08 /* External relay triggered */
110 #define WD_SRLY2 0x80 /* Software external relay triggered */
111 /* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
112 #define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
113 #define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
114 #define WD_REVC_TTRP 0x04 /* Temperature Trip status */
115 #define WD_REVC_RL2A 0x08 /* Relay 2 activated by
116 on-board processor */
117 #define WD_REVC_RL1A 0x10 /* Relay 1 active */
118 #define WD_REVC_R2DS 0x40 /* Relay 2 disable */
119 #define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
120 /* Port 2 : Control Status #2 */
121 #define WD_WDIS 0x10 /* Watchdog Disabled */
122 #define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
123 #define WD_SSEL 0x40 /* Watchdog Switch Select
125 #define WD_WCMD 0x80 /* Watchdog Command Mode */
127 /* max. time we give an ISA watchdog card to process a command */
128 /* 500ms for each 4 bit response (according to spec.) */
129 #define ISA_COMMAND_TIMEOUT 1000
131 /* Watchdog's internal commands */
132 #define CMD_ISA_IDLE 0x00
133 #define CMD_ISA_VERSION_INTEGER 0x01
134 #define CMD_ISA_VERSION_TENTH 0x02
135 #define CMD_ISA_VERSION_HUNDRETH 0x03
136 #define CMD_ISA_VERSION_MINOR 0x04
137 #define CMD_ISA_SWITCH_SETTINGS 0x05
138 #define CMD_ISA_RESET_PC 0x06
139 #define CMD_ISA_ARM_0 0x07
140 #define CMD_ISA_ARM_30 0x08
141 #define CMD_ISA_ARM_60 0x09
142 #define CMD_ISA_DELAY_TIME_2SECS 0x0A
143 #define CMD_ISA_DELAY_TIME_4SECS 0x0B
144 #define CMD_ISA_DELAY_TIME_8SECS 0x0C
145 #define CMD_ISA_RESET_RELAYS 0x0D
147 /* Watchdog's Dip Switch heartbeat values */
148 static const int heartbeat_tbl[] = {
149 20, /* OFF-OFF-OFF = 20 Sec */
150 40, /* OFF-OFF-ON = 40 Sec */
151 60, /* OFF-ON-OFF = 1 Min */
152 300, /* OFF-ON-ON = 5 Min */
153 600, /* ON-OFF-OFF = 10 Min */
154 1800, /* ON-OFF-ON = 30 Min */
155 3600, /* ON-ON-OFF = 1 Hour */
156 7200, /* ON-ON-ON = 2 hour */
160 * We are using an kernel timer to do the pinging of the watchdog
161 * every ~500ms. We try to set the internal heartbeat of the
165 #define WDT_INTERVAL (HZ/2+1)
167 /* We can only use 1 card due to the /dev/watchdog restriction */
168 static int cards_found;
170 /* internal variables */
171 static unsigned long open_allowed;
172 static char expect_close;
173 static int temp_panic;
175 /* this is private data for each ISA-PC watchdog card */
177 char fw_ver_str[6]; /* The cards firmware version */
178 int revision; /* The card's revision */
179 int supports_temp; /* Whether or not the card has
180 a temperature device */
181 int command_mode; /* Whether or not the card is in
183 int boot_status; /* The card's boot status */
184 int io_addr; /* The cards I/O address */
185 spinlock_t io_lock; /* the lock for io operations */
186 struct timer_list timer; /* The timer that pings the watchdog */
187 unsigned long next_heartbeat; /* the next_heartbeat for the timer */
190 /* module parameters */
191 #define QUIET 0 /* Default */
192 #define VERBOSE 1 /* Verbose */
193 #define DEBUG 2 /* print fancy stuff too */
194 static int debug = QUIET;
195 module_param(debug, int, 0);
196 MODULE_PARM_DESC(debug,
197 "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
199 /* default heartbeat = delay-time from dip-switches */
200 #define WATCHDOG_HEARTBEAT 0
201 static int heartbeat = WATCHDOG_HEARTBEAT;
202 module_param(heartbeat, int, 0);
203 MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2 <= heartbeat <= 7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
205 static int nowayout = WATCHDOG_NOWAYOUT;
206 module_param(nowayout, int, 0);
207 MODULE_PARM_DESC(nowayout,
208 "Watchdog cannot be stopped once started (default="
209 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
215 static int send_isa_command(int cmd)
219 int port0, last_port0; /* Double read for stabilising */
222 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
225 /* The WCMD bit must be 1 and the command is only 4 bits in size */
226 control_status = (cmd & 0x0F) | WD_WCMD;
227 outb_p(control_status, pcwd_private.io_addr + 2);
228 udelay(ISA_COMMAND_TIMEOUT);
230 port0 = inb_p(pcwd_private.io_addr);
231 for (i = 0; i < 25; ++i) {
233 port0 = inb_p(pcwd_private.io_addr);
235 if (port0 == last_port0)
236 break; /* Data is stable */
242 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
243 cmd, port0, last_port0);
248 static int set_command_mode(void)
250 int i, found = 0, count = 0;
252 /* Set the card into command mode */
253 spin_lock(&pcwd_private.io_lock);
254 while ((!found) && (count < 3)) {
255 i = send_isa_command(CMD_ISA_IDLE);
259 else if (i == 0xF3) {
260 /* Card does not like what we've done to it */
261 outb_p(0x00, pcwd_private.io_addr + 2);
262 udelay(1200); /* Spec says wait 1ms */
263 outb_p(0x00, pcwd_private.io_addr + 2);
264 udelay(ISA_COMMAND_TIMEOUT);
268 spin_unlock(&pcwd_private.io_lock);
269 pcwd_private.command_mode = found;
272 printk(KERN_DEBUG PFX "command_mode=%d\n",
273 pcwd_private.command_mode);
278 static void unset_command_mode(void)
280 /* Set the card into normal mode */
281 spin_lock(&pcwd_private.io_lock);
282 outb_p(0x00, pcwd_private.io_addr + 2);
283 udelay(ISA_COMMAND_TIMEOUT);
284 spin_unlock(&pcwd_private.io_lock);
286 pcwd_private.command_mode = 0;
289 printk(KERN_DEBUG PFX "command_mode=%d\n",
290 pcwd_private.command_mode);
293 static inline void pcwd_check_temperature_support(void)
295 if (inb(pcwd_private.io_addr) != 0xF0)
296 pcwd_private.supports_temp = 1;
299 static inline void pcwd_get_firmware(void)
301 int one, ten, hund, minor;
303 strcpy(pcwd_private.fw_ver_str, "ERROR");
305 if (set_command_mode()) {
306 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
307 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
308 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
309 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
310 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c",
311 one, ten, hund, minor);
313 unset_command_mode();
318 static inline int pcwd_get_option_switches(void)
320 int option_switches = 0;
322 if (set_command_mode()) {
323 /* Get switch settings */
324 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
327 unset_command_mode();
328 return option_switches;
331 static void pcwd_show_card_info(void)
335 /* Get some extra info from the hardware (in command/debug/diag mode) */
336 if (pcwd_private.revision == PCWD_REVISION_A)
338 "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n",
339 pcwd_private.io_addr);
340 else if (pcwd_private.revision == PCWD_REVISION_C) {
342 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
343 pcwd_private.io_addr, pcwd_private.fw_ver_str);
344 option_switches = pcwd_get_option_switches();
345 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
347 ((option_switches & 0x10) ? "ON" : "OFF"),
348 ((option_switches & 0x08) ? "ON" : "OFF"));
350 /* Reprogram internal heartbeat to 2 seconds */
351 if (set_command_mode()) {
352 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
353 unset_command_mode();
357 if (pcwd_private.supports_temp)
358 printk(KERN_INFO PFX "Temperature Option Detected\n");
360 if (pcwd_private.boot_status & WDIOF_CARDRESET)
361 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
363 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
364 printk(KERN_EMERG PFX
365 "Card senses a CPU Overheat. Panicking!\n");
366 printk(KERN_EMERG PFX
370 if (pcwd_private.boot_status == 0)
372 "No previous trip detected - Cold boot or reset\n");
375 static void pcwd_timer_ping(unsigned long data)
379 /* If we got a heartbeat pulse within the WDT_INTERVAL
380 * we agree to ping the WDT */
381 if (time_before(jiffies, pcwd_private.next_heartbeat)) {
382 /* Ping the watchdog */
383 spin_lock(&pcwd_private.io_lock);
384 if (pcwd_private.revision == PCWD_REVISION_A) {
385 /* Rev A cards are reset by setting the
386 WD_WDRST bit in register 1 */
387 wdrst_stat = inb_p(pcwd_private.io_addr);
389 wdrst_stat |= WD_WDRST;
391 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
393 /* Re-trigger watchdog by writing to port 0 */
394 outb_p(0x00, pcwd_private.io_addr);
397 /* Re-set the timer interval */
398 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
400 spin_unlock(&pcwd_private.io_lock);
402 printk(KERN_WARNING PFX
403 "Heartbeat lost! Will not ping the watchdog\n");
407 static int pcwd_start(void)
411 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
413 /* Start the timer */
414 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
416 /* Enable the port */
417 if (pcwd_private.revision == PCWD_REVISION_C) {
418 spin_lock(&pcwd_private.io_lock);
419 outb_p(0x00, 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) {
424 printk(KERN_INFO PFX "Could not start watchdog\n");
429 if (debug >= VERBOSE)
430 printk(KERN_DEBUG PFX "Watchdog started\n");
435 static int pcwd_stop(void)
440 del_timer(&pcwd_private.timer);
442 /* Disable the board */
443 if (pcwd_private.revision == PCWD_REVISION_C) {
444 spin_lock(&pcwd_private.io_lock);
445 outb_p(0xA5, pcwd_private.io_addr + 3);
446 udelay(ISA_COMMAND_TIMEOUT);
447 outb_p(0xA5, pcwd_private.io_addr + 3);
448 udelay(ISA_COMMAND_TIMEOUT);
449 stat_reg = inb_p(pcwd_private.io_addr + 2);
450 spin_unlock(&pcwd_private.io_lock);
451 if ((stat_reg & WD_WDIS) == 0) {
452 printk(KERN_INFO PFX "Could not stop watchdog\n");
457 if (debug >= VERBOSE)
458 printk(KERN_DEBUG PFX "Watchdog stopped\n");
463 static int pcwd_keepalive(void)
466 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
469 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
474 static int pcwd_set_heartbeat(int t)
476 if (t < 2 || t > 7200) /* arbitrary upper limit */
481 if (debug >= VERBOSE)
482 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
488 static int pcwd_get_status(int *status)
493 spin_lock(&pcwd_private.io_lock);
494 if (pcwd_private.revision == PCWD_REVISION_A)
495 /* Rev A cards return status information from
496 * the base register, which is used for the
497 * temperature in other cards. */
498 control_status = inb(pcwd_private.io_addr);
500 /* Rev C cards return card status in the base
501 * address + 1 register. And use different bits
502 * to indicate a card initiated reset, and an
503 * over-temperature condition. And the reboot
504 * status can be reset. */
505 control_status = inb(pcwd_private.io_addr + 1);
507 spin_unlock(&pcwd_private.io_lock);
509 if (pcwd_private.revision == PCWD_REVISION_A) {
510 if (control_status & WD_WDRST)
511 *status |= WDIOF_CARDRESET;
513 if (control_status & WD_T110) {
514 *status |= WDIOF_OVERHEAT;
517 "Temperature overheat trip!\n");
522 if (control_status & WD_REVC_WTRP)
523 *status |= WDIOF_CARDRESET;
525 if (control_status & WD_REVC_TTRP) {
526 *status |= WDIOF_OVERHEAT;
529 "Temperature overheat trip!\n");
538 static int pcwd_clear_status(void)
542 if (pcwd_private.revision == PCWD_REVISION_C) {
543 spin_lock(&pcwd_private.io_lock);
545 if (debug >= VERBOSE)
547 "clearing watchdog trip status\n");
549 control_status = inb_p(pcwd_private.io_addr + 1);
551 if (debug >= DEBUG) {
552 printk(KERN_DEBUG PFX "status was: 0x%02x\n",
554 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
555 (control_status & WD_REVC_R2DS));
558 /* clear reset status & Keep Relay 2 disable state as it is */
559 outb_p((control_status & WD_REVC_R2DS),
560 pcwd_private.io_addr + 1);
562 spin_unlock(&pcwd_private.io_lock);
567 static int pcwd_get_temperature(int *temperature)
569 /* check that port 0 gives temperature info and no command results */
570 if (pcwd_private.command_mode)
574 if (!pcwd_private.supports_temp)
578 * Convert celsius to fahrenheit, since this was
579 * the decided 'standard' for this return value.
581 spin_lock(&pcwd_private.io_lock);
582 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
583 spin_unlock(&pcwd_private.io_lock);
585 if (debug >= DEBUG) {
586 printk(KERN_DEBUG PFX "temperature is: %d F\n",
594 * /dev/watchdog handling
597 static long pcwd_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
603 int __user *argp = (int __user *)arg;
604 static struct watchdog_info ident = {
605 .options = WDIOF_OVERHEAT |
607 WDIOF_KEEPALIVEPING |
610 .firmware_version = 1,
615 case WDIOC_GETSUPPORT:
616 if (copy_to_user(argp, &ident, sizeof(ident)))
620 case WDIOC_GETSTATUS:
621 pcwd_get_status(&status);
622 return put_user(status, argp);
624 case WDIOC_GETBOOTSTATUS:
625 return put_user(pcwd_private.boot_status, argp);
628 if (pcwd_get_temperature(&temperature))
631 return put_user(temperature, argp);
633 case WDIOC_SETOPTIONS:
634 if (pcwd_private.revision == PCWD_REVISION_C) {
635 if (get_user(rv, argp))
638 if (rv & WDIOS_DISABLECARD) {
639 status = pcwd_stop();
643 if (rv & WDIOS_ENABLECARD) {
644 status = pcwd_start();
648 if (rv & WDIOS_TEMPPANIC)
653 case WDIOC_KEEPALIVE:
657 case WDIOC_SETTIMEOUT:
658 if (get_user(new_heartbeat, argp))
661 if (pcwd_set_heartbeat(new_heartbeat))
667 case WDIOC_GETTIMEOUT:
668 return put_user(heartbeat, argp);
677 static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
684 /* In case it was set long ago */
687 for (i = 0; i != len; i++) {
690 if (get_user(c, buf + i))
701 static int pcwd_open(struct inode *inode, struct file *file)
703 if (test_and_set_bit(0, &open_allowed))
706 __module_get(THIS_MODULE);
710 return nonseekable_open(inode, file);
713 static int pcwd_close(struct inode *inode, struct file *file)
715 if (expect_close == 42)
719 "Unexpected close, not stopping watchdog!\n");
723 clear_bit(0, &open_allowed);
728 * /dev/temperature handling
731 static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
736 if (pcwd_get_temperature(&temperature))
739 if (copy_to_user(buf, &temperature, 1))
745 static int pcwd_temp_open(struct inode *inode, struct file *file)
747 if (!pcwd_private.supports_temp)
750 return nonseekable_open(inode, file);
753 static int pcwd_temp_close(struct inode *inode, struct file *file)
762 static const struct file_operations pcwd_fops = {
763 .owner = THIS_MODULE,
766 .unlocked_ioctl = pcwd_ioctl,
768 .release = pcwd_close,
771 static struct miscdevice pcwd_miscdev = {
772 .minor = WATCHDOG_MINOR,
777 static const struct file_operations pcwd_temp_fops = {
778 .owner = THIS_MODULE,
780 .read = pcwd_temp_read,
781 .open = pcwd_temp_open,
782 .release = pcwd_temp_close,
785 static struct miscdevice temp_miscdev = {
787 .name = "temperature",
788 .fops = &pcwd_temp_fops,
792 * Init & exit routines
795 static inline int get_revision(void)
797 int r = PCWD_REVISION_C;
799 spin_lock(&pcwd_private.io_lock);
800 /* REV A cards use only 2 io ports; test
801 * presumes a floating bus reads as 0xff. */
802 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
803 (inb(pcwd_private.io_addr + 3) == 0xFF))
805 spin_unlock(&pcwd_private.io_lock);
811 * The ISA cards have a heartbeat bit in one of the registers, which
812 * register is card dependent. The heartbeat bit is monitored, and if
813 * found, is considered proof that a Berkshire card has been found.
814 * The initial rate is once per second at board start up, then twice
815 * per second for normal operation.
817 static int __devinit pcwd_isa_match(struct device *dev, unsigned int id)
819 int base_addr = pcwd_ioports[id];
820 int port0, last_port0; /* Reg 0, in case it's REV A */
821 int port1, last_port1; /* Register 1 for REV C cards */
826 printk(KERN_DEBUG PFX "pcwd_isa_match id=%d\n",
829 if (!request_region(base_addr, 4, "PCWD")) {
830 printk(KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
836 port0 = inb_p(base_addr); /* For REV A boards */
837 port1 = inb_p(base_addr + 1); /* For REV C boards */
838 if (port0 != 0xff || port1 != 0xff) {
839 /* Not an 'ff' from a floating bus, so must be a card! */
840 for (i = 0; i < 4; ++i) {
847 port0 = inb_p(base_addr);
848 port1 = inb_p(base_addr + 1);
850 /* Has either hearbeat bit changed? */
851 if ((port0 ^ last_port0) & WD_HRTBT ||
852 (port1 ^ last_port1) & WD_REVC_HRBT) {
858 release_region(base_addr, 4);
863 static int __devinit pcwd_isa_probe(struct device *dev, unsigned int id)
868 printk(KERN_DEBUG PFX "pcwd_isa_probe id=%d\n",
872 if (cards_found == 1)
873 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n",
876 if (cards_found > 1) {
877 printk(KERN_ERR PFX "This driver only supports 1 device\n");
881 if (pcwd_ioports[id] == 0x0000) {
882 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
885 pcwd_private.io_addr = pcwd_ioports[id];
887 spin_lock_init(&pcwd_private.io_lock);
889 /* Check card's revision */
890 pcwd_private.revision = get_revision();
892 if (!request_region(pcwd_private.io_addr,
893 (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
894 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
895 pcwd_private.io_addr);
897 goto error_request_region;
900 /* Initial variables */
901 pcwd_private.supports_temp = 0;
903 pcwd_private.boot_status = 0x0000;
905 /* get the boot_status */
906 pcwd_get_status(&pcwd_private.boot_status);
908 /* clear the "card caused reboot" flag */
911 setup_timer(&pcwd_private.timer, pcwd_timer_ping, 0);
913 /* Disable the board */
916 /* Check whether or not the card supports the temperature device */
917 pcwd_check_temperature_support();
919 /* Show info about the card itself */
920 pcwd_show_card_info();
922 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */
924 heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)];
926 /* Check that the heartbeat value is within it's range;
927 if not reset to the default */
928 if (pcwd_set_heartbeat(heartbeat)) {
929 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
931 "heartbeat value must be 2 <= heartbeat <= 7200, using %d\n",
935 if (pcwd_private.supports_temp) {
936 ret = misc_register(&temp_miscdev);
939 "cannot register miscdev on minor=%d (err=%d)\n",
941 goto error_misc_register_temp;
945 ret = misc_register(&pcwd_miscdev);
948 "cannot register miscdev on minor=%d (err=%d)\n",
949 WATCHDOG_MINOR, ret);
950 goto error_misc_register_watchdog;
953 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
954 heartbeat, nowayout);
958 error_misc_register_watchdog:
959 if (pcwd_private.supports_temp)
960 misc_deregister(&temp_miscdev);
961 error_misc_register_temp:
962 release_region(pcwd_private.io_addr,
963 (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
964 error_request_region:
965 pcwd_private.io_addr = 0x0000;
970 static int __devexit pcwd_isa_remove(struct device *dev, unsigned int id)
973 printk(KERN_DEBUG PFX "pcwd_isa_remove id=%d\n",
976 if (!pcwd_private.io_addr)
979 /* Disable the board */
984 misc_deregister(&pcwd_miscdev);
985 if (pcwd_private.supports_temp)
986 misc_deregister(&temp_miscdev);
987 release_region(pcwd_private.io_addr,
988 (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
989 pcwd_private.io_addr = 0x0000;
995 static void pcwd_isa_shutdown(struct device *dev, unsigned int id)
998 printk(KERN_DEBUG PFX "pcwd_isa_shutdown id=%d\n",
1004 static struct isa_driver pcwd_isa_driver = {
1005 .match = pcwd_isa_match,
1006 .probe = pcwd_isa_probe,
1007 .remove = __devexit_p(pcwd_isa_remove),
1008 .shutdown = pcwd_isa_shutdown,
1010 .owner = THIS_MODULE,
1011 .name = WATCHDOG_NAME,
1015 static int __init pcwd_init_module(void)
1017 return isa_register_driver(&pcwd_isa_driver, PCWD_ISA_NR_CARDS);
1020 static void __exit pcwd_cleanup_module(void)
1022 isa_unregister_driver(&pcwd_isa_driver);
1023 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
1026 module_init(pcwd_init_module);
1027 module_exit(pcwd_cleanup_module);
1029 MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, Wim Van Sebroeck <wim@iguana.be>");
1030 MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1031 MODULE_VERSION(WATCHDOG_VERSION);
1032 MODULE_LICENSE("GPL");
1033 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1034 MODULE_ALIAS_MISCDEV(TEMP_MINOR);