2 * Copyright (C) 2016 Socionext Inc.
5 * SPDX-License-Identifier: GPL-2.0+
10 #include <reset-uclass.h>
11 #include <linux/bitops.h>
13 #include <linux/sizes.h>
15 struct uniphier_reset_data {
20 #define UNIPHIER_RESET_ACTIVE_LOW BIT(0)
23 #define UNIPHIER_RESET_ID_END (unsigned int)(-1)
25 #define UNIPHIER_RESET_END \
26 { .id = UNIPHIER_RESET_ID_END }
28 #define UNIPHIER_RESET(_id, _reg, _bit) \
35 #define UNIPHIER_RESETX(_id, _reg, _bit) \
40 .flags = UNIPHIER_RESET_ACTIVE_LOW, \
43 /* System reset data */
44 static const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = {
45 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
46 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 */
53 static const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = {
54 UNIPHIER_RESETX(2, 0x2000, 2), /* NAND */
55 UNIPHIER_RESETX(8, 0x2000, 10), /* STDMAC */
56 UNIPHIER_RESETX(14, 0x2000, 17), /* USB30 */
57 UNIPHIER_RESETX(15, 0x2004, 17), /* USB31 */
58 UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */
59 UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */
60 UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */
61 UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */
62 UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */
63 UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */
64 UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */
68 static const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = {
69 UNIPHIER_RESETX(2, 0x200c, 0), /* NAND */
70 UNIPHIER_RESETX(4, 0x200c, 2), /* eMMC */
71 UNIPHIER_RESETX(8, 0x200c, 8), /* STDMAC */
72 UNIPHIER_RESETX(12, 0x200c, 5), /* GIO */
73 UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */
74 UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */
75 UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */
76 UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */
80 /* Media I/O reset data */
81 #define UNIPHIER_MIO_RESET_SD(id, ch) \
82 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0)
84 #define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \
85 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26)
87 #define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \
88 UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0)
90 #define UNIPHIER_MIO_RESET_USB2(id, ch) \
91 UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0)
93 #define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \
94 UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24)
96 #define UNIPHIER_MIO_RESET_DMAC(id) \
97 UNIPHIER_RESETX((id), 0x110, 17)
99 static const struct uniphier_reset_data uniphier_mio_reset_data[] = {
100 UNIPHIER_MIO_RESET_SD(0, 0),
101 UNIPHIER_MIO_RESET_SD(1, 1),
102 UNIPHIER_MIO_RESET_SD(2, 2),
103 UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0),
104 UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1),
105 UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2),
106 UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1),
107 UNIPHIER_MIO_RESET_DMAC(7),
108 UNIPHIER_MIO_RESET_USB2(8, 0),
109 UNIPHIER_MIO_RESET_USB2(9, 1),
110 UNIPHIER_MIO_RESET_USB2(10, 2),
111 UNIPHIER_MIO_RESET_USB2(11, 3),
112 UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0),
113 UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1),
114 UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2),
115 UNIPHIER_MIO_RESET_USB2_BRIDGE(15, 3),
119 /* Peripheral reset data */
120 #define UNIPHIER_PERI_RESET_UART(id, ch) \
121 UNIPHIER_RESETX((id), 0x114, 19 + (ch))
123 #define UNIPHIER_PERI_RESET_I2C(id, ch) \
124 UNIPHIER_RESETX((id), 0x114, 5 + (ch))
126 #define UNIPHIER_PERI_RESET_FI2C(id, ch) \
127 UNIPHIER_RESETX((id), 0x114, 24 + (ch))
129 static const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = {
130 UNIPHIER_PERI_RESET_UART(0, 0),
131 UNIPHIER_PERI_RESET_UART(1, 1),
132 UNIPHIER_PERI_RESET_UART(2, 2),
133 UNIPHIER_PERI_RESET_UART(3, 3),
134 UNIPHIER_PERI_RESET_I2C(4, 0),
135 UNIPHIER_PERI_RESET_I2C(5, 1),
136 UNIPHIER_PERI_RESET_I2C(6, 2),
137 UNIPHIER_PERI_RESET_I2C(7, 3),
138 UNIPHIER_PERI_RESET_I2C(8, 4),
142 static const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = {
143 UNIPHIER_PERI_RESET_UART(0, 0),
144 UNIPHIER_PERI_RESET_UART(1, 1),
145 UNIPHIER_PERI_RESET_UART(2, 2),
146 UNIPHIER_PERI_RESET_UART(3, 3),
147 UNIPHIER_PERI_RESET_FI2C(4, 0),
148 UNIPHIER_PERI_RESET_FI2C(5, 1),
149 UNIPHIER_PERI_RESET_FI2C(6, 2),
150 UNIPHIER_PERI_RESET_FI2C(7, 3),
151 UNIPHIER_PERI_RESET_FI2C(8, 4),
152 UNIPHIER_PERI_RESET_FI2C(9, 5),
153 UNIPHIER_PERI_RESET_FI2C(10, 6),
157 /* core implementaton */
158 struct uniphier_reset_priv {
160 const struct uniphier_reset_data *data;
163 static int uniphier_reset_request(struct reset_ctl *reset_ctl)
168 static int uniphier_reset_free(struct reset_ctl *reset_ctl)
173 static int uniphier_reset_update(struct reset_ctl *reset_ctl, int assert)
175 struct uniphier_reset_priv *priv = dev_get_priv(reset_ctl->dev);
176 unsigned long id = reset_ctl->id;
177 const struct uniphier_reset_data *p;
179 for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) {
185 val = readl(priv->base + p->reg);
187 if (p->flags & UNIPHIER_RESET_ACTIVE_LOW)
197 writel(val, priv->base + p->reg);
202 dev_err(priv->dev, "reset_id=%lu was not handled\n", id);
206 static int uniphier_reset_assert(struct reset_ctl *reset_ctl)
208 return uniphier_reset_update(reset_ctl, 1);
211 static int uniphier_reset_deassert(struct reset_ctl *reset_ctl)
213 return uniphier_reset_update(reset_ctl, 0);
216 static const struct reset_ops uniphier_reset_ops = {
217 .request = uniphier_reset_request,
218 .free = uniphier_reset_free,
219 .rst_assert = uniphier_reset_assert,
220 .rst_deassert = uniphier_reset_deassert,
223 static int uniphier_reset_probe(struct udevice *dev)
225 struct uniphier_reset_priv *priv = dev_get_priv(dev);
228 addr = devfdt_get_addr(dev->parent);
229 if (addr == FDT_ADDR_T_NONE)
232 priv->base = devm_ioremap(dev, addr, SZ_4K);
236 priv->data = (void *)dev_get_driver_data(dev);
241 static const struct udevice_id uniphier_reset_match[] = {
244 .compatible = "socionext,uniphier-ld4-reset",
245 .data = (ulong)uniphier_pro4_sys_reset_data,
248 .compatible = "socionext,uniphier-pro4-reset",
249 .data = (ulong)uniphier_pro4_sys_reset_data,
252 .compatible = "socionext,uniphier-sld8-reset",
253 .data = (ulong)uniphier_pro4_sys_reset_data,
256 .compatible = "socionext,uniphier-pro5-reset",
257 .data = (ulong)uniphier_pro4_sys_reset_data,
260 .compatible = "socionext,uniphier-pxs2-reset",
261 .data = (ulong)uniphier_pxs2_sys_reset_data,
264 .compatible = "socionext,uniphier-ld11-reset",
265 .data = (ulong)uniphier_ld20_sys_reset_data,
268 .compatible = "socionext,uniphier-ld20-reset",
269 .data = (ulong)uniphier_ld20_sys_reset_data,
271 /* Media I/O reset */
273 .compatible = "socionext,uniphier-ld4-mio-reset",
274 .data = (ulong)uniphier_mio_reset_data,
277 .compatible = "socionext,uniphier-pro4-mio-reset",
278 .data = (ulong)uniphier_mio_reset_data,
281 .compatible = "socionext,uniphier-sld8-mio-reset",
282 .data = (ulong)uniphier_mio_reset_data,
285 .compatible = "socionext,uniphier-pro5-mio-reset",
286 .data = (ulong)uniphier_mio_reset_data,
289 .compatible = "socionext,uniphier-pxs2-mio-reset",
290 .data = (ulong)uniphier_mio_reset_data,
293 .compatible = "socionext,uniphier-ld11-mio-reset",
294 .data = (ulong)uniphier_mio_reset_data,
297 .compatible = "socionext,uniphier-ld20-mio-reset",
298 .data = (ulong)uniphier_mio_reset_data,
300 /* Peripheral reset */
302 .compatible = "socionext,uniphier-ld4-peri-reset",
303 .data = (ulong)uniphier_ld4_peri_reset_data,
306 .compatible = "socionext,uniphier-pro4-peri-reset",
307 .data = (ulong)uniphier_pro4_peri_reset_data,
310 .compatible = "socionext,uniphier-sld8-peri-reset",
311 .data = (ulong)uniphier_ld4_peri_reset_data,
314 .compatible = "socionext,uniphier-pro5-peri-reset",
315 .data = (ulong)uniphier_pro4_peri_reset_data,
318 .compatible = "socionext,uniphier-pxs2-peri-reset",
319 .data = (ulong)uniphier_pro4_peri_reset_data,
322 .compatible = "socionext,uniphier-ld11-peri-reset",
323 .data = (ulong)uniphier_pro4_peri_reset_data,
326 .compatible = "socionext,uniphier-ld20-peri-reset",
327 .data = (ulong)uniphier_pro4_peri_reset_data,
332 U_BOOT_DRIVER(uniphier_reset) = {
333 .name = "uniphier-reset",
335 .of_match = uniphier_reset_match,
336 .probe = uniphier_reset_probe,
337 .priv_auto_alloc_size = sizeof(struct uniphier_reset_priv),
338 .ops = &uniphier_reset_ops,