Thomas Gleixner | 09c434b | 2019-05-19 13:08:20 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * PC Watchdog Driver |
| 4 | * by Ken Hollis (khollis@bitgate.com) |
| 5 | * |
Wim Van Sebroeck | f9146f2 | 2007-01-09 22:38:54 +0100 | [diff] [blame] | 6 | * Permission granted from Simon Machell (smachell@berkprod.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * Written for the Linux Kernel, and GPLed by Ken Hollis |
| 8 | * |
| 9 | * 960107 Added request_region routines, modulized the whole thing. |
| 10 | * 960108 Fixed end-of-file pointer (Thanks to Dan Hollis), added |
| 11 | * WD_TIMEOUT define. |
| 12 | * 960216 Added eof marker on the file, and changed verbose messages. |
| 13 | * 960716 Made functional and cosmetic changes to the source for |
| 14 | * inclusion in Linux 2.0.x kernels, thanks to Alan Cox. |
| 15 | * 960717 Removed read/seek routines, replaced with ioctl. Also, added |
| 16 | * check_region command due to Alan's suggestion. |
| 17 | * 960821 Made changes to compile in newer 2.0.x kernels. Added |
| 18 | * "cold reboot sense" entry. |
| 19 | * 960825 Made a few changes to code, deleted some defines and made |
| 20 | * typedefs to replace them. Made heartbeat reset only available |
| 21 | * via ioctl, and removed the write routine. |
| 22 | * 960828 Added new items for PC Watchdog Rev.C card. |
| 23 | * 960829 Changed around all of the IOCTLs, added new features, |
| 24 | * added watchdog disable/re-enable routines. Added firmware |
| 25 | * version reporting. Added read routine for temperature. |
| 26 | * Removed some extra defines, added an autodetect Revision |
| 27 | * routine. |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 28 | * 961006 Revised some documentation, fixed some cosmetic bugs. Made |
| 29 | * drivers to panic the system if it's overheating at bootup. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * 961118 Changed some verbiage on some of the output, tidied up |
| 31 | * code bits, and added compatibility to 2.1.x. |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 32 | * 970912 Enabled board on open and disable on close. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | * 971107 Took account of recent VFS changes (broke read). |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 34 | * 971210 Disable board on initialisation in case board already ticking. |
| 35 | * 971222 Changed open/close for temperature handling |
| 36 | * Michael Meskes <meskes@debian.org>. |
| 37 | * 980112 Used minor numbers from include/linux/miscdevice.h |
| 38 | * 990403 Clear reset status after reading control status register in |
| 39 | * pcwd_showprevstate(). [Marc Boucher <marc@mbsi.ca>] |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | * 990605 Made changes to code to support Firmware 1.22a, added |
| 41 | * fairly useless proc entry. |
| 42 | * 990610 removed said useless proc code for the merge <alan> |
| 43 | * 000403 Removed last traces of proc code. <davej> |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 44 | * 011214 Added nowayout module option to override |
| 45 | * CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com> |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 46 | * Added timeout module option to override default |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | */ |
| 48 | |
| 49 | /* |
| 50 | * A bells and whistles driver is available from http://www.pcwd.de/ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 51 | * More info available at http://www.berkprod.com/ or |
| 52 | * http://www.pcwatchdog.com/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | */ |
| 54 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 55 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 56 | |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 57 | #include <linux/module.h> /* For module specific items */ |
| 58 | #include <linux/moduleparam.h> /* For new moduleparam's */ |
| 59 | #include <linux/types.h> /* For standard types (like size_t) */ |
| 60 | #include <linux/errno.h> /* For the -ENODEV/... values */ |
| 61 | #include <linux/kernel.h> /* For printk/panic/... */ |
| 62 | #include <linux/delay.h> /* For mdelay function */ |
| 63 | #include <linux/timer.h> /* For timer related operations */ |
| 64 | #include <linux/jiffies.h> /* For jiffies stuff */ |
Jean Delvare | 487722c | 2013-10-21 17:38:49 +0200 | [diff] [blame] | 65 | #include <linux/miscdevice.h> /* For struct miscdevice */ |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 66 | #include <linux/watchdog.h> /* For the watchdog specific items */ |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 67 | #include <linux/reboot.h> /* For kernel_power_off() */ |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 68 | #include <linux/init.h> /* For __init/__exit/... */ |
| 69 | #include <linux/fs.h> /* For file operations */ |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 70 | #include <linux/isa.h> /* For isa devices */ |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 71 | #include <linux/ioport.h> /* For io-port access */ |
| 72 | #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 73 | #include <linux/uaccess.h> /* For copy_to_user/put_user/... */ |
| 74 | #include <linux/io.h> /* For inb/outb/... */ |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 75 | |
| 76 | /* Module and version information */ |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 77 | #define WATCHDOG_VERSION "1.20" |
| 78 | #define WATCHDOG_DATE "18 Feb 2007" |
Wim Van Sebroeck | a7122f9 | 2006-01-09 22:07:22 +0100 | [diff] [blame] | 79 | #define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog" |
| 80 | #define WATCHDOG_NAME "pcwd" |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 81 | #define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION "\n" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
| 84 | * It should be noted that PCWD_REVISION_B was removed because A and B |
| 85 | * are essentially the same types of card, with the exception that B |
| 86 | * has temperature reporting. Since I didn't receive a Rev.B card, |
| 87 | * the Rev.B card is not supported. (It's a good thing too, as they |
| 88 | * are no longer in production.) |
| 89 | */ |
| 90 | #define PCWD_REVISION_A 1 |
| 91 | #define PCWD_REVISION_C 2 |
| 92 | |
| 93 | /* |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 94 | * These are the auto-probe addresses available. |
| 95 | * |
| 96 | * Revision A only uses ports 0x270 and 0x370. Revision C introduced 0x350. |
| 97 | * Revision A has an address range of 2 addresses, while Revision C has 4. |
| 98 | */ |
| 99 | #define PCWD_ISA_NR_CARDS 3 |
| 100 | static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 }; |
| 101 | |
| 102 | /* |
Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 103 | * These are the defines that describe the control status bits for the |
| 104 | * PCI-PC Watchdog card. |
| 105 | */ |
| 106 | /* 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] | 107 | #define WD_WDRST 0x01 /* Previously reset state */ |
| 108 | #define WD_T110 0x02 /* Temperature overheat sense */ |
| 109 | #define WD_HRTBT 0x04 /* Heartbeat sense */ |
| 110 | #define WD_RLY2 0x08 /* External relay triggered */ |
| 111 | #define WD_SRLY2 0x80 /* Software external relay triggered */ |
Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 112 | /* 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] | 113 | #define WD_REVC_WTRP 0x01 /* Watchdog Trip status */ |
| 114 | #define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */ |
| 115 | #define WD_REVC_TTRP 0x04 /* Temperature Trip status */ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 116 | #define WD_REVC_RL2A 0x08 /* Relay 2 activated by |
| 117 | on-board processor */ |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 118 | #define WD_REVC_RL1A 0x10 /* Relay 1 active */ |
| 119 | #define WD_REVC_R2DS 0x40 /* Relay 2 disable */ |
| 120 | #define WD_REVC_RLY2 0x80 /* Relay 2 activated? */ |
Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 121 | /* Port 2 : Control Status #2 */ |
| 122 | #define WD_WDIS 0x10 /* Watchdog Disabled */ |
| 123 | #define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 124 | #define WD_SSEL 0x40 /* Watchdog Switch Select |
| 125 | (1:SW1 <-> 0:SW2) */ |
Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 126 | #define WD_WCMD 0x80 /* Watchdog Command Mode */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* max. time we give an ISA watchdog card to process a command */ |
| 129 | /* 500ms for each 4 bit response (according to spec.) */ |
| 130 | #define ISA_COMMAND_TIMEOUT 1000 |
| 131 | |
| 132 | /* Watchdog's internal commands */ |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 133 | #define CMD_ISA_IDLE 0x00 |
| 134 | #define CMD_ISA_VERSION_INTEGER 0x01 |
| 135 | #define CMD_ISA_VERSION_TENTH 0x02 |
| 136 | #define CMD_ISA_VERSION_HUNDRETH 0x03 |
| 137 | #define CMD_ISA_VERSION_MINOR 0x04 |
| 138 | #define CMD_ISA_SWITCH_SETTINGS 0x05 |
Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 139 | #define CMD_ISA_RESET_PC 0x06 |
| 140 | #define CMD_ISA_ARM_0 0x07 |
| 141 | #define CMD_ISA_ARM_30 0x08 |
| 142 | #define CMD_ISA_ARM_60 0x09 |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 143 | #define CMD_ISA_DELAY_TIME_2SECS 0x0A |
| 144 | #define CMD_ISA_DELAY_TIME_4SECS 0x0B |
| 145 | #define CMD_ISA_DELAY_TIME_8SECS 0x0C |
Wim Van Sebroeck | 369fa25 | 2006-02-12 17:44:57 +0100 | [diff] [blame] | 146 | #define CMD_ISA_RESET_RELAYS 0x0D |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 148 | /* Watchdog's Dip Switch heartbeat values */ |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 149 | static const int heartbeat_tbl[] = { |
Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 150 | 20, /* OFF-OFF-OFF = 20 Sec */ |
| 151 | 40, /* OFF-OFF-ON = 40 Sec */ |
| 152 | 60, /* OFF-ON-OFF = 1 Min */ |
| 153 | 300, /* OFF-ON-ON = 5 Min */ |
| 154 | 600, /* ON-OFF-OFF = 10 Min */ |
| 155 | 1800, /* ON-OFF-ON = 30 Min */ |
| 156 | 3600, /* ON-ON-OFF = 1 Hour */ |
| 157 | 7200, /* ON-ON-ON = 2 hour */ |
| 158 | }; |
| 159 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | /* |
| 161 | * We are using an kernel timer to do the pinging of the watchdog |
| 162 | * every ~500ms. We try to set the internal heartbeat of the |
| 163 | * watchdog to 2 ms. |
| 164 | */ |
| 165 | |
| 166 | #define WDT_INTERVAL (HZ/2+1) |
| 167 | |
| 168 | /* We can only use 1 card due to the /dev/watchdog restriction */ |
| 169 | static int cards_found; |
| 170 | |
| 171 | /* internal variables */ |
Wim Van Sebroeck | 36cbaa8 | 2008-08-10 21:57:03 +0000 | [diff] [blame] | 172 | static unsigned long open_allowed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | static char expect_close; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | static int temp_panic; |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 175 | |
| 176 | /* this is private data for each ISA-PC watchdog card */ |
| 177 | static struct { |
Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 178 | char fw_ver_str[6]; /* The cards firmware version */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 179 | int revision; /* The card's revision */ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 180 | int supports_temp; /* Whether or not the card has |
| 181 | a temperature device */ |
| 182 | int command_mode; /* Whether or not the card is in |
| 183 | command mode */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 184 | int boot_status; /* The card's boot status */ |
| 185 | int io_addr; /* The cards I/O address */ |
| 186 | spinlock_t io_lock; /* the lock for io operations */ |
| 187 | struct timer_list timer; /* The timer that pings the watchdog */ |
| 188 | unsigned long next_heartbeat; /* the next_heartbeat for the timer */ |
| 189 | } pcwd_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /* module parameters */ |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 192 | #define QUIET 0 /* Default */ |
| 193 | #define VERBOSE 1 /* Verbose */ |
| 194 | #define DEBUG 2 /* print fancy stuff too */ |
| 195 | static int debug = QUIET; |
| 196 | module_param(debug, int, 0); |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 197 | MODULE_PARM_DESC(debug, |
| 198 | "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)"); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 199 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 200 | /* default heartbeat = delay-time from dip-switches */ |
| 201 | #define WATCHDOG_HEARTBEAT 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | static int heartbeat = WATCHDOG_HEARTBEAT; |
| 203 | module_param(heartbeat, int, 0); |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 204 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. " |
| 205 | "(2 <= heartbeat <= 7200 or 0=delay-time from dip-switches, default=" |
| 206 | __MODULE_STRING(WATCHDOG_HEARTBEAT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 208 | static bool nowayout = WATCHDOG_NOWAYOUT; |
| 209 | module_param(nowayout, bool, 0); |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 210 | MODULE_PARM_DESC(nowayout, |
| 211 | "Watchdog cannot be stopped once started (default=" |
| 212 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Internal functions |
| 216 | */ |
| 217 | |
| 218 | static int send_isa_command(int cmd) |
| 219 | { |
| 220 | int i; |
| 221 | int control_status; |
| 222 | int port0, last_port0; /* Double read for stabilising */ |
| 223 | |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 224 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 225 | pr_debug("sending following data cmd=0x%02x\n", cmd); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 226 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | /* 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] | 228 | control_status = (cmd & 0x0F) | WD_WCMD; |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 229 | outb_p(control_status, pcwd_private.io_addr + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | udelay(ISA_COMMAND_TIMEOUT); |
| 231 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 232 | port0 = inb_p(pcwd_private.io_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | for (i = 0; i < 25; ++i) { |
| 234 | last_port0 = port0; |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 235 | port0 = inb_p(pcwd_private.io_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | if (port0 == last_port0) |
| 238 | break; /* Data is stable */ |
| 239 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 240 | udelay(250); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 243 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 244 | pr_debug("received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n", |
| 245 | cmd, port0, last_port0); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 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) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 274 | pr_debug("command_mode=%d\n", pcwd_private.command_mode); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 275 | |
Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 276 | return found; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | static void unset_command_mode(void) |
| 280 | { |
| 281 | /* Set the card into normal mode */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 282 | spin_lock(&pcwd_private.io_lock); |
| 283 | outb_p(0x00, pcwd_private.io_addr + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | udelay(ISA_COMMAND_TIMEOUT); |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 285 | spin_unlock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 287 | pcwd_private.command_mode = 0; |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 288 | |
| 289 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 290 | pr_debug("command_mode=%d\n", 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) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 337 | pr_info("ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", |
| 338 | pcwd_private.io_addr); |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 339 | else if (pcwd_private.revision == PCWD_REVISION_C) { |
Wim Van Sebroeck | 2891b6a | 2006-02-12 16:47:34 +0100 | [diff] [blame] | 340 | pcwd_get_firmware(); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 341 | pr_info("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] | 342 | pcwd_private.io_addr, pcwd_private.fw_ver_str); |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 343 | option_switches = pcwd_get_option_switches(); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 344 | pr_info("Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n", |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 345 | option_switches, |
| 346 | ((option_switches & 0x10) ? "ON" : "OFF"), |
| 347 | ((option_switches & 0x08) ? "ON" : "OFF")); |
| 348 | |
| 349 | /* Reprogram internal heartbeat to 2 seconds */ |
| 350 | if (set_command_mode()) { |
| 351 | send_isa_command(CMD_ISA_DELAY_TIME_2SECS); |
| 352 | unset_command_mode(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if (pcwd_private.supports_temp) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 357 | pr_info("Temperature Option Detected\n"); |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 358 | |
| 359 | if (pcwd_private.boot_status & WDIOF_CARDRESET) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 360 | pr_info("Previous reboot was caused by the card\n"); |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 361 | |
| 362 | if (pcwd_private.boot_status & WDIOF_OVERHEAT) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 363 | pr_emerg("Card senses a CPU Overheat. Panicking!\n"); |
| 364 | pr_emerg("CPU Overheat\n"); |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | if (pcwd_private.boot_status == 0) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 368 | pr_info("No previous trip detected - Cold boot or reset\n"); |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 371 | static void pcwd_timer_ping(struct timer_list *unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | { |
| 373 | int wdrst_stat; |
| 374 | |
| 375 | /* If we got a heartbeat pulse within the WDT_INTERVAL |
| 376 | * we agree to ping the WDT */ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 377 | if (time_before(jiffies, pcwd_private.next_heartbeat)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* Ping the watchdog */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 379 | spin_lock(&pcwd_private.io_lock); |
| 380 | if (pcwd_private.revision == PCWD_REVISION_A) { |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 381 | /* Rev A cards are reset by setting the |
| 382 | WD_WDRST bit in register 1 */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 383 | wdrst_stat = inb_p(pcwd_private.io_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | wdrst_stat &= 0x0F; |
| 385 | wdrst_stat |= WD_WDRST; |
| 386 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 387 | outb_p(wdrst_stat, pcwd_private.io_addr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | } else { |
| 389 | /* Re-trigger watchdog by writing to port 0 */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 390 | outb_p(0x00, pcwd_private.io_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | /* Re-set the timer interval */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 394 | mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 396 | spin_unlock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | } else { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 398 | pr_warn("Heartbeat lost! Will not ping the watchdog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | } |
| 400 | } |
| 401 | |
| 402 | static int pcwd_start(void) |
| 403 | { |
| 404 | int stat_reg; |
| 405 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 406 | pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | /* Start the timer */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 409 | mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* Enable the port */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 412 | if (pcwd_private.revision == PCWD_REVISION_C) { |
| 413 | spin_lock(&pcwd_private.io_lock); |
| 414 | outb_p(0x00, pcwd_private.io_addr + 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | udelay(ISA_COMMAND_TIMEOUT); |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 416 | stat_reg = inb_p(pcwd_private.io_addr + 2); |
| 417 | spin_unlock(&pcwd_private.io_lock); |
Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 418 | if (stat_reg & WD_WDIS) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 419 | pr_info("Could not start watchdog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | return -EIO; |
| 421 | } |
| 422 | } |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 423 | |
| 424 | if (debug >= VERBOSE) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 425 | pr_debug("Watchdog started\n"); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return 0; |
| 428 | } |
| 429 | |
| 430 | static int pcwd_stop(void) |
| 431 | { |
| 432 | int stat_reg; |
| 433 | |
| 434 | /* Stop the timer */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 435 | del_timer(&pcwd_private.timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* Disable the board */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 438 | if (pcwd_private.revision == PCWD_REVISION_C) { |
| 439 | spin_lock(&pcwd_private.io_lock); |
| 440 | outb_p(0xA5, pcwd_private.io_addr + 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | udelay(ISA_COMMAND_TIMEOUT); |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 442 | outb_p(0xA5, pcwd_private.io_addr + 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | udelay(ISA_COMMAND_TIMEOUT); |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 444 | stat_reg = inb_p(pcwd_private.io_addr + 2); |
| 445 | spin_unlock(&pcwd_private.io_lock); |
Wim Van Sebroeck | 8f0235d | 2006-01-09 21:56:09 +0100 | [diff] [blame] | 446 | if ((stat_reg & WD_WDIS) == 0) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 447 | pr_info("Could not stop watchdog\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | return -EIO; |
| 449 | } |
| 450 | } |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 451 | |
| 452 | if (debug >= VERBOSE) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 453 | pr_debug("Watchdog stopped\n"); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return 0; |
| 456 | } |
| 457 | |
| 458 | static int pcwd_keepalive(void) |
| 459 | { |
| 460 | /* user land ping */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 461 | pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 462 | |
| 463 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 464 | pr_debug("Watchdog keepalive signal send\n"); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int pcwd_set_heartbeat(int t) |
| 470 | { |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 471 | if (t < 2 || t > 7200) /* arbitrary upper limit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return -EINVAL; |
| 473 | |
| 474 | heartbeat = t; |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 475 | |
| 476 | if (debug >= VERBOSE) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 477 | pr_debug("New heartbeat: %d\n", heartbeat); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | static int pcwd_get_status(int *status) |
| 483 | { |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 484 | int control_status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 486 | *status = 0; |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 487 | spin_lock(&pcwd_private.io_lock); |
| 488 | if (pcwd_private.revision == PCWD_REVISION_A) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* Rev A cards return status information from |
| 490 | * the base register, which is used for the |
| 491 | * temperature in other cards. */ |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 492 | control_status = inb(pcwd_private.io_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | else { |
| 494 | /* Rev C cards return card status in the base |
| 495 | * address + 1 register. And use different bits |
| 496 | * to indicate a card initiated reset, and an |
| 497 | * over-temperature condition. And the reboot |
| 498 | * status can be reset. */ |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 499 | control_status = inb(pcwd_private.io_addr + 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | } |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 501 | spin_unlock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 503 | if (pcwd_private.revision == PCWD_REVISION_A) { |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 504 | if (control_status & WD_WDRST) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | *status |= WDIOF_CARDRESET; |
| 506 | |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 507 | if (control_status & WD_T110) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | *status |= WDIOF_OVERHEAT; |
| 509 | if (temp_panic) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 510 | pr_info("Temperature overheat trip!\n"); |
Eric W. Biederman | 68acc05 | 2005-07-26 12:03:08 -0600 | [diff] [blame] | 511 | kernel_power_off(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | } else { |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 515 | if (control_status & WD_REVC_WTRP) |
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_REVC_TTRP) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | *status |= WDIOF_OVERHEAT; |
| 520 | if (temp_panic) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 521 | pr_info("Temperature overheat trip!\n"); |
Eric W. Biederman | 68acc05 | 2005-07-26 12:03:08 -0600 | [diff] [blame] | 522 | kernel_power_off(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | } |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int pcwd_clear_status(void) |
| 531 | { |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 532 | int control_status; |
| 533 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 534 | if (pcwd_private.revision == PCWD_REVISION_C) { |
| 535 | spin_lock(&pcwd_private.io_lock); |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 536 | |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 537 | if (debug >= VERBOSE) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 538 | pr_info("clearing watchdog trip status\n"); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 539 | |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 540 | control_status = inb_p(pcwd_private.io_addr + 1); |
| 541 | |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 542 | if (debug >= DEBUG) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 543 | pr_debug("status was: 0x%02x\n", control_status); |
| 544 | pr_debug("sending: 0x%02x\n", |
| 545 | (control_status & WD_REVC_R2DS)); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 546 | } |
| 547 | |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 548 | /* clear reset status & Keep Relay 2 disable state as it is */ |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 549 | outb_p((control_status & WD_REVC_R2DS), |
| 550 | pcwd_private.io_addr + 1); |
Wim Van Sebroeck | 4206f0c | 2006-02-12 16:37:36 +0100 | [diff] [blame] | 551 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 552 | spin_unlock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | static int pcwd_get_temperature(int *temperature) |
| 558 | { |
| 559 | /* check that port 0 gives temperature info and no command results */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 560 | if (pcwd_private.command_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | return -1; |
| 562 | |
| 563 | *temperature = 0; |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 564 | if (!pcwd_private.supports_temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | return -ENODEV; |
| 566 | |
| 567 | /* |
| 568 | * Convert celsius to fahrenheit, since this was |
| 569 | * the decided 'standard' for this return value. |
| 570 | */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 571 | spin_lock(&pcwd_private.io_lock); |
| 572 | *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32; |
| 573 | spin_unlock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 575 | if (debug >= DEBUG) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 576 | pr_debug("temperature is: %d F\n", *temperature); |
Wim Van Sebroeck | c324ab4 | 2006-02-12 17:12:55 +0100 | [diff] [blame] | 577 | } |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | return 0; |
| 580 | } |
| 581 | |
| 582 | /* |
| 583 | * /dev/watchdog handling |
| 584 | */ |
| 585 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 586 | 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] | 587 | { |
| 588 | int rv; |
| 589 | int status; |
| 590 | int temperature; |
| 591 | int new_heartbeat; |
| 592 | int __user *argp = (int __user *)arg; |
Wim Van Sebroeck | 42747d7 | 2009-12-26 18:55:22 +0000 | [diff] [blame] | 593 | static const struct watchdog_info ident = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | .options = WDIOF_OVERHEAT | |
| 595 | WDIOF_CARDRESET | |
| 596 | WDIOF_KEEPALIVEPING | |
| 597 | WDIOF_SETTIMEOUT | |
| 598 | WDIOF_MAGICCLOSE, |
| 599 | .firmware_version = 1, |
| 600 | .identity = "PCWD", |
| 601 | }; |
| 602 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 603 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | case WDIOC_GETSUPPORT: |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 605 | if (copy_to_user(argp, &ident, sizeof(ident))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return -EFAULT; |
| 607 | return 0; |
| 608 | |
| 609 | case WDIOC_GETSTATUS: |
| 610 | pcwd_get_status(&status); |
| 611 | return put_user(status, argp); |
| 612 | |
| 613 | case WDIOC_GETBOOTSTATUS: |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 614 | return put_user(pcwd_private.boot_status, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | case WDIOC_GETTEMP: |
| 617 | if (pcwd_get_temperature(&temperature)) |
| 618 | return -EFAULT; |
| 619 | |
| 620 | return put_user(temperature, argp); |
| 621 | |
| 622 | case WDIOC_SETOPTIONS: |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 623 | if (pcwd_private.revision == PCWD_REVISION_C) { |
| 624 | if (get_user(rv, argp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | return -EFAULT; |
| 626 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 627 | if (rv & WDIOS_DISABLECARD) { |
| 628 | status = pcwd_stop(); |
| 629 | if (status < 0) |
| 630 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 632 | if (rv & WDIOS_ENABLECARD) { |
| 633 | status = pcwd_start(); |
| 634 | if (status < 0) |
| 635 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | if (rv & WDIOS_TEMPPANIC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | temp_panic = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | } |
| 640 | return -EINVAL; |
| 641 | |
| 642 | case WDIOC_KEEPALIVE: |
| 643 | pcwd_keepalive(); |
| 644 | return 0; |
| 645 | |
| 646 | case WDIOC_SETTIMEOUT: |
| 647 | if (get_user(new_heartbeat, argp)) |
| 648 | return -EFAULT; |
| 649 | |
| 650 | if (pcwd_set_heartbeat(new_heartbeat)) |
| 651 | return -EINVAL; |
| 652 | |
| 653 | pcwd_keepalive(); |
Gustavo A. R. Silva | bd490f8 | 2020-07-07 12:11:21 -0500 | [diff] [blame] | 654 | fallthrough; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | case WDIOC_GETTIMEOUT: |
| 657 | return put_user(heartbeat, argp); |
Wim Van Sebroeck | 0c06090 | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 658 | |
| 659 | default: |
| 660 | return -ENOTTY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len, |
| 667 | loff_t *ppos) |
| 668 | { |
| 669 | if (len) { |
| 670 | if (!nowayout) { |
| 671 | size_t i; |
| 672 | |
| 673 | /* In case it was set long ago */ |
| 674 | expect_close = 0; |
| 675 | |
| 676 | for (i = 0; i != len; i++) { |
| 677 | char c; |
| 678 | |
| 679 | if (get_user(c, buf + i)) |
| 680 | return -EFAULT; |
| 681 | if (c == 'V') |
| 682 | expect_close = 42; |
| 683 | } |
| 684 | } |
| 685 | pcwd_keepalive(); |
| 686 | } |
| 687 | return len; |
| 688 | } |
| 689 | |
| 690 | static int pcwd_open(struct inode *inode, struct file *file) |
| 691 | { |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 692 | if (test_and_set_bit(0, &open_allowed)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | if (nowayout) |
| 695 | __module_get(THIS_MODULE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | /* Activate */ |
| 697 | pcwd_start(); |
| 698 | pcwd_keepalive(); |
Kirill Smelkov | c5bf68f | 2019-03-26 23:51:19 +0300 | [diff] [blame] | 699 | return stream_open(inode, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static int pcwd_close(struct inode *inode, struct file *file) |
| 703 | { |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 704 | if (expect_close == 42) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | pcwd_stop(); |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 706 | else { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 707 | pr_crit("Unexpected close, not stopping watchdog!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | pcwd_keepalive(); |
| 709 | } |
| 710 | expect_close = 0; |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 711 | clear_bit(0, &open_allowed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | return 0; |
| 713 | } |
| 714 | |
| 715 | /* |
| 716 | * /dev/temperature handling |
| 717 | */ |
| 718 | |
| 719 | static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count, |
| 720 | loff_t *ppos) |
| 721 | { |
| 722 | int temperature; |
| 723 | |
| 724 | if (pcwd_get_temperature(&temperature)) |
| 725 | return -EFAULT; |
| 726 | |
| 727 | if (copy_to_user(buf, &temperature, 1)) |
| 728 | return -EFAULT; |
| 729 | |
| 730 | return 1; |
| 731 | } |
| 732 | |
| 733 | static int pcwd_temp_open(struct inode *inode, struct file *file) |
| 734 | { |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 735 | if (!pcwd_private.supports_temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | return -ENODEV; |
| 737 | |
Kirill Smelkov | c5bf68f | 2019-03-26 23:51:19 +0300 | [diff] [blame] | 738 | return stream_open(inode, file); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | static int pcwd_temp_close(struct inode *inode, struct file *file) |
| 742 | { |
| 743 | return 0; |
| 744 | } |
| 745 | |
| 746 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | * Kernel Interfaces |
| 748 | */ |
| 749 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 750 | static const struct file_operations pcwd_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | .owner = THIS_MODULE, |
| 752 | .llseek = no_llseek, |
| 753 | .write = pcwd_write, |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 754 | .unlocked_ioctl = pcwd_ioctl, |
Arnd Bergmann | b6dfb24 | 2019-06-03 14:23:09 +0200 | [diff] [blame] | 755 | .compat_ioctl = compat_ptr_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | .open = pcwd_open, |
| 757 | .release = pcwd_close, |
| 758 | }; |
| 759 | |
| 760 | static struct miscdevice pcwd_miscdev = { |
| 761 | .minor = WATCHDOG_MINOR, |
| 762 | .name = "watchdog", |
| 763 | .fops = &pcwd_fops, |
| 764 | }; |
| 765 | |
Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 766 | static const struct file_operations pcwd_temp_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | .owner = THIS_MODULE, |
| 768 | .llseek = no_llseek, |
| 769 | .read = pcwd_temp_read, |
| 770 | .open = pcwd_temp_open, |
| 771 | .release = pcwd_temp_close, |
| 772 | }; |
| 773 | |
| 774 | static struct miscdevice temp_miscdev = { |
| 775 | .minor = TEMP_MINOR, |
| 776 | .name = "temperature", |
| 777 | .fops = &pcwd_temp_fops, |
| 778 | }; |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | /* |
| 781 | * Init & exit routines |
| 782 | */ |
| 783 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | static inline int get_revision(void) |
| 785 | { |
| 786 | int r = PCWD_REVISION_C; |
| 787 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 788 | spin_lock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | /* REV A cards use only 2 io ports; test |
| 790 | * presumes a floating bus reads as 0xff. */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 791 | if ((inb(pcwd_private.io_addr + 2) == 0xFF) || |
| 792 | (inb(pcwd_private.io_addr + 3) == 0xFF)) |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 793 | r = PCWD_REVISION_A; |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 794 | spin_unlock(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | return r; |
| 797 | } |
| 798 | |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 799 | /* |
| 800 | * The ISA cards have a heartbeat bit in one of the registers, which |
| 801 | * register is card dependent. The heartbeat bit is monitored, and if |
| 802 | * found, is considered proof that a Berkshire card has been found. |
| 803 | * The initial rate is once per second at board start up, then twice |
| 804 | * per second for normal operation. |
| 805 | */ |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 806 | static int pcwd_isa_match(struct device *dev, unsigned int id) |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 807 | { |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 808 | int base_addr = pcwd_ioports[id]; |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 809 | int port0, last_port0; /* Reg 0, in case it's REV A */ |
| 810 | int port1, last_port1; /* Register 1 for REV C cards */ |
| 811 | int i; |
| 812 | int retval; |
| 813 | |
| 814 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 815 | pr_debug("pcwd_isa_match id=%d\n", id); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 816 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 817 | if (!request_region(base_addr, 4, "PCWD")) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 818 | pr_info("Port 0x%04x unavailable\n", base_addr); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | retval = 0; |
| 823 | |
| 824 | port0 = inb_p(base_addr); /* For REV A boards */ |
| 825 | port1 = inb_p(base_addr + 1); /* For REV C boards */ |
| 826 | if (port0 != 0xff || port1 != 0xff) { |
| 827 | /* Not an 'ff' from a floating bus, so must be a card! */ |
| 828 | for (i = 0; i < 4; ++i) { |
| 829 | |
| 830 | msleep(500); |
| 831 | |
| 832 | last_port0 = port0; |
| 833 | last_port1 = port1; |
| 834 | |
| 835 | port0 = inb_p(base_addr); |
| 836 | port1 = inb_p(base_addr + 1); |
| 837 | |
| 838 | /* Has either hearbeat bit changed? */ |
| 839 | if ((port0 ^ last_port0) & WD_HRTBT || |
| 840 | (port1 ^ last_port1) & WD_REVC_HRBT) { |
| 841 | retval = 1; |
| 842 | break; |
| 843 | } |
| 844 | } |
| 845 | } |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 846 | release_region(base_addr, 4); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 847 | |
| 848 | return retval; |
| 849 | } |
| 850 | |
Bill Pemberton | 2d991a1 | 2012-11-19 13:21:41 -0500 | [diff] [blame] | 851 | static int pcwd_isa_probe(struct device *dev, unsigned int id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | { |
| 853 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 855 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 856 | pr_debug("pcwd_isa_probe id=%d\n", id); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 857 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | cards_found++; |
| 859 | if (cards_found == 1) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 860 | pr_info("v%s Ken Hollis (kenji@bitgate.com)\n", |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 861 | WATCHDOG_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
| 863 | if (cards_found > 1) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 864 | pr_err("This driver only supports 1 device\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | return -ENODEV; |
| 866 | } |
| 867 | |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 868 | if (pcwd_ioports[id] == 0x0000) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 869 | pr_err("No I/O-Address for card detected\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | return -ENODEV; |
| 871 | } |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 872 | pcwd_private.io_addr = pcwd_ioports[id]; |
| 873 | |
| 874 | spin_lock_init(&pcwd_private.io_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | /* Check card's revision */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 877 | pcwd_private.revision = get_revision(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 879 | if (!request_region(pcwd_private.io_addr, |
| 880 | (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 881 | pr_err("I/O address 0x%04x already in use\n", |
| 882 | pcwd_private.io_addr); |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 883 | ret = -EIO; |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 884 | goto error_request_region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | /* Initial variables */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 888 | pcwd_private.supports_temp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | temp_panic = 0; |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 890 | pcwd_private.boot_status = 0x0000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
| 892 | /* get the boot_status */ |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 893 | pcwd_get_status(&pcwd_private.boot_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
| 895 | /* clear the "card caused reboot" flag */ |
| 896 | pcwd_clear_status(); |
| 897 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 898 | timer_setup(&pcwd_private.timer, pcwd_timer_ping, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | /* Disable the board */ |
| 901 | pcwd_stop(); |
| 902 | |
| 903 | /* Check whether or not the card supports the temperature device */ |
Wim Van Sebroeck | 8587521 | 2006-01-09 21:59:39 +0100 | [diff] [blame] | 904 | pcwd_check_temperature_support(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Wim Van Sebroeck | af3b38d | 2006-01-09 22:03:41 +0100 | [diff] [blame] | 906 | /* Show info about the card itself */ |
| 907 | pcwd_show_card_info(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
Wim Van Sebroeck | f3dc073 | 2007-01-09 22:43:49 +0100 | [diff] [blame] | 909 | /* If heartbeat = 0 then we use the heartbeat from the dip-switches */ |
| 910 | if (heartbeat == 0) |
| 911 | heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)]; |
| 912 | |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 913 | /* Check that the heartbeat value is within it's range; |
| 914 | if not reset to the default */ |
Wim Van Sebroeck | fd41fa6 | 2005-12-10 14:22:37 +0100 | [diff] [blame] | 915 | if (pcwd_set_heartbeat(heartbeat)) { |
| 916 | pcwd_set_heartbeat(WATCHDOG_HEARTBEAT); |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 917 | pr_info("heartbeat value must be 2 <= heartbeat <= 7200, using %d\n", |
| 918 | WATCHDOG_HEARTBEAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | } |
| 920 | |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 921 | if (pcwd_private.supports_temp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | ret = misc_register(&temp_miscdev); |
| 923 | if (ret) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 924 | pr_err("cannot register miscdev on minor=%d (err=%d)\n", |
| 925 | TEMP_MINOR, ret); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 926 | goto error_misc_register_temp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | ret = misc_register(&pcwd_miscdev); |
| 931 | if (ret) { |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 932 | pr_err("cannot register miscdev on minor=%d (err=%d)\n", |
| 933 | WATCHDOG_MINOR, ret); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 934 | goto error_misc_register_watchdog; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | } |
| 936 | |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 937 | pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | heartbeat, nowayout); |
| 939 | |
| 940 | return 0; |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 941 | |
| 942 | error_misc_register_watchdog: |
| 943 | if (pcwd_private.supports_temp) |
| 944 | misc_deregister(&temp_miscdev); |
| 945 | error_misc_register_temp: |
Alan Cox | 261dcc7 | 2008-05-19 14:07:43 +0100 | [diff] [blame] | 946 | release_region(pcwd_private.io_addr, |
| 947 | (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 948 | error_request_region: |
| 949 | pcwd_private.io_addr = 0x0000; |
| 950 | cards_found--; |
| 951 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | } |
| 953 | |
Uwe Kleine-König | 30e88d0 | 2021-01-22 10:24:49 +0100 | [diff] [blame] | 954 | static void pcwd_isa_remove(struct device *dev, unsigned int id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 955 | { |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 956 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 957 | pr_debug("pcwd_isa_remove id=%d\n", id); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | /* Disable the board */ |
| 960 | if (!nowayout) |
| 961 | pcwd_stop(); |
| 962 | |
| 963 | /* Deregister */ |
| 964 | misc_deregister(&pcwd_miscdev); |
Wim Van Sebroeck | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 965 | if (pcwd_private.supports_temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | misc_deregister(&temp_miscdev); |
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 | a2be878 | 2006-01-09 21:53:33 +0100 | [diff] [blame] | 969 | pcwd_private.io_addr = 0x0000; |
Wim Van Sebroeck | f1c3a05 | 2005-12-10 14:36:24 +0100 | [diff] [blame] | 970 | cards_found--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 973 | static void pcwd_isa_shutdown(struct device *dev, unsigned int id) |
| 974 | { |
| 975 | if (debug >= DEBUG) |
Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 976 | pr_debug("pcwd_isa_shutdown id=%d\n", id); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 977 | |
| 978 | pcwd_stop(); |
| 979 | } |
| 980 | |
| 981 | static struct isa_driver pcwd_isa_driver = { |
| 982 | .match = pcwd_isa_match, |
| 983 | .probe = pcwd_isa_probe, |
Bill Pemberton | 8226871 | 2012-11-19 13:21:12 -0500 | [diff] [blame] | 984 | .remove = pcwd_isa_remove, |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 985 | .shutdown = pcwd_isa_shutdown, |
| 986 | .driver = { |
| 987 | .owner = THIS_MODULE, |
| 988 | .name = WATCHDOG_NAME, |
| 989 | }, |
| 990 | }; |
| 991 | |
William Breathitt Gray | b7a8c42 | 2016-06-01 09:05:48 -0400 | [diff] [blame] | 992 | module_isa_driver(pcwd_isa_driver, PCWD_ISA_NR_CARDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | |
Wim Van Sebroeck | 143a2e5 | 2009-03-18 08:35:09 +0000 | [diff] [blame] | 994 | MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, " |
| 995 | "Wim Van Sebroeck <wim@iguana.be>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver"); |
Wim Van Sebroeck | 5aa1505 | 2007-05-05 05:48:23 +0000 | [diff] [blame] | 997 | MODULE_VERSION(WATCHDOG_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | MODULE_LICENSE("GPL"); |