2 * drivers/watchdog/orion_wdt.c
4 * Watchdog driver for Orion/Kirkwood processors
6 * Authors: Tomas Hlavacek <tmshlvck@gmail.com>
7 * Sylver Bruneau <sylver.bruneau@googlemail.com>
8 * Marek Behun <marek.behun@nic.cz>
10 * This file is licensed under the terms of the GNU General Public
11 * License version 2. This program is licensed "as is" without any
12 * warranty of any kind, whether express or implied.
20 #include <linux/bitops.h>
21 #include <linux/kernel.h>
23 #include <asm/arch/cpu.h>
24 #include <asm/arch/soc.h>
26 DECLARE_GLOBAL_DATA_PTR;
28 struct orion_wdt_priv {
30 int wdt_counter_offset;
32 void __iomem *rstout_mask;
34 unsigned long clk_rate;
38 #define RSTOUT_ENABLE_BIT BIT(8)
39 #define RSTOUT_MASK_BIT BIT(10)
40 #define WDT_ENABLE_BIT BIT(8)
42 #define TIMER_CTRL 0x0000
43 #define TIMER_A370_STATUS 0x04
45 #define WDT_AXP_FIXED_ENABLE_BIT BIT(10)
46 #define WDT_A370_EXPIRED BIT(31)
48 static int orion_wdt_reset(struct udevice *dev)
50 struct orion_wdt_priv *priv = dev_get_priv(dev);
52 /* Reload watchdog duration */
53 writel(priv->clk_rate * priv->timeout,
54 priv->reg + priv->wdt_counter_offset);
59 static int orion_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
61 struct orion_wdt_priv *priv = dev_get_priv(dev);
64 priv->timeout = DIV_ROUND_UP(timeout_ms, 1000);
66 /* Enable the fixed watchdog clock input */
67 reg = readl(priv->reg + TIMER_CTRL);
68 reg |= WDT_AXP_FIXED_ENABLE_BIT;
69 writel(reg, priv->reg + TIMER_CTRL);
71 /* Set watchdog duration */
72 writel(priv->clk_rate * priv->timeout,
73 priv->reg + priv->wdt_counter_offset);
75 /* Clear the watchdog expiration bit */
76 reg = readl(priv->reg + TIMER_A370_STATUS);
77 reg &= ~WDT_A370_EXPIRED;
78 writel(reg, priv->reg + TIMER_A370_STATUS);
80 /* Enable watchdog timer */
81 reg = readl(priv->reg + TIMER_CTRL);
82 reg |= WDT_ENABLE_BIT;
83 writel(reg, priv->reg + TIMER_CTRL);
85 /* Enable reset on watchdog */
86 reg = readl(priv->rstout);
87 reg |= RSTOUT_ENABLE_BIT;
88 writel(reg, priv->rstout);
90 reg = readl(priv->rstout_mask);
91 reg &= ~RSTOUT_MASK_BIT;
92 writel(reg, priv->rstout_mask);
97 static int orion_wdt_stop(struct udevice *dev)
99 struct orion_wdt_priv *priv = dev_get_priv(dev);
102 /* Disable reset on watchdog */
103 reg = readl(priv->rstout_mask);
104 reg |= RSTOUT_MASK_BIT;
105 writel(reg, priv->rstout_mask);
107 reg = readl(priv->rstout);
108 reg &= ~RSTOUT_ENABLE_BIT;
109 writel(reg, priv->rstout);
111 /* Disable watchdog timer */
112 reg = readl(priv->reg + TIMER_CTRL);
113 reg &= ~WDT_ENABLE_BIT;
114 writel(reg, priv->reg + TIMER_CTRL);
119 static inline bool save_reg_from_ofdata(struct udevice *dev, int index,
120 void __iomem **reg, int *offset)
125 addr = devfdt_get_addr_size_index(dev, index, &off);
126 if (addr == FDT_ADDR_T_NONE)
129 *reg = (void __iomem *) addr;
136 static int orion_wdt_of_to_plat(struct udevice *dev)
138 struct orion_wdt_priv *priv = dev_get_priv(dev);
140 if (!save_reg_from_ofdata(dev, 0, &priv->reg,
141 &priv->wdt_counter_offset))
144 if (!save_reg_from_ofdata(dev, 1, &priv->rstout, NULL))
147 if (!save_reg_from_ofdata(dev, 2, &priv->rstout_mask, NULL))
152 debug("%s: Could not determine Orion wdt IO addresses\n", __func__);
156 static int orion_wdt_probe(struct udevice *dev)
158 struct orion_wdt_priv *priv = dev_get_priv(dev);
161 debug("%s: Probing wdt%u\n", __func__, dev_seq(dev));
164 ret = clk_get_by_name(dev, "fixed", &priv->clk);
166 priv->clk_rate = clk_get_rate(&priv->clk);
168 priv->clk_rate = 25000000;
173 static const struct wdt_ops orion_wdt_ops = {
174 .start = orion_wdt_start,
175 .reset = orion_wdt_reset,
176 .stop = orion_wdt_stop,
179 static const struct udevice_id orion_wdt_ids[] = {
180 { .compatible = "marvell,armada-380-wdt" },
184 U_BOOT_DRIVER(orion_wdt) = {
187 .of_match = orion_wdt_ids,
188 .probe = orion_wdt_probe,
189 .priv_auto = sizeof(struct orion_wdt_priv),
190 .of_to_plat = orion_wdt_of_to_plat,
191 .ops = &orion_wdt_ops,