2 * ADM5120_WDT 0.01: Infineon ADM5120 SoC watchdog driver
3 * Copyright (c) Ondrej Zajicek <santiago@crfreenet.org>, 2007
7 * RC32434_WDT 0.01: IDT Interprise 79RC32434 watchdog driver
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
15 #include <linux/module.h>
16 #include <linux/types.h>
18 #include <linux/miscdevice.h>
19 #include <linux/watchdog.h>
20 #include <linux/irq.h>
22 #include <asm/bootinfo.h>
24 #include <asm/mach-adm5120/adm5120_info.h>
25 #include <asm/mach-adm5120/adm5120_defs.h>
26 #include <asm/mach-adm5120/adm5120_switch.h>
28 #define DEFAULT_TIMEOUT 15 /* (secs) Default is 15 seconds */
29 #define MAX_TIMEOUT 327
30 /* Max is 327 seconds, counter is 15-bit integer, step is 10 ms */
32 #define NAME "adm5120_wdt"
35 static int expect_close;
37 static unsigned int timeout = DEFAULT_TIMEOUT;
39 static int nowayout = WATCHDOG_NOWAYOUT;
40 module_param(nowayout, int, 0);
41 MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
42 MODULE_LICENSE("GPL");
45 static inline void wdt_set_timeout(void)
47 u32 val = (1 << 31) | (((timeout * 100) & 0x7FFF) << 16);
48 SW_WRITE_REG(SWITCH_REG_WDOG0, val);
52 It looks like WDOG0-register-write don't modify counter,
53 but WDOG0-register-read resets counter.
56 static inline void wdt_reset_counter(void)
58 SW_READ_REG(SWITCH_REG_WDOG0);
61 static inline void wdt_disable(void)
63 SW_WRITE_REG(SWITCH_REG_WDOG0, 0x7FFF0000);
68 static int wdt_open(struct inode *inode, struct file *file)
70 /* Allow only one person to hold it open */
75 __module_get(THIS_MODULE);
80 printk(KERN_INFO NAME ": enabling watchdog timer\n");
85 static int wdt_release(struct inode *inode, struct file *file)
89 * Lock it in if it's a module and we set nowayout
91 if (expect_close && (nowayout == 0)) {
93 printk(KERN_INFO NAME ": disabling watchdog timer\n");
94 module_put(THIS_MODULE);
96 printk(KERN_CRIT NAME ": device closed unexpectedly. WDT will not stop!\n");
102 static ssize_t wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
104 /* Refresh the timer. */
109 /* In case it was set long ago */
112 for (i = 0; i != len; i++) {
114 if (get_user(c, data + i))
126 static long wdt_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
129 static struct watchdog_info ident = {
130 .options = WDIOF_SETTIMEOUT |
131 WDIOF_KEEPALIVEPING |
133 .firmware_version = 0,
134 .identity = "ADM5120_WDT Watchdog",
139 case WDIOC_GETSUPPORT:
140 if (copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
143 case WDIOC_GETSTATUS:
144 case WDIOC_GETBOOTSTATUS:
145 return put_user(0, (int *)arg);
146 case WDIOC_KEEPALIVE:
149 case WDIOC_SETTIMEOUT:
150 if (get_user(new_timeout, (int *)arg))
154 if (new_timeout > MAX_TIMEOUT)
156 timeout = new_timeout;
159 case WDIOC_GETTIMEOUT:
160 return put_user(timeout, (int *)arg);
164 static const struct file_operations wdt_fops = {
165 .owner = THIS_MODULE,
168 .unlocked_ioctl = wdt_ioctl,
170 .release = wdt_release,
173 static struct miscdevice wdt_miscdev = {
174 .minor = WATCHDOG_MINOR,
179 static char banner[] __initdata = KERN_INFO NAME ": Watchdog Timer version " VERSION "\n";
181 static int __init watchdog_init(void)
185 ret = misc_register(&wdt_miscdev);
196 static void __exit watchdog_exit(void)
198 misc_deregister(&wdt_miscdev);
201 module_init(watchdog_init);
202 module_exit(watchdog_exit);