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