wdt_pci.c 18 KB

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