2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-05-16 16:29:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
|
|
|
|
*
|
|
|
|
* Derived from linux/drivers/watchdog/bcm63xx_wdt.c:
|
|
|
|
* Copyright (C) 2007 Miguel Gaio <miguel.gaio@efixo.com>
|
|
|
|
* Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-05-16 16:29:09 +00:00
|
|
|
#include <wdt.h>
|
2019-05-03 17:43:06 +00:00
|
|
|
#include <clk.h>
|
2017-05-16 16:29:09 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
|
|
|
|
/* WDT Value register */
|
|
|
|
#define WDT_VAL_REG 0x0
|
|
|
|
#define WDT_VAL_MIN 0x00000002
|
|
|
|
#define WDT_VAL_MAX 0xfffffffe
|
|
|
|
|
|
|
|
/* WDT Control register */
|
|
|
|
#define WDT_CTL_REG 0x4
|
|
|
|
#define WDT_CTL_START1_MASK 0x0000ff00
|
|
|
|
#define WDT_CTL_START2_MASK 0x000000ff
|
|
|
|
#define WDT_CTL_STOP1_MASK 0x0000ee00
|
|
|
|
#define WDT_CTL_STOP2_MASK 0x000000ee
|
|
|
|
|
|
|
|
struct bcm6345_wdt_priv {
|
|
|
|
void __iomem *regs;
|
2019-05-03 17:43:06 +00:00
|
|
|
unsigned long clk_rate;
|
2017-05-16 16:29:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm6345_wdt_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-01-28 14:37:27 +00:00
|
|
|
writel(WDT_CTL_START1_MASK, priv->regs + WDT_CTL_REG);
|
|
|
|
writel(WDT_CTL_START2_MASK, priv->regs + WDT_CTL_REG);
|
2017-05-16 16:29:09 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
|
|
|
|
{
|
|
|
|
struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
|
2019-05-03 17:43:06 +00:00
|
|
|
u32 val = priv->clk_rate / 1000 * timeout;
|
2017-05-16 16:29:09 +00:00
|
|
|
|
2019-05-03 17:43:06 +00:00
|
|
|
if (val < WDT_VAL_MIN) {
|
2017-05-16 16:29:09 +00:00
|
|
|
debug("watchdog won't fire with less than 2 ticks\n");
|
2019-05-03 17:43:06 +00:00
|
|
|
val = WDT_VAL_MIN;
|
|
|
|
} else if (val > WDT_VAL_MAX) {
|
2017-05-16 16:29:09 +00:00
|
|
|
debug("maximum watchdog timeout exceeded\n");
|
2019-05-03 17:43:06 +00:00
|
|
|
val = WDT_VAL_MAX;
|
2017-05-16 16:29:09 +00:00
|
|
|
}
|
|
|
|
|
2019-05-03 17:43:06 +00:00
|
|
|
writel(val, priv->regs + WDT_VAL_REG);
|
2017-05-16 16:29:09 +00:00
|
|
|
|
|
|
|
return bcm6345_wdt_reset(dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_wdt_expire_now(struct udevice *dev, ulong flags)
|
|
|
|
{
|
|
|
|
return bcm6345_wdt_start(dev, WDT_VAL_MIN, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int bcm6345_wdt_stop(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-01-28 14:37:27 +00:00
|
|
|
writel(WDT_CTL_STOP1_MASK, priv->regs + WDT_CTL_REG);
|
|
|
|
writel(WDT_CTL_STOP2_MASK, priv->regs + WDT_CTL_REG);
|
2017-05-16 16:29:09 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wdt_ops bcm6345_wdt_ops = {
|
|
|
|
.expire_now = bcm6345_wdt_expire_now,
|
|
|
|
.reset = bcm6345_wdt_reset,
|
|
|
|
.start = bcm6345_wdt_start,
|
|
|
|
.stop = bcm6345_wdt_stop,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id bcm6345_wdt_ids[] = {
|
|
|
|
{ .compatible = "brcm,bcm6345-wdt" },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
|
|
|
|
static int bcm6345_wdt_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
|
2019-05-03 17:43:06 +00:00
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
2017-05-16 16:29:09 +00:00
|
|
|
|
2018-03-22 18:39:28 +00:00
|
|
|
priv->regs = dev_remap_addr(dev);
|
|
|
|
if (!priv->regs)
|
2017-05-16 16:29:09 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-05-03 17:43:06 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
|
|
|
if (!ret)
|
|
|
|
priv->clk_rate = clk_get_rate(&clk);
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
|
2017-05-16 16:29:09 +00:00
|
|
|
bcm6345_wdt_stop(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(wdt_bcm6345) = {
|
|
|
|
.name = "wdt_bcm6345",
|
|
|
|
.id = UCLASS_WDT,
|
|
|
|
.of_match = bcm6345_wdt_ids,
|
|
|
|
.ops = &bcm6345_wdt_ops,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct bcm6345_wdt_priv),
|
|
|
|
.probe = bcm6345_wdt_probe,
|
|
|
|
};
|