wdt_pci.c 18 KB

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