[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 <n0-1@freewrt.org>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
This commit is contained in:
Phil Sutter 2009-02-08 16:44:42 +01:00 committed by Wim Van Sebroeck
parent 371d3525e3
commit 9b655e07d7

View file

@ -17,22 +17,22 @@
* *
*/ */
#include <linux/module.h> #include <linux/module.h> /* For module specific items */
#include <linux/types.h> #include <linux/moduleparam.h> /* For new moduleparam's */
#include <linux/kernel.h> #include <linux/types.h> /* For standard types (like size_t) */
#include <linux/fs.h> #include <linux/errno.h> /* For the -ENODEV/... values */
#include <linux/mm.h> #include <linux/kernel.h> /* For printk/panic/... */
#include <linux/miscdevice.h> #include <linux/fs.h> /* For file operations */
#include <linux/watchdog.h> #include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
#include <linux/reboot.h> (WATCHDOG_MINOR) */
#include <linux/smp_lock.h> #include <linux/watchdog.h> /* For the watchdog specific items */
#include <linux/init.h> #include <linux/init.h> /* For __init/__exit/... */
#include <linux/platform_device.h> #include <linux/platform_device.h> /* For platform_driver framework */
#include <linux/uaccess.h> #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
#include <asm/bootinfo.h> #include <asm/mach-rc32434/integ.h> /* For the Watchdog registers */
#include <asm/time.h>
#include <asm/mach-rc32434/integ.h> #define PFX KBUILD_MODNAME ": "
#define VERSION "0.4" #define VERSION "0.4"
@ -90,12 +90,16 @@ static void rc32434_wdt_start(void)
or = 1 << RC32434_WTC_EN; or = 1 << RC32434_WTC_EN;
SET_BITS(wdt_reg->wtc, or, nand); SET_BITS(wdt_reg->wtc, or, nand);
printk(KERN_INFO PFX "Started watchdog timer.\n");
} }
static void rc32434_wdt_stop(void) static void rc32434_wdt_stop(void)
{ {
/* Disable WDT */ /* Disable WDT */
SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN); 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) 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); int max_to = WTCOMP2SEC((u32)-1);
if (new_timeout < 0 || new_timeout > max_to) { if (new_timeout < 0 || new_timeout > max_to) {
printk(KERN_ERR KBUILD_MODNAME printk(KERN_ERR PFX "timeout value must be between 0 and %d",
": timeout value must be between 0 and %d",
max_to); max_to);
return -EINVAL; return -EINVAL;
} }
@ -137,11 +140,10 @@ static int rc32434_wdt_release(struct inode *inode, struct file *file)
{ {
if (expect_close == 42) { if (expect_close == 42) {
rc32434_wdt_stop(); rc32434_wdt_stop();
printk(KERN_INFO KBUILD_MODNAME ": disabling watchdog timer\n");
module_put(THIS_MODULE); module_put(THIS_MODULE);
} else { } else {
printk(KERN_CRIT KBUILD_MODNAME printk(KERN_CRIT PFX
": device closed unexpectedly. WDT will not stop !\n"); "device closed unexpectedly. WDT will not stop!\n");
rc32434_wdt_ping(); rc32434_wdt_ping();
} }
clear_bit(0, &rc32434_wdt_device.inuse); 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", .identity = "RC32434_WDT Watchdog",
}; };
switch (cmd) { switch (cmd) {
case WDIOC_KEEPALIVE: case WDIOC_GETSUPPORT:
rc32434_wdt_ping(); if (copy_to_user(argp, &ident, sizeof(ident)))
return -EFAULT;
break; break;
case WDIOC_GETSTATUS: case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS: 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))) if (copy_to_user(argp, &value, sizeof(int)))
return -EFAULT; return -EFAULT;
break; break;
case WDIOC_GETSUPPORT:
if (copy_to_user(argp, &ident, sizeof(ident)))
return -EFAULT;
break;
case WDIOC_SETOPTIONS: case WDIOC_SETOPTIONS:
if (copy_from_user(&value, argp, sizeof(int))) if (copy_from_user(&value, argp, sizeof(int)))
return -EFAULT; return -EFAULT;
@ -212,6 +211,9 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
return -EINVAL; return -EINVAL;
} }
break; break;
case WDIOC_KEEPALIVE:
rc32434_wdt_ping();
break;
case WDIOC_SETTIMEOUT: case WDIOC_SETTIMEOUT:
if (copy_from_user(&new_timeout, argp, sizeof(int))) if (copy_from_user(&new_timeout, argp, sizeof(int)))
return -EFAULT; return -EFAULT;
@ -242,8 +244,8 @@ static struct miscdevice rc32434_wdt_miscdev = {
.fops = &rc32434_wdt_fops, .fops = &rc32434_wdt_fops,
}; };
static char banner[] __devinitdata = KERN_INFO KBUILD_MODNAME static char banner[] __devinitdata = KERN_INFO PFX
": Watchdog Timer version " VERSION ", timer margin: %d sec\n"; "Watchdog Timer version " VERSION ", timer margin: %d sec\n";
static int __devinit rc32434_wdt_probe(struct platform_device *pdev) 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"); r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rb532_wdt_res");
if (!r) { if (!r) {
printk(KERN_ERR KBUILD_MODNAME printk(KERN_ERR PFX "failed to retrieve resources\n");
"failed to retrieve resources\n");
return -ENODEV; return -ENODEV;
} }
wdt_reg = ioremap_nocache(r->start, r->end - r->start); wdt_reg = ioremap_nocache(r->start, r->end - r->start);
if (!wdt_reg) { if (!wdt_reg) {
printk(KERN_ERR KBUILD_MODNAME printk(KERN_ERR PFX "failed to remap I/O resources\n");
"failed to remap I/O resources\n");
return -ENXIO; return -ENXIO;
} }
ret = misc_register(&rc32434_wdt_miscdev); ret = misc_register(&rc32434_wdt_miscdev);
if (ret < 0) { if (ret < 0) {
printk(KERN_ERR KBUILD_MODNAME printk(KERN_ERR PFX "failed to register watchdog device\n");
"failed to register watchdog device\n");
goto unmap; goto unmap;
} }
@ -287,7 +286,7 @@ static int __devexit rc32434_wdt_remove(struct platform_device *pdev)
return 0; return 0;
} }
static struct platform_driver rc32434_wdt = { static struct platform_driver rc32434_wdt_driver = {
.probe = rc32434_wdt_probe, .probe = rc32434_wdt_probe,
.remove = __devexit_p(rc32434_wdt_remove), .remove = __devexit_p(rc32434_wdt_remove),
.driver = { .driver = {
@ -297,12 +296,12 @@ static struct platform_driver rc32434_wdt = {
static int __init rc32434_wdt_init(void) 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) static void __exit rc32434_wdt_exit(void)
{ {
platform_driver_unregister(&rc32434_wdt); platform_driver_unregister(&rc32434_wdt_driver);
} }
module_init(rc32434_wdt_init); module_init(rc32434_wdt_init);