1
0
mirror of https://xff.cz/git/u-boot/ synced 2025-10-01 07:21:23 +02:00
Files
u-boot-megous/drivers/watchdog/ast2600_wdt.c
Tom Rini d678a59d2d Revert "Merge patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet""
When bringing in the series 'arm: dts: am62-beagleplay: Fix Beagleplay
Ethernet"' I failed to notice that b4 noticed it was based on next and
so took that as the base commit and merged that part of next to master.

This reverts commit c8ffd1356d, reversing
changes made to 2ee6f3a5f7.

Reported-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Tom Rini <trini@konsulko.com>
2024-05-19 08:16:36 -06:00

111 lines
2.4 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (c) 2020 Aspeed Technology, Inc
*/
#include <common.h>
#include <dm.h>
#include <errno.h>
#include <log.h>
#include <wdt.h>
#include <asm/io.h>
#include <asm/arch/wdt_ast2600.h>
#include <linux/err.h>
struct ast2600_wdt_priv {
struct ast2600_wdt *regs;
};
static int ast2600_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
{
struct ast2600_wdt_priv *priv = dev_get_priv(dev);
struct ast2600_wdt *wdt = priv->regs;
/* WDT counts in the 1MHz frequency, namely 1us */
writel((u32)(timeout_ms * 1000), &wdt->counter_reload_val);
writel(WDT_COUNTER_RESTART_VAL, &wdt->counter_restart);
writel(WDT_CTRL_EN | WDT_CTRL_RESET, &wdt->ctrl);
return 0;
}
static int ast2600_wdt_stop(struct udevice *dev)
{
struct ast2600_wdt_priv *priv = dev_get_priv(dev);
struct ast2600_wdt *wdt = priv->regs;
clrbits_le32(&wdt->ctrl, WDT_CTRL_EN);
writel(WDT_RESET_MASK1_DEFAULT, &wdt->reset_mask1);
writel(WDT_RESET_MASK2_DEFAULT, &wdt->reset_mask2);
return 0;
}
static int ast2600_wdt_reset(struct udevice *dev)
{
struct ast2600_wdt_priv *priv = dev_get_priv(dev);
struct ast2600_wdt *wdt = priv->regs;
writel(WDT_COUNTER_RESTART_VAL, &wdt->counter_restart);
return 0;
}
static int ast2600_wdt_expire_now(struct udevice *dev, ulong flags)
{
int ret;
struct ast2600_wdt_priv *priv = dev_get_priv(dev);
struct ast2600_wdt *wdt = priv->regs;
ret = ast2600_wdt_start(dev, 1, flags);
if (ret)
return ret;
while (readl(&wdt->ctrl) & WDT_CTRL_EN)
;
return ast2600_wdt_stop(dev);
}
static int ast2600_wdt_of_to_plat(struct udevice *dev)
{
struct ast2600_wdt_priv *priv = dev_get_priv(dev);
priv->regs = dev_read_addr_ptr(dev);
if (!priv->regs)
return -EINVAL;
return 0;
}
static const struct wdt_ops ast2600_wdt_ops = {
.start = ast2600_wdt_start,
.reset = ast2600_wdt_reset,
.stop = ast2600_wdt_stop,
.expire_now = ast2600_wdt_expire_now,
};
static const struct udevice_id ast2600_wdt_ids[] = {
{ .compatible = "aspeed,ast2600-wdt" },
{ }
};
static int ast2600_wdt_probe(struct udevice *dev)
{
debug("%s() wdt%u\n", __func__, dev_seq(dev));
ast2600_wdt_stop(dev);
return 0;
}
U_BOOT_DRIVER(ast2600_wdt) = {
.name = "ast2600_wdt",
.id = UCLASS_WDT,
.of_match = ast2600_wdt_ids,
.probe = ast2600_wdt_probe,
.priv_auto = sizeof(struct ast2600_wdt_priv),
.of_to_plat = ast2600_wdt_of_to_plat,
.ops = &ast2600_wdt_ops,
};