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