From 1d747be647c2239e39a9b5faa138c1e36222b37e Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Thu, 11 Jan 2007 22:19:28 +0100 Subject: [WATCHDOG] advantechwdt.c - cleanup before platform_device patches This cleanup consists of: - make sure that the printk's use the module/driver-name - do the exit of the module exactly the opposite of the init of the module Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/advantechwdt.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'drivers/char/watchdog/advantechwdt.c') diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c index 9d732769ba0..6c919797591 100644 --- a/drivers/char/watchdog/advantechwdt.c +++ b/drivers/char/watchdog/advantechwdt.c @@ -43,8 +43,9 @@ #include #include +#define DRV_NAME "advantechwdt" +#define PFX DRV_NAME ": " #define WATCHDOG_NAME "Advantech WDT" -#define PFX WATCHDOG_NAME ": " #define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */ static unsigned long advwdt_is_open; @@ -75,10 +76,10 @@ MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds. 1<= timeout <=63, defaul static int nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, int, 0); -MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=CONFIG_WATCHDOG_NOWAYOUT)"); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); /* - * Kernel methods. + * Watchdog Operations */ static void @@ -94,6 +95,10 @@ advwdt_disable(void) inb_p(wdt_stop); } +/* + * /dev/watchdog handling + */ + static ssize_t advwdt_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) { @@ -126,7 +131,7 @@ advwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, static struct watchdog_info ident = { .options = WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE, .firmware_version = 1, - .identity = "Advantech WDT", + .identity = WATCHDOG_NAME, }; switch (cmd) { @@ -237,9 +242,9 @@ static const struct file_operations advwdt_fops = { }; static struct miscdevice advwdt_miscdev = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", - .fops = &advwdt_fops, + .minor = WATCHDOG_MINOR, + .name = "watchdog", + .fops = &advwdt_fops, }; /* @@ -251,6 +256,10 @@ static struct notifier_block advwdt_notifier = { .notifier_call = advwdt_notify_sys, }; +/* + * Init & exit routines + */ + static int __init advwdt_init(void) { @@ -314,9 +323,9 @@ advwdt_exit(void) { misc_deregister(&advwdt_miscdev); unregister_reboot_notifier(&advwdt_notifier); + release_region(wdt_start,1); if(wdt_stop != wdt_start) release_region(wdt_stop,1); - release_region(wdt_start,1); } module_init(advwdt_init); -- cgit v1.2.3 From 0349a363e23a0533e081ca320c837bc08247343e Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Thu, 11 Jan 2007 22:27:51 +0100 Subject: [WATCHDOG] advantechwdt.c - move set_heartbeat to a seperate function Put the set_heartbeat/timeout code into a seperate function Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/advantechwdt.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'drivers/char/watchdog/advantechwdt.c') diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c index 6c919797591..216af0d67fd 100644 --- a/drivers/char/watchdog/advantechwdt.c +++ b/drivers/char/watchdog/advantechwdt.c @@ -95,6 +95,16 @@ advwdt_disable(void) inb_p(wdt_stop); } +static int +advwdt_set_heartbeat(int t) +{ + if ((t < 1) || (t > 63)) + return -EINVAL; + + timeout = t; + return 0; +} + /* * /dev/watchdog handling */ @@ -151,9 +161,8 @@ advwdt_ioctl(struct inode *inode, struct file *file, unsigned int cmd, case WDIOC_SETTIMEOUT: if (get_user(new_timeout, p)) return -EFAULT; - if ((new_timeout < 1) || (new_timeout > 63)) + if (advwdt_set_heartbeat(new_timeout)) return -EINVAL; - timeout = new_timeout; advwdt_ping(); /* Fall */ @@ -267,12 +276,6 @@ advwdt_init(void) printk(KERN_INFO "WDT driver for Advantech single board computer initialising.\n"); - if (timeout < 1 || timeout > 63) { - timeout = WATCHDOG_TIMEOUT; - printk (KERN_INFO PFX "timeout value must be 1<=x<=63, using %d\n", - timeout); - } - if (wdt_stop != wdt_start) { if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) { printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", @@ -289,6 +292,13 @@ advwdt_init(void) goto unreg_stop; } + /* Check that the heartbeat value is within it's range ; if not reset to the default */ + if (advwdt_set_heartbeat(timeout)) { + advwdt_set_heartbeat(WATCHDOG_TIMEOUT); + printk (KERN_INFO PFX "timeout value must be 1<=x<=63, using %d\n", + timeout); + } + ret = register_reboot_notifier(&advwdt_notifier); if (ret != 0) { printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", -- cgit v1.2.3 From c2bd11c7cbba45c3a1d850a8a29855cb4d61654c Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Thu, 11 Jan 2007 22:35:40 +0100 Subject: [WATCHDOG] advantechwdt.c - convert to platform_device Convert the advantechwdt watchdog into a platform_device Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/advantechwdt.c | 55 ++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 6 deletions(-) (limited to 'drivers/char/watchdog/advantechwdt.c') diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c index 216af0d67fd..528a417856c 100644 --- a/drivers/char/watchdog/advantechwdt.c +++ b/drivers/char/watchdog/advantechwdt.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -48,6 +49,7 @@ #define WATCHDOG_NAME "Advantech WDT" #define WATCHDOG_TIMEOUT 60 /* 60 sec default timeout */ +static struct platform_device *advwdt_platform_device; /* the watchdog platform device */ static unsigned long advwdt_is_open; static char adv_expect_close; @@ -269,13 +271,11 @@ static struct notifier_block advwdt_notifier = { * Init & exit routines */ -static int __init -advwdt_init(void) +static int __devinit +advwdt_probe(struct platform_device *dev) { int ret; - printk(KERN_INFO "WDT driver for Advantech single board computer initialising.\n"); - if (wdt_stop != wdt_start) { if (!request_region(wdt_stop, 1, WATCHDOG_NAME)) { printk (KERN_ERR PFX "I/O address 0x%04x already in use\n", @@ -328,14 +328,57 @@ unreg_stop: goto out; } -static void __exit -advwdt_exit(void) +static int __devexit +advwdt_remove(struct platform_device *dev) { misc_deregister(&advwdt_miscdev); unregister_reboot_notifier(&advwdt_notifier); release_region(wdt_start,1); if(wdt_stop != wdt_start) release_region(wdt_stop,1); + + return 0; +} + +static struct platform_driver advwdt_driver = { + .probe = advwdt_probe, + .remove = __devexit_p(advwdt_remove), + .driver = { + .owner = THIS_MODULE, + .name = DRV_NAME, + }, +}; + +static int __init +advwdt_init(void) +{ + int err; + + printk(KERN_INFO "WDT driver for Advantech single board computer initialising.\n"); + + err = platform_driver_register(&advwdt_driver); + if (err) + return err; + + advwdt_platform_device = platform_device_register_simple(DRV_NAME, -1, NULL, 0); + if (IS_ERR(advwdt_platform_device)) { + err = PTR_ERR(advwdt_platform_device); + goto unreg_platform_driver; + } + + return 0; + +unreg_platform_driver: + platform_driver_unregister(&advwdt_driver); + return err; +} + +static void __exit +advwdt_exit(void) +{ + platform_device_unregister(advwdt_platform_device); + platform_driver_unregister(&advwdt_driver); + printk(KERN_INFO PFX "Watchdog Module Unloaded.\n"); } module_init(advwdt_init); -- cgit v1.2.3 From 2e9c9cf44b17ef5fa1f360bc175ed7761daf3428 Mon Sep 17 00:00:00 2001 From: Wim Van Sebroeck Date: Thu, 11 Jan 2007 22:42:41 +0100 Subject: [WATCHDOG] advantechwdt.c - convert to platform_device part 2 Convert the reboot_notifier into the platform_device's shutdown method Signed-off-by: Wim Van Sebroeck --- drivers/char/watchdog/advantechwdt.c | 46 +++++++----------------------------- 1 file changed, 9 insertions(+), 37 deletions(-) (limited to 'drivers/char/watchdog/advantechwdt.c') diff --git a/drivers/char/watchdog/advantechwdt.c b/drivers/char/watchdog/advantechwdt.c index 528a417856c..8121cc24734 100644 --- a/drivers/char/watchdog/advantechwdt.c +++ b/drivers/char/watchdog/advantechwdt.c @@ -35,8 +35,6 @@ #include #include #include -#include -#include #include #include @@ -224,21 +222,6 @@ advwdt_close(struct inode *inode, struct file *file) return 0; } -/* - * Notifier for system down - */ - -static int -advwdt_notify_sys(struct notifier_block *this, unsigned long code, - void *unused) -{ - if (code == SYS_DOWN || code == SYS_HALT) { - /* Turn the WDT off */ - advwdt_disable(); - } - return NOTIFY_DONE; -} - /* * Kernel Interfaces */ @@ -258,15 +241,6 @@ static struct miscdevice advwdt_miscdev = { .fops = &advwdt_fops, }; -/* - * The WDT needs to learn about soft shutdowns in order to - * turn the timebomb registers off. - */ - -static struct notifier_block advwdt_notifier = { - .notifier_call = advwdt_notify_sys, -}; - /* * Init & exit routines */ @@ -299,18 +273,11 @@ advwdt_probe(struct platform_device *dev) timeout); } - ret = register_reboot_notifier(&advwdt_notifier); - if (ret != 0) { - printk (KERN_ERR PFX "cannot register reboot notifier (err=%d)\n", - ret); - goto unreg_regions; - } - ret = misc_register(&advwdt_miscdev); if (ret != 0) { printk (KERN_ERR PFX "cannot register miscdev on minor=%d (err=%d)\n", WATCHDOG_MINOR, ret); - goto unreg_reboot; + goto unreg_regions; } printk (KERN_INFO PFX "initialized. timeout=%d sec (nowayout=%d)\n", @@ -318,8 +285,6 @@ advwdt_probe(struct platform_device *dev) out: return ret; -unreg_reboot: - unregister_reboot_notifier(&advwdt_notifier); unreg_regions: release_region(wdt_start, 1); unreg_stop: @@ -332,7 +297,6 @@ static int __devexit advwdt_remove(struct platform_device *dev) { misc_deregister(&advwdt_miscdev); - unregister_reboot_notifier(&advwdt_notifier); release_region(wdt_start,1); if(wdt_stop != wdt_start) release_region(wdt_stop,1); @@ -340,9 +304,17 @@ advwdt_remove(struct platform_device *dev) return 0; } +static void +advwdt_shutdown(struct platform_device *dev) +{ + /* Turn the WDT off if we have a soft shutdown */ + advwdt_disable(); +} + static struct platform_driver advwdt_driver = { .probe = advwdt_probe, .remove = __devexit_p(advwdt_remove), + .shutdown = advwdt_shutdown, .driver = { .owner = THIS_MODULE, .name = DRV_NAME, -- cgit v1.2.3