wdt_pci.c 18 KB

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