1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
5 * Derived from linux/drivers/watchdog/bcm63xx_wdt.c:
6 * Copyright (C) 2007 Miguel Gaio <miguel.gaio@efixo.com>
7 * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
15 /* WDT Value register */
16 #define WDT_VAL_REG 0x0
17 #define WDT_VAL_MIN 0x00000002
18 #define WDT_VAL_MAX 0xfffffffe
20 /* WDT Control register */
21 #define WDT_CTL_REG 0x4
22 #define WDT_CTL_START1_MASK 0x0000ff00
23 #define WDT_CTL_START2_MASK 0x000000ff
24 #define WDT_CTL_STOP1_MASK 0x0000ee00
25 #define WDT_CTL_STOP2_MASK 0x000000ee
27 struct bcm6345_wdt_priv {
31 static int bcm6345_wdt_reset(struct udevice *dev)
33 struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
35 writel(WDT_CTL_START1_MASK, priv->regs + WDT_CTL_REG);
36 writel(WDT_CTL_START2_MASK, priv->regs + WDT_CTL_REG);
41 static int bcm6345_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
43 struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
45 if (timeout < WDT_VAL_MIN) {
46 debug("watchdog won't fire with less than 2 ticks\n");
47 timeout = WDT_VAL_MIN;
48 } else if (timeout > WDT_VAL_MAX) {
49 debug("maximum watchdog timeout exceeded\n");
50 timeout = WDT_VAL_MAX;
53 writel(timeout, priv->regs + WDT_VAL_REG);
55 return bcm6345_wdt_reset(dev);
58 static int bcm6345_wdt_expire_now(struct udevice *dev, ulong flags)
60 return bcm6345_wdt_start(dev, WDT_VAL_MIN, flags);
63 static int bcm6345_wdt_stop(struct udevice *dev)
65 struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
67 writel(WDT_CTL_STOP1_MASK, priv->regs + WDT_CTL_REG);
68 writel(WDT_CTL_STOP2_MASK, priv->regs + WDT_CTL_REG);
73 static const struct wdt_ops bcm6345_wdt_ops = {
74 .expire_now = bcm6345_wdt_expire_now,
75 .reset = bcm6345_wdt_reset,
76 .start = bcm6345_wdt_start,
77 .stop = bcm6345_wdt_stop,
80 static const struct udevice_id bcm6345_wdt_ids[] = {
81 { .compatible = "brcm,bcm6345-wdt" },
85 static int bcm6345_wdt_probe(struct udevice *dev)
87 struct bcm6345_wdt_priv *priv = dev_get_priv(dev);
89 priv->regs = dev_remap_addr(dev);
93 bcm6345_wdt_stop(dev);
98 U_BOOT_DRIVER(wdt_bcm6345) = {
99 .name = "wdt_bcm6345",
101 .of_match = bcm6345_wdt_ids,
102 .ops = &bcm6345_wdt_ops,
103 .priv_auto_alloc_size = sizeof(struct bcm6345_wdt_priv),
104 .probe = bcm6345_wdt_probe,