55 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
57 #include <linux/module.h>
59 #include <linux/types.h>
62 #include <linux/watchdog.h>
66 #include <linux/reboot.h>
83 #define WDT_INTERVAL (HZ/4+1)
91 #define WATCHDOG_TIMEOUT 30
96 "Watchdog timeout in seconds. (1 <= timeout <= 3600, default="
102 "Watchdog cannot be stopped once started (default="
108 #define MMCR_BASE 0xfffef000
109 #define OFFS_WDTMRCTL 0xCB0
112 #define WDT_EXP_SEL_01 0x0001
113 #define WDT_EXP_SEL_02 0x0002
114 #define WDT_EXP_SEL_03 0x0004
115 #define WDT_EXP_SEL_04 0x0008
116 #define WDT_EXP_SEL_05 0x0010
117 #define WDT_EXP_SEL_06 0x0020
118 #define WDT_EXP_SEL_07 0x0040
119 #define WDT_EXP_SEL_08 0x0080
120 #define WDT_IRQ_FLG 0x1000
121 #define WDT_WRST_ENB 0x4000
122 #define WDT_ENB 0x8000
126 static void wdt_timer_ping(
unsigned long);
129 static unsigned long wdt_is_open;
130 static char wdt_expect_close;
137 static void wdt_timer_ping(
unsigned long data)
144 spin_lock(&wdt_spinlock);
147 spin_unlock(&wdt_spinlock);
152 pr_warn(
"Heartbeat lost! Will not ping the watchdog\n");
159 static void wdt_config(
int writeval)
166 dummy =
readw(wdtmrctl);
173 writew(writeval, wdtmrctl);
174 spin_unlock_irqrestore(&wdt_spinlock, flags);
177 static int wdt_startup(
void)
187 pr_info(
"Watchdog timer is now enabled\n");
191 static int wdt_turnoff(
void)
199 pr_info(
"Watchdog timer is now disabled...\n");
203 static int wdt_keepalive(
void)
210 static int wdt_set_heartbeat(
int t)
212 if ((t < 1) || (t > 3600))
224 size_t count, loff_t *ppos)
233 wdt_expect_close = 0;
236 for (ofs = 0; ofs !=
count; ofs++) {
241 wdt_expect_close = 42;
252 static int fop_open(
struct inode *
inode,
struct file *file)
265 static int fop_close(
struct inode *inode,
struct file *file)
267 if (wdt_expect_close == 42)
270 pr_crit(
"Unexpected close, not stopping watchdog!\n");
274 wdt_expect_close = 0;
278 static long fop_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
285 .firmware_version = 1,
324 if (wdt_set_heartbeat(new_timeout))
342 .release = fop_close,
343 .unlocked_ioctl = fop_ioctl,
370 .notifier_call = wdt_notify_sys,
373 static void __exit sc520_wdt_unload(
void)
384 static int __init sc520_wdt_init(
void)
390 if (wdt_set_heartbeat(timeout)) {
392 pr_info(
"timeout value must be 1 <= timeout <= 3600, using %d\n",
398 pr_err(
"Unable to remap memory\n");
400 goto err_out_region2;
405 pr_err(
"cannot register reboot notifier (err=%d)\n", rc);
406 goto err_out_ioremap;
411 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
413 goto err_out_notifier;
416 pr_info(
"WDT driver for SC520 initialised. timeout=%d sec (nowayout=%d)\n",
434 "Driver for watchdog timer in AMD \"Elan\" SC520 uProcessor");