1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
// 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,
};
|