mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-10 15:19:51 +00:00
watchdog: max63xx: dynamically allocate device
This patch removes the static watchdog device for a new max63xx_wdt data structure, and constifies the max63xx_timeout data. The new structure contains pointers to pin access routines, which abstracts mmap-specific code. This will ease future accesses like GPIO. Signed-off-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Reviewed-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>
This commit is contained in:
parent
db11cba205
commit
b9be9660ba
@ -39,10 +39,22 @@ static bool nowayout = WATCHDOG_NOWAYOUT;
|
|||||||
#define MAX6369_WDSET (7 << 0)
|
#define MAX6369_WDSET (7 << 0)
|
||||||
#define MAX6369_WDI (1 << 3)
|
#define MAX6369_WDI (1 << 3)
|
||||||
|
|
||||||
static DEFINE_SPINLOCK(io_lock);
|
#define MAX6369_WDSET_DISABLED 3
|
||||||
|
|
||||||
static int nodelay;
|
static int nodelay;
|
||||||
static void __iomem *wdt_base;
|
|
||||||
|
struct max63xx_wdt {
|
||||||
|
struct watchdog_device wdd;
|
||||||
|
const struct max63xx_timeout *timeout;
|
||||||
|
|
||||||
|
/* memory mapping */
|
||||||
|
void __iomem *base;
|
||||||
|
spinlock_t lock;
|
||||||
|
|
||||||
|
/* WDI and WSET bits write access routines */
|
||||||
|
void (*ping)(struct max63xx_wdt *wdt);
|
||||||
|
void (*set)(struct max63xx_wdt *wdt, u8 set);
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The timeout values used are actually the absolute minimum the chip
|
* The timeout values used are actually the absolute minimum the chip
|
||||||
@ -59,25 +71,25 @@ static void __iomem *wdt_base;
|
|||||||
|
|
||||||
/* Timeouts in second */
|
/* Timeouts in second */
|
||||||
struct max63xx_timeout {
|
struct max63xx_timeout {
|
||||||
u8 wdset;
|
const u8 wdset;
|
||||||
u8 tdelay;
|
const u8 tdelay;
|
||||||
u8 twd;
|
const u8 twd;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct max63xx_timeout max6369_table[] = {
|
static const struct max63xx_timeout max6369_table[] = {
|
||||||
{ 5, 1, 1 },
|
{ 5, 1, 1 },
|
||||||
{ 6, 10, 10 },
|
{ 6, 10, 10 },
|
||||||
{ 7, 60, 60 },
|
{ 7, 60, 60 },
|
||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct max63xx_timeout max6371_table[] = {
|
static const struct max63xx_timeout max6371_table[] = {
|
||||||
{ 6, 60, 3 },
|
{ 6, 60, 3 },
|
||||||
{ 7, 60, 60 },
|
{ 7, 60, 60 },
|
||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct max63xx_timeout max6373_table[] = {
|
static const struct max63xx_timeout max6373_table[] = {
|
||||||
{ 2, 60, 1 },
|
{ 2, 60, 1 },
|
||||||
{ 5, 0, 1 },
|
{ 5, 0, 1 },
|
||||||
{ 1, 3, 3 },
|
{ 1, 3, 3 },
|
||||||
@ -86,8 +98,6 @@ static struct max63xx_timeout max6373_table[] = {
|
|||||||
{ },
|
{ },
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct max63xx_timeout *current_timeout;
|
|
||||||
|
|
||||||
static struct max63xx_timeout *
|
static struct max63xx_timeout *
|
||||||
max63xx_select_timeout(struct max63xx_timeout *table, int value)
|
max63xx_select_timeout(struct max63xx_timeout *table, int value)
|
||||||
{
|
{
|
||||||
@ -108,59 +118,32 @@ max63xx_select_timeout(struct max63xx_timeout *table, int value)
|
|||||||
|
|
||||||
static int max63xx_wdt_ping(struct watchdog_device *wdd)
|
static int max63xx_wdt_ping(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
u8 val;
|
struct max63xx_wdt *wdt = watchdog_get_drvdata(wdd);
|
||||||
|
|
||||||
spin_lock(&io_lock);
|
wdt->ping(wdt);
|
||||||
|
|
||||||
val = __raw_readb(wdt_base);
|
|
||||||
|
|
||||||
__raw_writeb(val | MAX6369_WDI, wdt_base);
|
|
||||||
__raw_writeb(val & ~MAX6369_WDI, wdt_base);
|
|
||||||
|
|
||||||
spin_unlock(&io_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max63xx_wdt_start(struct watchdog_device *wdd)
|
static int max63xx_wdt_start(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
struct max63xx_timeout *entry = watchdog_get_drvdata(wdd);
|
struct max63xx_wdt *wdt = watchdog_get_drvdata(wdd);
|
||||||
u8 val;
|
|
||||||
|
|
||||||
spin_lock(&io_lock);
|
wdt->set(wdt, wdt->timeout->wdset);
|
||||||
|
|
||||||
val = __raw_readb(wdt_base);
|
|
||||||
val &= ~MAX6369_WDSET;
|
|
||||||
val |= entry->wdset;
|
|
||||||
__raw_writeb(val, wdt_base);
|
|
||||||
|
|
||||||
spin_unlock(&io_lock);
|
|
||||||
|
|
||||||
/* check for a edge triggered startup */
|
/* check for a edge triggered startup */
|
||||||
if (entry->tdelay == 0)
|
if (wdt->timeout->tdelay == 0)
|
||||||
max63xx_wdt_ping(wdd);
|
wdt->ping(wdt);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max63xx_wdt_stop(struct watchdog_device *wdd)
|
static int max63xx_wdt_stop(struct watchdog_device *wdd)
|
||||||
{
|
{
|
||||||
u8 val;
|
struct max63xx_wdt *wdt = watchdog_get_drvdata(wdd);
|
||||||
|
|
||||||
spin_lock(&io_lock);
|
wdt->set(wdt, MAX6369_WDSET_DISABLED);
|
||||||
|
|
||||||
val = __raw_readb(wdt_base);
|
|
||||||
val &= ~MAX6369_WDSET;
|
|
||||||
val |= 3;
|
|
||||||
__raw_writeb(val, wdt_base);
|
|
||||||
|
|
||||||
spin_unlock(&io_lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct watchdog_info max63xx_wdt_info = {
|
|
||||||
.options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
|
|
||||||
.identity = "max63xx Watchdog",
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct watchdog_ops max63xx_wdt_ops = {
|
static const struct watchdog_ops max63xx_wdt_ops = {
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
.start = max63xx_wdt_start,
|
.start = max63xx_wdt_start,
|
||||||
@ -168,49 +151,104 @@ static const struct watchdog_ops max63xx_wdt_ops = {
|
|||||||
.ping = max63xx_wdt_ping,
|
.ping = max63xx_wdt_ping,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct watchdog_device max63xx_wdt_dev = {
|
static const struct watchdog_info max63xx_wdt_info = {
|
||||||
.info = &max63xx_wdt_info,
|
.options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
|
||||||
.ops = &max63xx_wdt_ops,
|
.identity = "max63xx Watchdog",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void max63xx_mmap_ping(struct max63xx_wdt *wdt)
|
||||||
|
{
|
||||||
|
u8 val;
|
||||||
|
|
||||||
|
spin_lock(&wdt->lock);
|
||||||
|
|
||||||
|
val = __raw_readb(wdt->base);
|
||||||
|
|
||||||
|
__raw_writeb(val | MAX6369_WDI, wdt->base);
|
||||||
|
__raw_writeb(val & ~MAX6369_WDI, wdt->base);
|
||||||
|
|
||||||
|
spin_unlock(&wdt->lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void max63xx_mmap_set(struct max63xx_wdt *wdt, u8 set)
|
||||||
|
{
|
||||||
|
u8 val;
|
||||||
|
|
||||||
|
spin_lock(&wdt->lock);
|
||||||
|
|
||||||
|
val = __raw_readb(wdt->base);
|
||||||
|
val &= ~MAX6369_WDSET;
|
||||||
|
val |= set & MAX6369_WDSET;
|
||||||
|
__raw_writeb(val, wdt->base);
|
||||||
|
|
||||||
|
spin_unlock(&wdt->lock);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int max63xx_mmap_init(struct platform_device *p, struct max63xx_wdt *wdt)
|
||||||
|
{
|
||||||
|
struct resource *mem = platform_get_resource(p, IORESOURCE_MEM, 0);
|
||||||
|
|
||||||
|
wdt->base = devm_ioremap_resource(&p->dev, mem);
|
||||||
|
if (IS_ERR(wdt->base))
|
||||||
|
return PTR_ERR(wdt->base);
|
||||||
|
|
||||||
|
spin_lock_init(&wdt->lock);
|
||||||
|
|
||||||
|
wdt->ping = max63xx_mmap_ping;
|
||||||
|
wdt->set = max63xx_mmap_set;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int max63xx_wdt_probe(struct platform_device *pdev)
|
static int max63xx_wdt_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct resource *wdt_mem;
|
struct max63xx_wdt *wdt;
|
||||||
struct max63xx_timeout *table;
|
struct max63xx_timeout *table;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);
|
||||||
|
if (!wdt)
|
||||||
|
return -ENOMEM;
|
||||||
|
|
||||||
table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
|
table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
|
||||||
|
|
||||||
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
|
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
|
||||||
heartbeat = DEFAULT_HEARTBEAT;
|
heartbeat = DEFAULT_HEARTBEAT;
|
||||||
|
|
||||||
dev_info(&pdev->dev, "requesting %ds heartbeat\n", heartbeat);
|
wdt->timeout = max63xx_select_timeout(table, heartbeat);
|
||||||
current_timeout = max63xx_select_timeout(table, heartbeat);
|
if (!wdt->timeout) {
|
||||||
|
dev_err(&pdev->dev, "unable to satisfy %ds heartbeat request\n",
|
||||||
if (!current_timeout) {
|
heartbeat);
|
||||||
dev_err(&pdev->dev, "unable to satisfy heartbeat request\n");
|
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = max63xx_mmap_init(pdev, wdt);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
platform_set_drvdata(pdev, &wdt->wdd);
|
||||||
|
watchdog_set_drvdata(&wdt->wdd, wdt);
|
||||||
|
|
||||||
|
wdt->wdd.parent = &pdev->dev;
|
||||||
|
wdt->wdd.timeout = wdt->timeout->twd;
|
||||||
|
wdt->wdd.info = &max63xx_wdt_info;
|
||||||
|
wdt->wdd.ops = &max63xx_wdt_ops;
|
||||||
|
|
||||||
|
watchdog_set_nowayout(&wdt->wdd, nowayout);
|
||||||
|
|
||||||
|
err = watchdog_register_device(&wdt->wdd);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
dev_info(&pdev->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);
|
wdt->timeout->twd, wdt->timeout->tdelay);
|
||||||
|
return 0;
|
||||||
heartbeat = current_timeout->twd;
|
|
||||||
|
|
||||||
wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
||||||
wdt_base = devm_ioremap_resource(&pdev->dev, wdt_mem);
|
|
||||||
if (IS_ERR(wdt_base))
|
|
||||||
return PTR_ERR(wdt_base);
|
|
||||||
|
|
||||||
max63xx_wdt_dev.timeout = heartbeat;
|
|
||||||
watchdog_set_nowayout(&max63xx_wdt_dev, nowayout);
|
|
||||||
watchdog_set_drvdata(&max63xx_wdt_dev, current_timeout);
|
|
||||||
|
|
||||||
return watchdog_register_device(&max63xx_wdt_dev);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max63xx_wdt_remove(struct platform_device *pdev)
|
static int max63xx_wdt_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
watchdog_unregister_device(&max63xx_wdt_dev);
|
struct watchdog_device *wdd = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
|
watchdog_unregister_device(wdd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user