20 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22 #include <linux/module.h>
24 #include <linux/types.h>
25 #include <linux/errno.h>
26 #include <linux/kernel.h>
30 #include <linux/watchdog.h>
54 #define WTCOMP2SEC(x) (x / idt_cpu_freq)
55 #define SEC2WTCOMP(x) (x * idt_cpu_freq)
60 #define WATCHDOG_TIMEOUT 20
69 MODULE_PARM_DESC(nowayout,
"Watchdog cannot be stopped once started (default="
73 #define SET_BITS(addr, or, nand) \
74 writel((readl(&addr) | or) & ~nand, &addr)
76 static int rc32434_wdt_set(
int new_timeout)
80 if (new_timeout < 0 || new_timeout > max_to) {
81 pr_err(
"timeout value must be between 0 and %d\n", max_to);
85 spin_lock(&rc32434_wdt_device.io_lock);
87 spin_unlock(&rc32434_wdt_device.io_lock);
92 static void rc32434_wdt_start(
void)
96 spin_lock(&rc32434_wdt_device.io_lock);
112 rc32434_wdt_set(timeout);
120 spin_unlock(&rc32434_wdt_device.io_lock);
121 pr_info(
"Started watchdog timer\n");
124 static void rc32434_wdt_stop(
void)
126 spin_lock(&rc32434_wdt_device.io_lock);
131 spin_unlock(&rc32434_wdt_device.io_lock);
132 pr_info(
"Stopped watchdog timer\n");
135 static void rc32434_wdt_ping(
void)
137 spin_lock(&rc32434_wdt_device.io_lock);
139 spin_unlock(&rc32434_wdt_device.io_lock);
156 static int rc32434_wdt_release(
struct inode *inode,
struct file *file)
158 if (expect_close == 42) {
162 pr_crit(
"device closed unexpectedly. WDT will not stop!\n");
169 static ssize_t rc32434_wdt_write(
struct file *file,
const char *
data,
170 size_t len, loff_t *ppos)
179 for (i = 0; i != len; i++) {
193 static long rc32434_wdt_ioctl(
struct file *file,
unsigned int cmd,
203 .identity =
"RC32434_WDT Watchdog",
236 if (rc32434_wdt_set(new_timeout))
251 .write = rc32434_wdt_write,
252 .unlocked_ioctl = rc32434_wdt_ioctl,
253 .open = rc32434_wdt_open,
254 .release = rc32434_wdt_release,
257 static struct miscdevice rc32434_wdt_miscdev = {
260 .fops = &rc32434_wdt_fops,
270 pr_err(
"failed to retrieve resources\n");
276 pr_err(
"failed to remap I/O resources\n");
287 if (rc32434_wdt_set(timeout)) {
289 pr_info(
"timeout value must be between 0 and %d\n",
295 pr_err(
"failed to register watchdog device\n");
299 pr_info(
"Watchdog Timer version " VERSION ", timer margin: %d sec\n",
322 .probe = rc32434_wdt_probe,
324 .shutdown = rc32434_wdt_shutdown,
326 .name =
"rc32434_wdt",