| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *	Industrial Computer Source PCI-WDT500/501 driver | 
 | 3 |  * | 
| Alan Cox | 29fa058 | 2008-10-27 15:17:56 +0000 | [diff] [blame] | 4 |  *	(c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>, | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 5 |  *						All Rights Reserved. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 |  * | 
 | 7 |  *	This program is free software; you can redistribute it and/or | 
 | 8 |  *	modify it under the terms of the GNU General Public License | 
 | 9 |  *	as published by the Free Software Foundation; either version | 
 | 10 |  *	2 of the License, or (at your option) any later version. | 
 | 11 |  * | 
 | 12 |  *	Neither Alan Cox nor CymruNet Ltd. admit liability nor provide | 
 | 13 |  *	warranty for any of this software. This material is provided | 
 | 14 |  *	"AS-IS" and at no charge. | 
 | 15 |  * | 
 | 16 |  *	(c) Copyright 1995    Alan Cox <alan@lxorguk.ukuu.org.uk> | 
 | 17 |  * | 
 | 18 |  *	Release 0.10. | 
 | 19 |  * | 
 | 20 |  *	Fixes | 
 | 21 |  *		Dave Gregorich	:	Modularisation and minor bugs | 
 | 22 |  *		Alan Cox	:	Added the watchdog ioctl() stuff | 
 | 23 |  *		Alan Cox	:	Fixed the reboot problem (as noted by | 
 | 24 |  *					Matt Crocker). | 
 | 25 |  *		Alan Cox	:	Added wdt= boot option | 
 | 26 |  *		Alan Cox	:	Cleaned up copy/user stuff | 
 | 27 |  *		Tim Hockin	:	Added insmod parameters, comment cleanup | 
 | 28 |  *					Parameterized timeout | 
 | 29 |  *		JP Nollmann	:	Added support for PCI wdt501p | 
 | 30 |  *		Alan Cox	:	Split ISA and PCI cards into two drivers | 
 | 31 |  *		Jeff Garzik	:	PCI cleanups | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 32 |  *		Tigran Aivazian	:	Restructured wdtpci_init_one() to handle | 
 | 33 |  *					failures | 
| Wim Van Sebroeck | 5f3b275 | 2011-02-23 20:04:38 +0000 | [diff] [blame] | 34 |  *		Joel Becker	:	Added WDIOC_GET/SETTIMEOUT | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 35 |  *		Zwane Mwaikambo	:	Magic char closing, locking changes, | 
 | 36 |  *					cleanups | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 |  *		Matt Domsch	:	nowayout module option | 
 | 38 |  */ | 
 | 39 |  | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 40 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 
 | 41 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/interrupt.h> | 
 | 43 | #include <linux/module.h> | 
 | 44 | #include <linux/moduleparam.h> | 
 | 45 | #include <linux/types.h> | 
 | 46 | #include <linux/miscdevice.h> | 
 | 47 | #include <linux/watchdog.h> | 
 | 48 | #include <linux/ioport.h> | 
| Andrew Morton | 8183006 | 2008-08-04 17:56:02 +0100 | [diff] [blame] | 49 | #include <linux/delay.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/notifier.h> | 
 | 51 | #include <linux/reboot.h> | 
 | 52 | #include <linux/init.h> | 
 | 53 | #include <linux/fs.h> | 
 | 54 | #include <linux/pci.h> | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 55 | #include <linux/io.h> | 
 | 56 | #include <linux/uaccess.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
 | 59 | #define WDT_IS_PCI | 
 | 60 | #include "wd501p.h" | 
 | 61 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | /* We can only use 1 card due to the /dev/watchdog restriction */ | 
 | 63 | static int dev_count; | 
 | 64 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 65 | static unsigned long open_lock; | 
| Alexey Dobriyan | c7dfd0c | 2007-11-01 16:27:08 -0700 | [diff] [blame] | 66 | static DEFINE_SPINLOCK(wdtpci_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | static char expect_close; | 
 | 68 |  | 
| Randy Dunlap | d1833c2 | 2009-08-07 15:02:00 -0700 | [diff] [blame] | 69 | static resource_size_t io; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static int irq; | 
 | 71 |  | 
 | 72 | /* Default timeout */ | 
 | 73 | #define WD_TIMO 60			/* Default heartbeat = 60 seconds */ | 
 | 74 |  | 
 | 75 | static int heartbeat = WD_TIMO; | 
 | 76 | static int wd_heartbeat; | 
 | 77 | module_param(heartbeat, int, 0); | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 78 | MODULE_PARM_DESC(heartbeat, | 
 | 79 | 		"Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" | 
 | 80 | 				__MODULE_STRING(WD_TIMO) ")"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 |  | 
| Wim Van Sebroeck | 86a1e18 | 2012-03-05 16:51:11 +0100 | [diff] [blame] | 82 | static bool nowayout = WATCHDOG_NOWAYOUT; | 
 | 83 | module_param(nowayout, bool, 0); | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 84 | MODULE_PARM_DESC(nowayout, | 
 | 85 | 		"Watchdog cannot be stopped once started (default=" | 
 | 86 | 				__MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | /* Support for the Fan Tachometer on the PCI-WDT501 */ | 
 | 89 | static int tachometer; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | module_param(tachometer, int, 0); | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 91 | MODULE_PARM_DESC(tachometer, | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 92 | 		"PCI-WDT501 Fan Tachometer support (0=disable, default=0)"); | 
 | 93 |  | 
 | 94 | static int type = 500; | 
 | 95 | module_param(type, int, 0); | 
 | 96 | MODULE_PARM_DESC(type, | 
 | 97 | 		"PCI-WDT501 Card type (500 or 501 , default=500)"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 |  | 
 | 99 | /* | 
 | 100 |  *	Programming support | 
 | 101 |  */ | 
 | 102 |  | 
 | 103 | static void wdtpci_ctr_mode(int ctr, int mode) | 
 | 104 | { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 105 | 	ctr <<= 6; | 
 | 106 | 	ctr |= 0x30; | 
 | 107 | 	ctr |= (mode << 1); | 
 | 108 | 	outb(ctr, WDT_CR); | 
 | 109 | 	udelay(8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | } | 
 | 111 |  | 
 | 112 | static void wdtpci_ctr_load(int ctr, int val) | 
 | 113 | { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 114 | 	outb(val & 0xFF, WDT_COUNT0 + ctr); | 
 | 115 | 	udelay(8); | 
 | 116 | 	outb(val >> 8, WDT_COUNT0 + ctr); | 
 | 117 | 	udelay(8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } | 
 | 119 |  | 
 | 120 | /** | 
 | 121 |  *	wdtpci_start: | 
 | 122 |  * | 
 | 123 |  *	Start the watchdog driver. | 
 | 124 |  */ | 
 | 125 |  | 
 | 126 | static int wdtpci_start(void) | 
 | 127 | { | 
 | 128 | 	unsigned long flags; | 
 | 129 |  | 
 | 130 | 	spin_lock_irqsave(&wdtpci_lock, flags); | 
 | 131 |  | 
 | 132 | 	/* | 
 | 133 | 	 * "pet" the watchdog, as Access says. | 
 | 134 | 	 * This resets the clock outputs. | 
 | 135 | 	 */ | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 136 | 	inb(WDT_DC);			/* Disable watchdog */ | 
 | 137 | 	udelay(8); | 
 | 138 | 	wdtpci_ctr_mode(2, 0);		/* Program CTR2 for Mode 0: | 
 | 139 | 						Pulse on Terminal Count */ | 
 | 140 | 	outb(0, WDT_DC);		/* Enable watchdog */ | 
 | 141 | 	udelay(8); | 
 | 142 | 	inb(WDT_DC);			/* Disable watchdog */ | 
 | 143 | 	udelay(8); | 
 | 144 | 	outb(0, WDT_CLOCK);		/* 2.0833MHz clock */ | 
 | 145 | 	udelay(8); | 
 | 146 | 	inb(WDT_BUZZER);		/* disable */ | 
 | 147 | 	udelay(8); | 
 | 148 | 	inb(WDT_OPTONOTRST);		/* disable */ | 
 | 149 | 	udelay(8); | 
 | 150 | 	inb(WDT_OPTORST);		/* disable */ | 
 | 151 | 	udelay(8); | 
 | 152 | 	inb(WDT_PROGOUT);		/* disable */ | 
 | 153 | 	udelay(8); | 
 | 154 | 	wdtpci_ctr_mode(0, 3);		/* Program CTR0 for Mode 3: | 
 | 155 | 						Square Wave Generator */ | 
 | 156 | 	wdtpci_ctr_mode(1, 2);		/* Program CTR1 for Mode 2: | 
 | 157 | 						Rate Generator */ | 
 | 158 | 	wdtpci_ctr_mode(2, 1);		/* Program CTR2 for Mode 1: | 
 | 159 | 						Retriggerable One-Shot */ | 
 | 160 | 	wdtpci_ctr_load(0, 20833);	/* count at 100Hz */ | 
 | 161 | 	wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | 	/* DO NOT LOAD CTR2 on PCI card! -- JPN */ | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 163 | 	outb(0, WDT_DC);		/* Enable watchdog */ | 
 | 164 | 	udelay(8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 |  | 
 | 166 | 	spin_unlock_irqrestore(&wdtpci_lock, flags); | 
 | 167 | 	return 0; | 
 | 168 | } | 
 | 169 |  | 
 | 170 | /** | 
 | 171 |  *	wdtpci_stop: | 
 | 172 |  * | 
 | 173 |  *	Stop the watchdog driver. | 
 | 174 |  */ | 
 | 175 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 176 | static int wdtpci_stop(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { | 
 | 178 | 	unsigned long flags; | 
 | 179 |  | 
 | 180 | 	/* Turn the card off */ | 
 | 181 | 	spin_lock_irqsave(&wdtpci_lock, flags); | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 182 | 	inb(WDT_DC);			/* Disable watchdog */ | 
 | 183 | 	udelay(8); | 
 | 184 | 	wdtpci_ctr_load(2, 0);		/* 0 length reset pulses now */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | 	spin_unlock_irqrestore(&wdtpci_lock, flags); | 
 | 186 | 	return 0; | 
 | 187 | } | 
 | 188 |  | 
 | 189 | /** | 
 | 190 |  *	wdtpci_ping: | 
 | 191 |  * | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 192 |  *	Reload counter one with the watchdog heartbeat. We don't bother | 
 | 193 |  *	reloading the cascade counter. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 |  */ | 
 | 195 |  | 
 | 196 | static int wdtpci_ping(void) | 
 | 197 | { | 
 | 198 | 	unsigned long flags; | 
 | 199 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | 	spin_lock_irqsave(&wdtpci_lock, flags); | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 201 | 	/* Write a watchdog value */ | 
 | 202 | 	inb(WDT_DC);			/* Disable watchdog */ | 
 | 203 | 	udelay(8); | 
 | 204 | 	wdtpci_ctr_mode(1, 2);		/* Re-Program CTR1 for Mode 2: | 
 | 205 | 							Rate Generator */ | 
 | 206 | 	wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */ | 
 | 207 | 	outb(0, WDT_DC);		/* Enable watchdog */ | 
 | 208 | 	udelay(8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | 	spin_unlock_irqrestore(&wdtpci_lock, flags); | 
 | 210 | 	return 0; | 
 | 211 | } | 
 | 212 |  | 
 | 213 | /** | 
 | 214 |  *	wdtpci_set_heartbeat: | 
 | 215 |  *	@t:		the new heartbeat value that needs to be set. | 
 | 216 |  * | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 217 |  *	Set a new heartbeat value for the watchdog device. If the heartbeat | 
 | 218 |  *	value is incorrect we keep the old value and return -EINVAL. | 
 | 219 |  *	If successful we return 0. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 |  */ | 
 | 221 | static int wdtpci_set_heartbeat(int t) | 
 | 222 | { | 
 | 223 | 	/* Arbitrary, can't find the card's limits */ | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 224 | 	if (t < 1 || t > 65535) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | 		return -EINVAL; | 
 | 226 |  | 
 | 227 | 	heartbeat = t; | 
 | 228 | 	wd_heartbeat = t * 100; | 
 | 229 | 	return 0; | 
 | 230 | } | 
 | 231 |  | 
 | 232 | /** | 
 | 233 |  *	wdtpci_get_status: | 
 | 234 |  *	@status:		the new status. | 
 | 235 |  * | 
 | 236 |  *	Extract the status information from a WDT watchdog device. There are | 
 | 237 |  *	several board variants so we have to know which bits are valid. Some | 
 | 238 |  *	bits default to one and some to zero in order to be maximally painful. | 
 | 239 |  * | 
 | 240 |  *	we then map the bits onto the status ioctl flags. | 
 | 241 |  */ | 
 | 242 |  | 
 | 243 | static int wdtpci_get_status(int *status) | 
 | 244 | { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 245 | 	unsigned char new_status; | 
 | 246 | 	unsigned long flags; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 248 | 	spin_lock_irqsave(&wdtpci_lock, flags); | 
 | 249 | 	new_status = inb(WDT_SR); | 
 | 250 | 	spin_unlock_irqrestore(&wdtpci_lock, flags); | 
 | 251 |  | 
 | 252 | 	*status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | 	if (new_status & WDC_SR_ISOI0) | 
 | 254 | 		*status |= WDIOF_EXTERN1; | 
 | 255 | 	if (new_status & WDC_SR_ISII1) | 
 | 256 | 		*status |= WDIOF_EXTERN2; | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 257 | 	if (type == 501) { | 
 | 258 | 		if (!(new_status & WDC_SR_TGOOD)) | 
 | 259 | 			*status |= WDIOF_OVERHEAT; | 
 | 260 | 		if (!(new_status & WDC_SR_PSUOVER)) | 
 | 261 | 			*status |= WDIOF_POWEROVER; | 
 | 262 | 		if (!(new_status & WDC_SR_PSUUNDR)) | 
 | 263 | 			*status |= WDIOF_POWERUNDER; | 
 | 264 | 		if (tachometer) { | 
 | 265 | 			if (!(new_status & WDC_SR_FANGOOD)) | 
 | 266 | 				*status |= WDIOF_FANFAULT; | 
 | 267 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | 	return 0; | 
 | 270 | } | 
 | 271 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | /** | 
 | 273 |  *	wdtpci_get_temperature: | 
 | 274 |  * | 
 | 275 |  *	Reports the temperature in degrees Fahrenheit. The API is in | 
 | 276 |  *	farenheit. It was designed by an imperial measurement luddite. | 
 | 277 |  */ | 
 | 278 |  | 
 | 279 | static int wdtpci_get_temperature(int *temperature) | 
 | 280 | { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 281 | 	unsigned short c; | 
 | 282 | 	unsigned long flags; | 
 | 283 | 	spin_lock_irqsave(&wdtpci_lock, flags); | 
 | 284 | 	c = inb(WDT_RT); | 
 | 285 | 	udelay(8); | 
 | 286 | 	spin_unlock_irqrestore(&wdtpci_lock, flags); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | 	*temperature = (c * 11 / 15) + 7; | 
 | 288 | 	return 0; | 
 | 289 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 |  | 
 | 291 | /** | 
 | 292 |  *	wdtpci_interrupt: | 
 | 293 |  *	@irq:		Interrupt number | 
 | 294 |  *	@dev_id:	Unused as we don't allow multiple devices. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 |  * | 
 | 296 |  *	Handle an interrupt from the board. These are raised when the status | 
 | 297 |  *	map changes in what the board considers an interesting way. That means | 
 | 298 |  *	a failure condition occurring. | 
 | 299 |  */ | 
 | 300 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 301 | static irqreturn_t wdtpci_interrupt(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { | 
 | 303 | 	/* | 
 | 304 | 	 *	Read the status register see what is up and | 
 | 305 | 	 *	then printk it. | 
 | 306 | 	 */ | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 307 | 	unsigned char status; | 
 | 308 |  | 
 | 309 | 	spin_lock(&wdtpci_lock); | 
 | 310 |  | 
 | 311 | 	status = inb(WDT_SR); | 
 | 312 | 	udelay(8); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 |  | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 314 | 	pr_crit("status %d\n", status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 |  | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 316 | 	if (type == 501) { | 
 | 317 | 		if (!(status & WDC_SR_TGOOD)) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 318 | 			pr_crit("Overheat alarm (%d)\n", inb(WDT_RT)); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 319 | 			udelay(8); | 
 | 320 | 		} | 
 | 321 | 		if (!(status & WDC_SR_PSUOVER)) | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 322 | 			pr_crit("PSU over voltage\n"); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 323 | 		if (!(status & WDC_SR_PSUUNDR)) | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 324 | 			pr_crit("PSU under voltage\n"); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 325 | 		if (tachometer) { | 
 | 326 | 			if (!(status & WDC_SR_FANGOOD)) | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 327 | 				pr_crit("Possible fan fault\n"); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 328 | 		} | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 329 | 	} | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 330 | 	if (!(status & WDC_SR_WCCR)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | #ifdef SOFTWARE_REBOOT | 
 | 332 | #ifdef ONLY_TESTING | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 333 | 		pr_crit("Would Reboot\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | #else | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 335 | 		pr_crit("Initiating system reboot\n"); | 
| Eric W. Biederman | f82567e | 2005-07-26 11:53:19 -0600 | [diff] [blame] | 336 | 		emergency_restart(NULL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | #endif | 
 | 338 | #else | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 339 | 		pr_crit("Reset in 5ms\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | #endif | 
| Ilpo Jarvinen | 59338d4 | 2007-10-23 13:40:54 -0700 | [diff] [blame] | 341 | 	} | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 342 | 	spin_unlock(&wdtpci_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | 	return IRQ_HANDLED; | 
 | 344 | } | 
 | 345 |  | 
 | 346 |  | 
 | 347 | /** | 
 | 348 |  *	wdtpci_write: | 
 | 349 |  *	@file: file handle to the watchdog | 
 | 350 |  *	@buf: buffer to write (unused as data does not matter here | 
 | 351 |  *	@count: count of bytes | 
 | 352 |  *	@ppos: pointer to the position to write. No seeks allowed | 
 | 353 |  * | 
 | 354 |  *	A write to a watchdog device is defined as a keepalive signal. Any | 
 | 355 |  *	write of data will do, as we we don't define content meaning. | 
 | 356 |  */ | 
 | 357 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 358 | static ssize_t wdtpci_write(struct file *file, const char __user *buf, | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 359 | 						size_t count, loff_t *ppos) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | { | 
 | 361 | 	if (count) { | 
 | 362 | 		if (!nowayout) { | 
 | 363 | 			size_t i; | 
 | 364 |  | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 365 | 			/* In case it was set long ago */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | 			expect_close = 0; | 
 | 367 |  | 
 | 368 | 			for (i = 0; i != count; i++) { | 
 | 369 | 				char c; | 
| Wim Van Sebroeck | 7944d3a | 2008-08-06 20:19:41 +0000 | [diff] [blame] | 370 | 				if (get_user(c, buf + i)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | 					return -EFAULT; | 
 | 372 | 				if (c == 'V') | 
 | 373 | 					expect_close = 42; | 
 | 374 | 			} | 
 | 375 | 		} | 
 | 376 | 		wdtpci_ping(); | 
 | 377 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | 	return count; | 
 | 379 | } | 
 | 380 |  | 
 | 381 | /** | 
 | 382 |  *	wdtpci_ioctl: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 |  *	@file: file handle to the device | 
 | 384 |  *	@cmd: watchdog command | 
 | 385 |  *	@arg: argument pointer | 
 | 386 |  * | 
 | 387 |  *	The watchdog API defines a common set of functions for all watchdogs | 
 | 388 |  *	according to their available features. We only actually usefully support | 
 | 389 |  *	querying capabilities and current status. | 
 | 390 |  */ | 
 | 391 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 392 | static long wdtpci_ioctl(struct file *file, unsigned int cmd, | 
 | 393 | 							unsigned long arg) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | 	void __user *argp = (void __user *)arg; | 
 | 396 | 	int __user *p = argp; | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 397 | 	int new_heartbeat; | 
 | 398 | 	int status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 |  | 
| Andrew Morton | c1bf3ac | 2010-03-03 11:57:40 -0800 | [diff] [blame] | 400 | 	struct watchdog_info ident = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | 		.options =		WDIOF_SETTIMEOUT| | 
 | 402 | 					WDIOF_MAGICCLOSE| | 
 | 403 | 					WDIOF_KEEPALIVEPING, | 
 | 404 | 		.firmware_version =	1, | 
 | 405 | 		.identity =		"PCI-WDT500/501", | 
 | 406 | 	}; | 
 | 407 |  | 
 | 408 | 	/* Add options according to the card we have */ | 
 | 409 | 	ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 410 | 	if (type == 501) { | 
 | 411 | 		ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER| | 
 | 412 | 							WDIOF_POWEROVER); | 
 | 413 | 		if (tachometer) | 
 | 414 | 			ident.options |= WDIOF_FANFAULT; | 
 | 415 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 417 | 	switch (cmd) { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 418 | 	case WDIOC_GETSUPPORT: | 
 | 419 | 		return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; | 
 | 420 | 	case WDIOC_GETSTATUS: | 
 | 421 | 		wdtpci_get_status(&status); | 
 | 422 | 		return put_user(status, p); | 
 | 423 | 	case WDIOC_GETBOOTSTATUS: | 
 | 424 | 		return put_user(0, p); | 
 | 425 | 	case WDIOC_KEEPALIVE: | 
 | 426 | 		wdtpci_ping(); | 
 | 427 | 		return 0; | 
 | 428 | 	case WDIOC_SETTIMEOUT: | 
 | 429 | 		if (get_user(new_heartbeat, p)) | 
 | 430 | 			return -EFAULT; | 
 | 431 | 		if (wdtpci_set_heartbeat(new_heartbeat)) | 
 | 432 | 			return -EINVAL; | 
 | 433 | 		wdtpci_ping(); | 
 | 434 | 		/* Fall */ | 
 | 435 | 	case WDIOC_GETTIMEOUT: | 
 | 436 | 		return put_user(heartbeat, p); | 
| Wim Van Sebroeck | 0c06090 | 2008-07-18 11:41:17 +0000 | [diff] [blame] | 437 | 	default: | 
 | 438 | 		return -ENOTTY; | 
 | 439 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | } | 
 | 441 |  | 
 | 442 | /** | 
 | 443 |  *	wdtpci_open: | 
 | 444 |  *	@inode: inode of device | 
 | 445 |  *	@file: file handle to device | 
 | 446 |  * | 
 | 447 |  *	The watchdog device has been opened. The watchdog device is single | 
 | 448 |  *	open and on opening we load the counters. Counter zero is a 100Hz | 
 | 449 |  *	cascade, into counter 1 which downcounts to reboot. When the counter | 
 | 450 |  *	triggers counter 2 downcounts the length of the reset pulse which | 
 | 451 |  *	set set to be as long as possible. | 
 | 452 |  */ | 
 | 453 |  | 
 | 454 | static int wdtpci_open(struct inode *inode, struct file *file) | 
 | 455 | { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 456 | 	if (test_and_set_bit(0, &open_lock)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | 		return -EBUSY; | 
 | 458 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 459 | 	if (nowayout) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | 		__module_get(THIS_MODULE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | 	/* | 
 | 462 | 	 *	Activate | 
 | 463 | 	 */ | 
 | 464 | 	wdtpci_start(); | 
 | 465 | 	return nonseekable_open(inode, file); | 
 | 466 | } | 
 | 467 |  | 
 | 468 | /** | 
 | 469 |  *	wdtpci_release: | 
 | 470 |  *	@inode: inode to board | 
 | 471 |  *	@file: file handle to board | 
 | 472 |  * | 
 | 473 |  *	The watchdog has a configurable API. There is a religious dispute | 
 | 474 |  *	between people who want their watchdog to be able to shut down and | 
 | 475 |  *	those who want to be sure if the watchdog manager dies the machine | 
 | 476 |  *	reboots. In the former case we disable the counters, in the latter | 
 | 477 |  *	case you have to open it again very soon. | 
 | 478 |  */ | 
 | 479 |  | 
 | 480 | static int wdtpci_release(struct inode *inode, struct file *file) | 
 | 481 | { | 
 | 482 | 	if (expect_close == 42) { | 
 | 483 | 		wdtpci_stop(); | 
 | 484 | 	} else { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 485 | 		pr_crit("Unexpected close, not stopping timer!\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | 		wdtpci_ping(); | 
 | 487 | 	} | 
 | 488 | 	expect_close = 0; | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 489 | 	clear_bit(0, &open_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | 	return 0; | 
 | 491 | } | 
 | 492 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | /** | 
 | 494 |  *	wdtpci_temp_read: | 
 | 495 |  *	@file: file handle to the watchdog board | 
 | 496 |  *	@buf: buffer to write 1 byte into | 
 | 497 |  *	@count: length of buffer | 
 | 498 |  *	@ptr: offset (no seek allowed) | 
 | 499 |  * | 
 | 500 |  *	Read reports the temperature in degrees Fahrenheit. The API is in | 
 | 501 |  *	fahrenheit. It was designed by an imperial measurement luddite. | 
 | 502 |  */ | 
 | 503 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 504 | static ssize_t wdtpci_temp_read(struct file *file, char __user *buf, | 
 | 505 | 						size_t count, loff_t *ptr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | { | 
 | 507 | 	int temperature; | 
 | 508 |  | 
 | 509 | 	if (wdtpci_get_temperature(&temperature)) | 
 | 510 | 		return -EFAULT; | 
 | 511 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 512 | 	if (copy_to_user(buf, &temperature, 1)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | 		return -EFAULT; | 
 | 514 |  | 
 | 515 | 	return 1; | 
 | 516 | } | 
 | 517 |  | 
 | 518 | /** | 
 | 519 |  *	wdtpci_temp_open: | 
 | 520 |  *	@inode: inode of device | 
 | 521 |  *	@file: file handle to device | 
 | 522 |  * | 
 | 523 |  *	The temperature device has been opened. | 
 | 524 |  */ | 
 | 525 |  | 
 | 526 | static int wdtpci_temp_open(struct inode *inode, struct file *file) | 
 | 527 | { | 
 | 528 | 	return nonseekable_open(inode, file); | 
 | 529 | } | 
 | 530 |  | 
 | 531 | /** | 
 | 532 |  *	wdtpci_temp_release: | 
 | 533 |  *	@inode: inode to board | 
 | 534 |  *	@file: file handle to board | 
 | 535 |  * | 
 | 536 |  *	The temperature device has been closed. | 
 | 537 |  */ | 
 | 538 |  | 
 | 539 | static int wdtpci_temp_release(struct inode *inode, struct file *file) | 
 | 540 | { | 
 | 541 | 	return 0; | 
 | 542 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 |  | 
 | 544 | /** | 
 | 545 |  *	notify_sys: | 
 | 546 |  *	@this: our notifier block | 
 | 547 |  *	@code: the event being reported | 
 | 548 |  *	@unused: unused | 
 | 549 |  * | 
 | 550 |  *	Our notifier is called on system shutdowns. We want to turn the card | 
 | 551 |  *	off at reboot otherwise the machine will reboot again during memory | 
 | 552 |  *	test or worse yet during the following fsck. This would suck, in fact | 
 | 553 |  *	trust me - if it happens it does suck. | 
 | 554 |  */ | 
 | 555 |  | 
 | 556 | static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code, | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 557 | 							void *unused) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | { | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 559 | 	if (code == SYS_DOWN || code == SYS_HALT) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | 		wdtpci_stop(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | 	return NOTIFY_DONE; | 
 | 562 | } | 
 | 563 |  | 
 | 564 | /* | 
 | 565 |  *	Kernel Interfaces | 
 | 566 |  */ | 
 | 567 |  | 
 | 568 |  | 
| Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 569 | static const struct file_operations wdtpci_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | 	.owner		= THIS_MODULE, | 
 | 571 | 	.llseek		= no_llseek, | 
 | 572 | 	.write		= wdtpci_write, | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 573 | 	.unlocked_ioctl	= wdtpci_ioctl, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | 	.open		= wdtpci_open, | 
 | 575 | 	.release	= wdtpci_release, | 
 | 576 | }; | 
 | 577 |  | 
 | 578 | static struct miscdevice wdtpci_miscdev = { | 
 | 579 | 	.minor	= WATCHDOG_MINOR, | 
 | 580 | 	.name	= "watchdog", | 
 | 581 | 	.fops	= &wdtpci_fops, | 
 | 582 | }; | 
 | 583 |  | 
| Arjan van de Ven | 62322d2 | 2006-07-03 00:24:21 -0700 | [diff] [blame] | 584 | static const struct file_operations wdtpci_temp_fops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | 	.owner		= THIS_MODULE, | 
 | 586 | 	.llseek		= no_llseek, | 
 | 587 | 	.read		= wdtpci_temp_read, | 
 | 588 | 	.open		= wdtpci_temp_open, | 
 | 589 | 	.release	= wdtpci_temp_release, | 
 | 590 | }; | 
 | 591 |  | 
 | 592 | static struct miscdevice temp_miscdev = { | 
 | 593 | 	.minor	= TEMP_MINOR, | 
 | 594 | 	.name	= "temperature", | 
 | 595 | 	.fops	= &wdtpci_temp_fops, | 
 | 596 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 |  | 
 | 598 | /* | 
 | 599 |  *	The WDT card needs to learn about soft shutdowns in order to | 
 | 600 |  *	turn the timebomb registers off. | 
 | 601 |  */ | 
 | 602 |  | 
 | 603 | static struct notifier_block wdtpci_notifier = { | 
 | 604 | 	.notifier_call = wdtpci_notify_sys, | 
 | 605 | }; | 
 | 606 |  | 
 | 607 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 608 | static int __devinit wdtpci_init_one(struct pci_dev *dev, | 
 | 609 | 					const struct pci_device_id *ent) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { | 
 | 611 | 	int ret = -EIO; | 
 | 612 |  | 
 | 613 | 	dev_count++; | 
 | 614 | 	if (dev_count > 1) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 615 | 		pr_err("This driver only supports one device\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | 		return -ENODEV; | 
 | 617 | 	} | 
 | 618 |  | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 619 | 	if (type != 500 && type != 501) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 620 | 		pr_err("unknown card type '%d'\n", type); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 621 | 		return -ENODEV; | 
 | 622 | 	} | 
 | 623 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 624 | 	if (pci_enable_device(dev)) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 625 | 		pr_err("Not possible to enable PCI Device\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | 		return -ENODEV; | 
 | 627 | 	} | 
 | 628 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 629 | 	if (pci_resource_start(dev, 2) == 0x0000) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 630 | 		pr_err("No I/O-Address for card detected\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | 		ret = -ENODEV; | 
 | 632 | 		goto out_pci; | 
 | 633 | 	} | 
 | 634 |  | 
| Wim Van Sebroeck | 119d3e5 | 2009-08-06 18:57:49 +0000 | [diff] [blame] | 635 | 	if (pci_request_region(dev, 2, "wdt_pci")) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 636 | 		pr_err("I/O address 0x%llx already in use\n", | 
 | 637 | 		       (unsigned long long)pci_resource_start(dev, 2)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | 		goto out_pci; | 
 | 639 | 	} | 
 | 640 |  | 
| Wim Van Sebroeck | 119d3e5 | 2009-08-06 18:57:49 +0000 | [diff] [blame] | 641 | 	irq = dev->irq; | 
 | 642 | 	io = pci_resource_start(dev, 2); | 
 | 643 |  | 
| Yong Zhang | 86b5912 | 2011-09-07 16:10:55 +0800 | [diff] [blame] | 644 | 	if (request_irq(irq, wdtpci_interrupt, IRQF_SHARED, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | 			 "wdt_pci", &wdtpci_miscdev)) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 646 | 		pr_err("IRQ %d is not free\n", irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | 		goto out_reg; | 
 | 648 | 	} | 
 | 649 |  | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 650 | 	pr_info("PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%llx (Interrupt %d)\n", | 
 | 651 | 		(unsigned long long)io, irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 653 | 	/* Check that the heartbeat value is within its range; | 
 | 654 | 	   if not reset to the default */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | 	if (wdtpci_set_heartbeat(heartbeat)) { | 
 | 656 | 		wdtpci_set_heartbeat(WD_TIMO); | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 657 | 		pr_info("heartbeat value must be 0 < heartbeat < 65536, using %d\n", | 
 | 658 | 			WD_TIMO); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | 	} | 
 | 660 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 661 | 	ret = register_reboot_notifier(&wdtpci_notifier); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | 	if (ret) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 663 | 		pr_err("cannot register reboot notifier (err=%d)\n", ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | 		goto out_irq; | 
 | 665 | 	} | 
 | 666 |  | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 667 | 	if (type == 501) { | 
 | 668 | 		ret = misc_register(&temp_miscdev); | 
 | 669 | 		if (ret) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 670 | 			pr_err("cannot register miscdev on minor=%d (err=%d)\n", | 
 | 671 | 			       TEMP_MINOR, ret); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 672 | 			goto out_rbt; | 
 | 673 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 676 | 	ret = misc_register(&wdtpci_miscdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | 	if (ret) { | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 678 | 		pr_err("cannot register miscdev on minor=%d (err=%d)\n", | 
 | 679 | 		       WATCHDOG_MINOR, ret); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | 		goto out_misc; | 
 | 681 | 	} | 
 | 682 |  | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 683 | 	pr_info("initialized. heartbeat=%d sec (nowayout=%d)\n", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | 		heartbeat, nowayout); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 685 | 	if (type == 501) | 
| Joe Perches | 27c766a | 2012-02-15 15:06:19 -0800 | [diff] [blame] | 686 | 		pr_info("Fan Tachometer is %s\n", | 
 | 687 | 			tachometer ? "Enabled" : "Disabled"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 |  | 
 | 689 | 	ret = 0; | 
 | 690 | out: | 
 | 691 | 	return ret; | 
 | 692 |  | 
 | 693 | out_misc: | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 694 | 	if (type == 501) | 
 | 695 | 		misc_deregister(&temp_miscdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | out_rbt: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | 	unregister_reboot_notifier(&wdtpci_notifier); | 
 | 698 | out_irq: | 
 | 699 | 	free_irq(irq, &wdtpci_miscdev); | 
 | 700 | out_reg: | 
| Wim Van Sebroeck | 119d3e5 | 2009-08-06 18:57:49 +0000 | [diff] [blame] | 701 | 	pci_release_region(dev, 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | out_pci: | 
 | 703 | 	pci_disable_device(dev); | 
 | 704 | 	goto out; | 
 | 705 | } | 
 | 706 |  | 
 | 707 |  | 
| Alan Cox | 9f2d1f0 | 2008-08-04 17:55:35 +0100 | [diff] [blame] | 708 | static void __devexit wdtpci_remove_one(struct pci_dev *pdev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | { | 
 | 710 | 	/* here we assume only one device will ever have | 
 | 711 | 	 * been picked up and registered by probe function */ | 
 | 712 | 	misc_deregister(&wdtpci_miscdev); | 
| Wim Van Sebroeck | 9b901ee | 2009-06-19 09:32:57 +0000 | [diff] [blame] | 713 | 	if (type == 501) | 
 | 714 | 		misc_deregister(&temp_miscdev); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | 	unregister_reboot_notifier(&wdtpci_notifier); | 
 | 716 | 	free_irq(irq, &wdtpci_miscdev); | 
| Wim Van Sebroeck | 119d3e5 | 2009-08-06 18:57:49 +0000 | [diff] [blame] | 717 | 	pci_release_region(pdev, 2); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | 	pci_disable_device(pdev); | 
 | 719 | 	dev_count--; | 
 | 720 | } | 
 | 721 |  | 
 | 722 |  | 
| Wim Van Sebroeck | 4562f53 | 2011-02-21 12:16:44 +0000 | [diff] [blame] | 723 | static DEFINE_PCI_DEVICE_TABLE(wdtpci_pci_tbl) = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | 	{ | 
 | 725 | 		.vendor	   = PCI_VENDOR_ID_ACCESSIO, | 
| H Hartley Sweeten | 9f2cc6f | 2010-05-21 18:38:52 -0500 | [diff] [blame] | 726 | 		.device	   = PCI_DEVICE_ID_ACCESSIO_WDG_CSM, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | 		.subvendor = PCI_ANY_ID, | 
 | 728 | 		.subdevice = PCI_ANY_ID, | 
 | 729 | 	}, | 
 | 730 | 	{ 0, }, /* terminate list */ | 
 | 731 | }; | 
 | 732 | MODULE_DEVICE_TABLE(pci, wdtpci_pci_tbl); | 
 | 733 |  | 
 | 734 |  | 
 | 735 | static struct pci_driver wdtpci_driver = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | 	.name		= "wdt_pci", | 
 | 737 | 	.id_table	= wdtpci_pci_tbl, | 
 | 738 | 	.probe		= wdtpci_init_one, | 
 | 739 | 	.remove		= __devexit_p(wdtpci_remove_one), | 
 | 740 | }; | 
 | 741 |  | 
| Wim Van Sebroeck | 5ce9c37 | 2012-05-04 14:43:25 +0200 | [diff] [blame] | 742 | module_pci_driver(wdtpci_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 |  | 
 | 744 | MODULE_AUTHOR("JP Nollmann, Alan Cox"); | 
 | 745 | MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards"); | 
 | 746 | MODULE_LICENSE("GPL"); | 
 | 747 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | 
 | 748 | MODULE_ALIAS_MISCDEV(TEMP_MINOR); |