blob: 7b41434fac8cadbce0a893ef79e7d5a46207f989 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * PC Watchdog Driver
3 * by Ken Hollis (khollis@bitgate.com)
4 *
Wim Van Sebroeckf9146f22007-01-09 22:38:54 +01005 * Permission granted from Simon Machell (smachell@berkprod.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * Written for the Linux Kernel, and GPLed by Ken Hollis
7 *
8 * 960107 Added request_region routines, modulized the whole thing.
9 * 960108 Fixed end-of-file pointer (Thanks to Dan Hollis), added
10 * WD_TIMEOUT define.
11 * 960216 Added eof marker on the file, and changed verbose messages.
12 * 960716 Made functional and cosmetic changes to the source for
13 * inclusion in Linux 2.0.x kernels, thanks to Alan Cox.
14 * 960717 Removed read/seek routines, replaced with ioctl. Also, added
15 * check_region command due to Alan's suggestion.
16 * 960821 Made changes to compile in newer 2.0.x kernels. Added
17 * "cold reboot sense" entry.
18 * 960825 Made a few changes to code, deleted some defines and made
19 * typedefs to replace them. Made heartbeat reset only available
20 * via ioctl, and removed the write routine.
21 * 960828 Added new items for PC Watchdog Rev.C card.
22 * 960829 Changed around all of the IOCTLs, added new features,
23 * added watchdog disable/re-enable routines. Added firmware
24 * version reporting. Added read routine for temperature.
25 * Removed some extra defines, added an autodetect Revision
26 * routine.
27 * 961006 Revised some documentation, fixed some cosmetic bugs. Made
28 * drivers to panic the system if it's overheating at bootup.
29 * 961118 Changed some verbiage on some of the output, tidied up
30 * code bits, and added compatibility to 2.1.x.
31 * 970912 Enabled board on open and disable on close.
32 * 971107 Took account of recent VFS changes (broke read).
33 * 971210 Disable board on initialisation in case board already ticking.
34 * 971222 Changed open/close for temperature handling
35 * Michael Meskes <meskes@debian.org>.
36 * 980112 Used minor numbers from include/linux/miscdevice.h
37 * 990403 Clear reset status after reading control status register in
38 * pcwd_showprevstate(). [Marc Boucher <marc@mbsi.ca>]
39 * 990605 Made changes to code to support Firmware 1.22a, added
40 * fairly useless proc entry.
41 * 990610 removed said useless proc code for the merge <alan>
42 * 000403 Removed last traces of proc code. <davej>
43 * 011214 Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT <Matt_Domsch@dell.com>
44 * Added timeout module option to override default
45 */
46
47/*
48 * A bells and whistles driver is available from http://www.pcwd.de/
49 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
50 */
51
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010052#include <linux/module.h> /* For module specific items */
53#include <linux/moduleparam.h> /* For new moduleparam's */
54#include <linux/types.h> /* For standard types (like size_t) */
55#include <linux/errno.h> /* For the -ENODEV/... values */
56#include <linux/kernel.h> /* For printk/panic/... */
57#include <linux/delay.h> /* For mdelay function */
58#include <linux/timer.h> /* For timer related operations */
59#include <linux/jiffies.h> /* For jiffies stuff */
60#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
61#include <linux/watchdog.h> /* For the watchdog specific items */
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +000062#include <linux/reboot.h> /* For kernel_power_off() */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010063#include <linux/init.h> /* For __init/__exit/... */
64#include <linux/fs.h> /* For file operations */
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +000065#include <linux/isa.h> /* For isa devices */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010066#include <linux/ioport.h> /* For io-port access */
67#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +010069#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
70#include <asm/io.h> /* For inb/outb/... */
71
72/* Module and version information */
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +000073#define WATCHDOG_VERSION "1.20"
74#define WATCHDOG_DATE "18 Feb 2007"
Wim Van Sebroecka7122f92006-01-09 22:07:22 +010075#define WATCHDOG_DRIVER_NAME "ISA-PC Watchdog"
76#define WATCHDOG_NAME "pcwd"
77#define PFX WATCHDOG_NAME ": "
78#define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
79#define WD_VER WATCHDOG_VERSION " (" WATCHDOG_DATE ")"
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
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 Sebroeck5aa15052007-05-05 05:48:23 +000092 * 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
98static int pcwd_ioports[] = { 0x270, 0x350, 0x370, 0x000 };
99
100/*
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100101 * 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 Sebroeck4206f0c2006-02-12 16:37:36 +0100105#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 Sebroeck8f0235d2006-01-09 21:56:09 +0100110/* Port 1 : Control Status #1 for the PC Watchdog card, revision C. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100111#define WD_REVC_WTRP 0x01 /* Watchdog Trip status */
112#define WD_REVC_HRBT 0x02 /* Watchdog Heartbeat */
113#define WD_REVC_TTRP 0x04 /* Temperature Trip status */
114#define WD_REVC_RL2A 0x08 /* Relay 2 activated by on-board processor */
115#define WD_REVC_RL1A 0x10 /* Relay 1 active */
116#define WD_REVC_R2DS 0x40 /* Relay 2 disable */
117#define WD_REVC_RLY2 0x80 /* Relay 2 activated? */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100118/* Port 2 : Control Status #2 */
119#define WD_WDIS 0x10 /* Watchdog Disabled */
120#define WD_ENTP 0x20 /* Watchdog Enable Temperature Trip */
121#define WD_SSEL 0x40 /* Watchdog Switch Select (1:SW1 <-> 0:SW2) */
122#define WD_WCMD 0x80 /* Watchdog Command Mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* max. time we give an ISA watchdog card to process a command */
125/* 500ms for each 4 bit response (according to spec.) */
126#define ISA_COMMAND_TIMEOUT 1000
127
128/* Watchdog's internal commands */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100129#define CMD_ISA_IDLE 0x00
130#define CMD_ISA_VERSION_INTEGER 0x01
131#define CMD_ISA_VERSION_TENTH 0x02
132#define CMD_ISA_VERSION_HUNDRETH 0x03
133#define CMD_ISA_VERSION_MINOR 0x04
134#define CMD_ISA_SWITCH_SETTINGS 0x05
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100135#define CMD_ISA_RESET_PC 0x06
136#define CMD_ISA_ARM_0 0x07
137#define CMD_ISA_ARM_30 0x08
138#define CMD_ISA_ARM_60 0x09
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100139#define CMD_ISA_DELAY_TIME_2SECS 0x0A
140#define CMD_ISA_DELAY_TIME_4SECS 0x0B
141#define CMD_ISA_DELAY_TIME_8SECS 0x0C
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100142#define CMD_ISA_RESET_RELAYS 0x0D
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Wim Van Sebroeckf3dc0732007-01-09 22:43:49 +0100144/* Watchdog's Dip Switch heartbeat values */
145static const int heartbeat_tbl [] = {
146 20, /* OFF-OFF-OFF = 20 Sec */
147 40, /* OFF-OFF-ON = 40 Sec */
148 60, /* OFF-ON-OFF = 1 Min */
149 300, /* OFF-ON-ON = 5 Min */
150 600, /* ON-OFF-OFF = 10 Min */
151 1800, /* ON-OFF-ON = 30 Min */
152 3600, /* ON-ON-OFF = 1 Hour */
153 7200, /* ON-ON-ON = 2 hour */
154};
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156/*
157 * We are using an kernel timer to do the pinging of the watchdog
158 * every ~500ms. We try to set the internal heartbeat of the
159 * watchdog to 2 ms.
160 */
161
162#define WDT_INTERVAL (HZ/2+1)
163
164/* We can only use 1 card due to the /dev/watchdog restriction */
165static int cards_found;
166
167/* internal variables */
168static atomic_t open_allowed = ATOMIC_INIT(1);
169static char expect_close;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170static int temp_panic;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100171static struct { /* this is private data for each ISA-PC watchdog card */
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100172 char fw_ver_str[6]; /* The cards firmware version */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100173 int revision; /* The card's revision */
174 int supports_temp; /* Wether or not the card has a temperature device */
175 int command_mode; /* Wether or not the card is in command mode */
176 int boot_status; /* The card's boot status */
177 int io_addr; /* The cards I/O address */
178 spinlock_t io_lock; /* the lock for io operations */
179 struct timer_list timer; /* The timer that pings the watchdog */
180 unsigned long next_heartbeat; /* the next_heartbeat for the timer */
181} pcwd_private;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183/* module parameters */
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100184#define QUIET 0 /* Default */
185#define VERBOSE 1 /* Verbose */
186#define DEBUG 2 /* print fancy stuff too */
187static int debug = QUIET;
188module_param(debug, int, 0);
189MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
190
Wim Van Sebroeckf3dc0732007-01-09 22:43:49 +0100191#define WATCHDOG_HEARTBEAT 0 /* default heartbeat = delay-time from dip-switches */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static int heartbeat = WATCHDOG_HEARTBEAT;
193module_param(heartbeat, int, 0);
Wim Van Sebroeckf3dc0732007-01-09 22:43:49 +0100194MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (2<=heartbeat<=7200 or 0=delay-time from dip-switches, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
Andrey Panin4bfdf372005-07-27 11:43:58 -0700196static int nowayout = WATCHDOG_NOWAYOUT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197module_param(nowayout, int, 0);
Wim Van Sebroeckbffda5c2007-01-27 20:54:24 +0100198MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200/*
201 * Internal functions
202 */
203
204static int send_isa_command(int cmd)
205{
206 int i;
207 int control_status;
208 int port0, last_port0; /* Double read for stabilising */
209
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100210 if (debug >= DEBUG)
211 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x\n",
212 cmd);
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /* The WCMD bit must be 1 and the command is only 4 bits in size */
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100215 control_status = (cmd & 0x0F) | WD_WCMD;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100216 outb_p(control_status, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 udelay(ISA_COMMAND_TIMEOUT);
218
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100219 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 for (i = 0; i < 25; ++i) {
221 last_port0 = port0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100222 port0 = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223
224 if (port0 == last_port0)
225 break; /* Data is stable */
226
227 udelay (250);
228 }
229
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100230 if (debug >= DEBUG)
231 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: port0=0x%02x last_port0=0x%02x\n",
232 cmd, port0, last_port0);
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return port0;
235}
236
237static int set_command_mode(void)
238{
239 int i, found=0, count=0;
240
241 /* Set the card into command mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100242 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243 while ((!found) && (count < 3)) {
244 i = send_isa_command(CMD_ISA_IDLE);
245
246 if (i == 0x00)
247 found = 1;
248 else if (i == 0xF3) {
249 /* Card does not like what we've done to it */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100250 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 udelay(1200); /* Spec says wait 1ms */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100252 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 udelay(ISA_COMMAND_TIMEOUT);
254 }
255 count++;
256 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100257 spin_unlock(&pcwd_private.io_lock);
258 pcwd_private.command_mode = found;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100260 if (debug >= DEBUG)
261 printk(KERN_DEBUG PFX "command_mode=%d\n",
262 pcwd_private.command_mode);
263
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 return(found);
265}
266
267static void unset_command_mode(void)
268{
269 /* Set the card into normal mode */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100270 spin_lock(&pcwd_private.io_lock);
271 outb_p(0x00, pcwd_private.io_addr + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100273 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100275 pcwd_private.command_mode = 0;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100276
277 if (debug >= DEBUG)
278 printk(KERN_DEBUG PFX "command_mode=%d\n",
279 pcwd_private.command_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280}
281
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100282static inline void pcwd_check_temperature_support(void)
283{
284 if (inb(pcwd_private.io_addr) != 0xF0)
285 pcwd_private.supports_temp = 1;
286}
287
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100288static inline void pcwd_get_firmware(void)
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100289{
290 int one, ten, hund, minor;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100291
Wim Van Sebroeck6bbc20b2006-03-02 20:05:16 +0100292 strcpy(pcwd_private.fw_ver_str, "ERROR");
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100293
294 if (set_command_mode()) {
295 one = send_isa_command(CMD_ISA_VERSION_INTEGER);
296 ten = send_isa_command(CMD_ISA_VERSION_TENTH);
297 hund = send_isa_command(CMD_ISA_VERSION_HUNDRETH);
298 minor = send_isa_command(CMD_ISA_VERSION_MINOR);
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100299 sprintf(pcwd_private.fw_ver_str, "%c.%c%c%c", one, ten, hund, minor);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100300 }
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100301 unset_command_mode();
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100302
303 return;
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100304}
305
306static inline int pcwd_get_option_switches(void)
307{
308 int option_switches=0;
309
310 if (set_command_mode()) {
311 /* Get switch settings */
312 option_switches = send_isa_command(CMD_ISA_SWITCH_SETTINGS);
313 }
314
315 unset_command_mode();
316 return(option_switches);
317}
318
319static void pcwd_show_card_info(void)
320{
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100321 int option_switches;
322
323 /* Get some extra info from the hardware (in command/debug/diag mode) */
324 if (pcwd_private.revision == PCWD_REVISION_A)
325 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.A) detected at port 0x%04x\n", pcwd_private.io_addr);
326 else if (pcwd_private.revision == PCWD_REVISION_C) {
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100327 pcwd_get_firmware();
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100328 printk(KERN_INFO PFX "ISA-PC Watchdog (REV.C) detected at port 0x%04x (Firmware version: %s)\n",
Wim Van Sebroeck2891b6a2006-02-12 16:47:34 +0100329 pcwd_private.io_addr, pcwd_private.fw_ver_str);
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100330 option_switches = pcwd_get_option_switches();
331 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
332 option_switches,
333 ((option_switches & 0x10) ? "ON" : "OFF"),
334 ((option_switches & 0x08) ? "ON" : "OFF"));
335
336 /* Reprogram internal heartbeat to 2 seconds */
337 if (set_command_mode()) {
338 send_isa_command(CMD_ISA_DELAY_TIME_2SECS);
339 unset_command_mode();
340 }
341 }
342
343 if (pcwd_private.supports_temp)
344 printk(KERN_INFO PFX "Temperature Option Detected\n");
345
346 if (pcwd_private.boot_status & WDIOF_CARDRESET)
347 printk(KERN_INFO PFX "Previous reboot was caused by the card\n");
348
349 if (pcwd_private.boot_status & WDIOF_OVERHEAT) {
350 printk(KERN_EMERG PFX "Card senses a CPU Overheat. Panicking!\n");
351 printk(KERN_EMERG PFX "CPU Overheat\n");
352 }
353
354 if (pcwd_private.boot_status == 0)
355 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
356}
357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358static void pcwd_timer_ping(unsigned long data)
359{
360 int wdrst_stat;
361
362 /* If we got a heartbeat pulse within the WDT_INTERVAL
363 * we agree to ping the WDT */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100364 if(time_before(jiffies, pcwd_private.next_heartbeat)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 /* Ping the watchdog */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100366 spin_lock(&pcwd_private.io_lock);
367 if (pcwd_private.revision == PCWD_REVISION_A) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 /* Rev A cards are reset by setting the WD_WDRST bit in register 1 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100369 wdrst_stat = inb_p(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 wdrst_stat &= 0x0F;
371 wdrst_stat |= WD_WDRST;
372
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100373 outb_p(wdrst_stat, pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 } else {
375 /* Re-trigger watchdog by writing to port 0 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100376 outb_p(0x00, pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 }
378
379 /* Re-set the timer interval */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100380 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100382 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 } else {
384 printk(KERN_WARNING PFX "Heartbeat lost! Will not ping the watchdog\n");
385 }
386}
387
388static int pcwd_start(void)
389{
390 int stat_reg;
391
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100392 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 /* Start the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100395 mod_timer(&pcwd_private.timer, jiffies + WDT_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
397 /* Enable the port */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100398 if (pcwd_private.revision == PCWD_REVISION_C) {
399 spin_lock(&pcwd_private.io_lock);
400 outb_p(0x00, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100402 stat_reg = inb_p(pcwd_private.io_addr + 2);
403 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100404 if (stat_reg & WD_WDIS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 printk(KERN_INFO PFX "Could not start watchdog\n");
406 return -EIO;
407 }
408 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100409
410 if (debug >= VERBOSE)
411 printk(KERN_DEBUG PFX "Watchdog started\n");
412
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 return 0;
414}
415
416static int pcwd_stop(void)
417{
418 int stat_reg;
419
420 /* Stop the timer */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100421 del_timer(&pcwd_private.timer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423 /* Disable the board */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100424 if (pcwd_private.revision == PCWD_REVISION_C) {
425 spin_lock(&pcwd_private.io_lock);
426 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100428 outb_p(0xA5, pcwd_private.io_addr + 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 udelay(ISA_COMMAND_TIMEOUT);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100430 stat_reg = inb_p(pcwd_private.io_addr + 2);
431 spin_unlock(&pcwd_private.io_lock);
Wim Van Sebroeck8f0235d2006-01-09 21:56:09 +0100432 if ((stat_reg & WD_WDIS) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 printk(KERN_INFO PFX "Could not stop watchdog\n");
434 return -EIO;
435 }
436 }
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100437
438 if (debug >= VERBOSE)
439 printk(KERN_DEBUG PFX "Watchdog stopped\n");
440
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 return 0;
442}
443
444static int pcwd_keepalive(void)
445{
446 /* user land ping */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100447 pcwd_private.next_heartbeat = jiffies + (heartbeat * HZ);
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100448
449 if (debug >= DEBUG)
450 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return 0;
453}
454
455static int pcwd_set_heartbeat(int t)
456{
457 if ((t < 2) || (t > 7200)) /* arbitrary upper limit */
458 return -EINVAL;
459
460 heartbeat = t;
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100461
462 if (debug >= VERBOSE)
463 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
464 heartbeat);
465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 return 0;
467}
468
469static int pcwd_get_status(int *status)
470{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100471 int control_status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
473 *status=0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100474 spin_lock(&pcwd_private.io_lock);
475 if (pcwd_private.revision == PCWD_REVISION_A)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 /* Rev A cards return status information from
477 * the base register, which is used for the
478 * temperature in other cards. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100479 control_status = inb(pcwd_private.io_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 else {
481 /* Rev C cards return card status in the base
482 * address + 1 register. And use different bits
483 * to indicate a card initiated reset, and an
484 * over-temperature condition. And the reboot
485 * status can be reset. */
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100486 control_status = inb(pcwd_private.io_addr + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 }
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100488 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100490 if (pcwd_private.revision == PCWD_REVISION_A) {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100491 if (control_status & WD_WDRST)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 *status |= WDIOF_CARDRESET;
493
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100494 if (control_status & WD_T110) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 *status |= WDIOF_OVERHEAT;
496 if (temp_panic) {
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000497 printk(KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600498 kernel_power_off();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100499 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 }
501 }
502 } else {
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100503 if (control_status & WD_REVC_WTRP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 *status |= WDIOF_CARDRESET;
505
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100506 if (control_status & WD_REVC_TTRP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 *status |= WDIOF_OVERHEAT;
508 if (temp_panic) {
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000509 printk(KERN_INFO PFX "Temperature overheat trip!\n");
Eric W. Biederman68acc052005-07-26 12:03:08 -0600510 kernel_power_off();
Wim Van Sebroeck369fa252006-02-12 17:44:57 +0100511 /* or should we just do a: panic(PFX "Temperature overheat trip!\n"); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 }
513 }
514 }
515
516 return 0;
517}
518
519static int pcwd_clear_status(void)
520{
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100521 int control_status;
522
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100523 if (pcwd_private.revision == PCWD_REVISION_C) {
524 spin_lock(&pcwd_private.io_lock);
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100525
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100526 if (debug >= VERBOSE)
527 printk(KERN_INFO PFX "clearing watchdog trip status\n");
528
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100529 control_status = inb_p(pcwd_private.io_addr + 1);
530
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100531 if (debug >= DEBUG) {
532 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
533 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
534 (control_status & WD_REVC_R2DS));
535 }
536
Wim Van Sebroeck4206f0c2006-02-12 16:37:36 +0100537 /* clear reset status & Keep Relay 2 disable state as it is */
538 outb_p((control_status & WD_REVC_R2DS), pcwd_private.io_addr + 1);
539
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100540 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 }
542 return 0;
543}
544
545static int pcwd_get_temperature(int *temperature)
546{
547 /* check that port 0 gives temperature info and no command results */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100548 if (pcwd_private.command_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 return -1;
550
551 *temperature = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100552 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 return -ENODEV;
554
555 /*
556 * Convert celsius to fahrenheit, since this was
557 * the decided 'standard' for this return value.
558 */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100559 spin_lock(&pcwd_private.io_lock);
560 *temperature = ((inb(pcwd_private.io_addr)) * 9 / 5) + 32;
561 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100563 if (debug >= DEBUG) {
564 printk(KERN_DEBUG PFX "temperature is: %d F\n",
565 *temperature);
566 }
567
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 return 0;
569}
570
571/*
572 * /dev/watchdog handling
573 */
574
575static int pcwd_ioctl(struct inode *inode, struct file *file,
576 unsigned int cmd, unsigned long arg)
577{
578 int rv;
579 int status;
580 int temperature;
581 int new_heartbeat;
582 int __user *argp = (int __user *)arg;
583 static struct watchdog_info ident = {
584 .options = WDIOF_OVERHEAT |
585 WDIOF_CARDRESET |
586 WDIOF_KEEPALIVEPING |
587 WDIOF_SETTIMEOUT |
588 WDIOF_MAGICCLOSE,
589 .firmware_version = 1,
590 .identity = "PCWD",
591 };
592
593 switch(cmd) {
594 default:
Samuel Tardieu795b89d2006-09-09 17:34:31 +0200595 return -ENOTTY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
597 case WDIOC_GETSUPPORT:
598 if(copy_to_user(argp, &ident, sizeof(ident)))
599 return -EFAULT;
600 return 0;
601
602 case WDIOC_GETSTATUS:
603 pcwd_get_status(&status);
604 return put_user(status, argp);
605
606 case WDIOC_GETBOOTSTATUS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100607 return put_user(pcwd_private.boot_status, argp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 case WDIOC_GETTEMP:
610 if (pcwd_get_temperature(&temperature))
611 return -EFAULT;
612
613 return put_user(temperature, argp);
614
615 case WDIOC_SETOPTIONS:
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100616 if (pcwd_private.revision == PCWD_REVISION_C)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 {
618 if(copy_from_user(&rv, argp, sizeof(int)))
619 return -EFAULT;
620
621 if (rv & WDIOS_DISABLECARD)
622 {
623 return pcwd_stop();
624 }
625
626 if (rv & WDIOS_ENABLECARD)
627 {
628 return pcwd_start();
629 }
630
631 if (rv & WDIOS_TEMPPANIC)
632 {
633 temp_panic = 1;
634 }
635 }
636 return -EINVAL;
637
638 case WDIOC_KEEPALIVE:
639 pcwd_keepalive();
640 return 0;
641
642 case WDIOC_SETTIMEOUT:
643 if (get_user(new_heartbeat, argp))
644 return -EFAULT;
645
646 if (pcwd_set_heartbeat(new_heartbeat))
647 return -EINVAL;
648
649 pcwd_keepalive();
650 /* Fall */
651
652 case WDIOC_GETTIMEOUT:
653 return put_user(heartbeat, argp);
654 }
655
656 return 0;
657}
658
659static ssize_t pcwd_write(struct file *file, const char __user *buf, size_t len,
660 loff_t *ppos)
661{
662 if (len) {
663 if (!nowayout) {
664 size_t i;
665
666 /* In case it was set long ago */
667 expect_close = 0;
668
669 for (i = 0; i != len; i++) {
670 char c;
671
672 if (get_user(c, buf + i))
673 return -EFAULT;
674 if (c == 'V')
675 expect_close = 42;
676 }
677 }
678 pcwd_keepalive();
679 }
680 return len;
681}
682
683static int pcwd_open(struct inode *inode, struct file *file)
684{
685 if (!atomic_dec_and_test(&open_allowed) ) {
Wim Van Sebroeckc324ab42006-02-12 17:12:55 +0100686 if (debug >= VERBOSE)
687 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 atomic_inc( &open_allowed );
689 return -EBUSY;
690 }
691
692 if (nowayout)
693 __module_get(THIS_MODULE);
694
695 /* Activate */
696 pcwd_start();
697 pcwd_keepalive();
698 return nonseekable_open(inode, file);
699}
700
701static int pcwd_close(struct inode *inode, struct file *file)
702{
703 if (expect_close == 42) {
704 pcwd_stop();
705 } else {
706 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
707 pcwd_keepalive();
708 }
709 expect_close = 0;
710 atomic_inc( &open_allowed );
711 return 0;
712}
713
714/*
715 * /dev/temperature handling
716 */
717
718static ssize_t pcwd_temp_read(struct file *file, char __user *buf, size_t count,
719 loff_t *ppos)
720{
721 int temperature;
722
723 if (pcwd_get_temperature(&temperature))
724 return -EFAULT;
725
726 if (copy_to_user(buf, &temperature, 1))
727 return -EFAULT;
728
729 return 1;
730}
731
732static int pcwd_temp_open(struct inode *inode, struct file *file)
733{
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100734 if (!pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 return -ENODEV;
736
737 return nonseekable_open(inode, file);
738}
739
740static int pcwd_temp_close(struct inode *inode, struct file *file)
741{
742 return 0;
743}
744
745/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 * Kernel Interfaces
747 */
748
Arjan van de Ven62322d22006-07-03 00:24:21 -0700749static const struct file_operations pcwd_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 .owner = THIS_MODULE,
751 .llseek = no_llseek,
752 .write = pcwd_write,
753 .ioctl = pcwd_ioctl,
754 .open = pcwd_open,
755 .release = pcwd_close,
756};
757
758static struct miscdevice pcwd_miscdev = {
759 .minor = WATCHDOG_MINOR,
760 .name = "watchdog",
761 .fops = &pcwd_fops,
762};
763
Arjan van de Ven62322d22006-07-03 00:24:21 -0700764static const struct file_operations pcwd_temp_fops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 .owner = THIS_MODULE,
766 .llseek = no_llseek,
767 .read = pcwd_temp_read,
768 .open = pcwd_temp_open,
769 .release = pcwd_temp_close,
770};
771
772static struct miscdevice temp_miscdev = {
773 .minor = TEMP_MINOR,
774 .name = "temperature",
775 .fops = &pcwd_temp_fops,
776};
777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778/*
779 * Init & exit routines
780 */
781
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782static inline int get_revision(void)
783{
784 int r = PCWD_REVISION_C;
785
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100786 spin_lock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 /* REV A cards use only 2 io ports; test
788 * presumes a floating bus reads as 0xff. */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100789 if ((inb(pcwd_private.io_addr + 2) == 0xFF) ||
790 (inb(pcwd_private.io_addr + 3) == 0xFF))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 r=PCWD_REVISION_A;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100792 spin_unlock(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 return r;
795}
796
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000797/*
798 * The ISA cards have a heartbeat bit in one of the registers, which
799 * register is card dependent. The heartbeat bit is monitored, and if
800 * found, is considered proof that a Berkshire card has been found.
801 * The initial rate is once per second at board start up, then twice
802 * per second for normal operation.
803 */
804static int __devinit pcwd_isa_match(struct device *dev, unsigned int id)
805{
806 int base_addr=pcwd_ioports[id];
807 int port0, last_port0; /* Reg 0, in case it's REV A */
808 int port1, last_port1; /* Register 1 for REV C cards */
809 int i;
810 int retval;
811
812 if (debug >= DEBUG)
813 printk(KERN_DEBUG PFX "pcwd_isa_match id=%d\n",
814 id);
815
816 if (!request_region (base_addr, 4, "PCWD")) {
817 printk(KERN_INFO PFX "Port 0x%04x unavailable\n", base_addr);
818 return 0;
819 }
820
821 retval = 0;
822
823 port0 = inb_p(base_addr); /* For REV A boards */
824 port1 = inb_p(base_addr + 1); /* For REV C boards */
825 if (port0 != 0xff || port1 != 0xff) {
826 /* Not an 'ff' from a floating bus, so must be a card! */
827 for (i = 0; i < 4; ++i) {
828
829 msleep(500);
830
831 last_port0 = port0;
832 last_port1 = port1;
833
834 port0 = inb_p(base_addr);
835 port1 = inb_p(base_addr + 1);
836
837 /* Has either hearbeat bit changed? */
838 if ((port0 ^ last_port0) & WD_HRTBT ||
839 (port1 ^ last_port1) & WD_REVC_HRBT) {
840 retval = 1;
841 break;
842 }
843 }
844 }
845 release_region (base_addr, 4);
846
847 return retval;
848}
849
850static int __devinit pcwd_isa_probe(struct device *dev, unsigned int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851{
852 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000854 if (debug >= DEBUG)
855 printk(KERN_DEBUG PFX "pcwd_isa_probe id=%d\n",
856 id);
857
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 cards_found++;
859 if (cards_found == 1)
860 printk(KERN_INFO PFX "v%s Ken Hollis (kenji@bitgate.com)\n", WD_VER);
861
862 if (cards_found > 1) {
863 printk(KERN_ERR PFX "This driver only supports 1 device\n");
864 return -ENODEV;
865 }
866
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000867 if (pcwd_ioports[id] == 0x0000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
869 return -ENODEV;
870 }
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000871 pcwd_private.io_addr = pcwd_ioports[id];
872
873 spin_lock_init(&pcwd_private.io_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
875 /* Check card's revision */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100876 pcwd_private.revision = get_revision();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100878 if (!request_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4, "PCWD")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100880 pcwd_private.io_addr);
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000881 ret=-EIO;
882 goto error_request_region;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 }
884
885 /* Initial variables */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100886 pcwd_private.supports_temp = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 temp_panic = 0;
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100888 pcwd_private.boot_status = 0x0000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
890 /* get the boot_status */
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100891 pcwd_get_status(&pcwd_private.boot_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
893 /* clear the "card caused reboot" flag */
894 pcwd_clear_status();
895
Jiri Slaby82eb7c52007-02-08 18:39:36 +0100896 setup_timer(&pcwd_private.timer, pcwd_timer_ping, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898 /* Disable the board */
899 pcwd_stop();
900
901 /* Check whether or not the card supports the temperature device */
Wim Van Sebroeck85875212006-01-09 21:59:39 +0100902 pcwd_check_temperature_support();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
Wim Van Sebroeckaf3b38d2006-01-09 22:03:41 +0100904 /* Show info about the card itself */
905 pcwd_show_card_info();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906
Wim Van Sebroeckf3dc0732007-01-09 22:43:49 +0100907 /* If heartbeat = 0 then we use the heartbeat from the dip-switches */
908 if (heartbeat == 0)
909 heartbeat = heartbeat_tbl[(pcwd_get_option_switches() & 0x07)];
910
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 /* Check that the heartbeat value is within it's range ; if not reset to the default */
Wim Van Sebroeckfd41fa62005-12-10 14:22:37 +0100912 if (pcwd_set_heartbeat(heartbeat)) {
913 pcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
914 printk(KERN_INFO PFX "heartbeat value must be 2<=heartbeat<=7200, using %d\n",
915 WATCHDOG_HEARTBEAT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
917
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100918 if (pcwd_private.supports_temp) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 ret = misc_register(&temp_miscdev);
920 if (ret) {
921 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
922 TEMP_MINOR, ret);
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000923 goto error_misc_register_temp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925 }
926
927 ret = misc_register(&pcwd_miscdev);
928 if (ret) {
929 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
930 WATCHDOG_MINOR, ret);
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000931 goto error_misc_register_watchdog;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933
934 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
935 heartbeat, nowayout);
936
937 return 0;
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000938
939error_misc_register_watchdog:
940 if (pcwd_private.supports_temp)
941 misc_deregister(&temp_miscdev);
942error_misc_register_temp:
943 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
944error_request_region:
945 pcwd_private.io_addr = 0x0000;
946 cards_found--;
947 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948}
949
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000950static int __devexit pcwd_isa_remove(struct device *dev, unsigned int id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951{
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000952 if (debug >= DEBUG)
953 printk(KERN_DEBUG PFX "pcwd_isa_remove id=%d\n",
954 id);
955
956 if (!pcwd_private.io_addr)
957 return 1;
958
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 /* Disable the board */
960 if (!nowayout)
961 pcwd_stop();
962
963 /* Deregister */
964 misc_deregister(&pcwd_miscdev);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100965 if (pcwd_private.supports_temp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 misc_deregister(&temp_miscdev);
Wim Van Sebroecka2be8782006-01-09 21:53:33 +0100967 release_region(pcwd_private.io_addr, (pcwd_private.revision == PCWD_REVISION_A) ? 2 : 4);
968 pcwd_private.io_addr = 0x0000;
Wim Van Sebroeckf1c3a052005-12-10 14:36:24 +0100969 cards_found--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970
971 return 0;
972}
973
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +0000974static void pcwd_isa_shutdown(struct device *dev, unsigned int id)
975{
976 if (debug >= DEBUG)
977 printk(KERN_DEBUG PFX "pcwd_isa_shutdown id=%d\n",
978 id);
979
980 pcwd_stop();
981}
982
983static struct isa_driver pcwd_isa_driver = {
984 .match = pcwd_isa_match,
985 .probe = pcwd_isa_probe,
986 .remove = __devexit_p(pcwd_isa_remove),
987 .shutdown = pcwd_isa_shutdown,
988 .driver = {
989 .owner = THIS_MODULE,
990 .name = WATCHDOG_NAME,
991 },
992};
993
994static int __init pcwd_init_module(void)
995{
996 return isa_register_driver(&pcwd_isa_driver, PCWD_ISA_NR_CARDS);
997}
998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999static void __exit pcwd_cleanup_module(void)
1000{
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +00001001 isa_unregister_driver(&pcwd_isa_driver);
Wim Van Sebroeck369fa252006-02-12 17:44:57 +01001002 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003}
1004
1005module_init(pcwd_init_module);
1006module_exit(pcwd_cleanup_module);
1007
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +00001008MODULE_AUTHOR("Ken Hollis <kenji@bitgate.com>, Wim Van Sebroeck <wim@iguana.be>");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009MODULE_DESCRIPTION("Berkshire ISA-PC Watchdog driver");
Wim Van Sebroeck5aa15052007-05-05 05:48:23 +00001010MODULE_VERSION(WATCHDOG_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011MODULE_LICENSE("GPL");
1012MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
1013MODULE_ALIAS_MISCDEV(TEMP_MINOR);