Revision | 1aa2b85810a5c05e6712f9a8ac2d92a1c2916c9a (tree) |
---|---|
Time | 2022-07-21 15:09:06 |
Author | Stefan Roese <sr@denx...> |
Commiter | Stefan Roese |
watchdog: octeontx_wdt: Add MIPS Octeon support
This patch adds support for the Marvell Octeon watchdog driver, which
currently only support the ARM64 Octeon TX & TX2 platforms. Since the
IP is pretty similar, it makes sense to extend this driver to also
support the MIPS Octeon SoC.
A follow-up patch will enable this watchdog support on the EBB7304
eval board.
Signed-off-by: Stefan Roese <sr@denx.de>
Cc: Aaron Williams <awilliams@marvell.com>
Cc: Chandrakala Chavva <cchavva@marvell.com>
@@ -213,14 +213,13 @@ config WDT_NPCM | ||
213 | 213 | It performs full SoC reset. |
214 | 214 | |
215 | 215 | config WDT_OCTEONTX |
216 | - bool "OcteonTX core watchdog support" | |
217 | - depends on WDT && (ARCH_OCTEONTX || ARCH_OCTEONTX2) | |
216 | + bool "Octeon core watchdog support" | |
217 | + depends on WDT && (ARCH_OCTEON || ARCH_OCTEONTX || ARCH_OCTEONTX2) | |
218 | 218 | default y |
219 | 219 | imply WATCHDOG |
220 | 220 | help |
221 | - This enables OcteonTX watchdog driver, which can be | |
222 | - found on OcteonTX/TX2 chipsets and inline with driver model. | |
223 | - Only supports watchdog reset. | |
221 | + This enables the Octeon watchdog driver, which can be found on | |
222 | + various Octeon parts such as Octeon II/III and OcteonTX/TX2. | |
224 | 223 | |
225 | 224 | config WDT_OMAP3 |
226 | 225 | bool "TI OMAP watchdog timer support" |
@@ -15,16 +15,22 @@ | ||
15 | 15 | |
16 | 16 | DECLARE_GLOBAL_DATA_PTR; |
17 | 17 | |
18 | -#define CORE0_WDOG_OFFSET 0x40000 | |
19 | -#define CORE0_POKE_OFFSET 0x50000 | |
20 | 18 | #define CORE0_POKE_OFFSET_MASK 0xfffffULL |
21 | 19 | |
22 | 20 | #define WDOG_MODE GENMASK_ULL(1, 0) |
23 | 21 | #define WDOG_LEN GENMASK_ULL(19, 4) |
24 | 22 | #define WDOG_CNT GENMASK_ULL(43, 20) |
25 | 23 | |
24 | +struct octeontx_wdt_data { | |
25 | + u32 wdog_offset; | |
26 | + u32 poke_offset; | |
27 | + int timer_shift; | |
28 | + bool has_clk; | |
29 | +}; | |
30 | + | |
26 | 31 | struct octeontx_wdt { |
27 | 32 | void __iomem *reg; |
33 | + const struct octeontx_wdt_data *data; | |
28 | 34 | struct clk clk; |
29 | 35 | }; |
30 | 36 |
@@ -34,12 +40,16 @@ static int octeontx_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) | ||
34 | 40 | u64 clk_rate, val; |
35 | 41 | u64 tout_wdog; |
36 | 42 | |
37 | - clk_rate = clk_get_rate(&priv->clk); | |
38 | - if (IS_ERR_VALUE(clk_rate)) | |
39 | - return -EINVAL; | |
43 | + if (priv->data->has_clk) { | |
44 | + clk_rate = clk_get_rate(&priv->clk); | |
45 | + if (IS_ERR_VALUE(clk_rate)) | |
46 | + return -EINVAL; | |
47 | + } else { | |
48 | + clk_rate = gd->bus_clk; | |
49 | + } | |
40 | 50 | |
41 | - /* Watchdog counts in 1024 cycle steps */ | |
42 | - tout_wdog = (clk_rate * timeout_ms / 1000) >> 10; | |
51 | + /* Watchdog counts in configured cycle steps */ | |
52 | + tout_wdog = (clk_rate * timeout_ms / 1000) >> priv->data->timer_shift; | |
43 | 53 | |
44 | 54 | /* |
45 | 55 | * We can only specify the upper 16 bits of a 24 bit value. |
@@ -54,7 +64,7 @@ static int octeontx_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags) | ||
54 | 64 | val = FIELD_PREP(WDOG_MODE, 0x3) | |
55 | 65 | FIELD_PREP(WDOG_LEN, tout_wdog) | |
56 | 66 | FIELD_PREP(WDOG_CNT, tout_wdog << 8); |
57 | - writeq(val, priv->reg + CORE0_WDOG_OFFSET); | |
67 | + writeq(val, priv->reg + priv->data->wdog_offset); | |
58 | 68 | |
59 | 69 | return 0; |
60 | 70 | } |
@@ -63,7 +73,7 @@ static int octeontx_wdt_stop(struct udevice *dev) | ||
63 | 73 | { |
64 | 74 | struct octeontx_wdt *priv = dev_get_priv(dev); |
65 | 75 | |
66 | - writeq(0, priv->reg + CORE0_WDOG_OFFSET); | |
76 | + writeq(0, priv->reg + priv->data->wdog_offset); | |
67 | 77 | |
68 | 78 | return 0; |
69 | 79 | } |
@@ -82,7 +92,7 @@ static int octeontx_wdt_reset(struct udevice *dev) | ||
82 | 92 | { |
83 | 93 | struct octeontx_wdt *priv = dev_get_priv(dev); |
84 | 94 | |
85 | - writeq(~0ULL, priv->reg + CORE0_POKE_OFFSET); | |
95 | + writeq(~0ULL, priv->reg + priv->data->poke_offset); | |
86 | 96 | |
87 | 97 | return 0; |
88 | 98 | } |
@@ -103,6 +113,10 @@ static int octeontx_wdt_probe(struct udevice *dev) | ||
103 | 113 | if (!priv->reg) |
104 | 114 | return -EINVAL; |
105 | 115 | |
116 | + priv->data = (void *)dev_get_driver_data(dev); | |
117 | + if (!priv->data) | |
118 | + return -EINVAL; | |
119 | + | |
106 | 120 | /* |
107 | 121 | * Save base register address in reg masking lower 20 bits |
108 | 122 | * as 0xa0000 appears when extracted from the DT |
@@ -110,13 +124,15 @@ static int octeontx_wdt_probe(struct udevice *dev) | ||
110 | 124 | priv->reg = (void __iomem *)(((u64)priv->reg & |
111 | 125 | ~CORE0_POKE_OFFSET_MASK)); |
112 | 126 | |
113 | - ret = clk_get_by_index(dev, 0, &priv->clk); | |
114 | - if (ret < 0) | |
115 | - return ret; | |
127 | + if (priv->data->has_clk) { | |
128 | + ret = clk_get_by_index(dev, 0, &priv->clk); | |
129 | + if (ret < 0) | |
130 | + return ret; | |
116 | 131 | |
117 | - ret = clk_enable(&priv->clk); | |
118 | - if (ret) | |
119 | - return ret; | |
132 | + ret = clk_enable(&priv->clk); | |
133 | + if (ret) | |
134 | + return ret; | |
135 | + } | |
120 | 136 | |
121 | 137 | return 0; |
122 | 138 | } |
@@ -128,8 +144,23 @@ static const struct wdt_ops octeontx_wdt_ops = { | ||
128 | 144 | .expire_now = octeontx_wdt_expire_now, |
129 | 145 | }; |
130 | 146 | |
147 | +static const struct octeontx_wdt_data octeontx_data = { | |
148 | + .wdog_offset = 0x40000, | |
149 | + .poke_offset = 0x50000, | |
150 | + .timer_shift = 10, | |
151 | + .has_clk = true, | |
152 | +}; | |
153 | + | |
154 | +static const struct octeontx_wdt_data octeon_data = { | |
155 | + .wdog_offset = 0x20000, | |
156 | + .poke_offset = 0x30000, | |
157 | + .timer_shift = 10, | |
158 | + .has_clk = false, | |
159 | +}; | |
160 | + | |
131 | 161 | static const struct udevice_id octeontx_wdt_ids[] = { |
132 | - { .compatible = "arm,sbsa-gwdt" }, | |
162 | + { .compatible = "arm,sbsa-gwdt", .data = (ulong)&octeontx_data }, | |
163 | + { .compatible = "cavium,octeon-7890-ciu3", .data = (ulong)&octeon_data }, | |
133 | 164 | {} |
134 | 165 | }; |
135 | 166 |
@@ -138,7 +169,7 @@ U_BOOT_DRIVER(wdt_octeontx) = { | ||
138 | 169 | .id = UCLASS_WDT, |
139 | 170 | .of_match = octeontx_wdt_ids, |
140 | 171 | .ops = &octeontx_wdt_ops, |
141 | - .priv_auto = sizeof(struct octeontx_wdt), | |
172 | + .priv_auto = sizeof(struct octeontx_wdt), | |
142 | 173 | .probe = octeontx_wdt_probe, |
143 | 174 | .remove = octeontx_wdt_remove, |
144 | 175 | .flags = DM_FLAG_OS_PREPARE, |