it87_wdt.c 18 KB

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