aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/bcm47xx_wdt.c
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2013-01-12 12:14:07 -0500
committerWim Van Sebroeck <wim@iguana.be>2013-03-01 06:47:13 -0500
commit5434a04db905bb0af281cdb758d1357fbecd0fe8 (patch)
treeb87b6045e6d308a495e70be16564e879061f3bb9 /drivers/watchdog/bcm47xx_wdt.c
parent52e5cc4efa576223174ad4c08a335802a36cb18c (diff)
watchdog: bcm47xx_wdt.c: convert to watchdog core api
Convert the bcm47xx_wdt.c driver to the new watchdog core api. The nowayout parameter is now added unconditionally to the module. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog/bcm47xx_wdt.c')
-rw-r--r--drivers/watchdog/bcm47xx_wdt.c152
1 files changed, 22 insertions, 130 deletions
diff --git a/drivers/watchdog/bcm47xx_wdt.c b/drivers/watchdog/bcm47xx_wdt.c
index bc0e91e78e86..4c520d68397e 100644
--- a/drivers/watchdog/bcm47xx_wdt.c
+++ b/drivers/watchdog/bcm47xx_wdt.c
@@ -14,15 +14,12 @@
14 14
15#include <linux/bitops.h> 15#include <linux/bitops.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/fs.h>
18#include <linux/init.h> 17#include <linux/init.h>
19#include <linux/kernel.h> 18#include <linux/kernel.h>
20#include <linux/miscdevice.h>
21#include <linux/module.h> 19#include <linux/module.h>
22#include <linux/moduleparam.h> 20#include <linux/moduleparam.h>
23#include <linux/reboot.h> 21#include <linux/reboot.h>
24#include <linux/types.h> 22#include <linux/types.h>
25#include <linux/uaccess.h>
26#include <linux/watchdog.h> 23#include <linux/watchdog.h>
27#include <linux/timer.h> 24#include <linux/timer.h>
28#include <linux/jiffies.h> 25#include <linux/jiffies.h>
@@ -41,15 +38,11 @@ module_param(wdt_time, int, 0);
41MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default=" 38MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="
42 __MODULE_STRING(WDT_DEFAULT_TIME) ")"); 39 __MODULE_STRING(WDT_DEFAULT_TIME) ")");
43 40
44#ifdef CONFIG_WATCHDOG_NOWAYOUT
45module_param(nowayout, bool, 0); 41module_param(nowayout, bool, 0);
46MODULE_PARM_DESC(nowayout, 42MODULE_PARM_DESC(nowayout,
47 "Watchdog cannot be stopped once started (default=" 43 "Watchdog cannot be stopped once started (default="
48 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 44 __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
49#endif
50 45
51static unsigned long bcm47xx_wdt_busy;
52static char expect_release;
53static struct timer_list wdt_timer; 46static struct timer_list wdt_timer;
54static atomic_t ticks; 47static atomic_t ticks;
55 48
@@ -97,29 +90,31 @@ static void bcm47xx_timer_tick(unsigned long unused)
97 } 90 }
98} 91}
99 92
100static inline void bcm47xx_wdt_pet(void) 93static int bcm47xx_wdt_keepalive(struct watchdog_device *wdd)
101{ 94{
102 atomic_set(&ticks, wdt_time); 95 atomic_set(&ticks, wdt_time);
96
97 return 0;
103} 98}
104 99
105static void bcm47xx_wdt_start(void) 100static int bcm47xx_wdt_start(struct watchdog_device *wdd)
106{ 101{
107 bcm47xx_wdt_pet(); 102 bcm47xx_wdt_pet();
108 bcm47xx_timer_tick(0); 103 bcm47xx_timer_tick(0);
104
105 return 0;
109} 106}
110 107
111static void bcm47xx_wdt_pause(void) 108static int bcm47xx_wdt_stop(struct watchdog_device *wdd)
112{ 109{
113 del_timer_sync(&wdt_timer); 110 del_timer_sync(&wdt_timer);
114 bcm47xx_wdt_hw_stop(); 111 bcm47xx_wdt_hw_stop();
115}
116 112
117static void bcm47xx_wdt_stop(void) 113 return 0;
118{
119 bcm47xx_wdt_pause();
120} 114}
121 115
122static int bcm47xx_wdt_settimeout(int new_time) 116static int bcm47xx_wdt_set_timeout(struct watchdog_device *wdd,
117 unsigned int new_time)
123{ 118{
124 if ((new_time <= 0) || (new_time > WDT_MAX_TIME)) 119 if ((new_time <= 0) || (new_time > WDT_MAX_TIME))
125 return -EINVAL; 120 return -EINVAL;
@@ -128,51 +123,6 @@ static int bcm47xx_wdt_settimeout(int new_time)
128 return 0; 123 return 0;
129} 124}
130 125
131static int bcm47xx_wdt_open(struct inode *inode, struct file *file)
132{
133 if (test_and_set_bit(0, &bcm47xx_wdt_busy))
134 return -EBUSY;
135
136 bcm47xx_wdt_start();
137 return nonseekable_open(inode, file);
138}
139
140static int bcm47xx_wdt_release(struct inode *inode, struct file *file)
141{
142 if (expect_release == 42) {
143 bcm47xx_wdt_stop();
144 } else {
145 pr_crit("Unexpected close, not stopping watchdog!\n");
146 bcm47xx_wdt_start();
147 }
148
149 clear_bit(0, &bcm47xx_wdt_busy);
150 expect_release = 0;
151 return 0;
152}
153
154static ssize_t bcm47xx_wdt_write(struct file *file, const char __user *data,
155 size_t len, loff_t *ppos)
156{
157 if (len) {
158 if (!nowayout) {
159 size_t i;
160
161 expect_release = 0;
162
163 for (i = 0; i != len; i++) {
164 char c;
165 if (get_user(c, data + i))
166 return -EFAULT;
167 if (c == 'V')
168 expect_release = 42;
169 }
170 }
171 bcm47xx_wdt_pet();
172 }
173 return len;
174}
175
176static const struct watchdog_info bcm47xx_wdt_info = { 126static const struct watchdog_info bcm47xx_wdt_info = {
177 .identity = DRV_NAME, 127 .identity = DRV_NAME,
178 .options = WDIOF_SETTIMEOUT | 128 .options = WDIOF_SETTIMEOUT |
@@ -180,80 +130,25 @@ static const struct watchdog_info bcm47xx_wdt_info = {
180 WDIOF_MAGICCLOSE, 130 WDIOF_MAGICCLOSE,
181}; 131};
182 132
183static long bcm47xx_wdt_ioctl(struct file *file,
184 unsigned int cmd, unsigned long arg)
185{
186 void __user *argp = (void __user *)arg;
187 int __user *p = argp;
188 int new_value, retval = -EINVAL;
189
190 switch (cmd) {
191 case WDIOC_GETSUPPORT:
192 return copy_to_user(argp, &bcm47xx_wdt_info,
193 sizeof(bcm47xx_wdt_info)) ? -EFAULT : 0;
194
195 case WDIOC_GETSTATUS:
196 case WDIOC_GETBOOTSTATUS:
197 return put_user(0, p);
198
199 case WDIOC_SETOPTIONS:
200 if (get_user(new_value, p))
201 return -EFAULT;
202
203 if (new_value & WDIOS_DISABLECARD) {
204 bcm47xx_wdt_stop();
205 retval = 0;
206 }
207
208 if (new_value & WDIOS_ENABLECARD) {
209 bcm47xx_wdt_start();
210 retval = 0;
211 }
212
213 return retval;
214
215 case WDIOC_KEEPALIVE:
216 bcm47xx_wdt_pet();
217 return 0;
218
219 case WDIOC_SETTIMEOUT:
220 if (get_user(new_value, p))
221 return -EFAULT;
222
223 if (bcm47xx_wdt_settimeout(new_value))
224 return -EINVAL;
225
226 bcm47xx_wdt_pet();
227
228 case WDIOC_GETTIMEOUT:
229 return put_user(wdt_time, p);
230
231 default:
232 return -ENOTTY;
233 }
234}
235
236static int bcm47xx_wdt_notify_sys(struct notifier_block *this, 133static int bcm47xx_wdt_notify_sys(struct notifier_block *this,
237 unsigned long code, void *unused) 134 unsigned long code, void *unused)
238{ 135{
239 if (code == SYS_DOWN || code == SYS_HALT) 136 if (code == SYS_DOWN || code == SYS_HALT)
240 bcm47xx_wdt_stop(); 137 bcm47xx_wdt_stop();
241 return NOTIFY_DONE; 138 return NOTIFY_DONE;
242} 139}
243 140
244static const struct file_operations bcm47xx_wdt_fops = { 141static struct watchdog_ops bcm47xx_wdt_ops = {
245 .owner = THIS_MODULE, 142 .owner = THIS_MODULE,
246 .llseek = no_llseek, 143 .start = bcm47xx_wdt_start,
247 .unlocked_ioctl = bcm47xx_wdt_ioctl, 144 .stop = bcm47xx_wdt_stop,
248 .open = bcm47xx_wdt_open, 145 .ping = bcm47xx_wdt_keepalive,
249 .release = bcm47xx_wdt_release, 146 .set_timeout = bcm47xx_wdt_set_timeout,
250 .write = bcm47xx_wdt_write,
251}; 147};
252 148
253static struct miscdevice bcm47xx_wdt_miscdev = { 149static struct watchdog_device bcm47xx_wdt_wdd = {
254 .minor = WATCHDOG_MINOR, 150 .info = &bcm47xx_wdt_info,
255 .name = "watchdog", 151 .ops = &bcm47xx_wdt_ops,
256 .fops = &bcm47xx_wdt_fops,
257}; 152};
258 153
259static struct notifier_block bcm47xx_wdt_notifier = { 154static struct notifier_block bcm47xx_wdt_notifier = {
@@ -274,12 +169,13 @@ static int __init bcm47xx_wdt_init(void)
274 pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n", 169 pr_info("wdt_time value must be 0 < wdt_time < %d, using %d\n",
275 (WDT_MAX_TIME + 1), wdt_time); 170 (WDT_MAX_TIME + 1), wdt_time);
276 } 171 }
172 watchdog_set_nowayout(&bcm47xx_wdt_wdd, nowayout);
277 173
278 ret = register_reboot_notifier(&bcm47xx_wdt_notifier); 174 ret = register_reboot_notifier(&bcm47xx_wdt_notifier);
279 if (ret) 175 if (ret)
280 return ret; 176 return ret;
281 177
282 ret = misc_register(&bcm47xx_wdt_miscdev); 178 ret = watchdog_register_device(&bcm47xx_wdt_wdd);
283 if (ret) { 179 if (ret) {
284 unregister_reboot_notifier(&bcm47xx_wdt_notifier); 180 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
285 return ret; 181 return ret;
@@ -292,10 +188,7 @@ static int __init bcm47xx_wdt_init(void)
292 188
293static void __exit bcm47xx_wdt_exit(void) 189static void __exit bcm47xx_wdt_exit(void)
294{ 190{
295 if (!nowayout) 191 watchdog_unregister_device(&bcm47xx_wdt_wdd);
296 bcm47xx_wdt_stop();
297
298 misc_deregister(&bcm47xx_wdt_miscdev);
299 192
300 unregister_reboot_notifier(&bcm47xx_wdt_notifier); 193 unregister_reboot_notifier(&bcm47xx_wdt_notifier);
301} 194}
@@ -306,4 +199,3 @@ module_exit(bcm47xx_wdt_exit);
306MODULE_AUTHOR("Aleksandar Radovanovic"); 199MODULE_AUTHOR("Aleksandar Radovanovic");
307MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx"); 200MODULE_DESCRIPTION("Watchdog driver for Broadcom BCM47xx");
308MODULE_LICENSE("GPL"); 201MODULE_LICENSE("GPL");
309MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);