1 // SPDX-License-Identifier: GPL-2.0+
3 * Watchdog driver for SBSA
8 #include <asm/global_data.h>
11 #include <dm/device.h>
12 #include <dm/fdtaddr.h>
14 #include <linux/bitops.h>
15 #include <linux/err.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 /* SBSA Generic Watchdog register definitions */
23 #define SBSA_GWDT_WRR 0x000
26 #define SBSA_GWDT_WCS 0x000
27 #define SBSA_GWDT_WOR 0x008
28 #define SBSA_GWDT_WCV 0x010
30 /* refresh/control frame */
31 #define SBSA_GWDT_W_IIDR 0xfcc
32 #define SBSA_GWDT_IDR 0xfd0
34 /* Watchdog Control and Status Register */
35 #define SBSA_GWDT_WCS_EN BIT(0)
36 #define SBSA_GWDT_WCS_WS0 BIT(1)
37 #define SBSA_GWDT_WCS_WS1 BIT(2)
39 struct sbsa_gwdt_priv {
40 void __iomem *reg_refresh;
41 void __iomem *reg_control;
44 static int sbsa_gwdt_reset(struct udevice *dev)
46 struct sbsa_gwdt_priv *priv = dev_get_priv(dev);
48 writel(0, priv->reg_refresh + SBSA_GWDT_WRR);
53 static int sbsa_gwdt_start(struct udevice *dev, u64 timeout, ulong flags)
55 struct sbsa_gwdt_priv *priv = dev_get_priv(dev);
59 * it work in the single stage mode in u-boot,
60 * The first signal (WS0) is ignored,
61 * the timeout is (WOR * 2), so the WOR should be configured
62 * to half value of timeout.
65 writel(clk / (2 * 1000) * timeout,
66 priv->reg_control + SBSA_GWDT_WOR);
68 /* writing WCS will cause an explicit watchdog refresh */
69 writel(SBSA_GWDT_WCS_EN, priv->reg_control + SBSA_GWDT_WCS);
74 static int sbsa_gwdt_stop(struct udevice *dev)
76 struct sbsa_gwdt_priv *priv = dev_get_priv(dev);
78 writel(0, priv->reg_control + SBSA_GWDT_WCS);
83 static int sbsa_gwdt_expire_now(struct udevice *dev, ulong flags)
85 sbsa_gwdt_start(dev, 0, flags);
90 static int sbsa_gwdt_probe(struct udevice *dev)
92 debug("%s: Probing wdt%u (sbsa-gwdt)\n", __func__, dev_seq(dev));
97 static int sbsa_gwdt_of_to_plat(struct udevice *dev)
99 struct sbsa_gwdt_priv *priv = dev_get_priv(dev);
101 priv->reg_control = dev_read_addr_index_ptr(dev, 0);
102 if (!priv->reg_control)
105 priv->reg_refresh = dev_read_addr_index_ptr(dev, 1);
106 if (!priv->reg_refresh)
112 static const struct wdt_ops sbsa_gwdt_ops = {
113 .start = sbsa_gwdt_start,
114 .reset = sbsa_gwdt_reset,
115 .stop = sbsa_gwdt_stop,
116 .expire_now = sbsa_gwdt_expire_now,
119 static const struct udevice_id sbsa_gwdt_ids[] = {
120 { .compatible = "arm,sbsa-gwdt" },
124 U_BOOT_DRIVER(sbsa_gwdt) = {
127 .of_match = sbsa_gwdt_ids,
128 .probe = sbsa_gwdt_probe,
129 .priv_auto = sizeof(struct sbsa_gwdt_priv),
130 .of_to_plat = sbsa_gwdt_of_to_plat,
131 .ops = &sbsa_gwdt_ops,