Commit 159859b6 authored by Kevin Hilman's avatar Kevin Hilman

watchdog: davinci: use clock framework for timer frequency

Signed-off-by: default avatarKevin Hilman <khilman@deeprootsystems.com>
parent b27da366
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/clk.h>
#define MODULE_NAME "DAVINCI-WDT: " #define MODULE_NAME "DAVINCI-WDT: "
...@@ -69,6 +70,7 @@ static unsigned long wdt_status; ...@@ -69,6 +70,7 @@ static unsigned long wdt_status;
static struct resource *wdt_mem; static struct resource *wdt_mem;
static void __iomem *wdt_base; static void __iomem *wdt_base;
struct clk *wdt_clk;
static void wdt_service(void) static void wdt_service(void)
{ {
...@@ -86,6 +88,10 @@ static void wdt_enable(void) ...@@ -86,6 +88,10 @@ static void wdt_enable(void)
{ {
u32 tgcr; u32 tgcr;
u32 timer_margin; u32 timer_margin;
u32 wdt_freq;
BUG_ON(!wdt_clk);
wdt_freq = clk_get_rate(wdt_clk);
spin_lock(&io_lock); spin_lock(&io_lock);
...@@ -99,9 +105,9 @@ static void wdt_enable(void) ...@@ -99,9 +105,9 @@ static void wdt_enable(void)
iowrite32(0, wdt_base + TIM12); iowrite32(0, wdt_base + TIM12);
iowrite32(0, wdt_base + TIM34); iowrite32(0, wdt_base + TIM34);
/* set timeout period */ /* set timeout period */
timer_margin = (((u64)heartbeat * CLOCK_TICK_RATE) & 0xffffffff); timer_margin = (((u64)heartbeat * wdt_freq) & 0xffffffff);
iowrite32(timer_margin, wdt_base + PRD12); iowrite32(timer_margin, wdt_base + PRD12);
timer_margin = (((u64)heartbeat * CLOCK_TICK_RATE) >> 32); timer_margin = (((u64)heartbeat * wdt_freq) >> 32);
iowrite32(timer_margin, wdt_base + PRD34); iowrite32(timer_margin, wdt_base + PRD34);
/* enable run continuously */ /* enable run continuously */
iowrite32(ENAMODE12_PERIODIC, wdt_base + TCR); iowrite32(ENAMODE12_PERIODIC, wdt_base + TCR);
...@@ -199,6 +205,11 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev) ...@@ -199,6 +205,11 @@ static int __devinit davinci_wdt_probe(struct platform_device *pdev)
struct resource *res; struct resource *res;
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
wdt_clk = clk_get(dev, NULL);
if (WARN_ON(!wdt_clk))
return -ENODEV;
clk_enable(wdt_clk);
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT) if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
heartbeat = DEFAULT_HEARTBEAT; heartbeat = DEFAULT_HEARTBEAT;
...@@ -245,6 +256,12 @@ static int __devexit davinci_wdt_remove(struct platform_device *pdev) ...@@ -245,6 +256,12 @@ static int __devexit davinci_wdt_remove(struct platform_device *pdev)
kfree(wdt_mem); kfree(wdt_mem);
wdt_mem = NULL; wdt_mem = NULL;
} }
if (wdt_clk) {
clk_disable(wdt_clk);
clk_put(wdt_clk);
}
return 0; return 0;
} }
......
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