blob: 35e3ccebd72e6271ad49816be975139e86143a25 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada4fb96c42016-10-08 13:25:31 +09002/*
3 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +09005 * Author: Kunihiko Hayashi <hayashi.kunihiko@socionext.com>
Masahiro Yamada4fb96c42016-10-08 13:25:31 +09006 */
7
8#include <common.h>
Simon Glass9d922452017-05-17 17:18:03 -06009#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Simon Glass336d4612020-02-03 07:36:16 -070011#include <malloc.h>
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090012#include <reset-uclass.h>
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +090013#include <clk.h>
14#include <reset.h>
Simon Glass336d4612020-02-03 07:36:16 -070015#include <dm/device_compat.h>
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090016#include <linux/bitops.h>
17#include <linux/io.h>
18#include <linux/sizes.h>
19
20struct uniphier_reset_data {
21 unsigned int id;
22 unsigned int reg;
23 unsigned int bit;
24 unsigned int flags;
25#define UNIPHIER_RESET_ACTIVE_LOW BIT(0)
26};
27
28#define UNIPHIER_RESET_ID_END (unsigned int)(-1)
29
30#define UNIPHIER_RESET_END \
31 { .id = UNIPHIER_RESET_ID_END }
32
33#define UNIPHIER_RESET(_id, _reg, _bit) \
34 { \
35 .id = (_id), \
36 .reg = (_reg), \
37 .bit = (_bit), \
38 }
39
40#define UNIPHIER_RESETX(_id, _reg, _bit) \
41 { \
42 .id = (_id), \
43 .reg = (_reg), \
44 .bit = (_bit), \
45 .flags = UNIPHIER_RESET_ACTIVE_LOW, \
46 }
47
48/* System reset data */
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +090049static const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = {
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090050 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090051 UNIPHIER_RESETX(6, 0x2000, 12), /* ETHER */
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090052 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
53 UNIPHIER_RESETX(12, 0x2000, 6), /* GIO */
54 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
55 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
Kunihiko Hayashi34707b32021-07-06 19:01:07 +090056 UNIPHIER_RESETX(24, 0x2008, 2), /* PCIE */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090057 UNIPHIER_RESET_END,
58};
59
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +090060static const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = {
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090061 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090062 UNIPHIER_RESETX(6, 0x2000, 12), /* ETHER */
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090063 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
64 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
65 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090066 UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */
67 UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */
68 UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */
69 UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */
70 UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */
71 UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */
72 UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */
73 UNIPHIER_RESET_END,
74};
75
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +090076static const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = {
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090077 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
78 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090079 UNIPHIER_RESETX(6, 0x200c, 6), /* ETHER */
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090080 UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC */
Masahiro Yamada25ed0fe2018-06-19 16:11:43 +090081 UNIPHIER_RESETX(14, 0x200c, 5), /* USB30 */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090082 UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */
83 UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */
84 UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */
85 UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */
Kunihiko Hayashi34707b32021-07-06 19:01:07 +090086 UNIPHIER_RESETX(24, 0x200c, 4), /* PCIE */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090087 UNIPHIER_RESET_END,
88};
89
Masahiro Yamada111689e2017-08-29 12:20:51 +090090static const struct uniphier_reset_data uniphier_pxs3_sys_reset_data[] = {
91 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
92 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090093 UNIPHIER_RESETX(6, 0x200c, 9), /* ETHER0 */
94 UNIPHIER_RESETX(7, 0x200c, 10), /* ETHER1 */
Masahiro Yamada111689e2017-08-29 12:20:51 +090095 UNIPHIER_RESETX(8, 0x200c, 12), /* STDMAC */
Masahiro Yamada25ed0fe2018-06-19 16:11:43 +090096 UNIPHIER_RESETX(12, 0x200c, 4), /* USB30 link */
97 UNIPHIER_RESETX(13, 0x200c, 5), /* USB31 link */
98 UNIPHIER_RESETX(16, 0x200c, 16), /* USB30-PHY0 */
99 UNIPHIER_RESETX(17, 0x200c, 18), /* USB30-PHY1 */
100 UNIPHIER_RESETX(18, 0x200c, 20), /* USB30-PHY2 */
101 UNIPHIER_RESETX(20, 0x200c, 17), /* USB31-PHY0 */
102 UNIPHIER_RESETX(21, 0x200c, 19), /* USB31-PHY1 */
Kunihiko Hayashi34707b32021-07-06 19:01:07 +0900103 UNIPHIER_RESETX(24, 0x200c, 3), /* PCIE */
Masahiro Yamada111689e2017-08-29 12:20:51 +0900104 UNIPHIER_RESET_END,
105};
106
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900107/* Media I/O reset data */
108#define UNIPHIER_MIO_RESET_SD(id, ch) \
109 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0)
110
111#define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \
112 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26)
113
114#define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \
115 UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0)
116
117#define UNIPHIER_MIO_RESET_USB2(id, ch) \
118 UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0)
119
120#define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \
121 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24)
122
123#define UNIPHIER_MIO_RESET_DMAC(id) \
124 UNIPHIER_RESETX((id), 0x110, 17)
125
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +0900126static const struct uniphier_reset_data uniphier_mio_reset_data[] = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900127 UNIPHIER_MIO_RESET_SD(0, 0),
128 UNIPHIER_MIO_RESET_SD(1, 1),
129 UNIPHIER_MIO_RESET_SD(2, 2),
130 UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0),
131 UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1),
132 UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2),
133 UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1),
134 UNIPHIER_MIO_RESET_DMAC(7),
135 UNIPHIER_MIO_RESET_USB2(8, 0),
136 UNIPHIER_MIO_RESET_USB2(9, 1),
137 UNIPHIER_MIO_RESET_USB2(10, 2),
138 UNIPHIER_MIO_RESET_USB2(11, 3),
139 UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0),
140 UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1),
141 UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2),
142 UNIPHIER_MIO_RESET_USB2_BRIDGE(15, 3),
143 UNIPHIER_RESET_END,
144};
145
146/* Peripheral reset data */
147#define UNIPHIER_PERI_RESET_UART(id, ch) \
148 UNIPHIER_RESETX((id), 0x114, 19 + (ch))
149
150#define UNIPHIER_PERI_RESET_I2C(id, ch) \
151 UNIPHIER_RESETX((id), 0x114, 5 + (ch))
152
153#define UNIPHIER_PERI_RESET_FI2C(id, ch) \
154 UNIPHIER_RESETX((id), 0x114, 24 + (ch))
155
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +0900156static const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900157 UNIPHIER_PERI_RESET_UART(0, 0),
158 UNIPHIER_PERI_RESET_UART(1, 1),
159 UNIPHIER_PERI_RESET_UART(2, 2),
160 UNIPHIER_PERI_RESET_UART(3, 3),
161 UNIPHIER_PERI_RESET_I2C(4, 0),
162 UNIPHIER_PERI_RESET_I2C(5, 1),
163 UNIPHIER_PERI_RESET_I2C(6, 2),
164 UNIPHIER_PERI_RESET_I2C(7, 3),
165 UNIPHIER_PERI_RESET_I2C(8, 4),
166 UNIPHIER_RESET_END,
167};
168
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +0900169static const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900170 UNIPHIER_PERI_RESET_UART(0, 0),
171 UNIPHIER_PERI_RESET_UART(1, 1),
172 UNIPHIER_PERI_RESET_UART(2, 2),
173 UNIPHIER_PERI_RESET_UART(3, 3),
174 UNIPHIER_PERI_RESET_FI2C(4, 0),
175 UNIPHIER_PERI_RESET_FI2C(5, 1),
176 UNIPHIER_PERI_RESET_FI2C(6, 2),
177 UNIPHIER_PERI_RESET_FI2C(7, 3),
178 UNIPHIER_PERI_RESET_FI2C(8, 4),
179 UNIPHIER_PERI_RESET_FI2C(9, 5),
180 UNIPHIER_PERI_RESET_FI2C(10, 6),
181 UNIPHIER_RESET_END,
182};
183
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +0900184/* Glue reset data */
185static const struct uniphier_reset_data uniphier_pro4_usb3_reset_data[] = {
186 UNIPHIER_RESETX(15, 0, 15)
187};
188
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900189/* core implementaton */
190struct uniphier_reset_priv {
191 void __iomem *base;
192 const struct uniphier_reset_data *data;
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +0900193 struct clk_bulk clks;
194 struct reset_ctl_bulk rsts;
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900195};
196
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900197static int uniphier_reset_update(struct reset_ctl *reset_ctl, int assert)
198{
199 struct uniphier_reset_priv *priv = dev_get_priv(reset_ctl->dev);
200 unsigned long id = reset_ctl->id;
201 const struct uniphier_reset_data *p;
202
203 for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) {
204 u32 mask, val;
205
206 if (p->id != id)
207 continue;
208
209 val = readl(priv->base + p->reg);
210
211 if (p->flags & UNIPHIER_RESET_ACTIVE_LOW)
212 assert = !assert;
213
214 mask = BIT(p->bit);
215
216 if (assert)
217 val |= mask;
218 else
219 val &= ~mask;
220
221 writel(val, priv->base + p->reg);
222
223 return 0;
224 }
225
Masahiro Yamadadef4ead2017-10-13 19:22:02 +0900226 dev_err(reset_ctl->dev, "reset_id=%lu was not handled\n", id);
227
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900228 return -EINVAL;
229}
230
231static int uniphier_reset_assert(struct reset_ctl *reset_ctl)
232{
233 return uniphier_reset_update(reset_ctl, 1);
234}
235
236static int uniphier_reset_deassert(struct reset_ctl *reset_ctl)
237{
238 return uniphier_reset_update(reset_ctl, 0);
239}
240
241static const struct reset_ops uniphier_reset_ops = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900242 .rst_assert = uniphier_reset_assert,
243 .rst_deassert = uniphier_reset_deassert,
244};
245
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +0900246static int uniphier_reset_rst_init(struct udevice *dev)
247{
248 struct uniphier_reset_priv *priv = dev_get_priv(dev);
249 int ret;
250
251 ret = reset_get_bulk(dev, &priv->rsts);
252 if (ret == -ENOSYS || ret == -ENOENT)
253 return 0;
254 else if (ret)
255 return ret;
256
257 ret = reset_deassert_bulk(&priv->rsts);
258 if (ret)
259 reset_release_bulk(&priv->rsts);
260
261 return ret;
262}
263
264static int uniphier_reset_clk_init(struct udevice *dev)
265{
266 struct uniphier_reset_priv *priv = dev_get_priv(dev);
267 int ret;
268
269 ret = clk_get_bulk(dev, &priv->clks);
270 if (ret == -ENOSYS || ret == -ENOENT)
271 return 0;
272 if (ret)
273 return ret;
274
275 ret = clk_enable_bulk(&priv->clks);
276 if (ret)
277 clk_release_bulk(&priv->clks);
278
279 return ret;
280}
281
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900282static int uniphier_reset_probe(struct udevice *dev)
283{
284 struct uniphier_reset_priv *priv = dev_get_priv(dev);
285 fdt_addr_t addr;
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +0900286 int ret;
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900287
Masahiro Yamada25484932020-07-17 14:36:48 +0900288 addr = dev_read_addr(dev->parent);
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900289 if (addr == FDT_ADDR_T_NONE)
290 return -EINVAL;
291
292 priv->base = devm_ioremap(dev, addr, SZ_4K);
293 if (!priv->base)
294 return -ENOMEM;
295
296 priv->data = (void *)dev_get_driver_data(dev);
297
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +0900298 ret = uniphier_reset_clk_init(dev);
299 if (ret)
300 return ret;
301
302 return uniphier_reset_rst_init(dev);
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900303}
304
305static const struct udevice_id uniphier_reset_match[] = {
306 /* System reset */
307 {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900308 .compatible = "socionext,uniphier-ld4-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900309 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900310 },
311 {
312 .compatible = "socionext,uniphier-pro4-reset",
313 .data = (ulong)uniphier_pro4_sys_reset_data,
314 },
315 {
316 .compatible = "socionext,uniphier-sld8-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900317 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900318 },
319 {
320 .compatible = "socionext,uniphier-pro5-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900321 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900322 },
323 {
324 .compatible = "socionext,uniphier-pxs2-reset",
325 .data = (ulong)uniphier_pxs2_sys_reset_data,
326 },
327 {
328 .compatible = "socionext,uniphier-ld11-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900329 .data = (ulong)uniphier_ld20_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900330 },
331 {
332 .compatible = "socionext,uniphier-ld20-reset",
333 .data = (ulong)uniphier_ld20_sys_reset_data,
334 },
Masahiro Yamada111689e2017-08-29 12:20:51 +0900335 {
336 .compatible = "socionext,uniphier-pxs3-reset",
337 .data = (ulong)uniphier_pxs3_sys_reset_data,
338 },
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900339 /* Media I/O reset */
340 {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900341 .compatible = "socionext,uniphier-ld4-mio-reset",
342 .data = (ulong)uniphier_mio_reset_data,
343 },
344 {
345 .compatible = "socionext,uniphier-pro4-mio-reset",
346 .data = (ulong)uniphier_mio_reset_data,
347 },
348 {
349 .compatible = "socionext,uniphier-sld8-mio-reset",
350 .data = (ulong)uniphier_mio_reset_data,
351 },
352 {
353 .compatible = "socionext,uniphier-pro5-mio-reset",
354 .data = (ulong)uniphier_mio_reset_data,
355 },
356 {
357 .compatible = "socionext,uniphier-pxs2-mio-reset",
358 .data = (ulong)uniphier_mio_reset_data,
359 },
360 {
361 .compatible = "socionext,uniphier-ld11-mio-reset",
362 .data = (ulong)uniphier_mio_reset_data,
363 },
364 {
Masahiro Yamada1fc84d62017-08-29 12:20:50 +0900365 .compatible = "socionext,uniphier-ld11-sd-reset",
366 .data = (ulong)uniphier_mio_reset_data,
367 },
368 {
369 .compatible = "socionext,uniphier-ld20-sd-reset",
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900370 .data = (ulong)uniphier_mio_reset_data,
371 },
Masahiro Yamada111689e2017-08-29 12:20:51 +0900372 {
373 .compatible = "socionext,uniphier-pxs3-sd-reset",
374 .data = (ulong)uniphier_mio_reset_data,
375 },
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900376 /* Peripheral reset */
377 {
378 .compatible = "socionext,uniphier-ld4-peri-reset",
379 .data = (ulong)uniphier_ld4_peri_reset_data,
380 },
381 {
382 .compatible = "socionext,uniphier-pro4-peri-reset",
383 .data = (ulong)uniphier_pro4_peri_reset_data,
384 },
385 {
386 .compatible = "socionext,uniphier-sld8-peri-reset",
387 .data = (ulong)uniphier_ld4_peri_reset_data,
388 },
389 {
390 .compatible = "socionext,uniphier-pro5-peri-reset",
391 .data = (ulong)uniphier_pro4_peri_reset_data,
392 },
393 {
394 .compatible = "socionext,uniphier-pxs2-peri-reset",
395 .data = (ulong)uniphier_pro4_peri_reset_data,
396 },
397 {
398 .compatible = "socionext,uniphier-ld11-peri-reset",
399 .data = (ulong)uniphier_pro4_peri_reset_data,
400 },
401 {
402 .compatible = "socionext,uniphier-ld20-peri-reset",
403 .data = (ulong)uniphier_pro4_peri_reset_data,
404 },
Masahiro Yamada111689e2017-08-29 12:20:51 +0900405 {
406 .compatible = "socionext,uniphier-pxs3-peri-reset",
407 .data = (ulong)uniphier_pro4_peri_reset_data,
408 },
Kunihiko Hayashi1c866de2023-02-20 14:50:30 +0900409 /* USB glue reset */
410 {
411 .compatible = "socionext,uniphier-pro4-usb3-reset",
412 .data = (ulong)uniphier_pro4_usb3_reset_data,
413 },
414 {
415 .compatible = "socionext,uniphier-pro5-usb3-reset",
416 .data = (ulong)uniphier_pro4_usb3_reset_data,
417 },
418 {
419 .compatible = "socionext,uniphier-pxs2-usb3-reset",
420 .data = (ulong)uniphier_pro4_usb3_reset_data,
421 },
422 {
423 .compatible = "socionext,uniphier-ld20-usb3-reset",
424 .data = (ulong)uniphier_pro4_usb3_reset_data,
425 },
426 {
427 .compatible = "socionext,uniphier-pxs3-usb3-reset",
428 .data = (ulong)uniphier_pro4_usb3_reset_data,
429 },
430 {
431 .compatible = "socionext,uniphier-nx1-usb3-reset",
432 .data = (ulong)uniphier_pro4_usb3_reset_data,
433 },
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900434 { /* sentinel */ }
435};
436
437U_BOOT_DRIVER(uniphier_reset) = {
438 .name = "uniphier-reset",
439 .id = UCLASS_RESET,
440 .of_match = uniphier_reset_match,
441 .probe = uniphier_reset_probe,
Simon Glass41575d82020-12-03 16:55:17 -0700442 .priv_auto = sizeof(struct uniphier_reset_priv),
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900443 .ops = &uniphier_reset_ops,
444};