it87_wdt.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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, IT8726
  16. * and IT8728.
  17. *
  18. * This program is free software; you can redistribute it and/or
  19. * modify it under the terms of the GNU General Public License
  20. * as published by the Free Software Foundation; either version
  21. * 2 of the License, or (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. */
  32. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  33. #include <linux/module.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/types.h>
  36. #include <linux/kernel.h>
  37. #include <linux/fs.h>
  38. #include <linux/miscdevice.h>
  39. #include <linux/init.h>
  40. #include <linux/ioport.h>
  41. #include <linux/watchdog.h>
  42. #include <linux/notifier.h>
  43. #include <linux/reboot.h>
  44. #include <linux/uaccess.h>
  45. #include <linux/io.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. #define IT8728_ID 0x8728
  80. /* GPIO Configuration Registers LDN=0x07 */
  81. #define WDTCTRL 0x71
  82. #define WDTCFG 0x72
  83. #define WDTVALLSB 0x73
  84. #define WDTVALMSB 0x74
  85. /* GPIO Bits WDTCTRL */
  86. #define WDT_CIRINT 0x80
  87. #define WDT_MOUSEINT 0x40
  88. #define WDT_KYBINT 0x20
  89. #define WDT_GAMEPORT 0x10 /* not in it8718, it8720, it8721, it8728 */
  90. #define WDT_FORCE 0x02
  91. #define WDT_ZERO 0x01
  92. /* GPIO Bits WDTCFG */
  93. #define WDT_TOV1 0x80
  94. #define WDT_KRST 0x40
  95. #define WDT_TOVE 0x20
  96. #define WDT_PWROK 0x10 /* not in it8721 */
  97. #define WDT_INT_MASK 0x0f
  98. /* CIR Configuration Register LDN=0x0a */
  99. #define CIR_ILS 0x70
  100. /* The default Base address is not always available, we use this */
  101. #define CIR_BASE 0x0208
  102. /* CIR Controller */
  103. #define CIR_DR(b) (b)
  104. #define CIR_IER(b) (b + 1)
  105. #define CIR_RCR(b) (b + 2)
  106. #define CIR_TCR1(b) (b + 3)
  107. #define CIR_TCR2(b) (b + 4)
  108. #define CIR_TSR(b) (b + 5)
  109. #define CIR_RSR(b) (b + 6)
  110. #define CIR_BDLR(b) (b + 5)
  111. #define CIR_BDHR(b) (b + 6)
  112. #define CIR_IIR(b) (b + 7)
  113. /* Default Base address of Game port */
  114. #define GP_BASE_DEFAULT 0x0201
  115. /* wdt_status */
  116. #define WDTS_TIMER_RUN 0
  117. #define WDTS_DEV_OPEN 1
  118. #define WDTS_KEEPALIVE 2
  119. #define WDTS_LOCKED 3
  120. #define WDTS_USE_GP 4
  121. #define WDTS_EXPECTED 5
  122. static unsigned int base, gpact, ciract, max_units, chip_type;
  123. static unsigned long wdt_status;
  124. static int nogameport = DEFAULT_NOGAMEPORT;
  125. static int exclusive = DEFAULT_EXCLUSIVE;
  126. static int timeout = DEFAULT_TIMEOUT;
  127. static int testmode = DEFAULT_TESTMODE;
  128. static bool nowayout = DEFAULT_NOWAYOUT;
  129. module_param(nogameport, int, 0);
  130. MODULE_PARM_DESC(nogameport, "Forbid the activation of game port, default="
  131. __MODULE_STRING(DEFAULT_NOGAMEPORT));
  132. module_param(exclusive, int, 0);
  133. MODULE_PARM_DESC(exclusive, "Watchdog exclusive device open, default="
  134. __MODULE_STRING(DEFAULT_EXCLUSIVE));
  135. module_param(timeout, int, 0);
  136. MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds, default="
  137. __MODULE_STRING(DEFAULT_TIMEOUT));
  138. module_param(testmode, int, 0);
  139. MODULE_PARM_DESC(testmode, "Watchdog test mode (1 = no reboot), default="
  140. __MODULE_STRING(DEFAULT_TESTMODE));
  141. module_param(nowayout, bool, 0);
  142. MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started, default="
  143. __MODULE_STRING(WATCHDOG_NOWAYOUT));
  144. /* Superio Chip */
  145. static inline int superio_enter(void)
  146. {
  147. /*
  148. * Try to reserve REG and REG + 1 for exclusive access.
  149. */
  150. if (!request_muxed_region(REG, 2, WATCHDOG_NAME))
  151. return -EBUSY;
  152. outb(0x87, REG);
  153. outb(0x01, REG);
  154. outb(0x55, REG);
  155. outb(0x55, REG);
  156. return 0;
  157. }
  158. static inline void superio_exit(void)
  159. {
  160. outb(0x02, REG);
  161. outb(0x02, VAL);
  162. release_region(REG, 2);
  163. }
  164. static inline void superio_select(int ldn)
  165. {
  166. outb(LDNREG, REG);
  167. outb(ldn, VAL);
  168. }
  169. static inline int superio_inb(int reg)
  170. {
  171. outb(reg, REG);
  172. return inb(VAL);
  173. }
  174. static inline void superio_outb(int val, int reg)
  175. {
  176. outb(reg, REG);
  177. outb(val, VAL);
  178. }
  179. static inline int superio_inw(int reg)
  180. {
  181. int val;
  182. outb(reg++, REG);
  183. val = inb(VAL) << 8;
  184. outb(reg, REG);
  185. val |= inb(VAL);
  186. return val;
  187. }
  188. static inline void superio_outw(int val, int reg)
  189. {
  190. outb(reg++, REG);
  191. outb(val >> 8, VAL);
  192. outb(reg, REG);
  193. outb(val, VAL);
  194. }
  195. /* Internal function, should be called after superio_select(GPIO) */
  196. static void wdt_update_timeout(void)
  197. {
  198. unsigned char cfg = WDT_KRST;
  199. int tm = timeout;
  200. if (testmode)
  201. cfg = 0;
  202. if (tm <= max_units)
  203. cfg |= WDT_TOV1;
  204. else
  205. tm /= 60;
  206. if (chip_type != IT8721_ID)
  207. cfg |= WDT_PWROK;
  208. superio_outb(cfg, WDTCFG);
  209. superio_outb(tm, WDTVALLSB);
  210. if (max_units > 255)
  211. superio_outb(tm>>8, WDTVALMSB);
  212. }
  213. static int wdt_round_time(int t)
  214. {
  215. t += 59;
  216. t -= t % 60;
  217. return t;
  218. }
  219. /* watchdog timer handling */
  220. static void wdt_keepalive(void)
  221. {
  222. if (test_bit(WDTS_USE_GP, &wdt_status))
  223. inb(base);
  224. else
  225. /* The timer reloads with around 5 msec delay */
  226. outb(0x55, CIR_DR(base));
  227. set_bit(WDTS_KEEPALIVE, &wdt_status);
  228. }
  229. static int wdt_start(void)
  230. {
  231. int ret = superio_enter();
  232. if (ret)
  233. return ret;
  234. superio_select(GPIO);
  235. if (test_bit(WDTS_USE_GP, &wdt_status))
  236. superio_outb(WDT_GAMEPORT, WDTCTRL);
  237. else
  238. superio_outb(WDT_CIRINT, WDTCTRL);
  239. wdt_update_timeout();
  240. superio_exit();
  241. return 0;
  242. }
  243. static int wdt_stop(void)
  244. {
  245. int ret = superio_enter();
  246. if (ret)
  247. return ret;
  248. superio_select(GPIO);
  249. superio_outb(0x00, WDTCTRL);
  250. superio_outb(WDT_TOV1, WDTCFG);
  251. superio_outb(0x00, WDTVALLSB);
  252. if (max_units > 255)
  253. superio_outb(0x00, WDTVALMSB);
  254. superio_exit();
  255. return 0;
  256. }
  257. /**
  258. * wdt_set_timeout - set a new timeout value with watchdog ioctl
  259. * @t: timeout value in seconds
  260. *
  261. * The hardware device has a 8 or 16 bit watchdog timer (depends on
  262. * chip version) that can be configured to count seconds or minutes.
  263. *
  264. * Used within WDIOC_SETTIMEOUT watchdog device ioctl.
  265. */
  266. static int wdt_set_timeout(int t)
  267. {
  268. if (t < 1 || t > max_units * 60)
  269. return -EINVAL;
  270. if (t > max_units)
  271. timeout = wdt_round_time(t);
  272. else
  273. timeout = t;
  274. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  275. int ret = superio_enter();
  276. if (ret)
  277. return ret;
  278. superio_select(GPIO);
  279. wdt_update_timeout();
  280. superio_exit();
  281. }
  282. return 0;
  283. }
  284. /**
  285. * wdt_get_status - determines the status supported by watchdog ioctl
  286. * @status: status returned to user space
  287. *
  288. * The status bit of the device does not allow to distinguish
  289. * between a regular system reset and a watchdog forced reset.
  290. * But, in test mode it is useful, so it is supported through
  291. * WDIOC_GETSTATUS watchdog ioctl. Additionally the driver
  292. * reports the keepalive signal and the acception of the magic.
  293. *
  294. * Used within WDIOC_GETSTATUS watchdog device ioctl.
  295. */
  296. static int wdt_get_status(int *status)
  297. {
  298. *status = 0;
  299. if (testmode) {
  300. int ret = superio_enter();
  301. if (ret)
  302. return ret;
  303. superio_select(GPIO);
  304. if (superio_inb(WDTCTRL) & WDT_ZERO) {
  305. superio_outb(0x00, WDTCTRL);
  306. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  307. *status |= WDIOF_CARDRESET;
  308. }
  309. superio_exit();
  310. }
  311. if (test_and_clear_bit(WDTS_KEEPALIVE, &wdt_status))
  312. *status |= WDIOF_KEEPALIVEPING;
  313. if (test_bit(WDTS_EXPECTED, &wdt_status))
  314. *status |= WDIOF_MAGICCLOSE;
  315. return 0;
  316. }
  317. /* /dev/watchdog handling */
  318. /**
  319. * wdt_open - watchdog file_operations .open
  320. * @inode: inode of the device
  321. * @file: file handle to the device
  322. *
  323. * The watchdog timer starts by opening the device.
  324. *
  325. * Used within the file operation of the watchdog device.
  326. */
  327. static int wdt_open(struct inode *inode, struct file *file)
  328. {
  329. if (exclusive && test_and_set_bit(WDTS_DEV_OPEN, &wdt_status))
  330. return -EBUSY;
  331. if (!test_and_set_bit(WDTS_TIMER_RUN, &wdt_status)) {
  332. int ret;
  333. if (nowayout && !test_and_set_bit(WDTS_LOCKED, &wdt_status))
  334. __module_get(THIS_MODULE);
  335. ret = wdt_start();
  336. if (ret) {
  337. clear_bit(WDTS_LOCKED, &wdt_status);
  338. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  339. clear_bit(WDTS_DEV_OPEN, &wdt_status);
  340. return ret;
  341. }
  342. }
  343. return nonseekable_open(inode, file);
  344. }
  345. /**
  346. * wdt_release - watchdog file_operations .release
  347. * @inode: inode of the device
  348. * @file: file handle to the device
  349. *
  350. * Closing the watchdog device either stops the watchdog timer
  351. * or in the case, that nowayout is set or the magic character
  352. * wasn't written, a critical warning about an running watchdog
  353. * timer is given.
  354. *
  355. * Used within the file operation of the watchdog device.
  356. */
  357. static int wdt_release(struct inode *inode, struct file *file)
  358. {
  359. if (test_bit(WDTS_TIMER_RUN, &wdt_status)) {
  360. if (test_and_clear_bit(WDTS_EXPECTED, &wdt_status)) {
  361. int ret = wdt_stop();
  362. if (ret) {
  363. /*
  364. * Stop failed. Just keep the watchdog alive
  365. * and hope nothing bad happens.
  366. */
  367. set_bit(WDTS_EXPECTED, &wdt_status);
  368. wdt_keepalive();
  369. return ret;
  370. }
  371. clear_bit(WDTS_TIMER_RUN, &wdt_status);
  372. } else {
  373. wdt_keepalive();
  374. pr_crit("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. case IT8728_ID:
  537. max_units = 65535;
  538. try_gameport = 0;
  539. break;
  540. case IT8705_ID:
  541. pr_err("Unsupported Chip found, Chip %04x Revision %02x\n",
  542. chip_type, chip_rev);
  543. return -ENODEV;
  544. case NO_DEV_ID:
  545. pr_err("no device\n");
  546. return -ENODEV;
  547. default:
  548. pr_err("Unknown Chip found, Chip %04x Revision %04x\n",
  549. chip_type, chip_rev);
  550. return -ENODEV;
  551. }
  552. rc = superio_enter();
  553. if (rc)
  554. return rc;
  555. superio_select(GPIO);
  556. superio_outb(WDT_TOV1, WDTCFG);
  557. superio_outb(0x00, WDTCTRL);
  558. /* First try to get Gameport support */
  559. if (try_gameport) {
  560. superio_select(GAMEPORT);
  561. base = superio_inw(BASEREG);
  562. if (!base) {
  563. base = GP_BASE_DEFAULT;
  564. superio_outw(base, BASEREG);
  565. }
  566. gpact = superio_inb(ACTREG);
  567. superio_outb(0x01, ACTREG);
  568. if (request_region(base, 1, WATCHDOG_NAME))
  569. set_bit(WDTS_USE_GP, &wdt_status);
  570. else
  571. gp_rreq_fail = 1;
  572. }
  573. /* If we haven't Gameport support, try to get CIR support */
  574. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  575. if (!request_region(CIR_BASE, 8, WATCHDOG_NAME)) {
  576. if (gp_rreq_fail)
  577. pr_err("I/O Address 0x%04x and 0x%04x already in use\n",
  578. base, CIR_BASE);
  579. else
  580. pr_err("I/O Address 0x%04x already in use\n",
  581. CIR_BASE);
  582. rc = -EIO;
  583. goto err_out;
  584. }
  585. base = CIR_BASE;
  586. superio_select(CIR);
  587. superio_outw(base, BASEREG);
  588. superio_outb(0x00, CIR_ILS);
  589. ciract = superio_inb(ACTREG);
  590. superio_outb(0x01, ACTREG);
  591. if (gp_rreq_fail) {
  592. superio_select(GAMEPORT);
  593. superio_outb(gpact, ACTREG);
  594. }
  595. }
  596. if (timeout < 1 || timeout > max_units * 60) {
  597. timeout = DEFAULT_TIMEOUT;
  598. pr_warn("Timeout value out of range, use default %d sec\n",
  599. DEFAULT_TIMEOUT);
  600. }
  601. if (timeout > max_units)
  602. timeout = wdt_round_time(timeout);
  603. rc = register_reboot_notifier(&wdt_notifier);
  604. if (rc) {
  605. pr_err("Cannot register reboot notifier (err=%d)\n", rc);
  606. goto err_out_region;
  607. }
  608. rc = misc_register(&wdt_miscdev);
  609. if (rc) {
  610. pr_err("Cannot register miscdev on minor=%d (err=%d)\n",
  611. wdt_miscdev.minor, rc);
  612. goto err_out_reboot;
  613. }
  614. /* Initialize CIR to use it as keepalive source */
  615. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  616. outb(0x00, CIR_RCR(base));
  617. outb(0xc0, CIR_TCR1(base));
  618. outb(0x5c, CIR_TCR2(base));
  619. outb(0x10, CIR_IER(base));
  620. outb(0x00, CIR_BDHR(base));
  621. outb(0x01, CIR_BDLR(base));
  622. outb(0x09, CIR_IER(base));
  623. }
  624. pr_info("Chip IT%04x revision %d initialized. timeout=%d sec (nowayout=%d testmode=%d exclusive=%d nogameport=%d)\n",
  625. chip_type, chip_rev, timeout,
  626. nowayout, testmode, exclusive, nogameport);
  627. superio_exit();
  628. return 0;
  629. err_out_reboot:
  630. unregister_reboot_notifier(&wdt_notifier);
  631. err_out_region:
  632. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  633. if (!test_bit(WDTS_USE_GP, &wdt_status)) {
  634. superio_select(CIR);
  635. superio_outb(ciract, ACTREG);
  636. }
  637. err_out:
  638. if (try_gameport) {
  639. superio_select(GAMEPORT);
  640. superio_outb(gpact, ACTREG);
  641. }
  642. superio_exit();
  643. return rc;
  644. }
  645. static void __exit it87_wdt_exit(void)
  646. {
  647. if (superio_enter() == 0) {
  648. superio_select(GPIO);
  649. superio_outb(0x00, WDTCTRL);
  650. superio_outb(0x00, WDTCFG);
  651. superio_outb(0x00, WDTVALLSB);
  652. if (max_units > 255)
  653. superio_outb(0x00, WDTVALMSB);
  654. if (test_bit(WDTS_USE_GP, &wdt_status)) {
  655. superio_select(GAMEPORT);
  656. superio_outb(gpact, ACTREG);
  657. } else {
  658. superio_select(CIR);
  659. superio_outb(ciract, ACTREG);
  660. }
  661. superio_exit();
  662. }
  663. misc_deregister(&wdt_miscdev);
  664. unregister_reboot_notifier(&wdt_notifier);
  665. release_region(base, test_bit(WDTS_USE_GP, &wdt_status) ? 1 : 8);
  666. }
  667. module_init(it87_wdt_init);
  668. module_exit(it87_wdt_exit);
  669. MODULE_AUTHOR("Oliver Schuster");
  670. MODULE_DESCRIPTION("Hardware Watchdog Device Driver for IT87xx EC-LPC I/O");
  671. MODULE_LICENSE("GPL");
  672. MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);