wdt_pci.c 18 KB

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