wdt_pci.c 19 KB

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