2 * RC32434_WDT 0.01: IDT Interprise 79RC32434 watchdog driver
3 * Copyright (c) Ondrej Zajicek <santiago@crfreenet.org>, 2006
7 * SoftDog 0.05: A Software Watchdog Device
9 * (c) Copyright 1996 Alan Cox <alan@redhat.com>, All Rights Reserved.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
23 #include <linux/miscdevice.h>
24 #include <linux/watchdog.h>
25 #include <linux/reboot.h>
26 #include <linux/smp_lock.h>
27 #include <linux/init.h>
28 #include <asm/bootinfo.h>
30 #include <asm/uaccess.h>
31 #include <asm/rc32434/integ.h>
33 #define DEFAULT_TIMEOUT 15 /* (secs) Default is 15 seconds */
34 #define MAX_TIMEOUT 20
36 * (secs) Max is 20 seconds
37 * (max frequency of counter is ~200 MHz, counter is 32-bit unsigned int)
40 #define NAME "rc32434_wdt"
43 static INTEG_t rc_wdt
= (INTEG_t
) INTEG_VirtualAddress
;
45 static int expect_close
= 0;
46 static int access
= 0;
47 static int timeout
= 0;
49 static int nowayout
= WATCHDOG_NOWAYOUT
;
50 module_param(nowayout
, int, 0);
51 MODULE_PARM_DESC(nowayout
, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT
) ")");
52 MODULE_LICENSE("GPL");
55 static inline void start_wdt(void)
57 rc_wdt
-> wtcount
= 0;
58 rc_wdt
-> errcs
|= ERRCS_wre_m
;
59 rc_wdt
-> wtc
|= WTC_en_m
;
62 static inline void stop_wdt(void)
64 rc_wdt
-> wtc
&= ~WTC_en_m
;
65 rc_wdt
-> errcs
&= ~ERRCS_wre_m
;
68 static inline void set_wdt(int new_timeout
)
70 u32 cmp
= new_timeout
* mips_hpt_frequency
;
73 timeout
= new_timeout
;
75 * store and disable WTC
77 state
= rc_wdt
-> wtc
& WTC_en_m
;
78 rc_wdt
-> wtc
&= ~WTC_en_m
;
80 rc_wdt
-> wtcount
= 0;
81 rc_wdt
-> wtcompare
= cmp
;
86 rc_wdt
-> wtc
|= state
;
89 static inline void update_wdt(void)
91 rc_wdt
-> wtcount
= 0;
95 * Allow only one person to hold it open
98 static int wdt_open(struct inode
*inode
, struct file
*file
)
103 __module_get(THIS_MODULE
);
109 printk(KERN_INFO NAME
": enabling watchdog timer\n");
114 static int wdt_release(struct inode
*inode
, struct file
*file
)
117 * Shut off the timer.
118 * Lock it in if it's a module and we set nowayout
120 if (expect_close
&& nowayout
== 0) {
122 printk(KERN_INFO NAME
": disabling watchdog timer\n");
123 module_put(THIS_MODULE
);
125 printk (KERN_CRIT NAME
": device closed unexpectedly. WDT will not stop!\n");
131 static ssize_t
wdt_write(struct file
*file
, const char *data
, size_t len
, loff_t
*ppos
)
140 /* In case it was set long ago */
143 for (i
= 0; i
!= len
; i
++) {
145 if (get_user(c
, data
+ i
))
157 static int wdt_ioctl(struct inode
*inode
, struct file
*file
,
158 unsigned int cmd
, unsigned long arg
)
161 static struct watchdog_info ident
= {
162 .options
= WDIOF_SETTIMEOUT
|
163 WDIOF_KEEPALIVEPING
|
165 .firmware_version
= 0,
166 .identity
= "RC32434_WDT Watchdog",
171 case WDIOC_GETSUPPORT
:
172 if(copy_to_user((struct watchdog_info
*)arg
, &ident
, sizeof(ident
)))
175 case WDIOC_GETSTATUS
:
176 case WDIOC_GETBOOTSTATUS
:
177 return put_user(0,(int *)arg
);
178 case WDIOC_KEEPALIVE
:
181 case WDIOC_SETTIMEOUT
:
182 if (get_user(new_timeout
, (int *)arg
))
186 if (new_timeout
> MAX_TIMEOUT
)
188 set_wdt(new_timeout
);
190 case WDIOC_GETTIMEOUT
:
191 return put_user(timeout
, (int *)arg
);
195 static struct file_operations wdt_fops
= {
201 release
: wdt_release
,
204 static struct miscdevice wdt_miscdev
= {
205 minor
: WATCHDOG_MINOR
,
210 static char banner
[] __initdata
= KERN_INFO NAME
": Watchdog Timer version " VERSION
", timer margin: %d sec\n";
212 static int __init
watchdog_init(void)
217 * There should be check for RC32434 SoC
219 if (mips_machgroup
!= MACH_GROUP_MIKROTIK
) return -1;
221 ret
= misc_register(&wdt_miscdev
);
227 set_wdt(DEFAULT_TIMEOUT
);
229 printk(banner
, timeout
);
234 static void __exit
watchdog_exit(void)
236 misc_deregister(&wdt_miscdev
);
239 module_init(watchdog_init
);
240 module_exit(watchdog_exit
);
This page took 0.058063 seconds and 5 git commands to generate.