blob: 657243ae62073f8ae623112c98b3bcb037a6a07e [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>
Masahiro Yamada4fb96c42016-10-08 13:25:31 +09005 */
6
7#include <common.h>
Simon Glass9d922452017-05-17 17:18:03 -06008#include <dm.h>
Masahiro Yamada4fb96c42016-10-08 13:25:31 +09009#include <reset-uclass.h>
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090010#include <linux/bitops.h>
11#include <linux/io.h>
12#include <linux/sizes.h>
13
14struct uniphier_reset_data {
15 unsigned int id;
16 unsigned int reg;
17 unsigned int bit;
18 unsigned int flags;
19#define UNIPHIER_RESET_ACTIVE_LOW BIT(0)
20};
21
22#define UNIPHIER_RESET_ID_END (unsigned int)(-1)
23
24#define UNIPHIER_RESET_END \
25 { .id = UNIPHIER_RESET_ID_END }
26
27#define UNIPHIER_RESET(_id, _reg, _bit) \
28 { \
29 .id = (_id), \
30 .reg = (_reg), \
31 .bit = (_bit), \
32 }
33
34#define UNIPHIER_RESETX(_id, _reg, _bit) \
35 { \
36 .id = (_id), \
37 .reg = (_reg), \
38 .bit = (_bit), \
39 .flags = UNIPHIER_RESET_ACTIVE_LOW, \
40 }
41
42/* System reset data */
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +090043static const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = {
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090044 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090045 UNIPHIER_RESETX(6, 0x2000, 12), /* ETHER */
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090046 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
47 UNIPHIER_RESETX(12, 0x2000, 6), /* GIO */
48 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
49 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090050 UNIPHIER_RESET_END,
51};
52
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +090053static const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = {
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090054 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090055 UNIPHIER_RESETX(6, 0x2000, 12), /* ETHER */
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090056 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
57 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
58 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090059 UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */
60 UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */
61 UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */
62 UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */
63 UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */
64 UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */
65 UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */
66 UNIPHIER_RESET_END,
67};
68
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +090069static const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = {
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090070 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
71 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090072 UNIPHIER_RESETX(6, 0x200c, 6), /* ETHER */
Masahiro Yamada6584b1e2017-08-13 09:01:16 +090073 UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC */
74 UNIPHIER_RESETX(12, 0x200c, 5), /* GIO */
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090075 UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */
76 UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */
77 UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */
78 UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */
79 UNIPHIER_RESET_END,
80};
81
Masahiro Yamada111689e2017-08-29 12:20:51 +090082static const struct uniphier_reset_data uniphier_pxs3_sys_reset_data[] = {
83 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
84 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
Kunihiko Hayashif8c08ab2018-04-18 10:06:07 +090085 UNIPHIER_RESETX(6, 0x200c, 9), /* ETHER0 */
86 UNIPHIER_RESETX(7, 0x200c, 10), /* ETHER1 */
Masahiro Yamada111689e2017-08-29 12:20:51 +090087 UNIPHIER_RESETX(8, 0x200c, 12), /* STDMAC */
88 UNIPHIER_RESETX(12, 0x200c, 5), /* USB30 (GIO0) */
89 UNIPHIER_RESETX(13, 0x200c, 6), /* USB31 (GIO1) */
90 UNIPHIER_RESETX(16, 0x200c, 16), /* USB30-PHY */
91 UNIPHIER_RESETX(20, 0x200c, 17), /* USB31-PHY */
92 UNIPHIER_RESET_END,
93};
94
Masahiro Yamada4fb96c42016-10-08 13:25:31 +090095/* Media I/O reset data */
96#define UNIPHIER_MIO_RESET_SD(id, ch) \
97 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0)
98
99#define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \
100 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26)
101
102#define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \
103 UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0)
104
105#define UNIPHIER_MIO_RESET_USB2(id, ch) \
106 UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0)
107
108#define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \
109 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24)
110
111#define UNIPHIER_MIO_RESET_DMAC(id) \
112 UNIPHIER_RESETX((id), 0x110, 17)
113
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +0900114static const struct uniphier_reset_data uniphier_mio_reset_data[] = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900115 UNIPHIER_MIO_RESET_SD(0, 0),
116 UNIPHIER_MIO_RESET_SD(1, 1),
117 UNIPHIER_MIO_RESET_SD(2, 2),
118 UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0),
119 UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1),
120 UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2),
121 UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1),
122 UNIPHIER_MIO_RESET_DMAC(7),
123 UNIPHIER_MIO_RESET_USB2(8, 0),
124 UNIPHIER_MIO_RESET_USB2(9, 1),
125 UNIPHIER_MIO_RESET_USB2(10, 2),
126 UNIPHIER_MIO_RESET_USB2(11, 3),
127 UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0),
128 UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1),
129 UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2),
130 UNIPHIER_MIO_RESET_USB2_BRIDGE(15, 3),
131 UNIPHIER_RESET_END,
132};
133
134/* Peripheral reset data */
135#define UNIPHIER_PERI_RESET_UART(id, ch) \
136 UNIPHIER_RESETX((id), 0x114, 19 + (ch))
137
138#define UNIPHIER_PERI_RESET_I2C(id, ch) \
139 UNIPHIER_RESETX((id), 0x114, 5 + (ch))
140
141#define UNIPHIER_PERI_RESET_FI2C(id, ch) \
142 UNIPHIER_RESETX((id), 0x114, 24 + (ch))
143
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +0900144static const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900145 UNIPHIER_PERI_RESET_UART(0, 0),
146 UNIPHIER_PERI_RESET_UART(1, 1),
147 UNIPHIER_PERI_RESET_UART(2, 2),
148 UNIPHIER_PERI_RESET_UART(3, 3),
149 UNIPHIER_PERI_RESET_I2C(4, 0),
150 UNIPHIER_PERI_RESET_I2C(5, 1),
151 UNIPHIER_PERI_RESET_I2C(6, 2),
152 UNIPHIER_PERI_RESET_I2C(7, 3),
153 UNIPHIER_PERI_RESET_I2C(8, 4),
154 UNIPHIER_RESET_END,
155};
156
Masahiro Yamada1d21e1b2017-06-22 16:42:04 +0900157static const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900158 UNIPHIER_PERI_RESET_UART(0, 0),
159 UNIPHIER_PERI_RESET_UART(1, 1),
160 UNIPHIER_PERI_RESET_UART(2, 2),
161 UNIPHIER_PERI_RESET_UART(3, 3),
162 UNIPHIER_PERI_RESET_FI2C(4, 0),
163 UNIPHIER_PERI_RESET_FI2C(5, 1),
164 UNIPHIER_PERI_RESET_FI2C(6, 2),
165 UNIPHIER_PERI_RESET_FI2C(7, 3),
166 UNIPHIER_PERI_RESET_FI2C(8, 4),
167 UNIPHIER_PERI_RESET_FI2C(9, 5),
168 UNIPHIER_PERI_RESET_FI2C(10, 6),
169 UNIPHIER_RESET_END,
170};
171
172/* core implementaton */
173struct uniphier_reset_priv {
174 void __iomem *base;
175 const struct uniphier_reset_data *data;
176};
177
178static int uniphier_reset_request(struct reset_ctl *reset_ctl)
179{
180 return 0;
181}
182
183static int uniphier_reset_free(struct reset_ctl *reset_ctl)
184{
185 return 0;
186}
187
188static int uniphier_reset_update(struct reset_ctl *reset_ctl, int assert)
189{
190 struct uniphier_reset_priv *priv = dev_get_priv(reset_ctl->dev);
191 unsigned long id = reset_ctl->id;
192 const struct uniphier_reset_data *p;
193
194 for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) {
195 u32 mask, val;
196
197 if (p->id != id)
198 continue;
199
200 val = readl(priv->base + p->reg);
201
202 if (p->flags & UNIPHIER_RESET_ACTIVE_LOW)
203 assert = !assert;
204
205 mask = BIT(p->bit);
206
207 if (assert)
208 val |= mask;
209 else
210 val &= ~mask;
211
212 writel(val, priv->base + p->reg);
213
214 return 0;
215 }
216
Masahiro Yamadadef4ead2017-10-13 19:22:02 +0900217 dev_err(reset_ctl->dev, "reset_id=%lu was not handled\n", id);
218
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900219 return -EINVAL;
220}
221
222static int uniphier_reset_assert(struct reset_ctl *reset_ctl)
223{
224 return uniphier_reset_update(reset_ctl, 1);
225}
226
227static int uniphier_reset_deassert(struct reset_ctl *reset_ctl)
228{
229 return uniphier_reset_update(reset_ctl, 0);
230}
231
232static const struct reset_ops uniphier_reset_ops = {
233 .request = uniphier_reset_request,
234 .free = uniphier_reset_free,
235 .rst_assert = uniphier_reset_assert,
236 .rst_deassert = uniphier_reset_deassert,
237};
238
239static int uniphier_reset_probe(struct udevice *dev)
240{
241 struct uniphier_reset_priv *priv = dev_get_priv(dev);
242 fdt_addr_t addr;
243
Simon Glassa821c4a2017-05-17 17:18:05 -0600244 addr = devfdt_get_addr(dev->parent);
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900245 if (addr == FDT_ADDR_T_NONE)
246 return -EINVAL;
247
248 priv->base = devm_ioremap(dev, addr, SZ_4K);
249 if (!priv->base)
250 return -ENOMEM;
251
252 priv->data = (void *)dev_get_driver_data(dev);
253
254 return 0;
255}
256
257static const struct udevice_id uniphier_reset_match[] = {
258 /* System reset */
259 {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900260 .compatible = "socionext,uniphier-ld4-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900261 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900262 },
263 {
264 .compatible = "socionext,uniphier-pro4-reset",
265 .data = (ulong)uniphier_pro4_sys_reset_data,
266 },
267 {
268 .compatible = "socionext,uniphier-sld8-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900269 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900270 },
271 {
272 .compatible = "socionext,uniphier-pro5-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900273 .data = (ulong)uniphier_pro4_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900274 },
275 {
276 .compatible = "socionext,uniphier-pxs2-reset",
277 .data = (ulong)uniphier_pxs2_sys_reset_data,
278 },
279 {
280 .compatible = "socionext,uniphier-ld11-reset",
Masahiro Yamada6584b1e2017-08-13 09:01:16 +0900281 .data = (ulong)uniphier_ld20_sys_reset_data,
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900282 },
283 {
284 .compatible = "socionext,uniphier-ld20-reset",
285 .data = (ulong)uniphier_ld20_sys_reset_data,
286 },
Masahiro Yamada111689e2017-08-29 12:20:51 +0900287 {
288 .compatible = "socionext,uniphier-pxs3-reset",
289 .data = (ulong)uniphier_pxs3_sys_reset_data,
290 },
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900291 /* Media I/O reset */
292 {
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900293 .compatible = "socionext,uniphier-ld4-mio-reset",
294 .data = (ulong)uniphier_mio_reset_data,
295 },
296 {
297 .compatible = "socionext,uniphier-pro4-mio-reset",
298 .data = (ulong)uniphier_mio_reset_data,
299 },
300 {
301 .compatible = "socionext,uniphier-sld8-mio-reset",
302 .data = (ulong)uniphier_mio_reset_data,
303 },
304 {
305 .compatible = "socionext,uniphier-pro5-mio-reset",
306 .data = (ulong)uniphier_mio_reset_data,
307 },
308 {
309 .compatible = "socionext,uniphier-pxs2-mio-reset",
310 .data = (ulong)uniphier_mio_reset_data,
311 },
312 {
313 .compatible = "socionext,uniphier-ld11-mio-reset",
314 .data = (ulong)uniphier_mio_reset_data,
315 },
316 {
Masahiro Yamada1fc84d62017-08-29 12:20:50 +0900317 .compatible = "socionext,uniphier-ld11-sd-reset",
318 .data = (ulong)uniphier_mio_reset_data,
319 },
320 {
321 .compatible = "socionext,uniphier-ld20-sd-reset",
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900322 .data = (ulong)uniphier_mio_reset_data,
323 },
Masahiro Yamada111689e2017-08-29 12:20:51 +0900324 {
325 .compatible = "socionext,uniphier-pxs3-sd-reset",
326 .data = (ulong)uniphier_mio_reset_data,
327 },
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900328 /* Peripheral reset */
329 {
330 .compatible = "socionext,uniphier-ld4-peri-reset",
331 .data = (ulong)uniphier_ld4_peri_reset_data,
332 },
333 {
334 .compatible = "socionext,uniphier-pro4-peri-reset",
335 .data = (ulong)uniphier_pro4_peri_reset_data,
336 },
337 {
338 .compatible = "socionext,uniphier-sld8-peri-reset",
339 .data = (ulong)uniphier_ld4_peri_reset_data,
340 },
341 {
342 .compatible = "socionext,uniphier-pro5-peri-reset",
343 .data = (ulong)uniphier_pro4_peri_reset_data,
344 },
345 {
346 .compatible = "socionext,uniphier-pxs2-peri-reset",
347 .data = (ulong)uniphier_pro4_peri_reset_data,
348 },
349 {
350 .compatible = "socionext,uniphier-ld11-peri-reset",
351 .data = (ulong)uniphier_pro4_peri_reset_data,
352 },
353 {
354 .compatible = "socionext,uniphier-ld20-peri-reset",
355 .data = (ulong)uniphier_pro4_peri_reset_data,
356 },
Masahiro Yamada111689e2017-08-29 12:20:51 +0900357 {
358 .compatible = "socionext,uniphier-pxs3-peri-reset",
359 .data = (ulong)uniphier_pro4_peri_reset_data,
360 },
Masahiro Yamada4fb96c42016-10-08 13:25:31 +0900361 { /* sentinel */ }
362};
363
364U_BOOT_DRIVER(uniphier_reset) = {
365 .name = "uniphier-reset",
366 .id = UCLASS_RESET,
367 .of_match = uniphier_reset_match,
368 .probe = uniphier_reset_probe,
369 .priv_auto_alloc_size = sizeof(struct uniphier_reset_priv),
370 .ops = &uniphier_reset_ops,
371};