2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-04-17 19:00:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google, Inc
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-04-17 19:00:22 +00:00
|
|
|
#include <wdt.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/wdt.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2017-04-17 19:00:22 +00:00
|
|
|
|
|
|
|
#define WDT_AST2500 2500
|
|
|
|
#define WDT_AST2400 2400
|
|
|
|
|
|
|
|
struct ast_wdt_priv {
|
|
|
|
struct ast_wdt *regs;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ast_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
|
|
|
|
{
|
|
|
|
struct ast_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
ulong driver_data = dev_get_driver_data(dev);
|
|
|
|
u32 reset_mode = ast_reset_mode_from_flags(flags);
|
|
|
|
|
2019-06-06 07:38:45 +00:00
|
|
|
/* 32 bits at 1MHz is 4294967ms */
|
|
|
|
timeout = min_t(u64, timeout, 4294967);
|
|
|
|
|
|
|
|
/* WDT counts in ticks of 1MHz clock. 1ms / 1e3 * 1e6 */
|
|
|
|
timeout *= 1000;
|
|
|
|
|
2017-04-17 19:00:22 +00:00
|
|
|
clrsetbits_le32(&priv->regs->ctrl,
|
|
|
|
WDT_CTRL_RESET_MASK << WDT_CTRL_RESET_MODE_SHIFT,
|
|
|
|
reset_mode << WDT_CTRL_RESET_MODE_SHIFT);
|
|
|
|
|
|
|
|
if (driver_data >= WDT_AST2500 && reset_mode == WDT_CTRL_RESET_SOC)
|
|
|
|
writel(ast_reset_mask_from_flags(flags),
|
|
|
|
&priv->regs->reset_mask);
|
|
|
|
|
|
|
|
writel((u32) timeout, &priv->regs->counter_reload_val);
|
|
|
|
writel(WDT_COUNTER_RESTART_VAL, &priv->regs->counter_restart);
|
|
|
|
/*
|
|
|
|
* Setting CLK1MHZ bit is just for compatibility with ast2400 part.
|
|
|
|
* On ast2500 watchdog timer clock is fixed at 1MHz and the bit is
|
|
|
|
* read-only
|
|
|
|
*/
|
|
|
|
setbits_le32(&priv->regs->ctrl,
|
|
|
|
WDT_CTRL_EN | WDT_CTRL_RESET | WDT_CTRL_CLK1MHZ);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ast_wdt_stop(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ast_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
clrbits_le32(&priv->regs->ctrl, WDT_CTRL_EN);
|
|
|
|
|
2018-10-16 11:57:11 +00:00
|
|
|
writel(WDT_RESET_DEFAULT, &priv->regs->reset_mask);
|
2017-04-17 19:00:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ast_wdt_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct ast_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
writel(WDT_COUNTER_RESTART_VAL, &priv->regs->counter_restart);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ast_wdt_expire_now(struct udevice *dev, ulong flags)
|
|
|
|
{
|
|
|
|
struct ast_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ast_wdt_start(dev, 1, flags);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
while (readl(&priv->regs->ctrl) & WDT_CTRL_EN)
|
|
|
|
;
|
|
|
|
|
|
|
|
return ast_wdt_stop(dev);
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int ast_wdt_of_to_plat(struct udevice *dev)
|
2017-04-17 19:00:22 +00:00
|
|
|
{
|
|
|
|
struct ast_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2020-08-04 05:14:43 +00:00
|
|
|
priv->regs = dev_read_addr_ptr(dev);
|
2020-08-03 19:17:35 +00:00
|
|
|
if (!priv->regs)
|
|
|
|
return -EINVAL;
|
2017-04-17 19:00:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wdt_ops ast_wdt_ops = {
|
|
|
|
.start = ast_wdt_start,
|
|
|
|
.reset = ast_wdt_reset,
|
|
|
|
.stop = ast_wdt_stop,
|
|
|
|
.expire_now = ast_wdt_expire_now,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id ast_wdt_ids[] = {
|
|
|
|
{ .compatible = "aspeed,wdt", .data = WDT_AST2500 },
|
|
|
|
{ .compatible = "aspeed,ast2500-wdt", .data = WDT_AST2500 },
|
|
|
|
{ .compatible = "aspeed,ast2400-wdt", .data = WDT_AST2400 },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ast_wdt_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-17 04:20:07 +00:00
|
|
|
debug("%s() wdt%u\n", __func__, dev_seq(dev));
|
2017-04-17 19:00:22 +00:00
|
|
|
ast_wdt_stop(dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ast_wdt) = {
|
|
|
|
.name = "ast_wdt",
|
|
|
|
.id = UCLASS_WDT,
|
|
|
|
.of_match = ast_wdt_ids,
|
|
|
|
.probe = ast_wdt_probe,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct ast_wdt_priv),
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = ast_wdt_of_to_plat,
|
2017-04-17 19:00:22 +00:00
|
|
|
.ops = &ast_wdt_ops,
|
|
|
|
};
|