51 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
53 #include <linux/module.h>
55 #include <linux/types.h>
59 #include <linux/watchdog.h>
63 #include <linux/reboot.h>
69 #define OUR_NAME "sbc60xxwdt"
70 #define PFX OUR_NAME ": "
76 static int wdt_stop = 0x45;
80 static int wdt_start = 0x443;
90 #define WDT_INTERVAL (HZ/4+1)
101 #define WATCHDOG_TIMEOUT 30
106 "Watchdog timeout in seconds. (1<=timeout<=3600, default="
112 "Watchdog cannot be stopped once started (default="
115 static void wdt_timer_ping(
unsigned long);
118 static unsigned long wdt_is_open;
119 static char wdt_expect_close;
125 static void wdt_timer_ping(
unsigned long data)
136 pr_warn(
"Heartbeat lost! Will not ping the watchdog\n");
143 static void wdt_startup(
void)
149 pr_info(
"Watchdog timer is now enabled\n");
152 static void wdt_turnoff(
void)
157 pr_info(
"Watchdog timer is now disabled...\n");
160 static void wdt_keepalive(
void)
171 size_t count, loff_t *ppos)
180 wdt_expect_close = 0;
184 for (ofs = 0; ofs !=
count; ofs++) {
189 wdt_expect_close = 42;
200 static int fop_open(
struct inode *
inode,
struct file *file)
214 static int fop_close(
struct inode *inode,
struct file *file)
216 if (wdt_expect_close == 42)
220 pr_crit(
"device file closed unexpectedly. Will not stop the WDT!\n");
223 wdt_expect_close = 0;
227 static long fop_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
234 .firmware_version = 1,
235 .identity =
"SBC60xx",
268 if (new_timeout < 1 || new_timeout > 3600)
287 .release = fop_close,
288 .unlocked_ioctl = fop_ioctl,
315 .notifier_call = wdt_notify_sys,
318 static void __exit sbc60xxwdt_unload(
void)
326 if ((wdt_stop != 0x45) && (wdt_stop != wdt_start))
331 static int __init sbc60xxwdt_init(
void)
335 if (timeout < 1 || timeout > 3600) {
337 pr_info(
"timeout value must be 1 <= x <= 3600, using %d\n",
342 pr_err(
"I/O address 0x%04x already in use\n", wdt_start);
348 if (wdt_stop != 0x45 && wdt_stop != wdt_start) {
350 pr_err(
"I/O address 0x%04x already in use\n", wdt_stop);
352 goto err_out_region1;
358 pr_err(
"cannot register reboot notifier (err=%d)\n", rc);
359 goto err_out_region2;
364 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
365 wdt_miscdev.
minor, rc);
368 pr_info(
"WDT driver for 60XX single board computer initialised. timeout=%d sec (nowayout=%d)\n",
376 if (wdt_stop != 0x45 && wdt_stop != wdt_start)