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 int wdt_ioctl(struct inode
*inode
, struct file
*file
,
127 unsigned int cmd
, unsigned long arg
)
130 static struct watchdog_info ident
= {
131 .options
= WDIOF_SETTIMEOUT
|
132 WDIOF_KEEPALIVEPING
|
134 .firmware_version
= 0,
135 .identity
= "ADM5120_WDT Watchdog",
140 case WDIOC_GETSUPPORT
:
141 if (copy_to_user((struct watchdog_info
*)arg
, &ident
, sizeof(ident
)))
144 case WDIOC_GETSTATUS
:
145 case WDIOC_GETBOOTSTATUS
:
146 return put_user(0, (int *)arg
);
147 case WDIOC_KEEPALIVE
:
150 case WDIOC_SETTIMEOUT
:
151 if (get_user(new_timeout
, (int *)arg
))
155 if (new_timeout
> MAX_TIMEOUT
)
157 timeout
= new_timeout
;
160 case WDIOC_GETTIMEOUT
:
161 return put_user(timeout
, (int *)arg
);
165 static const struct file_operations wdt_fops
= {
166 .owner
= THIS_MODULE
,
171 .release
= wdt_release
,
174 static struct miscdevice wdt_miscdev
= {
175 .minor
= WATCHDOG_MINOR
,
180 static char banner
[] __initdata
= KERN_INFO NAME
": Watchdog Timer version " VERSION
"\n";
182 static int __init
watchdog_init(void)
186 ret
= misc_register(&wdt_miscdev
);
197 static void __exit
watchdog_exit(void)
199 misc_deregister(&wdt_miscdev
);
202 module_init(watchdog_init
);
203 module_exit(watchdog_exit
);
This page took 0.061775 seconds and 5 git commands to generate.