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