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 = 0;
36 static int access = 0;
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);
81 printk(KERN_INFO NAME ": enabling watchdog timer\n");
86 static int wdt_release(struct inode *inode, struct file *file)
90 * Lock it in if it's a module and we set nowayout
92 if (expect_close && (nowayout == 0)) {
94 printk(KERN_INFO NAME ": disabling watchdog timer\n");
95 module_put(THIS_MODULE);
97 printk(KERN_CRIT NAME ": device closed unexpectedly. WDT will not stop!\n");
103 static ssize_t wdt_write(struct file *file, const char *data, size_t len, loff_t *ppos)
105 /* Refresh the timer. */
110 /* In case it was set long ago */
113 for (i = 0; i != len; i++) {
115 if (get_user(c, data + i))
127 static int wdt_ioctl(struct inode *inode, struct file *file,
128 unsigned int cmd, unsigned long arg)
131 static struct watchdog_info ident = {
132 .options = WDIOF_SETTIMEOUT |
133 WDIOF_KEEPALIVEPING |
135 .firmware_version = 0,
136 .identity = "ADM5120_WDT Watchdog",
141 case WDIOC_GETSUPPORT:
142 if(copy_to_user((struct watchdog_info *)arg, &ident, sizeof(ident)))
145 case WDIOC_GETSTATUS:
146 case WDIOC_GETBOOTSTATUS:
147 return put_user(0,(int *)arg);
148 case WDIOC_KEEPALIVE:
151 case WDIOC_SETTIMEOUT:
152 if (get_user(new_timeout, (int *)arg))
156 if (new_timeout > MAX_TIMEOUT)
158 timeout = new_timeout;
161 case WDIOC_GETTIMEOUT:
162 return put_user(timeout, (int *)arg);
166 static struct file_operations wdt_fops = {
172 release: wdt_release,
175 static struct miscdevice wdt_miscdev = {
176 minor: WATCHDOG_MINOR,
181 static char banner[] __initdata = KERN_INFO NAME ": Watchdog Timer version " VERSION "\n";
183 static int __init watchdog_init(void)
187 ret = misc_register(&wdt_miscdev);
198 static void __exit watchdog_exit(void)
200 misc_deregister(&wdt_miscdev);
203 module_init(watchdog_init);
204 module_exit(watchdog_exit);