aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/watchdog/acquirewdt.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/watchdog/acquirewdt.c')
-rw-r--r--drivers/char/watchdog/acquirewdt.c155
1 files changed, 88 insertions, 67 deletions
diff --git a/drivers/char/watchdog/acquirewdt.c b/drivers/char/watchdog/acquirewdt.c
index 154d67e591e5..85269c365a10 100644
--- a/drivers/char/watchdog/acquirewdt.c
+++ b/drivers/char/watchdog/acquirewdt.c
@@ -48,46 +48,52 @@
48 * It can be 1, 2, 10, 20, 110 or 220 seconds. 48 * It can be 1, 2, 10, 20, 110 or 220 seconds.
49 */ 49 */
50 50
51#include <linux/module.h> 51/*
52#include <linux/moduleparam.h> 52 * Includes, defines, variables, module parameters, ...
53#include <linux/types.h> 53 */
54#include <linux/miscdevice.h>
55#include <linux/watchdog.h>
56#include <linux/fs.h>
57#include <linux/ioport.h>
58#include <linux/notifier.h>
59#include <linux/reboot.h>
60#include <linux/init.h>
61
62#include <asm/io.h>
63#include <asm/uaccess.h>
64#include <asm/system.h>
65 54
55/* Includes */
56#include <linux/module.h> /* For module specific items */
57#include <linux/moduleparam.h> /* For new moduleparam's */
58#include <linux/types.h> /* For standard types (like size_t) */
59#include <linux/errno.h> /* For the -ENODEV/... values */
60#include <linux/kernel.h> /* For printk/panic/... */
61#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR) */
62#include <linux/watchdog.h> /* For the watchdog specific items */
63#include <linux/fs.h> /* For file operations */
64#include <linux/ioport.h> /* For io-port access */
65#include <linux/platform_device.h> /* For platform_driver framework */
66#include <linux/init.h> /* For __init/__exit/... */
67
68#include <asm/uaccess.h> /* For copy_to_user/put_user/... */
69#include <asm/io.h> /* For inb/outb/... */
70
71/* Module information */
72#define DRV_NAME "acquirewdt"
73#define PFX DRV_NAME ": "
66#define WATCHDOG_NAME "Acquire WDT" 74#define WATCHDOG_NAME "Acquire WDT"
67#define PFX WATCHDOG_NAME ": "
68#define WATCHDOG_HEARTBEAT 0 /* There is no way to see what the correct time-out period is */ 75#define WATCHDOG_HEARTBEAT 0 /* There is no way to see what the correct time-out period is */
69 76
77/* internal variables */
78static struct platform_device *acq_platform_device; /* the watchdog platform device */
70static unsigned long acq_is_open; 79static unsigned long acq_is_open;
71static char expect_close; 80static char expect_close;
72 81
73/* 82/* module parameters */
74 * You must set these - there is no sane way to probe for this board. 83static int wdt_stop = 0x43; /* You must set this - there is no sane way to probe for this board. */
75 */
76
77static int wdt_stop = 0x43;
78module_param(wdt_stop, int, 0); 84module_param(wdt_stop, int, 0);
79MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)"); 85MODULE_PARM_DESC(wdt_stop, "Acquire WDT 'stop' io port (default 0x43)");
80 86
81static int wdt_start = 0x443; 87static int wdt_start = 0x443; /* You must set this - there is no sane way to probe for this board. */
82module_param(wdt_start, int, 0); 88module_param(wdt_start, int, 0);
83MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)"); 89MODULE_PARM_DESC(wdt_start, "Acquire WDT 'start' io port (default 0x443)");
84 90
85static int nowayout = WATCHDOG_NOWAYOUT; 91static int nowayout = WATCHDOG_NOWAYOUT;
86module_param(nowayout, int, 0); 92module_param(nowayout, int, 0);
87MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); 93MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
88 94
89/* 95/*
90 * Kernel methods. 96 * Watchdog Operations
91 */ 97 */
92 98
93static void acq_keepalive(void) 99static void acq_keepalive(void)
@@ -103,7 +109,7 @@ static void acq_stop(void)
103} 109}
104 110
105/* 111/*
106 * /dev/watchdog handling. 112 * /dev/watchdog handling
107 */ 113 */
108 114
109static ssize_t acq_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) 115static ssize_t acq_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
@@ -143,7 +149,7 @@ static int acq_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
143 { 149 {
144 .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE, 150 .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
145 .firmware_version = 1, 151 .firmware_version = 1,
146 .identity = "Acquire WDT", 152 .identity = WATCHDOG_NAME,
147 }; 153 };
148 154
149 switch(cmd) 155 switch(cmd)
@@ -214,20 +220,6 @@ static int acq_close(struct inode *inode, struct file *file)
214} 220}
215 221
216/* 222/*
217 * Notifier for system down
218 */
219
220static int acq_notify_sys(struct notifier_block *this, unsigned long code,
221 void *unused)
222{
223 if(code==SYS_DOWN || code==SYS_HALT) {
224 /* Turn the WDT off */
225 acq_stop();
226 }
227 return NOTIFY_DONE;
228}
229
230/*
231 * Kernel Interfaces 223 * Kernel Interfaces
232 */ 224 */
233 225
@@ -240,29 +232,20 @@ static const struct file_operations acq_fops = {
240 .release = acq_close, 232 .release = acq_close,
241}; 233};
242 234
243static struct miscdevice acq_miscdev= 235static struct miscdevice acq_miscdev = {
244{ 236 .minor = WATCHDOG_MINOR,
245 .minor = WATCHDOG_MINOR, 237 .name = "watchdog",
246 .name = "watchdog", 238 .fops = &acq_fops,
247 .fops = &acq_fops,
248}; 239};
249 240
250/* 241/*
251 * The WDT card needs to learn about soft shutdowns in order to 242 * Init & exit routines
252 * turn the timebomb registers off.
253 */ 243 */
254 244
255static struct notifier_block acq_notifier = 245static int __devinit acq_probe(struct platform_device *dev)
256{
257 .notifier_call = acq_notify_sys,
258};
259
260static int __init acq_init(void)
261{ 246{
262 int ret; 247 int ret;
263 248
264 printk(KERN_INFO "WDT driver for Acquire single board computer initialising.\n");
265
266 if (wdt_stop != wdt_start) { 249 if (wdt_stop != wdt_start) {
267 if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) { 250 if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) {
268 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", 251 printk (KERN_ERR PFX "I/O address 0x%04x already in use\n",
@@ -279,18 +262,11 @@ static int __init acq_init(void)
279 goto unreg_stop; 262 goto unreg_stop;
280 } 263 }
281 264
282 ret = register_reboot_notifier(&acq_notifier);
283 if (ret != 0) {
284 printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n",
285 ret);
286 goto unreg_regions;
287 }
288
289 ret = misc_register(&acq_miscdev); 265 ret = misc_register(&acq_miscdev);
290 if (ret != 0) { 266 if (ret != 0) {
291 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", 267 printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n",
292 WATCHDOG_MINOR, ret); 268 WATCHDOG_MINOR, ret);
293 goto unreg_reboot; 269 goto unreg_regions;
294 } 270 }
295 271
296 printk (KERN_INFO PFX "initialized. (nowayout=%d)\n", 272 printk (KERN_INFO PFX "initialized. (nowayout=%d)\n",
@@ -298,8 +274,6 @@ static int __init acq_init(void)
298 274
299 return 0; 275 return 0;
300 276
301unreg_reboot:
302 unregister_reboot_notifier(&acq_notifier);
303unreg_regions: 277unreg_regions:
304 release_region(wdt_start, 1); 278 release_region(wdt_start, 1);
305unreg_stop: 279unreg_stop:
@@ -309,13 +283,60 @@ out:
309 return ret; 283 return ret;
310} 284}
311 285
312static void __exit acq_exit(void) 286static int __devexit acq_remove(struct platform_device *dev)
313{ 287{
314 misc_deregister(&acq_miscdev); 288 misc_deregister(&acq_miscdev);
315 unregister_reboot_notifier(&acq_notifier); 289 release_region(wdt_start,1);
316 if(wdt_stop != wdt_start) 290 if(wdt_stop != wdt_start)
317 release_region(wdt_stop,1); 291 release_region(wdt_stop,1);
318 release_region(wdt_start,1); 292
293 return 0;
294}
295
296static void acq_shutdown(struct platform_device *dev)
297{
298 /* Turn the WDT off if we have a soft shutdown */
299 acq_stop();
300}
301
302static struct platform_driver acquirewdt_driver = {
303 .probe = acq_probe,
304 .remove = __devexit_p(acq_remove),
305 .shutdown = acq_shutdown,
306 .driver = {
307 .owner = THIS_MODULE,
308 .name = DRV_NAME,
309 },
310};
311
312static int __init acq_init(void)
313{
314 int err;
315
316 printk(KERN_INFO "WDT driver for Acquire single board computer initialising.\n");
317
318 err = platform_driver_register(&acquirewdt_driver);
319 if (err)
320 return err;
321
322 acq_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0);
323 if (IS_ERR(acq_platform_device)) {
324 err = PTR_ERR(acq_platform_device);
325 goto unreg_platform_driver;
326 }
327
328 return 0;
329
330unreg_platform_driver:
331 platform_driver_unregister(&acquirewdt_driver);
332 return err;
333}
334
335static void __exit acq_exit(void)
336{
337 platform_device_unregister(acq_platform_device);
338 platform_driver_unregister(&acquirewdt_driver);
339 printk(KERN_INFO PFX "Watchdog Module Unloaded.\n");
319} 340}
320 341
321module_init(acq_init); 342module_init(acq_init);