pcwd_pci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Berkshire PCI-PC Watchdog Card Driver
  3. *
  4. * (c) Copyright 2003 Wim Van Sebroeck <wim@iguana.be>.
  5. *
  6. * Based on source code of the following authors:
  7. * Ken Hollis <kenji@bitgate.com>,
  8. * Lindsay Harris <lindsay@bluegum.com>,
  9. * Alan Cox <alan@redhat.com>,
  10. * Matt Domsch <Matt_Domsch@dell.com>,
  11. * Rob Radez <rob@osinvestor.com>
  12. *
  13. * This program is free software; you can redistribute it and/or
  14. * modify it under the terms of the GNU General Public License
  15. * as published by the Free Software Foundation; either version
  16. * 2 of the License, or (at your option) any later version.
  17. *
  18. * Neither Wim Van Sebroeck nor Iguana vzw. admit liability nor
  19. * provide warranty for any of this software. This material is
  20. * provided "AS-IS" and at no charge.
  21. */
  22. /*
  23. * A bells and whistles driver is available from http://www.pcwd.de/
  24. * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
  25. */
  26. /*
  27. * Includes, defines, variables, module parameters, ...
  28. */
  29. #include <linux/config.h> /* For CONFIG_WATCHDOG_NOWAYOUT/... */
  30. #include <linux/module.h> /* For module specific items */
  31. #include <linux/moduleparam.h> /* For new moduleparam's */
  32. #include <linux/types.h> /* For standard types (like size_t) */
  33. #include <linux/errno.h> /* For the -ENODEV/... values */
  34. #include <linux/kernel.h> /* For printk/panic/... */
  35. #include <linux/delay.h> /* For mdelay function */
  36. #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
  37. #include <linux/watchdog.h> /* For the watchdog specific items */
  38. #include <linux/notifier.h> /* For notifier support */
  39. #include <linux/reboot.h> /* For reboot_notifier stuff */
  40. #include <linux/init.h> /* For __init/__exit/... */
  41. #include <linux/fs.h> /* For file operations */
  42. #include <linux/pci.h> /* For pci functions */
  43. #include <linux/ioport.h> /* For io-port access */
  44. #include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
  45. #include <asm/uaccess.h> /* For copy_to_user/put_user/... */
  46. #include <asm/io.h> /* For inb/outb/... */
  47. /* Module and version information */
  48. #define WATCHDOG_VERSION "1.02"
  49. #define WATCHDOG_DATE "03 Sep 2005"
  50. #define WATCHDOG_DRIVER_NAME "PCI-PC Watchdog"
  51. #define WATCHDOG_NAME "pcwd_pci"
  52. #define PFX WATCHDOG_NAME ": "
  53. #define DRIVER_VERSION WATCHDOG_DRIVER_NAME " driver, v" WATCHDOG_VERSION " (" WATCHDOG_DATE ")\n"
  54. /* Stuff for the PCI ID's */
  55. #ifndef PCI_VENDOR_ID_QUICKLOGIC
  56. #define PCI_VENDOR_ID_QUICKLOGIC 0x11e3
  57. #endif
  58. #ifndef PCI_DEVICE_ID_WATCHDOG_PCIPCWD
  59. #define PCI_DEVICE_ID_WATCHDOG_PCIPCWD 0x5030
  60. #endif
  61. /*
  62. * These are the defines that describe the control status bits for the
  63. * PCI-PC Watchdog card.
  64. */
  65. /* Port 1 : Control Status #1 */
  66. #define WD_PCI_WTRP 0x01 /* Watchdog Trip status */
  67. #define WD_PCI_HRBT 0x02 /* Watchdog Heartbeat */
  68. #define WD_PCI_TTRP 0x04 /* Temperature Trip status */
  69. #define WD_PCI_RL2A 0x08 /* Relay 2 Active */
  70. #define WD_PCI_RL1A 0x10 /* Relay 1 Active */
  71. #define WD_PCI_R2DS 0x40 /* Relay 2 Disable Temperature-trip/reset */
  72. #define WD_PCI_RLY2 0x80 /* Activate Relay 2 on the board */
  73. /* Port 2 : Control Status #2 */
  74. #define WD_PCI_WDIS 0x10 /* Watchdog Disable */
  75. #define WD_PCI_ENTP 0x20 /* Enable Temperature Trip Reset */
  76. #define WD_PCI_WRSP 0x40 /* Watchdog wrote response */
  77. #define WD_PCI_PCMD 0x80 /* PC has sent command */
  78. /* according to documentation max. time to process a command for the pci
  79. * watchdog card is 100 ms, so we give it 150 ms to do it's job */
  80. #define PCI_COMMAND_TIMEOUT 150
  81. /* Watchdog's internal commands */
  82. #define CMD_GET_STATUS 0x04
  83. #define CMD_GET_FIRMWARE_VERSION 0x08
  84. #define CMD_READ_WATCHDOG_TIMEOUT 0x18
  85. #define CMD_WRITE_WATCHDOG_TIMEOUT 0x19
  86. #define CMD_GET_CLEAR_RESET_COUNT 0x84
  87. /* We can only use 1 card due to the /dev/watchdog restriction */
  88. static int cards_found;
  89. /* internal variables */
  90. static int temp_panic;
  91. static unsigned long is_active;
  92. static char expect_release;
  93. static struct { /* this is private data for each PCI-PC watchdog card */
  94. int supports_temp; /* Wether or not the card has a temperature device */
  95. int boot_status; /* The card's boot status */
  96. unsigned long io_addr; /* The cards I/O address */
  97. spinlock_t io_lock; /* the lock for io operations */
  98. struct pci_dev *pdev; /* the PCI-device */
  99. } pcipcwd_private;
  100. /* module parameters */
  101. #define WATCHDOG_HEARTBEAT 2 /* 2 sec default heartbeat */
  102. static int heartbeat = WATCHDOG_HEARTBEAT;
  103. module_param(heartbeat, int, 0);
  104. MODULE_PARM_DESC(heartbeat, "Watchdog heartbeat in seconds. (0<heartbeat<65536, default=" __MODULE_STRING(WATCHDOG_HEARTBEAT) ")");
  105. static int nowayout = WATCHDOG_NOWAYOUT;
  106. module_param(nowayout, int, 0);
  107. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)");
  108. /*
  109. * Internal functions
  110. */
  111. static int send_command(int cmd, int *msb, int *lsb)
  112. {
  113. int got_response, count;
  114. spin_lock(&pcipcwd_private.io_lock);
  115. /* If a command requires data it should be written first.
  116. * Data for commands with 8 bits of data should be written to port 4.
  117. * Commands with 16 bits of data, should be written as LSB to port 4
  118. * and MSB to port 5.
  119. * After the required data has been written then write the command to
  120. * port 6. */
  121. outb_p(*lsb, pcipcwd_private.io_addr + 4);
  122. outb_p(*msb, pcipcwd_private.io_addr + 5);
  123. outb_p(cmd, pcipcwd_private.io_addr + 6);
  124. /* wait till the pci card processed the command, signaled by
  125. * the WRSP bit in port 2 and give it a max. timeout of
  126. * PCI_COMMAND_TIMEOUT to process */
  127. got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
  128. for (count = 0; (count < PCI_COMMAND_TIMEOUT) && (!got_response); count++) {
  129. mdelay(1);
  130. got_response = inb_p(pcipcwd_private.io_addr + 2) & WD_PCI_WRSP;
  131. }
  132. if (got_response) {
  133. /* read back response */
  134. *lsb = inb_p(pcipcwd_private.io_addr + 4);
  135. *msb = inb_p(pcipcwd_private.io_addr + 5);
  136. /* clear WRSP bit */
  137. inb_p(pcipcwd_private.io_addr + 6);
  138. }
  139. spin_unlock(&pcipcwd_private.io_lock);
  140. return got_response;
  141. }
  142. static inline void pcipcwd_check_temperature_support(void)
  143. {
  144. if (inb_p(pcipcwd_private.io_addr) != 0xF0)
  145. pcipcwd_private.supports_temp = 1;
  146. }
  147. static int pcipcwd_get_option_switches(void)
  148. {
  149. int option_switches;
  150. option_switches = inb_p(pcipcwd_private.io_addr + 3);
  151. return option_switches;
  152. }
  153. static void pcipcwd_show_card_info(void)
  154. {
  155. int got_fw_rev, fw_rev_major, fw_rev_minor;
  156. char fw_ver_str[20]; /* The cards firmware version */
  157. int option_switches;
  158. got_fw_rev = send_command(CMD_GET_FIRMWARE_VERSION, &fw_rev_major, &fw_rev_minor);
  159. if (got_fw_rev) {
  160. sprintf(fw_ver_str, "%u.%02u", fw_rev_major, fw_rev_minor);
  161. } else {
  162. sprintf(fw_ver_str, "<card no answer>");
  163. }
  164. /* Get switch settings */
  165. option_switches = pcipcwd_get_option_switches();
  166. printk(KERN_INFO PFX "Found card at port 0x%04x (Firmware: %s) %s temp option\n",
  167. (int) pcipcwd_private.io_addr, fw_ver_str,
  168. (pcipcwd_private.supports_temp ? "with" : "without"));
  169. printk(KERN_INFO PFX "Option switches (0x%02x): Temperature Reset Enable=%s, Power On Delay=%s\n",
  170. option_switches,
  171. ((option_switches & 0x10) ? "ON" : "OFF"),
  172. ((option_switches & 0x08) ? "ON" : "OFF"));
  173. if (pcipcwd_private.boot_status & WDIOF_CARDRESET)
  174. printk(KERN_INFO PFX "Previous reset was caused by the Watchdog card\n");
  175. if (pcipcwd_private.boot_status & WDIOF_OVERHEAT)
  176. printk(KERN_INFO PFX "Card sensed a CPU Overheat\n");
  177. if (pcipcwd_private.boot_status == 0)
  178. printk(KERN_INFO PFX "No previous trip detected - Cold boot or reset\n");
  179. }
  180. static int pcipcwd_start(void)
  181. {
  182. int stat_reg;
  183. spin_lock(&pcipcwd_private.io_lock);
  184. outb_p(0x00, pcipcwd_private.io_addr + 3);
  185. udelay(1000);
  186. stat_reg = inb_p(pcipcwd_private.io_addr + 2);
  187. spin_unlock(&pcipcwd_private.io_lock);
  188. if (stat_reg & WD_PCI_WDIS) {
  189. printk(KERN_ERR PFX "Card timer not enabled\n");
  190. return -1;
  191. }
  192. return 0;
  193. }
  194. static int pcipcwd_stop(void)
  195. {
  196. int stat_reg;
  197. spin_lock(&pcipcwd_private.io_lock);
  198. outb_p(0xA5, pcipcwd_private.io_addr + 3);
  199. udelay(1000);
  200. outb_p(0xA5, pcipcwd_private.io_addr + 3);
  201. udelay(1000);
  202. stat_reg = inb_p(pcipcwd_private.io_addr + 2);
  203. spin_unlock(&pcipcwd_private.io_lock);
  204. if (!(stat_reg & WD_PCI_WDIS)) {
  205. printk(KERN_ERR PFX "Card did not acknowledge disable attempt\n");
  206. return -1;
  207. }
  208. return 0;
  209. }
  210. static int pcipcwd_keepalive(void)
  211. {
  212. /* Re-trigger watchdog by writing to port 0 */
  213. outb_p(0x42, pcipcwd_private.io_addr); /* send out any data */
  214. return 0;
  215. }
  216. static int pcipcwd_set_heartbeat(int t)
  217. {
  218. int t_msb = t / 256;
  219. int t_lsb = t % 256;
  220. if ((t < 0x0001) || (t > 0xFFFF))
  221. return -EINVAL;
  222. /* Write new heartbeat to watchdog */
  223. send_command(CMD_WRITE_WATCHDOG_TIMEOUT, &t_msb, &t_lsb);
  224. heartbeat = t;
  225. return 0;
  226. }
  227. static int pcipcwd_get_status(int *status)
  228. {
  229. int control_status;
  230. *status=0;
  231. control_status = inb_p(pcipcwd_private.io_addr + 1);
  232. if (control_status & WD_PCI_WTRP)
  233. *status |= WDIOF_CARDRESET;
  234. if (control_status & WD_PCI_TTRP) {
  235. *status |= WDIOF_OVERHEAT;
  236. if (temp_panic)
  237. panic(PFX "Temperature overheat trip!\n");
  238. }
  239. return 0;
  240. }
  241. static int pcipcwd_clear_status(void)
  242. {
  243. int control_status;
  244. int msb;
  245. int reset_counter;
  246. control_status = inb_p(pcipcwd_private.io_addr + 1);
  247. /* clear trip status & LED and keep mode of relay 2 */
  248. outb_p((control_status & WD_PCI_R2DS) | WD_PCI_WTRP, pcipcwd_private.io_addr + 1);
  249. /* clear reset counter */
  250. msb=0;
  251. reset_counter=0xff;
  252. send_command(CMD_GET_CLEAR_RESET_COUNT, &msb, &reset_counter);
  253. return 0;
  254. }
  255. static int pcipcwd_get_temperature(int *temperature)
  256. {
  257. *temperature = 0;
  258. if (!pcipcwd_private.supports_temp)
  259. return -ENODEV;
  260. *temperature = inb_p(pcipcwd_private.io_addr);
  261. /*
  262. * Convert celsius to fahrenheit, since this was
  263. * the decided 'standard' for this return value.
  264. */
  265. *temperature = (*temperature * 9 / 5) + 32;
  266. return 0;
  267. }
  268. /*
  269. * /dev/watchdog handling
  270. */
  271. static ssize_t pcipcwd_write(struct file *file, const char __user *data,
  272. size_t len, loff_t *ppos)
  273. {
  274. /* See if we got the magic character 'V' and reload the timer */
  275. if (len) {
  276. if (!nowayout) {
  277. size_t i;
  278. /* note: just in case someone wrote the magic character
  279. * five months ago... */
  280. expect_release = 0;
  281. /* scan to see whether or not we got the magic character */
  282. for (i = 0; i != len; i++) {
  283. char c;
  284. if(get_user(c, data+i))
  285. return -EFAULT;
  286. if (c == 'V')
  287. expect_release = 42;
  288. }
  289. }
  290. /* someone wrote to us, we should reload the timer */
  291. pcipcwd_keepalive();
  292. }
  293. return len;
  294. }
  295. static int pcipcwd_ioctl(struct inode *inode, struct file *file,
  296. unsigned int cmd, unsigned long arg)
  297. {
  298. void __user *argp = (void __user *)arg;
  299. int __user *p = argp;
  300. static struct watchdog_info ident = {
  301. .options = WDIOF_OVERHEAT |
  302. WDIOF_CARDRESET |
  303. WDIOF_KEEPALIVEPING |
  304. WDIOF_SETTIMEOUT |
  305. WDIOF_MAGICCLOSE,
  306. .firmware_version = 1,
  307. .identity = WATCHDOG_DRIVER_NAME,
  308. };
  309. switch (cmd) {
  310. case WDIOC_GETSUPPORT:
  311. return copy_to_user(argp, &ident,
  312. sizeof (ident)) ? -EFAULT : 0;
  313. case WDIOC_GETSTATUS:
  314. {
  315. int status;
  316. pcipcwd_get_status(&status);
  317. return put_user(status, p);
  318. }
  319. case WDIOC_GETBOOTSTATUS:
  320. return put_user(pcipcwd_private.boot_status, p);
  321. case WDIOC_GETTEMP:
  322. {
  323. int temperature;
  324. if (pcipcwd_get_temperature(&temperature))
  325. return -EFAULT;
  326. return put_user(temperature, p);
  327. }
  328. case WDIOC_KEEPALIVE:
  329. pcipcwd_keepalive();
  330. return 0;
  331. case WDIOC_SETOPTIONS:
  332. {
  333. int new_options, retval = -EINVAL;
  334. if (get_user (new_options, p))
  335. return -EFAULT;
  336. if (new_options & WDIOS_DISABLECARD) {
  337. if (pcipcwd_stop())
  338. return -EIO;
  339. retval = 0;
  340. }
  341. if (new_options & WDIOS_ENABLECARD) {
  342. if (pcipcwd_start())
  343. return -EIO;
  344. retval = 0;
  345. }
  346. if (new_options & WDIOS_TEMPPANIC) {
  347. temp_panic = 1;
  348. retval = 0;
  349. }
  350. return retval;
  351. }
  352. case WDIOC_SETTIMEOUT:
  353. {
  354. int new_heartbeat;
  355. if (get_user(new_heartbeat, p))
  356. return -EFAULT;
  357. if (pcipcwd_set_heartbeat(new_heartbeat))
  358. return -EINVAL;
  359. pcipcwd_keepalive();
  360. /* Fall */
  361. }
  362. case WDIOC_GETTIMEOUT:
  363. return put_user(heartbeat, p);
  364. default:
  365. return -ENOIOCTLCMD;
  366. }
  367. }
  368. static int pcipcwd_open(struct inode *inode, struct file *file)
  369. {
  370. /* /dev/watchdog can only be opened once */
  371. if (test_and_set_bit(0, &is_active)) {
  372. return -EBUSY;
  373. }
  374. /* Activate */
  375. pcipcwd_start();
  376. pcipcwd_keepalive();
  377. return nonseekable_open(inode, file);
  378. }
  379. static int pcipcwd_release(struct inode *inode, struct file *file)
  380. {
  381. /*
  382. * Shut off the timer.
  383. */
  384. if (expect_release == 42) {
  385. pcipcwd_stop();
  386. } else {
  387. printk(KERN_CRIT PFX "Unexpected close, not stopping watchdog!\n");
  388. pcipcwd_keepalive();
  389. }
  390. expect_release = 0;
  391. clear_bit(0, &is_active);
  392. return 0;
  393. }
  394. /*
  395. * /dev/temperature handling
  396. */
  397. static ssize_t pcipcwd_temp_read(struct file *file, char __user *data,
  398. size_t len, loff_t *ppos)
  399. {
  400. int temperature;
  401. if (pcipcwd_get_temperature(&temperature))
  402. return -EFAULT;
  403. if (copy_to_user (data, &temperature, 1))
  404. return -EFAULT;
  405. return 1;
  406. }
  407. static int pcipcwd_temp_open(struct inode *inode, struct file *file)
  408. {
  409. if (!pcipcwd_private.supports_temp)
  410. return -ENODEV;
  411. return nonseekable_open(inode, file);
  412. }
  413. static int pcipcwd_temp_release(struct inode *inode, struct file *file)
  414. {
  415. return 0;
  416. }
  417. /*
  418. * Notify system
  419. */
  420. static int pcipcwd_notify_sys(struct notifier_block *this, unsigned long code, void *unused)
  421. {
  422. if (code==SYS_DOWN || code==SYS_HALT) {
  423. /* Turn the WDT off */
  424. pcipcwd_stop();
  425. }
  426. return NOTIFY_DONE;
  427. }
  428. /*
  429. * Kernel Interfaces
  430. */
  431. static struct file_operations pcipcwd_fops = {
  432. .owner = THIS_MODULE,
  433. .llseek = no_llseek,
  434. .write = pcipcwd_write,
  435. .ioctl = pcipcwd_ioctl,
  436. .open = pcipcwd_open,
  437. .release = pcipcwd_release,
  438. };
  439. static struct miscdevice pcipcwd_miscdev = {
  440. .minor = WATCHDOG_MINOR,
  441. .name = "watchdog",
  442. .fops = &pcipcwd_fops,
  443. };
  444. static struct file_operations pcipcwd_temp_fops = {
  445. .owner = THIS_MODULE,
  446. .llseek = no_llseek,
  447. .read = pcipcwd_temp_read,
  448. .open = pcipcwd_temp_open,
  449. .release = pcipcwd_temp_release,
  450. };
  451. static struct miscdevice pcipcwd_temp_miscdev = {
  452. .minor = TEMP_MINOR,
  453. .name = "temperature",
  454. .fops = &pcipcwd_temp_fops,
  455. };
  456. static struct notifier_block pcipcwd_notifier = {
  457. .notifier_call = pcipcwd_notify_sys,
  458. };
  459. /*
  460. * Init & exit routines
  461. */
  462. static int __devinit pcipcwd_card_init(struct pci_dev *pdev,
  463. const struct pci_device_id *ent)
  464. {
  465. int ret = -EIO;
  466. cards_found++;
  467. if (cards_found == 1)
  468. printk(KERN_INFO PFX DRIVER_VERSION);
  469. if (cards_found > 1) {
  470. printk(KERN_ERR PFX "This driver only supports 1 device\n");
  471. return -ENODEV;
  472. }
  473. if (pci_enable_device(pdev)) {
  474. printk(KERN_ERR PFX "Not possible to enable PCI Device\n");
  475. return -ENODEV;
  476. }
  477. if (pci_resource_start(pdev, 0) == 0x0000) {
  478. printk(KERN_ERR PFX "No I/O-Address for card detected\n");
  479. ret = -ENODEV;
  480. goto err_out_disable_device;
  481. }
  482. pcipcwd_private.pdev = pdev;
  483. pcipcwd_private.io_addr = pci_resource_start(pdev, 0);
  484. if (pci_request_regions(pdev, WATCHDOG_NAME)) {
  485. printk(KERN_ERR PFX "I/O address 0x%04x already in use\n",
  486. (int) pcipcwd_private.io_addr);
  487. ret = -EIO;
  488. goto err_out_disable_device;
  489. }
  490. /* get the boot_status */
  491. pcipcwd_get_status(&pcipcwd_private.boot_status);
  492. /* clear the "card caused reboot" flag */
  493. pcipcwd_clear_status();
  494. /* disable card */
  495. pcipcwd_stop();
  496. /* Check whether or not the card supports the temperature device */
  497. pcipcwd_check_temperature_support();
  498. /* Show info about the card itself */
  499. pcipcwd_show_card_info();
  500. /* Check that the heartbeat value is within it's range ; if not reset to the default */
  501. if (pcipcwd_set_heartbeat(heartbeat)) {
  502. pcipcwd_set_heartbeat(WATCHDOG_HEARTBEAT);
  503. printk(KERN_INFO PFX "heartbeat value must be 0<heartbeat<65536, using %d\n",
  504. WATCHDOG_HEARTBEAT);
  505. }
  506. ret = register_reboot_notifier(&pcipcwd_notifier);
  507. if (ret != 0) {
  508. printk(KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
  509. ret);
  510. goto err_out_release_region;
  511. }
  512. if (pcipcwd_private.supports_temp) {
  513. ret = misc_register(&pcipcwd_temp_miscdev);
  514. if (ret != 0) {
  515. printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
  516. TEMP_MINOR, ret);
  517. goto err_out_unregister_reboot;
  518. }
  519. }
  520. ret = misc_register(&pcipcwd_miscdev);
  521. if (ret != 0) {
  522. printk(KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
  523. WATCHDOG_MINOR, ret);
  524. goto err_out_misc_deregister;
  525. }
  526. printk(KERN_INFO PFX "initialized. heartbeat=%d sec (nowayout=%d)\n",
  527. heartbeat, nowayout);
  528. return 0;
  529. err_out_misc_deregister:
  530. if (pcipcwd_private.supports_temp)
  531. misc_deregister(&pcipcwd_temp_miscdev);
  532. err_out_unregister_reboot:
  533. unregister_reboot_notifier(&pcipcwd_notifier);
  534. err_out_release_region:
  535. pci_release_regions(pdev);
  536. err_out_disable_device:
  537. pci_disable_device(pdev);
  538. return ret;
  539. }
  540. static void __devexit pcipcwd_card_exit(struct pci_dev *pdev)
  541. {
  542. /* Stop the timer before we leave */
  543. if (!nowayout)
  544. pcipcwd_stop();
  545. /* Deregister */
  546. misc_deregister(&pcipcwd_miscdev);
  547. if (pcipcwd_private.supports_temp)
  548. misc_deregister(&pcipcwd_temp_miscdev);
  549. unregister_reboot_notifier(&pcipcwd_notifier);
  550. pci_release_regions(pdev);
  551. pci_disable_device(pdev);
  552. cards_found--;
  553. }
  554. static struct pci_device_id pcipcwd_pci_tbl[] = {
  555. { PCI_VENDOR_ID_QUICKLOGIC, PCI_DEVICE_ID_WATCHDOG_PCIPCWD,
  556. PCI_ANY_ID, PCI_ANY_ID, },
  557. { 0 }, /* End of list */
  558. };
  559. MODULE_DEVICE_TABLE(pci, pcipcwd_pci_tbl);
  560. static struct pci_driver pcipcwd_driver = {
  561. .name = WATCHDOG_NAME,
  562. .id_table = pcipcwd_pci_tbl,
  563. .probe = pcipcwd_card_init,
  564. .remove = __devexit_p(pcipcwd_card_exit),
  565. };
  566. static int __init pcipcwd_init_module(void)
  567. {
  568. spin_lock_init(&pcipcwd_private.io_lock);
  569. return pci_register_driver(&pcipcwd_driver);
  570. }
  571. static void __exit pcipcwd_cleanup_module(void)
  572. {
  573. pci_unregister_driver(&pcipcwd_driver);
  574. }
  575. module_init(pcipcwd_init_module);
  576. module_exit(pcipcwd_cleanup_module);
  577. MODULE_AUTHOR("Wim Van Sebroeck <wim@iguana.be>");
  578. MODULE_DESCRIPTION("Berkshire PCI-PC Watchdog driver");
  579. MODULE_LICENSE("GPL");
  580. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  581. MODULE_ALIAS_MISCDEV(TEMP_MINOR);