提交 a0f36833 编写于 作者: A Axel Lin 提交者: Wim Van Sebroeck

watchdog: Convert max63xx_wdt driver to watchdog framework

This patch converts max63xx_wdt driver to watchdog framework.
Also use devm_* APIs to save a few error handling code.
Signed-off-by: NAxel Lin <axel.lin@gmail.com>
Signed-off-by: NWim Van Sebroeck <wim@iguana.be>
上级 6b1e8386
...@@ -330,6 +330,7 @@ config TS72XX_WATCHDOG ...@@ -330,6 +330,7 @@ config TS72XX_WATCHDOG
config MAX63XX_WATCHDOG config MAX63XX_WATCHDOG
tristate "Max63xx watchdog" tristate "Max63xx watchdog"
depends on ARM && HAS_IOMEM depends on ARM && HAS_IOMEM
select WATCHDOG_CORE
help help
Support for memory mapped max63{69,70,71,72,73,74} watchdog timer. Support for memory mapped max63{69,70,71,72,73,74} watchdog timer.
......
...@@ -18,22 +18,19 @@ ...@@ -18,22 +18,19 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/watchdog.h> #include <linux/watchdog.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/device.h>
#include <linux/slab.h> #include <linux/slab.h>
#define DEFAULT_HEARTBEAT 60 #define DEFAULT_HEARTBEAT 60
#define MAX_HEARTBEAT 60 #define MAX_HEARTBEAT 60
static int heartbeat = DEFAULT_HEARTBEAT; static unsigned int heartbeat = DEFAULT_HEARTBEAT;
static bool nowayout = WATCHDOG_NOWAYOUT; static bool nowayout = WATCHDOG_NOWAYOUT;
/* /*
...@@ -45,15 +42,8 @@ static bool nowayout = WATCHDOG_NOWAYOUT; ...@@ -45,15 +42,8 @@ static bool nowayout = WATCHDOG_NOWAYOUT;
static DEFINE_SPINLOCK(io_lock); static DEFINE_SPINLOCK(io_lock);
static unsigned long wdt_status;
#define WDT_IN_USE 0
#define WDT_RUNNING 1
#define WDT_OK_TO_CLOSE 2
static int nodelay; static int nodelay;
static struct resource *wdt_mem;
static void __iomem *wdt_base; static void __iomem *wdt_base;
static struct platform_device *max63xx_pdev;
/* /*
* The timeout values used are actually the absolute minimum the chip * The timeout values used are actually the absolute minimum the chip
...@@ -117,7 +107,7 @@ max63xx_select_timeout(struct max63xx_timeout *table, int value) ...@@ -117,7 +107,7 @@ max63xx_select_timeout(struct max63xx_timeout *table, int value)
return NULL; return NULL;
} }
static void max63xx_wdt_ping(void) static int max63xx_wdt_ping(struct watchdog_device *wdd)
{ {
u8 val; u8 val;
...@@ -129,15 +119,14 @@ static void max63xx_wdt_ping(void) ...@@ -129,15 +119,14 @@ static void max63xx_wdt_ping(void)
__raw_writeb(val & ~MAX6369_WDI, wdt_base); __raw_writeb(val & ~MAX6369_WDI, wdt_base);
spin_unlock(&io_lock); spin_unlock(&io_lock);
return 0;
} }
static void max63xx_wdt_enable(struct max63xx_timeout *entry) static int max63xx_wdt_start(struct watchdog_device *wdd)
{ {
struct max63xx_timeout *entry = watchdog_get_drvdata(wdd);
u8 val; u8 val;
if (test_and_set_bit(WDT_RUNNING, &wdt_status))
return;
spin_lock(&io_lock); spin_lock(&io_lock);
val = __raw_readb(wdt_base); val = __raw_readb(wdt_base);
...@@ -149,10 +138,11 @@ static void max63xx_wdt_enable(struct max63xx_timeout *entry) ...@@ -149,10 +138,11 @@ static void max63xx_wdt_enable(struct max63xx_timeout *entry)
/* check for a edge triggered startup */ /* check for a edge triggered startup */
if (entry->tdelay == 0) if (entry->tdelay == 0)
max63xx_wdt_ping(); max63xx_wdt_ping(wdd);
return 0;
} }
static void max63xx_wdt_disable(void) static int max63xx_wdt_stop(struct watchdog_device *wdd)
{ {
u8 val; u8 val;
...@@ -164,113 +154,29 @@ static void max63xx_wdt_disable(void) ...@@ -164,113 +154,29 @@ static void max63xx_wdt_disable(void)
__raw_writeb(val, wdt_base); __raw_writeb(val, wdt_base);
spin_unlock(&io_lock); spin_unlock(&io_lock);
return 0;
clear_bit(WDT_RUNNING, &wdt_status);
}
static int max63xx_wdt_open(struct inode *inode, struct file *file)
{
if (test_and_set_bit(WDT_IN_USE, &wdt_status))
return -EBUSY;
max63xx_wdt_enable(current_timeout);
clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
return nonseekable_open(inode, file);
}
static ssize_t max63xx_wdt_write(struct file *file, const char *data,
size_t len, loff_t *ppos)
{
if (len) {
if (!nowayout) {
size_t i;
clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
for (i = 0; i != len; i++) {
char c;
if (get_user(c, data + i))
return -EFAULT;
if (c == 'V')
set_bit(WDT_OK_TO_CLOSE, &wdt_status);
}
}
max63xx_wdt_ping();
}
return len;
} }
static const struct watchdog_info ident = { static const struct watchdog_info max63xx_wdt_info = {
.options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING, .options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
.identity = "max63xx Watchdog", .identity = "max63xx Watchdog",
}; };
static long max63xx_wdt_ioctl(struct file *file, unsigned int cmd, static const struct watchdog_ops max63xx_wdt_ops = {
unsigned long arg) .owner = THIS_MODULE,
{ .start = max63xx_wdt_start,
int ret = -ENOTTY; .stop = max63xx_wdt_stop,
.ping = max63xx_wdt_ping,
switch (cmd) {
case WDIOC_GETSUPPORT:
ret = copy_to_user((struct watchdog_info *)arg, &ident,
sizeof(ident)) ? -EFAULT : 0;
break;
case WDIOC_GETSTATUS:
case WDIOC_GETBOOTSTATUS:
ret = put_user(0, (int *)arg);
break;
case WDIOC_KEEPALIVE:
max63xx_wdt_ping();
ret = 0;
break;
case WDIOC_GETTIMEOUT:
ret = put_user(heartbeat, (int *)arg);
break;
}
return ret;
}
static int max63xx_wdt_release(struct inode *inode, struct file *file)
{
if (test_bit(WDT_OK_TO_CLOSE, &wdt_status))
max63xx_wdt_disable();
else
dev_crit(&max63xx_pdev->dev,
"device closed unexpectedly - timer will not stop\n");
clear_bit(WDT_IN_USE, &wdt_status);
clear_bit(WDT_OK_TO_CLOSE, &wdt_status);
return 0;
}
static const struct file_operations max63xx_wdt_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.write = max63xx_wdt_write,
.unlocked_ioctl = max63xx_wdt_ioctl,
.open = max63xx_wdt_open,
.release = max63xx_wdt_release,
}; };
static struct miscdevice max63xx_wdt_miscdev = { static struct watchdog_device max63xx_wdt_dev = {
.minor = WATCHDOG_MINOR, .info = &max63xx_wdt_info,
.name = "watchdog", .ops = &max63xx_wdt_ops,
.fops = &max63xx_wdt_fops,
}; };
static int __devinit max63xx_wdt_probe(struct platform_device *pdev) static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
{ {
int ret = 0; struct resource *wdt_mem;
int size;
struct device *dev = &pdev->dev;
struct max63xx_timeout *table; struct max63xx_timeout *table;
table = (struct max63xx_timeout *)pdev->id_entry->driver_data; table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
...@@ -278,68 +184,34 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev) ...@@ -278,68 +184,34 @@ static int __devinit max63xx_wdt_probe(struct platform_device *pdev)
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT) if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
heartbeat = DEFAULT_HEARTBEAT; heartbeat = DEFAULT_HEARTBEAT;
dev_info(dev, "requesting %ds heartbeat\n", heartbeat); dev_info(&pdev->dev, "requesting %ds heartbeat\n", heartbeat);
current_timeout = max63xx_select_timeout(table, heartbeat); current_timeout = max63xx_select_timeout(table, heartbeat);
if (!current_timeout) { if (!current_timeout) {
dev_err(dev, "unable to satisfy heartbeat request\n"); dev_err(&pdev->dev, "unable to satisfy heartbeat request\n");
return -EINVAL; return -EINVAL;
} }
dev_info(dev, "using %ds heartbeat with %ds initial delay\n", dev_info(&pdev->dev, "using %ds heartbeat with %ds initial delay\n",
current_timeout->twd, current_timeout->tdelay); current_timeout->twd, current_timeout->tdelay);
heartbeat = current_timeout->twd; heartbeat = current_timeout->twd;
max63xx_pdev = pdev;
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (wdt_mem == NULL) { wdt_base = devm_request_and_ioremap(&pdev->dev, wdt_mem);
dev_err(dev, "failed to get memory region resource\n"); if (!wdt_base)
return -ENOENT; return -ENOMEM;
}
size = resource_size(wdt_mem); max63xx_wdt_dev.timeout = heartbeat;
if (!request_mem_region(wdt_mem->start, size, pdev->name)) { watchdog_set_nowayout(&max63xx_wdt_dev, nowayout);
dev_err(dev, "failed to get memory region\n"); watchdog_set_drvdata(&max63xx_wdt_dev, current_timeout);
return -ENOENT;
}
wdt_base = ioremap(wdt_mem->start, size);
if (!wdt_base) {
dev_err(dev, "failed to map memory region\n");
ret = -ENOMEM;
goto out_request;
}
ret = misc_register(&max63xx_wdt_miscdev); return watchdog_register_device(&max63xx_wdt_dev);
if (ret < 0) {
dev_err(dev, "cannot register misc device\n");
goto out_unmap;
}
return 0;
out_unmap:
iounmap(wdt_base);
out_request:
release_mem_region(wdt_mem->start, size);
wdt_mem = NULL;
return ret;
} }
static int __devexit max63xx_wdt_remove(struct platform_device *pdev) static int __devexit max63xx_wdt_remove(struct platform_device *pdev)
{ {
misc_deregister(&max63xx_wdt_miscdev); watchdog_unregister_device(&max63xx_wdt_dev);
if (wdt_mem) {
release_mem_region(wdt_mem->start, resource_size(wdt_mem));
wdt_mem = NULL;
}
if (wdt_base)
iounmap(wdt_base);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册