wdt_pci.c 18 KB

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