8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/errno.h>
12 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
18 #include <linux/watchdog.h>
19 #include <linux/reboot.h>
22 #include <linux/bitops.h>
27 #define DRV_NAME "PIKA-WDT"
30 #define WDT_HW_TIMEOUT 2
33 #define WDT_TIMEOUT (HZ/2)
36 #define WDT_HEARTBEAT 15
67 static inline void pikawdt_reset(
void)
81 out_be32(pikawdt_private.fpga + 0x14, reset);
87 static void pikawdt_ping(
unsigned long data)
89 if (
time_before(jiffies, pikawdt_private.next_heartbeat) ||
90 (!nowayout && !pikawdt_private.open)) {
94 pr_crit(
"I will reset your machine !\n");
98 static void pikawdt_keepalive(
void)
103 static void pikawdt_start(
void)
126 static int pikawdt_release(
struct inode *inode,
struct file *file)
129 if (!pikawdt_private.expect_close)
133 pikawdt_private.expect_close = 0;
140 static ssize_t pikawdt_write(
struct file *file,
const char __user *data,
141 size_t len, loff_t *ppos)
150 pikawdt_private.expect_close = 0;
152 for (i = 0; i < len; i++) {
157 pikawdt_private.expect_close = 42;
171 static long pikawdt_ioctl(
struct file *file,
172 unsigned int cmd,
unsigned long arg)
186 return put_user(pikawdt_private.bootstatus, p);
211 .open = pikawdt_open,
212 .release = pikawdt_release,
213 .write = pikawdt_write,
214 .unlocked_ioctl = pikawdt_ioctl,
220 .fops = &pikawdt_fops,
223 static int __init pikawdt_init(
void)
232 pr_err(
"Unable to find fpga\n");
236 pikawdt_private.fpga =
of_iomap(np, 0);
238 if (pikawdt_private.fpga ==
NULL) {
239 pr_err(
"Unable to map fpga\n");
248 pr_err(
"Unable to find fpga-sd\n");
256 pr_err(
"Unable to map fpga-sd\n");
266 if (post1 & 0x80000000)
271 setup_timer(&pikawdt_private.timer, pikawdt_ping, 0);
275 pr_err(
"Unable to register miscdev\n");
279 pr_info(
"initialized. heartbeat=%d sec (nowayout=%d)\n",
288 static void __exit pikawdt_exit(
void)