ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 *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
378         static struct watchdog_info ident = {
379                 .options =              WDIOF_SETTIMEOUT|
380                                         WDIOF_MAGICCLOSE|
381                                         WDIOF_KEEPALIVEPING,
382                 .firmware_version =     1,
383                 .identity =             "PCI-WDT500/501",
384         };
385
386         /* Add options according to the card we have */
387         ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2);
388 #ifdef CONFIG_WDT_501_PCI
389         ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER|WDIOF_POWEROVER);
390         if (tachometer)
391                 ident.options |= WDIOF_FANFAULT;
392 #endif /* CONFIG_WDT_501_PCI */
393
394         switch(cmd)
395         {
396                 default:
397                         return -ENOIOCTLCMD;
398                 case WDIOC_GETSUPPORT:
399                         return copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident))?-EFAULT:0;
400
401                 case WDIOC_GETSTATUS:
402                         wdtpci_get_status(&status);
403                         return put_user(status,(int *)arg);
404                 case WDIOC_GETBOOTSTATUS:
405                         return put_user(0, (int *)arg);
406                 case WDIOC_KEEPALIVE:
407                         wdtpci_ping();
408                         return 0;
409                 case WDIOC_SETTIMEOUT:
410                         if (get_user(new_heartbeat, (int *)arg))
411                                 return -EFAULT;
412
413                         if (wdtpci_set_heartbeat(new_heartbeat))
414                                 return -EINVAL;
415
416                         wdtpci_ping();
417                         /* Fall */
418                 case WDIOC_GETTIMEOUT:
419                         return put_user(heartbeat, (int *)arg);
420         }
421 }
422
423 /**
424  *      wdtpci_open:
425  *      @inode: inode of device
426  *      @file: file handle to device
427  *
428  *      The watchdog device has been opened. The watchdog device is single
429  *      open and on opening we load the counters. Counter zero is a 100Hz
430  *      cascade, into counter 1 which downcounts to reboot. When the counter
431  *      triggers counter 2 downcounts the length of the reset pulse which
432  *      set set to be as long as possible.
433  */
434
435 static int wdtpci_open(struct inode *inode, struct file *file)
436 {
437         if (down_trylock(&open_sem))
438                 return -EBUSY;
439
440         if (nowayout) {
441                 __module_get(THIS_MODULE);
442         }
443         /*
444          *      Activate
445          */
446         wdtpci_start();
447         return 0;
448 }
449
450 /**
451  *      wdtpci_release:
452  *      @inode: inode to board
453  *      @file: file handle to board
454  *
455  *      The watchdog has a configurable API. There is a religious dispute
456  *      between people who want their watchdog to be able to shut down and
457  *      those who want to be sure if the watchdog manager dies the machine
458  *      reboots. In the former case we disable the counters, in the latter
459  *      case you have to open it again very soon.
460  */
461
462 static int wdtpci_release(struct inode *inode, struct file *file)
463 {
464         if (expect_close == 42) {
465                 wdtpci_stop();
466         } else {
467                 printk(KERN_CRIT PFX "Unexpected close, not stopping timer!");
468                 wdtpci_ping();
469         }
470         expect_close = 0;
471         up(&open_sem);
472         return 0;
473 }
474
475 #ifdef CONFIG_WDT_501_PCI
476 /**
477  *      wdtpci_temp_read:
478  *      @file: file handle to the watchdog board
479  *      @buf: buffer to write 1 byte into
480  *      @count: length of buffer
481  *      @ptr: offset (no seek allowed)
482  *
483  *      Read reports the temperature in degrees Fahrenheit. The API is in
484  *      fahrenheit. It was designed by an imperial measurement luddite.
485  */
486
487 static ssize_t wdtpci_temp_read(struct file *file, char *buf, size_t count, loff_t *ptr)
488 {
489         int temperature;
490
491         /*  Can't seek (pread) on this device  */
492         if (ptr != &file->f_pos)
493                 return -ESPIPE;
494
495         if (wdtpci_get_temperature(&temperature))
496                 return -EFAULT;
497
498         if (copy_to_user (buf, &temperature, 1))
499                 return -EFAULT;
500
501         return 1;
502 }
503
504 /**
505  *      wdtpci_temp_open:
506  *      @inode: inode of device
507  *      @file: file handle to device
508  *
509  *      The temperature device has been opened.
510  */
511
512 static int wdtpci_temp_open(struct inode *inode, struct file *file)
513 {
514         return 0;
515 }
516
517 /**
518  *      wdtpci_temp_release:
519  *      @inode: inode to board
520  *      @file: file handle to board
521  *
522  *      The temperature device has been closed.
523  */
524
525 static int wdtpci_temp_release(struct inode *inode, struct file *file)
526 {
527         return 0;
528 }
529 #endif /* CONFIG_WDT_501_PCI */
530
531 /**
532  *      notify_sys:
533  *      @this: our notifier block
534  *      @code: the event being reported
535  *      @unused: unused
536  *
537  *      Our notifier is called on system shutdowns. We want to turn the card
538  *      off at reboot otherwise the machine will reboot again during memory
539  *      test or worse yet during the following fsck. This would suck, in fact
540  *      trust me - if it happens it does suck.
541  */
542
543 static int wdtpci_notify_sys(struct notifier_block *this, unsigned long code,
544         void *unused)
545 {
546         if (code==SYS_DOWN || code==SYS_HALT) {
547                 /* Turn the card off */
548                 wdtpci_stop();
549         }
550         return NOTIFY_DONE;
551 }
552
553 /*
554  *      Kernel Interfaces
555  */
556
557
558 static struct file_operations wdtpci_fops = {
559         .owner          = THIS_MODULE,
560         .llseek         = no_llseek,
561         .write          = wdtpci_write,
562         .ioctl          = wdtpci_ioctl,
563         .open           = wdtpci_open,
564         .release        = wdtpci_release,
565 };
566
567 static struct miscdevice wdtpci_miscdev = {
568         .minor  = WATCHDOG_MINOR,
569         .name   = "watchdog",
570         .fops   = &wdtpci_fops,
571 };
572
573 #ifdef CONFIG_WDT_501_PCI
574 static struct file_operations wdtpci_temp_fops = {
575         .owner          = THIS_MODULE,
576         .llseek         = no_llseek,
577         .read           = wdtpci_temp_read,
578         .open           = wdtpci_temp_open,
579         .release        = wdtpci_temp_release,
580 };
581
582 static struct miscdevice temp_miscdev = {
583         .minor  = TEMP_MINOR,
584         .name   = "temperature",
585         .fops   = &wdtpci_temp_fops,
586 };
587 #endif /* CONFIG_WDT_501_PCI */
588
589 /*
590  *      The WDT card needs to learn about soft shutdowns in order to
591  *      turn the timebomb registers off.
592  */
593
594 static struct notifier_block wdtpci_notifier = {
595         .notifier_call = wdtpci_notify_sys,
596 };
597
598
599 static int __devinit wdtpci_init_one (struct pci_dev *dev,
600                                    const struct pci_device_id *ent)
601 {
602         int ret = -EIO;
603
604         dev_count++;
605         if (dev_count > 1) {
606                 printk (KERN_ERR PFX "this driver only supports 1 device\n");
607                 return -ENODEV;
608         }
609
610         if (pci_enable_device (dev)) {
611                 printk (KERN_ERR PFX "Not possible to enable PCI Device\n");
612                 return -ENODEV;
613         }
614
615         if (pci_resource_start (dev, 2) == 0x0000) {
616                 printk (KERN_ERR PFX "No I/O-Address for card detected\n");
617                 ret = -ENODEV;
618                 goto out_pci;
619         }
620
621         sema_init(&open_sem, 1);
622         spin_lock_init(&wdtpci_lock);
623
624         irq = dev->irq;
625         io = pci_resource_start (dev, 2);
626
627         if (request_region (io, 16, "wdt_pci") == NULL) {
628                 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", io);
629                 goto out_pci;
630         }
631
632         if (request_irq (irq, wdtpci_interrupt, SA_INTERRUPT | SA_SHIRQ,
633                          "wdt_pci", &wdtpci_miscdev)) {
634                 printk (KERN_ERR PFX "IRQ %d is not free\n", irq);
635                 goto out_reg;
636         }
637
638         printk ("PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n",
639                 io, irq);
640
641         /* Check that the heartbeat value is within it's range ; if not reset to the default */
642         if (wdtpci_set_heartbeat(heartbeat)) {
643                 wdtpci_set_heartbeat(WD_TIMO);
644                 printk(KERN_INFO PFX "heartbeat value must be 0<heartbeat<65536, using %d\n",
645                         WD_TIMO);
646         }
647
648         ret = register_reboot_notifier (&wdtpci_notifier);
649         if (ret) {
650                 printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", ret);
651                 goto out_irq;
652         }
653
654 #ifdef CONFIG_WDT_501_PCI
655         ret = misc_register (&temp_miscdev);
656         if (ret) {
657                 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
658                         TEMP_MINOR, ret);
659                 goto out_rbt;
660         }
661 #endif /* CONFIG_WDT_501_PCI */
662
663         ret = misc_register (&wdtpci_miscdev);
664         if (ret) {
665                 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
666                         WATCHDOG_MINOR, ret);
667                 goto out_misc;
668         }
669
670         printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
671                 heartbeat, nowayout);
672 #ifdef CONFIG_WDT_501_PCI
673         printk(KERN_INFO "wdt: Fan Tachometer is %s\n", (tachometer ? "Enabled" : "Disabled"));
674 #endif /* CONFIG_WDT_501_PCI */
675
676         ret = 0;
677 out:
678         return ret;
679
680 out_misc:
681 #ifdef CONFIG_WDT_501_PCI
682         misc_deregister(&temp_miscdev);
683 #endif /* CONFIG_WDT_501_PCI */
684 out_rbt:
685         unregister_reboot_notifier(&wdtpci_notifier);
686 out_irq:
687         free_irq(irq, &wdtpci_miscdev);
688 out_reg:
689         release_region (io, 16);
690 out_pci:
691         pci_disable_device(dev);
692         goto out;
693 }
694
695
696 static void __devexit wdtpci_remove_one (struct pci_dev *pdev)
697 {
698         /* here we assume only one device will ever have
699          * been picked up and registered by probe function */
700         misc_deregister(&wdtpci_miscdev);
701 #ifdef CONFIG_WDT_501_PCI
702         misc_deregister(&temp_miscdev);
703 #endif /* CONFIG_WDT_501_PCI */
704         unregister_reboot_notifier(&wdtpci_notifier);
705         free_irq(irq, &wdtpci_miscdev);
706         release_region(io, 16);
707         pci_disable_device(pdev);
708         dev_count--;
709 }
710
711
712 static struct pci_device_id wdtpci_pci_tbl[] = {
713         {
714                 .vendor    = PCI_VENDOR_ID_ACCESSIO,
715                 .device    = PCI_DEVICE_ID_WDG_CSM,
716                 .subvendor = PCI_ANY_ID,
717                 .subdevice = PCI_ANY_ID,
718         },
719         { 0, }, /* terminate list */
720 };
721 MODULE_DEVICE_TABLE(pci, wdtpci_pci_tbl);
722
723
724 static struct pci_driver wdtpci_driver = {
725         .name           = "wdt_pci",
726         .id_table       = wdtpci_pci_tbl,
727         .probe          = wdtpci_init_one,
728         .remove         = __devexit_p(wdtpci_remove_one),
729 };
730
731
732 /**
733  *      wdtpci_cleanup:
734  *
735  *      Unload the watchdog. You cannot do this with any file handles open.
736  *      If your watchdog is set to continue ticking on close and you unload
737  *      it, well it keeps ticking. We won't get the interrupt but the board
738  *      will not touch PC memory so all is fine. You just have to load a new
739  *      module in xx seconds or reboot.
740  */
741
742 static void __exit wdtpci_cleanup(void)
743 {
744         pci_unregister_driver (&wdtpci_driver);
745 }
746
747
748 /**
749  *      wdtpci_init:
750  *
751  *      Set up the WDT watchdog board. All we have to do is grab the
752  *      resources we require and bitch if anyone beat us to them.
753  *      The open() function will actually kick the board off.
754  */
755
756 static int __init wdtpci_init(void)
757 {
758         return pci_register_driver (&wdtpci_driver);
759 }
760
761
762 module_init(wdtpci_init);
763 module_exit(wdtpci_cleanup);
764
765 MODULE_AUTHOR("JP Nollmann, Alan Cox");
766 MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards");
767 MODULE_LICENSE("GPL");
768 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
769 MODULE_ALIAS_MISCDEV(TEMP_MINOR);