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.
16 #include <linux/module.h>
17 #include <linux/types.h>
19 #include <linux/miscdevice.h>
20 #include <linux/watchdog.h>
22 #include <asm/bootinfo.h>
24 #include <adm5120_info.h>
25 #include <adm5120_defs.h>
26 #include <adm5120_irq.h>
27 #include <adm5120_switch.h>
30 #define DEFAULT_TIMEOUT 15 /* (secs) Default is 15 seconds */
31 #define MAX_TIMEOUT 327
32 /* Max is 327 seconds, counter is 15-bit integer, step is 10 ms */
34 #define NAME "adm5120_wdt"
37 static int expect_close
= 0;
38 static int access
= 0;
39 static unsigned int timeout
= DEFAULT_TIMEOUT
;
41 static int nowayout
= WATCHDOG_NOWAYOUT
;
42 module_param(nowayout
, int, 0);
43 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
44 MODULE_LICENSE("GPL");
47 static inline void wdt_set_timeout(void)
49 u32 val
= (1 << 31) | (((timeout
* 100) & 0x7FFF) << 16);
50 SW_WRITE_REG(SWITCH_REG_WDOG0
, val
);
54 It looks like WDOG0-register-write don't modify counter,
55 but WDOG0-register-read resets counter.
58 static inline void wdt_reset_counter(void)
60 SW_READ_REG(SWITCH_REG_WDOG0
);
63 static inline void wdt_disable(void)
65 SW_WRITE_REG(SWITCH_REG_WDOG0
, 0x7FFF0000);
70 static int wdt_open(struct inode
*inode
, struct file
*file
)
72 /* Allow only one person to hold it open */
77 __module_get(THIS_MODULE
);
83 printk(KERN_INFO NAME
": enabling watchdog timer\n");
88 static int wdt_release(struct inode
*inode
, struct file
*file
)
92 * Lock it in if it's a module and we set nowayout
94 if (expect_close
&& (nowayout
== 0)) {
96 printk(KERN_INFO NAME
": disabling watchdog timer\n");
97 module_put(THIS_MODULE
);
99 printk(KERN_CRIT NAME
": device closed unexpectedly. WDT will not stop!\n");
105 static ssize_t
wdt_write(struct file
*file
, const char *data
, size_t len
, loff_t
*ppos
)
107 /* Refresh the timer. */
112 /* In case it was set long ago */
115 for (i
= 0; i
!= len
; i
++) {
117 if (get_user(c
, data
+ i
))
129 static int wdt_ioctl(struct inode
*inode
, struct file
*file
,
130 unsigned int cmd
, unsigned long arg
)
133 static struct watchdog_info ident
= {
134 .options
= WDIOF_SETTIMEOUT
|
135 WDIOF_KEEPALIVEPING
|
137 .firmware_version
= 0,
138 .identity
= "ADM5120_WDT Watchdog",
143 case WDIOC_GETSUPPORT
:
144 if(copy_to_user((struct watchdog_info
*)arg
, &ident
, sizeof(ident
)))
147 case WDIOC_GETSTATUS
:
148 case WDIOC_GETBOOTSTATUS
:
149 return put_user(0,(int *)arg
);
150 case WDIOC_KEEPALIVE
:
153 case WDIOC_SETTIMEOUT
:
154 if (get_user(new_timeout
, (int *)arg
))
158 if (new_timeout
> MAX_TIMEOUT
)
160 timeout
= new_timeout
;
163 case WDIOC_GETTIMEOUT
:
164 return put_user(timeout
, (int *)arg
);
168 static struct file_operations wdt_fops
= {
174 release
: wdt_release
,
177 static struct miscdevice wdt_miscdev
= {
178 minor
: WATCHDOG_MINOR
,
183 static char banner
[] __initdata
= KERN_INFO NAME
": Watchdog Timer version " VERSION
"\n";
185 static int __init
watchdog_init(void)
189 ret
= misc_register(&wdt_miscdev
);
200 static void __exit
watchdog_exit(void)
202 misc_deregister(&wdt_miscdev
);
205 module_init(watchdog_init
);
206 module_exit(watchdog_exit
);
This page took 0.057477 seconds and 5 git commands to generate.