blob: 65a352b71fd7698f5c35d090b7e7db952bf58352 [file] [log] [blame]
Patrick Wildtdbc644f2019-10-03 16:08:35 +02001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2017, Impinj, Inc.
4 */
5
Simon Glass0f2af882020-05-10 11:40:05 -06006#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -07007#include <malloc.h>
Patrick Wildtdbc644f2019-10-03 16:08:35 +02008#include <asm/io.h>
Patrick Wildtdbc644f2019-10-03 16:08:35 +02009#include <dm.h>
10#include <dt-bindings/reset/imx7-reset.h>
Sumit Garg41e0ad52024-03-21 20:24:59 +053011#include <dt-bindings/reset/imx8mp-reset.h>
Patrick Wildtdbc644f2019-10-03 16:08:35 +020012#include <dt-bindings/reset/imx8mq-reset.h>
13#include <reset-uclass.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
Patrick Wildtdbc644f2019-10-03 16:08:35 +020016
Sumit Garg9ab2ffa2024-03-21 20:24:58 +053017struct imx_reset_priv {
Patrick Wildtdbc644f2019-10-03 16:08:35 +020018 void __iomem *base;
19 struct reset_ops ops;
20};
21
22struct imx7_src_signal {
23 unsigned int offset, bit;
24};
25
26enum imx7_src_registers {
27 SRC_A7RCR0 = 0x0004,
28 SRC_M4RCR = 0x000c,
29 SRC_ERCR = 0x0014,
30 SRC_HSICPHY_RCR = 0x001c,
31 SRC_USBOPHY1_RCR = 0x0020,
32 SRC_USBOPHY2_RCR = 0x0024,
33 SRC_MIPIPHY_RCR = 0x0028,
34 SRC_PCIEPHY_RCR = 0x002c,
35 SRC_DDRC_RCR = 0x1000,
36};
37
38static const struct imx7_src_signal imx7_src_signals[IMX7_RESET_NUM] = {
39 [IMX7_RESET_A7_CORE_POR_RESET0] = { SRC_A7RCR0, BIT(0) },
40 [IMX7_RESET_A7_CORE_POR_RESET1] = { SRC_A7RCR0, BIT(1) },
41 [IMX7_RESET_A7_CORE_RESET0] = { SRC_A7RCR0, BIT(4) },
42 [IMX7_RESET_A7_CORE_RESET1] = { SRC_A7RCR0, BIT(5) },
43 [IMX7_RESET_A7_DBG_RESET0] = { SRC_A7RCR0, BIT(8) },
44 [IMX7_RESET_A7_DBG_RESET1] = { SRC_A7RCR0, BIT(9) },
45 [IMX7_RESET_A7_ETM_RESET0] = { SRC_A7RCR0, BIT(12) },
46 [IMX7_RESET_A7_ETM_RESET1] = { SRC_A7RCR0, BIT(13) },
47 [IMX7_RESET_A7_SOC_DBG_RESET] = { SRC_A7RCR0, BIT(20) },
48 [IMX7_RESET_A7_L2RESET] = { SRC_A7RCR0, BIT(21) },
49 [IMX7_RESET_SW_M4C_RST] = { SRC_M4RCR, BIT(1) },
50 [IMX7_RESET_SW_M4P_RST] = { SRC_M4RCR, BIT(2) },
51 [IMX7_RESET_EIM_RST] = { SRC_ERCR, BIT(0) },
52 [IMX7_RESET_HSICPHY_PORT_RST] = { SRC_HSICPHY_RCR, BIT(1) },
53 [IMX7_RESET_USBPHY1_POR] = { SRC_USBOPHY1_RCR, BIT(0) },
54 [IMX7_RESET_USBPHY1_PORT_RST] = { SRC_USBOPHY1_RCR, BIT(1) },
55 [IMX7_RESET_USBPHY2_POR] = { SRC_USBOPHY2_RCR, BIT(0) },
56 [IMX7_RESET_USBPHY2_PORT_RST] = { SRC_USBOPHY2_RCR, BIT(1) },
57 [IMX7_RESET_MIPI_PHY_MRST] = { SRC_MIPIPHY_RCR, BIT(1) },
58 [IMX7_RESET_MIPI_PHY_SRST] = { SRC_MIPIPHY_RCR, BIT(2) },
59 [IMX7_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR, BIT(2) | BIT(1) },
60 [IMX7_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) },
61 [IMX7_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) },
62 [IMX7_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) },
63 [IMX7_RESET_DDRC_PRST] = { SRC_DDRC_RCR, BIT(0) },
64 [IMX7_RESET_DDRC_CORE_RST] = { SRC_DDRC_RCR, BIT(1) },
65};
66
Sumit Garg9ab2ffa2024-03-21 20:24:58 +053067static int imx7_reset_deassert(struct reset_ctl *rst)
Patrick Wildtdbc644f2019-10-03 16:08:35 +020068{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +053069 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +020070 const struct imx7_src_signal *sig = imx7_src_signals;
71 u32 val;
72
73 if (rst->id >= IMX7_RESET_NUM)
74 return -EINVAL;
75
76 if (rst->id == IMX7_RESET_PCIEPHY) {
77 /*
78 * wait for more than 10us to release phy g_rst and
79 * btnrst
80 */
81 udelay(10);
82 }
83
84 val = readl(priv->base + sig[rst->id].offset);
85 switch (rst->id) {
86 case IMX7_RESET_PCIE_CTRL_APPS_EN:
87 val |= sig[rst->id].bit;
88 break;
89 default:
90 val &= ~sig[rst->id].bit;
91 break;
92 }
93 writel(val, priv->base + sig[rst->id].offset);
94
95 return 0;
96}
97
Sumit Garg9ab2ffa2024-03-21 20:24:58 +053098static int imx7_reset_assert(struct reset_ctl *rst)
Patrick Wildtdbc644f2019-10-03 16:08:35 +020099{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530100 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200101 const struct imx7_src_signal *sig = imx7_src_signals;
102 u32 val;
103
104 if (rst->id >= IMX7_RESET_NUM)
105 return -EINVAL;
106
107 val = readl(priv->base + sig[rst->id].offset);
108 switch (rst->id) {
109 case IMX7_RESET_PCIE_CTRL_APPS_EN:
110 val &= ~sig[rst->id].bit;
111 break;
112 default:
113 val |= sig[rst->id].bit;
114 break;
115 }
116 writel(val, priv->base + sig[rst->id].offset);
117
118 return 0;
119}
120
121enum imx8mq_src_registers {
122 SRC_A53RCR0 = 0x0004,
123 SRC_HDMI_RCR = 0x0030,
124 SRC_DISP_RCR = 0x0034,
125 SRC_GPU_RCR = 0x0040,
126 SRC_VPU_RCR = 0x0044,
127 SRC_PCIE2_RCR = 0x0048,
128 SRC_MIPIPHY1_RCR = 0x004c,
129 SRC_MIPIPHY2_RCR = 0x0050,
130 SRC_DDRC2_RCR = 0x1004,
131};
132
133static const struct imx7_src_signal imx8mq_src_signals[IMX8MQ_RESET_NUM] = {
134 [IMX8MQ_RESET_A53_CORE_POR_RESET0] = { SRC_A53RCR0, BIT(0) },
135 [IMX8MQ_RESET_A53_CORE_POR_RESET1] = { SRC_A53RCR0, BIT(1) },
136 [IMX8MQ_RESET_A53_CORE_POR_RESET2] = { SRC_A53RCR0, BIT(2) },
137 [IMX8MQ_RESET_A53_CORE_POR_RESET3] = { SRC_A53RCR0, BIT(3) },
138 [IMX8MQ_RESET_A53_CORE_RESET0] = { SRC_A53RCR0, BIT(4) },
139 [IMX8MQ_RESET_A53_CORE_RESET1] = { SRC_A53RCR0, BIT(5) },
140 [IMX8MQ_RESET_A53_CORE_RESET2] = { SRC_A53RCR0, BIT(6) },
141 [IMX8MQ_RESET_A53_CORE_RESET3] = { SRC_A53RCR0, BIT(7) },
142 [IMX8MQ_RESET_A53_DBG_RESET0] = { SRC_A53RCR0, BIT(8) },
143 [IMX8MQ_RESET_A53_DBG_RESET1] = { SRC_A53RCR0, BIT(9) },
144 [IMX8MQ_RESET_A53_DBG_RESET2] = { SRC_A53RCR0, BIT(10) },
145 [IMX8MQ_RESET_A53_DBG_RESET3] = { SRC_A53RCR0, BIT(11) },
146 [IMX8MQ_RESET_A53_ETM_RESET0] = { SRC_A53RCR0, BIT(12) },
147 [IMX8MQ_RESET_A53_ETM_RESET1] = { SRC_A53RCR0, BIT(13) },
148 [IMX8MQ_RESET_A53_ETM_RESET2] = { SRC_A53RCR0, BIT(14) },
149 [IMX8MQ_RESET_A53_ETM_RESET3] = { SRC_A53RCR0, BIT(15) },
150 [IMX8MQ_RESET_A53_SOC_DBG_RESET] = { SRC_A53RCR0, BIT(20) },
151 [IMX8MQ_RESET_A53_L2RESET] = { SRC_A53RCR0, BIT(21) },
152 [IMX8MQ_RESET_SW_NON_SCLR_M4C_RST] = { SRC_M4RCR, BIT(0) },
153 [IMX8MQ_RESET_OTG1_PHY_RESET] = { SRC_USBOPHY1_RCR, BIT(0) },
154 [IMX8MQ_RESET_OTG2_PHY_RESET] = { SRC_USBOPHY2_RCR, BIT(0) },
155 [IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N] = { SRC_MIPIPHY_RCR, BIT(1) },
156 [IMX8MQ_RESET_MIPI_DSI_RESET_N] = { SRC_MIPIPHY_RCR, BIT(2) },
157 [IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N] = { SRC_MIPIPHY_RCR, BIT(3) },
158 [IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N] = { SRC_MIPIPHY_RCR, BIT(4) },
159 [IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N] = { SRC_MIPIPHY_RCR, BIT(5) },
160 [IMX8MQ_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR,
161 BIT(2) | BIT(1) },
162 [IMX8MQ_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) },
163 [IMX8MQ_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) },
164 [IMX8MQ_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) },
165 [IMX8MQ_RESET_HDMI_PHY_APB_RESET] = { SRC_HDMI_RCR, BIT(0) },
166 [IMX8MQ_RESET_DISP_RESET] = { SRC_DISP_RCR, BIT(0) },
167 [IMX8MQ_RESET_GPU_RESET] = { SRC_GPU_RCR, BIT(0) },
168 [IMX8MQ_RESET_VPU_RESET] = { SRC_VPU_RCR, BIT(0) },
169 [IMX8MQ_RESET_PCIEPHY2] = { SRC_PCIE2_RCR,
170 BIT(2) | BIT(1) },
171 [IMX8MQ_RESET_PCIEPHY2_PERST] = { SRC_PCIE2_RCR, BIT(3) },
172 [IMX8MQ_RESET_PCIE2_CTRL_APPS_EN] = { SRC_PCIE2_RCR, BIT(6) },
173 [IMX8MQ_RESET_PCIE2_CTRL_APPS_TURNOFF] = { SRC_PCIE2_RCR, BIT(11) },
174 [IMX8MQ_RESET_MIPI_CSI1_CORE_RESET] = { SRC_MIPIPHY1_RCR, BIT(0) },
175 [IMX8MQ_RESET_MIPI_CSI1_PHY_REF_RESET] = { SRC_MIPIPHY1_RCR, BIT(1) },
176 [IMX8MQ_RESET_MIPI_CSI1_ESC_RESET] = { SRC_MIPIPHY1_RCR, BIT(2) },
177 [IMX8MQ_RESET_MIPI_CSI2_CORE_RESET] = { SRC_MIPIPHY2_RCR, BIT(0) },
178 [IMX8MQ_RESET_MIPI_CSI2_PHY_REF_RESET] = { SRC_MIPIPHY2_RCR, BIT(1) },
179 [IMX8MQ_RESET_MIPI_CSI2_ESC_RESET] = { SRC_MIPIPHY2_RCR, BIT(2) },
180 [IMX8MQ_RESET_DDRC1_PRST] = { SRC_DDRC_RCR, BIT(0) },
181 [IMX8MQ_RESET_DDRC1_CORE_RESET] = { SRC_DDRC_RCR, BIT(1) },
182 [IMX8MQ_RESET_DDRC1_PHY_RESET] = { SRC_DDRC_RCR, BIT(2) },
183 [IMX8MQ_RESET_DDRC2_PHY_RESET] = { SRC_DDRC2_RCR, BIT(0) },
184 [IMX8MQ_RESET_DDRC2_CORE_RESET] = { SRC_DDRC2_RCR, BIT(1) },
185 [IMX8MQ_RESET_DDRC2_PRST] = { SRC_DDRC2_RCR, BIT(2) },
186};
187
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530188static int imx8mq_reset_deassert(struct reset_ctl *rst)
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200189{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530190 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200191 const struct imx7_src_signal *sig = imx8mq_src_signals;
192 u32 val;
193
194 if (rst->id >= IMX8MQ_RESET_NUM)
195 return -EINVAL;
196
197 if (rst->id == IMX8MQ_RESET_PCIEPHY ||
198 rst->id == IMX8MQ_RESET_PCIEPHY2) {
199 /*
200 * wait for more than 10us to release phy g_rst and
201 * btnrst
202 */
203 udelay(10);
204 }
205
206 val = readl(priv->base + sig[rst->id].offset);
207 switch (rst->id) {
208 case IMX8MQ_RESET_PCIE_CTRL_APPS_EN:
209 case IMX8MQ_RESET_PCIE2_CTRL_APPS_EN: /* fallthrough */
210 case IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N: /* fallthrough */
211 case IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N: /* fallthrough */
212 case IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N: /* fallthrough */
213 case IMX8MQ_RESET_MIPI_DSI_RESET_N: /* fallthrough */
214 case IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N: /* fallthrough */
215 val |= sig[rst->id].bit;
216 break;
217 default:
218 val &= ~sig[rst->id].bit;
219 break;
220 }
221 writel(val, priv->base + sig[rst->id].offset);
222
223 return 0;
224}
225
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530226static int imx8mq_reset_assert(struct reset_ctl *rst)
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200227{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530228 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200229 const struct imx7_src_signal *sig = imx8mq_src_signals;
230 u32 val;
231
232 if (rst->id >= IMX8MQ_RESET_NUM)
233 return -EINVAL;
234
235 val = readl(priv->base + sig[rst->id].offset);
236 switch (rst->id) {
237 case IMX8MQ_RESET_PCIE_CTRL_APPS_EN:
238 case IMX8MQ_RESET_PCIE2_CTRL_APPS_EN: /* fallthrough */
239 case IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N: /* fallthrough */
240 case IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N: /* fallthrough */
241 case IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N: /* fallthrough */
242 case IMX8MQ_RESET_MIPI_DSI_RESET_N: /* fallthrough */
243 case IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N: /* fallthrough */
244 val &= ~sig[rst->id].bit;
245 break;
246 default:
247 val |= sig[rst->id].bit;
248 break;
249 }
250 writel(val, priv->base + sig[rst->id].offset);
251
252 return 0;
253}
254
Sumit Garg41e0ad52024-03-21 20:24:59 +0530255enum imx8mp_src_registers {
256 SRC_SUPERMIX_RCR = 0x0018,
257 SRC_AUDIOMIX_RCR = 0x001c,
258 SRC_MLMIX_RCR = 0x0028,
259 SRC_GPU2D_RCR = 0x0038,
260 SRC_GPU3D_RCR = 0x003c,
261 SRC_VPU_G1_RCR = 0x0048,
262 SRC_VPU_G2_RCR = 0x004c,
263 SRC_VPUVC8KE_RCR = 0x0050,
264 SRC_NOC_RCR = 0x0054,
265};
266
267static const struct imx7_src_signal imx8mp_src_signals[IMX8MP_RESET_NUM] = {
268 [IMX8MP_RESET_A53_CORE_POR_RESET0] = { SRC_A53RCR0, BIT(0) },
269 [IMX8MP_RESET_A53_CORE_POR_RESET1] = { SRC_A53RCR0, BIT(1) },
270 [IMX8MP_RESET_A53_CORE_POR_RESET2] = { SRC_A53RCR0, BIT(2) },
271 [IMX8MP_RESET_A53_CORE_POR_RESET3] = { SRC_A53RCR0, BIT(3) },
272 [IMX8MP_RESET_A53_CORE_RESET0] = { SRC_A53RCR0, BIT(4) },
273 [IMX8MP_RESET_A53_CORE_RESET1] = { SRC_A53RCR0, BIT(5) },
274 [IMX8MP_RESET_A53_CORE_RESET2] = { SRC_A53RCR0, BIT(6) },
275 [IMX8MP_RESET_A53_CORE_RESET3] = { SRC_A53RCR0, BIT(7) },
276 [IMX8MP_RESET_A53_DBG_RESET0] = { SRC_A53RCR0, BIT(8) },
277 [IMX8MP_RESET_A53_DBG_RESET1] = { SRC_A53RCR0, BIT(9) },
278 [IMX8MP_RESET_A53_DBG_RESET2] = { SRC_A53RCR0, BIT(10) },
279 [IMX8MP_RESET_A53_DBG_RESET3] = { SRC_A53RCR0, BIT(11) },
280 [IMX8MP_RESET_A53_ETM_RESET0] = { SRC_A53RCR0, BIT(12) },
281 [IMX8MP_RESET_A53_ETM_RESET1] = { SRC_A53RCR0, BIT(13) },
282 [IMX8MP_RESET_A53_ETM_RESET2] = { SRC_A53RCR0, BIT(14) },
283 [IMX8MP_RESET_A53_ETM_RESET3] = { SRC_A53RCR0, BIT(15) },
284 [IMX8MP_RESET_A53_SOC_DBG_RESET] = { SRC_A53RCR0, BIT(20) },
285 [IMX8MP_RESET_A53_L2RESET] = { SRC_A53RCR0, BIT(21) },
286 [IMX8MP_RESET_SW_NON_SCLR_M7C_RST] = { SRC_M4RCR, BIT(0) },
287 [IMX8MP_RESET_OTG1_PHY_RESET] = { SRC_USBOPHY1_RCR, BIT(0) },
288 [IMX8MP_RESET_OTG2_PHY_RESET] = { SRC_USBOPHY2_RCR, BIT(0) },
289 [IMX8MP_RESET_SUPERMIX_RESET] = { SRC_SUPERMIX_RCR, BIT(0) },
290 [IMX8MP_RESET_AUDIOMIX_RESET] = { SRC_AUDIOMIX_RCR, BIT(0) },
291 [IMX8MP_RESET_MLMIX_RESET] = { SRC_MLMIX_RCR, BIT(0) },
292 [IMX8MP_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR, BIT(2) },
293 [IMX8MP_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) },
294 [IMX8MP_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) },
295 [IMX8MP_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) },
296 [IMX8MP_RESET_HDMI_PHY_APB_RESET] = { SRC_HDMI_RCR, BIT(0) },
297 [IMX8MP_RESET_MEDIA_RESET] = { SRC_DISP_RCR, BIT(0) },
298 [IMX8MP_RESET_GPU2D_RESET] = { SRC_GPU2D_RCR, BIT(0) },
299 [IMX8MP_RESET_GPU3D_RESET] = { SRC_GPU3D_RCR, BIT(0) },
300 [IMX8MP_RESET_GPU_RESET] = { SRC_GPU_RCR, BIT(0) },
301 [IMX8MP_RESET_VPU_RESET] = { SRC_VPU_RCR, BIT(0) },
302 [IMX8MP_RESET_VPU_G1_RESET] = { SRC_VPU_G1_RCR, BIT(0) },
303 [IMX8MP_RESET_VPU_G2_RESET] = { SRC_VPU_G2_RCR, BIT(0) },
304 [IMX8MP_RESET_VPUVC8KE_RESET] = { SRC_VPUVC8KE_RCR, BIT(0) },
305 [IMX8MP_RESET_NOC_RESET] = { SRC_NOC_RCR, BIT(0) },
306};
307
308static int imx8mp_reset_set(struct reset_ctl *rst, bool assert)
309{
310 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
311 unsigned int bit, value;
312
313 if (rst->id >= IMX8MP_RESET_NUM)
314 return -EINVAL;
315
316 bit = imx8mp_src_signals[rst->id].bit;
317 value = assert ? bit : 0;
318
319 switch (rst->id) {
320 case IMX8MP_RESET_PCIEPHY:
321 /*
322 * wait for more than 10us to release phy g_rst and
323 * btnrst
324 */
325 if (!assert)
326 udelay(10);
327 break;
328
329 case IMX8MP_RESET_PCIE_CTRL_APPS_EN:
330 case IMX8MP_RESET_PCIEPHY_PERST:
331 value = assert ? 0 : bit;
332 break;
333 }
334
335 clrsetbits_le32(priv->base + imx8mp_src_signals[rst->id].offset, bit,
336 value);
337
338 return 0;
339}
340
341static int imx8mp_reset_assert(struct reset_ctl *rst)
342{
343 return imx8mp_reset_set(rst, true);
344}
345
346static int imx8mp_reset_deassert(struct reset_ctl *rst)
347{
348 return imx8mp_reset_set(rst, false);
349}
350
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530351static int imx_reset_assert(struct reset_ctl *rst)
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200352{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530353 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200354 return priv->ops.rst_assert(rst);
355}
356
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530357static int imx_reset_deassert(struct reset_ctl *rst)
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200358{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530359 struct imx_reset_priv *priv = dev_get_priv(rst->dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200360 return priv->ops.rst_deassert(rst);
361}
362
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200363static const struct reset_ops imx7_reset_reset_ops = {
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530364 .rst_assert = imx_reset_assert,
365 .rst_deassert = imx_reset_deassert,
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200366};
367
368static const struct udevice_id imx7_reset_ids[] = {
369 { .compatible = "fsl,imx7d-src" },
370 { .compatible = "fsl,imx8mq-src" },
Sumit Garg41e0ad52024-03-21 20:24:59 +0530371 { .compatible = "fsl,imx8mp-src" },
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200372 { }
373};
374
375static int imx7_reset_probe(struct udevice *dev)
376{
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530377 struct imx_reset_priv *priv = dev_get_priv(dev);
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200378
379 priv->base = dev_remap_addr(dev);
380 if (!priv->base)
381 return -ENOMEM;
382
383 if (device_is_compatible(dev, "fsl,imx8mq-src")) {
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530384 priv->ops.rst_assert = imx8mq_reset_assert;
385 priv->ops.rst_deassert = imx8mq_reset_deassert;
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200386 } else if (device_is_compatible(dev, "fsl,imx7d-src")) {
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530387 priv->ops.rst_assert = imx7_reset_assert;
388 priv->ops.rst_deassert = imx7_reset_deassert;
Sumit Garg41e0ad52024-03-21 20:24:59 +0530389 } else if (device_is_compatible(dev, "fsl,imx8mp-src")) {
390 priv->ops.rst_assert = imx8mp_reset_assert;
391 priv->ops.rst_deassert = imx8mp_reset_deassert;
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200392 }
393
394 return 0;
395}
396
397U_BOOT_DRIVER(imx7_reset) = {
398 .name = "imx7_reset",
399 .id = UCLASS_RESET,
400 .of_match = imx7_reset_ids,
401 .ops = &imx7_reset_reset_ops,
402 .probe = imx7_reset_probe,
Sumit Garg9ab2ffa2024-03-21 20:24:58 +0530403 .priv_auto = sizeof(struct imx_reset_priv),
Patrick Wildtdbc644f2019-10-03 16:08:35 +0200404};