45 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
47 #include <linux/module.h>
49 #include <linux/types.h>
53 #include <linux/watchdog.h>
57 #include <linux/reboot.h>
62 #define OUR_NAME "w83877f_wdt"
64 #define ENABLE_W83877F_PORT 0x3F0
65 #define ENABLE_W83877F 0x87
66 #define DISABLE_W83877F 0xAA
67 #define WDT_PING 0x443
68 #define WDT_REGISTER 0x14
69 #define WDT_ENABLE 0x9C
70 #define WDT_DISABLE 0x8C
77 #define WDT_INTERVAL (HZ/4+1)
85 #define WATCHDOG_TIMEOUT 30
90 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
97 "Watchdog cannot be stopped once started (default="
100 static void wdt_timer_ping(
unsigned long);
103 static unsigned long wdt_is_open;
104 static char wdt_expect_close;
111 static void wdt_timer_ping(
unsigned long data)
118 spin_lock(&wdt_spinlock);
126 spin_unlock(&wdt_spinlock);
129 pr_warn(
"Heartbeat lost! Will not ping the watchdog\n");
155 spin_unlock_irqrestore(&wdt_spinlock, flags);
158 static void wdt_startup(
void)
167 pr_info(
"Watchdog timer is now enabled\n");
170 static void wdt_turnoff(
void)
177 pr_info(
"Watchdog timer is now disabled...\n");
180 static void wdt_keepalive(
void)
191 size_t count, loff_t *ppos)
200 wdt_expect_close = 0;
204 for (ofs = 0; ofs !=
count; ofs++) {
209 wdt_expect_close = 42;
219 static int fop_open(
struct inode *
inode,
struct file *file)
230 static int fop_close(
struct inode *inode,
struct file *file)
232 if (wdt_expect_close == 42)
236 pr_crit(
"device file closed unexpectedly. Will not stop the WDT!\n");
239 wdt_expect_close = 0;
243 static long fop_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
250 .firmware_version = 1,
251 .identity =
"W83877F",
290 if (new_timeout < 1 || new_timeout > 3600)
309 .release = fop_close,
310 .unlocked_ioctl = fop_ioctl,
337 .notifier_call = wdt_notify_sys,
340 static void __exit w83877f_wdt_unload(
void)
352 static int __init w83877f_wdt_init(
void)
356 if (timeout < 1 || timeout > 3600) {
358 pr_info(
"timeout value must be 1 <= x <= 3600, using %d\n",
363 pr_err(
"I/O address 0x%04x already in use\n",
372 goto err_out_region1;
377 pr_err(
"cannot register reboot notifier (err=%d)\n", rc);
378 goto err_out_region2;
383 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
384 wdt_miscdev.
minor, rc);
388 pr_info(
"WDT driver for W83877F initialised. timeout=%d sec (nowayout=%d)\n",