diff options
Diffstat (limited to 'drivers/char/watchdog/ib700wdt.c')
-rw-r--r-- | drivers/char/watchdog/ib700wdt.c | 192 |
1 files changed, 127 insertions, 65 deletions
diff --git a/drivers/char/watchdog/ib700wdt.c b/drivers/char/watchdog/ib700wdt.c index c1ed209a138c..c3a60f52ccb9 100644 --- a/drivers/char/watchdog/ib700wdt.c +++ b/drivers/char/watchdog/ib700wdt.c | |||
@@ -3,8 +3,8 @@ | |||
3 | * | 3 | * |
4 | * (c) Copyright 2001 Charles Howes <chowes@vsol.net> | 4 | * (c) Copyright 2001 Charles Howes <chowes@vsol.net> |
5 | * | 5 | * |
6 | * Based on advantechwdt.c which is based on acquirewdt.c which | 6 | * Based on advantechwdt.c which is based on acquirewdt.c which |
7 | * is based on wdt.c. | 7 | * is based on wdt.c. |
8 | * | 8 | * |
9 | * (c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl> | 9 | * (c) Copyright 2000-2001 Marek Michalkiewicz <marekm@linux.org.pl> |
10 | * | 10 | * |
@@ -25,9 +25,9 @@ | |||
25 | * | 25 | * |
26 | * (c) Copyright 1995 Alan Cox <alan@redhat.com> | 26 | * (c) Copyright 1995 Alan Cox <alan@redhat.com> |
27 | * | 27 | * |
28 | * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com> | 28 | * 14-Dec-2001 Matt Domsch <Matt_Domsch@dell.com> |
29 | * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT | 29 | * Added nowayout module option to override CONFIG_WATCHDOG_NOWAYOUT |
30 | * Added timeout module option to override default | 30 | * Added timeout module option to override default |
31 | * | 31 | * |
32 | */ | 32 | */ |
33 | 33 | ||
@@ -36,22 +36,24 @@ | |||
36 | #include <linux/miscdevice.h> | 36 | #include <linux/miscdevice.h> |
37 | #include <linux/watchdog.h> | 37 | #include <linux/watchdog.h> |
38 | #include <linux/ioport.h> | 38 | #include <linux/ioport.h> |
39 | #include <linux/notifier.h> | ||
40 | #include <linux/fs.h> | 39 | #include <linux/fs.h> |
41 | #include <linux/reboot.h> | ||
42 | #include <linux/init.h> | 40 | #include <linux/init.h> |
43 | #include <linux/spinlock.h> | 41 | #include <linux/spinlock.h> |
44 | #include <linux/moduleparam.h> | 42 | #include <linux/moduleparam.h> |
43 | #include <linux/platform_device.h> | ||
45 | 44 | ||
46 | #include <asm/io.h> | 45 | #include <asm/io.h> |
47 | #include <asm/uaccess.h> | 46 | #include <asm/uaccess.h> |
48 | #include <asm/system.h> | 47 | #include <asm/system.h> |
49 | 48 | ||
49 | static struct platform_device *ibwdt_platform_device; | ||
50 | static unsigned long ibwdt_is_open; | 50 | static unsigned long ibwdt_is_open; |
51 | static spinlock_t ibwdt_lock; | 51 | static spinlock_t ibwdt_lock; |
52 | static char expect_close; | 52 | static char expect_close; |
53 | 53 | ||
54 | #define PFX "ib700wdt: " | 54 | /* Module information */ |
55 | #define DRV_NAME "ib700wdt" | ||
56 | #define PFX DRV_NAME ": " | ||
55 | 57 | ||
56 | /* | 58 | /* |
57 | * | 59 | * |
@@ -118,20 +120,51 @@ static int wd_margin = WD_TIMO; | |||
118 | 120 | ||
119 | static int nowayout = WATCHDOG_NOWAYOUT; | 121 | static int nowayout = WATCHDOG_NOWAYOUT; |
120 | module_param(nowayout, int, 0); | 122 | module_param(nowayout, int, 0); |
121 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); | 123 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); |
122 | 124 | ||
123 | 125 | ||
124 | /* | 126 | /* |
125 | * Kernel methods. | 127 | * Watchdog Operations |
126 | */ | 128 | */ |
127 | 129 | ||
128 | static void | 130 | static void |
129 | ibwdt_ping(void) | 131 | ibwdt_ping(void) |
130 | { | 132 | { |
133 | spin_lock(&ibwdt_lock); | ||
134 | |||
131 | /* Write a watchdog value */ | 135 | /* Write a watchdog value */ |
132 | outb_p(wd_margin, WDT_START); | 136 | outb_p(wd_margin, WDT_START); |
137 | |||
138 | spin_unlock(&ibwdt_lock); | ||
133 | } | 139 | } |
134 | 140 | ||
141 | static void | ||
142 | ibwdt_disable(void) | ||
143 | { | ||
144 | spin_lock(&ibwdt_lock); | ||
145 | outb_p(0, WDT_STOP); | ||
146 | spin_unlock(&ibwdt_lock); | ||
147 | } | ||
148 | |||
149 | static int | ||
150 | ibwdt_set_heartbeat(int t) | ||
151 | { | ||
152 | int i; | ||
153 | |||
154 | if ((t < 0) || (t > 30)) | ||
155 | return -EINVAL; | ||
156 | |||
157 | for (i = 0x0F; i > -1; i--) | ||
158 | if (wd_times[i] > t) | ||
159 | break; | ||
160 | wd_margin = i; | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | /* | ||
165 | * /dev/watchdog handling | ||
166 | */ | ||
167 | |||
135 | static ssize_t | 168 | static ssize_t |
136 | ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) | 169 | ibwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
137 | { | 170 | { |
@@ -159,7 +192,7 @@ static int | |||
159 | ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | 192 | ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, |
160 | unsigned long arg) | 193 | unsigned long arg) |
161 | { | 194 | { |
162 | int i, new_margin; | 195 | int new_margin; |
163 | void __user *argp = (void __user *)arg; | 196 | void __user *argp = (void __user *)arg; |
164 | int __user *p = argp; | 197 | int __user *p = argp; |
165 | 198 | ||
@@ -176,6 +209,7 @@ ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
176 | break; | 209 | break; |
177 | 210 | ||
178 | case WDIOC_GETSTATUS: | 211 | case WDIOC_GETSTATUS: |
212 | case WDIOC_GETBOOTSTATUS: | ||
179 | return put_user(0, p); | 213 | return put_user(0, p); |
180 | 214 | ||
181 | case WDIOC_KEEPALIVE: | 215 | case WDIOC_KEEPALIVE: |
@@ -185,18 +219,33 @@ ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
185 | case WDIOC_SETTIMEOUT: | 219 | case WDIOC_SETTIMEOUT: |
186 | if (get_user(new_margin, p)) | 220 | if (get_user(new_margin, p)) |
187 | return -EFAULT; | 221 | return -EFAULT; |
188 | if ((new_margin < 0) || (new_margin > 30)) | 222 | if (ibwdt_set_heartbeat(new_margin)) |
189 | return -EINVAL; | 223 | return -EINVAL; |
190 | for (i = 0x0F; i > -1; i--) | ||
191 | if (wd_times[i] > new_margin) | ||
192 | break; | ||
193 | wd_margin = i; | ||
194 | ibwdt_ping(); | 224 | ibwdt_ping(); |
195 | /* Fall */ | 225 | /* Fall */ |
196 | 226 | ||
197 | case WDIOC_GETTIMEOUT: | 227 | case WDIOC_GETTIMEOUT: |
198 | return put_user(wd_times[wd_margin], p); | 228 | return put_user(wd_times[wd_margin], p); |
199 | break; | 229 | |
230 | case WDIOC_SETOPTIONS: | ||
231 | { | ||
232 | int options, retval = -EINVAL; | ||
233 | |||
234 | if (get_user(options, p)) | ||
235 | return -EFAULT; | ||
236 | |||
237 | if (options & WDIOS_DISABLECARD) { | ||
238 | ibwdt_disable(); | ||
239 | retval = 0; | ||
240 | } | ||
241 | |||
242 | if (options & WDIOS_ENABLECARD) { | ||
243 | ibwdt_ping(); | ||
244 | retval = 0; | ||
245 | } | ||
246 | |||
247 | return retval; | ||
248 | } | ||
200 | 249 | ||
201 | default: | 250 | default: |
202 | return -ENOTTY; | 251 | return -ENOTTY; |
@@ -207,9 +256,7 @@ ibwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, | |||
207 | static int | 256 | static int |
208 | ibwdt_open(struct inode *inode, struct file *file) | 257 | ibwdt_open(struct inode *inode, struct file *file) |
209 | { | 258 | { |
210 | spin_lock(&ibwdt_lock); | ||
211 | if (test_and_set_bit(0, &ibwdt_is_open)) { | 259 | if (test_and_set_bit(0, &ibwdt_is_open)) { |
212 | spin_unlock(&ibwdt_lock); | ||
213 | return -EBUSY; | 260 | return -EBUSY; |
214 | } | 261 | } |
215 | if (nowayout) | 262 | if (nowayout) |
@@ -217,41 +264,24 @@ ibwdt_open(struct inode *inode, struct file *file) | |||
217 | 264 | ||
218 | /* Activate */ | 265 | /* Activate */ |
219 | ibwdt_ping(); | 266 | ibwdt_ping(); |
220 | spin_unlock(&ibwdt_lock); | ||
221 | return nonseekable_open(inode, file); | 267 | return nonseekable_open(inode, file); |
222 | } | 268 | } |
223 | 269 | ||
224 | static int | 270 | static int |
225 | ibwdt_close(struct inode *inode, struct file *file) | 271 | ibwdt_close(struct inode *inode, struct file *file) |
226 | { | 272 | { |
227 | spin_lock(&ibwdt_lock); | 273 | if (expect_close == 42) { |
228 | if (expect_close == 42) | 274 | ibwdt_disable(); |
229 | outb_p(0, WDT_STOP); | 275 | } else { |
230 | else | ||
231 | printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); | 276 | printk(KERN_CRIT PFX "WDT device closed unexpectedly. WDT will not stop!\n"); |
232 | 277 | ibwdt_ping(); | |
278 | } | ||
233 | clear_bit(0, &ibwdt_is_open); | 279 | clear_bit(0, &ibwdt_is_open); |
234 | expect_close = 0; | 280 | expect_close = 0; |
235 | spin_unlock(&ibwdt_lock); | ||
236 | return 0; | 281 | return 0; |
237 | } | 282 | } |
238 | 283 | ||
239 | /* | 284 | /* |
240 | * Notifier for system down | ||
241 | */ | ||
242 | |||
243 | static int | ||
244 | ibwdt_notify_sys(struct notifier_block *this, unsigned long code, | ||
245 | void *unused) | ||
246 | { | ||
247 | if (code == SYS_DOWN || code == SYS_HALT) { | ||
248 | /* Turn the WDT off */ | ||
249 | outb_p(0, WDT_STOP); | ||
250 | } | ||
251 | return NOTIFY_DONE; | ||
252 | } | ||
253 | |||
254 | /* | ||
255 | * Kernel Interfaces | 285 | * Kernel Interfaces |
256 | */ | 286 | */ |
257 | 287 | ||
@@ -271,26 +301,14 @@ static struct miscdevice ibwdt_miscdev = { | |||
271 | }; | 301 | }; |
272 | 302 | ||
273 | /* | 303 | /* |
274 | * The WDT needs to learn about soft shutdowns in order to | 304 | * Init & exit routines |
275 | * turn the timebomb registers off. | ||
276 | */ | 305 | */ |
277 | 306 | ||
278 | static struct notifier_block ibwdt_notifier = { | 307 | static int __devinit ibwdt_probe(struct platform_device *dev) |
279 | .notifier_call = ibwdt_notify_sys, | ||
280 | }; | ||
281 | |||
282 | static int __init ibwdt_init(void) | ||
283 | { | 308 | { |
284 | int res; | 309 | int res; |
285 | 310 | ||
286 | printk(KERN_INFO PFX "WDT driver for IB700 single board computer initialising.\n"); | ||
287 | |||
288 | spin_lock_init(&ibwdt_lock); | 311 | spin_lock_init(&ibwdt_lock); |
289 | res = misc_register(&ibwdt_miscdev); | ||
290 | if (res) { | ||
291 | printk (KERN_ERR PFX "failed to register misc device\n"); | ||
292 | goto out_nomisc; | ||
293 | } | ||
294 | 312 | ||
295 | #if WDT_START != WDT_STOP | 313 | #if WDT_START != WDT_STOP |
296 | if (!request_region(WDT_STOP, 1, "IB700 WDT")) { | 314 | if (!request_region(WDT_STOP, 1, "IB700 WDT")) { |
@@ -305,34 +323,78 @@ static int __init ibwdt_init(void) | |||
305 | res = -EIO; | 323 | res = -EIO; |
306 | goto out_nostartreg; | 324 | goto out_nostartreg; |
307 | } | 325 | } |
308 | res = register_reboot_notifier(&ibwdt_notifier); | 326 | |
327 | res = misc_register(&ibwdt_miscdev); | ||
309 | if (res) { | 328 | if (res) { |
310 | printk (KERN_ERR PFX "Failed to register reboot notifier.\n"); | 329 | printk (KERN_ERR PFX "failed to register misc device\n"); |
311 | goto out_noreboot; | 330 | goto out_nomisc; |
312 | } | 331 | } |
313 | return 0; | 332 | return 0; |
314 | 333 | ||
315 | out_noreboot: | 334 | out_nomisc: |
316 | release_region(WDT_START, 1); | 335 | release_region(WDT_START, 1); |
317 | out_nostartreg: | 336 | out_nostartreg: |
318 | #if WDT_START != WDT_STOP | 337 | #if WDT_START != WDT_STOP |
319 | release_region(WDT_STOP, 1); | 338 | release_region(WDT_STOP, 1); |
320 | #endif | 339 | #endif |
321 | out_nostopreg: | 340 | out_nostopreg: |
322 | misc_deregister(&ibwdt_miscdev); | ||
323 | out_nomisc: | ||
324 | return res; | 341 | return res; |
325 | } | 342 | } |
326 | 343 | ||
327 | static void __exit | 344 | static int __devexit ibwdt_remove(struct platform_device *dev) |
328 | ibwdt_exit(void) | ||
329 | { | 345 | { |
330 | misc_deregister(&ibwdt_miscdev); | 346 | misc_deregister(&ibwdt_miscdev); |
331 | unregister_reboot_notifier(&ibwdt_notifier); | 347 | release_region(WDT_START,1); |
332 | #if WDT_START != WDT_STOP | 348 | #if WDT_START != WDT_STOP |
333 | release_region(WDT_STOP,1); | 349 | release_region(WDT_STOP,1); |
334 | #endif | 350 | #endif |
335 | release_region(WDT_START,1); | 351 | return 0; |
352 | } | ||
353 | |||
354 | static void ibwdt_shutdown(struct platform_device *dev) | ||
355 | { | ||
356 | /* Turn the WDT off if we have a soft shutdown */ | ||
357 | ibwdt_disable(); | ||
358 | } | ||
359 | |||
360 | static struct platform_driver ibwdt_driver = { | ||
361 | .probe = ibwdt_probe, | ||
362 | .remove = __devexit_p(ibwdt_remove), | ||
363 | .shutdown = ibwdt_shutdown, | ||
364 | .driver = { | ||
365 | .owner = THIS_MODULE, | ||
366 | .name = DRV_NAME, | ||
367 | }, | ||
368 | }; | ||
369 | |||
370 | static int __init ibwdt_init(void) | ||
371 | { | ||
372 | int err; | ||
373 | |||
374 | printk(KERN_INFO PFX "WDT driver for IB700 single board computer initialising.\n"); | ||
375 | |||
376 | err = platform_driver_register(&ibwdt_driver); | ||
377 | if (err) | ||
378 | return err; | ||
379 | |||
380 | ibwdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); | ||
381 | if (IS_ERR(ibwdt_platform_device)) { | ||
382 | err = PTR_ERR(ibwdt_platform_device); | ||
383 | goto unreg_platform_driver; | ||
384 | } | ||
385 | |||
386 | return 0; | ||
387 | |||
388 | unreg_platform_driver: | ||
389 | platform_driver_unregister(&ibwdt_driver); | ||
390 | return err; | ||
391 | } | ||
392 | |||
393 | static void __exit ibwdt_exit(void) | ||
394 | { | ||
395 | platform_device_unregister(ibwdt_platform_device); | ||
396 | platform_driver_unregister(&ibwdt_driver); | ||
397 | printk(KERN_INFO PFX "Watchdog Module Unloaded.\n"); | ||
336 | } | 398 | } |
337 | 399 | ||
338 | module_init(ibwdt_init); | 400 | module_init(ibwdt_init); |