aboutsummaryrefslogtreecommitdiff
path: root/drivers/watchdog/pnx4008_wdt.c
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2012-02-02 18:48:08 +0100
committerWim Van Sebroeck <wim@iguana.be>2012-03-27 19:59:03 +0200
commit19f505f09c60d637c695a8e8c4768570e2309631 (patch)
tree88304a11bbc66990f30ae2fb97c15828bab6b229 /drivers/watchdog/pnx4008_wdt.c
parent16ac4abe0d0ea0a8d42d6a2a7de2a4a00bbf5b40 (diff)
downloadvexpress-lsk-19f505f09c60d637c695a8e8c4768570e2309631.tar.gz
watchdog: pnx4008: cleanup resource handling using managed devices
The resource handling in this driver was flaky: IO_ADDRESS instead of ioremap (and no unmapping), an unneeded static resource, no central exit path for error cases. Fix this by converting the driver to use managed resources. Also use dev_*-messages instead of pr_* while we are here. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
Diffstat (limited to 'drivers/watchdog/pnx4008_wdt.c')
-rw-r--r--drivers/watchdog/pnx4008_wdt.c69
1 files changed, 22 insertions, 47 deletions
diff --git a/drivers/watchdog/pnx4008_wdt.c b/drivers/watchdog/pnx4008_wdt.c
index dfae030a7ef..55c5224bf19 100644
--- a/drivers/watchdog/pnx4008_wdt.c
+++ b/drivers/watchdog/pnx4008_wdt.c
@@ -84,12 +84,9 @@ static DEFINE_SPINLOCK(io_lock);
static unsigned long wdt_status;
#define WDT_IN_USE 0
#define WDT_OK_TO_CLOSE 1
-#define WDT_REGION_INITED 2
-#define WDT_DEVICE_INITED 3
static unsigned long boot_status;
-static struct resource *wdt_mem;
static void __iomem *wdt_base;
struct clk *wdt_clk;
@@ -253,61 +250,43 @@ static struct miscdevice pnx4008_wdt_miscdev = {
static int __devinit pnx4008_wdt_probe(struct platform_device *pdev)
{
- int ret = 0, size;
+ struct resource *r;
+ int ret = 0;
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
heartbeat = DEFAULT_HEARTBEAT;
- printk(KERN_INFO MODULE_NAME
- "PNX4008 Watchdog Timer: heartbeat %d sec\n", heartbeat);
-
- wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (wdt_mem == NULL) {
- printk(KERN_INFO MODULE_NAME
- "failed to get memory region resource\n");
- return -ENOENT;
- }
-
- size = resource_size(wdt_mem);
-
- if (!request_mem_region(wdt_mem->start, size, pdev->name)) {
- printk(KERN_INFO MODULE_NAME "failed to get memory region\n");
- return -ENOENT;
- }
- wdt_base = (void __iomem *)IO_ADDRESS(wdt_mem->start);
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ wdt_base = devm_request_and_ioremap(&pdev->dev, r);
+ if (!wdt_base)
+ return -EADDRINUSE;
wdt_clk = clk_get(&pdev->dev, NULL);
- if (IS_ERR(wdt_clk)) {
- ret = PTR_ERR(wdt_clk);
- release_mem_region(wdt_mem->start, size);
- wdt_mem = NULL;
- goto out;
- }
+ if (IS_ERR(wdt_clk))
+ return PTR_ERR(wdt_clk);
ret = clk_enable(wdt_clk);
- if (ret) {
- release_mem_region(wdt_mem->start, size);
- wdt_mem = NULL;
- clk_put(wdt_clk);
+ if (ret)
goto out;
- }
+
+ boot_status = (__raw_readl(WDTIM_RES(wdt_base)) &
+ WDOG_RESET) ? WDIOF_CARDRESET : 0;
+ wdt_disable(); /*disable for now */
+ clk_disable(wdt_clk);
ret = misc_register(&pnx4008_wdt_miscdev);
if (ret < 0) {
- printk(KERN_ERR MODULE_NAME "cannot register misc device\n");
- release_mem_region(wdt_mem->start, size);
- wdt_mem = NULL;
- clk_disable(wdt_clk);
- clk_put(wdt_clk);
- } else {
- boot_status = (__raw_readl(WDTIM_RES(wdt_base)) & WDOG_RESET) ?
- WDIOF_CARDRESET : 0;
- wdt_disable(); /*disable for now */
- clk_disable(wdt_clk);
- set_bit(WDT_DEVICE_INITED, &wdt_status);
+ dev_err(&pdev->dev, "cannot register misc device\n");
+ goto out;
}
+ dev_info(&pdev->dev, "PNX4008 Watchdog Timer: heartbeat %d sec\n",
+ heartbeat);
+
+ return 0;
+
out:
+ clk_put(wdt_clk);
return ret;
}
@@ -318,10 +297,6 @@ static int __devexit pnx4008_wdt_remove(struct platform_device *pdev)
clk_disable(wdt_clk);
clk_put(wdt_clk);
- if (wdt_mem) {
- release_mem_region(wdt_mem->start, resource_size(wdt_mem));
- wdt_mem = NULL;
- }
return 0;
}