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. #include <asm/system.h>
  46. #define WATCHDOG_VERSION "1.14"
  47. #define WATCHDOG_NAME "IT87 WDT"
  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 bool 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, bool, 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. pr_crit("unexpected close, not stopping watchdog!\n");
  374. }
  375. }
  376. clear_bit(WDTS_DEV_OPEN, &wdt_status);
  377. return 0;
  378. }
  379. /**
  380. * wdt_write - watchdog file_operations .write
  381. * @file: file handle to the watchdog
  382. * @buf: buffer to write
  383. * @count: count of bytes
  384. * @ppos: pointer to the position to write. No seeks allowed
  385. *
  386. * A write to a watchdog device is defined as a keepalive signal. Any
  387. * write of data will do, as we don't define content meaning.
  388. *
  389. * Used within the file operation of the watchdog device.
  390. */
  391. static ssize_t wdt_write(struct file *file, const char __user *buf,
  392. size_t count, loff_t *ppos)
  393. {
  394. if (count) {
  395. clear_bit(WDTS_EXPECTED, &wdt_status);
  396. wdt_keepalive();
  397. }
  398. if (!nowayout) {
  399. size_t ofs;
  400. /* note: just in case someone wrote the magic character long ago */
  401. for (ofs = 0; ofs != count; ofs++) {
  402. char c;
  403. if (get_user(c, buf + ofs))
  404. return -EFAULT;
  405. if (c == WD_MAGIC)
  406. set_bit(WDTS_EXPECTED, &wdt_status);
  407. }
  408. }
  409. return count;
  410. }
  411. static const struct watchdog_info ident = {
  412. .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
  413. .firmware_version = 1,
  414. .identity = WATCHDOG_NAME,
  415. };
  416. /**
  417. * wdt_ioctl - watchdog file_operations .unlocked_ioctl
  418. * @file: file handle to the device
  419. * @cmd: watchdog command
  420. * @arg: argument pointer
  421. *
  422. * The watchdog API defines a common set of functions for all watchdogs
  423. * according to their available features.
  424. *
  425. * Used within the file operation of the watchdog device.
  426. */
  427. static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  428. {
  429. int rc = 0, status, new_options, new_timeout;
  430. union {
  431. struct watchdog_info __user *ident;
  432. int __user *i;
  433. } uarg;
  434. uarg.i = (int __user *)arg;
  435. switch (cmd) {
  436. case WDIOC_GETSUPPORT:
  437. return copy_to_user(uarg.ident,
  438. &ident, sizeof(ident)) ? -EFAULT : 0;
  439. case WDIOC_GETSTATUS:
  440. rc = wdt_get_status(&status);
  441. if (rc)
  442. return rc;
  443. return put_user(status, uarg.i);
  444. case WDIOC_GETBOOTSTATUS:
  445. return put_user(0, uarg.i);
  446. case WDIOC_KEEPALIVE:
  447. wdt_keepalive();
  448. return 0;
  449. case WDIOC_SETOPTIONS:
  450. if (get_user(new_options, uarg.i))
  451. return -EFAULT;
  452. switch (new_options) {
  453. case WDIOS_DISABLECARD:
  454. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  455. rc = wdt_stop();
  456. if (rc)
  457. return rc;
  458. }
  459. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  460. return 0;
  461. case WDIOS_ENABLECARD:
  462. if (!test_and_set_bit(WDTS_TIMER_RUN, &wdt_status)) {
  463. rc = wdt_start();
  464. if (rc) {
  465. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  466. return rc;
  467. }
  468. }
  469. return 0;
  470. default:
  471. return -EFAULT;
  472. }
  473. case WDIOC_SETTIMEOUT:
  474. if (get_user(new_timeout, uarg.i))
  475. return -EFAULT;
  476. rc = wdt_set_timeout(new_timeout);
  477. case WDIOC_GETTIMEOUT:
  478. if (put_user(timeout, uarg.i))
  479. return -EFAULT;
  480. return rc;
  481. default:
  482. return -ENOTTY;
  483. }
  484. }
  485. static int wdt_notify_sys(struct notifier_block *this, unsigned long code,
  486. void *unused)
  487. {
  488. if (code == SYS_DOWN || code == SYS_HALT)
  489. wdt_stop();
  490. return NOTIFY_DONE;
  491. }
  492. static const struct file_operations wdt_fops = {
  493. .owner = THIS_MODULE,
  494. .llseek = no_llseek,
  495. .write = wdt_write,
  496. .unlocked_ioctl = wdt_ioctl,
  497. .open = wdt_open,
  498. .release = wdt_release,
  499. };
  500. static struct miscdevice wdt_miscdev = {
  501. .minor = WATCHDOG_MINOR,
  502. .name = "watchdog",
  503. .fops = &wdt_fops,
  504. };
  505. static struct notifier_block wdt_notifier = {
  506. .notifier_call = wdt_notify_sys,
  507. };
  508. static int __init it87_wdt_init(void)
  509. {
  510. int rc = 0;
  511. int try_gameport = !nogameport;
  512. u8 chip_rev;
  513. int gp_rreq_fail = 0;
  514. wdt_status = 0;
  515. rc = superio_enter();
  516. if (rc)
  517. return rc;
  518. chip_type = superio_inw(CHIPID);
  519. chip_rev = superio_inb(CHIPREV) & 0x0f;
  520. superio_exit();
  521. switch (chip_type) {
  522. case IT8702_ID:
  523. max_units = 255;
  524. break;
  525. case IT8712_ID:
  526. max_units = (chip_rev < 8) ? 255 : 65535;
  527. break;
  528. case IT8716_ID:
  529. case IT8726_ID:
  530. max_units = 65535;
  531. break;
  532. case IT8718_ID:
  533. case IT8720_ID:
  534. case IT8721_ID:
  535. max_units = 65535;
  536. try_gameport = 0;
  537. break;
  538. case IT8705_ID:
  539. pr_err("Unsupported Chip found, Chip %04x Revision %02x\n",
  540. chip_type, chip_rev);
  541. return -ENODEV;
  542. case NO_DEV_ID:
  543. pr_err("no device\n");
  544. return -ENODEV;
  545. default:
  546. pr_err("Unknown Chip found, Chip %04x Revision %04x\n",
  547. chip_type, chip_rev);
  548. return -ENODEV;
  549. }
  550. rc = superio_enter();
  551. if (rc)
  552. return rc;
  553. superio_select(GPIO);
  554. superio_outb(WDT_TOV1, WDTCFG);
  555. superio_outb(0x00, WDTCTRL);
  556. /* First try to get Gameport support */
  557. if (try_gameport) {
  558. superio_select(GAMEPORT);
  559. base = superio_inw(BASEREG);
  560. if (!base) {
  561. base = GP_BASE_DEFAULT;
  562. superio_outw(base, BASEREG);
  563. }
  564. gpact = superio_inb(ACTREG);
  565. superio_outb(0x01, ACTREG);
  566. if (request_region(base, 1, WATCHDOG_NAME))
  567. set_bit(WDTS_USE_GP, &wdt_status);
  568. else
  569. gp_rreq_fail = 1;
  570. }
  571. /* If we haven't Gameport support, try to get CIR support */
  572. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  573. if (!request_region(CIR_BASE, 8, WATCHDOG_NAME)) {
  574. if (gp_rreq_fail)
  575. pr_err("I/O Address 0x%04x and 0x%04x already in use\n",
  576. base, CIR_BASE);
  577. else
  578. pr_err("I/O Address 0x%04x already in use\n",
  579. CIR_BASE);
  580. rc = -EIO;
  581. goto err_out;
  582. }
  583. base = CIR_BASE;
  584. superio_select(CIR);
  585. superio_outw(base, BASEREG);
  586. superio_outb(0x00, CIR_ILS);
  587. ciract = superio_inb(ACTREG);
  588. superio_outb(0x01, ACTREG);
  589. if (gp_rreq_fail) {
  590. superio_select(GAMEPORT);
  591. superio_outb(gpact, ACTREG);
  592. }
  593. }
  594. if (timeout < 1 || timeout > max_units * 60) {
  595. timeout = DEFAULT_TIMEOUT;
  596. pr_warn("Timeout value out of range, use default %d sec\n",
  597. DEFAULT_TIMEOUT);
  598. }
  599. if (timeout > max_units)
  600. timeout = wdt_round_time(timeout);
  601. rc = register_reboot_notifier(&wdt_notifier);
  602. if (rc) {
  603. pr_err("Cannot register reboot notifier (err=%d)\n", rc);
  604. goto err_out_region;
  605. }
  606. rc = misc_register(&wdt_miscdev);
  607. if (rc) {
  608. pr_err("Cannot register miscdev on minor=%d (err=%d)\n",
  609. wdt_miscdev.minor, rc);
  610. goto err_out_reboot;
  611. }
  612. /* Initialize CIR to use it as keepalive source */
  613. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  614. outb(0x00, CIR_RCR(base));
  615. outb(0xc0, CIR_TCR1(base));
  616. outb(0x5c, CIR_TCR2(base));
  617. outb(0x10, CIR_IER(base));
  618. outb(0x00, CIR_BDHR(base));
  619. outb(0x01, CIR_BDLR(base));
  620. outb(0x09, CIR_IER(base));
  621. }
  622. pr_info("Chip IT%04x revision %d initialized. timeout=%d sec (nowayout=%d testmode=%d exclusive=%d nogameport=%d)\n",
  623. chip_type, chip_rev, timeout,
  624. nowayout, testmode, exclusive, nogameport);
  625. superio_exit();
  626. return 0;
  627. err_out_reboot:
  628. unregister_reboot_notifier(&wdt_notifier);
  629. err_out_region:
  630. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  631. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  632. superio_select(CIR);
  633. superio_outb(ciract, ACTREG);
  634. }
  635. err_out:
  636. if (try_gameport) {
  637. superio_select(GAMEPORT);
  638. superio_outb(gpact, ACTREG);
  639. }
  640. superio_exit();
  641. return rc;
  642. }
  643. static void __exit it87_wdt_exit(void)
  644. {
  645. if (superio_enter() == 0) {
  646. superio_select(GPIO);
  647. superio_outb(0x00, WDTCTRL);
  648. superio_outb(0x00, WDTCFG);
  649. superio_outb(0x00, WDTVALLSB);
  650. if (max_units > 255)
  651. superio_outb(0x00, WDTVALMSB);
  652. if (test_bit(WDTS_USE_GP, &wdt_status)) {
  653. superio_select(GAMEPORT);
  654. superio_outb(gpact, ACTREG);
  655. } else {
  656. superio_select(CIR);
  657. superio_outb(ciract, ACTREG);
  658. }
  659. superio_exit();
  660. }
  661. misc_deregister(&wdt_miscdev);
  662. unregister_reboot_notifier(&wdt_notifier);
  663. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  664. }
  665. module_init(it87_wdt_init);
  666. module_exit(it87_wdt_exit);
  667. MODULE_AUTHOR("Oliver Schuster");
  668. MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O");
  669. MODULE_LICENSE("GPL");
  670. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);