it87_wdt.c 18 KB

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