it87_wdt.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  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. * IT8716, IT8718, IT8726 and IT8712 (J,K version).
  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.12"
  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 IT8705_ID 0x8705
  72. #define IT8712_ID 0x8712
  73. #define IT8716_ID 0x8716
  74. #define IT8718_ID 0x8718
  75. #define IT8726_ID 0x8726 /* the data sheet suggest wrongly 0x8716 */
  76. /* GPIO Configuration Registers LDN=0x07 */
  77. #define WDTCTRL 0x71
  78. #define WDTCFG 0x72
  79. #define WDTVALLSB 0x73
  80. #define WDTVALMSB 0x74
  81. /* GPIO Bits WDTCTRL */
  82. #define WDT_CIRINT 0x80
  83. #define WDT_MOUSEINT 0x40
  84. #define WDT_KYBINT 0x20
  85. #define WDT_GAMEPORT 0x10 /* not it8718 */
  86. #define WDT_FORCE 0x02
  87. #define WDT_ZERO 0x01
  88. /* GPIO Bits WDTCFG */
  89. #define WDT_TOV1 0x80
  90. #define WDT_KRST 0x40
  91. #define WDT_TOVE 0x20
  92. #define WDT_PWROK 0x10
  93. #define WDT_INT_MASK 0x0f
  94. /* CIR Configuration Register LDN=0x0a */
  95. #define CIR_ILS 0x70
  96. /* The default Base address is not always available, we use this */
  97. #define CIR_BASE 0x0208
  98. /* CIR Controller */
  99. #define CIR_DR(b) (b)
  100. #define CIR_IER(b) (b + 1)
  101. #define CIR_RCR(b) (b + 2)
  102. #define CIR_TCR1(b) (b + 3)
  103. #define CIR_TCR2(b) (b + 4)
  104. #define CIR_TSR(b) (b + 5)
  105. #define CIR_RSR(b) (b + 6)
  106. #define CIR_BDLR(b) (b + 5)
  107. #define CIR_BDHR(b) (b + 6)
  108. #define CIR_IIR(b) (b + 7)
  109. /* Default Base address of Game port */
  110. #define GP_BASE_DEFAULT 0x0201
  111. /* wdt_status */
  112. #define WDTS_TIMER_RUN 0
  113. #define WDTS_DEV_OPEN 1
  114. #define WDTS_KEEPALIVE 2
  115. #define WDTS_LOCKED 3
  116. #define WDTS_USE_GP 4
  117. #define WDTS_EXPECTED 5
  118. static unsigned int base, gpact, ciract;
  119. static unsigned long wdt_status;
  120. static DEFINE_SPINLOCK(spinlock);
  121. static int nogameport = DEFAULT_NOGAMEPORT;
  122. static int exclusive = DEFAULT_EXCLUSIVE;
  123. static int timeout = DEFAULT_TIMEOUT;
  124. static int testmode = DEFAULT_TESTMODE;
  125. static int nowayout = DEFAULT_NOWAYOUT;
  126. module_param(nogameport, int, 0);
  127. MODULE_PARM_DESC(nogameport, "Forbid the activation of game port, default="
  128. __MODULE_STRING(DEFAULT_NOGAMEPORT));
  129. module_param(exclusive, int, 0);
  130. MODULE_PARM_DESC(exclusive, "Watchdog exclusive device open, default="
  131. __MODULE_STRING(DEFAULT_EXCLUSIVE));
  132. module_param(timeout, int, 0);
  133. MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds, default="
  134. __MODULE_STRING(DEFAULT_TIMEOUT));
  135. module_param(testmode, int, 0);
  136. MODULE_PARM_DESC(testmode, "Watchdog test mode (1 = no reboot), default="
  137. __MODULE_STRING(DEFAULT_TESTMODE));
  138. module_param(nowayout, int, 0);
  139. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started, default="
  140. __MODULE_STRING(WATCHDOG_NOWAYOUT));
  141. /* Superio Chip */
  142. static inline void superio_enter(void)
  143. {
  144. outb(0x87, REG);
  145. outb(0x01, REG);
  146. outb(0x55, REG);
  147. outb(0x55, REG);
  148. }
  149. static inline void superio_exit(void)
  150. {
  151. outb(0x02, REG);
  152. outb(0x02, VAL);
  153. }
  154. static inline void superio_select(int ldn)
  155. {
  156. outb(LDNREG, REG);
  157. outb(ldn, VAL);
  158. }
  159. static inline int superio_inb(int reg)
  160. {
  161. outb(reg, REG);
  162. return inb(VAL);
  163. }
  164. static inline void superio_outb(int val, int reg)
  165. {
  166. outb(reg, REG);
  167. outb(val, VAL);
  168. }
  169. static inline int superio_inw(int reg)
  170. {
  171. int val;
  172. outb(reg++, REG);
  173. val = inb(VAL) << 8;
  174. outb(reg, REG);
  175. val |= inb(VAL);
  176. return val;
  177. }
  178. static inline void superio_outw(int val, int reg)
  179. {
  180. outb(reg++, REG);
  181. outb(val >> 8, VAL);
  182. outb(reg, REG);
  183. outb(val, VAL);
  184. }
  185. /* watchdog timer handling */
  186. static void wdt_keepalive(void)
  187. {
  188. if (test_bit(WDTS_USE_GP, &wdt_status))
  189. inb(base);
  190. else
  191. /* The timer reloads with around 5 msec delay */
  192. outb(0x55, CIR_DR(base));
  193. set_bit(WDTS_KEEPALIVE, &wdt_status);
  194. }
  195. static void wdt_start(void)
  196. {
  197. unsigned long flags;
  198. spin_lock_irqsave(&spinlock, flags);
  199. superio_enter();
  200. superio_select(GPIO);
  201. if (test_bit(WDTS_USE_GP, &wdt_status))
  202. superio_outb(WDT_GAMEPORT, WDTCTRL);
  203. else
  204. superio_outb(WDT_CIRINT, WDTCTRL);
  205. if (!testmode)
  206. superio_outb(WDT_TOV1 | WDT_KRST | WDT_PWROK, WDTCFG);
  207. else
  208. superio_outb(WDT_TOV1, WDTCFG);
  209. superio_outb(timeout>>8, WDTVALMSB);
  210. superio_outb(timeout, WDTVALLSB);
  211. superio_exit();
  212. spin_unlock_irqrestore(&spinlock, flags);
  213. }
  214. static void wdt_stop(void)
  215. {
  216. unsigned long flags;
  217. spin_lock_irqsave(&spinlock, flags);
  218. superio_enter();
  219. superio_select(GPIO);
  220. superio_outb(0x00, WDTCTRL);
  221. superio_outb(WDT_TOV1, WDTCFG);
  222. superio_outb(0x00, WDTVALMSB);
  223. superio_outb(0x00, WDTVALLSB);
  224. superio_exit();
  225. spin_unlock_irqrestore(&spinlock, flags);
  226. }
  227. /**
  228. * wdt_set_timeout - set a new timeout value with watchdog ioctl
  229. * @t: timeout value in seconds
  230. *
  231. * The hardware device has a 16 bit watchdog timer, thus the
  232. * timeout time ranges between 1 and 65535 seconds.
  233. *
  234. * Used within WDIOC_SETTIMEOUT watchdog device ioctl.
  235. */
  236. static int wdt_set_timeout(int t)
  237. {
  238. unsigned long flags;
  239. if (t < 1 || t > 65535)
  240. return -EINVAL;
  241. timeout = t;
  242. spin_lock_irqsave(&spinlock, flags);
  243. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  244. superio_enter();
  245. superio_select(GPIO);
  246. superio_outb(t>>8, WDTVALMSB);
  247. superio_outb(t, WDTVALLSB);
  248. superio_exit();
  249. }
  250. spin_unlock_irqrestore(&spinlock, flags);
  251. return 0;
  252. }
  253. /**
  254. * wdt_get_status - determines the status supported by watchdog ioctl
  255. * @status: status returned to user space
  256. *
  257. * The status bit of the device does not allow to distinguish
  258. * between a regular system reset and a watchdog forced reset.
  259. * But, in test mode it is useful, so it is supported through
  260. * WDIOC_GETSTATUS watchdog ioctl. Additionally the driver
  261. * reports the keepalive signal and the acception of the magic.
  262. *
  263. * Used within WDIOC_GETSTATUS watchdog device ioctl.
  264. */
  265. static int wdt_get_status(int *status)
  266. {
  267. unsigned long flags;
  268. *status = 0;
  269. if (testmode) {
  270. spin_lock_irqsave(&spinlock, flags);
  271. superio_enter();
  272. superio_select(GPIO);
  273. if (superio_inb(WDTCTRL) & WDT_ZERO) {
  274. superio_outb(0x00, WDTCTRL);
  275. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  276. *status |= WDIOF_CARDRESET;
  277. }
  278. superio_exit();
  279. spin_unlock_irqrestore(&spinlock, flags);
  280. }
  281. if (test_and_clear_bit(WDTS_KEEPALIVE, &wdt_status))
  282. *status |= WDIOF_KEEPALIVEPING;
  283. if (test_bit(WDTS_EXPECTED, &wdt_status))
  284. *status |= WDIOF_MAGICCLOSE;
  285. return 0;
  286. }
  287. /* /dev/watchdog handling */
  288. /**
  289. * wdt_open - watchdog file_operations .open
  290. * @inode: inode of the device
  291. * @file: file handle to the device
  292. *
  293. * The watchdog timer starts by opening the device.
  294. *
  295. * Used within the file operation of the watchdog device.
  296. */
  297. static int wdt_open(struct inode *inode, struct file *file)
  298. {
  299. if (exclusive && test_and_set_bit(WDTS_DEV_OPEN, &wdt_status))
  300. return -EBUSY;
  301. if (!test_and_set_bit(WDTS_TIMER_RUN, &wdt_status)) {
  302. if (nowayout && !test_and_set_bit(WDTS_LOCKED, &wdt_status))
  303. __module_get(THIS_MODULE);
  304. wdt_start();
  305. }
  306. return nonseekable_open(inode, file);
  307. }
  308. /**
  309. * wdt_release - watchdog file_operations .release
  310. * @inode: inode of the device
  311. * @file: file handle to the device
  312. *
  313. * Closing the watchdog device either stops the watchdog timer
  314. * or in the case, that nowayout is set or the magic character
  315. * wasn't written, a critical warning about an running watchdog
  316. * timer is given.
  317. *
  318. * Used within the file operation of the watchdog device.
  319. */
  320. static int wdt_release(struct inode *inode, struct file *file)
  321. {
  322. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  323. if (test_and_clear_bit(WDTS_EXPECTED, &wdt_status)) {
  324. wdt_stop();
  325. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  326. } else {
  327. wdt_keepalive();
  328. printk(KERN_CRIT PFX
  329. "unexpected close, not stopping watchdog!\n");
  330. }
  331. }
  332. clear_bit(WDTS_DEV_OPEN, &wdt_status);
  333. return 0;
  334. }
  335. /**
  336. * wdt_write - watchdog file_operations .write
  337. * @file: file handle to the watchdog
  338. * @buf: buffer to write
  339. * @count: count of bytes
  340. * @ppos: pointer to the position to write. No seeks allowed
  341. *
  342. * A write to a watchdog device is defined as a keepalive signal. Any
  343. * write of data will do, as we don't define content meaning.
  344. *
  345. * Used within the file operation of the watchdog device.
  346. */
  347. static ssize_t wdt_write(struct file *file, const char __user *buf,
  348. size_t count, loff_t *ppos)
  349. {
  350. if (count) {
  351. clear_bit(WDTS_EXPECTED, &wdt_status);
  352. wdt_keepalive();
  353. }
  354. if (!nowayout) {
  355. size_t ofs;
  356. /* note: just in case someone wrote the magic character long ago */
  357. for (ofs = 0; ofs != count; ofs++) {
  358. char c;
  359. if (get_user(c, buf + ofs))
  360. return -EFAULT;
  361. if (c == WD_MAGIC)
  362. set_bit(WDTS_EXPECTED, &wdt_status);
  363. }
  364. }
  365. return count;
  366. }
  367. static struct watchdog_info ident = {
  368. .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
  369. .firmware_version = 1,
  370. .identity = WATCHDOG_NAME,
  371. };
  372. /**
  373. * wdt_ioctl - watchdog file_operations .unlocked_ioctl
  374. * @file: file handle to the device
  375. * @cmd: watchdog command
  376. * @arg: argument pointer
  377. *
  378. * The watchdog API defines a common set of functions for all watchdogs
  379. * according to their available features.
  380. *
  381. * Used within the file operation of the watchdog device.
  382. */
  383. static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  384. {
  385. int rc = 0, status, new_options, new_timeout;
  386. union {
  387. struct watchdog_info __user *ident;
  388. int __user *i;
  389. } uarg;
  390. uarg.i = (int __user *)arg;
  391. switch (cmd) {
  392. case WDIOC_GETSUPPORT:
  393. return copy_to_user(uarg.ident,
  394. &ident, sizeof(ident)) ? -EFAULT : 0;
  395. case WDIOC_GETSTATUS:
  396. wdt_get_status(&status);
  397. return put_user(status, uarg.i);
  398. case WDIOC_GETBOOTSTATUS:
  399. return put_user(0, uarg.i);
  400. case WDIOC_KEEPALIVE:
  401. wdt_keepalive();
  402. return 0;
  403. case WDIOC_SETOPTIONS:
  404. if (get_user(new_options, uarg.i))
  405. return -EFAULT;
  406. switch (new_options) {
  407. case WDIOS_DISABLECARD:
  408. if (test_bit(WDTS_TIMER_RUN, &wdt_status))
  409. wdt_stop();
  410. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  411. return 0;
  412. case WDIOS_ENABLECARD:
  413. if (!test_and_set_bit(WDTS_TIMER_RUN, &wdt_status))
  414. wdt_start();
  415. return 0;
  416. default:
  417. return -EFAULT;
  418. }
  419. case WDIOC_SETTIMEOUT:
  420. if (get_user(new_timeout, uarg.i))
  421. return -EFAULT;
  422. rc = wdt_set_timeout(new_timeout);
  423. case WDIOC_GETTIMEOUT:
  424. if (put_user(timeout, uarg.i))
  425. return -EFAULT;
  426. return rc;
  427. default:
  428. return -ENOTTY;
  429. }
  430. }
  431. static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
  432. void *unused)
  433. {
  434. if (code == SYS_DOWN || code == SYS_HALT)
  435. wdt_stop();
  436. return NOTIFY_DONE;
  437. }
  438. static const struct file_operations wdt_fops = {
  439. .owner = THIS_MODULE,
  440. .llseek = no_llseek,
  441. .write = wdt_write,
  442. .unlocked_ioctl = wdt_ioctl,
  443. .open = wdt_open,
  444. .release = wdt_release,
  445. };
  446. static struct miscdevice wdt_miscdev = {
  447. .minor = WATCHDOG_MINOR,
  448. .name = "watchdog",
  449. .fops = &wdt_fops,
  450. };
  451. static struct notifier_block wdt_notifier = {
  452. .notifier_call = wdt_notify_sys,
  453. };
  454. static int __init it87_wdt_init(void)
  455. {
  456. int rc = 0;
  457. u16 chip_type;
  458. u8 chip_rev;
  459. unsigned long flags;
  460. spin_lock_irqsave(&spinlock, flags);
  461. superio_enter();
  462. chip_type = superio_inw(CHIPID);
  463. chip_rev = superio_inb(CHIPREV) & 0x0f;
  464. superio_exit();
  465. spin_unlock_irqrestore(&spinlock, flags);
  466. switch (chip_type) {
  467. case IT8716_ID:
  468. case IT8718_ID:
  469. case IT8726_ID:
  470. break;
  471. case IT8712_ID:
  472. if (chip_rev > 7)
  473. break;
  474. case IT8705_ID:
  475. printk(KERN_ERR PFX
  476. "Unsupported Chip found, Chip %04x Revision %02x\n",
  477. chip_type, chip_rev);
  478. return -ENODEV;
  479. case NO_DEV_ID:
  480. printk(KERN_ERR PFX "no device\n");
  481. return -ENODEV;
  482. default:
  483. printk(KERN_ERR PFX
  484. "Unknown Chip found, Chip %04x Revision %04x\n",
  485. chip_type, chip_rev);
  486. return -ENODEV;
  487. }
  488. spin_lock_irqsave(&spinlock, flags);
  489. superio_enter();
  490. superio_select(GPIO);
  491. superio_outb(WDT_TOV1, WDTCFG);
  492. superio_outb(0x00, WDTCTRL);
  493. /* First try to get Gameport support */
  494. if (chip_type != IT8718_ID && !nogameport) {
  495. superio_select(GAMEPORT);
  496. base = superio_inw(BASEREG);
  497. if (!base) {
  498. base = GP_BASE_DEFAULT;
  499. superio_outw(base, BASEREG);
  500. }
  501. gpact = superio_inb(ACTREG);
  502. superio_outb(0x01, ACTREG);
  503. superio_exit();
  504. spin_unlock_irqrestore(&spinlock, flags);
  505. if (request_region(base, 1, WATCHDOG_NAME))
  506. set_bit(WDTS_USE_GP, &wdt_status);
  507. else
  508. rc = -EIO;
  509. } else {
  510. superio_exit();
  511. spin_unlock_irqrestore(&spinlock, flags);
  512. }
  513. /* If we haven't Gameport support, try to get CIR support */
  514. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  515. if (!request_region(CIR_BASE, 8, WATCHDOG_NAME)) {
  516. if (rc == -EIO)
  517. printk(KERN_ERR PFX
  518. "I/O Address 0x%04x and 0x%04x"
  519. " already in use\n", base, CIR_BASE);
  520. else
  521. printk(KERN_ERR PFX
  522. "I/O Address 0x%04x already in use\n",
  523. CIR_BASE);
  524. rc = -EIO;
  525. goto err_out;
  526. }
  527. base = CIR_BASE;
  528. spin_lock_irqsave(&spinlock, flags);
  529. superio_enter();
  530. superio_select(CIR);
  531. superio_outw(base, BASEREG);
  532. superio_outb(0x00, CIR_ILS);
  533. ciract = superio_inb(ACTREG);
  534. superio_outb(0x01, ACTREG);
  535. if (rc == -EIO) {
  536. superio_select(GAMEPORT);
  537. superio_outb(gpact, ACTREG);
  538. }
  539. superio_exit();
  540. spin_unlock_irqrestore(&spinlock, flags);
  541. }
  542. if (timeout < 1 || timeout > 65535) {
  543. timeout = DEFAULT_TIMEOUT;
  544. printk(KERN_WARNING PFX
  545. "Timeout value out of range, use default %d sec\n",
  546. DEFAULT_TIMEOUT);
  547. }
  548. rc = register_reboot_notifier(&wdt_notifier);
  549. if (rc) {
  550. printk(KERN_ERR PFX
  551. "Cannot register reboot notifier (err=%d)\n", rc);
  552. goto err_out_region;
  553. }
  554. rc = misc_register(&wdt_miscdev);
  555. if (rc) {
  556. printk(KERN_ERR PFX
  557. "Cannot register miscdev on minor=%d (err=%d)\n",
  558. wdt_miscdev.minor, rc);
  559. goto err_out_reboot;
  560. }
  561. /* Initialize CIR to use it as keepalive source */
  562. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  563. outb(0x00, CIR_RCR(base));
  564. outb(0xc0, CIR_TCR1(base));
  565. outb(0x5c, CIR_TCR2(base));
  566. outb(0x10, CIR_IER(base));
  567. outb(0x00, CIR_BDHR(base));
  568. outb(0x01, CIR_BDLR(base));
  569. outb(0x09, CIR_IER(base));
  570. }
  571. printk(KERN_INFO PFX "Chip it%04x revision %d initialized. "
  572. "timeout=%d sec (nowayout=%d testmode=%d exclusive=%d "
  573. "nogameport=%d)\n", chip_type, chip_rev, timeout,
  574. nowayout, testmode, exclusive, nogameport);
  575. return 0;
  576. err_out_reboot:
  577. unregister_reboot_notifier(&wdt_notifier);
  578. err_out_region:
  579. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  580. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  581. spin_lock_irqsave(&spinlock, flags);
  582. superio_enter();
  583. superio_select(CIR);
  584. superio_outb(ciract, ACTREG);
  585. superio_exit();
  586. spin_unlock_irqrestore(&spinlock, flags);
  587. }
  588. err_out:
  589. if (chip_type != IT8718_ID && !nogameport) {
  590. spin_lock_irqsave(&spinlock, flags);
  591. superio_enter();
  592. superio_select(GAMEPORT);
  593. superio_outb(gpact, ACTREG);
  594. superio_exit();
  595. spin_unlock_irqrestore(&spinlock, flags);
  596. }
  597. return rc;
  598. }
  599. static void __exit it87_wdt_exit(void)
  600. {
  601. unsigned long flags;
  602. int nolock;
  603. nolock = !spin_trylock_irqsave(&spinlock, flags);
  604. superio_enter();
  605. superio_select(GPIO);
  606. superio_outb(0x00, WDTCTRL);
  607. superio_outb(0x00, WDTCFG);
  608. superio_outb(0x00, WDTVALMSB);
  609. superio_outb(0x00, WDTVALLSB);
  610. if (test_bit(WDTS_USE_GP, &wdt_status)) {
  611. superio_select(GAMEPORT);
  612. superio_outb(gpact, ACTREG);
  613. } else {
  614. superio_select(CIR);
  615. superio_outb(ciract, ACTREG);
  616. }
  617. superio_exit();
  618. if (!nolock)
  619. spin_unlock_irqrestore(&spinlock, flags);
  620. misc_deregister(&wdt_miscdev);
  621. unregister_reboot_notifier(&wdt_notifier);
  622. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  623. }
  624. module_init(it87_wdt_init);
  625. module_exit(it87_wdt_exit);
  626. MODULE_AUTHOR("Oliver Schuster");
  627. MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O");
  628. MODULE_LICENSE("GPL");
  629. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);