aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/watchdog/rc32434_wdt.c
diff options
context:
space:
mode:
authorPhil Sutter <n0-1@freewrt.org>2009-02-08 10:44:42 -0500
committerWim Van Sebroeck <wim@iguana.be>2009-03-25 04:59:12 -0400
commit9b655e07d77e3b1a00c1c8302e2ef3b7fb719de3 (patch)
tree04eeeda09f15f2af0813bd9fd80accdf0851ce1e /drivers/watchdog/rc32434_wdt.c
parent371d3525e3b9d57c00ca307f8ee4ca51a2eaa70b (diff)
[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>
Diffstat (limited to 'drivers/watchdog/rc32434_wdt.c')
-rw-r--r--drivers/watchdog/rc32434_wdt.c75
1 files 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 @@
17 * 17 *
18 */ 18 */
19 19
20#include <linux/module.h> 20#include <linux/module.h> /* For module specific items */
21#include <linux/types.h> 21#include <linux/moduleparam.h> /* For new moduleparam's */
22#include <linux/kernel.h> 22#include <linux/types.h> /* For standard types (like size_t) */
23#include <linux/fs.h> 23#include <linux/errno.h> /* For the -ENODEV/... values */
24#include <linux/mm.h> 24#include <linux/kernel.h> /* For printk/panic/... */
25#include <linux/miscdevice.h> 25#include <linux/fs.h> /* For file operations */
26#include <linux/watchdog.h> 26#include <linux/miscdevice.h> /* For MODULE_ALIAS_MISCDEV
27#include <linux/reboot.h> 27 (WATCHDOG_MINOR) */
28#include <linux/smp_lock.h> 28#include <linux/watchdog.h> /* For the watchdog specific items */
29#include <linux/init.h> 29#include <linux/init.h> /* For __init/__exit/... */
30#include <linux/platform_device.h> 30#include <linux/platform_device.h> /* For platform_driver framework */
31#include <linux/uaccess.h> 31#include <linux/uaccess.h> /* For copy_to_user/put_user/... */
32 32
33#include <asm/bootinfo.h> 33#include <asm/mach-rc32434/integ.h> /* For the Watchdog registers */
34#include <asm/time.h> 34
35#include <asm/mach-rc32434/integ.h> 35#define PFX KBUILD_MODNAME ": "
36 36
37#define VERSION "0.4" 37#define VERSION "0.4"
38 38
@@ -90,12 +90,16 @@ static void rc32434_wdt_start(void)
90 or = 1 << RC32434_WTC_EN; 90 or = 1 << RC32434_WTC_EN;
91 91
92 SET_BITS(wdt_reg->wtc, or, nand); 92 SET_BITS(wdt_reg->wtc, or, nand);
93
94 printk(KERN_INFO PFX "Started watchdog timer.\n");
93} 95}
94 96
95static void rc32434_wdt_stop(void) 97static void rc32434_wdt_stop(void)
96{ 98{
97 /* Disable WDT */ 99 /* Disable WDT */
98 SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN); 100 SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN);
101
102 printk(KERN_INFO PFX "Stopped watchdog timer.\n");
99} 103}
100 104
101static int rc32434_wdt_set(int new_timeout) 105static int rc32434_wdt_set(int new_timeout)
@@ -103,8 +107,7 @@ static int rc32434_wdt_set(int new_timeout)
103 int max_to = WTCOMP2SEC((u32)-1); 107 int max_to = WTCOMP2SEC((u32)-1);
104 108
105 if (new_timeout < 0 || new_timeout > max_to) { 109 if (new_timeout < 0 || new_timeout > max_to) {
106 printk(KERN_ERR KBUILD_MODNAME 110 printk(KERN_ERR PFX "timeout value must be between 0 and %d",
107 ": timeout value must be between 0 and %d",
108 max_to); 111 max_to);
109 return -EINVAL; 112 return -EINVAL;
110 } 113 }
@@ -137,11 +140,10 @@ static int rc32434_wdt_release(struct inode *inode, struct file *file)
137{ 140{
138 if (expect_close == 42) { 141 if (expect_close == 42) {
139 rc32434_wdt_stop(); 142 rc32434_wdt_stop();
140 printk(KERN_INFO KBUILD_MODNAME ": disabling watchdog timer\n");
141 module_put(THIS_MODULE); 143 module_put(THIS_MODULE);
142 } else { 144 } else {
143 printk(KERN_CRIT KBUILD_MODNAME 145 printk(KERN_CRIT PFX
144 ": device closed unexpectedly. WDT will not stop !\n"); 146 "device closed unexpectedly. WDT will not stop!\n");
145 rc32434_wdt_ping(); 147 rc32434_wdt_ping();
146 } 148 }
147 clear_bit(0, &rc32434_wdt_device.inuse); 149 clear_bit(0, &rc32434_wdt_device.inuse);
@@ -185,8 +187,9 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
185 .identity = "RC32434_WDT Watchdog", 187 .identity = "RC32434_WDT Watchdog",
186 }; 188 };
187 switch (cmd) { 189 switch (cmd) {
188 case WDIOC_KEEPALIVE: 190 case WDIOC_GETSUPPORT:
189 rc32434_wdt_ping(); 191 if (copy_to_user(argp, &ident, sizeof(ident)))
192 return -EFAULT;
190 break; 193 break;
191 case WDIOC_GETSTATUS: 194 case WDIOC_GETSTATUS:
192 case WDIOC_GETBOOTSTATUS: 195 case WDIOC_GETBOOTSTATUS:
@@ -194,10 +197,6 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
194 if (copy_to_user(argp, &value, sizeof(int))) 197 if (copy_to_user(argp, &value, sizeof(int)))
195 return -EFAULT; 198 return -EFAULT;
196 break; 199 break;
197 case WDIOC_GETSUPPORT:
198 if (copy_to_user(argp, &ident, sizeof(ident)))
199 return -EFAULT;
200 break;
201 case WDIOC_SETOPTIONS: 200 case WDIOC_SETOPTIONS:
202 if (copy_from_user(&value, argp, sizeof(int))) 201 if (copy_from_user(&value, argp, sizeof(int)))
203 return -EFAULT; 202 return -EFAULT;
@@ -212,6 +211,9 @@ static long rc32434_wdt_ioctl(struct file *file, unsigned int cmd,
212 return -EINVAL; 211 return -EINVAL;
213 } 212 }
214 break; 213 break;
214 case WDIOC_KEEPALIVE:
215 rc32434_wdt_ping();
216 break;
215 case WDIOC_SETTIMEOUT: 217 case WDIOC_SETTIMEOUT:
216 if (copy_from_user(&new_timeout, argp, sizeof(int))) 218 if (copy_from_user(&new_timeout, argp, sizeof(int)))
217 return -EFAULT; 219 return -EFAULT;
@@ -242,8 +244,8 @@ static struct miscdevice rc32434_wdt_miscdev = {
242 .fops = &rc32434_wdt_fops, 244 .fops = &rc32434_wdt_fops,
243}; 245};
244 246
245static char banner[] __devinitdata = KERN_INFO KBUILD_MODNAME 247static char banner[] __devinitdata = KERN_INFO PFX
246 ": Watchdog Timer version " VERSION ", timer margin: %d sec\n"; 248 "Watchdog Timer version " VERSION ", timer margin: %d sec\n";
247 249
248static int __devinit rc32434_wdt_probe(struct platform_device *pdev) 250static int __devinit rc32434_wdt_probe(struct platform_device *pdev)
249{ 251{
@@ -252,22 +254,19 @@ static int __devinit rc32434_wdt_probe(struct platform_device *pdev)
252 254
253 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rb532_wdt_res"); 255 r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rb532_wdt_res");
254 if (!r) { 256 if (!r) {
255 printk(KERN_ERR KBUILD_MODNAME 257 printk(KERN_ERR PFX "failed to retrieve resources\n");
256 "failed to retrieve resources\n");
257 return -ENODEV; 258 return -ENODEV;
258 } 259 }
259 260
260 wdt_reg = ioremap_nocache(r->start, r->end - r->start); 261 wdt_reg = ioremap_nocache(r->start, r->end - r->start);
261 if (!wdt_reg) { 262 if (!wdt_reg) {
262 printk(KERN_ERR KBUILD_MODNAME 263 printk(KERN_ERR PFX "failed to remap I/O resources\n");
263 "failed to remap I/O resources\n");
264 return -ENXIO; 264 return -ENXIO;
265 } 265 }
266 266
267 ret = misc_register(&rc32434_wdt_miscdev); 267 ret = misc_register(&rc32434_wdt_miscdev);
268 if (ret < 0) { 268 if (ret < 0) {
269 printk(KERN_ERR KBUILD_MODNAME 269 printk(KERN_ERR PFX "failed to register watchdog device\n");
270 "failed to register watchdog device\n");
271 goto unmap; 270 goto unmap;
272 } 271 }
273 272
@@ -287,7 +286,7 @@ static int __devexit rc32434_wdt_remove(struct platform_device *pdev)
287 return 0; 286 return 0;
288} 287}
289 288
290static struct platform_driver rc32434_wdt = { 289static struct platform_driver rc32434_wdt_driver = {
291 .probe = rc32434_wdt_probe, 290 .probe = rc32434_wdt_probe,
292 .remove = __devexit_p(rc32434_wdt_remove), 291 .remove = __devexit_p(rc32434_wdt_remove),
293 .driver = { 292 .driver = {
@@ -297,12 +296,12 @@ static struct platform_driver rc32434_wdt = {
297 296
298static int __init rc32434_wdt_init(void) 297static int __init rc32434_wdt_init(void)
299{ 298{
300 return platform_driver_register(&rc32434_wdt); 299 return platform_driver_register(&rc32434_wdt_driver);
301} 300}
302 301
303static void __exit rc32434_wdt_exit(void) 302static void __exit rc32434_wdt_exit(void)
304{ 303{
305 platform_driver_unregister(&rc32434_wdt); 304 platform_driver_unregister(&rc32434_wdt_driver);
306} 305}
307 306
308module_init(rc32434_wdt_init); 307module_init(rc32434_wdt_init);