[WATCHDOG] rc32434_wdt: clean-up driver
authorPhil Sutter <n0-1@freewrt.org>
Sun, 8 Feb 2009 15:44:42 +0000 (16:44 +0100)
committerWim Van Sebroeck <wim@iguana.be>
Wed, 25 Mar 2009 08:59:12 +0000 (08:59 +0000)
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 <n0-1@freewrt.org>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
drivers/watchdog/rc32434_wdt.c

index f3553fa..68fb226 100644 (file)
  *
  */
 
-#include <linux/module.h>
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/fs.h>
-#include <linux/mm.h>
-#include <linux/miscdevice.h>
-#include <linux/watchdog.h>
-#include <linux/reboot.h>
-#include <linux/smp_lock.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <linux/uaccess.h>
-
-#include <asm/bootinfo.h>
-#include <asm/time.h>
-#include <asm/mach-rc32434/integ.h>
+#include <linux/module.h>              /* For module specific items */
+#include <linux/moduleparam.h>         /* For new moduleparam's */
+#include <linux/types.h>               /* For standard types (like size_t) */
+#include <linux/errno.h>               /* For the -ENODEV/... values */
+#include <linux/kernel.h>              /* For printk/panic/... */
+#include <linux/fs.h>                  /* For file operations */
+#include <linux/miscdevice.h>          /* For MODULE_ALIAS_MISCDEV
+                                                       (WATCHDOG_MINOR) */
+#include <linux/watchdog.h>            /* For the watchdog specific items */
+#include <linux/init.h>                        /* For __init/__exit/... */
+#include <linux/platform_device.h>     /* For platform_driver framework */
+#include <linux/uaccess.h>             /* For copy_to_user/put_user/... */
+
+#include <asm/mach-rc32434/integ.h>    /* 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);