diff options
author | Alan Cox <alan@lxorguk.ukuu.org.uk> | 2009-03-22 06:46:42 -0400 |
---|---|---|
committer | Wim Van Sebroeck <wim@iguana.be> | 2009-03-25 05:08:16 -0400 |
commit | 04bedfa542d90ac7a1bbf28287e9861d0da21576 (patch) | |
tree | dd73752bf09bb2c2daf3e860217a1ec00fcd61bb /drivers/watchdog/wdt.c | |
parent | 278aefc51bdbc7f1a3d39c9bd5313c78335b7828 (diff) |
[WATCHDOG] wdt.c: remove #ifdef CONFIG_WDT_501
Change the wdt.c watchdog driver so that the code is the same for
both the WDT500 as the WDT501-P card. The selection of the card
is now being done via the module parameter: 'type' instead of the
config option CONFIG_WDT_501.
Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog/wdt.c')
-rw-r--r-- | drivers/watchdog/wdt.c | 152 |
1 files changed, 74 insertions, 78 deletions
diff --git a/drivers/watchdog/wdt.c b/drivers/watchdog/wdt.c index eddb9187e7b6..3bbefe9a2634 100644 --- a/drivers/watchdog/wdt.c +++ b/drivers/watchdog/wdt.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Industrial Computer Source WDT500/501 driver | 2 | * Industrial Computer Source WDT501 driver |
3 | * | 3 | * |
4 | * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>, | 4 | * (c) Copyright 1996-1997 Alan Cox <alan@lxorguk.ukuu.org.uk>, |
5 | * All Rights Reserved. | 5 | * All Rights Reserved. |
@@ -82,14 +82,16 @@ MODULE_PARM_DESC(io, "WDT io port (default=0x240)"); | |||
82 | module_param(irq, int, 0); | 82 | module_param(irq, int, 0); |
83 | MODULE_PARM_DESC(irq, "WDT irq (default=11)"); | 83 | MODULE_PARM_DESC(irq, "WDT irq (default=11)"); |
84 | 84 | ||
85 | #ifdef CONFIG_WDT_501 | ||
86 | /* Support for the Fan Tachometer on the WDT501-P */ | 85 | /* Support for the Fan Tachometer on the WDT501-P */ |
87 | static int tachometer; | 86 | static int tachometer; |
88 | |||
89 | module_param(tachometer, int, 0); | 87 | module_param(tachometer, int, 0); |
90 | MODULE_PARM_DESC(tachometer, | 88 | MODULE_PARM_DESC(tachometer, |
91 | "WDT501-P Fan Tachometer support (0=disable, default=0)"); | 89 | "WDT501-P Fan Tachometer support (0=disable, default=0)"); |
92 | #endif /* CONFIG_WDT_501 */ | 90 | |
91 | static int type = 500; | ||
92 | module_param(type, int, 0); | ||
93 | MODULE_PARM_DESC(type, | ||
94 | "WDT501-P Card type (500 or 501 , default=500)"); | ||
93 | 95 | ||
94 | /* | 96 | /* |
95 | * Programming support | 97 | * Programming support |
@@ -158,7 +160,7 @@ static int wdt_stop(void) | |||
158 | * reloading the cascade counter. | 160 | * reloading the cascade counter. |
159 | */ | 161 | */ |
160 | 162 | ||
161 | static int wdt_ping(void) | 163 | static void wdt_ping(void) |
162 | { | 164 | { |
163 | unsigned long flags; | 165 | unsigned long flags; |
164 | spin_lock_irqsave(&wdt_lock, flags); | 166 | spin_lock_irqsave(&wdt_lock, flags); |
@@ -169,7 +171,6 @@ static int wdt_ping(void) | |||
169 | wdt_ctr_load(1, wd_heartbeat); /* Heartbeat */ | 171 | wdt_ctr_load(1, wd_heartbeat); /* Heartbeat */ |
170 | outb_p(0, WDT_DC); /* Enable watchdog */ | 172 | outb_p(0, WDT_DC); /* Enable watchdog */ |
171 | spin_unlock_irqrestore(&wdt_lock, flags); | 173 | spin_unlock_irqrestore(&wdt_lock, flags); |
172 | return 0; | ||
173 | } | 174 | } |
174 | 175 | ||
175 | /** | 176 | /** |
@@ -193,7 +194,6 @@ static int wdt_set_heartbeat(int t) | |||
193 | 194 | ||
194 | /** | 195 | /** |
195 | * wdt_get_status: | 196 | * wdt_get_status: |
196 | * @status: the new status. | ||
197 | * | 197 | * |
198 | * Extract the status information from a WDT watchdog device. There are | 198 | * Extract the status information from a WDT watchdog device. There are |
199 | * several board variants so we have to know which bits are valid. Some | 199 | * several board variants so we have to know which bits are valid. Some |
@@ -202,36 +202,35 @@ static int wdt_set_heartbeat(int t) | |||
202 | * we then map the bits onto the status ioctl flags. | 202 | * we then map the bits onto the status ioctl flags. |
203 | */ | 203 | */ |
204 | 204 | ||
205 | static int wdt_get_status(int *status) | 205 | static int wdt_get_status(void) |
206 | { | 206 | { |
207 | unsigned char new_status; | 207 | unsigned char new_status; |
208 | int status = 0; | ||
208 | unsigned long flags; | 209 | unsigned long flags; |
209 | 210 | ||
210 | spin_lock_irqsave(&wdt_lock, flags); | 211 | spin_lock_irqsave(&wdt_lock, flags); |
211 | new_status = inb_p(WDT_SR); | 212 | new_status = inb_p(WDT_SR); |
212 | spin_unlock_irqrestore(&wdt_lock, flags); | 213 | spin_unlock_irqrestore(&wdt_lock, flags); |
213 | 214 | ||
214 | *status = 0; | ||
215 | if (new_status & WDC_SR_ISOI0) | 215 | if (new_status & WDC_SR_ISOI0) |
216 | *status |= WDIOF_EXTERN1; | 216 | status |= WDIOF_EXTERN1; |
217 | if (new_status & WDC_SR_ISII1) | 217 | if (new_status & WDC_SR_ISII1) |
218 | *status |= WDIOF_EXTERN2; | 218 | status |= WDIOF_EXTERN2; |
219 | #ifdef CONFIG_WDT_501 | 219 | if (type == 501) { |
220 | if (!(new_status & WDC_SR_TGOOD)) | 220 | if (!(new_status & WDC_SR_TGOOD)) |
221 | *status |= WDIOF_OVERHEAT; | 221 | status |= WDIOF_OVERHEAT; |
222 | if (!(new_status & WDC_SR_PSUOVER)) | 222 | if (!(new_status & WDC_SR_PSUOVER)) |
223 | *status |= WDIOF_POWEROVER; | 223 | status |= WDIOF_POWEROVER; |
224 | if (!(new_status & WDC_SR_PSUUNDR)) | 224 | if (!(new_status & WDC_SR_PSUUNDR)) |
225 | *status |= WDIOF_POWERUNDER; | 225 | status |= WDIOF_POWERUNDER; |
226 | if (tachometer) { | 226 | if (tachometer) { |
227 | if (!(new_status & WDC_SR_FANGOOD)) | 227 | if (!(new_status & WDC_SR_FANGOOD)) |
228 | *status |= WDIOF_FANFAULT; | 228 | status |= WDIOF_FANFAULT; |
229 | } | ||
229 | } | 230 | } |
230 | #endif /* CONFIG_WDT_501 */ | 231 | return status; |
231 | return 0; | ||
232 | } | 232 | } |
233 | 233 | ||
234 | #ifdef CONFIG_WDT_501 | ||
235 | /** | 234 | /** |
236 | * wdt_get_temperature: | 235 | * wdt_get_temperature: |
237 | * | 236 | * |
@@ -239,7 +238,7 @@ static int wdt_get_status(int *status) | |||
239 | * farenheit. It was designed by an imperial measurement luddite. | 238 | * farenheit. It was designed by an imperial measurement luddite. |
240 | */ | 239 | */ |
241 | 240 | ||
242 | static int wdt_get_temperature(int *temperature) | 241 | static int wdt_get_temperature(void) |
243 | { | 242 | { |
244 | unsigned short c; | 243 | unsigned short c; |
245 | unsigned long flags; | 244 | unsigned long flags; |
@@ -247,10 +246,18 @@ static int wdt_get_temperature(int *temperature) | |||
247 | spin_lock_irqsave(&wdt_lock, flags); | 246 | spin_lock_irqsave(&wdt_lock, flags); |
248 | c = inb_p(WDT_RT); | 247 | c = inb_p(WDT_RT); |
249 | spin_unlock_irqrestore(&wdt_lock, flags); | 248 | spin_unlock_irqrestore(&wdt_lock, flags); |
250 | *temperature = (c * 11 / 15) + 7; | 249 | return (c * 11 / 15) + 7; |
251 | return 0; | 250 | } |
251 | |||
252 | static void wdt_decode_501(int status) | ||
253 | { | ||
254 | if (!(status & WDC_SR_TGOOD)) | ||
255 | printk(KERN_CRIT "Overheat alarm.(%d)\n", inb_p(WDT_RT)); | ||
256 | if (!(status & WDC_SR_PSUOVER)) | ||
257 | printk(KERN_CRIT "PSU over voltage.\n"); | ||
258 | if (!(status & WDC_SR_PSUUNDR)) | ||
259 | printk(KERN_CRIT "PSU under voltage.\n"); | ||
252 | } | 260 | } |
253 | #endif /* CONFIG_WDT_501 */ | ||
254 | 261 | ||
255 | /** | 262 | /** |
256 | * wdt_interrupt: | 263 | * wdt_interrupt: |
@@ -275,18 +282,13 @@ static irqreturn_t wdt_interrupt(int irq, void *dev_id) | |||
275 | 282 | ||
276 | printk(KERN_CRIT "WDT status %d\n", status); | 283 | printk(KERN_CRIT "WDT status %d\n", status); |
277 | 284 | ||
278 | #ifdef CONFIG_WDT_501 | 285 | if (type == 501) { |
279 | if (!(status & WDC_SR_TGOOD)) | 286 | wdt_decode_501(status); |
280 | printk(KERN_CRIT "Overheat alarm.(%d)\n", inb_p(WDT_RT)); | 287 | if (tachometer) { |
281 | if (!(status & WDC_SR_PSUOVER)) | 288 | if (!(status & WDC_SR_FANGOOD)) |
282 | printk(KERN_CRIT "PSU over voltage.\n"); | 289 | printk(KERN_CRIT "Possible fan fault.\n"); |
283 | if (!(status & WDC_SR_PSUUNDR)) | 290 | } |
284 | printk(KERN_CRIT "PSU under voltage.\n"); | ||
285 | if (tachometer) { | ||
286 | if (!(status & WDC_SR_FANGOOD)) | ||
287 | printk(KERN_CRIT "Possible fan fault.\n"); | ||
288 | } | 291 | } |
289 | #endif /* CONFIG_WDT_501 */ | ||
290 | if (!(status & WDC_SR_WCCR)) { | 292 | if (!(status & WDC_SR_WCCR)) { |
291 | #ifdef SOFTWARE_REBOOT | 293 | #ifdef SOFTWARE_REBOOT |
292 | #ifdef ONLY_TESTING | 294 | #ifdef ONLY_TESTING |
@@ -366,17 +368,18 @@ static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |||
366 | 368 | ||
367 | /* Add options according to the card we have */ | 369 | /* Add options according to the card we have */ |
368 | ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2); | 370 | ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2); |
369 | #ifdef CONFIG_WDT_501 | 371 | if (type == 501) { |
370 | ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER|WDIOF_POWEROVER); | 372 | ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER| |
371 | if (tachometer) | 373 | WDIOF_POWEROVER); |
372 | ident.options |= WDIOF_FANFAULT; | 374 | if (tachometer) |
373 | #endif /* CONFIG_WDT_501 */ | 375 | ident.options |= WDIOF_FANFAULT; |
376 | } | ||
374 | 377 | ||
375 | switch (cmd) { | 378 | switch (cmd) { |
376 | case WDIOC_GETSUPPORT: | 379 | case WDIOC_GETSUPPORT: |
377 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; | 380 | return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0; |
378 | case WDIOC_GETSTATUS: | 381 | case WDIOC_GETSTATUS: |
379 | wdt_get_status(&status); | 382 | status = wdt_get_status(); |
380 | return put_user(status, p); | 383 | return put_user(status, p); |
381 | case WDIOC_GETBOOTSTATUS: | 384 | case WDIOC_GETBOOTSTATUS: |
382 | return put_user(0, p); | 385 | return put_user(0, p); |
@@ -446,7 +449,6 @@ static int wdt_release(struct inode *inode, struct file *file) | |||
446 | return 0; | 449 | return 0; |
447 | } | 450 | } |
448 | 451 | ||
449 | #ifdef CONFIG_WDT_501 | ||
450 | /** | 452 | /** |
451 | * wdt_temp_read: | 453 | * wdt_temp_read: |
452 | * @file: file handle to the watchdog board | 454 | * @file: file handle to the watchdog board |
@@ -461,10 +463,7 @@ static int wdt_release(struct inode *inode, struct file *file) | |||
461 | static ssize_t wdt_temp_read(struct file *file, char __user *buf, | 463 | static ssize_t wdt_temp_read(struct file *file, char __user *buf, |
462 | size_t count, loff_t *ptr) | 464 | size_t count, loff_t *ptr) |
463 | { | 465 | { |
464 | int temperature; | 466 | int temperature = wdt_get_temperature(); |
465 | |||
466 | if (wdt_get_temperature(&temperature)) | ||
467 | return -EFAULT; | ||
468 | 467 | ||
469 | if (copy_to_user(buf, &temperature, 1)) | 468 | if (copy_to_user(buf, &temperature, 1)) |
470 | return -EFAULT; | 469 | return -EFAULT; |
@@ -497,7 +496,6 @@ static int wdt_temp_release(struct inode *inode, struct file *file) | |||
497 | { | 496 | { |
498 | return 0; | 497 | return 0; |
499 | } | 498 | } |
500 | #endif /* CONFIG_WDT_501 */ | ||
501 | 499 | ||
502 | /** | 500 | /** |
503 | * notify_sys: | 501 | * notify_sys: |
@@ -539,7 +537,6 @@ static struct miscdevice wdt_miscdev = { | |||
539 | .fops = &wdt_fops, | 537 | .fops = &wdt_fops, |
540 | }; | 538 | }; |
541 | 539 | ||
542 | #ifdef CONFIG_WDT_501 | ||
543 | static const struct file_operations wdt_temp_fops = { | 540 | static const struct file_operations wdt_temp_fops = { |
544 | .owner = THIS_MODULE, | 541 | .owner = THIS_MODULE, |
545 | .llseek = no_llseek, | 542 | .llseek = no_llseek, |
@@ -553,7 +550,6 @@ static struct miscdevice temp_miscdev = { | |||
553 | .name = "temperature", | 550 | .name = "temperature", |
554 | .fops = &wdt_temp_fops, | 551 | .fops = &wdt_temp_fops, |
555 | }; | 552 | }; |
556 | #endif /* CONFIG_WDT_501 */ | ||
557 | 553 | ||
558 | /* | 554 | /* |
559 | * The WDT card needs to learn about soft shutdowns in order to | 555 | * The WDT card needs to learn about soft shutdowns in order to |
@@ -577,9 +573,8 @@ static struct notifier_block wdt_notifier = { | |||
577 | static void __exit wdt_exit(void) | 573 | static void __exit wdt_exit(void) |
578 | { | 574 | { |
579 | misc_deregister(&wdt_miscdev); | 575 | misc_deregister(&wdt_miscdev); |
580 | #ifdef CONFIG_WDT_501 | 576 | if (type == 501) |
581 | misc_deregister(&temp_miscdev); | 577 | misc_deregister(&temp_miscdev); |
582 | #endif /* CONFIG_WDT_501 */ | ||
583 | unregister_reboot_notifier(&wdt_notifier); | 578 | unregister_reboot_notifier(&wdt_notifier); |
584 | free_irq(irq, NULL); | 579 | free_irq(irq, NULL); |
585 | release_region(io, 8); | 580 | release_region(io, 8); |
@@ -597,12 +592,17 @@ static int __init wdt_init(void) | |||
597 | { | 592 | { |
598 | int ret; | 593 | int ret; |
599 | 594 | ||
595 | if (type != 500 && type != 501) { | ||
596 | printk(KERN_ERR "wdt: unknown card type '%d'.\n", type); | ||
597 | return -ENODEV; | ||
598 | } | ||
599 | |||
600 | /* Check that the heartbeat value is within it's range; | 600 | /* Check that the heartbeat value is within it's range; |
601 | if not reset to the default */ | 601 | if not reset to the default */ |
602 | if (wdt_set_heartbeat(heartbeat)) { | 602 | if (wdt_set_heartbeat(heartbeat)) { |
603 | wdt_set_heartbeat(WD_TIMO); | 603 | wdt_set_heartbeat(WD_TIMO); |
604 | printk(KERN_INFO "wdt: heartbeat value must be 0 < heartbeat < 65536, using %d\n", | 604 | printk(KERN_INFO "wdt: heartbeat value must be " |
605 | WD_TIMO); | 605 | "0 < heartbeat < 65536, using %d\n", WD_TIMO); |
606 | } | 606 | } |
607 | 607 | ||
608 | if (!request_region(io, 8, "wdt501p")) { | 608 | if (!request_region(io, 8, "wdt501p")) { |
@@ -625,15 +625,14 @@ static int __init wdt_init(void) | |||
625 | goto outirq; | 625 | goto outirq; |
626 | } | 626 | } |
627 | 627 | ||
628 | #ifdef CONFIG_WDT_501 | 628 | if (type == 501) { |
629 | ret = misc_register(&temp_miscdev); | 629 | ret = misc_register(&temp_miscdev); |
630 | if (ret) { | 630 | if (ret) { |
631 | printk(KERN_ERR | 631 | printk(KERN_ERR "wdt: cannot register miscdev " |
632 | "wdt: cannot register miscdev on minor=%d (err=%d)\n", | 632 | "on minor=%d (err=%d)\n", TEMP_MINOR, ret); |
633 | TEMP_MINOR, ret); | 633 | goto outrbt; |
634 | goto outrbt; | 634 | } |
635 | } | 635 | } |
636 | #endif /* CONFIG_WDT_501 */ | ||
637 | 636 | ||
638 | ret = misc_register(&wdt_miscdev); | 637 | ret = misc_register(&wdt_miscdev); |
639 | if (ret) { | 638 | if (ret) { |
@@ -643,28 +642,25 @@ static int __init wdt_init(void) | |||
643 | goto outmisc; | 642 | goto outmisc; |
644 | } | 643 | } |
645 | 644 | ||
646 | ret = 0; | 645 | printk(KERN_INFO "WDT500/501-P driver 0.10 " |
647 | printk(KERN_INFO "WDT500/501-P driver 0.10 at 0x%04x (Interrupt %d). heartbeat=%d sec (nowayout=%d)\n", | 646 | "at 0x%04x (Interrupt %d). heartbeat=%d sec (nowayout=%d)\n", |
648 | io, irq, heartbeat, nowayout); | 647 | io, irq, heartbeat, nowayout); |
649 | #ifdef CONFIG_WDT_501 | 648 | if (type == 501) |
650 | printk(KERN_INFO "wdt: Fan Tachometer is %s\n", | 649 | printk(KERN_INFO "wdt: Fan Tachometer is %s\n", |
651 | (tachometer ? "Enabled" : "Disabled")); | 650 | (tachometer ? "Enabled" : "Disabled")); |
652 | #endif /* CONFIG_WDT_501 */ | 651 | return 0; |
653 | |||
654 | out: | ||
655 | return ret; | ||
656 | 652 | ||
657 | outmisc: | 653 | outmisc: |
658 | #ifdef CONFIG_WDT_501 | 654 | if (type == 501) |
659 | misc_deregister(&temp_miscdev); | 655 | misc_deregister(&temp_miscdev); |
660 | outrbt: | 656 | outrbt: |
661 | #endif /* CONFIG_WDT_501 */ | ||
662 | unregister_reboot_notifier(&wdt_notifier); | 657 | unregister_reboot_notifier(&wdt_notifier); |
663 | outirq: | 658 | outirq: |
664 | free_irq(irq, NULL); | 659 | free_irq(irq, NULL); |
665 | outreg: | 660 | outreg: |
666 | release_region(io, 8); | 661 | release_region(io, 8); |
667 | goto out; | 662 | out: |
663 | return ret; | ||
668 | } | 664 | } |
669 | 665 | ||
670 | module_init(wdt_init); | 666 | module_init(wdt_init); |