wdt_pci.c 18 KB

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