| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * PC Watchdog Driver | 
|  | 3 | * by Ken Hollis (khollis@bitgate.com) | 
|  | 4 | * | 
| Wim Van Sebroeck | f9146f2 | 2007-01-09 22:38:54 +0100 | [diff] [blame] | 5 | * Permission granted from Simon Machell (smachell@berkprod.com) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 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 */ | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 62 | #include <linux/reboot.h>	/* For kernel_power_off() */ | 
| Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 63 | #include <linux/init.h>		/* For __init/__exit/... */ | 
|  | 64 | #include <linux/fs.h>		/* For file operations */ | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 65 | #include <linux/isa.h>		/* For isa devices */ | 
| Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 66 | #include <linux/ioport.h>	/* For io-port access */ | 
|  | 67 | #include <linux/spinlock.h>	/* For spin_lock/spin_unlock/... */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 |  | 
| Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 69 | #include <asm/uaccess.h>	/* For copy_to_user/put_user/... */ | 
|  | 70 | #include <asm/io.h>		/* For inb/outb/... */ | 
|  | 71 |  | 
|  | 72 | /* Module and version information */ | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 73 | #define WATCHDOG_VERSION "1.20" | 
|  | 74 | #define WATCHDOG_DATE "18 Feb 2007" | 
| Wim Van Sebroeck | a7122f9 | 2006-01-09 22:07:22 +0100 | [diff] [blame] | 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 ")" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 |  | 
|  | 81 | /* | 
|  | 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.) | 
|  | 87 | */ | 
|  | 88 | #define	PCWD_REVISION_A		1 | 
|  | 89 | #define	PCWD_REVISION_C		2 | 
|  | 90 |  | 
|  | 91 | /* | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 92 | * These are the auto-probe addresses available. | 
|  | 93 | * | 
|  | 94 | * Revision A only uses ports 0x270 and 0x370.  Revision C introduced 0x350. | 
|  | 95 | * Revision A has an address range of 2 addresses, while Revision C has 4. | 
|  | 96 | */ | 
|  | 97 | #define PCWD_ISA_NR_CARDS	3 | 
|  | 98 | static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 }; | 
|  | 99 |  | 
|  | 100 | /* | 
| Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 101 | * These are the defines that describe the control status bits for the | 
|  | 102 | * PCI-PC Watchdog card. | 
|  | 103 | */ | 
|  | 104 | /* Port 1 : Control Status #1 for the PC Watchdog card, revision A. */ | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 105 | #define WD_WDRST		0x01	/* Previously reset state */ | 
|  | 106 | #define WD_T110			0x02	/* Temperature overheat sense */ | 
|  | 107 | #define WD_HRTBT		0x04	/* Heartbeat sense */ | 
|  | 108 | #define WD_RLY2			0x08	/* External relay triggered */ | 
|  | 109 | #define WD_SRLY2		0x80	/* Software external relay triggered */ | 
| Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 110 | /* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */ | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 111 | #define WD_REVC_WTRP		0x01	/* Watchdog Trip status */ | 
|  | 112 | #define WD_REVC_HRBT		0x02	/* Watchdog Heartbeat */ | 
|  | 113 | #define WD_REVC_TTRP		0x04	/* Temperature Trip status */ | 
|  | 114 | #define WD_REVC_RL2A		0x08	/* Relay 2 activated by on-board processor */ | 
|  | 115 | #define WD_REVC_RL1A		0x10	/* Relay 1 active */ | 
|  | 116 | #define WD_REVC_R2DS		0x40	/* Relay 2 disable */ | 
|  | 117 | #define WD_REVC_RLY2		0x80	/* Relay 2 activated? */ | 
| Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 118 | /* Port 2 : Control Status #2 */ | 
|  | 119 | #define WD_WDIS			0x10	/* Watchdog Disabled */ | 
|  | 120 | #define WD_ENTP			0x20	/* Watchdog Enable Temperature Trip */ | 
|  | 121 | #define WD_SSEL			0x40	/* Watchdog Switch Select (1:SW1 <-> 0:SW2) */ | 
|  | 122 | #define WD_WCMD			0x80	/* Watchdog Command Mode */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 |  | 
|  | 124 | /* max. time we give an ISA watchdog card to process a command */ | 
|  | 125 | /* 500ms for each 4 bit response (according to spec.) */ | 
|  | 126 | #define ISA_COMMAND_TIMEOUT     1000 | 
|  | 127 |  | 
|  | 128 | /* Watchdog's internal commands */ | 
| Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 129 | #define CMD_ISA_IDLE			0x00 | 
|  | 130 | #define CMD_ISA_VERSION_INTEGER		0x01 | 
|  | 131 | #define CMD_ISA_VERSION_TENTH		0x02 | 
|  | 132 | #define CMD_ISA_VERSION_HUNDRETH	0x03 | 
|  | 133 | #define CMD_ISA_VERSION_MINOR		0x04 | 
|  | 134 | #define CMD_ISA_SWITCH_SETTINGS		0x05 | 
| Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 135 | #define CMD_ISA_RESET_PC		0x06 | 
|  | 136 | #define CMD_ISA_ARM_0			0x07 | 
|  | 137 | #define CMD_ISA_ARM_30			0x08 | 
|  | 138 | #define CMD_ISA_ARM_60			0x09 | 
| Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 139 | #define CMD_ISA_DELAY_TIME_2SECS	0x0A | 
|  | 140 | #define CMD_ISA_DELAY_TIME_4SECS	0x0B | 
|  | 141 | #define CMD_ISA_DELAY_TIME_8SECS	0x0C | 
| Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 142 | #define CMD_ISA_RESET_RELAYS		0x0D | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 |  | 
| Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 144 | /* Watchdog's Dip Switch heartbeat values */ | 
|  | 145 | static const int heartbeat_tbl [] = { | 
|  | 146 | 20,	/* OFF-OFF-OFF	= 20 Sec  */ | 
|  | 147 | 40,	/* OFF-OFF-ON	= 40 Sec  */ | 
|  | 148 | 60,	/* OFF-ON-OFF	=  1 Min  */ | 
|  | 149 | 300,	/* OFF-ON-ON	=  5 Min  */ | 
|  | 150 | 600,	/* ON-OFF-OFF	= 10 Min  */ | 
|  | 151 | 1800,	/* ON-OFF-ON	= 30 Min  */ | 
|  | 152 | 3600,	/* ON-ON-OFF	=  1 Hour */ | 
|  | 153 | 7200,	/* ON-ON-ON	=  2 hour */ | 
|  | 154 | }; | 
|  | 155 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* | 
|  | 157 | * We are using an kernel timer to do the pinging of the watchdog | 
|  | 158 | * every ~500ms. We try to set the internal heartbeat of the | 
|  | 159 | * watchdog to 2 ms. | 
|  | 160 | */ | 
|  | 161 |  | 
|  | 162 | #define WDT_INTERVAL (HZ/2+1) | 
|  | 163 |  | 
|  | 164 | /* We can only use 1 card due to the /dev/watchdog restriction */ | 
|  | 165 | static int cards_found; | 
|  | 166 |  | 
|  | 167 | /* internal variables */ | 
|  | 168 | static atomic_t open_allowed = ATOMIC_INIT(1); | 
|  | 169 | static char expect_close; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | static int temp_panic; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 171 | static struct {				/* this is private data for each ISA-PC watchdog card */ | 
| Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 172 | char fw_ver_str[6];		/* The cards firmware version */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 173 | int revision;			/* The card's revision */ | 
|  | 174 | int supports_temp;		/* Wether or not the card has a temperature device */ | 
|  | 175 | int command_mode;		/* Wether or not the card is in command mode */ | 
|  | 176 | int boot_status;		/* The card's boot status */ | 
|  | 177 | int io_addr;			/* The cards I/O address */ | 
|  | 178 | spinlock_t io_lock;		/* the lock for io operations */ | 
|  | 179 | struct timer_list timer;	/* The timer that pings the watchdog */ | 
|  | 180 | unsigned long next_heartbeat;	/* the next_heartbeat for the timer */ | 
|  | 181 | } pcwd_private; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 |  | 
|  | 183 | /* module parameters */ | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 184 | #define QUIET	0	/* Default */ | 
|  | 185 | #define VERBOSE	1	/* Verbose */ | 
|  | 186 | #define DEBUG	2	/* print fancy stuff too */ | 
|  | 187 | static int debug = QUIET; | 
|  | 188 | module_param(debug, int, 0); | 
|  | 189 | MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)"); | 
|  | 190 |  | 
| Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 191 | #define WATCHDOG_HEARTBEAT 0		/* default heartbeat = delay-time from dip-switches */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | static int heartbeat = WATCHDOG_HEARTBEAT; | 
|  | 193 | module_param(heartbeat, int, 0); | 
| Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 194 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 |  | 
| Andrey Panin | 4bfdf37 | 2005-07-27 11:43:58 -0700 | [diff] [blame] | 196 | static int nowayout = WATCHDOG_NOWAYOUT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | module_param(nowayout, int, 0); | 
| Wim Van Sebroeck | bffda5c | 2007-01-27 20:54:24 +0100 | [diff] [blame] | 198 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
|  | 200 | /* | 
|  | 201 | *	Internal functions | 
|  | 202 | */ | 
|  | 203 |  | 
|  | 204 | static int send_isa_command(int cmd) | 
|  | 205 | { | 
|  | 206 | int i; | 
|  | 207 | int control_status; | 
|  | 208 | int port0, last_port0;	/* Double read for stabilising */ | 
|  | 209 |  | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 210 | if (debug >= DEBUG) | 
|  | 211 | printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n", | 
|  | 212 | cmd); | 
|  | 213 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | /* The WCMD bit must be 1 and the command is only 4 bits in size */ | 
| Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 215 | control_status = (cmd & 0x0F) | WD_WCMD; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 216 | outb_p(control_status, pcwd_private.io_addr + 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | udelay(ISA_COMMAND_TIMEOUT); | 
|  | 218 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 219 | port0 = inb_p(pcwd_private.io_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | for (i = 0; i < 25; ++i) { | 
|  | 221 | last_port0 = port0; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 222 | port0 = inb_p(pcwd_private.io_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 |  | 
|  | 224 | if (port0 == last_port0) | 
|  | 225 | break;	/* Data is stable */ | 
|  | 226 |  | 
|  | 227 | udelay (250); | 
|  | 228 | } | 
|  | 229 |  | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 230 | if (debug >= DEBUG) | 
|  | 231 | printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n", | 
|  | 232 | cmd, port0, last_port0); | 
|  | 233 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return port0; | 
|  | 235 | } | 
|  | 236 |  | 
|  | 237 | static int set_command_mode(void) | 
|  | 238 | { | 
|  | 239 | int i, found=0, count=0; | 
|  | 240 |  | 
|  | 241 | /* Set the card into command mode */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 242 | spin_lock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | while ((!found) && (count < 3)) { | 
|  | 244 | i = send_isa_command(CMD_ISA_IDLE); | 
|  | 245 |  | 
|  | 246 | if (i == 0x00) | 
|  | 247 | found = 1; | 
|  | 248 | else if (i == 0xF3) { | 
|  | 249 | /* Card does not like what we've done to it */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 250 | outb_p(0x00, pcwd_private.io_addr + 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | udelay(1200);	/* Spec says wait 1ms */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 252 | outb_p(0x00, pcwd_private.io_addr + 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | udelay(ISA_COMMAND_TIMEOUT); | 
|  | 254 | } | 
|  | 255 | count++; | 
|  | 256 | } | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 257 | spin_unlock(&pcwd_private.io_lock); | 
|  | 258 | pcwd_private.command_mode = found; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 |  | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 260 | if (debug >= DEBUG) | 
|  | 261 | printk(KERN_DEBUG PFX "command_mode=%d\n", | 
|  | 262 | pcwd_private.command_mode); | 
|  | 263 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return(found); | 
|  | 265 | } | 
|  | 266 |  | 
|  | 267 | static void unset_command_mode(void) | 
|  | 268 | { | 
|  | 269 | /* Set the card into normal mode */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 270 | spin_lock(&pcwd_private.io_lock); | 
|  | 271 | outb_p(0x00, pcwd_private.io_addr + 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | udelay(ISA_COMMAND_TIMEOUT); | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 273 | spin_unlock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 275 | pcwd_private.command_mode = 0; | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 276 |  | 
|  | 277 | if (debug >= DEBUG) | 
|  | 278 | printk(KERN_DEBUG PFX "command_mode=%d\n", | 
|  | 279 | pcwd_private.command_mode); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } | 
|  | 281 |  | 
| Wim Van Sebroeck | 8587521 | 2006-01-09 21:59:39 +0100 | [diff] [blame] | 282 | static inline void pcwd_check_temperature_support(void) | 
|  | 283 | { | 
|  | 284 | if (inb(pcwd_private.io_addr) != 0xF0) | 
|  | 285 | pcwd_private.supports_temp = 1; | 
|  | 286 | } | 
|  | 287 |  | 
| Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 288 | static inline void pcwd_get_firmware(void) | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 289 | { | 
|  | 290 | int one, ten, hund, minor; | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 291 |  | 
| Wim Van Sebroeck | 6bbc20b | 2006-03-02 20:05:16 +0100 | [diff] [blame] | 292 | strcpy(pcwd_private.fw_ver_str, "ERROR"); | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 293 |  | 
|  | 294 | if (set_command_mode()) { | 
|  | 295 | one = send_isa_command(CMD_ISA_VERSION_INTEGER); | 
|  | 296 | ten = send_isa_command(CMD_ISA_VERSION_TENTH); | 
|  | 297 | hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH); | 
|  | 298 | minor = send_isa_command(CMD_ISA_VERSION_MINOR); | 
| Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 299 | sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor); | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 300 | } | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 301 | unset_command_mode(); | 
| Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 302 |  | 
|  | 303 | return; | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 304 | } | 
|  | 305 |  | 
|  | 306 | static inline int pcwd_get_option_switches(void) | 
|  | 307 | { | 
|  | 308 | int option_switches=0; | 
|  | 309 |  | 
|  | 310 | if (set_command_mode()) { | 
|  | 311 | /* Get switch settings */ | 
|  | 312 | option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS); | 
|  | 313 | } | 
|  | 314 |  | 
|  | 315 | unset_command_mode(); | 
|  | 316 | return(option_switches); | 
|  | 317 | } | 
|  | 318 |  | 
|  | 319 | static void pcwd_show_card_info(void) | 
|  | 320 | { | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 321 | int option_switches; | 
|  | 322 |  | 
|  | 323 | /* Get some extra info from the hardware (in command/debug/diag mode) */ | 
|  | 324 | if (pcwd_private.revision == PCWD_REVISION_A) | 
|  | 325 | printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr); | 
|  | 326 | else if (pcwd_private.revision == PCWD_REVISION_C) { | 
| Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 327 | pcwd_get_firmware(); | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 328 | printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n", | 
| Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 329 | pcwd_private.io_addr, pcwd_private.fw_ver_str); | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 330 | option_switches = pcwd_get_option_switches(); | 
|  | 331 | printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", | 
|  | 332 | option_switches, | 
|  | 333 | ((option_switches & 0x10) ? "ON" : "OFF"), | 
|  | 334 | ((option_switches & 0x08) ? "ON" : "OFF")); | 
|  | 335 |  | 
|  | 336 | /* Reprogram internal heartbeat to 2 seconds */ | 
|  | 337 | if (set_command_mode()) { | 
|  | 338 | send_isa_command(CMD_ISA_DELAY_TIME_2SECS); | 
|  | 339 | unset_command_mode(); | 
|  | 340 | } | 
|  | 341 | } | 
|  | 342 |  | 
|  | 343 | if (pcwd_private.supports_temp) | 
|  | 344 | printk(KERN_INFO PFX "Temperature Option Detected\n"); | 
|  | 345 |  | 
|  | 346 | if (pcwd_private.boot_status & WDIOF_CARDRESET) | 
|  | 347 | printk(KERN_INFO PFX "Previous reboot was caused by the card\n"); | 
|  | 348 |  | 
|  | 349 | if (pcwd_private.boot_status & WDIOF_OVERHEAT) { | 
|  | 350 | printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n"); | 
|  | 351 | printk(KERN_EMERG PFX "CPU Overheat\n"); | 
|  | 352 | } | 
|  | 353 |  | 
|  | 354 | if (pcwd_private.boot_status == 0) | 
|  | 355 | printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n"); | 
|  | 356 | } | 
|  | 357 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | static void pcwd_timer_ping(unsigned long data) | 
|  | 359 | { | 
|  | 360 | int wdrst_stat; | 
|  | 361 |  | 
|  | 362 | /* If we got a heartbeat pulse within the WDT_INTERVAL | 
|  | 363 | * we agree to ping the WDT */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 364 | if(time_before(jiffies, pcwd_private.next_heartbeat)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | /* Ping the watchdog */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 366 | spin_lock(&pcwd_private.io_lock); | 
|  | 367 | if (pcwd_private.revision == PCWD_REVISION_A) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | /*  Rev A cards are reset by setting the WD_WDRST bit in register 1 */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 369 | wdrst_stat = inb_p(pcwd_private.io_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | wdrst_stat &= 0x0F; | 
|  | 371 | wdrst_stat |= WD_WDRST; | 
|  | 372 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 373 | outb_p(wdrst_stat, pcwd_private.io_addr + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } else { | 
|  | 375 | /* Re-trigger watchdog by writing to port 0 */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 376 | outb_p(0x00, pcwd_private.io_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } | 
|  | 378 |  | 
|  | 379 | /* Re-set the timer interval */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 380 | mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 382 | spin_unlock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } else { | 
|  | 384 | printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n"); | 
|  | 385 | } | 
|  | 386 | } | 
|  | 387 |  | 
|  | 388 | static int pcwd_start(void) | 
|  | 389 | { | 
|  | 390 | int stat_reg; | 
|  | 391 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 392 | pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 |  | 
|  | 394 | /* Start the timer */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 395 | mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 |  | 
|  | 397 | /* Enable the port */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 398 | if (pcwd_private.revision == PCWD_REVISION_C) { | 
|  | 399 | spin_lock(&pcwd_private.io_lock); | 
|  | 400 | outb_p(0x00, pcwd_private.io_addr + 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | udelay(ISA_COMMAND_TIMEOUT); | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 402 | stat_reg = inb_p(pcwd_private.io_addr + 2); | 
|  | 403 | spin_unlock(&pcwd_private.io_lock); | 
| Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 404 | if (stat_reg & WD_WDIS) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | printk(KERN_INFO PFX "Could not start watchdog\n"); | 
|  | 406 | return -EIO; | 
|  | 407 | } | 
|  | 408 | } | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 409 |  | 
|  | 410 | if (debug >= VERBOSE) | 
|  | 411 | printk(KERN_DEBUG PFX "Watchdog started\n"); | 
|  | 412 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | return 0; | 
|  | 414 | } | 
|  | 415 |  | 
|  | 416 | static int pcwd_stop(void) | 
|  | 417 | { | 
|  | 418 | int stat_reg; | 
|  | 419 |  | 
|  | 420 | /* Stop the timer */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 421 | del_timer(&pcwd_private.timer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 |  | 
|  | 423 | /*  Disable the board  */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 424 | if (pcwd_private.revision == PCWD_REVISION_C) { | 
|  | 425 | spin_lock(&pcwd_private.io_lock); | 
|  | 426 | outb_p(0xA5, pcwd_private.io_addr + 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | udelay(ISA_COMMAND_TIMEOUT); | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 428 | outb_p(0xA5, pcwd_private.io_addr + 3); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | udelay(ISA_COMMAND_TIMEOUT); | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 430 | stat_reg = inb_p(pcwd_private.io_addr + 2); | 
|  | 431 | spin_unlock(&pcwd_private.io_lock); | 
| Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 432 | if ((stat_reg & WD_WDIS) == 0) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | printk(KERN_INFO PFX "Could not stop watchdog\n"); | 
|  | 434 | return -EIO; | 
|  | 435 | } | 
|  | 436 | } | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 437 |  | 
|  | 438 | if (debug >= VERBOSE) | 
|  | 439 | printk(KERN_DEBUG PFX "Watchdog stopped\n"); | 
|  | 440 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | return 0; | 
|  | 442 | } | 
|  | 443 |  | 
|  | 444 | static int pcwd_keepalive(void) | 
|  | 445 | { | 
|  | 446 | /* user land ping */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 447 | pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 448 |  | 
|  | 449 | if (debug >= DEBUG) | 
|  | 450 | printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n"); | 
|  | 451 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return 0; | 
|  | 453 | } | 
|  | 454 |  | 
|  | 455 | static int pcwd_set_heartbeat(int t) | 
|  | 456 | { | 
|  | 457 | if ((t < 2) || (t > 7200)) /* arbitrary upper limit */ | 
|  | 458 | return -EINVAL; | 
|  | 459 |  | 
|  | 460 | heartbeat = t; | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 461 |  | 
|  | 462 | if (debug >= VERBOSE) | 
|  | 463 | printk(KERN_DEBUG PFX "New heartbeat: %d\n", | 
|  | 464 | heartbeat); | 
|  | 465 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 0; | 
|  | 467 | } | 
|  | 468 |  | 
|  | 469 | static int pcwd_get_status(int *status) | 
|  | 470 | { | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 471 | int control_status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 |  | 
|  | 473 | *status=0; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 474 | spin_lock(&pcwd_private.io_lock); | 
|  | 475 | if (pcwd_private.revision == PCWD_REVISION_A) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | /* Rev A cards return status information from | 
|  | 477 | * the base register, which is used for the | 
|  | 478 | * temperature in other cards. */ | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 479 | control_status = inb(pcwd_private.io_addr); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | else { | 
|  | 481 | /* Rev C cards return card status in the base | 
|  | 482 | * address + 1 register. And use different bits | 
|  | 483 | * to indicate a card initiated reset, and an | 
|  | 484 | * over-temperature condition. And the reboot | 
|  | 485 | * status can be reset. */ | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 486 | control_status = inb(pcwd_private.io_addr + 1); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 488 | spin_unlock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 490 | if (pcwd_private.revision == PCWD_REVISION_A) { | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 491 | if (control_status & WD_WDRST) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | *status |= WDIOF_CARDRESET; | 
|  | 493 |  | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 494 | if (control_status & WD_T110) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | *status |= WDIOF_OVERHEAT; | 
|  | 496 | if (temp_panic) { | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 497 | printk(KERN_INFO PFX "Temperature overheat trip!\n"); | 
| Eric W. Biederman | 68acc05 | 2005-07-26 12:03:08 -0600 | [diff] [blame] | 498 | kernel_power_off(); | 
| Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 499 | /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } | 
|  | 501 | } | 
|  | 502 | } else { | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 503 | if (control_status & WD_REVC_WTRP) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | *status |= WDIOF_CARDRESET; | 
|  | 505 |  | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 506 | if (control_status & WD_REVC_TTRP) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | *status |= WDIOF_OVERHEAT; | 
|  | 508 | if (temp_panic) { | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 509 | printk(KERN_INFO PFX "Temperature overheat trip!\n"); | 
| Eric W. Biederman | 68acc05 | 2005-07-26 12:03:08 -0600 | [diff] [blame] | 510 | kernel_power_off(); | 
| Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 511 | /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } | 
|  | 513 | } | 
|  | 514 | } | 
|  | 515 |  | 
|  | 516 | return 0; | 
|  | 517 | } | 
|  | 518 |  | 
|  | 519 | static int pcwd_clear_status(void) | 
|  | 520 | { | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 521 | int control_status; | 
|  | 522 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 523 | if (pcwd_private.revision == PCWD_REVISION_C) { | 
|  | 524 | spin_lock(&pcwd_private.io_lock); | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 525 |  | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 526 | if (debug >= VERBOSE) | 
|  | 527 | printk(KERN_INFO PFX "clearing watchdog trip status\n"); | 
|  | 528 |  | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 529 | control_status = inb_p(pcwd_private.io_addr + 1); | 
|  | 530 |  | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 531 | if (debug >= DEBUG) { | 
|  | 532 | printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status); | 
|  | 533 | printk(KERN_DEBUG PFX "sending: 0x%02x\n", | 
|  | 534 | (control_status & WD_REVC_R2DS)); | 
|  | 535 | } | 
|  | 536 |  | 
| Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 537 | /* clear reset status & Keep Relay 2 disable state as it is */ | 
|  | 538 | outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1); | 
|  | 539 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 540 | spin_unlock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } | 
|  | 542 | return 0; | 
|  | 543 | } | 
|  | 544 |  | 
|  | 545 | static int pcwd_get_temperature(int *temperature) | 
|  | 546 | { | 
|  | 547 | /* check that port 0 gives temperature info and no command results */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 548 | if (pcwd_private.command_mode) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | return -1; | 
|  | 550 |  | 
|  | 551 | *temperature = 0; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 552 | if (!pcwd_private.supports_temp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | return -ENODEV; | 
|  | 554 |  | 
|  | 555 | /* | 
|  | 556 | * Convert celsius to fahrenheit, since this was | 
|  | 557 | * the decided 'standard' for this return value. | 
|  | 558 | */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 559 | spin_lock(&pcwd_private.io_lock); | 
|  | 560 | *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32; | 
|  | 561 | spin_unlock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 |  | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 563 | if (debug >= DEBUG) { | 
|  | 564 | printk(KERN_DEBUG PFX "temperature is: %d F\n", | 
|  | 565 | *temperature); | 
|  | 566 | } | 
|  | 567 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | return 0; | 
|  | 569 | } | 
|  | 570 |  | 
|  | 571 | /* | 
|  | 572 | *	/dev/watchdog handling | 
|  | 573 | */ | 
|  | 574 |  | 
|  | 575 | static int pcwd_ioctl(struct inode *inode, struct file *file, | 
|  | 576 | unsigned int cmd, unsigned long arg) | 
|  | 577 | { | 
|  | 578 | int rv; | 
|  | 579 | int status; | 
|  | 580 | int temperature; | 
|  | 581 | int new_heartbeat; | 
|  | 582 | int __user *argp = (int __user *)arg; | 
|  | 583 | static struct watchdog_info ident = { | 
|  | 584 | .options =		WDIOF_OVERHEAT | | 
|  | 585 | WDIOF_CARDRESET | | 
|  | 586 | WDIOF_KEEPALIVEPING | | 
|  | 587 | WDIOF_SETTIMEOUT | | 
|  | 588 | WDIOF_MAGICCLOSE, | 
|  | 589 | .firmware_version =	1, | 
|  | 590 | .identity =		"PCWD", | 
|  | 591 | }; | 
|  | 592 |  | 
|  | 593 | switch(cmd) { | 
|  | 594 | default: | 
| Samuel Tardieu | 795b89d | 2006-09-09 17:34:31 +0200 | [diff] [blame] | 595 | return -ENOTTY; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 |  | 
|  | 597 | case WDIOC_GETSUPPORT: | 
|  | 598 | if(copy_to_user(argp, &ident, sizeof(ident))) | 
|  | 599 | return -EFAULT; | 
|  | 600 | return 0; | 
|  | 601 |  | 
|  | 602 | case WDIOC_GETSTATUS: | 
|  | 603 | pcwd_get_status(&status); | 
|  | 604 | return put_user(status, argp); | 
|  | 605 |  | 
|  | 606 | case WDIOC_GETBOOTSTATUS: | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 607 | return put_user(pcwd_private.boot_status, argp); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 |  | 
|  | 609 | case WDIOC_GETTEMP: | 
|  | 610 | if (pcwd_get_temperature(&temperature)) | 
|  | 611 | return -EFAULT; | 
|  | 612 |  | 
|  | 613 | return put_user(temperature, argp); | 
|  | 614 |  | 
|  | 615 | case WDIOC_SETOPTIONS: | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 616 | if (pcwd_private.revision == PCWD_REVISION_C) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { | 
|  | 618 | if(copy_from_user(&rv, argp, sizeof(int))) | 
|  | 619 | return -EFAULT; | 
|  | 620 |  | 
|  | 621 | if (rv & WDIOS_DISABLECARD) | 
|  | 622 | { | 
|  | 623 | return pcwd_stop(); | 
|  | 624 | } | 
|  | 625 |  | 
|  | 626 | if (rv & WDIOS_ENABLECARD) | 
|  | 627 | { | 
|  | 628 | return pcwd_start(); | 
|  | 629 | } | 
|  | 630 |  | 
|  | 631 | if (rv & WDIOS_TEMPPANIC) | 
|  | 632 | { | 
|  | 633 | temp_panic = 1; | 
|  | 634 | } | 
|  | 635 | } | 
|  | 636 | return -EINVAL; | 
|  | 637 |  | 
|  | 638 | case WDIOC_KEEPALIVE: | 
|  | 639 | pcwd_keepalive(); | 
|  | 640 | return 0; | 
|  | 641 |  | 
|  | 642 | case WDIOC_SETTIMEOUT: | 
|  | 643 | if (get_user(new_heartbeat, argp)) | 
|  | 644 | return -EFAULT; | 
|  | 645 |  | 
|  | 646 | if (pcwd_set_heartbeat(new_heartbeat)) | 
|  | 647 | return -EINVAL; | 
|  | 648 |  | 
|  | 649 | pcwd_keepalive(); | 
|  | 650 | /* Fall */ | 
|  | 651 |  | 
|  | 652 | case WDIOC_GETTIMEOUT: | 
|  | 653 | return put_user(heartbeat, argp); | 
|  | 654 | } | 
|  | 655 |  | 
|  | 656 | return 0; | 
|  | 657 | } | 
|  | 658 |  | 
|  | 659 | static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len, | 
|  | 660 | loff_t *ppos) | 
|  | 661 | { | 
|  | 662 | if (len) { | 
|  | 663 | if (!nowayout) { | 
|  | 664 | size_t i; | 
|  | 665 |  | 
|  | 666 | /* In case it was set long ago */ | 
|  | 667 | expect_close = 0; | 
|  | 668 |  | 
|  | 669 | for (i = 0; i != len; i++) { | 
|  | 670 | char c; | 
|  | 671 |  | 
|  | 672 | if (get_user(c, buf + i)) | 
|  | 673 | return -EFAULT; | 
|  | 674 | if (c == 'V') | 
|  | 675 | expect_close = 42; | 
|  | 676 | } | 
|  | 677 | } | 
|  | 678 | pcwd_keepalive(); | 
|  | 679 | } | 
|  | 680 | return len; | 
|  | 681 | } | 
|  | 682 |  | 
|  | 683 | static int pcwd_open(struct inode *inode, struct file *file) | 
|  | 684 | { | 
|  | 685 | if (!atomic_dec_and_test(&open_allowed) ) { | 
| Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 686 | if (debug >= VERBOSE) | 
|  | 687 | printk(KERN_ERR PFX "Attempt to open already opened device.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | atomic_inc( &open_allowed ); | 
|  | 689 | return -EBUSY; | 
|  | 690 | } | 
|  | 691 |  | 
|  | 692 | if (nowayout) | 
|  | 693 | __module_get(THIS_MODULE); | 
|  | 694 |  | 
|  | 695 | /* Activate */ | 
|  | 696 | pcwd_start(); | 
|  | 697 | pcwd_keepalive(); | 
|  | 698 | return nonseekable_open(inode, file); | 
|  | 699 | } | 
|  | 700 |  | 
|  | 701 | static int pcwd_close(struct inode *inode, struct file *file) | 
|  | 702 | { | 
|  | 703 | if (expect_close == 42) { | 
|  | 704 | pcwd_stop(); | 
|  | 705 | } else { | 
|  | 706 | printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n"); | 
|  | 707 | pcwd_keepalive(); | 
|  | 708 | } | 
|  | 709 | expect_close = 0; | 
|  | 710 | atomic_inc( &open_allowed ); | 
|  | 711 | return 0; | 
|  | 712 | } | 
|  | 713 |  | 
|  | 714 | /* | 
|  | 715 | *	/dev/temperature handling | 
|  | 716 | */ | 
|  | 717 |  | 
|  | 718 | static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count, | 
|  | 719 | loff_t *ppos) | 
|  | 720 | { | 
|  | 721 | int temperature; | 
|  | 722 |  | 
|  | 723 | if (pcwd_get_temperature(&temperature)) | 
|  | 724 | return -EFAULT; | 
|  | 725 |  | 
|  | 726 | if (copy_to_user(buf, &temperature, 1)) | 
|  | 727 | return -EFAULT; | 
|  | 728 |  | 
|  | 729 | return 1; | 
|  | 730 | } | 
|  | 731 |  | 
|  | 732 | static int pcwd_temp_open(struct inode *inode, struct file *file) | 
|  | 733 | { | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 734 | if (!pcwd_private.supports_temp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | return -ENODEV; | 
|  | 736 |  | 
|  | 737 | return nonseekable_open(inode, file); | 
|  | 738 | } | 
|  | 739 |  | 
|  | 740 | static int pcwd_temp_close(struct inode *inode, struct file *file) | 
|  | 741 | { | 
|  | 742 | return 0; | 
|  | 743 | } | 
|  | 744 |  | 
|  | 745 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | *	Kernel Interfaces | 
|  | 747 | */ | 
|  | 748 |  | 
| Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 749 | static const struct file_operations pcwd_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | .owner		= THIS_MODULE, | 
|  | 751 | .llseek		= no_llseek, | 
|  | 752 | .write		= pcwd_write, | 
|  | 753 | .ioctl		= pcwd_ioctl, | 
|  | 754 | .open		= pcwd_open, | 
|  | 755 | .release	= pcwd_close, | 
|  | 756 | }; | 
|  | 757 |  | 
|  | 758 | static struct miscdevice pcwd_miscdev = { | 
|  | 759 | .minor =	WATCHDOG_MINOR, | 
|  | 760 | .name =		"watchdog", | 
|  | 761 | .fops =		&pcwd_fops, | 
|  | 762 | }; | 
|  | 763 |  | 
| Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 764 | static const struct file_operations pcwd_temp_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | .owner		= THIS_MODULE, | 
|  | 766 | .llseek		= no_llseek, | 
|  | 767 | .read		= pcwd_temp_read, | 
|  | 768 | .open		= pcwd_temp_open, | 
|  | 769 | .release	= pcwd_temp_close, | 
|  | 770 | }; | 
|  | 771 |  | 
|  | 772 | static struct miscdevice temp_miscdev = { | 
|  | 773 | .minor =	TEMP_MINOR, | 
|  | 774 | .name =		"temperature", | 
|  | 775 | .fops =		&pcwd_temp_fops, | 
|  | 776 | }; | 
|  | 777 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | /* | 
|  | 779 | *	Init & exit routines | 
|  | 780 | */ | 
|  | 781 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | static inline int get_revision(void) | 
|  | 783 | { | 
|  | 784 | int r = PCWD_REVISION_C; | 
|  | 785 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 786 | spin_lock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | /* REV A cards use only 2 io ports; test | 
|  | 788 | * presumes a floating bus reads as 0xff. */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 789 | if ((inb(pcwd_private.io_addr + 2) == 0xFF) || | 
|  | 790 | (inb(pcwd_private.io_addr + 3) == 0xFF)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | r=PCWD_REVISION_A; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 792 | spin_unlock(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 |  | 
|  | 794 | return r; | 
|  | 795 | } | 
|  | 796 |  | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 797 | /* | 
|  | 798 | *  The ISA cards have a heartbeat bit in one of the registers, which | 
|  | 799 | *  register is card dependent.  The heartbeat bit is monitored, and if | 
|  | 800 | *  found, is considered proof that a Berkshire card has been found. | 
|  | 801 | *  The initial rate is once per second at board start up, then twice | 
|  | 802 | *  per second for normal operation. | 
|  | 803 | */ | 
|  | 804 | static int __devinit pcwd_isa_match(struct device *dev, unsigned int id) | 
|  | 805 | { | 
|  | 806 | int base_addr=pcwd_ioports[id]; | 
|  | 807 | int port0, last_port0;	/* Reg 0, in case it's REV A */ | 
|  | 808 | int port1, last_port1;	/* Register 1 for REV C cards */ | 
|  | 809 | int i; | 
|  | 810 | int retval; | 
|  | 811 |  | 
|  | 812 | if (debug >= DEBUG) | 
|  | 813 | printk(KERN_DEBUG PFX "pcwd_isa_match id=%d\n", | 
|  | 814 | id); | 
|  | 815 |  | 
|  | 816 | if (!request_region (base_addr, 4, "PCWD")) { | 
|  | 817 | printk(KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr); | 
|  | 818 | return 0; | 
|  | 819 | } | 
|  | 820 |  | 
|  | 821 | retval = 0; | 
|  | 822 |  | 
|  | 823 | port0 = inb_p(base_addr);	/* For REV A boards */ | 
|  | 824 | port1 = inb_p(base_addr + 1);	/* For REV C boards */ | 
|  | 825 | if (port0 != 0xff || port1 != 0xff) { | 
|  | 826 | /* Not an 'ff' from a floating bus, so must be a card! */ | 
|  | 827 | for (i = 0; i < 4; ++i) { | 
|  | 828 |  | 
|  | 829 | msleep(500); | 
|  | 830 |  | 
|  | 831 | last_port0 = port0; | 
|  | 832 | last_port1 = port1; | 
|  | 833 |  | 
|  | 834 | port0 = inb_p(base_addr); | 
|  | 835 | port1 = inb_p(base_addr + 1); | 
|  | 836 |  | 
|  | 837 | /* Has either hearbeat bit changed?  */ | 
|  | 838 | if ((port0 ^ last_port0) & WD_HRTBT || | 
|  | 839 | (port1 ^ last_port1) & WD_REVC_HRBT) { | 
|  | 840 | retval = 1; | 
|  | 841 | break; | 
|  | 842 | } | 
|  | 843 | } | 
|  | 844 | } | 
|  | 845 | release_region (base_addr, 4); | 
|  | 846 |  | 
|  | 847 | return retval; | 
|  | 848 | } | 
|  | 849 |  | 
|  | 850 | static int __devinit pcwd_isa_probe(struct device *dev, unsigned int id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { | 
|  | 852 | int ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 |  | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 854 | if (debug >= DEBUG) | 
|  | 855 | printk(KERN_DEBUG PFX "pcwd_isa_probe id=%d\n", | 
|  | 856 | id); | 
|  | 857 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | cards_found++; | 
|  | 859 | if (cards_found == 1) | 
|  | 860 | printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER); | 
|  | 861 |  | 
|  | 862 | if (cards_found > 1) { | 
|  | 863 | printk(KERN_ERR PFX "This driver only supports 1 device\n"); | 
|  | 864 | return -ENODEV; | 
|  | 865 | } | 
|  | 866 |  | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 867 | if (pcwd_ioports[id] == 0x0000) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | printk(KERN_ERR PFX "No I/O-Address for card detected\n"); | 
|  | 869 | return -ENODEV; | 
|  | 870 | } | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 871 | pcwd_private.io_addr = pcwd_ioports[id]; | 
|  | 872 |  | 
|  | 873 | spin_lock_init(&pcwd_private.io_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 |  | 
|  | 875 | /* Check card's revision */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 876 | pcwd_private.revision = get_revision(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 878 | if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 880 | pcwd_private.io_addr); | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 881 | ret=-EIO; | 
|  | 882 | goto error_request_region; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } | 
|  | 884 |  | 
|  | 885 | /* Initial variables */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 886 | pcwd_private.supports_temp = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | temp_panic = 0; | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 888 | pcwd_private.boot_status = 0x0000; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 |  | 
|  | 890 | /* get the boot_status */ | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 891 | pcwd_get_status(&pcwd_private.boot_status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 |  | 
|  | 893 | /* clear the "card caused reboot" flag */ | 
|  | 894 | pcwd_clear_status(); | 
|  | 895 |  | 
| Jiri Slaby | 82eb7c5 | 2007-02-08 18:39:36 +0100 | [diff] [blame] | 896 | setup_timer(&pcwd_private.timer, pcwd_timer_ping, 0); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 |  | 
|  | 898 | /*  Disable the board  */ | 
|  | 899 | pcwd_stop(); | 
|  | 900 |  | 
|  | 901 | /*  Check whether or not the card supports the temperature device */ | 
| Wim Van Sebroeck | 8587521 | 2006-01-09 21:59:39 +0100 | [diff] [blame] | 902 | pcwd_check_temperature_support(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 |  | 
| Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 904 | /* Show info about the card itself */ | 
|  | 905 | pcwd_show_card_info(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 |  | 
| Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 907 | /* If heartbeat = 0 then we use the heartbeat from the dip-switches */ | 
|  | 908 | if (heartbeat == 0) | 
|  | 909 | heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)]; | 
|  | 910 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | /* Check that the heartbeat value is within it's range ; if not reset to the default */ | 
| Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 912 | if (pcwd_set_heartbeat(heartbeat)) { | 
|  | 913 | pcwd_set_heartbeat(WATCHDOG_HEARTBEAT); | 
|  | 914 | printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n", | 
|  | 915 | WATCHDOG_HEARTBEAT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | } | 
|  | 917 |  | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 918 | if (pcwd_private.supports_temp) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | ret = misc_register(&temp_miscdev); | 
|  | 920 | if (ret) { | 
|  | 921 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 
|  | 922 | TEMP_MINOR, ret); | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 923 | goto error_misc_register_temp; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } | 
|  | 925 | } | 
|  | 926 |  | 
|  | 927 | ret = misc_register(&pcwd_miscdev); | 
|  | 928 | if (ret) { | 
|  | 929 | printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 
|  | 930 | WATCHDOG_MINOR, ret); | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 931 | goto error_misc_register_watchdog; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | } | 
|  | 933 |  | 
|  | 934 | printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", | 
|  | 935 | heartbeat, nowayout); | 
|  | 936 |  | 
|  | 937 | return 0; | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 938 |  | 
|  | 939 | error_misc_register_watchdog: | 
|  | 940 | if (pcwd_private.supports_temp) | 
|  | 941 | misc_deregister(&temp_miscdev); | 
|  | 942 | error_misc_register_temp: | 
|  | 943 | release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); | 
|  | 944 | error_request_region: | 
|  | 945 | pcwd_private.io_addr = 0x0000; | 
|  | 946 | cards_found--; | 
|  | 947 | return ret; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | } | 
|  | 949 |  | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 950 | static int __devexit pcwd_isa_remove(struct device *dev, unsigned int id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | { | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 952 | if (debug >= DEBUG) | 
|  | 953 | printk(KERN_DEBUG PFX "pcwd_isa_remove id=%d\n", | 
|  | 954 | id); | 
|  | 955 |  | 
|  | 956 | if (!pcwd_private.io_addr) | 
|  | 957 | return 1; | 
|  | 958 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | /*  Disable the board  */ | 
|  | 960 | if (!nowayout) | 
|  | 961 | pcwd_stop(); | 
|  | 962 |  | 
|  | 963 | /* Deregister */ | 
|  | 964 | misc_deregister(&pcwd_miscdev); | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 965 | if (pcwd_private.supports_temp) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | misc_deregister(&temp_miscdev); | 
| Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 967 | release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); | 
|  | 968 | pcwd_private.io_addr = 0x0000; | 
| Wim Van Sebroeck | f1c3a05 | 2005-12-10 14:36:24 +0100 | [diff] [blame] | 969 | cards_found--; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 |  | 
|  | 971 | return 0; | 
|  | 972 | } | 
|  | 973 |  | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 974 | static void pcwd_isa_shutdown(struct device *dev, unsigned int id) | 
|  | 975 | { | 
|  | 976 | if (debug >= DEBUG) | 
|  | 977 | printk(KERN_DEBUG PFX "pcwd_isa_shutdown id=%d\n", | 
|  | 978 | id); | 
|  | 979 |  | 
|  | 980 | pcwd_stop(); | 
|  | 981 | } | 
|  | 982 |  | 
|  | 983 | static struct isa_driver pcwd_isa_driver = { | 
|  | 984 | .match		= pcwd_isa_match, | 
|  | 985 | .probe		= pcwd_isa_probe, | 
|  | 986 | .remove		= __devexit_p(pcwd_isa_remove), | 
|  | 987 | .shutdown	= pcwd_isa_shutdown, | 
|  | 988 | .driver		= { | 
|  | 989 | .owner	= THIS_MODULE, | 
|  | 990 | .name	= WATCHDOG_NAME, | 
|  | 991 | }, | 
|  | 992 | }; | 
|  | 993 |  | 
|  | 994 | static int __init pcwd_init_module(void) | 
|  | 995 | { | 
|  | 996 | return isa_register_driver(&pcwd_isa_driver, PCWD_ISA_NR_CARDS); | 
|  | 997 | } | 
|  | 998 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 999 | static void __exit pcwd_cleanup_module(void) | 
|  | 1000 | { | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 1001 | isa_unregister_driver(&pcwd_isa_driver); | 
| Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 1002 | printk(KERN_INFO PFX "Watchdog Module Unloaded.\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } | 
|  | 1004 |  | 
|  | 1005 | module_init(pcwd_init_module); | 
|  | 1006 | module_exit(pcwd_cleanup_module); | 
|  | 1007 |  | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 1008 | MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, Wim Van Sebroeck <wim@iguana.be>"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver"); | 
| Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 1010 | MODULE_VERSION(WATCHDOG_VERSION); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | MODULE_LICENSE("GPL"); | 
|  | 1012 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | 
|  | 1013 | MODULE_ALIAS_MISCDEV(TEMP_MINOR); |