wdt_pci.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  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
  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. #ifdef CONFIG_WDT_501_PCI
  90. /* Support for the Fan Tachometer on the PCI-WDT501 */
  91. static int tachometer;
  92. module_param(tachometer, int, 0);
  93. MODULE_PARM_DESC(tachometer,
  94. "PCI-WDT501 Fan Tachometer support (0=disable, default=0)");
  95. #endif /* CONFIG_WDT_501_PCI */
  96. /*
  97. * Programming support
  98. */
  99. static void wdtpci_ctr_mode(int ctr, int mode)
  100. {
  101. ctr <<= 6;
  102. ctr |= 0x30;
  103. ctr |= (mode << 1);
  104. outb(ctr, WDT_CR);
  105. udelay(8);
  106. }
  107. static void wdtpci_ctr_load(int ctr, int val)
  108. {
  109. outb(val & 0xFF, WDT_COUNT0 + ctr);
  110. udelay(8);
  111. outb(val >> 8, WDT_COUNT0 + ctr);
  112. udelay(8);
  113. }
  114. /**
  115. * wdtpci_start:
  116. *
  117. * Start the watchdog driver.
  118. */
  119. static int wdtpci_start(void)
  120. {
  121. unsigned long flags;
  122. spin_lock_irqsave(&wdtpci_lock, flags);
  123. /*
  124. * "pet" the watchdog, as Access says.
  125. * This resets the clock outputs.
  126. */
  127. inb(WDT_DC); /* Disable watchdog */
  128. udelay(8);
  129. wdtpci_ctr_mode(2, 0); /* Program CTR2 for Mode 0:
  130. Pulse on Terminal Count */
  131. outb(0, WDT_DC); /* Enable watchdog */
  132. udelay(8);
  133. inb(WDT_DC); /* Disable watchdog */
  134. udelay(8);
  135. outb(0, WDT_CLOCK); /* 2.0833MHz clock */
  136. udelay(8);
  137. inb(WDT_BUZZER); /* disable */
  138. udelay(8);
  139. inb(WDT_OPTONOTRST); /* disable */
  140. udelay(8);
  141. inb(WDT_OPTORST); /* disable */
  142. udelay(8);
  143. inb(WDT_PROGOUT); /* disable */
  144. udelay(8);
  145. wdtpci_ctr_mode(0, 3); /* Program CTR0 for Mode 3:
  146. Square Wave Generator */
  147. wdtpci_ctr_mode(1, 2); /* Program CTR1 for Mode 2:
  148. Rate Generator */
  149. wdtpci_ctr_mode(2, 1); /* Program CTR2 for Mode 1:
  150. Retriggerable One-Shot */
  151. wdtpci_ctr_load(0, 20833); /* count at 100Hz */
  152. wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */
  153. /* DO NOT LOAD CTR2 on PCI card! -- JPN */
  154. outb(0, WDT_DC); /* Enable watchdog */
  155. udelay(8);
  156. spin_unlock_irqrestore(&wdtpci_lock, flags);
  157. return 0;
  158. }
  159. /**
  160. * wdtpci_stop:
  161. *
  162. * Stop the watchdog driver.
  163. */
  164. static int wdtpci_stop(void)
  165. {
  166. unsigned long flags;
  167. /* Turn the card off */
  168. spin_lock_irqsave(&wdtpci_lock, flags);
  169. inb(WDT_DC); /* Disable watchdog */
  170. udelay(8);
  171. wdtpci_ctr_load(2, 0); /* 0 length reset pulses now */
  172. spin_unlock_irqrestore(&wdtpci_lock, flags);
  173. return 0;
  174. }
  175. /**
  176. * wdtpci_ping:
  177. *
  178. * Reload counter one with the watchdog heartbeat. We don't bother
  179. * reloading the cascade counter.
  180. */
  181. static int wdtpci_ping(void)
  182. {
  183. unsigned long flags;
  184. spin_lock_irqsave(&wdtpci_lock, flags);
  185. /* Write a watchdog value */
  186. inb(WDT_DC); /* Disable watchdog */
  187. udelay(8);
  188. wdtpci_ctr_mode(1, 2); /* Re-Program CTR1 for Mode 2:
  189. Rate Generator */
  190. wdtpci_ctr_load(1, wd_heartbeat);/* Heartbeat */
  191. outb(0, WDT_DC); /* Enable watchdog */
  192. udelay(8);
  193. spin_unlock_irqrestore(&wdtpci_lock, flags);
  194. return 0;
  195. }
  196. /**
  197. * wdtpci_set_heartbeat:
  198. * @t: the new heartbeat value that needs to be set.
  199. *
  200. * Set a new heartbeat value for the watchdog device. If the heartbeat
  201. * value is incorrect we keep the old value and return -EINVAL.
  202. * If successful we return 0.
  203. */
  204. static int wdtpci_set_heartbeat(int t)
  205. {
  206. /* Arbitrary, can't find the card's limits */
  207. if (t < 1 || t > 65535)
  208. return -EINVAL;
  209. heartbeat = t;
  210. wd_heartbeat = t * 100;
  211. return 0;
  212. }
  213. /**
  214. * wdtpci_get_status:
  215. * @status: the new status.
  216. *
  217. * Extract the status information from a WDT watchdog device. There are
  218. * several board variants so we have to know which bits are valid. Some
  219. * bits default to one and some to zero in order to be maximally painful.
  220. *
  221. * we then map the bits onto the status ioctl flags.
  222. */
  223. static int wdtpci_get_status(int *status)
  224. {
  225. unsigned char new_status;
  226. unsigned long flags;
  227. spin_lock_irqsave(&wdtpci_lock, flags);
  228. new_status = inb(WDT_SR);
  229. spin_unlock_irqrestore(&wdtpci_lock, flags);
  230. *status = 0;
  231. if (new_status & WDC_SR_ISOI0)
  232. *status |= WDIOF_EXTERN1;
  233. if (new_status & WDC_SR_ISII1)
  234. *status |= WDIOF_EXTERN2;
  235. #ifdef CONFIG_WDT_501_PCI
  236. if (!(new_status & WDC_SR_TGOOD))
  237. *status |= WDIOF_OVERHEAT;
  238. if (!(new_status & WDC_SR_PSUOVER))
  239. *status |= WDIOF_POWEROVER;
  240. if (!(new_status & WDC_SR_PSUUNDR))
  241. *status |= WDIOF_POWERUNDER;
  242. if (tachometer) {
  243. if (!(new_status & WDC_SR_FANGOOD))
  244. *status |= WDIOF_FANFAULT;
  245. }
  246. #endif /* CONFIG_WDT_501_PCI */
  247. return 0;
  248. }
  249. #ifdef CONFIG_WDT_501_PCI
  250. /**
  251. * wdtpci_get_temperature:
  252. *
  253. * Reports the temperature in degrees Fahrenheit. The API is in
  254. * farenheit. It was designed by an imperial measurement luddite.
  255. */
  256. static int wdtpci_get_temperature(int *temperature)
  257. {
  258. unsigned short c;
  259. unsigned long flags;
  260. spin_lock_irqsave(&wdtpci_lock, flags);
  261. c = inb(WDT_RT);
  262. udelay(8);
  263. spin_unlock_irqrestore(&wdtpci_lock, flags);
  264. *temperature = (c * 11 / 15) + 7;
  265. return 0;
  266. }
  267. #endif /* CONFIG_WDT_501_PCI */
  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. #ifdef CONFIG_WDT_501_PCI
  289. if (!(status & WDC_SR_TGOOD)) {
  290. u8 alarm = inb(WDT_RT);
  291. printk(KERN_CRIT PFX "Overheat alarm.(%d)\n", alarm);
  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. #endif /* CONFIG_WDT_501_PCI */
  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. expect_close = 0;
  335. for (i = 0; i != count; i++) {
  336. char c;
  337. if (get_user(c, buf + i))
  338. return -EFAULT;
  339. if (c == 'V')
  340. expect_close = 42;
  341. }
  342. }
  343. wdtpci_ping();
  344. }
  345. return count;
  346. }
  347. /**
  348. * wdtpci_ioctl:
  349. * @file: file handle to the device
  350. * @cmd: watchdog command
  351. * @arg: argument pointer
  352. *
  353. * The watchdog API defines a common set of functions for all watchdogs
  354. * according to their available features. We only actually usefully support
  355. * querying capabilities and current status.
  356. */
  357. static long wdtpci_ioctl(struct file *file, unsigned int cmd,
  358. unsigned long arg)
  359. {
  360. int new_heartbeat;
  361. int status;
  362. void __user *argp = (void __user *)arg;
  363. int __user *p = argp;
  364. static struct watchdog_info ident = {
  365. .options = WDIOF_SETTIMEOUT|
  366. WDIOF_MAGICCLOSE|
  367. WDIOF_KEEPALIVEPING,
  368. .firmware_version = 1,
  369. .identity = "PCI-WDT500/501",
  370. };
  371. /* Add options according to the card we have */
  372. ident.options |= (WDIOF_EXTERN1|WDIOF_EXTERN2);
  373. #ifdef CONFIG_WDT_501_PCI
  374. ident.options |= (WDIOF_OVERHEAT|WDIOF_POWERUNDER|WDIOF_POWEROVER);
  375. if (tachometer)
  376. ident.options |= WDIOF_FANFAULT;
  377. #endif /* CONFIG_WDT_501_PCI */
  378. switch (cmd) {
  379. case WDIOC_GETSUPPORT:
  380. return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  381. case WDIOC_GETSTATUS:
  382. wdtpci_get_status(&status);
  383. return put_user(status, p);
  384. case WDIOC_GETBOOTSTATUS:
  385. return put_user(0, p);
  386. case WDIOC_KEEPALIVE:
  387. wdtpci_ping();
  388. return 0;
  389. case WDIOC_SETTIMEOUT:
  390. if (get_user(new_heartbeat, p))
  391. return -EFAULT;
  392. if (wdtpci_set_heartbeat(new_heartbeat))
  393. return -EINVAL;
  394. wdtpci_ping();
  395. /* Fall */
  396. case WDIOC_GETTIMEOUT:
  397. return put_user(heartbeat, p);
  398. default:
  399. return -ENOTTY;
  400. }
  401. }
  402. /**
  403. * wdtpci_open:
  404. * @inode: inode of device
  405. * @file: file handle to device
  406. *
  407. * The watchdog device has been opened. The watchdog device is single
  408. * open and on opening we load the counters. Counter zero is a 100Hz
  409. * cascade, into counter 1 which downcounts to reboot. When the counter
  410. * triggers counter 2 downcounts the length of the reset pulse which
  411. * set set to be as long as possible.
  412. */
  413. static int wdtpci_open(struct inode *inode, struct file *file)
  414. {
  415. if (test_and_set_bit(0, &open_lock))
  416. return -EBUSY;
  417. if (nowayout)
  418. __module_get(THIS_MODULE);
  419. /*
  420. * Activate
  421. */
  422. wdtpci_start();
  423. return nonseekable_open(inode, file);
  424. }
  425. /**
  426. * wdtpci_release:
  427. * @inode: inode to board
  428. * @file: file handle to board
  429. *
  430. * The watchdog has a configurable API. There is a religious dispute
  431. * between people who want their watchdog to be able to shut down and
  432. * those who want to be sure if the watchdog manager dies the machine
  433. * reboots. In the former case we disable the counters, in the latter
  434. * case you have to open it again very soon.
  435. */
  436. static int wdtpci_release(struct inode *inode, struct file *file)
  437. {
  438. if (expect_close == 42) {
  439. wdtpci_stop();
  440. } else {
  441. printk(KERN_CRIT PFX "Unexpected close, not stopping timer!");
  442. wdtpci_ping();
  443. }
  444. expect_close = 0;
  445. clear_bit(0, &open_lock);
  446. return 0;
  447. }
  448. #ifdef CONFIG_WDT_501_PCI
  449. /**
  450. * wdtpci_temp_read:
  451. * @file: file handle to the watchdog board
  452. * @buf: buffer to write 1 byte into
  453. * @count: length of buffer
  454. * @ptr: offset (no seek allowed)
  455. *
  456. * Read reports the temperature in degrees Fahrenheit. The API is in
  457. * fahrenheit. It was designed by an imperial measurement luddite.
  458. */
  459. static ssize_t wdtpci_temp_read(struct file *file, char __user *buf,
  460. size_t count, loff_t *ptr)
  461. {
  462. int temperature;
  463. if (wdtpci_get_temperature(&temperature))
  464. return -EFAULT;
  465. if (copy_to_user(buf, &temperature, 1))
  466. return -EFAULT;
  467. return 1;
  468. }
  469. /**
  470. * wdtpci_temp_open:
  471. * @inode: inode of device
  472. * @file: file handle to device
  473. *
  474. * The temperature device has been opened.
  475. */
  476. static int wdtpci_temp_open(struct inode *inode, struct file *file)
  477. {
  478. return nonseekable_open(inode, file);
  479. }
  480. /**
  481. * wdtpci_temp_release:
  482. * @inode: inode to board
  483. * @file: file handle to board
  484. *
  485. * The temperature device has been closed.
  486. */
  487. static int wdtpci_temp_release(struct inode *inode, struct file *file)
  488. {
  489. return 0;
  490. }
  491. #endif /* CONFIG_WDT_501_PCI */
  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. #ifdef CONFIG_WDT_501_PCI
  527. static const struct file_operations wdtpci_temp_fops = {
  528. .owner = THIS_MODULE,
  529. .llseek = no_llseek,
  530. .read = wdtpci_temp_read,
  531. .open = wdtpci_temp_open,
  532. .release = wdtpci_temp_release,
  533. };
  534. static struct miscdevice temp_miscdev = {
  535. .minor = TEMP_MINOR,
  536. .name = "temperature",
  537. .fops = &wdtpci_temp_fops,
  538. };
  539. #endif /* CONFIG_WDT_501_PCI */
  540. /*
  541. * The WDT card needs to learn about soft shutdowns in order to
  542. * turn the timebomb registers off.
  543. */
  544. static struct notifier_block wdtpci_notifier = {
  545. .notifier_call = wdtpci_notify_sys,
  546. };
  547. static int __devinit wdtpci_init_one(struct pci_dev *dev,
  548. const struct pci_device_id *ent)
  549. {
  550. int ret = -EIO;
  551. dev_count++;
  552. if (dev_count > 1) {
  553. printk(KERN_ERR PFX "This driver only supports one device\n");
  554. return -ENODEV;
  555. }
  556. if (pci_enable_device(dev)) {
  557. printk(KERN_ERR PFX "Not possible to enable PCI Device\n");
  558. return -ENODEV;
  559. }
  560. if (pci_resource_start(dev, 2) == 0x0000) {
  561. printk(KERN_ERR PFX "No I/O-Address for card detected\n");
  562. ret = -ENODEV;
  563. goto out_pci;
  564. }
  565. irq = dev->irq;
  566. io = pci_resource_start(dev, 2);
  567. if (request_region(io, 16, "wdt_pci") == NULL) {
  568. printk(KERN_ERR PFX "I/O address 0x%04x already in use\n", io);
  569. goto out_pci;
  570. }
  571. if (request_irq(irq, wdtpci_interrupt, IRQF_DISABLED | IRQF_SHARED,
  572. "wdt_pci", &wdtpci_miscdev)) {
  573. printk(KERN_ERR PFX "IRQ %d is not free\n", irq);
  574. goto out_reg;
  575. }
  576. printk(KERN_INFO
  577. "PCI-WDT500/501 (PCI-WDG-CSM) driver 0.10 at 0x%04x (Interrupt %d)\n",
  578. io, irq);
  579. /* Check that the heartbeat value is within its range;
  580. if not reset to the default */
  581. if (wdtpci_set_heartbeat(heartbeat)) {
  582. wdtpci_set_heartbeat(WD_TIMO);
  583. printk(KERN_INFO PFX
  584. "heartbeat value must be 0 < heartbeat < 65536, using %d\n",
  585. WD_TIMO);
  586. }
  587. ret = register_reboot_notifier(&wdtpci_notifier);
  588. if (ret) {
  589. printk(KERN_ERR PFX
  590. "cannot register reboot notifier (err=%d)\n", ret);
  591. goto out_irq;
  592. }
  593. #ifdef CONFIG_WDT_501_PCI
  594. ret = misc_register(&temp_miscdev);
  595. if (ret) {
  596. printk(KERN_ERR PFX
  597. "cannot register miscdev on minor=%d (err=%d)\n",
  598. TEMP_MINOR, ret);
  599. goto out_rbt;
  600. }
  601. #endif /* CONFIG_WDT_501_PCI */
  602. ret = misc_register(&wdtpci_miscdev);
  603. if (ret) {
  604. printk(KERN_ERR PFX
  605. "cannot register miscdev on minor=%d (err=%d)\n",
  606. WATCHDOG_MINOR, ret);
  607. goto out_misc;
  608. }
  609. printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
  610. heartbeat, nowayout);
  611. #ifdef CONFIG_WDT_501_PCI
  612. printk(KERN_INFO "wdt: Fan Tachometer is %s\n",
  613. (tachometer ? "Enabled" : "Disabled"));
  614. #endif /* CONFIG_WDT_501_PCI */
  615. ret = 0;
  616. out:
  617. return ret;
  618. out_misc:
  619. #ifdef CONFIG_WDT_501_PCI
  620. misc_deregister(&temp_miscdev);
  621. out_rbt:
  622. #endif /* CONFIG_WDT_501_PCI */
  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. #ifdef CONFIG_WDT_501_PCI
  638. misc_deregister(&temp_miscdev);
  639. #endif /* CONFIG_WDT_501_PCI */
  640. unregister_reboot_notifier(&wdtpci_notifier);
  641. free_irq(irq, &wdtpci_miscdev);
  642. release_region(io, 16);
  643. pci_disable_device(pdev);
  644. dev_count--;
  645. }
  646. static struct pci_device_id wdtpci_pci_tbl[] = {
  647. {
  648. .vendor = PCI_VENDOR_ID_ACCESSIO,
  649. .device = PCI_DEVICE_ID_WDG_CSM,
  650. .subvendor = PCI_ANY_ID,
  651. .subdevice = PCI_ANY_ID,
  652. },
  653. { 0, }, /* terminate list */
  654. };
  655. MODULE_DEVICE_TABLE(pci, wdtpci_pci_tbl);
  656. static struct pci_driver wdtpci_driver = {
  657. .name = "wdt_pci",
  658. .id_table = wdtpci_pci_tbl,
  659. .probe = wdtpci_init_one,
  660. .remove = __devexit_p(wdtpci_remove_one),
  661. };
  662. /**
  663. * wdtpci_cleanup:
  664. *
  665. * Unload the watchdog. You cannot do this with any file handles open.
  666. * If your watchdog is set to continue ticking on close and you unload
  667. * it, well it keeps ticking. We won't get the interrupt but the board
  668. * will not touch PC memory so all is fine. You just have to load a new
  669. * module in xx seconds or reboot.
  670. */
  671. static void __exit wdtpci_cleanup(void)
  672. {
  673. pci_unregister_driver(&wdtpci_driver);
  674. }
  675. /**
  676. * wdtpci_init:
  677. *
  678. * Set up the WDT watchdog board. All we have to do is grab the
  679. * resources we require and bitch if anyone beat us to them.
  680. * The open() function will actually kick the board off.
  681. */
  682. static int __init wdtpci_init(void)
  683. {
  684. return pci_register_driver(&wdtpci_driver);
  685. }
  686. module_init(wdtpci_init);
  687. module_exit(wdtpci_cleanup);
  688. MODULE_AUTHOR("JP Nollmann, Alan Cox");
  689. MODULE_DESCRIPTION("Driver for the ICS PCI-WDT500/501 watchdog cards");
  690. MODULE_LICENSE("GPL");
  691. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  692. MODULE_ALIAS_MISCDEV(TEMP_MINOR);