[WATCHDOG] add WDIOC_GETTIMELEFT ioctl
[linux-2.6/zen-sources.git] / drivers / char / watchdog / pcwd_pci.c
blob1f40ecefbf7260c020c6117118975a0facfadff6
1 /*
2 * Berkshire PCI-PC Watchdog Card Driver
4 * (c) Copyright 2003-2005 Wim Van Sebroeck <wim@iguana.be>.
6 * Based on source code of the following authors:
7 * Ken Hollis <kenji@bitgate.com>,
8 * Lindsay Harris <lindsay@bluegum.com>,
9 * Alan Cox <alan@redhat.com>,
10 * Matt Domsch <Matt_Domsch@dell.com>,
11 * Rob Radez <rob@osinvestor.com>
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
18 * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
19 * provide warranty for any of this software. This material is
20 * provided "AS-IS" and at no charge.
24 * A bells and whistles driver is available from:
25 * http://www.kernel.org/pub/linux/kernel/people/wim/pcwd/pcwd_pci/
27 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
31 * Includes, defines, variables, module parameters, ...
34 #include <linux/config.h> /* For CONFIG_WATCHDOG_NOWAYOUT/... */
35 #include <linux/module.h> /* For module specific items */
36 #include <linux/moduleparam.h> /* For new moduleparam's */
37 #include <linux/types.h> /* For standard types (like size_t) */
38 #include <linux/errno.h> /* For the -ENODEV/... values */
39 #include <linux/kernel.h> /* For printk/panic/... */
40 #include <linux/delay.h> /* For mdelay function */
41 #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
42 #include <linux/watchdog.h> /* For the watchdog specific items */
43 #include <linux/notifier.h> /* For notifier support */
44 #include <linux/reboot.h> /* For reboot_notifier stuff */
45 #include <linux/init.h> /* For __init/__exit/... */
46 #include <linux/fs.h> /* For file operations */
47 #include <linux/pci.h> /* For pci functions */
48 #include <linux/ioport.h> /* For io-port access */
49 #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
51 #include <asm/uaccess.h> /* For copy_to_user/put_user/... */
52 #include <asm/io.h> /* For inb/outb/... */
54 /* Module and version information */
55 #define WATCHDOG_VERSION "1.02"
56 #define WATCHDOG_DATE "03 Sep 2005"
57 #define WATCHDOG_DRIVER_NAME "PCI-PC Watchdog"
58 #define WATCHDOG_NAME "pcwd_pci"
59 #define PFX WATCHDOG_NAME ": "
60 #define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
62 /* Stuff for the PCI ID's */
63 #ifndef PCI_VENDOR_ID_QUICKLOGIC
64 #define PCI_VENDOR_ID_QUICKLOGIC 0x11e3
65 #endif
67 #ifndef PCI_DEVICE_ID_WATCHDOG_PCIPCWD
68 #define PCI_DEVICE_ID_WATCHDOG_PCIPCWD 0x5030
69 #endif
72 * These are the defines that describe the control status bits for the
73 * PCI-PC Watchdog card.
75 /* Port 1 : Control Status #1 */
76 #define WD_PCI_WTRP 0x01 /* Watchdog Trip status */
77 #define WD_PCI_HRBT 0x02 /* Watchdog Heartbeat */
78 #define WD_PCI_TTRP 0x04 /* Temperature Trip status */
79 #define WD_PCI_RL2A 0x08 /* Relay 2 Active */
80 #define WD_PCI_RL1A 0x10 /* Relay 1 Active */
81 #define WD_PCI_R2DS 0x40 /* Relay 2 Disable Temperature-trip/reset */
82 #define WD_PCI_RLY2 0x80 /* Activate Relay 2 on the board */
83 /* Port 2 : Control Status #2 */
84 #define WD_PCI_WDIS 0x10 /* Watchdog Disable */
85 #define WD_PCI_ENTP 0x20 /* Enable Temperature Trip Reset */
86 #define WD_PCI_WRSP 0x40 /* Watchdog wrote response */
87 #define WD_PCI_PCMD 0x80 /* PC has sent command */
89 /* according to documentation max. time to process a command for the pci
90 * watchdog card is 100 ms, so we give it 150 ms to do it's job */
91 #define PCI_COMMAND_TIMEOUT 150
93 /* Watchdog's internal commands */
94 #define CMD_GET_STATUS 0x04
95 #define CMD_GET_FIRMWARE_VERSION 0x08
96 #define CMD_READ_WATCHDOG_TIMEOUT 0x18
97 #define CMD_WRITE_WATCHDOG_TIMEOUT 0x19
98 #define CMD_GET_CLEAR_RESET_COUNT 0x84
100 /* We can only use 1 card due to the /dev/watchdog restriction */
101 static int cards_found;
103 /* internal variables */
104 static int temp_panic;
105 static unsigned long is_active;
106 static char expect_release;
107 static struct { /* this is private data for each PCI-PC watchdog card */
108 int supports_temp; /* Wether or not the card has a temperature device */
109 int boot_status; /* The card's boot status */
110 unsigned long io_addr; /* The cards I/O address */
111 spinlock_t io_lock; /* the lock for io operations */
112 struct pci_dev *pdev; /* the PCI-device */
113 } pcipcwd_private;
115 /* module parameters */
116 #define QUIET 0 /* Default */
117 #define VERBOSE 1 /* Verbose */
118 #define DEBUG 2 /* print fancy stuff too */
119 static int debug = QUIET;
120 module_param(debug, int, 0);
121 MODULE_PARM_DESC(debug, "Debug level: 0=Quiet, 1=Verbose, 2=Debug (default=0)");
123 #define WATCHDOG_HEARTBEAT 2 /* 2 sec default heartbeat */
124 static int heartbeat = WATCHDOG_HEARTBEAT;
125 module_param(heartbeat, int, 0);
126 MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
128 static int nowayout = WATCHDOG_NOWAYOUT;
129 module_param(nowayout, int, 0);
130 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
133 * Internal functions
136 static int send_command(int cmd, int *msb, int *lsb)
138 int got_response, count;
140 if (debug >= DEBUG)
141 printk(KERN_DEBUG PFX "sending following data cmd=0x%02x msb=0x%02x lsb=0x%02x\n",
142 cmd, *msb, *lsb);
144 spin_lock(&pcipcwd_private.io_lock);
145 /* If a command requires data it should be written first.
146 * Data for commands with 8 bits of data should be written to port 4.
147 * Commands with 16 bits of data, should be written as LSB to port 4
148 * and MSB to port 5.
149 * After the required data has been written then write the command to
150 * port 6. */
151 outb_p(*lsb, pcipcwd_private.io_addr + 4);
152 outb_p(*msb, pcipcwd_private.io_addr + 5);
153 outb_p(cmd, pcipcwd_private.io_addr + 6);
155 /* wait till the pci card processed the command, signaled by
156 * the WRSP bit in port 2 and give it a max. timeout of
157 * PCI_COMMAND_TIMEOUT to process */
158 got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
159 for (count = 0; (count < PCI_COMMAND_TIMEOUT) && (!got_response); count++) {
160 mdelay(1);
161 got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
164 if (debug >= DEBUG) {
165 if (got_response) {
166 printk(KERN_DEBUG PFX "time to process command was: %d ms\n",
167 count);
168 } else {
169 printk(KERN_DEBUG PFX "card did not respond on command!\n");
173 if (got_response) {
174 /* read back response */
175 *lsb = inb_p(pcipcwd_private.io_addr + 4);
176 *msb = inb_p(pcipcwd_private.io_addr + 5);
178 /* clear WRSP bit */
179 inb_p(pcipcwd_private.io_addr + 6);
181 if (debug >= DEBUG)
182 printk(KERN_DEBUG PFX "received following data for cmd=0x%02x: msb=0x%02x lsb=0x%02x\n",
183 cmd, *msb, *lsb);
186 spin_unlock(&pcipcwd_private.io_lock);
188 return got_response;
191 static inline void pcipcwd_check_temperature_support(void)
193 if (inb_p(pcipcwd_private.io_addr) != 0xF0)
194 pcipcwd_private.supports_temp = 1;
197 static int pcipcwd_get_option_switches(void)
199 int option_switches;
201 option_switches = inb_p(pcipcwd_private.io_addr + 3);
202 return option_switches;
205 static void pcipcwd_show_card_info(void)
207 int got_fw_rev, fw_rev_major, fw_rev_minor;
208 char fw_ver_str[20]; /* The cards firmware version */
209 int option_switches;
211 got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major, &fw_rev_minor);
212 if (got_fw_rev) {
213 sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
214 } else {
215 sprintf(fw_ver_str, "<card no answer>");
218 /* Get switch settings */
219 option_switches = pcipcwd_get_option_switches();
221 printk(KERN_INFO PFX "Found card at port 0x%04x (Firmware: %s) %s temp option\n",
222 (int) pcipcwd_private.io_addr, fw_ver_str,
223 (pcipcwd_private.supports_temp ? "with" : "without"));
225 printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
226 option_switches,
227 ((option_switches & 0x10) ? "ON" : "OFF"),
228 ((option_switches & 0x08) ? "ON" : "OFF"));
230 if (pcipcwd_private.boot_status & WDIOF_CARDRESET)
231 printk(KERN_INFO PFX "Previous reset was caused by the Watchdog card\n");
233 if (pcipcwd_private.boot_status & WDIOF_OVERHEAT)
234 printk(KERN_INFO PFX "Card sensed a CPU Overheat\n");
236 if (pcipcwd_private.boot_status == 0)
237 printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
240 static int pcipcwd_start(void)
242 int stat_reg;
244 spin_lock(&pcipcwd_private.io_lock);
245 outb_p(0x00, pcipcwd_private.io_addr + 3);
246 udelay(1000);
248 stat_reg = inb_p(pcipcwd_private.io_addr + 2);
249 spin_unlock(&pcipcwd_private.io_lock);
251 if (stat_reg & WD_PCI_WDIS) {
252 printk(KERN_ERR PFX "Card timer not enabled\n");
253 return -1;
256 if (debug >= VERBOSE)
257 printk(KERN_DEBUG PFX "Watchdog started\n");
259 return 0;
262 static int pcipcwd_stop(void)
264 int stat_reg;
266 spin_lock(&pcipcwd_private.io_lock);
267 outb_p(0xA5, pcipcwd_private.io_addr + 3);
268 udelay(1000);
270 outb_p(0xA5, pcipcwd_private.io_addr + 3);
271 udelay(1000);
273 stat_reg = inb_p(pcipcwd_private.io_addr + 2);
274 spin_unlock(&pcipcwd_private.io_lock);
276 if (!(stat_reg & WD_PCI_WDIS)) {
277 printk(KERN_ERR PFX "Card did not acknowledge disable attempt\n");
278 return -1;
281 if (debug >= VERBOSE)
282 printk(KERN_DEBUG PFX "Watchdog stopped\n");
284 return 0;
287 static int pcipcwd_keepalive(void)
289 /* Re-trigger watchdog by writing to port 0 */
290 outb_p(0x42, pcipcwd_private.io_addr); /* send out any data */
292 if (debug >= DEBUG)
293 printk(KERN_DEBUG PFX "Watchdog keepalive signal send\n");
295 return 0;
298 static int pcipcwd_set_heartbeat(int t)
300 int t_msb = t / 256;
301 int t_lsb = t % 256;
303 if ((t < 0x0001) || (t > 0xFFFF))
304 return -EINVAL;
306 /* Write new heartbeat to watchdog */
307 send_command(CMD_WRITE_WATCHDOG_TIMEOUT, &t_msb, &t_lsb);
309 heartbeat = t;
310 if (debug >= VERBOSE)
311 printk(KERN_DEBUG PFX "New heartbeat: %d\n",
312 heartbeat);
314 return 0;
317 static int pcipcwd_get_status(int *status)
319 int control_status;
321 *status=0;
322 control_status = inb_p(pcipcwd_private.io_addr + 1);
323 if (control_status & WD_PCI_WTRP)
324 *status |= WDIOF_CARDRESET;
325 if (control_status & WD_PCI_TTRP) {
326 *status |= WDIOF_OVERHEAT;
327 if (temp_panic)
328 panic(PFX "Temperature overheat trip!\n");
331 if (debug >= DEBUG)
332 printk(KERN_DEBUG PFX "Control Status #1: 0x%02x\n",
333 control_status);
335 return 0;
338 static int pcipcwd_clear_status(void)
340 int control_status;
341 int msb;
342 int reset_counter;
344 if (debug >= VERBOSE)
345 printk(KERN_INFO PFX "clearing watchdog trip status & LED\n");
347 control_status = inb_p(pcipcwd_private.io_addr + 1);
349 if (debug >= DEBUG) {
350 printk(KERN_DEBUG PFX "status was: 0x%02x\n", control_status);
351 printk(KERN_DEBUG PFX "sending: 0x%02x\n",
352 (control_status & WD_PCI_R2DS) | WD_PCI_WTRP);
355 /* clear trip status & LED and keep mode of relay 2 */
356 outb_p((control_status & WD_PCI_R2DS) | WD_PCI_WTRP, pcipcwd_private.io_addr + 1);
358 /* clear reset counter */
359 msb=0;
360 reset_counter=0xff;
361 send_command(CMD_GET_CLEAR_RESET_COUNT, &msb, &reset_counter);
363 if (debug >= DEBUG) {
364 printk(KERN_DEBUG PFX "reset count was: 0x%02x\n",
365 reset_counter);
368 return 0;
371 static int pcipcwd_get_temperature(int *temperature)
373 *temperature = 0;
374 if (!pcipcwd_private.supports_temp)
375 return -ENODEV;
377 *temperature = inb_p(pcipcwd_private.io_addr);
380 * Convert celsius to fahrenheit, since this was
381 * the decided 'standard' for this return value.
383 *temperature = (*temperature * 9 / 5) + 32;
385 if (debug >= DEBUG) {
386 printk(KERN_DEBUG PFX "temperature is: %d F\n",
387 *temperature);
390 return 0;
393 static int pcipcwd_get_timeleft(int *time_left)
395 int msb;
396 int lsb;
398 /* Read the time that's left before rebooting */
399 /* Note: if the board is not yet armed then we will read 0xFFFF */
400 send_command(CMD_READ_WATCHDOG_TIMEOUT, &msb, &lsb);
402 *time_left = (msb << 8) + lsb;
404 if (debug >= VERBOSE)
405 printk(KERN_DEBUG PFX "Time left before next reboot: %d\n",
406 *time_left);
408 return 0;
412 * /dev/watchdog handling
415 static ssize_t pcipcwd_write(struct file *file, const char __user *data,
416 size_t len, loff_t *ppos)
418 /* See if we got the magic character 'V' and reload the timer */
419 if (len) {
420 if (!nowayout) {
421 size_t i;
423 /* note: just in case someone wrote the magic character
424 * five months ago... */
425 expect_release = 0;
427 /* scan to see whether or not we got the magic character */
428 for (i = 0; i != len; i++) {
429 char c;
430 if(get_user(c, data+i))
431 return -EFAULT;
432 if (c == 'V')
433 expect_release = 42;
437 /* someone wrote to us, we should reload the timer */
438 pcipcwd_keepalive();
440 return len;
443 static int pcipcwd_ioctl(struct inode *inode, struct file *file,
444 unsigned int cmd, unsigned long arg)
446 void __user *argp = (void __user *)arg;
447 int __user *p = argp;
448 static struct watchdog_info ident = {
449 .options = WDIOF_OVERHEAT |
450 WDIOF_CARDRESET |
451 WDIOF_KEEPALIVEPING |
452 WDIOF_SETTIMEOUT |
453 WDIOF_MAGICCLOSE,
454 .firmware_version = 1,
455 .identity = WATCHDOG_DRIVER_NAME,
458 switch (cmd) {
459 case WDIOC_GETSUPPORT:
460 return copy_to_user(argp, &ident,
461 sizeof (ident)) ? -EFAULT : 0;
463 case WDIOC_GETSTATUS:
465 int status;
467 pcipcwd_get_status(&status);
469 return put_user(status, p);
472 case WDIOC_GETBOOTSTATUS:
473 return put_user(pcipcwd_private.boot_status, p);
475 case WDIOC_GETTEMP:
477 int temperature;
479 if (pcipcwd_get_temperature(&temperature))
480 return -EFAULT;
482 return put_user(temperature, p);
485 case WDIOC_KEEPALIVE:
486 pcipcwd_keepalive();
487 return 0;
489 case WDIOC_SETOPTIONS:
491 int new_options, retval = -EINVAL;
493 if (get_user (new_options, p))
494 return -EFAULT;
496 if (new_options & WDIOS_DISABLECARD) {
497 if (pcipcwd_stop())
498 return -EIO;
499 retval = 0;
502 if (new_options & WDIOS_ENABLECARD) {
503 if (pcipcwd_start())
504 return -EIO;
505 retval = 0;
508 if (new_options & WDIOS_TEMPPANIC) {
509 temp_panic = 1;
510 retval = 0;
513 return retval;
516 case WDIOC_SETTIMEOUT:
518 int new_heartbeat;
520 if (get_user(new_heartbeat, p))
521 return -EFAULT;
523 if (pcipcwd_set_heartbeat(new_heartbeat))
524 return -EINVAL;
526 pcipcwd_keepalive();
527 /* Fall */
530 case WDIOC_GETTIMEOUT:
531 return put_user(heartbeat, p);
533 case WDIOC_GETTIMELEFT:
535 int time_left;
537 if (pcipcwd_get_timeleft(&time_left))
538 return -EFAULT;
540 return put_user(time_left, p);
543 default:
544 return -ENOIOCTLCMD;
548 static int pcipcwd_open(struct inode *inode, struct file *file)
550 /* /dev/watchdog can only be opened once */
551 if (test_and_set_bit(0, &is_active)) {
552 if (debug >= VERBOSE)
553 printk(KERN_ERR PFX "Attempt to open already opened device.\n");
554 return -EBUSY;
557 /* Activate */
558 pcipcwd_start();
559 pcipcwd_keepalive();
560 return nonseekable_open(inode, file);
563 static int pcipcwd_release(struct inode *inode, struct file *file)
566 * Shut off the timer.
568 if (expect_release == 42) {
569 pcipcwd_stop();
570 } else {
571 printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
572 pcipcwd_keepalive();
574 expect_release = 0;
575 clear_bit(0, &is_active);
576 return 0;
580 * /dev/temperature handling
583 static ssize_t pcipcwd_temp_read(struct file *file, char __user *data,
584 size_t len, loff_t *ppos)
586 int temperature;
588 if (pcipcwd_get_temperature(&temperature))
589 return -EFAULT;
591 if (copy_to_user (data, &temperature, 1))
592 return -EFAULT;
594 return 1;
597 static int pcipcwd_temp_open(struct inode *inode, struct file *file)
599 if (!pcipcwd_private.supports_temp)
600 return -ENODEV;
602 return nonseekable_open(inode, file);
605 static int pcipcwd_temp_release(struct inode *inode, struct file *file)
607 return 0;
611 * Notify system
614 static int pcipcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
616 if (code==SYS_DOWN || code==SYS_HALT) {
617 /* Turn the WDT off */
618 pcipcwd_stop();
621 return NOTIFY_DONE;
625 * Kernel Interfaces
628 static struct file_operations pcipcwd_fops = {
629 .owner = THIS_MODULE,
630 .llseek = no_llseek,
631 .write = pcipcwd_write,
632 .ioctl = pcipcwd_ioctl,
633 .open = pcipcwd_open,
634 .release = pcipcwd_release,
637 static struct miscdevice pcipcwd_miscdev = {
638 .minor = WATCHDOG_MINOR,
639 .name = "watchdog",
640 .fops = &pcipcwd_fops,
643 static struct file_operations pcipcwd_temp_fops = {
644 .owner = THIS_MODULE,
645 .llseek = no_llseek,
646 .read = pcipcwd_temp_read,
647 .open = pcipcwd_temp_open,
648 .release = pcipcwd_temp_release,
651 static struct miscdevice pcipcwd_temp_miscdev = {
652 .minor = TEMP_MINOR,
653 .name = "temperature",
654 .fops = &pcipcwd_temp_fops,
657 static struct notifier_block pcipcwd_notifier = {
658 .notifier_call = pcipcwd_notify_sys,
662 * Init & exit routines
665 static int __devinit pcipcwd_card_init(struct pci_dev *pdev,
666 const struct pci_device_id *ent)
668 int ret = -EIO;
670 cards_found++;
671 if (cards_found == 1)
672 printk(KERN_INFO PFX DRIVER_VERSION);
674 if (cards_found > 1) {
675 printk(KERN_ERR PFX "This driver only supports 1 device\n");
676 return -ENODEV;
679 if (pci_enable_device(pdev)) {
680 printk(KERN_ERR PFX "Not possible to enable PCI Device\n");
681 return -ENODEV;
684 if (pci_resource_start(pdev, 0) == 0x0000) {
685 printk(KERN_ERR PFX "No I/O-Address for card detected\n");
686 ret = -ENODEV;
687 goto err_out_disable_device;
690 pcipcwd_private.pdev = pdev;
691 pcipcwd_private.io_addr = pci_resource_start(pdev, 0);
693 if (pci_request_regions(pdev, WATCHDOG_NAME)) {
694 printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
695 (int) pcipcwd_private.io_addr);
696 ret = -EIO;
697 goto err_out_disable_device;
700 /* get the boot_status */
701 pcipcwd_get_status(&pcipcwd_private.boot_status);
703 /* clear the "card caused reboot" flag */
704 pcipcwd_clear_status();
706 /* disable card */
707 pcipcwd_stop();
709 /* Check whether or not the card supports the temperature device */
710 pcipcwd_check_temperature_support();
712 /* Show info about the card itself */
713 pcipcwd_show_card_info();
715 /* Check that the heartbeat value is within it's range ; if not reset to the default */
716 if (pcipcwd_set_heartbeat(heartbeat)) {
717 pcipcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
718 printk(KERN_INFO PFX "heartbeat value must be 0<heartbeat<65536, using %d\n",
719 WATCHDOG_HEARTBEAT);
722 ret = register_reboot_notifier(&pcipcwd_notifier);
723 if (ret != 0) {
724 printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
725 ret);
726 goto err_out_release_region;
729 if (pcipcwd_private.supports_temp) {
730 ret = misc_register(&pcipcwd_temp_miscdev);
731 if (ret != 0) {
732 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
733 TEMP_MINOR, ret);
734 goto err_out_unregister_reboot;
738 ret = misc_register(&pcipcwd_miscdev);
739 if (ret != 0) {
740 printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
741 WATCHDOG_MINOR, ret);
742 goto err_out_misc_deregister;
745 printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
746 heartbeat, nowayout);
748 return 0;
750 err_out_misc_deregister:
751 if (pcipcwd_private.supports_temp)
752 misc_deregister(&pcipcwd_temp_miscdev);
753 err_out_unregister_reboot:
754 unregister_reboot_notifier(&pcipcwd_notifier);
755 err_out_release_region:
756 pci_release_regions(pdev);
757 err_out_disable_device:
758 pci_disable_device(pdev);
759 return ret;
762 static void __devexit pcipcwd_card_exit(struct pci_dev *pdev)
764 /* Stop the timer before we leave */
765 if (!nowayout)
766 pcipcwd_stop();
768 /* Deregister */
769 misc_deregister(&pcipcwd_miscdev);
770 if (pcipcwd_private.supports_temp)
771 misc_deregister(&pcipcwd_temp_miscdev);
772 unregister_reboot_notifier(&pcipcwd_notifier);
773 pci_release_regions(pdev);
774 pci_disable_device(pdev);
775 cards_found--;
778 static struct pci_device_id pcipcwd_pci_tbl[] = {
779 { PCI_VENDOR_ID_QUICKLOGIC, PCI_DEVICE_ID_WATCHDOG_PCIPCWD,
780 PCI_ANY_ID, PCI_ANY_ID, },
781 { 0 }, /* End of list */
783 MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl);
785 static struct pci_driver pcipcwd_driver = {
786 .name = WATCHDOG_NAME,
787 .id_table = pcipcwd_pci_tbl,
788 .probe = pcipcwd_card_init,
789 .remove = __devexit_p(pcipcwd_card_exit),
792 static int __init pcipcwd_init_module(void)
794 spin_lock_init(&pcipcwd_private.io_lock);
796 return pci_register_driver(&pcipcwd_driver);
799 static void __exit pcipcwd_cleanup_module(void)
801 pci_unregister_driver(&pcipcwd_driver);
804 module_init(pcipcwd_init_module);
805 module_exit(pcipcwd_cleanup_module);
807 MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
808 MODULE_DESCRIPTION("Berkshire PCI-PC Watchdog driver");
809 MODULE_LICENSE("GPL");
810 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
811 MODULE_ALIAS_MISCDEV(TEMP_MINOR);