28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/module.h>
32 #include <linux/types.h>
34 #include <linux/watchdog.h>
38 #include <linux/reboot.h>
45 #define WATCHDOG_NAME "w83697hf/hg WDT"
46 #define WATCHDOG_TIMEOUT 60
47 #define WATCHDOG_EARLY_DISABLE 1
49 static unsigned long wdt_is_open;
54 static int wdt_io = 0x2e;
57 "w83697hf/hg WDT io port (default 0x2e, 0 = autodetect)");
62 "Watchdog timeout in seconds. 1<= timeout <=255 (default="
68 "Watchdog cannot be stopped once started (default="
74 "Watchdog gets disabled at boot time (default="
81 #define W83697HF_EFER (wdt_io + 0)
82 #define W83697HF_EFIR (wdt_io + 0)
84 #define W83697HF_EFDR (wdt_io + 1)
86 static inline void w83697hf_unlock(
void)
92 static inline void w83697hf_lock(
void)
102 static unsigned char w83697hf_get_reg(
unsigned char reg)
108 static void w83697hf_set_reg(
unsigned char reg,
unsigned char data)
114 static void w83697hf_write_timeout(
int timeout)
117 w83697hf_set_reg(0xF4, timeout);
120 static void w83697hf_select_wdt(
void)
123 w83697hf_set_reg(0x07, 0x08);
126 static inline void w83697hf_deselect_wdt(
void)
131 static void w83697hf_init(
void)
135 w83697hf_select_wdt();
137 bbuf = w83697hf_get_reg(0x29);
142 w83697hf_set_reg(0x29, bbuf);
144 bbuf = w83697hf_get_reg(0xF3);
146 w83697hf_set_reg(0xF3, bbuf);
148 w83697hf_deselect_wdt();
151 static void wdt_ping(
void)
154 w83697hf_select_wdt();
156 w83697hf_write_timeout(timeout);
158 w83697hf_deselect_wdt();
162 static void wdt_enable(
void)
165 w83697hf_select_wdt();
167 w83697hf_write_timeout(timeout);
168 w83697hf_set_reg(0x30, 1);
170 w83697hf_deselect_wdt();
174 static void wdt_disable(
void)
177 w83697hf_select_wdt();
179 w83697hf_set_reg(0x30, 0);
180 w83697hf_write_timeout(0);
182 w83697hf_deselect_wdt();
186 static unsigned char wdt_running(
void)
191 w83697hf_select_wdt();
193 t = w83697hf_get_reg(0xF4);
195 w83697hf_deselect_wdt();
201 static int wdt_set_heartbeat(
int t)
203 if (t < 1 || t > 255)
211 size_t count, loff_t *ppos)
219 for (i = 0; i !=
count; i++) {
232 static long wdt_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
240 .firmware_version = 1,
241 .identity =
"W83697HF WDT",
281 if (wdt_set_heartbeat(new_timeout))
295 static int wdt_open(
struct inode *
inode,
struct file *file)
307 static int wdt_close(
struct inode *inode,
struct file *file)
309 if (expect_close == 42)
312 pr_crit(
"Unexpected close, not stopping watchdog!\n");
341 .unlocked_ioctl = wdt_ioctl,
343 .release = wdt_close,
358 .notifier_call = wdt_notify_sys,
361 static int w83697hf_check_wdt(
void)
364 pr_err(
"I/O address 0x%x already in use\n", wdt_io);
368 pr_debug(
"Looking for watchdog at address 0x%x\n", wdt_io);
370 if (w83697hf_get_reg(0x20) == 0x60) {
371 pr_info(
"watchdog found at address 0x%x\n", wdt_io);
378 pr_info(
"watchdog not found at address 0x%x\n", wdt_io);
383 static int w83697hf_ioports[] = { 0x2e, 0x4e, 0x00 };
387 int ret,
i, found = 0;
389 pr_info(
"WDT driver for W83697HF/HG initializing\n");
393 for (i = 0; ((!found) && (w83697hf_ioports[i] != 0)); i++) {
394 wdt_io = w83697hf_ioports[
i];
395 if (!w83697hf_check_wdt())
399 if (!w83697hf_check_wdt())
404 pr_err(
"No W83697HF/HG could be found\n");
412 pr_warn(
"Stopping previously enabled watchdog until userland kicks in\n");
416 if (wdt_set_heartbeat(timeout)) {
418 pr_info(
"timeout value must be 1 <= timeout <= 255, using %d\n",
424 pr_err(
"cannot register reboot notifier (err=%d)\n", ret);
430 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
435 pr_info(
"initialized. timeout=%d sec (nowayout=%d)\n",
447 static void __exit wdt_exit(
void)