14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 #include <linux/module.h>
19 #include <linux/types.h>
22 #include <linux/watchdog.h>
30 #define stamp(fmt, args...) \
31 pr_debug("%s:%i: " fmt "\n", __func__, __LINE__, ## args)
32 #define stampit() stamp("here i am")
34 #define WATCHDOG_NAME "bfin-wdt"
40 # define bfin_read_WDOG_CTL() bfin_read_WDOGA_CTL()
41 # define bfin_read_WDOG_CNT() bfin_read_WDOGA_CNT()
42 # define bfin_read_WDOG_STAT() bfin_read_WDOGA_STAT()
43 # define bfin_write_WDOG_CTL(x) bfin_write_WDOGA_CTL(x)
44 # define bfin_write_WDOG_CNT(x) bfin_write_WDOGA_CNT(x)
45 # define bfin_write_WDOG_STAT(x) bfin_write_WDOGA_STAT(x)
49 #define WATCHDOG_TIMEOUT 20
54 static unsigned long open_check;
63 static int bfin_wdt_keepalive(
void)
75 static int bfin_wdt_stop(
void)
88 static int bfin_wdt_start(
void)
100 static int bfin_wdt_running(
void)
113 static int bfin_wdt_set_timeout(
unsigned long t)
121 stamp(
"maxtimeout=%us newtimeout=%lus (cnt=%#x)", max_t, t, cnt);
124 pr_warn(
"timeout value is too large\n");
130 int run = bfin_wdt_running();
136 spin_unlock_irqrestore(&bfin_wdt_spinlock, flags);
160 bfin_wdt_keepalive();
173 static int bfin_wdt_release(
struct inode *inode,
struct file *file)
177 if (expect_close == 42)
180 pr_crit(
"Unexpected close, not stopping watchdog!\n");
181 bfin_wdt_keepalive();
197 static ssize_t bfin_wdt_write(
struct file *file,
const char __user *
data,
198 size_t len, loff_t *ppos)
209 for (i = 0; i != len; i++) {
217 bfin_wdt_keepalive();
232 static long bfin_wdt_ioctl(
struct file *file,
233 unsigned int cmd,
unsigned long arg)
242 if (
copy_to_user(argp, &bfin_wdt_info,
sizeof(bfin_wdt_info)))
265 spin_unlock_irqrestore(&bfin_wdt_spinlock, flags);
269 bfin_wdt_keepalive();
276 if (bfin_wdt_set_timeout(new_timeout))
288 static int state_before_suspend;
303 state_before_suspend = bfin_wdt_running();
319 if (state_before_suspend) {
320 bfin_wdt_set_timeout(timeout);
327 # define bfin_wdt_suspend NULL
328 # define bfin_wdt_resume NULL
334 .write = bfin_wdt_write,
335 .unlocked_ioctl = bfin_wdt_ioctl,
336 .open = bfin_wdt_open,
337 .release = bfin_wdt_release,
343 .fops = &bfin_wdt_fops,
347 .identity =
"Blackfin Watchdog",
365 pr_err(
"cannot register miscdev on minor=%d (err=%d)\n",
370 pr_info(
"initialized: timeout=%d sec (nowayout=%d)\n",
403 .probe = bfin_wdt_probe,
405 .shutdown = bfin_wdt_shutdown,
420 static int __init bfin_wdt_init(
void)
427 if (bfin_wdt_set_timeout(timeout))
435 pr_err(
"unable to register driver\n");
439 bfin_wdt_device = platform_device_register_simple(
WATCHDOG_NAME,
441 if (IS_ERR(bfin_wdt_device)) {
442 pr_err(
"unable to register device\n");
444 return PTR_ERR(bfin_wdt_device);
456 static void __exit bfin_wdt_exit(
void)
472 "Watchdog timeout in seconds. (1<=timeout<=((2^32)/SCLK), default="
477 "Watchdog cannot be stopped once started (default="