diff options
Diffstat (limited to 'drivers/watchdog/wdt_pci.c')
-rw-r--r-- | drivers/watchdog/wdt_pci.c | 301 |
1 files changed, 172 insertions, 129 deletions
diff --git a/drivers/watchdog/wdt_pci.c b/drivers/watchdog/wdt_pci.c index 1355608683e..5d922fd6eaf 100644 --- a/drivers/watchdog/wdt_pci.c +++ b/drivers/watchdog/wdt_pci.c | |||
@@ -29,9 +29,11 @@ | |||
29 | * JP Nollmann : Added support for PCI wdt501p | 29 | * JP Nollmann : Added support for PCI wdt501p |
30 | * Alan Cox : Split ISA and PCI cards into two drivers | 30 | * Alan Cox : Split ISA and PCI cards into two drivers |
31 | * Jeff Garzik : PCI cleanups | 31 | * Jeff Garzik : PCI cleanups |
32 | * Tigran Aivazian : Restructured wdtpci_init_one() to handle failures | 32 | * Tigran Aivazian : Restructured wdtpci_init_one() to handle |
33 | * failures | ||
33 | * Joel Becker : Added WDIOC_GET/SETTIMEOUT | 34 | * Joel Becker : Added WDIOC_GET/SETTIMEOUT |
34 | * Zwane Mwaikambo : Magic char closing, locking changes, cleanups | 35 | * Zwane Mwaikambo : Magic char closing, locking changes, |
36 | * cleanups | ||
35 | * Matt Domsch : nowayout module option | 37 | * Matt Domsch : nowayout module option |
36 | */ | 38 | */ |
37 | 39 | ||
@@ -42,14 +44,15 @@ | |||
42 | #include <linux/miscdevice.h> | 44 | #include <linux/miscdevice.h> |
43 | #include <linux/watchdog.h> | 45 | #include <linux/watchdog.h> |
44 | #include <linux/ioport.h> | 46 | #include <linux/ioport.h> |
47 | #include <linux/delay.h> | ||
45 | #include <linux/notifier.h> | 48 | #include <linux/notifier.h> |
46 | #include <linux/reboot.h> | 49 | #include <linux/reboot.h> |
47 | #include <linux/init.h> | 50 | #include <linux/init.h> |
48 | #include <linux/fs.h> | 51 | #include <linux/fs.h> |
49 | #include <linux/pci.h> | 52 | #include <linux/pci.h> |
53 | #include <linux/io.h> | ||
54 | #include <linux/uaccess.h> | ||
50 | 55 | ||
51 | #include <asm/io.h> | ||
52 | #include <asm/uaccess.h> | ||
53 | #include <asm/system.h> | 56 | #include <asm/system.h> |
54 | 57 | ||
55 | #define WDT_IS_PCI | 58 | #define WDT_IS_PCI |
@@ -73,7 +76,7 @@ | |||
73 | /* We can only use 1 card due to the /dev/watchdog restriction */ | 76 | /* We can only use 1 card due to the /dev/watchdog restriction */ |
74 | static int dev_count; | 77 | static int dev_count; |
75 | 78 | ||
76 | static struct semaphore open_sem; | 79 | static unsigned long open_lock; |
77 | static DEFINE_SPINLOCK(wdtpci_lock); | 80 | static DEFINE_SPINLOCK(wdtpci_lock); |
78 | static char expect_close; | 81 | static char expect_close; |
79 | 82 | ||
@@ -86,18 +89,23 @@ static int irq; | |||
86 | static int heartbeat = WD_TIMO; | 89 | static int heartbeat = WD_TIMO; |
87 | static int wd_heartbeat; | 90 | static int wd_heartbeat; |
88 | module_param(heartbeat, int, 0); | 91 | module_param(heartbeat, int, 0); |
89 | MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WD_TIMO) ")"); | 92 | MODULE_PARM_DESC(heartbeat, |
93 | "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" | ||
94 | __MODULE_STRING(WD_TIMO) ")"); | ||
90 | 95 | ||
91 | static int nowayout = WATCHDOG_NOWAYOUT; | 96 | static int nowayout = WATCHDOG_NOWAYOUT; |
92 | module_param(nowayout, int, 0); | 97 | module_param(nowayout, int, 0); |
93 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | 98 | MODULE_PARM_DESC(nowayout, |
99 | "Watchdog cannot be stopped once started (default=" | ||
100 | __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); | ||
94 | 101 | ||
95 | #ifdef CONFIG_WDT_501_PCI | 102 | #ifdef CONFIG_WDT_501_PCI |
96 | /* Support for the Fan Tachometer on the PCI-WDT501 */ | 103 | /* Support for the Fan Tachometer on the PCI-WDT501 */ |
97 | static int tachometer; | 104 | static int tachometer; |
98 | 105 | ||
99 | module_param(tachometer, int, 0); | 106 | module_param(tachometer, int, 0); |
100 | MODULE_PARM_DESC(tachometer, "PCI-WDT501 Fan Tachometer support (0=disable, default=0)"); | 107 | MODULE_PARM_DESC(tachometer, |
108 | "PCI-WDT501 Fan Tachometer support (0=disable, default=0)"); | ||
101 | #endif /* CONFIG_WDT_501_PCI */ | 109 | #endif /* CONFIG_WDT_501_PCI */ |
102 | 110 | ||
103 | /* | 111 | /* |
@@ -106,16 +114,19 @@ MODULE_PARM_DESC(tachometer, "PCI-WDT501 Fan Tachometer support (0=disable, defa | |||
106 | 114 | ||
107 | static void wdtpci_ctr_mode(int ctr, int mode) | 115 | static void wdtpci_ctr_mode(int ctr, int mode) |
108 | { | 116 | { |
109 | ctr<<=6; | 117 | ctr <<= 6; |
110 | ctr|=0x30; | 118 | ctr |= 0x30; |
111 | ctr|=(mode<<1); | 119 | ctr |= (mode << 1); |
112 | outb_p(ctr, WDT_CR); | 120 | outb(ctr, WDT_CR); |
121 | udelay(8); | ||
113 | } | 122 | } |
114 | 123 | ||
115 | static void wdtpci_ctr_load(int ctr, int val) | 124 | static void wdtpci_ctr_load(int ctr, int val) |
116 | { | 125 | { |
117 | outb_p(val&0xFF, WDT_COUNT0+ctr); | 126 | outb(val & 0xFF, WDT_COUNT0 + ctr); |
118 | outb_p(val>>8, WDT_COUNT0+ctr); | 127 | udelay(8); |
128 | outb(val >> 8, WDT_COUNT0 + ctr); | ||
129 | udelay(8); | ||
119 | } | 130 | } |
120 | 131 | ||
121 | /** | 132 | /** |
@@ -134,23 +145,35 @@ static int wdtpci_start(void) | |||
134 | * "pet" the watchdog, as Access says. | 145 | * "pet" the watchdog, as Access says. |
135 | * This resets the clock outputs. | 146 | * This resets the clock outputs. |
136 | */ | 147 | */ |
137 | inb_p(WDT_DC); /* Disable watchdog */ | 148 | inb(WDT_DC); /* Disable watchdog */ |
138 | wdtpci_ctr_mode(2,0); /* Program CTR2 for Mode 0: Pulse on Terminal Count */ | 149 | udelay(8); |
139 | outb_p(0, WDT_DC); /* Enable watchdog */ | 150 | wdtpci_ctr_mode(2, 0); /* Program CTR2 for Mode 0: |
140 | 151 | Pulse on Terminal Count */ | |
141 | inb_p(WDT_DC); /* Disable watchdog */ | 152 | outb(0, WDT_DC); /* Enable watchdog */ |
142 | outb_p(0, WDT_CLOCK); /* 2.0833MHz clock */ | 153 | udelay(8); |
143 | inb_p(WDT_BUZZER); /* disable */ | 154 | inb(WDT_DC); /* Disable watchdog */ |
144 | inb_p(WDT_OPTONOTRST); /* disable */ | 155 | udelay(8); |
145 | inb_p(WDT_OPTORST); /* disable */ | 156 | outb(0, WDT_CLOCK); /* 2.0833MHz clock */ |
146 | inb_p(WDT_PROGOUT); /* disable */ | 157 | udelay(8); |
147 | wdtpci_ctr_mode(0,3); /* Program CTR0 for Mode 3: Square Wave Generator */ | 158 | inb(WDT_BUZZER); /* disable */ |
148 | wdtpci_ctr_mode(1,2); /* Program CTR1 for Mode 2: Rate Generator */ | 159 | udelay(8); |
149 | wdtpci_ctr_mode(2,1); /* Program CTR2 for Mode 1: Retriggerable One-Shot */ | 160 | inb(WDT_OPTONOTRST); /* disable */ |
150 | wdtpci_ctr_load(0,20833); /* count at 100Hz */ | 161 | udelay(8); |
151 | wdtpci_ctr_load(1,wd_heartbeat);/* Heartbeat */ | 162 | inb(WDT_OPTORST); /* disable */ |
163 | udelay(8); | ||
164 | inb(WDT_PROGOUT); /* disable */ | ||
165 | udelay(8); | ||
166 | wdtpci_ctr_mode(0, 3); /* Program CTR0 for Mode 3: | ||
167 | Square Wave Generator */ | ||
168 | wdtpci_ctr_mode(1, 2); /* Program CTR1 for Mode 2: | ||
169 | Rate Generator */ | ||
170 | wdtpci_ctr_mode(2, 1); /* Program CTR2 for Mode 1: | ||
171 | Retriggerable One-Shot */ | ||
172 | wdtpci_ctr_load(0, 20833); /* count at 100Hz */ | ||
173 | wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */ | ||
152 | /* DO NOT LOAD CTR2 on PCI card! -- JPN */ | 174 | /* DO NOT LOAD CTR2 on PCI card! -- JPN */ |
153 | outb_p(0, WDT_DC); /* Enable watchdog */ | 175 | outb(0, WDT_DC); /* Enable watchdog */ |
176 | udelay(8); | ||
154 | 177 | ||
155 | spin_unlock_irqrestore(&wdtpci_lock, flags); | 178 | spin_unlock_irqrestore(&wdtpci_lock, flags); |
156 | return 0; | 179 | return 0; |
@@ -162,14 +185,15 @@ static int wdtpci_start(void) | |||
162 | * Stop the watchdog driver. | 185 | * Stop the watchdog driver. |
163 | */ | 186 | */ |
164 | 187 | ||
165 | static int wdtpci_stop (void) | 188 | static int wdtpci_stop(void) |
166 | { | 189 | { |
167 | unsigned long flags; | 190 | unsigned long flags; |
168 | 191 | ||
169 | /* Turn the card off */ | 192 | /* Turn the card off */ |
170 | spin_lock_irqsave(&wdtpci_lock, flags); | 193 | spin_lock_irqsave(&wdtpci_lock, flags); |
171 | inb_p(WDT_DC); /* Disable watchdog */ | 194 | inb(WDT_DC); /* Disable watchdog */ |
172 | wdtpci_ctr_load(2,0); /* 0 length reset pulses now */ | 195 | udelay(8); |
196 | wdtpci_ctr_load(2, 0); /* 0 length reset pulses now */ | ||
173 | spin_unlock_irqrestore(&wdtpci_lock, flags); | 197 | spin_unlock_irqrestore(&wdtpci_lock, flags); |
174 | return 0; | 198 | return 0; |
175 | } | 199 | } |
@@ -177,20 +201,23 @@ static int wdtpci_stop (void) | |||
177 | /** | 201 | /** |
178 | * wdtpci_ping: | 202 | * wdtpci_ping: |
179 | * | 203 | * |
180 | * Reload counter one with the watchdog heartbeat. We don't bother reloading | 204 | * Reload counter one with the watchdog heartbeat. We don't bother |
181 | * the cascade counter. | 205 | * reloading the cascade counter. |
182 | */ | 206 | */ |
183 | 207 | ||
184 | static int wdtpci_ping(void) | 208 | static int wdtpci_ping(void) |
185 | { | 209 | { |
186 | unsigned long flags; | 210 | unsigned long flags; |
187 | 211 | ||
188 | /* Write a watchdog value */ | ||
189 | spin_lock_irqsave(&wdtpci_lock, flags); | 212 | spin_lock_irqsave(&wdtpci_lock, flags); |
190 | inb_p(WDT_DC); /* Disable watchdog */ | 213 | /* Write a watchdog value */ |
191 | wdtpci_ctr_mode(1,2); /* Re-Program CTR1 for Mode 2: Rate Generator */ | 214 | inb(WDT_DC); /* Disable watchdog */ |
192 | wdtpci_ctr_load(1,wd_heartbeat);/* Heartbeat */ | 215 | udelay(8); |
193 | outb_p(0, WDT_DC); /* Enable watchdog */ | 216 | wdtpci_ctr_mode(1, 2); /* Re-Program CTR1 for Mode 2: |
217 | Rate Generator */ | ||
218 | wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */ | ||
219 | outb(0, WDT_DC); /* Enable watchdog */ | ||
220 | udelay(8); | ||
194 | spin_unlock_irqrestore(&wdtpci_lock, flags); | 221 | spin_unlock_irqrestore(&wdtpci_lock, flags); |
195 | return 0; | 222 | return 0; |
196 | } | 223 | } |
@@ -199,14 +226,14 @@ static int wdtpci_ping(void) | |||
199 | * wdtpci_set_heartbeat: | 226 | * wdtpci_set_heartbeat: |
200 | * @t: the new heartbeat value that needs to be set. | 227 | * @t: the new heartbeat value that needs to be set. |
201 | * | 228 | * |
202 | * Set a new heartbeat value for the watchdog device. If the heartbeat value is | 229 | * Set a new heartbeat value for the watchdog device. If the heartbeat |
203 | * incorrect we keep the old value and return -EINVAL. If successfull we | 230 | * value is incorrect we keep the old value and return -EINVAL. |
204 | * return 0. | 231 | * If successful we return 0. |
205 | */ | 232 | */ |
206 | static int wdtpci_set_heartbeat(int t) | 233 | static int wdtpci_set_heartbeat(int t) |
207 | { | 234 | { |
208 | /* Arbitrary, can't find the card's limits */ | 235 | /* Arbitrary, can't find the card's limits */ |
209 | if ((t < 1) || (t > 65535)) | 236 | if (t < 1 || t > 65535) |
210 | return -EINVAL; | 237 | return -EINVAL; |
211 | 238 | ||
212 | heartbeat = t; | 239 | heartbeat = t; |
@@ -227,9 +254,14 @@ static int wdtpci_set_heartbeat(int t) | |||
227 | 254 | ||
228 | static int wdtpci_get_status(int *status) | 255 | static int wdtpci_get_status(int *status) |
229 | { | 256 | { |
230 | unsigned char new_status=inb_p(WDT_SR); | 257 | unsigned char new_status; |
258 | unsigned long flags; | ||
259 | |||
260 | spin_lock_irqsave(&wdtpci_lock, flags); | ||
261 | new_status = inb(WDT_SR); | ||
262 | spin_unlock_irqrestore(&wdtpci_lock, flags); | ||
231 | 263 | ||
232 | *status=0; | 264 | *status = 0; |
233 | if (new_status & WDC_SR_ISOI0) | 265 | if (new_status & WDC_SR_ISOI0) |
234 | *status |= WDIOF_EXTERN1; | 266 | *status |= WDIOF_EXTERN1; |
235 | if (new_status & WDC_SR_ISII1) | 267 | if (new_status & WDC_SR_ISII1) |
@@ -259,8 +291,12 @@ static int wdtpci_get_status(int *status) | |||
259 | 291 | ||
260 | static int wdtpci_get_temperature(int *temperature) | 292 | static int wdtpci_get_temperature(int *temperature) |
261 | { | 293 | { |
262 | unsigned short c=inb_p(WDT_RT); | 294 | unsigned short c; |
263 | 295 | unsigned long flags; | |
296 | spin_lock_irqsave(&wdtpci_lock, flags); | ||
297 | c = inb(WDT_RT); | ||
298 | udelay(8); | ||
299 | spin_unlock_irqrestore(&wdtpci_lock, flags); | ||
264 | *temperature = (c * 11 / 15) + 7; | 300 | *temperature = (c * 11 / 15) + 7; |
265 | return 0; | 301 | return 0; |
266 | } | 302 | } |
@@ -282,17 +318,25 @@ static irqreturn_t wdtpci_interrupt(int irq, void *dev_id) | |||
282 | * Read the status register see what is up and | 318 | * Read the status register see what is up and |
283 | * then printk it. | 319 | * then printk it. |
284 | */ | 320 | */ |
285 | unsigned char status=inb_p(WDT_SR); | 321 | unsigned char status; |
322 | |||
323 | spin_lock(&wdtpci_lock); | ||
324 | |||
325 | status = inb(WDT_SR); | ||
326 | udelay(8); | ||
286 | 327 | ||
287 | printk(KERN_CRIT PFX "status %d\n", status); | 328 | printk(KERN_CRIT PFX "status %d\n", status); |
288 | 329 | ||
289 | #ifdef CONFIG_WDT_501_PCI | 330 | #ifdef CONFIG_WDT_501_PCI |
290 | if (!(status & WDC_SR_TGOOD)) | 331 | if (!(status & WDC_SR_TGOOD)) { |
291 | printk(KERN_CRIT PFX "Overheat alarm.(%d)\n",inb_p(WDT_RT)); | 332 | u8 alarm = inb(WDT_RT); |
333 | printk(KERN_CRIT PFX "Overheat alarm.(%d)\n", alarm); | ||
334 | udelay(8); | ||
335 | } | ||
292 | if (!(status & WDC_SR_PSUOVER)) | 336 | if (!(status & WDC_SR_PSUOVER)) |
293 | printk(KERN_CRIT PFX "PSU over voltage.\n"); | 337 | printk(KERN_CRIT PFX "PSU over voltage.\n"); |
294 | if (!(status & WDC_SR_PSUUNDR)) | 338 | if (!(status & WDC_SR_PSUUNDR)) |
295 | printk(KERN_CRIT PFX "PSU under voltage.\n"); | 339 | printk(KERN_CRIT PFX "PSU under voltage.\n"); |
296 | if (tachometer) { | 340 | if (tachometer) { |
297 | if (!(status & WDC_SR_FANGOOD)) | 341 | if (!(status & WDC_SR_FANGOOD)) |
298 | printk(KERN_CRIT PFX "Possible fan fault.\n"); | 342 | printk(KERN_CRIT PFX "Possible fan fault.\n"); |
@@ -310,6 +354,7 @@ static irqreturn_t wdtpci_interrupt(int irq, void *dev_id) | |||
310 | printk(KERN_CRIT PFX "Reset in 5ms.\n"); | 354 | printk(KERN_CRIT PFX "Reset in 5ms.\n"); |
311 | #endif | 355 | #endif |
312 | } | 356 | } |
357 | spin_unlock(&wdtpci_lock); | ||
313 | return IRQ_HANDLED; | 358 | return IRQ_HANDLED; |
314 | } | 359 | } |
315 | 360 | ||
@@ -325,7 +370,8 @@ static irqreturn_t wdtpci_interrupt(int irq, void *dev_id) | |||
325 | * write of data will do, as we we don't define content meaning. | 370 | * write of data will do, as we we don't define content meaning. |
326 | */ | 371 | */ |
327 | 372 | ||
328 | static ssize_t wdtpci_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) | 373 | static ssize_t wdtpci_write(struct file *file, const char __user *buf, |
374 | size_t count, loff_t *ppos) | ||
329 | { | 375 | { |
330 | if (count) { | 376 | if (count) { |
331 | if (!nowayout) { | 377 | if (!nowayout) { |
@@ -335,7 +381,7 @@ static ssize_t wdtpci_write(struct file *file, const char __user *buf, size_t co | |||
335 | 381 | ||
336 | for (i = 0; i != count; i++) { | 382 | for (i = 0; i != count; i++) { |
337 | char c; | 383 | char c; |
338 | if(get_user(c, buf+i)) | 384 | if (get_user(c, buf+i)) |
339 | return -EFAULT; | 385 | return -EFAULT; |
340 | if (c == 'V') | 386 | if (c == 'V') |
341 | expect_close = 42; | 387 | expect_close = 42; |
@@ -343,13 +389,11 @@ static ssize_t wdtpci_write(struct file *file, const char __user *buf, size_t co | |||
343 | } | 389 | } |
344 | wdtpci_ping(); | 390 | wdtpci_ping(); |
345 | } | 391 | } |
346 | |||
347 | return count; | 392 | return count; |
348 | } | 393 | } |
349 | 394 | ||
350 | /** | 395 | /** |
351 | * wdtpci_ioctl: | 396 | * wdtpci_ioctl: |
352 | * @inode: inode of the device | ||
353 | * @file: file handle to the device | 397 | * @file: file handle to the device |
354 | * @cmd: watchdog command | 398 | * @cmd: watchdog command |
355 | * @arg: argument pointer | 399 | * @arg: argument pointer |
@@ -359,8 +403,8 @@ static ssize_t wdtpci_write(struct file *file, const char __user *buf, size_t co | |||
359 | * querying capabilities and current status. | 403 | * querying capabilities and current status. |
360 | */ | 404 | */ |
361 | 405 | ||
362 | static int wdtpci_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 406 | static long wdtpci_ioctl(struct file *file, unsigned int cmd, |
363 | unsigned long arg) | 407 | unsigned long arg) |
364 | { | 408 | { |
365 | int new_heartbeat; | 409 | int new_heartbeat; |
366 | int status; | 410 | int status; |
@@ -383,33 +427,29 @@ static int wdtpci_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
383 | ident.options |= WDIOF_FANFAULT; | 427 | ident.options |= WDIOF_FANFAULT; |
384 | #endif /* CONFIG_WDT_501_PCI */ | 428 | #endif /* CONFIG_WDT_501_PCI */ |
385 | 429 | ||
386 | switch(cmd) | 430 | switch (cmd) { |
387 | { | 431 | default: |
388 | default: | 432 | return -ENOTTY; |
389 | return -ENOTTY; | 433 | case WDIOC_GETSUPPORT: |
390 | case WDIOC_GETSUPPORT: | 434 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
391 | return copy_to_user(argp, &ident, sizeof(ident))?-EFAULT:0; | 435 | case WDIOC_GETSTATUS: |
392 | 436 | wdtpci_get_status(&status); | |
393 | case WDIOC_GETSTATUS: | 437 | return put_user(status, p); |
394 | wdtpci_get_status(&status); | 438 | case WDIOC_GETBOOTSTATUS: |
395 | return put_user(status, p); | 439 | return put_user(0, p); |
396 | case WDIOC_GETBOOTSTATUS: | 440 | case WDIOC_KEEPALIVE: |
397 | return put_user(0, p); | 441 | wdtpci_ping(); |
398 | case WDIOC_KEEPALIVE: | 442 | return 0; |
399 | wdtpci_ping(); | 443 | case WDIOC_SETTIMEOUT: |
400 | return 0; | 444 | if (get_user(new_heartbeat, p)) |
401 | case WDIOC_SETTIMEOUT: | 445 | return -EFAULT; |
402 | if (get_user(new_heartbeat, p)) | 446 | if (wdtpci_set_heartbeat(new_heartbeat)) |
403 | return -EFAULT; | 447 | return -EINVAL; |
404 | 448 | wdtpci_ping(); | |
405 | if (wdtpci_set_heartbeat(new_heartbeat)) | 449 | /* Fall */ |
406 | return -EINVAL; | 450 | case WDIOC_GETTIMEOUT: |
407 | 451 | return put_user(heartbeat, p); | |
408 | wdtpci_ping(); | 452 | } |
409 | /* Fall */ | ||
410 | case WDIOC_GETTIMEOUT: | ||
411 | return put_user(heartbeat, p); | ||
412 | } | ||
413 | } | 453 | } |
414 | 454 | ||
415 | /** | 455 | /** |
@@ -426,12 +466,11 @@ static int wdtpci_ioctl(struct inode *inode, struct file *file, unsigned int cmd | |||
426 | 466 | ||
427 | static int wdtpci_open(struct inode *inode, struct file *file) | 467 | static int wdtpci_open(struct inode *inode, struct file *file) |
428 | { | 468 | { |
429 | if (down_trylock(&open_sem)) | 469 | if (test_and_set_bit(0, &open_lock)) |
430 | return -EBUSY; | 470 | return -EBUSY; |
431 | 471 | ||
432 | if (nowayout) { | 472 | if (nowayout) |
433 | __module_get(THIS_MODULE); | 473 | __module_get(THIS_MODULE); |
434 | } | ||
435 | /* | 474 | /* |
436 | * Activate | 475 | * Activate |
437 | */ | 476 | */ |
@@ -460,7 +499,7 @@ static int wdtpci_release(struct inode *inode, struct file *file) | |||
460 | wdtpci_ping(); | 499 | wdtpci_ping(); |
461 | } | 500 | } |
462 | expect_close = 0; | 501 | expect_close = 0; |
463 | up(&open_sem); | 502 | clear_bit(0, &open_lock); |
464 | return 0; | 503 | return 0; |
465 | } | 504 | } |
466 | 505 | ||
@@ -476,14 +515,15 @@ static int wdtpci_release(struct inode *inode, struct file *file) | |||
476 | * fahrenheit. It was designed by an imperial measurement luddite. | 515 | * fahrenheit. It was designed by an imperial measurement luddite. |
477 | */ | 516 | */ |
478 | 517 | ||
479 | static ssize_t wdtpci_temp_read(struct file *file, char __user *buf, size_t count, loff_t *ptr) | 518 | static ssize_t wdtpci_temp_read(struct file *file, char __user *buf, |
519 | size_t count, loff_t *ptr) | ||
480 | { | 520 | { |
481 | int temperature; | 521 | int temperature; |
482 | 522 | ||
483 | if (wdtpci_get_temperature(&temperature)) | 523 | if (wdtpci_get_temperature(&temperature)) |
484 | return -EFAULT; | 524 | return -EFAULT; |
485 | 525 | ||
486 | if (copy_to_user (buf, &temperature, 1)) | 526 | if (copy_to_user(buf, &temperature, 1)) |
487 | return -EFAULT; | 527 | return -EFAULT; |
488 | 528 | ||
489 | return 1; | 529 | return 1; |
@@ -529,12 +569,10 @@ static int wdtpci_temp_release(struct inode *inode, struct file *file) | |||
529 | */ | 569 | */ |
530 | 570 | ||
531 | static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code, | 571 | static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code, |
532 | void *unused) | 572 | void *unused) |
533 | { | 573 | { |
534 | if (code==SYS_DOWN || code==SYS_HALT) { | 574 | if (code == SYS_DOWN || code == SYS_HALT) |
535 | /* Turn the card off */ | ||
536 | wdtpci_stop(); | 575 | wdtpci_stop(); |
537 | } | ||
538 | return NOTIFY_DONE; | 576 | return NOTIFY_DONE; |
539 | } | 577 | } |
540 | 578 | ||
@@ -547,7 +585,7 @@ static const struct file_operations wdtpci_fops = { | |||
547 | .owner = THIS_MODULE, | 585 | .owner = THIS_MODULE, |
548 | .llseek = no_llseek, | 586 | .llseek = no_llseek, |
549 | .write = wdtpci_write, | 587 | .write = wdtpci_write, |
550 | .ioctl = wdtpci_ioctl, | 588 | .unlocked_ioctl = wdtpci_ioctl, |
551 | .open = wdtpci_open, | 589 | .open = wdtpci_open, |
552 | .release = wdtpci_release, | 590 | .release = wdtpci_release, |
553 | }; | 591 | }; |
@@ -584,80 +622,85 @@ static struct notifier_block wdtpci_notifier = { | |||
584 | }; | 622 | }; |
585 | 623 | ||
586 | 624 | ||
587 | static int __devinit wdtpci_init_one (struct pci_dev *dev, | 625 | static int __devinit wdtpci_init_one(struct pci_dev *dev, |
588 | const struct pci_device_id *ent) | 626 | const struct pci_device_id *ent) |
589 | { | 627 | { |
590 | int ret = -EIO; | 628 | int ret = -EIO; |
591 | 629 | ||
592 | dev_count++; | 630 | dev_count++; |
593 | if (dev_count > 1) { | 631 | if (dev_count > 1) { |
594 | printk (KERN_ERR PFX "this driver only supports 1 device\n"); | 632 | printk(KERN_ERR PFX "This driver only supports one device\n"); |
595 | return -ENODEV; | 633 | return -ENODEV; |
596 | } | 634 | } |
597 | 635 | ||
598 | if (pci_enable_device (dev)) { | 636 | if (pci_enable_device(dev)) { |
599 | printk (KERN_ERR PFX "Not possible to enable PCI Device\n"); | 637 | printk(KERN_ERR PFX "Not possible to enable PCI Device\n"); |
600 | return -ENODEV; | 638 | return -ENODEV; |
601 | } | 639 | } |
602 | 640 | ||
603 | if (pci_resource_start (dev, 2) == 0x0000) { | 641 | if (pci_resource_start(dev, 2) == 0x0000) { |
604 | printk (KERN_ERR PFX "No I/O-Address for card detected\n"); | 642 | printk(KERN_ERR PFX "No I/O-Address for card detected\n"); |
605 | ret = -ENODEV; | 643 | ret = -ENODEV; |
606 | goto out_pci; | 644 | goto out_pci; |
607 | } | 645 | } |
608 | 646 | ||
609 | sema_init(&open_sem, 1); | ||
610 | |||
611 | irq = dev->irq; | 647 | irq = dev->irq; |
612 | io = pci_resource_start (dev, 2); | 648 | io = pci_resource_start(dev, 2); |
613 | 649 | ||
614 | if (request_region (io, 16, "wdt_pci") == NULL) { | 650 | if (request_region(io, 16, "wdt_pci") == NULL) { |
615 | printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", io); | 651 | printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", io); |
616 | goto out_pci; | 652 | goto out_pci; |
617 | } | 653 | } |
618 | 654 | ||
619 | if (request_irq (irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED, | 655 | if (request_irq(irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED, |
620 | "wdt_pci", &wdtpci_miscdev)) { | 656 | "wdt_pci", &wdtpci_miscdev)) { |
621 | printk (KERN_ERR PFX "IRQ %d is not free\n", irq); | 657 | printk(KERN_ERR PFX "IRQ %d is not free\n", irq); |
622 | goto out_reg; | 658 | goto out_reg; |
623 | } | 659 | } |
624 | 660 | ||
625 | printk ("PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n", | 661 | printk(KERN_INFO |
626 | io, irq); | 662 | "PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n", |
663 | io, irq); | ||
627 | 664 | ||
628 | /* Check that the heartbeat value is within it's range ; if not reset to the default */ | 665 | /* Check that the heartbeat value is within its range; |
666 | if not reset to the default */ | ||
629 | if (wdtpci_set_heartbeat(heartbeat)) { | 667 | if (wdtpci_set_heartbeat(heartbeat)) { |
630 | wdtpci_set_heartbeat(WD_TIMO); | 668 | wdtpci_set_heartbeat(WD_TIMO); |
631 | printk(KERN_INFO PFX "heartbeat value must be 0<heartbeat<65536, using %d\n", | 669 | printk(KERN_INFO PFX |
632 | WD_TIMO); | 670 | "heartbeat value must be 0 < heartbeat < 65536, using %d\n", |
671 | WD_TIMO); | ||
633 | } | 672 | } |
634 | 673 | ||
635 | ret = register_reboot_notifier (&wdtpci_notifier); | 674 | ret = register_reboot_notifier(&wdtpci_notifier); |
636 | if (ret) { | 675 | if (ret) { |
637 | printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", ret); | 676 | printk(KERN_ERR PFX |
677 | "cannot register reboot notifier (err=%d)\n", ret); | ||
638 | goto out_irq; | 678 | goto out_irq; |
639 | } | 679 | } |
640 | 680 | ||
641 | #ifdef CONFIG_WDT_501_PCI | 681 | #ifdef CONFIG_WDT_501_PCI |
642 | ret = misc_register (&temp_miscdev); | 682 | ret = misc_register(&temp_miscdev); |
643 | if (ret) { | 683 | if (ret) { |
644 | printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 684 | printk(KERN_ERR PFX |
645 | TEMP_MINOR, ret); | 685 | "cannot register miscdev on minor=%d (err=%d)\n", |
686 | TEMP_MINOR, ret); | ||
646 | goto out_rbt; | 687 | goto out_rbt; |
647 | } | 688 | } |
648 | #endif /* CONFIG_WDT_501_PCI */ | 689 | #endif /* CONFIG_WDT_501_PCI */ |
649 | 690 | ||
650 | ret = misc_register (&wdtpci_miscdev); | 691 | ret = misc_register(&wdtpci_miscdev); |
651 | if (ret) { | 692 | if (ret) { |
652 | printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", | 693 | printk(KERN_ERR PFX |
653 | WATCHDOG_MINOR, ret); | 694 | "cannot register miscdev on minor=%d (err=%d)\n", |
695 | WATCHDOG_MINOR, ret); | ||
654 | goto out_misc; | 696 | goto out_misc; |
655 | } | 697 | } |
656 | 698 | ||
657 | printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", | 699 | printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n", |
658 | heartbeat, nowayout); | 700 | heartbeat, nowayout); |
659 | #ifdef CONFIG_WDT_501_PCI | 701 | #ifdef CONFIG_WDT_501_PCI |
660 | printk(KERN_INFO "wdt: Fan Tachometer is %s\n", (tachometer ? "Enabled" : "Disabled")); | 702 | printk(KERN_INFO "wdt: Fan Tachometer is %s\n", |
703 | (tachometer ? "Enabled" : "Disabled")); | ||
661 | #endif /* CONFIG_WDT_501_PCI */ | 704 | #endif /* CONFIG_WDT_501_PCI */ |
662 | 705 | ||
663 | ret = 0; | 706 | ret = 0; |
@@ -673,14 +716,14 @@ out_rbt: | |||
673 | out_irq: | 716 | out_irq: |
674 | free_irq(irq, &wdtpci_miscdev); | 717 | free_irq(irq, &wdtpci_miscdev); |
675 | out_reg: | 718 | out_reg: |
676 | release_region (io, 16); | 719 | release_region(io, 16); |
677 | out_pci: | 720 | out_pci: |
678 | pci_disable_device(dev); | 721 | pci_disable_device(dev); |
679 | goto out; | 722 | goto out; |
680 | } | 723 | } |
681 | 724 | ||
682 | 725 | ||
683 | static void __devexit wdtpci_remove_one (struct pci_dev *pdev) | 726 | static void __devexit wdtpci_remove_one(struct pci_dev *pdev) |
684 | { | 727 | { |
685 | /* here we assume only one device will ever have | 728 | /* here we assume only one device will ever have |
686 | * been picked up and registered by probe function */ | 729 | * been picked up and registered by probe function */ |
@@ -728,7 +771,7 @@ static struct pci_driver wdtpci_driver = { | |||
728 | 771 | ||
729 | static void __exit wdtpci_cleanup(void) | 772 | static void __exit wdtpci_cleanup(void) |
730 | { | 773 | { |
731 | pci_unregister_driver (&wdtpci_driver); | 774 | pci_unregister_driver(&wdtpci_driver); |
732 | } | 775 | } |
733 | 776 | ||
734 | 777 | ||
@@ -742,7 +785,7 @@ static void __exit wdtpci_cleanup(void) | |||
742 | 785 | ||
743 | static int __init wdtpci_init(void) | 786 | static int __init wdtpci_init(void) |
744 | { | 787 | { |
745 | return pci_register_driver (&wdtpci_driver); | 788 | return pci_register_driver(&wdtpci_driver); |
746 | } | 789 | } |
747 | 790 | ||
748 | 791 | ||