Commit e455b6b4 authored by Wim Van Sebroeck's avatar Wim Van Sebroeck

[WATCHDOG] rc32434_wdt: add spin_locking

Add spin_locks to prevent races.
Signed-off-by: default avatarWim Van Sebroeck <wim@iguana.be>
parent 0aaae661
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <linux/watchdog.h> /* For the watchdog specific items */ #include <linux/watchdog.h> /* For the watchdog specific items */
#include <linux/init.h> /* For __init/__exit/... */ #include <linux/init.h> /* For __init/__exit/... */
#include <linux/platform_device.h> /* For platform_driver framework */ #include <linux/platform_device.h> /* For platform_driver framework */
#include <linux/spinlock.h> /* For spin_lock/spin_unlock/... */
#include <linux/uaccess.h> /* For copy_to_user/put_user/... */ #include <linux/uaccess.h> /* For copy_to_user/put_user/... */
#include <asm/mach-rc32434/integ.h> /* For the Watchdog registers */ #include <asm/mach-rc32434/integ.h> /* For the Watchdog registers */
...@@ -38,6 +39,7 @@ ...@@ -38,6 +39,7 @@
static struct { static struct {
unsigned long inuse; unsigned long inuse;
spinlock_t io_lock;
} rc32434_wdt_device; } rc32434_wdt_device;
static struct integ __iomem *wdt_reg; static struct integ __iomem *wdt_reg;
...@@ -81,7 +83,9 @@ static int rc32434_wdt_set(int new_timeout) ...@@ -81,7 +83,9 @@ static int rc32434_wdt_set(int new_timeout)
return -EINVAL; return -EINVAL;
} }
timeout = new_timeout; timeout = new_timeout;
spin_lock(&rc32434_wdt_device.io_lock);
writel(SEC2WTCOMP(timeout), &wdt_reg->wtcompare); writel(SEC2WTCOMP(timeout), &wdt_reg->wtcompare);
spin_unlock(&rc32434_wdt_device.io_lock);
return 0; return 0;
} }
...@@ -90,6 +94,8 @@ static void rc32434_wdt_start(void) ...@@ -90,6 +94,8 @@ static void rc32434_wdt_start(void)
{ {
u32 or, nand; u32 or, nand;
spin_lock(&rc32434_wdt_device.io_lock);
/* zero the counter before enabling */ /* zero the counter before enabling */
writel(0, &wdt_reg->wtcount); writel(0, &wdt_reg->wtcount);
...@@ -112,20 +118,26 @@ static void rc32434_wdt_start(void) ...@@ -112,20 +118,26 @@ static void rc32434_wdt_start(void)
SET_BITS(wdt_reg->wtc, or, nand); SET_BITS(wdt_reg->wtc, or, nand);
spin_unlock(&rc32434_wdt_device.io_lock);
printk(KERN_INFO PFX "Started watchdog timer.\n"); printk(KERN_INFO PFX "Started watchdog timer.\n");
} }
static void rc32434_wdt_stop(void) static void rc32434_wdt_stop(void)
{ {
spin_lock(&rc32434_wdt_device.io_lock);
/* Disable WDT */ /* Disable WDT */
SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN); SET_BITS(wdt_reg->wtc, 0, 1 << RC32434_WTC_EN);
spin_unlock(&rc32434_wdt_device.io_lock);
printk(KERN_INFO PFX "Stopped watchdog timer.\n"); printk(KERN_INFO PFX "Stopped watchdog timer.\n");
} }
static void rc32434_wdt_ping(void) static void rc32434_wdt_ping(void)
{ {
spin_lock(&rc32434_wdt_device.io_lock);
writel(0, &wdt_reg->wtcount); writel(0, &wdt_reg->wtcount);
spin_unlock(&rc32434_wdt_device.io_lock);
} }
static int rc32434_wdt_open(struct inode *inode, struct file *file) static int rc32434_wdt_open(struct inode *inode, struct file *file)
...@@ -270,6 +282,8 @@ static int __devinit rc32434_wdt_probe(struct platform_device *pdev) ...@@ -270,6 +282,8 @@ static int __devinit rc32434_wdt_probe(struct platform_device *pdev)
return -ENXIO; return -ENXIO;
} }
spin_lock_init(&rc32434_wdt_device.io_lock);
/* Check that the heartbeat value is within it's range; /* Check that the heartbeat value is within it's range;
* if not reset to the default */ * if not reset to the default */
if (rc32434_wdt_set(timeout)) { if (rc32434_wdt_set(timeout)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment