1 // SPDX-License-Identifier: GPL-2.0-only
4 * by Ken Hollis (khollis@bitgate.com)
6 * Permission granted from Simon Machell (smachell@berkprod.com)
7 * Written for the Linux Kernel, and GPLed by Ken Hollis
9 * 960107 Added request_region routines, modulized the whole thing.
10 * 960108 Fixed end-of-file pointer (Thanks to Dan Hollis), added
12 * 960216 Added eof marker on the file, and changed verbose messages.
13 * 960716 Made functional and cosmetic changes to the source for
14 * inclusion in Linux 2.0.x kernels, thanks to Alan Cox.
15 * 960717 Removed read/seek routines, replaced with ioctl. Also, added
16 * check_region command due to Alan's suggestion.
17 * 960821 Made changes to compile in newer 2.0.x kernels. Added
18 * "cold reboot sense" entry.
19 * 960825 Made a few changes to code, deleted some defines and made
20 * typedefs to replace them. Made heartbeat reset only available
21 * via ioctl, and removed the write routine.
22 * 960828 Added new items for PC Watchdog Rev.C card.
23 * 960829 Changed around all of the IOCTLs, added new features,
24 * added watchdog disable/re-enable routines. Added firmware
25 * version reporting. Added read routine for temperature.
26 * Removed some extra defines, added an autodetect Revision
28 * 961006 Revised some documentation, fixed some cosmetic bugs. Made
29 * drivers to panic the system if it's overheating at bootup.
30 * 961118 Changed some verbiage on some of the output, tidied up
31 * code bits, and added compatibility to 2.1.x.
32 * 970912 Enabled board on open and disable on close.
33 * 971107 Took account of recent VFS changes (broke read).
34 * 971210 Disable board on initialisation in case board already ticking.
35 * 971222 Changed open/close for temperature handling
36 * Michael Meskes <meskes@debian.org>.
37 * 980112 Used minor numbers from include/linux/miscdevice.h
38 * 990403 Clear reset status after reading control status register in
39 * pcwd_showprevstate(). [Marc Boucher <marc@mbsi.ca>]
40 * 990605 Made changes to code to support Firmware 1.22a, added
41 * fairly useless proc entry.
42 * 990610 removed said useless proc code for the merge <alan>
43 * 000403 Removed last traces of proc code. <davej>
44 * 011214 Added nowayout module option to override
45 * CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
46 * Added timeout module option to override default
50 * A bells and whistles driver is available from http://www.pcwd.de/
51 * More info available at http://www.berkprod.com/ or
52 * http://www.pcwatchdog.com/
55 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
57 #include <linux/module.h> /* For module specific items */
58 #include <linux/moduleparam.h> /* For new moduleparam's */
59 #include <linux/types.h> /* For standard types (like size_t) */
60 #include <linux/errno.h> /* For the -ENODEV/... values */
61 #include <linux/kernel.h> /* For printk/panic/... */
62 #include <linux/delay.h> /* For mdelay function */
63 #include <linux/timer.h> /* For timer related operations */
64 #include <linux/jiffies.h> /* For jiffies stuff */
65 #include <linux/miscdevice.h> /* For struct miscdevice */
66 #include <linux/watchdog.h> /* For the watchdog specific items */
67 #include <linux/reboot.h> /* For kernel_power_off() */
68 #include <linux/init.h> /* For __init/__exit/... */
69 #include <linux/fs.h> /* For file operations */
70 #include <linux/isa.h> /* For isa devices */
71 #include <linux/ioport.h> /* For io-port access */
72 #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
73 #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
74 #include <linux/io.h> /* For inb/outb/... */
76 /* Module and version information */
77 #define WATCHDOG_VERSION "1.20"
78 #define WATCHDOG_DATE "18 Feb 2007"
79 #define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
80 #define WATCHDOG_NAME "pcwd"
81 #define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION "\n"
84 * It should be noted that PCWD_REVISION_B was removed because A and B
85 * are essentially the same types of card, with the exception that B
86 * has temperature reporting. Since I didn't receive a Rev.B card,
87 * the Rev.B card is not supported. (It's a good thing too, as they
88 * are no longer in production.)
90 #define PCWD_REVISION_A 1
91 #define PCWD_REVISION_C 2
94 * These are the auto-probe addresses available.
96 * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350.
97 * Revision A has an address range of 2 addresses, while Revision C has 4.
99 #define PCWD_ISA_NR_CARDS 3
100 static int pcwd_ioports
[] = { 0x270, 0x350, 0x370, 0x000 };
103 * These are the defines that describe the control status bits for the
104 * PCI-PC Watchdog card.
106 /* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */
107 #define WD_WDRST 0x01 /* Previously reset state */
108 #define WD_T110 0x02 /* Temperature overheat sense */
109 #define WD_HRTBT 0x04 /* Heartbeat sense */
110 #define WD_RLY2 0x08 /* External relay triggered */
111 #define WD_SRLY2 0x80 /* Software external relay triggered */
112 /* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
113 #define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
114 #define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
115 #define WD_REVC_TTRP 0x04 /* Temperature Trip status */
116 #define WD_REVC_RL2A 0x08 /* Relay 2 activated by
117 on-board processor */
118 #define WD_REVC_RL1A 0x10 /* Relay 1 active */
119 #define WD_REVC_R2DS 0x40 /* Relay 2 disable */
120 #define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
121 /* Port 2 : Control Status #2 */
122 #define WD_WDIS 0x10 /* Watchdog Disabled */
123 #define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
124 #define WD_SSEL 0x40 /* Watchdog Switch Select
126 #define WD_WCMD 0x80 /* Watchdog Command Mode */
128 /* max. time we give an ISA watchdog card to process a command */
129 /* 500ms for each 4 bit response (according to spec.) */
130 #define ISA_COMMAND_TIMEOUT 1000
132 /* Watchdog's internal commands */
133 #define CMD_ISA_IDLE 0x00
134 #define CMD_ISA_VERSION_INTEGER 0x01
135 #define CMD_ISA_VERSION_TENTH 0x02
136 #define CMD_ISA_VERSION_HUNDRETH 0x03
137 #define CMD_ISA_VERSION_MINOR 0x04
138 #define CMD_ISA_SWITCH_SETTINGS 0x05
139 #define CMD_ISA_RESET_PC 0x06
140 #define CMD_ISA_ARM_0 0x07
141 #define CMD_ISA_ARM_30 0x08
142 #define CMD_ISA_ARM_60 0x09
143 #define CMD_ISA_DELAY_TIME_2SECS 0x0A
144 #define CMD_ISA_DELAY_TIME_4SECS 0x0B
145 #define CMD_ISA_DELAY_TIME_8SECS 0x0C
146 #define CMD_ISA_RESET_RELAYS 0x0D
148 /* Watchdog's Dip Switch heartbeat values */
149 static const int heartbeat_tbl
[] = {
150 20, /* OFF-OFF-OFF = 20 Sec */
151 40, /* OFF-OFF-ON = 40 Sec */
152 60, /* OFF-ON-OFF = 1 Min */
153 300, /* OFF-ON-ON = 5 Min */
154 600, /* ON-OFF-OFF = 10 Min */
155 1800, /* ON-OFF-ON = 30 Min */
156 3600, /* ON-ON-OFF = 1 Hour */
157 7200, /* ON-ON-ON = 2 hour */
161 * We are using an kernel timer to do the pinging of the watchdog
162 * every ~500ms. We try to set the internal heartbeat of the
166 #define WDT_INTERVAL (HZ/2+1)
168 /* We can only use 1 card due to the /dev/watchdog restriction */
169 static int cards_found
;
171 /* internal variables */
172 static unsigned long open_allowed
;
173 static char expect_close
;
174 static int temp_panic
;
176 /* this is private data for each ISA-PC watchdog card */
178 char fw_ver_str
[6]; /* The cards firmware version */
179 int revision
; /* The card's revision */
180 int supports_temp
; /* Whether or not the card has
181 a temperature device */
182 int command_mode
; /* Whether or not the card is in
184 int boot_status
; /* The card's boot status */
185 int io_addr
; /* The cards I/O address */
186 spinlock_t io_lock
; /* the lock for io operations */
187 struct timer_list timer
; /* The timer that pings the watchdog */
188 unsigned long next_heartbeat
; /* the next_heartbeat for the timer */
191 /* module parameters */
192 #define QUIET 0 /* Default */
193 #define VERBOSE 1 /* Verbose */
194 #define DEBUG 2 /* print fancy stuff too */
195 static int debug
= QUIET
;
196 module_param(debug
, int, 0);
197 MODULE_PARM_DESC(debug
,
198 "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
200 /* default heartbeat = delay-time from dip-switches */
201 #define WATCHDOG_HEARTBEAT 0
202 static int heartbeat
= WATCHDOG_HEARTBEAT
;
203 module_param(heartbeat
, int, 0);
204 MODULE_PARM_DESC(heartbeat
, "Watchdog heartbeat in seconds. "
205 "(2 <= heartbeat <= 7200 or 0=delay-time from dip-switches, default="
206 __MODULE_STRING(WATCHDOG_HEARTBEAT
) ")");
208 static bool nowayout
= WATCHDOG_NOWAYOUT
;
209 module_param(nowayout
, bool, 0);
210 MODULE_PARM_DESC(nowayout
,
211 "Watchdog cannot be stopped once started (default="
212 __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
218 static int send_isa_command(int cmd
)
222 int port0
, last_port0
; /* Double read for stabilising */
225 pr_debug("sending following data cmd=0x%02x\n", cmd
);
227 /* The WCMD bit must be 1 and the command is only 4 bits in size */
228 control_status
= (cmd
& 0x0F) | WD_WCMD
;
229 outb_p(control_status
, pcwd_private
.io_addr
+ 2);
230 udelay(ISA_COMMAND_TIMEOUT
);
232 port0
= inb_p(pcwd_private
.io_addr
);
233 for (i
= 0; i
< 25; ++i
) {
235 port0
= inb_p(pcwd_private
.io_addr
);
237 if (port0
== last_port0
)
238 break; /* Data is stable */
244 pr_debug("received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
245 cmd
, port0
, last_port0
);
250 static int set_command_mode(void)
252 int i
, found
= 0, count
= 0;
254 /* Set the card into command mode */
255 spin_lock(&pcwd_private
.io_lock
);
256 while ((!found
) && (count
< 3)) {
257 i
= send_isa_command(CMD_ISA_IDLE
);
261 else if (i
== 0xF3) {
262 /* Card does not like what we've done to it */
263 outb_p(0x00, pcwd_private
.io_addr
+ 2);
264 udelay(1200); /* Spec says wait 1ms */
265 outb_p(0x00, pcwd_private
.io_addr
+ 2);
266 udelay(ISA_COMMAND_TIMEOUT
);
270 spin_unlock(&pcwd_private
.io_lock
);
271 pcwd_private
.command_mode
= found
;
274 pr_debug("command_mode=%d\n", pcwd_private
.command_mode
);
279 static void unset_command_mode(void)
281 /* Set the card into normal mode */
282 spin_lock(&pcwd_private
.io_lock
);
283 outb_p(0x00, pcwd_private
.io_addr
+ 2);
284 udelay(ISA_COMMAND_TIMEOUT
);
285 spin_unlock(&pcwd_private
.io_lock
);
287 pcwd_private
.command_mode
= 0;
290 pr_debug("command_mode=%d\n", 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
)
337 pr_info("ISA-PC Watchdog (REV.A) detected at port 0x%04x\n",
338 pcwd_private
.io_addr
);
339 else if (pcwd_private
.revision
== PCWD_REVISION_C
) {
341 pr_info("ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
342 pcwd_private
.io_addr
, pcwd_private
.fw_ver_str
);
343 option_switches
= pcwd_get_option_switches();
344 pr_info("Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
346 ((option_switches
& 0x10) ? "ON" : "OFF"),
347 ((option_switches
& 0x08) ? "ON" : "OFF"));
349 /* Reprogram internal heartbeat to 2 seconds */
350 if (set_command_mode()) {
351 send_isa_command(CMD_ISA_DELAY_TIME_2SECS
);
352 unset_command_mode();
356 if (pcwd_private
.supports_temp
)
357 pr_info("Temperature Option Detected\n");
359 if (pcwd_private
.boot_status
& WDIOF_CARDRESET
)
360 pr_info("Previous reboot was caused by the card\n");
362 if (pcwd_private
.boot_status
& WDIOF_OVERHEAT
) {
363 pr_emerg("Card senses a CPU Overheat. Panicking!\n");
364 pr_emerg("CPU Overheat\n");
367 if (pcwd_private
.boot_status
== 0)
368 pr_info("No previous trip detected - Cold boot or reset\n");
371 static void pcwd_timer_ping(struct timer_list
*unused
)
375 /* If we got a heartbeat pulse within the WDT_INTERVAL
376 * we agree to ping the WDT */
377 if (time_before(jiffies
, pcwd_private
.next_heartbeat
)) {
378 /* Ping the watchdog */
379 spin_lock(&pcwd_private
.io_lock
);
380 if (pcwd_private
.revision
== PCWD_REVISION_A
) {
381 /* Rev A cards are reset by setting the
382 WD_WDRST bit in register 1 */
383 wdrst_stat
= inb_p(pcwd_private
.io_addr
);
385 wdrst_stat
|= WD_WDRST
;
387 outb_p(wdrst_stat
, pcwd_private
.io_addr
+ 1);
389 /* Re-trigger watchdog by writing to port 0 */
390 outb_p(0x00, pcwd_private
.io_addr
);
393 /* Re-set the timer interval */
394 mod_timer(&pcwd_private
.timer
, jiffies
+ WDT_INTERVAL
);
396 spin_unlock(&pcwd_private
.io_lock
);
398 pr_warn("Heartbeat lost! Will not ping the watchdog\n");
402 static int pcwd_start(void)
406 pcwd_private
.next_heartbeat
= jiffies
+ (heartbeat
* HZ
);
408 /* Start the timer */
409 mod_timer(&pcwd_private
.timer
, jiffies
+ WDT_INTERVAL
);
411 /* Enable the port */
412 if (pcwd_private
.revision
== PCWD_REVISION_C
) {
413 spin_lock(&pcwd_private
.io_lock
);
414 outb_p(0x00, pcwd_private
.io_addr
+ 3);
415 udelay(ISA_COMMAND_TIMEOUT
);
416 stat_reg
= inb_p(pcwd_private
.io_addr
+ 2);
417 spin_unlock(&pcwd_private
.io_lock
);
418 if (stat_reg
& WD_WDIS
) {
419 pr_info("Could not start watchdog\n");
424 if (debug
>= VERBOSE
)
425 pr_debug("Watchdog started\n");
430 static int pcwd_stop(void)
435 del_timer(&pcwd_private
.timer
);
437 /* Disable the board */
438 if (pcwd_private
.revision
== PCWD_REVISION_C
) {
439 spin_lock(&pcwd_private
.io_lock
);
440 outb_p(0xA5, pcwd_private
.io_addr
+ 3);
441 udelay(ISA_COMMAND_TIMEOUT
);
442 outb_p(0xA5, pcwd_private
.io_addr
+ 3);
443 udelay(ISA_COMMAND_TIMEOUT
);
444 stat_reg
= inb_p(pcwd_private
.io_addr
+ 2);
445 spin_unlock(&pcwd_private
.io_lock
);
446 if ((stat_reg
& WD_WDIS
) == 0) {
447 pr_info("Could not stop watchdog\n");
452 if (debug
>= VERBOSE
)
453 pr_debug("Watchdog stopped\n");
458 static int pcwd_keepalive(void)
461 pcwd_private
.next_heartbeat
= jiffies
+ (heartbeat
* HZ
);
464 pr_debug("Watchdog keepalive signal send\n");
469 static int pcwd_set_heartbeat(int t
)
471 if (t
< 2 || t
> 7200) /* arbitrary upper limit */
476 if (debug
>= VERBOSE
)
477 pr_debug("New heartbeat: %d\n", heartbeat
);
482 static int pcwd_get_status(int *status
)
487 spin_lock(&pcwd_private
.io_lock
);
488 if (pcwd_private
.revision
== PCWD_REVISION_A
)
489 /* Rev A cards return status information from
490 * the base register, which is used for the
491 * temperature in other cards. */
492 control_status
= inb(pcwd_private
.io_addr
);
494 /* Rev C cards return card status in the base
495 * address + 1 register. And use different bits
496 * to indicate a card initiated reset, and an
497 * over-temperature condition. And the reboot
498 * status can be reset. */
499 control_status
= inb(pcwd_private
.io_addr
+ 1);
501 spin_unlock(&pcwd_private
.io_lock
);
503 if (pcwd_private
.revision
== PCWD_REVISION_A
) {
504 if (control_status
& WD_WDRST
)
505 *status
|= WDIOF_CARDRESET
;
507 if (control_status
& WD_T110
) {
508 *status
|= WDIOF_OVERHEAT
;
510 pr_info("Temperature overheat trip!\n");
515 if (control_status
& WD_REVC_WTRP
)
516 *status
|= WDIOF_CARDRESET
;
518 if (control_status
& WD_REVC_TTRP
) {
519 *status
|= WDIOF_OVERHEAT
;
521 pr_info("Temperature overheat trip!\n");
530 static int pcwd_clear_status(void)
534 if (pcwd_private
.revision
== PCWD_REVISION_C
) {
535 spin_lock(&pcwd_private
.io_lock
);
537 if (debug
>= VERBOSE
)
538 pr_info("clearing watchdog trip status\n");
540 control_status
= inb_p(pcwd_private
.io_addr
+ 1);
542 if (debug
>= DEBUG
) {
543 pr_debug("status was: 0x%02x\n", control_status
);
544 pr_debug("sending: 0x%02x\n",
545 (control_status
& WD_REVC_R2DS
));
548 /* clear reset status & Keep Relay 2 disable state as it is */
549 outb_p((control_status
& WD_REVC_R2DS
),
550 pcwd_private
.io_addr
+ 1);
552 spin_unlock(&pcwd_private
.io_lock
);
557 static int pcwd_get_temperature(int *temperature
)
559 /* check that port 0 gives temperature info and no command results */
560 if (pcwd_private
.command_mode
)
564 if (!pcwd_private
.supports_temp
)
568 * Convert celsius to fahrenheit, since this was
569 * the decided 'standard' for this return value.
571 spin_lock(&pcwd_private
.io_lock
);
572 *temperature
= ((inb(pcwd_private
.io_addr
)) * 9 / 5) + 32;
573 spin_unlock(&pcwd_private
.io_lock
);
575 if (debug
>= DEBUG
) {
576 pr_debug("temperature is: %d F\n", *temperature
);
583 * /dev/watchdog handling
586 static long pcwd_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
592 int __user
*argp
= (int __user
*)arg
;
593 static const struct watchdog_info ident
= {
594 .options
= WDIOF_OVERHEAT
|
596 WDIOF_KEEPALIVEPING
|
599 .firmware_version
= 1,
604 case WDIOC_GETSUPPORT
:
605 if (copy_to_user(argp
, &ident
, sizeof(ident
)))
609 case WDIOC_GETSTATUS
:
610 pcwd_get_status(&status
);
611 return put_user(status
, argp
);
613 case WDIOC_GETBOOTSTATUS
:
614 return put_user(pcwd_private
.boot_status
, argp
);
617 if (pcwd_get_temperature(&temperature
))
620 return put_user(temperature
, argp
);
622 case WDIOC_SETOPTIONS
:
623 if (pcwd_private
.revision
== PCWD_REVISION_C
) {
624 if (get_user(rv
, argp
))
627 if (rv
& WDIOS_DISABLECARD
) {
628 status
= pcwd_stop();
632 if (rv
& WDIOS_ENABLECARD
) {
633 status
= pcwd_start();
637 if (rv
& WDIOS_TEMPPANIC
)
642 case WDIOC_KEEPALIVE
:
646 case WDIOC_SETTIMEOUT
:
647 if (get_user(new_heartbeat
, argp
))
650 if (pcwd_set_heartbeat(new_heartbeat
))
656 case WDIOC_GETTIMEOUT
:
657 return put_user(heartbeat
, argp
);
666 static ssize_t
pcwd_write(struct file
*file
, const char __user
*buf
, size_t len
,
673 /* In case it was set long ago */
676 for (i
= 0; i
!= len
; i
++) {
679 if (get_user(c
, buf
+ i
))
690 static int pcwd_open(struct inode
*inode
, struct file
*file
)
692 if (test_and_set_bit(0, &open_allowed
))
695 __module_get(THIS_MODULE
);
699 return stream_open(inode
, file
);
702 static int pcwd_close(struct inode
*inode
, struct file
*file
)
704 if (expect_close
== 42)
707 pr_crit("Unexpected close, not stopping watchdog!\n");
711 clear_bit(0, &open_allowed
);
716 * /dev/temperature handling
719 static ssize_t
pcwd_temp_read(struct file
*file
, char __user
*buf
, size_t count
,
724 if (pcwd_get_temperature(&temperature
))
727 if (copy_to_user(buf
, &temperature
, 1))
733 static int pcwd_temp_open(struct inode
*inode
, struct file
*file
)
735 if (!pcwd_private
.supports_temp
)
738 return stream_open(inode
, file
);
741 static int pcwd_temp_close(struct inode
*inode
, struct file
*file
)
750 static const struct file_operations pcwd_fops
= {
751 .owner
= THIS_MODULE
,
754 .unlocked_ioctl
= pcwd_ioctl
,
755 .compat_ioctl
= compat_ptr_ioctl
,
757 .release
= pcwd_close
,
760 static struct miscdevice pcwd_miscdev
= {
761 .minor
= WATCHDOG_MINOR
,
766 static const struct file_operations pcwd_temp_fops
= {
767 .owner
= THIS_MODULE
,
769 .read
= pcwd_temp_read
,
770 .open
= pcwd_temp_open
,
771 .release
= pcwd_temp_close
,
774 static struct miscdevice temp_miscdev
= {
776 .name
= "temperature",
777 .fops
= &pcwd_temp_fops
,
781 * Init & exit routines
784 static inline int get_revision(void)
786 int r
= PCWD_REVISION_C
;
788 spin_lock(&pcwd_private
.io_lock
);
789 /* REV A cards use only 2 io ports; test
790 * presumes a floating bus reads as 0xff. */
791 if ((inb(pcwd_private
.io_addr
+ 2) == 0xFF) ||
792 (inb(pcwd_private
.io_addr
+ 3) == 0xFF))
794 spin_unlock(&pcwd_private
.io_lock
);
800 * The ISA cards have a heartbeat bit in one of the registers, which
801 * register is card dependent. The heartbeat bit is monitored, and if
802 * found, is considered proof that a Berkshire card has been found.
803 * The initial rate is once per second at board start up, then twice
804 * per second for normal operation.
806 static int pcwd_isa_match(struct device
*dev
, unsigned int id
)
808 int base_addr
= pcwd_ioports
[id
];
809 int port0
, last_port0
; /* Reg 0, in case it's REV A */
810 int port1
, last_port1
; /* Register 1 for REV C cards */
815 pr_debug("pcwd_isa_match id=%d\n", id
);
817 if (!request_region(base_addr
, 4, "PCWD")) {
818 pr_info("Port 0x%04x unavailable\n", base_addr
);
824 port0
= inb_p(base_addr
); /* For REV A boards */
825 port1
= inb_p(base_addr
+ 1); /* For REV C boards */
826 if (port0
!= 0xff || port1
!= 0xff) {
827 /* Not an 'ff' from a floating bus, so must be a card! */
828 for (i
= 0; i
< 4; ++i
) {
835 port0
= inb_p(base_addr
);
836 port1
= inb_p(base_addr
+ 1);
838 /* Has either hearbeat bit changed? */
839 if ((port0
^ last_port0
) & WD_HRTBT
||
840 (port1
^ last_port1
) & WD_REVC_HRBT
) {
846 release_region(base_addr
, 4);
851 static int pcwd_isa_probe(struct device
*dev
, unsigned int id
)
856 pr_debug("pcwd_isa_probe id=%d\n", id
);
859 if (cards_found
== 1)
860 pr_info("v%s Ken Hollis (kenji@bitgate.com)\n",
863 if (cards_found
> 1) {
864 pr_err("This driver only supports 1 device\n");
868 if (pcwd_ioports
[id
] == 0x0000) {
869 pr_err("No I/O-Address for card detected\n");
872 pcwd_private
.io_addr
= pcwd_ioports
[id
];
874 spin_lock_init(&pcwd_private
.io_lock
);
876 /* Check card's revision */
877 pcwd_private
.revision
= get_revision();
879 if (!request_region(pcwd_private
.io_addr
,
880 (pcwd_private
.revision
== PCWD_REVISION_A
) ? 2 : 4, "PCWD")) {
881 pr_err("I/O address 0x%04x already in use\n",
882 pcwd_private
.io_addr
);
884 goto error_request_region
;
887 /* Initial variables */
888 pcwd_private
.supports_temp
= 0;
890 pcwd_private
.boot_status
= 0x0000;
892 /* get the boot_status */
893 pcwd_get_status(&pcwd_private
.boot_status
);
895 /* clear the "card caused reboot" flag */
898 timer_setup(&pcwd_private
.timer
, pcwd_timer_ping
, 0);
900 /* Disable the board */
903 /* Check whether or not the card supports the temperature device */
904 pcwd_check_temperature_support();
906 /* Show info about the card itself */
907 pcwd_show_card_info();
909 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */
911 heartbeat
= heartbeat_tbl
[(pcwd_get_option_switches() & 0x07)];
913 /* Check that the heartbeat value is within it's range;
914 if not reset to the default */
915 if (pcwd_set_heartbeat(heartbeat
)) {
916 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT
);
917 pr_info("heartbeat value must be 2 <= heartbeat <= 7200, using %d\n",
921 if (pcwd_private
.supports_temp
) {
922 ret
= misc_register(&temp_miscdev
);
924 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
926 goto error_misc_register_temp
;
930 ret
= misc_register(&pcwd_miscdev
);
932 pr_err("cannot register miscdev on minor=%d (err=%d)\n",
933 WATCHDOG_MINOR
, ret
);
934 goto error_misc_register_watchdog
;
937 pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n",
938 heartbeat
, nowayout
);
942 error_misc_register_watchdog
:
943 if (pcwd_private
.supports_temp
)
944 misc_deregister(&temp_miscdev
);
945 error_misc_register_temp
:
946 release_region(pcwd_private
.io_addr
,
947 (pcwd_private
.revision
== PCWD_REVISION_A
) ? 2 : 4);
948 error_request_region
:
949 pcwd_private
.io_addr
= 0x0000;
954 static int pcwd_isa_remove(struct device
*dev
, unsigned int id
)
957 pr_debug("pcwd_isa_remove id=%d\n", id
);
959 if (!pcwd_private
.io_addr
)
962 /* Disable the board */
967 misc_deregister(&pcwd_miscdev
);
968 if (pcwd_private
.supports_temp
)
969 misc_deregister(&temp_miscdev
);
970 release_region(pcwd_private
.io_addr
,
971 (pcwd_private
.revision
== PCWD_REVISION_A
) ? 2 : 4);
972 pcwd_private
.io_addr
= 0x0000;
978 static void pcwd_isa_shutdown(struct device
*dev
, unsigned int id
)
981 pr_debug("pcwd_isa_shutdown id=%d\n", id
);
986 static struct isa_driver pcwd_isa_driver
= {
987 .match
= pcwd_isa_match
,
988 .probe
= pcwd_isa_probe
,
989 .remove
= pcwd_isa_remove
,
990 .shutdown
= pcwd_isa_shutdown
,
992 .owner
= THIS_MODULE
,
993 .name
= WATCHDOG_NAME
,
997 module_isa_driver(pcwd_isa_driver
, PCWD_ISA_NR_CARDS
);
999 MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, "
1000 "Wim Van Sebroeck <wim@iguana.be>");
1001 MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
1002 MODULE_VERSION(WATCHDOG_VERSION
);
1003 MODULE_LICENSE("GPL");