From 9b655e07d77e3b1a00c1c8302e2ef3b7fb719de3 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Sun, 8 Feb 2009 16:44:42 +0100 Subject: [PATCH] [WATCHDOG] rc32434_wdt: clean-up driver Clean-up the rc32434 driver code: - name the platform driver rc32434_wdt_driver - Replace KBUILD_MODNAME ": " with PFX define. - Cleanup include files - Order the ioctl's Signed-off-by: Phil Sutter Signed-off-by: Wim Van Sebroeck --- drivers/watchdog/rc32434_wdt.c | 75 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/drivers/watchdog/rc32434_wdt.c b/drivers/watchdog/rc32434_wdt.c index f3553fa40b17..68fb22625cdc 100644 --- a/drivers/watchdog/rc32434_wdt.c +++ b/drivers/watchdog/rc32434_wdt.c @@ -17,22 +17,22 @@ * */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include +#include /* For module specific items */ +#include /* For new moduleparam's */ +#include /* For standard types (like size_t) */ +#include /* For the -ENODEV/... values */ +#include /* For printk/panic/... */ +#include /* For file operations */ +#include /* For MODULE_ALIAS_MISCDEV + (WATCHDOG_MINOR) */ +#include /* For the watchdog specific items */ +#include /* For __init/__exit/... */ +#include /* For platform_driver framework */ +#include /* For copy_to_user/put_user/... */ + +#include /* For the Watchdog registers */ + +#define PFX KBUILD_MODNAME ": " #define VERSION "0.4" @@ -90,12 +90,16 @@ static void rc32434_wdt_start(void) or = 1 << RC32434_WTC_EN; SET_BITS(wdt_reg->wtc, or, nand); + + printk(KERN_INFO PFX "Started watchdog timer.\n"); } static void rc32434_wdt_stop(void) { /* Disable WDT */ SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN); + + printk(KERN_INFO PFX "Stopped watchdog timer.\n"); } static int rc32434_wdt_set(int new_timeout) @@ -103,8 +107,7 @@ static int rc32434_wdt_set(int new_timeout) int max_to = WTCOMP2SEC((u32)-1); if (new_timeout < 0 || new_timeout > max_to) { - printk(KERN_ERR KBUILD_MODNAME - ": timeout value must be between 0 and %d", + printk(KERN_ERR PFX "timeout value must be between 0 and %d", max_to); return -EINVAL; } @@ -137,11 +140,10 @@ static int rc32434_wdt_release(struct inode *inode, struct file *file) { if (expect_close == 42) { rc32434_wdt_stop(); - printk(KERN_INFO KBUILD_MODNAME ": disabling watchdog timer\n"); module_put(THIS_MODULE); } else { - printk(KERN_CRIT KBUILD_MODNAME - ": device closed unexpectedly. WDT will not stop !\n"); + printk(KERN_CRIT PFX + "device closed unexpectedly. WDT will not stop!\n"); rc32434_wdt_ping(); } clear_bit(0, &rc32434_wdt_device.inuse); @@ -185,8 +187,9 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd, .identity = "RC32434_WDT Watchdog", }; switch (cmd) { - case WDIOC_KEEPALIVE: - rc32434_wdt_ping(); + case WDIOC_GETSUPPORT: + if (copy_to_user(argp, &ident, sizeof(ident))) + return -EFAULT; break; case WDIOC_GETSTATUS: case WDIOC_GETBOOTSTATUS: @@ -194,10 +197,6 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd, if (copy_to_user(argp, &value, sizeof(int))) return -EFAULT; break; - case WDIOC_GETSUPPORT: - if (copy_to_user(argp, &ident, sizeof(ident))) - return -EFAULT; - break; case WDIOC_SETOPTIONS: if (copy_from_user(&value, argp, sizeof(int))) return -EFAULT; @@ -212,6 +211,9 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd, return -EINVAL; } break; + case WDIOC_KEEPALIVE: + rc32434_wdt_ping(); + break; case WDIOC_SETTIMEOUT: if (copy_from_user(&new_timeout, argp, sizeof(int))) return -EFAULT; @@ -242,8 +244,8 @@ static struct miscdevice rc32434_wdt_miscdev = { .fops = &rc32434_wdt_fops, }; -static char banner[] __devinitdata = KERN_INFO KBUILD_MODNAME - ": Watchdog Timer version " VERSION ", timer margin: %d sec\n"; +static char banner[] __devinitdata = KERN_INFO PFX + "Watchdog Timer version " VERSION ", timer margin: %d sec\n"; static int __devinit rc32434_wdt_probe(struct platform_device *pdev) { @@ -252,22 +254,19 @@ static int __devinit rc32434_wdt_probe(struct platform_device *pdev) r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rb532_wdt_res"); if (!r) { - printk(KERN_ERR KBUILD_MODNAME - "failed to retrieve resources\n"); + printk(KERN_ERR PFX "failed to retrieve resources\n"); return -ENODEV; } wdt_reg = ioremap_nocache(r->start, r->end - r->start); if (!wdt_reg) { - printk(KERN_ERR KBUILD_MODNAME - "failed to remap I/O resources\n"); + printk(KERN_ERR PFX "failed to remap I/O resources\n"); return -ENXIO; } ret = misc_register(&rc32434_wdt_miscdev); if (ret < 0) { - printk(KERN_ERR KBUILD_MODNAME - "failed to register watchdog device\n"); + printk(KERN_ERR PFX "failed to register watchdog device\n"); goto unmap; } @@ -287,7 +286,7 @@ static int __devexit rc32434_wdt_remove(struct platform_device *pdev) return 0; } -static struct platform_driver rc32434_wdt = { +static struct platform_driver rc32434_wdt_driver = { .probe = rc32434_wdt_probe, .remove = __devexit_p(rc32434_wdt_remove), .driver = { @@ -297,12 +296,12 @@ static struct platform_driver rc32434_wdt = { static int __init rc32434_wdt_init(void) { - return platform_driver_register(&rc32434_wdt); + return platform_driver_register(&rc32434_wdt_driver); } static void __exit rc32434_wdt_exit(void) { - platform_driver_unregister(&rc32434_wdt); + platform_driver_unregister(&rc32434_wdt_driver); } module_init(rc32434_wdt_init); -- 2.20.1