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