提交 9ea64046 编写于 作者: P Paul Mundt

watchdog: shwdt: Basic clock framework support.

This plugs in basic clock framework support for the watchdog. As it's an
optional MSTP bit, we don't particularly care if a platform has provided
it or not, though a valid clock will need to be available for the more
complex overflow period calculations found on newer parts -- this will be
addressed later.
Signed-off-by: NPaul Mundt <lethal@linux-sh.org>
上级 f9e2eae6
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/clk.h>
#include <asm/watchdog.h> #include <asm/watchdog.h>
#define DRV_NAME "sh-wdt" #define DRV_NAME "sh-wdt"
...@@ -74,6 +75,7 @@ static unsigned long next_heartbeat; ...@@ -74,6 +75,7 @@ static unsigned long next_heartbeat;
struct sh_wdt { struct sh_wdt {
void __iomem *base; void __iomem *base;
struct device *dev; struct device *dev;
struct clk *clk;
spinlock_t lock; spinlock_t lock;
struct timer_list timer; struct timer_list timer;
...@@ -225,27 +227,32 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev) ...@@ -225,27 +227,32 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev)
if (unlikely(!res)) if (unlikely(!res))
return -EINVAL; return -EINVAL;
if (!devm_request_mem_region(&pdev->dev, res->start,
resource_size(res), DRV_NAME))
return -EBUSY;
wdt = devm_kzalloc(&pdev->dev, sizeof(struct sh_wdt), GFP_KERNEL); wdt = devm_kzalloc(&pdev->dev, sizeof(struct sh_wdt), GFP_KERNEL);
if (unlikely(!wdt)) { if (unlikely(!wdt))
rc = -ENOMEM; return -ENOMEM;
goto out_release;
}
wdt->dev = &pdev->dev; wdt->dev = &pdev->dev;
watchdog_set_nowayout(&sh_wdt_dev, nowayout); wdt->clk = clk_get(&pdev->dev, NULL);
watchdog_set_drvdata(&sh_wdt_dev, wdt); if (IS_ERR(wdt->clk)) {
/*
* Clock framework support is optional, continue on
* anyways if we don't find a matching clock.
*/
wdt->clk = NULL;
}
wdt->base = devm_ioremap(&pdev->dev, res->start, resource_size(res)); clk_enable(wdt->clk);
wdt->base = devm_request_and_ioremap(wdt->dev, res);
if (unlikely(!wdt->base)) { if (unlikely(!wdt->base)) {
rc = -ENXIO; rc = -EADDRNOTAVAIL;
goto out_err; goto out_disable;
} }
watchdog_set_nowayout(&sh_wdt_dev, nowayout);
watchdog_set_drvdata(&sh_wdt_dev, wdt);
spin_lock_init(&wdt->lock); spin_lock_init(&wdt->lock);
rc = sh_wdt_set_heartbeat(&sh_wdt_dev, heartbeat); rc = sh_wdt_set_heartbeat(&sh_wdt_dev, heartbeat);
...@@ -264,7 +271,7 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev) ...@@ -264,7 +271,7 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev)
rc = watchdog_register_device(&sh_wdt_dev); rc = watchdog_register_device(&sh_wdt_dev);
if (unlikely(rc)) { if (unlikely(rc)) {
dev_err(&pdev->dev, "Can't register watchdog (err=%d)\n", rc); dev_err(&pdev->dev, "Can't register watchdog (err=%d)\n", rc);
goto out_unmap; goto out_disable;
} }
init_timer(&wdt->timer); init_timer(&wdt->timer);
...@@ -278,12 +285,9 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev) ...@@ -278,12 +285,9 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev)
return 0; return 0;
out_unmap: out_disable:
devm_iounmap(&pdev->dev, wdt->base); clk_disable(wdt->clk);
out_err: clk_put(wdt->clk);
devm_kfree(&pdev->dev, wdt);
out_release:
devm_release_mem_region(&pdev->dev, res->start, resource_size(res));
return rc; return rc;
} }
...@@ -291,15 +295,13 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev) ...@@ -291,15 +295,13 @@ static int __devinit sh_wdt_probe(struct platform_device *pdev)
static int __devexit sh_wdt_remove(struct platform_device *pdev) static int __devexit sh_wdt_remove(struct platform_device *pdev)
{ {
struct sh_wdt *wdt = platform_get_drvdata(pdev); struct sh_wdt *wdt = platform_get_drvdata(pdev);
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
watchdog_unregister_device(&sh_wdt_dev); watchdog_unregister_device(&sh_wdt_dev);
devm_release_mem_region(&pdev->dev, res->start, resource_size(res)); clk_disable(wdt->clk);
devm_iounmap(&pdev->dev, wdt->base); clk_put(wdt->clk);
devm_kfree(&pdev->dev, wdt);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册