wdt_pci.c 19 KB

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