18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/errno.h>
24 #include <linux/kernel.h>
26 #include <linux/module.h>
29 #include <linux/types.h>
30 #include <linux/watchdog.h>
33 #include <linux/bitops.h>
38 #define DRV_NAME "AT91SAM9 Watchdog"
40 #define wdt_read(field) \
41 __raw_readl(at91wdt_private.base + field)
42 #define wdt_write(field, val) \
43 __raw_writel((val), at91wdt_private.base + field)
49 #define ms_to_ticks(t) (((t << 8) / 1000) - 1)
50 #define ticks_to_ms(t) (((t + 1) * 1000) >> 8)
53 #define WDT_HW_TIMEOUT 2
56 #define WDT_TIMEOUT (HZ/2)
59 #define WDT_HEARTBEAT 15
70 static void at91_ping(
unsigned long data);
86 static inline void at91_wdt_reset(
void)
94 static void at91_ping(
unsigned long data)
96 if (
time_before(jiffies, at91wdt_private.next_heartbeat) ||
97 (!nowayout && !at91wdt_private.open)) {
101 pr_crit(
"I will reset your machine !\n");
121 static int at91_wdt_close(
struct inode *inode,
struct file *file)
126 if (!at91wdt_private.expect_close)
129 at91wdt_private.expect_close = 0;
137 static int at91_wdt_settimeout(
unsigned int timeout)
145 pr_err(
"sorry, watchdog is disabled\n");
174 static long at91_wdt_ioctl(
struct file *file,
175 unsigned int cmd,
unsigned long arg)
184 sizeof(at91_wdt_info)) ? -
EFAULT : 0;
212 static ssize_t at91_wdt_write(
struct file *file,
const char *data,
size_t len,
222 at91wdt_private.expect_close = 0;
224 for (i = 0; i < len; i++) {
229 at91wdt_private.expect_close = 42;
245 .unlocked_ioctl = at91_wdt_ioctl,
246 .open = at91_wdt_open,
247 .release = at91_wdt_close,
248 .write = at91_wdt_write,
254 .fops = &at91wdt_fops,
262 if (at91wdt_miscdev.
parent)
269 at91wdt_private.base =
ioremap(r->
start, resource_size(r));
270 if (!at91wdt_private.base) {
271 dev_err(&pdev->
dev,
"failed to map registers, aborting.\n");
288 pr_info(
"enabled (heartbeat=%d sec, nowayout=%d)\n",
313 static int __init at91sam_wdt_init(
void)
318 static void __exit at91sam_wdt_exit(
void)