2 * IT8712F "Smart Guardian" Watchdog support
4 * Copyright (c) 2006-2007 Jorge Boncompte - DTI2 <jorge@dti2.net>
6 * Based on info and code taken from:
8 * drivers/char/watchdog/scx200_wdt.c
10 <<<<<<< HEAD:drivers/watchdog/it8712f_wdt.c
11 * IT8712F EC-LPC I/O Preliminary Specification 0.9.2.pdf
13 * IT8712F EC-LPC I/O Preliminary Specification 0.8.2
14 * IT8712F EC-LPC I/O Preliminary Specification 0.9.3
15 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/watchdog/it8712f_wdt.c
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License as
19 * published by the Free Software Foundation; either version 2 of the
20 * License, or (at your option) any later version.
22 * The author(s) of this software shall not be held liable for damages
23 * of any nature resulting due to the use of this software. This
24 * software is provided AS-IS with no warranties.
27 #include <linux/module.h>
28 #include <linux/moduleparam.h>
29 #include <linux/init.h>
30 #include <linux/miscdevice.h>
31 #include <linux/watchdog.h>
32 #include <linux/notifier.h>
33 #include <linux/reboot.h>
35 #include <linux/pci.h>
36 #include <linux/spinlock.h>
38 #include <asm/uaccess.h>
41 #define NAME "it8712f_wdt"
43 MODULE_AUTHOR("Jorge Boncompte - DTI2 <jorge@dti2.net>");
44 MODULE_DESCRIPTION("IT8712F Watchdog Driver");
45 MODULE_LICENSE("GPL");
46 MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR
);
48 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
50 static int max_units
= 255;
51 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
52 static int margin
= 60; /* in seconds */
53 module_param(margin
, int, 0);
54 MODULE_PARM_DESC(margin
, "Watchdog margin in seconds");
56 static int nowayout
= WATCHDOG_NOWAYOUT
;
57 module_param(nowayout
, int, 0);
58 MODULE_PARM_DESC(nowayout
, "Disable watchdog shutdown on close");
60 static struct semaphore it8712f_wdt_sem
;
61 static unsigned expect_close
;
62 static spinlock_t io_lock
;
63 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
65 static unsigned char revision
;
66 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
68 /* Dog Food address - We use the game port address */
69 static unsigned short address
;
71 #define REG 0x2e /* The register to read/write */
72 #define VAL 0x2f /* The value to read/write */
74 #define LDN 0x07 /* Register: Logical device select */
75 #define DEVID 0x20 /* Register: Device ID */
76 #define DEVREV 0x22 /* Register: Device Revision */
77 #define ACT_REG 0x30 /* LDN Register: Activation */
78 #define BASE_REG 0x60 /* LDN Register: Base address */
80 #define IT8712F_DEVID 0x8712
82 #define LDN_GPIO 0x07 /* GPIO and Watch Dog Timer */
83 #define LDN_GAME 0x09 /* Game Port */
85 #define WDT_CONTROL 0x71 /* WDT Register: Control */
86 #define WDT_CONFIG 0x72 /* WDT Register: Configuration */
87 #define WDT_TIMEOUT 0x73 /* WDT Register: Timeout Value */
89 #define WDT_RESET_GAME 0x10
90 #define WDT_RESET_KBD 0x20
91 #define WDT_RESET_MOUSE 0x40
92 #define WDT_RESET_CIR 0x80
94 #define WDT_UNIT_SEC 0x80 /* If 0 in MINUTES */
96 #define WDT_OUT_PWROK 0x10
97 #define WDT_OUT_KRST 0x40
107 superio_outb(int val
, int reg
)
124 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
127 superio_outw(int val
, int reg
)
130 outb((val
>> 8) & 0xff, VAL
);
132 outb(val
& 0xff, VAL
);
135 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
137 superio_select(int ldn
)
158 spin_unlock(&io_lock
);
162 it8712f_wdt_ping(void)
168 it8712f_wdt_update_margin(void)
170 int config
= WDT_OUT_KRST
| WDT_OUT_PWROK
;
171 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
173 printk(KERN_INFO NAME
": timer margin %d seconds\n", margin
);
175 /* The timeout register only has 8bits wide */
177 config
|= WDT_UNIT_SEC
; /* else UNIT are MINUTES */
181 /* Switch to minutes precision if the configured margin
182 * value does not fit within the register width.
184 if (units
<= max_units
) {
185 config
|= WDT_UNIT_SEC
; /* else UNIT is MINUTES */
186 printk(KERN_INFO NAME
": timer margin %d seconds\n", units
);
189 printk(KERN_INFO NAME
": timer margin %d minutes\n", units
);
191 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
192 superio_outb(config
, WDT_CONFIG
);
194 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
195 superio_outb((margin
> 255) ? (margin
/ 60) : margin
, WDT_TIMEOUT
);
197 if (revision
>= 0x08)
198 superio_outw(units
, WDT_TIMEOUT
);
200 superio_outb(units
, WDT_TIMEOUT
);
204 it8712f_wdt_get_status(void)
206 if (superio_inb(WDT_CONTROL
) & 0x01)
207 return WDIOF_CARDRESET
;
210 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
214 it8712f_wdt_enable(void)
216 printk(KERN_DEBUG NAME
": enabling watchdog timer\n");
218 superio_select(LDN_GPIO
);
220 superio_outb(WDT_RESET_GAME
, WDT_CONTROL
);
222 it8712f_wdt_update_margin();
230 it8712f_wdt_disable(void)
232 printk(KERN_DEBUG NAME
": disabling watchdog timer\n");
235 superio_select(LDN_GPIO
);
237 superio_outb(0, WDT_CONFIG
);
238 superio_outb(0, WDT_CONTROL
);
239 superio_outb(0, WDT_TIMEOUT
);
245 it8712f_wdt_notify(struct notifier_block
*this,
246 unsigned long code
, void *unused
)
248 if (code
== SYS_HALT
|| code
== SYS_POWER_OFF
)
250 it8712f_wdt_disable();
255 static struct notifier_block it8712f_wdt_notifier
= {
256 .notifier_call
= it8712f_wdt_notify
,
260 it8712f_wdt_write(struct file
*file
, const char __user
*data
,
261 size_t len
, loff_t
*ppos
)
263 /* check for a magic close character */
270 for (i
= 0; i
< len
; ++i
) {
272 if (get_user(c
, data
+i
))
283 it8712f_wdt_ioctl(struct inode
*inode
, struct file
*file
,
284 unsigned int cmd
, unsigned long arg
)
286 void __user
*argp
= (void __user
*)arg
;
287 int __user
*p
= argp
;
288 static struct watchdog_info ident
= {
289 .identity
= "IT8712F Watchdog",
290 .firmware_version
= 1,
291 .options
= WDIOF_SETTIMEOUT
| WDIOF_KEEPALIVEPING
,
293 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
297 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
302 case WDIOC_GETSUPPORT
:
303 if (copy_to_user(argp
, &ident
, sizeof(ident
)))
306 case WDIOC_GETSTATUS
:
307 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
310 superio_select(LDN_GPIO
);
312 value
= it8712f_wdt_get_status();
316 return put_user(value
, p
);
317 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
318 case WDIOC_GETBOOTSTATUS
:
319 return put_user(0, p
);
320 case WDIOC_KEEPALIVE
:
323 case WDIOC_SETTIMEOUT
:
324 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
325 if (get_user(new_margin
, p
))
327 if (get_user(value
, p
))
328 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
330 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
335 if (value
> (max_units
* 60))
336 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
338 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
342 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
344 superio_select(LDN_GPIO
);
346 it8712f_wdt_update_margin();
350 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
353 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
354 case WDIOC_GETTIMEOUT
:
355 if (put_user(margin
, p
))
362 it8712f_wdt_open(struct inode
*inode
, struct file
*file
)
364 /* only allow one at a time */
365 if (down_trylock(&it8712f_wdt_sem
))
367 it8712f_wdt_enable();
369 return nonseekable_open(inode
, file
);
373 it8712f_wdt_release(struct inode
*inode
, struct file
*file
)
375 if (expect_close
!= 42) {
376 printk(KERN_WARNING NAME
377 ": watchdog device closed unexpectedly, will not"
378 " disable the watchdog timer\n");
379 } else if (!nowayout
) {
380 it8712f_wdt_disable();
383 up(&it8712f_wdt_sem
);
388 static const struct file_operations it8712f_wdt_fops
= {
389 .owner
= THIS_MODULE
,
391 .write
= it8712f_wdt_write
,
392 .ioctl
= it8712f_wdt_ioctl
,
393 .open
= it8712f_wdt_open
,
394 .release
= it8712f_wdt_release
,
397 static struct miscdevice it8712f_wdt_miscdev
= {
398 .minor
= WATCHDOG_MINOR
,
400 .fops
= &it8712f_wdt_fops
,
404 it8712f_wdt_find(unsigned short *address
)
410 chip_type
= superio_inw(DEVID
);
411 if (chip_type
!= IT8712F_DEVID
)
414 superio_select(LDN_GAME
);
415 superio_outb(1, ACT_REG
);
416 if (!(superio_inb(ACT_REG
) & 0x01)) {
417 printk(KERN_ERR NAME
": Device not activated, skipping\n");
421 *address
= superio_inw(BASE_REG
);
423 printk(KERN_ERR NAME
": Base address not set, skipping\n");
428 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
429 printk(KERN_DEBUG NAME
": Found IT%04xF chip revision %d - "
431 revision
= superio_inb(DEVREV
) & 0x0f;
433 /* Later revisions have 16-bit values per datasheet 0.9.1 */
434 if (revision
>= 0x08)
437 if (margin
> (max_units
* 60))
438 margin
= (max_units
* 60);
440 printk(KERN_INFO NAME
": Found IT%04xF chip revision %d - "
441 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
442 "using DogFood address 0x%x\n",
443 <<<<<<< HEAD
:drivers
/watchdog
/it8712f_wdt
.c
444 chip_type
, superio_inb(DEVREV
) & 0x0f, *address
);
446 chip_type
, revision
, *address
);
447 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:drivers
/watchdog
/it8712f_wdt
.c
455 it8712f_wdt_init(void)
459 spin_lock_init(&io_lock
);
461 if (it8712f_wdt_find(&address
))
464 if (!request_region(address
, 1, "IT8712F Watchdog")) {
465 printk(KERN_WARNING NAME
": watchdog I/O region busy\n");
469 it8712f_wdt_disable();
471 sema_init(&it8712f_wdt_sem
, 1);
473 err
= register_reboot_notifier(&it8712f_wdt_notifier
);
475 printk(KERN_ERR NAME
": unable to register reboot notifier\n");
479 err
= misc_register(&it8712f_wdt_miscdev
);
482 ": cannot register miscdev on minor=%d (err=%d)\n",
483 WATCHDOG_MINOR
, err
);
491 unregister_reboot_notifier(&it8712f_wdt_notifier
);
493 release_region(address
, 1);
498 it8712f_wdt_exit(void)
500 misc_deregister(&it8712f_wdt_miscdev
);
501 unregister_reboot_notifier(&it8712f_wdt_notifier
);
502 release_region(address
, 1);
505 module_init(it8712f_wdt_init
);
506 module_exit(it8712f_wdt_exit
);