PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/drivers/watchdog/it87_wdt.c

https://github.com/mstsirkin/linux
C | 781 lines | 555 code | 102 blank | 124 comment | 75 complexity | ab8b9b2cde479ff8dec351e47e45786d MD5 | raw file
  1. /*
  2. * Watchdog Timer Driver
  3. * for ITE IT87xx Environment Control - Low Pin Count Input / Output
  4. *
  5. * (c) Copyright 2007 Oliver Schuster <olivers137@aol.com>
  6. *
  7. * Based on softdog.c by Alan Cox,
  8. * 83977f_wdt.c by Jose Goncalves,
  9. * it87.c by Chris Gauthron, Jean Delvare
  10. *
  11. * Data-sheets: Publicly available at the ITE website
  12. * http://www.ite.com.tw/
  13. *
  14. * Support of the watchdog timers, which are available on
  15. * IT8702, IT8712, IT8716, IT8718, IT8720, IT8721 and IT8726.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * as published by the Free Software Foundation; either version
  20. * 2 of the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30. */
  31. #include <linux/module.h>
  32. #include <linux/moduleparam.h>
  33. #include <linux/types.h>
  34. #include <linux/kernel.h>
  35. #include <linux/fs.h>
  36. #include <linux/miscdevice.h>
  37. #include <linux/init.h>
  38. #include <linux/ioport.h>
  39. #include <linux/watchdog.h>
  40. #include <linux/notifier.h>
  41. #include <linux/reboot.h>
  42. #include <linux/uaccess.h>
  43. #include <linux/io.h>
  44. #include <asm/system.h>
  45. #define WATCHDOG_VERSION "1.14"
  46. #define WATCHDOG_NAME "IT87 WDT"
  47. #define PFX WATCHDOG_NAME ": "
  48. #define DRIVER_VERSION WATCHDOG_NAME " driver, v" WATCHDOG_VERSION "\n"
  49. #define WD_MAGIC 'V'
  50. /* Defaults for Module Parameter */
  51. #define DEFAULT_NOGAMEPORT 0
  52. #define DEFAULT_EXCLUSIVE 1
  53. #define DEFAULT_TIMEOUT 60
  54. #define DEFAULT_TESTMODE 0
  55. #define DEFAULT_NOWAYOUT WATCHDOG_NOWAYOUT
  56. /* IO Ports */
  57. #define REG 0x2e
  58. #define VAL 0x2f
  59. /* Logical device Numbers LDN */
  60. #define GPIO 0x07
  61. #define GAMEPORT 0x09
  62. #define CIR 0x0a
  63. /* Configuration Registers and Functions */
  64. #define LDNREG 0x07
  65. #define CHIPID 0x20
  66. #define CHIPREV 0x22
  67. #define ACTREG 0x30
  68. #define BASEREG 0x60
  69. /* Chip Id numbers */
  70. #define NO_DEV_ID 0xffff
  71. #define IT8702_ID 0x8702
  72. #define IT8705_ID 0x8705
  73. #define IT8712_ID 0x8712
  74. #define IT8716_ID 0x8716
  75. #define IT8718_ID 0x8718
  76. #define IT8720_ID 0x8720
  77. #define IT8721_ID 0x8721
  78. #define IT8726_ID 0x8726 /* the data sheet suggest wrongly 0x8716 */
  79. /* GPIO Configuration Registers LDN=0x07 */
  80. #define WDTCTRL 0x71
  81. #define WDTCFG 0x72
  82. #define WDTVALLSB 0x73
  83. #define WDTVALMSB 0x74
  84. /* GPIO Bits WDTCTRL */
  85. #define WDT_CIRINT 0x80
  86. #define WDT_MOUSEINT 0x40
  87. #define WDT_KYBINT 0x20
  88. #define WDT_GAMEPORT 0x10 /* not in it8718, it8720, it8721 */
  89. #define WDT_FORCE 0x02
  90. #define WDT_ZERO 0x01
  91. /* GPIO Bits WDTCFG */
  92. #define WDT_TOV1 0x80
  93. #define WDT_KRST 0x40
  94. #define WDT_TOVE 0x20
  95. #define WDT_PWROK 0x10 /* not in it8721 */
  96. #define WDT_INT_MASK 0x0f
  97. /* CIR Configuration Register LDN=0x0a */
  98. #define CIR_ILS 0x70
  99. /* The default Base address is not always available, we use this */
  100. #define CIR_BASE 0x0208
  101. /* CIR Controller */
  102. #define CIR_DR(b) (b)
  103. #define CIR_IER(b) (b + 1)
  104. #define CIR_RCR(b) (b + 2)
  105. #define CIR_TCR1(b) (b + 3)
  106. #define CIR_TCR2(b) (b + 4)
  107. #define CIR_TSR(b) (b + 5)
  108. #define CIR_RSR(b) (b + 6)
  109. #define CIR_BDLR(b) (b + 5)
  110. #define CIR_BDHR(b) (b + 6)
  111. #define CIR_IIR(b) (b + 7)
  112. /* Default Base address of Game port */
  113. #define GP_BASE_DEFAULT 0x0201
  114. /* wdt_status */
  115. #define WDTS_TIMER_RUN 0
  116. #define WDTS_DEV_OPEN 1
  117. #define WDTS_KEEPALIVE 2
  118. #define WDTS_LOCKED 3
  119. #define WDTS_USE_GP 4
  120. #define WDTS_EXPECTED 5
  121. static unsigned int base, gpact, ciract, max_units, chip_type;
  122. static unsigned long wdt_status;
  123. static int nogameport = DEFAULT_NOGAMEPORT;
  124. static int exclusive = DEFAULT_EXCLUSIVE;
  125. static int timeout = DEFAULT_TIMEOUT;
  126. static int testmode = DEFAULT_TESTMODE;
  127. static int nowayout = DEFAULT_NOWAYOUT;
  128. module_param(nogameport, int, 0);
  129. MODULE_PARM_DESC(nogameport, "Forbid the activation of game port, default="
  130. __MODULE_STRING(DEFAULT_NOGAMEPORT));
  131. module_param(exclusive, int, 0);
  132. MODULE_PARM_DESC(exclusive, "Watchdog exclusive device open, default="
  133. __MODULE_STRING(DEFAULT_EXCLUSIVE));
  134. module_param(timeout, int, 0);
  135. MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds, default="
  136. __MODULE_STRING(DEFAULT_TIMEOUT));
  137. module_param(testmode, int, 0);
  138. MODULE_PARM_DESC(testmode, "Watchdog test mode (1 = no reboot), default="
  139. __MODULE_STRING(DEFAULT_TESTMODE));
  140. module_param(nowayout, int, 0);
  141. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started, default="
  142. __MODULE_STRING(WATCHDOG_NOWAYOUT));
  143. /* Superio Chip */
  144. static inline int superio_enter(void)
  145. {
  146. /*
  147. * Try to reserve REG and REG + 1 for exclusive access.
  148. */
  149. if (!request_muxed_region(REG, 2, WATCHDOG_NAME))
  150. return -EBUSY;
  151. outb(0x87, REG);
  152. outb(0x01, REG);
  153. outb(0x55, REG);
  154. outb(0x55, REG);
  155. return 0;
  156. }
  157. static inline void superio_exit(void)
  158. {
  159. outb(0x02, REG);
  160. outb(0x02, VAL);
  161. release_region(REG, 2);
  162. }
  163. static inline void superio_select(int ldn)
  164. {
  165. outb(LDNREG, REG);
  166. outb(ldn, VAL);
  167. }
  168. static inline int superio_inb(int reg)
  169. {
  170. outb(reg, REG);
  171. return inb(VAL);
  172. }
  173. static inline void superio_outb(int val, int reg)
  174. {
  175. outb(reg, REG);
  176. outb(val, VAL);
  177. }
  178. static inline int superio_inw(int reg)
  179. {
  180. int val;
  181. outb(reg++, REG);
  182. val = inb(VAL) << 8;
  183. outb(reg, REG);
  184. val |= inb(VAL);
  185. return val;
  186. }
  187. static inline void superio_outw(int val, int reg)
  188. {
  189. outb(reg++, REG);
  190. outb(val >> 8, VAL);
  191. outb(reg, REG);
  192. outb(val, VAL);
  193. }
  194. /* Internal function, should be called after superio_select(GPIO) */
  195. static void wdt_update_timeout(void)
  196. {
  197. unsigned char cfg = WDT_KRST;
  198. int tm = timeout;
  199. if (testmode)
  200. cfg = 0;
  201. if (tm <= max_units)
  202. cfg |= WDT_TOV1;
  203. else
  204. tm /= 60;
  205. if (chip_type != IT8721_ID)
  206. cfg |= WDT_PWROK;
  207. superio_outb(cfg, WDTCFG);
  208. superio_outb(tm, WDTVALLSB);
  209. if (max_units > 255)
  210. superio_outb(tm>>8, WDTVALMSB);
  211. }
  212. static int wdt_round_time(int t)
  213. {
  214. t += 59;
  215. t -= t % 60;
  216. return t;
  217. }
  218. /* watchdog timer handling */
  219. static void wdt_keepalive(void)
  220. {
  221. if (test_bit(WDTS_USE_GP, &wdt_status))
  222. inb(base);
  223. else
  224. /* The timer reloads with around 5 msec delay */
  225. outb(0x55, CIR_DR(base));
  226. set_bit(WDTS_KEEPALIVE, &wdt_status);
  227. }
  228. static int wdt_start(void)
  229. {
  230. int ret = superio_enter();
  231. if (ret)
  232. return ret;
  233. superio_select(GPIO);
  234. if (test_bit(WDTS_USE_GP, &wdt_status))
  235. superio_outb(WDT_GAMEPORT, WDTCTRL);
  236. else
  237. superio_outb(WDT_CIRINT, WDTCTRL);
  238. wdt_update_timeout();
  239. superio_exit();
  240. return 0;
  241. }
  242. static int wdt_stop(void)
  243. {
  244. int ret = superio_enter();
  245. if (ret)
  246. return ret;
  247. superio_select(GPIO);
  248. superio_outb(0x00, WDTCTRL);
  249. superio_outb(WDT_TOV1, WDTCFG);
  250. superio_outb(0x00, WDTVALLSB);
  251. if (max_units > 255)
  252. superio_outb(0x00, WDTVALMSB);
  253. superio_exit();
  254. return 0;
  255. }
  256. /**
  257. * wdt_set_timeout - set a new timeout value with watchdog ioctl
  258. * @t: timeout value in seconds
  259. *
  260. * The hardware device has a 8 or 16 bit watchdog timer (depends on
  261. * chip version) that can be configured to count seconds or minutes.
  262. *
  263. * Used within WDIOC_SETTIMEOUT watchdog device ioctl.
  264. */
  265. static int wdt_set_timeout(int t)
  266. {
  267. if (t < 1 || t > max_units * 60)
  268. return -EINVAL;
  269. if (t > max_units)
  270. timeout = wdt_round_time(t);
  271. else
  272. timeout = t;
  273. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  274. int ret = superio_enter();
  275. if (ret)
  276. return ret;
  277. superio_select(GPIO);
  278. wdt_update_timeout();
  279. superio_exit();
  280. }
  281. return 0;
  282. }
  283. /**
  284. * wdt_get_status - determines the status supported by watchdog ioctl
  285. * @status: status returned to user space
  286. *
  287. * The status bit of the device does not allow to distinguish
  288. * between a regular system reset and a watchdog forced reset.
  289. * But, in test mode it is useful, so it is supported through
  290. * WDIOC_GETSTATUS watchdog ioctl. Additionally the driver
  291. * reports the keepalive signal and the acception of the magic.
  292. *
  293. * Used within WDIOC_GETSTATUS watchdog device ioctl.
  294. */
  295. static int wdt_get_status(int *status)
  296. {
  297. *status = 0;
  298. if (testmode) {
  299. int ret = superio_enter();
  300. if (ret)
  301. return ret;
  302. superio_select(GPIO);
  303. if (superio_inb(WDTCTRL) & WDT_ZERO) {
  304. superio_outb(0x00, WDTCTRL);
  305. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  306. *status |= WDIOF_CARDRESET;
  307. }
  308. superio_exit();
  309. }
  310. if (test_and_clear_bit(WDTS_KEEPALIVE, &wdt_status))
  311. *status |= WDIOF_KEEPALIVEPING;
  312. if (test_bit(WDTS_EXPECTED, &wdt_status))
  313. *status |= WDIOF_MAGICCLOSE;
  314. return 0;
  315. }
  316. /* /dev/watchdog handling */
  317. /**
  318. * wdt_open - watchdog file_operations .open
  319. * @inode: inode of the device
  320. * @file: file handle to the device
  321. *
  322. * The watchdog timer starts by opening the device.
  323. *
  324. * Used within the file operation of the watchdog device.
  325. */
  326. static int wdt_open(struct inode *inode, struct file *file)
  327. {
  328. if (exclusive && test_and_set_bit(WDTS_DEV_OPEN, &wdt_status))
  329. return -EBUSY;
  330. if (!test_and_set_bit(WDTS_TIMER_RUN, &wdt_status)) {
  331. int ret;
  332. if (nowayout && !test_and_set_bit(WDTS_LOCKED, &wdt_status))
  333. __module_get(THIS_MODULE);
  334. ret = wdt_start();
  335. if (ret) {
  336. clear_bit(WDTS_LOCKED, &wdt_status);
  337. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  338. clear_bit(WDTS_DEV_OPEN, &wdt_status);
  339. return ret;
  340. }
  341. }
  342. return nonseekable_open(inode, file);
  343. }
  344. /**
  345. * wdt_release - watchdog file_operations .release
  346. * @inode: inode of the device
  347. * @file: file handle to the device
  348. *
  349. * Closing the watchdog device either stops the watchdog timer
  350. * or in the case, that nowayout is set or the magic character
  351. * wasn't written, a critical warning about an running watchdog
  352. * timer is given.
  353. *
  354. * Used within the file operation of the watchdog device.
  355. */
  356. static int wdt_release(struct inode *inode, struct file *file)
  357. {
  358. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  359. if (test_and_clear_bit(WDTS_EXPECTED, &wdt_status)) {
  360. int ret = wdt_stop();
  361. if (ret) {
  362. /*
  363. * Stop failed. Just keep the watchdog alive
  364. * and hope nothing bad happens.
  365. */
  366. set_bit(WDTS_EXPECTED, &wdt_status);
  367. wdt_keepalive();
  368. return ret;
  369. }
  370. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  371. } else {
  372. wdt_keepalive();
  373. printk(KERN_CRIT PFX
  374. "unexpected close, not stopping watchdog!\n");
  375. }
  376. }
  377. clear_bit(WDTS_DEV_OPEN, &wdt_status);
  378. return 0;
  379. }
  380. /**
  381. * wdt_write - watchdog file_operations .write
  382. * @file: file handle to the watchdog
  383. * @buf: buffer to write
  384. * @count: count of bytes
  385. * @ppos: pointer to the position to write. No seeks allowed
  386. *
  387. * A write to a watchdog device is defined as a keepalive signal. Any
  388. * write of data will do, as we don't define content meaning.
  389. *
  390. * Used within the file operation of the watchdog device.
  391. */
  392. static ssize_t wdt_write(struct file *file, const char __user *buf,
  393. size_t count, loff_t *ppos)
  394. {
  395. if (count) {
  396. clear_bit(WDTS_EXPECTED, &wdt_status);
  397. wdt_keepalive();
  398. }
  399. if (!nowayout) {
  400. size_t ofs;
  401. /* note: just in case someone wrote the magic character long ago */
  402. for (ofs = 0; ofs != count; ofs++) {
  403. char c;
  404. if (get_user(c, buf + ofs))
  405. return -EFAULT;
  406. if (c == WD_MAGIC)
  407. set_bit(WDTS_EXPECTED, &wdt_status);
  408. }
  409. }
  410. return count;
  411. }
  412. static const struct watchdog_info ident = {
  413. .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
  414. .firmware_version = 1,
  415. .identity = WATCHDOG_NAME,
  416. };
  417. /**
  418. * wdt_ioctl - watchdog file_operations .unlocked_ioctl
  419. * @file: file handle to the device
  420. * @cmd: watchdog command
  421. * @arg: argument pointer
  422. *
  423. * The watchdog API defines a common set of functions for all watchdogs
  424. * according to their available features.
  425. *
  426. * Used within the file operation of the watchdog device.
  427. */
  428. static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  429. {
  430. int rc = 0, status, new_options, new_timeout;
  431. union {
  432. struct watchdog_info __user *ident;
  433. int __user *i;
  434. } uarg;
  435. uarg.i = (int __user *)arg;
  436. switch (cmd) {
  437. case WDIOC_GETSUPPORT:
  438. return copy_to_user(uarg.ident,
  439. &ident, sizeof(ident)) ? -EFAULT : 0;
  440. case WDIOC_GETSTATUS:
  441. rc = wdt_get_status(&status);
  442. if (rc)
  443. return rc;
  444. return put_user(status, uarg.i);
  445. case WDIOC_GETBOOTSTATUS:
  446. return put_user(0, uarg.i);
  447. case WDIOC_KEEPALIVE:
  448. wdt_keepalive();
  449. return 0;
  450. case WDIOC_SETOPTIONS:
  451. if (get_user(new_options, uarg.i))
  452. return -EFAULT;
  453. switch (new_options) {
  454. case WDIOS_DISABLECARD:
  455. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  456. rc = wdt_stop();
  457. if (rc)
  458. return rc;
  459. }
  460. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  461. return 0;
  462. case WDIOS_ENABLECARD:
  463. if (!test_and_set_bit(WDTS_TIMER_RUN, &wdt_status)) {
  464. rc = wdt_start();
  465. if (rc) {
  466. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  467. return rc;
  468. }
  469. }
  470. return 0;
  471. default:
  472. return -EFAULT;
  473. }
  474. case WDIOC_SETTIMEOUT:
  475. if (get_user(new_timeout, uarg.i))
  476. return -EFAULT;
  477. rc = wdt_set_timeout(new_timeout);
  478. case WDIOC_GETTIMEOUT:
  479. if (put_user(timeout, uarg.i))
  480. return -EFAULT;
  481. return rc;
  482. default:
  483. return -ENOTTY;
  484. }
  485. }
  486. static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
  487. void *unused)
  488. {
  489. if (code == SYS_DOWN || code == SYS_HALT)
  490. wdt_stop();
  491. return NOTIFY_DONE;
  492. }
  493. static const struct file_operations wdt_fops = {
  494. .owner = THIS_MODULE,
  495. .llseek = no_llseek,
  496. .write = wdt_write,
  497. .unlocked_ioctl = wdt_ioctl,
  498. .open = wdt_open,
  499. .release = wdt_release,
  500. };
  501. static struct miscdevice wdt_miscdev = {
  502. .minor = WATCHDOG_MINOR,
  503. .name = "watchdog",
  504. .fops = &wdt_fops,
  505. };
  506. static struct notifier_block wdt_notifier = {
  507. .notifier_call = wdt_notify_sys,
  508. };
  509. static int __init it87_wdt_init(void)
  510. {
  511. int rc = 0;
  512. int try_gameport = !nogameport;
  513. u8 chip_rev;
  514. int gp_rreq_fail = 0;
  515. wdt_status = 0;
  516. rc = superio_enter();
  517. if (rc)
  518. return rc;
  519. chip_type = superio_inw(CHIPID);
  520. chip_rev = superio_inb(CHIPREV) & 0x0f;
  521. superio_exit();
  522. switch (chip_type) {
  523. case IT8702_ID:
  524. max_units = 255;
  525. break;
  526. case IT8712_ID:
  527. max_units = (chip_rev < 8) ? 255 : 65535;
  528. break;
  529. case IT8716_ID:
  530. case IT8726_ID:
  531. max_units = 65535;
  532. break;
  533. case IT8718_ID:
  534. case IT8720_ID:
  535. case IT8721_ID:
  536. max_units = 65535;
  537. try_gameport = 0;
  538. break;
  539. case IT8705_ID:
  540. printk(KERN_ERR PFX
  541. "Unsupported Chip found, Chip %04x Revision %02x\n",
  542. chip_type, chip_rev);
  543. return -ENODEV;
  544. case NO_DEV_ID:
  545. printk(KERN_ERR PFX "no device\n");
  546. return -ENODEV;
  547. default:
  548. printk(KERN_ERR PFX
  549. "Unknown Chip found, Chip %04x Revision %04x\n",
  550. chip_type, chip_rev);
  551. return -ENODEV;
  552. }
  553. rc = superio_enter();
  554. if (rc)
  555. return rc;
  556. superio_select(GPIO);
  557. superio_outb(WDT_TOV1, WDTCFG);
  558. superio_outb(0x00, WDTCTRL);
  559. /* First try to get Gameport support */
  560. if (try_gameport) {
  561. superio_select(GAMEPORT);
  562. base = superio_inw(BASEREG);
  563. if (!base) {
  564. base = GP_BASE_DEFAULT;
  565. superio_outw(base, BASEREG);
  566. }
  567. gpact = superio_inb(ACTREG);
  568. superio_outb(0x01, ACTREG);
  569. if (request_region(base, 1, WATCHDOG_NAME))
  570. set_bit(WDTS_USE_GP, &wdt_status);
  571. else
  572. gp_rreq_fail = 1;
  573. }
  574. /* If we haven't Gameport support, try to get CIR support */
  575. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  576. if (!request_region(CIR_BASE, 8, WATCHDOG_NAME)) {
  577. if (gp_rreq_fail)
  578. printk(KERN_ERR PFX
  579. "I/O Address 0x%04x and 0x%04x"
  580. " already in use\n", base, CIR_BASE);
  581. else
  582. printk(KERN_ERR PFX
  583. "I/O Address 0x%04x already in use\n",
  584. CIR_BASE);
  585. rc = -EIO;
  586. goto err_out;
  587. }
  588. base = CIR_BASE;
  589. superio_select(CIR);
  590. superio_outw(base, BASEREG);
  591. superio_outb(0x00, CIR_ILS);
  592. ciract = superio_inb(ACTREG);
  593. superio_outb(0x01, ACTREG);
  594. if (gp_rreq_fail) {
  595. superio_select(GAMEPORT);
  596. superio_outb(gpact, ACTREG);
  597. }
  598. }
  599. if (timeout < 1 || timeout > max_units * 60) {
  600. timeout = DEFAULT_TIMEOUT;
  601. printk(KERN_WARNING PFX
  602. "Timeout value out of range, use default %d sec\n",
  603. DEFAULT_TIMEOUT);
  604. }
  605. if (timeout > max_units)
  606. timeout = wdt_round_time(timeout);
  607. rc = register_reboot_notifier(&wdt_notifier);
  608. if (rc) {
  609. printk(KERN_ERR PFX
  610. "Cannot register reboot notifier (err=%d)\n", rc);
  611. goto err_out_region;
  612. }
  613. rc = misc_register(&wdt_miscdev);
  614. if (rc) {
  615. printk(KERN_ERR PFX
  616. "Cannot register miscdev on minor=%d (err=%d)\n",
  617. wdt_miscdev.minor, rc);
  618. goto err_out_reboot;
  619. }
  620. /* Initialize CIR to use it as keepalive source */
  621. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  622. outb(0x00, CIR_RCR(base));
  623. outb(0xc0, CIR_TCR1(base));
  624. outb(0x5c, CIR_TCR2(base));
  625. outb(0x10, CIR_IER(base));
  626. outb(0x00, CIR_BDHR(base));
  627. outb(0x01, CIR_BDLR(base));
  628. outb(0x09, CIR_IER(base));
  629. }
  630. printk(KERN_INFO PFX "Chip IT%04x revision %d initialized. "
  631. "timeout=%d sec (nowayout=%d testmode=%d exclusive=%d "
  632. "nogameport=%d)\n", chip_type, chip_rev, timeout,
  633. nowayout, testmode, exclusive, nogameport);
  634. superio_exit();
  635. return 0;
  636. err_out_reboot:
  637. unregister_reboot_notifier(&wdt_notifier);
  638. err_out_region:
  639. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  640. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  641. superio_select(CIR);
  642. superio_outb(ciract, ACTREG);
  643. }
  644. err_out:
  645. if (try_gameport) {
  646. superio_select(GAMEPORT);
  647. superio_outb(gpact, ACTREG);
  648. }
  649. superio_exit();
  650. return rc;
  651. }
  652. static void __exit it87_wdt_exit(void)
  653. {
  654. if (superio_enter() == 0) {
  655. superio_select(GPIO);
  656. superio_outb(0x00, WDTCTRL);
  657. superio_outb(0x00, WDTCFG);
  658. superio_outb(0x00, WDTVALLSB);
  659. if (max_units > 255)
  660. superio_outb(0x00, WDTVALMSB);
  661. if (test_bit(WDTS_USE_GP, &wdt_status)) {
  662. superio_select(GAMEPORT);
  663. superio_outb(gpact, ACTREG);
  664. } else {
  665. superio_select(CIR);
  666. superio_outb(ciract, ACTREG);
  667. }
  668. superio_exit();
  669. }
  670. misc_deregister(&wdt_miscdev);
  671. unregister_reboot_notifier(&wdt_notifier);
  672. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  673. }
  674. module_init(it87_wdt_init);
  675. module_exit(it87_wdt_exit);
  676. MODULE_AUTHOR("Oliver Schuster");
  677. MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O");
  678. MODULE_LICENSE("GPL");
  679. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);