blob: 348f3886d1046310fbe3d85567ddbeaad620db68 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +09002/*
3 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +09005 */
6
7#include <common.h>
Simon Glass11c89f32017-05-17 17:18:03 -06008#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +090010#include <reset-uclass.h>
Simon Glass9bc15642020-02-03 07:36:16 -070011#include <dm/device_compat.h>
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +090012#include <linux/bitops.h>
13#include <linux/io.h>
14#include <linux/sizes.h>
15
16struct uniphier_reset_data {
17 unsigned int id;
18 unsigned int reg;
19 unsigned int bit;
20 unsigned int flags;
21#define UNIPHIER_RESET_ACTIVE_LOW BIT(0)
22};
23
24#define UNIPHIER_RESET_ID_END (unsigned int)(-1)
25
26#define UNIPHIER_RESET_END \
27 { .id = UNIPHIER_RESET_ID_END }
28
29#define UNIPHIER_RESET(_id, _reg, _bit) \
30 { \
31 .id = (_id), \
32 .reg = (_reg), \
33 .bit = (_bit), \
34 }
35
36#define UNIPHIER_RESETX(_id, _reg, _bit) \
37 { \
38 .id = (_id), \
39 .reg = (_reg), \
40 .bit = (_bit), \
41 .flags = UNIPHIER_RESET_ACTIVE_LOW, \
42 }
43
44/* System reset data */
Masahiro Yamada5e05c4d2017-06-22 16:42:04 +090045static const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = {
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +090046 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
Kunihiko Hayashi6cce8372018-04-18 10:06:07 +090047 UNIPHIER_RESETX(6, 0x2000, 12), /* ETHER */
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +090048 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
49 UNIPHIER_RESETX(12, 0x2000, 6), /* GIO */
50 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
51 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +090052 UNIPHIER_RESET_END,
53};
54
Masahiro Yamada5e05c4d2017-06-22 16:42:04 +090055static const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = {
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +090056 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
Kunihiko Hayashi6cce8372018-04-18 10:06:07 +090057 UNIPHIER_RESETX(6, 0x2000, 12), /* ETHER */
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +090058 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
59 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
60 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +090061 UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */
62 UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */
63 UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */
64 UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */
65 UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */
66 UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */
67 UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */
68 UNIPHIER_RESET_END,
69};
70
Masahiro Yamada5e05c4d2017-06-22 16:42:04 +090071static const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = {
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +090072 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
73 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
Kunihiko Hayashi6cce8372018-04-18 10:06:07 +090074 UNIPHIER_RESETX(6, 0x200c, 6), /* ETHER */
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +090075 UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC */
Masahiro Yamada096c4662018-06-19 16:11:43 +090076 UNIPHIER_RESETX(14, 0x200c, 5), /* USB30 */
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +090077 UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */
78 UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */
79 UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */
80 UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */
81 UNIPHIER_RESET_END,
82};
83
Masahiro Yamada8eb6a1c2017-08-29 12:20:51 +090084static const struct uniphier_reset_data uniphier_pxs3_sys_reset_data[] = {
85 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
86 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
Kunihiko Hayashi6cce8372018-04-18 10:06:07 +090087 UNIPHIER_RESETX(6, 0x200c, 9), /* ETHER0 */
88 UNIPHIER_RESETX(7, 0x200c, 10), /* ETHER1 */
Masahiro Yamada8eb6a1c2017-08-29 12:20:51 +090089 UNIPHIER_RESETX(8, 0x200c, 12), /* STDMAC */
Masahiro Yamada096c4662018-06-19 16:11:43 +090090 UNIPHIER_RESETX(12, 0x200c, 4), /* USB30 link */
91 UNIPHIER_RESETX(13, 0x200c, 5), /* USB31 link */
92 UNIPHIER_RESETX(16, 0x200c, 16), /* USB30-PHY0 */
93 UNIPHIER_RESETX(17, 0x200c, 18), /* USB30-PHY1 */
94 UNIPHIER_RESETX(18, 0x200c, 20), /* USB30-PHY2 */
95 UNIPHIER_RESETX(20, 0x200c, 17), /* USB31-PHY0 */
96 UNIPHIER_RESETX(21, 0x200c, 19), /* USB31-PHY1 */
Masahiro Yamada8eb6a1c2017-08-29 12:20:51 +090097 UNIPHIER_RESET_END,
98};
99
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900100/* Media I/O reset data */
101#define UNIPHIER_MIO_RESET_SD(id, ch) \
102 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0)
103
104#define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \
105 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26)
106
107#define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \
108 UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0)
109
110#define UNIPHIER_MIO_RESET_USB2(id, ch) \
111 UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0)
112
113#define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \
114 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24)
115
116#define UNIPHIER_MIO_RESET_DMAC(id) \
117 UNIPHIER_RESETX((id), 0x110, 17)
118
Masahiro Yamada5e05c4d2017-06-22 16:42:04 +0900119static const struct uniphier_reset_data uniphier_mio_reset_data[] = {
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900120 UNIPHIER_MIO_RESET_SD(0, 0),
121 UNIPHIER_MIO_RESET_SD(1, 1),
122 UNIPHIER_MIO_RESET_SD(2, 2),
123 UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0),
124 UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1),
125 UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2),
126 UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1),
127 UNIPHIER_MIO_RESET_DMAC(7),
128 UNIPHIER_MIO_RESET_USB2(8, 0),
129 UNIPHIER_MIO_RESET_USB2(9, 1),
130 UNIPHIER_MIO_RESET_USB2(10, 2),
131 UNIPHIER_MIO_RESET_USB2(11, 3),
132 UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0),
133 UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1),
134 UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2),
135 UNIPHIER_MIO_RESET_USB2_BRIDGE(15, 3),
136 UNIPHIER_RESET_END,
137};
138
139/* Peripheral reset data */
140#define UNIPHIER_PERI_RESET_UART(id, ch) \
141 UNIPHIER_RESETX((id), 0x114, 19 + (ch))
142
143#define UNIPHIER_PERI_RESET_I2C(id, ch) \
144 UNIPHIER_RESETX((id), 0x114, 5 + (ch))
145
146#define UNIPHIER_PERI_RESET_FI2C(id, ch) \
147 UNIPHIER_RESETX((id), 0x114, 24 + (ch))
148
Masahiro Yamada5e05c4d2017-06-22 16:42:04 +0900149static const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = {
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900150 UNIPHIER_PERI_RESET_UART(0, 0),
151 UNIPHIER_PERI_RESET_UART(1, 1),
152 UNIPHIER_PERI_RESET_UART(2, 2),
153 UNIPHIER_PERI_RESET_UART(3, 3),
154 UNIPHIER_PERI_RESET_I2C(4, 0),
155 UNIPHIER_PERI_RESET_I2C(5, 1),
156 UNIPHIER_PERI_RESET_I2C(6, 2),
157 UNIPHIER_PERI_RESET_I2C(7, 3),
158 UNIPHIER_PERI_RESET_I2C(8, 4),
159 UNIPHIER_RESET_END,
160};
161
Masahiro Yamada5e05c4d2017-06-22 16:42:04 +0900162static const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = {
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900163 UNIPHIER_PERI_RESET_UART(0, 0),
164 UNIPHIER_PERI_RESET_UART(1, 1),
165 UNIPHIER_PERI_RESET_UART(2, 2),
166 UNIPHIER_PERI_RESET_UART(3, 3),
167 UNIPHIER_PERI_RESET_FI2C(4, 0),
168 UNIPHIER_PERI_RESET_FI2C(5, 1),
169 UNIPHIER_PERI_RESET_FI2C(6, 2),
170 UNIPHIER_PERI_RESET_FI2C(7, 3),
171 UNIPHIER_PERI_RESET_FI2C(8, 4),
172 UNIPHIER_PERI_RESET_FI2C(9, 5),
173 UNIPHIER_PERI_RESET_FI2C(10, 6),
174 UNIPHIER_RESET_END,
175};
176
177/* core implementaton */
178struct uniphier_reset_priv {
179 void __iomem *base;
180 const struct uniphier_reset_data *data;
181};
182
183static int uniphier_reset_request(struct reset_ctl *reset_ctl)
184{
185 return 0;
186}
187
188static int uniphier_reset_free(struct reset_ctl *reset_ctl)
189{
190 return 0;
191}
192
193static int uniphier_reset_update(struct reset_ctl *reset_ctl, int assert)
194{
195 struct uniphier_reset_priv *priv = dev_get_priv(reset_ctl->dev);
196 unsigned long id = reset_ctl->id;
197 const struct uniphier_reset_data *p;
198
199 for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) {
200 u32 mask, val;
201
202 if (p->id != id)
203 continue;
204
205 val = readl(priv->base + p->reg);
206
207 if (p->flags & UNIPHIER_RESET_ACTIVE_LOW)
208 assert = !assert;
209
210 mask = BIT(p->bit);
211
212 if (assert)
213 val |= mask;
214 else
215 val &= ~mask;
216
217 writel(val, priv->base + p->reg);
218
219 return 0;
220 }
221
Masahiro Yamada63f42e32017-10-13 19:22:02 +0900222 dev_err(reset_ctl->dev, "reset_id=%lu was not handled\n", id);
223
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900224 return -EINVAL;
225}
226
227static int uniphier_reset_assert(struct reset_ctl *reset_ctl)
228{
229 return uniphier_reset_update(reset_ctl, 1);
230}
231
232static int uniphier_reset_deassert(struct reset_ctl *reset_ctl)
233{
234 return uniphier_reset_update(reset_ctl, 0);
235}
236
237static const struct reset_ops uniphier_reset_ops = {
238 .request = uniphier_reset_request,
Simon Glass1928cd42020-02-03 07:35:52 -0700239 .rfree = uniphier_reset_free,
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900240 .rst_assert = uniphier_reset_assert,
241 .rst_deassert = uniphier_reset_deassert,
242};
243
244static int uniphier_reset_probe(struct udevice *dev)
245{
246 struct uniphier_reset_priv *priv = dev_get_priv(dev);
247 fdt_addr_t addr;
248
Simon Glassba1dea42017-05-17 17:18:05 -0600249 addr = devfdt_get_addr(dev->parent);
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900250 if (addr == FDT_ADDR_T_NONE)
251 return -EINVAL;
252
253 priv->base = devm_ioremap(dev, addr, SZ_4K);
254 if (!priv->base)
255 return -ENOMEM;
256
257 priv->data = (void *)dev_get_driver_data(dev);
258
259 return 0;
260}
261
262static const struct udevice_id uniphier_reset_match[] = {
263 /* System reset */
264 {
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900265 .compatible = "socionext,uniphier-ld4-reset",
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +0900266 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900267 },
268 {
269 .compatible = "socionext,uniphier-pro4-reset",
270 .data = (ulong)uniphier_pro4_sys_reset_data,
271 },
272 {
273 .compatible = "socionext,uniphier-sld8-reset",
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +0900274 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900275 },
276 {
277 .compatible = "socionext,uniphier-pro5-reset",
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +0900278 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900279 },
280 {
281 .compatible = "socionext,uniphier-pxs2-reset",
282 .data = (ulong)uniphier_pxs2_sys_reset_data,
283 },
284 {
285 .compatible = "socionext,uniphier-ld11-reset",
Masahiro Yamada0eb2cec2017-08-13 09:01:16 +0900286 .data = (ulong)uniphier_ld20_sys_reset_data,
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900287 },
288 {
289 .compatible = "socionext,uniphier-ld20-reset",
290 .data = (ulong)uniphier_ld20_sys_reset_data,
291 },
Masahiro Yamada8eb6a1c2017-08-29 12:20:51 +0900292 {
293 .compatible = "socionext,uniphier-pxs3-reset",
294 .data = (ulong)uniphier_pxs3_sys_reset_data,
295 },
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900296 /* Media I/O reset */
297 {
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900298 .compatible = "socionext,uniphier-ld4-mio-reset",
299 .data = (ulong)uniphier_mio_reset_data,
300 },
301 {
302 .compatible = "socionext,uniphier-pro4-mio-reset",
303 .data = (ulong)uniphier_mio_reset_data,
304 },
305 {
306 .compatible = "socionext,uniphier-sld8-mio-reset",
307 .data = (ulong)uniphier_mio_reset_data,
308 },
309 {
310 .compatible = "socionext,uniphier-pro5-mio-reset",
311 .data = (ulong)uniphier_mio_reset_data,
312 },
313 {
314 .compatible = "socionext,uniphier-pxs2-mio-reset",
315 .data = (ulong)uniphier_mio_reset_data,
316 },
317 {
318 .compatible = "socionext,uniphier-ld11-mio-reset",
319 .data = (ulong)uniphier_mio_reset_data,
320 },
321 {
Masahiro Yamada68199a22017-08-29 12:20:50 +0900322 .compatible = "socionext,uniphier-ld11-sd-reset",
323 .data = (ulong)uniphier_mio_reset_data,
324 },
325 {
326 .compatible = "socionext,uniphier-ld20-sd-reset",
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900327 .data = (ulong)uniphier_mio_reset_data,
328 },
Masahiro Yamada8eb6a1c2017-08-29 12:20:51 +0900329 {
330 .compatible = "socionext,uniphier-pxs3-sd-reset",
331 .data = (ulong)uniphier_mio_reset_data,
332 },
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900333 /* Peripheral reset */
334 {
335 .compatible = "socionext,uniphier-ld4-peri-reset",
336 .data = (ulong)uniphier_ld4_peri_reset_data,
337 },
338 {
339 .compatible = "socionext,uniphier-pro4-peri-reset",
340 .data = (ulong)uniphier_pro4_peri_reset_data,
341 },
342 {
343 .compatible = "socionext,uniphier-sld8-peri-reset",
344 .data = (ulong)uniphier_ld4_peri_reset_data,
345 },
346 {
347 .compatible = "socionext,uniphier-pro5-peri-reset",
348 .data = (ulong)uniphier_pro4_peri_reset_data,
349 },
350 {
351 .compatible = "socionext,uniphier-pxs2-peri-reset",
352 .data = (ulong)uniphier_pro4_peri_reset_data,
353 },
354 {
355 .compatible = "socionext,uniphier-ld11-peri-reset",
356 .data = (ulong)uniphier_pro4_peri_reset_data,
357 },
358 {
359 .compatible = "socionext,uniphier-ld20-peri-reset",
360 .data = (ulong)uniphier_pro4_peri_reset_data,
361 },
Masahiro Yamada8eb6a1c2017-08-29 12:20:51 +0900362 {
363 .compatible = "socionext,uniphier-pxs3-peri-reset",
364 .data = (ulong)uniphier_pro4_peri_reset_data,
365 },
Masahiro Yamada2aa4b5b2016-10-08 13:25:31 +0900366 { /* sentinel */ }
367};
368
369U_BOOT_DRIVER(uniphier_reset) = {
370 .name = "uniphier-reset",
371 .id = UCLASS_RESET,
372 .of_match = uniphier_reset_match,
373 .probe = uniphier_reset_probe,
374 .priv_auto_alloc_size = sizeof(struct uniphier_reset_priv),
375 .ops = &uniphier_reset_ops,
376};