xref: /linux/drivers/reset/reset-imx7.c (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
18e8e69d6SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2abf97755SAndrey Smirnov /*
3abf97755SAndrey Smirnov  * Copyright (c) 2017, Impinj, Inc.
4abf97755SAndrey Smirnov  *
5abf97755SAndrey Smirnov  * i.MX7 System Reset Controller (SRC) driver
6abf97755SAndrey Smirnov  *
7abf97755SAndrey Smirnov  * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
8abf97755SAndrey Smirnov  */
9abf97755SAndrey Smirnov 
10abf97755SAndrey Smirnov #include <linux/mfd/syscon.h>
11a442abbbSAnson Huang #include <linux/module.h>
12*bad8a8afSRob Herring #include <linux/of.h>
13abf97755SAndrey Smirnov #include <linux/platform_device.h>
14abf97755SAndrey Smirnov #include <linux/reset-controller.h>
15abf97755SAndrey Smirnov #include <linux/regmap.h>
16abf97755SAndrey Smirnov #include <dt-bindings/reset/imx7-reset.h>
17c979dbf5SAndrey Smirnov #include <dt-bindings/reset/imx8mq-reset.h>
18e08672c0SAnson Huang #include <dt-bindings/reset/imx8mp-reset.h>
19abf97755SAndrey Smirnov 
2010590358SAndrey Smirnov struct imx7_src_signal {
2110590358SAndrey Smirnov 	unsigned int offset, bit;
2210590358SAndrey Smirnov };
2310590358SAndrey Smirnov 
2410590358SAndrey Smirnov struct imx7_src_variant {
2510590358SAndrey Smirnov 	const struct imx7_src_signal *signals;
2610590358SAndrey Smirnov 	unsigned int signals_num;
2710590358SAndrey Smirnov 	struct reset_control_ops ops;
2810590358SAndrey Smirnov };
2910590358SAndrey Smirnov 
30abf97755SAndrey Smirnov struct imx7_src {
31abf97755SAndrey Smirnov 	struct reset_controller_dev rcdev;
32abf97755SAndrey Smirnov 	struct regmap *regmap;
3310590358SAndrey Smirnov 	const struct imx7_src_signal *signals;
34abf97755SAndrey Smirnov };
35abf97755SAndrey Smirnov 
36abf97755SAndrey Smirnov enum imx7_src_registers {
37abf97755SAndrey Smirnov 	SRC_A7RCR0		= 0x0004,
38abf97755SAndrey Smirnov 	SRC_M4RCR		= 0x000c,
39abf97755SAndrey Smirnov 	SRC_ERCR		= 0x0014,
40abf97755SAndrey Smirnov 	SRC_HSICPHY_RCR		= 0x001c,
41abf97755SAndrey Smirnov 	SRC_USBOPHY1_RCR	= 0x0020,
42abf97755SAndrey Smirnov 	SRC_USBOPHY2_RCR	= 0x0024,
43abf97755SAndrey Smirnov 	SRC_MIPIPHY_RCR		= 0x0028,
44abf97755SAndrey Smirnov 	SRC_PCIEPHY_RCR		= 0x002c,
45abf97755SAndrey Smirnov 	SRC_DDRC_RCR		= 0x1000,
46abf97755SAndrey Smirnov };
47abf97755SAndrey Smirnov 
imx7_reset_update(struct imx7_src * imx7src,unsigned long id,unsigned int value)4810590358SAndrey Smirnov static int imx7_reset_update(struct imx7_src *imx7src,
4910590358SAndrey Smirnov 			     unsigned long id, unsigned int value)
5010590358SAndrey Smirnov {
5110590358SAndrey Smirnov 	const struct imx7_src_signal *signal = &imx7src->signals[id];
5210590358SAndrey Smirnov 
5310590358SAndrey Smirnov 	return regmap_update_bits(imx7src->regmap,
5410590358SAndrey Smirnov 				  signal->offset, signal->bit, value);
5510590358SAndrey Smirnov }
56abf97755SAndrey Smirnov 
57abf97755SAndrey Smirnov static const struct imx7_src_signal imx7_src_signals[IMX7_RESET_NUM] = {
58abf97755SAndrey Smirnov 	[IMX7_RESET_A7_CORE_POR_RESET0] = { SRC_A7RCR0, BIT(0) },
59abf97755SAndrey Smirnov 	[IMX7_RESET_A7_CORE_POR_RESET1] = { SRC_A7RCR0, BIT(1) },
60abf97755SAndrey Smirnov 	[IMX7_RESET_A7_CORE_RESET0]     = { SRC_A7RCR0, BIT(4) },
61abf97755SAndrey Smirnov 	[IMX7_RESET_A7_CORE_RESET1]	= { SRC_A7RCR0, BIT(5) },
62abf97755SAndrey Smirnov 	[IMX7_RESET_A7_DBG_RESET0]	= { SRC_A7RCR0, BIT(8) },
63abf97755SAndrey Smirnov 	[IMX7_RESET_A7_DBG_RESET1]	= { SRC_A7RCR0, BIT(9) },
64abf97755SAndrey Smirnov 	[IMX7_RESET_A7_ETM_RESET0]	= { SRC_A7RCR0, BIT(12) },
65abf97755SAndrey Smirnov 	[IMX7_RESET_A7_ETM_RESET1]	= { SRC_A7RCR0, BIT(13) },
66abf97755SAndrey Smirnov 	[IMX7_RESET_A7_SOC_DBG_RESET]	= { SRC_A7RCR0, BIT(20) },
67abf97755SAndrey Smirnov 	[IMX7_RESET_A7_L2RESET]		= { SRC_A7RCR0, BIT(21) },
68abf97755SAndrey Smirnov 	[IMX7_RESET_SW_M4C_RST]		= { SRC_M4RCR, BIT(1) },
69abf97755SAndrey Smirnov 	[IMX7_RESET_SW_M4P_RST]		= { SRC_M4RCR, BIT(2) },
70abf97755SAndrey Smirnov 	[IMX7_RESET_EIM_RST]		= { SRC_ERCR, BIT(0) },
71abf97755SAndrey Smirnov 	[IMX7_RESET_HSICPHY_PORT_RST]	= { SRC_HSICPHY_RCR, BIT(1) },
72abf97755SAndrey Smirnov 	[IMX7_RESET_USBPHY1_POR]	= { SRC_USBOPHY1_RCR, BIT(0) },
73abf97755SAndrey Smirnov 	[IMX7_RESET_USBPHY1_PORT_RST]	= { SRC_USBOPHY1_RCR, BIT(1) },
74abf97755SAndrey Smirnov 	[IMX7_RESET_USBPHY2_POR]	= { SRC_USBOPHY2_RCR, BIT(0) },
75abf97755SAndrey Smirnov 	[IMX7_RESET_USBPHY2_PORT_RST]	= { SRC_USBOPHY2_RCR, BIT(1) },
76abf97755SAndrey Smirnov 	[IMX7_RESET_MIPI_PHY_MRST]	= { SRC_MIPIPHY_RCR, BIT(1) },
77abf97755SAndrey Smirnov 	[IMX7_RESET_MIPI_PHY_SRST]	= { SRC_MIPIPHY_RCR, BIT(2) },
78abf97755SAndrey Smirnov 	[IMX7_RESET_PCIEPHY]		= { SRC_PCIEPHY_RCR, BIT(2) | BIT(1) },
79abf97755SAndrey Smirnov 	[IMX7_RESET_PCIEPHY_PERST]	= { SRC_PCIEPHY_RCR, BIT(3) },
80abf97755SAndrey Smirnov 	[IMX7_RESET_PCIE_CTRL_APPS_EN]	= { SRC_PCIEPHY_RCR, BIT(6) },
81de248327SLeonard Crestez 	[IMX7_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) },
82abf97755SAndrey Smirnov 	[IMX7_RESET_DDRC_PRST]		= { SRC_DDRC_RCR, BIT(0) },
83abf97755SAndrey Smirnov 	[IMX7_RESET_DDRC_CORE_RST]	= { SRC_DDRC_RCR, BIT(1) },
84abf97755SAndrey Smirnov };
85abf97755SAndrey Smirnov 
to_imx7_src(struct reset_controller_dev * rcdev)86abf97755SAndrey Smirnov static struct imx7_src *to_imx7_src(struct reset_controller_dev *rcdev)
87abf97755SAndrey Smirnov {
88abf97755SAndrey Smirnov 	return container_of(rcdev, struct imx7_src, rcdev);
89abf97755SAndrey Smirnov }
90abf97755SAndrey Smirnov 
imx7_reset_set(struct reset_controller_dev * rcdev,unsigned long id,bool assert)91abf97755SAndrey Smirnov static int imx7_reset_set(struct reset_controller_dev *rcdev,
92abf97755SAndrey Smirnov 			  unsigned long id, bool assert)
93abf97755SAndrey Smirnov {
94abf97755SAndrey Smirnov 	struct imx7_src *imx7src = to_imx7_src(rcdev);
9510590358SAndrey Smirnov 	const unsigned int bit = imx7src->signals[id].bit;
9610590358SAndrey Smirnov 	unsigned int value = assert ? bit : 0;
97abf97755SAndrey Smirnov 
98abf97755SAndrey Smirnov 	switch (id) {
99abf97755SAndrey Smirnov 	case IMX7_RESET_PCIEPHY:
100abf97755SAndrey Smirnov 		/*
101abf97755SAndrey Smirnov 		 * wait for more than 10us to release phy g_rst and
102abf97755SAndrey Smirnov 		 * btnrst
103abf97755SAndrey Smirnov 		 */
104abf97755SAndrey Smirnov 		if (!assert)
105abf97755SAndrey Smirnov 			udelay(10);
106abf97755SAndrey Smirnov 		break;
107abf97755SAndrey Smirnov 
108abf97755SAndrey Smirnov 	case IMX7_RESET_PCIE_CTRL_APPS_EN:
10910590358SAndrey Smirnov 		value = assert ? 0 : bit;
110abf97755SAndrey Smirnov 		break;
111abf97755SAndrey Smirnov 	}
112abf97755SAndrey Smirnov 
11310590358SAndrey Smirnov 	return imx7_reset_update(imx7src, id, value);
114abf97755SAndrey Smirnov }
115abf97755SAndrey Smirnov 
imx7_reset_assert(struct reset_controller_dev * rcdev,unsigned long id)116abf97755SAndrey Smirnov static int imx7_reset_assert(struct reset_controller_dev *rcdev,
117abf97755SAndrey Smirnov 			     unsigned long id)
118abf97755SAndrey Smirnov {
119abf97755SAndrey Smirnov 	return imx7_reset_set(rcdev, id, true);
120abf97755SAndrey Smirnov }
121abf97755SAndrey Smirnov 
imx7_reset_deassert(struct reset_controller_dev * rcdev,unsigned long id)122abf97755SAndrey Smirnov static int imx7_reset_deassert(struct reset_controller_dev *rcdev,
123abf97755SAndrey Smirnov 			       unsigned long id)
124abf97755SAndrey Smirnov {
125abf97755SAndrey Smirnov 	return imx7_reset_set(rcdev, id, false);
126abf97755SAndrey Smirnov }
127abf97755SAndrey Smirnov 
12810590358SAndrey Smirnov static const struct imx7_src_variant variant_imx7 = {
12910590358SAndrey Smirnov 	.signals = imx7_src_signals,
13010590358SAndrey Smirnov 	.signals_num = ARRAY_SIZE(imx7_src_signals),
13110590358SAndrey Smirnov 	.ops = {
132abf97755SAndrey Smirnov 		.assert   = imx7_reset_assert,
133abf97755SAndrey Smirnov 		.deassert = imx7_reset_deassert,
13410590358SAndrey Smirnov 	},
135abf97755SAndrey Smirnov };
136abf97755SAndrey Smirnov 
137c979dbf5SAndrey Smirnov enum imx8mq_src_registers {
138c979dbf5SAndrey Smirnov 	SRC_A53RCR0		= 0x0004,
139c979dbf5SAndrey Smirnov 	SRC_HDMI_RCR		= 0x0030,
140c979dbf5SAndrey Smirnov 	SRC_DISP_RCR		= 0x0034,
141c979dbf5SAndrey Smirnov 	SRC_GPU_RCR		= 0x0040,
142c979dbf5SAndrey Smirnov 	SRC_VPU_RCR		= 0x0044,
143c979dbf5SAndrey Smirnov 	SRC_PCIE2_RCR		= 0x0048,
144c979dbf5SAndrey Smirnov 	SRC_MIPIPHY1_RCR	= 0x004c,
145c979dbf5SAndrey Smirnov 	SRC_MIPIPHY2_RCR	= 0x0050,
146c979dbf5SAndrey Smirnov 	SRC_DDRC2_RCR		= 0x1004,
147c979dbf5SAndrey Smirnov };
148c979dbf5SAndrey Smirnov 
149e08672c0SAnson Huang enum imx8mp_src_registers {
150e08672c0SAnson Huang 	SRC_SUPERMIX_RCR	= 0x0018,
151e08672c0SAnson Huang 	SRC_AUDIOMIX_RCR	= 0x001c,
152e08672c0SAnson Huang 	SRC_MLMIX_RCR		= 0x0028,
153e08672c0SAnson Huang 	SRC_GPU2D_RCR		= 0x0038,
154e08672c0SAnson Huang 	SRC_GPU3D_RCR		= 0x003c,
155e08672c0SAnson Huang 	SRC_VPU_G1_RCR		= 0x0048,
156e08672c0SAnson Huang 	SRC_VPU_G2_RCR		= 0x004c,
157e08672c0SAnson Huang 	SRC_VPUVC8KE_RCR	= 0x0050,
158e08672c0SAnson Huang 	SRC_NOC_RCR		= 0x0054,
159e08672c0SAnson Huang };
160e08672c0SAnson Huang 
161c979dbf5SAndrey Smirnov static const struct imx7_src_signal imx8mq_src_signals[IMX8MQ_RESET_NUM] = {
162c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_POR_RESET0]	= { SRC_A53RCR0, BIT(0) },
163c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_POR_RESET1]	= { SRC_A53RCR0, BIT(1) },
164c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_POR_RESET2]	= { SRC_A53RCR0, BIT(2) },
165c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_POR_RESET3]	= { SRC_A53RCR0, BIT(3) },
166c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_RESET0]		= { SRC_A53RCR0, BIT(4) },
167c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_RESET1]		= { SRC_A53RCR0, BIT(5) },
168c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_RESET2]		= { SRC_A53RCR0, BIT(6) },
169c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_CORE_RESET3]		= { SRC_A53RCR0, BIT(7) },
170c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_DBG_RESET0]		= { SRC_A53RCR0, BIT(8) },
171c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_DBG_RESET1]		= { SRC_A53RCR0, BIT(9) },
172c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_DBG_RESET2]		= { SRC_A53RCR0, BIT(10) },
173c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_DBG_RESET3]		= { SRC_A53RCR0, BIT(11) },
174c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_ETM_RESET0]		= { SRC_A53RCR0, BIT(12) },
175c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_ETM_RESET1]		= { SRC_A53RCR0, BIT(13) },
176c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_ETM_RESET2]		= { SRC_A53RCR0, BIT(14) },
177c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_ETM_RESET3]		= { SRC_A53RCR0, BIT(15) },
178c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_SOC_DBG_RESET]	= { SRC_A53RCR0, BIT(20) },
179c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_A53_L2RESET]		= { SRC_A53RCR0, BIT(21) },
180c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_SW_NON_SCLR_M4C_RST]	= { SRC_M4RCR, BIT(0) },
181f008c403SPeng Fan 	[IMX8MQ_RESET_SW_M4C_RST]		= { SRC_M4RCR, BIT(1) },
182f008c403SPeng Fan 	[IMX8MQ_RESET_SW_M4P_RST]		= { SRC_M4RCR, BIT(2) },
183f008c403SPeng Fan 	[IMX8MQ_RESET_M4_ENABLE]		= { SRC_M4RCR, BIT(3) },
184c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_OTG1_PHY_RESET]		= { SRC_USBOPHY1_RCR, BIT(0) },
185c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_OTG2_PHY_RESET]		= { SRC_USBOPHY2_RCR, BIT(0) },
186c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N]	= { SRC_MIPIPHY_RCR, BIT(1) },
187c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_DSI_RESET_N]		= { SRC_MIPIPHY_RCR, BIT(2) },
188942b4c10SGuido Günther 	[IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N]	= { SRC_MIPIPHY_RCR, BIT(3) },
189942b4c10SGuido Günther 	[IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N]	= { SRC_MIPIPHY_RCR, BIT(4) },
190942b4c10SGuido Günther 	[IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N]	= { SRC_MIPIPHY_RCR, BIT(5) },
191c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIEPHY]			= { SRC_PCIEPHY_RCR,
192c979dbf5SAndrey Smirnov 						    BIT(2) | BIT(1) },
193c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIEPHY_PERST]		= { SRC_PCIEPHY_RCR, BIT(3) },
194c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIE_CTRL_APPS_EN]	= { SRC_PCIEPHY_RCR, BIT(6) },
195c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIE_CTRL_APPS_TURNOFF]	= { SRC_PCIEPHY_RCR, BIT(11) },
196c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_HDMI_PHY_APB_RESET]	= { SRC_HDMI_RCR, BIT(0) },
197c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DISP_RESET]		= { SRC_DISP_RCR, BIT(0) },
198c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_GPU_RESET]		= { SRC_GPU_RCR, BIT(0) },
199c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_VPU_RESET]		= { SRC_VPU_RCR, BIT(0) },
200c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIEPHY2]			= { SRC_PCIE2_RCR,
201c979dbf5SAndrey Smirnov 						    BIT(2) | BIT(1) },
202c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIEPHY2_PERST]		= { SRC_PCIE2_RCR, BIT(3) },
203c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIE2_CTRL_APPS_EN]	= { SRC_PCIE2_RCR, BIT(6) },
204c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_PCIE2_CTRL_APPS_TURNOFF]	= { SRC_PCIE2_RCR, BIT(11) },
205c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_CSI1_CORE_RESET]	= { SRC_MIPIPHY1_RCR, BIT(0) },
206c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_CSI1_PHY_REF_RESET]	= { SRC_MIPIPHY1_RCR, BIT(1) },
207c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_CSI1_ESC_RESET]	= { SRC_MIPIPHY1_RCR, BIT(2) },
208c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_CSI2_CORE_RESET]	= { SRC_MIPIPHY2_RCR, BIT(0) },
209c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_CSI2_PHY_REF_RESET]	= { SRC_MIPIPHY2_RCR, BIT(1) },
210c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_MIPI_CSI2_ESC_RESET]	= { SRC_MIPIPHY2_RCR, BIT(2) },
211c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DDRC1_PRST]		= { SRC_DDRC_RCR, BIT(0) },
212c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DDRC1_CORE_RESET]		= { SRC_DDRC_RCR, BIT(1) },
213c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DDRC1_PHY_RESET]		= { SRC_DDRC_RCR, BIT(2) },
214c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DDRC2_PHY_RESET]		= { SRC_DDRC2_RCR, BIT(0) },
215c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DDRC2_CORE_RESET]		= { SRC_DDRC2_RCR, BIT(1) },
216c979dbf5SAndrey Smirnov 	[IMX8MQ_RESET_DDRC2_PRST]		= { SRC_DDRC2_RCR, BIT(2) },
217c979dbf5SAndrey Smirnov };
218c979dbf5SAndrey Smirnov 
imx8mq_reset_set(struct reset_controller_dev * rcdev,unsigned long id,bool assert)219c979dbf5SAndrey Smirnov static int imx8mq_reset_set(struct reset_controller_dev *rcdev,
220c979dbf5SAndrey Smirnov 			    unsigned long id, bool assert)
221c979dbf5SAndrey Smirnov {
222c979dbf5SAndrey Smirnov 	struct imx7_src *imx7src = to_imx7_src(rcdev);
223c979dbf5SAndrey Smirnov 	const unsigned int bit = imx7src->signals[id].bit;
224c979dbf5SAndrey Smirnov 	unsigned int value = assert ? bit : 0;
225c979dbf5SAndrey Smirnov 
226c979dbf5SAndrey Smirnov 	switch (id) {
227c979dbf5SAndrey Smirnov 	case IMX8MQ_RESET_PCIEPHY:
228df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_PCIEPHY2:
229c979dbf5SAndrey Smirnov 		/*
230c979dbf5SAndrey Smirnov 		 * wait for more than 10us to release phy g_rst and
231c979dbf5SAndrey Smirnov 		 * btnrst
232c979dbf5SAndrey Smirnov 		 */
233c979dbf5SAndrey Smirnov 		if (!assert)
234c979dbf5SAndrey Smirnov 			udelay(10);
235c979dbf5SAndrey Smirnov 		break;
236c979dbf5SAndrey Smirnov 
237c979dbf5SAndrey Smirnov 	case IMX8MQ_RESET_PCIE_CTRL_APPS_EN:
238df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_PCIE2_CTRL_APPS_EN:
239df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N:
240df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N:
241df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N:
242df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_MIPI_DSI_RESET_N:
243df561f66SGustavo A. R. Silva 	case IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N:
244f008c403SPeng Fan 	case IMX8MQ_RESET_M4_ENABLE:
245c979dbf5SAndrey Smirnov 		value = assert ? 0 : bit;
246c979dbf5SAndrey Smirnov 		break;
247c979dbf5SAndrey Smirnov 	}
248c979dbf5SAndrey Smirnov 
249c979dbf5SAndrey Smirnov 	return imx7_reset_update(imx7src, id, value);
250c979dbf5SAndrey Smirnov }
251c979dbf5SAndrey Smirnov 
imx8mq_reset_assert(struct reset_controller_dev * rcdev,unsigned long id)252c979dbf5SAndrey Smirnov static int imx8mq_reset_assert(struct reset_controller_dev *rcdev,
253c979dbf5SAndrey Smirnov 			       unsigned long id)
254c979dbf5SAndrey Smirnov {
255c979dbf5SAndrey Smirnov 	return imx8mq_reset_set(rcdev, id, true);
256c979dbf5SAndrey Smirnov }
257c979dbf5SAndrey Smirnov 
imx8mq_reset_deassert(struct reset_controller_dev * rcdev,unsigned long id)258c979dbf5SAndrey Smirnov static int imx8mq_reset_deassert(struct reset_controller_dev *rcdev,
259c979dbf5SAndrey Smirnov 				 unsigned long id)
260c979dbf5SAndrey Smirnov {
261c979dbf5SAndrey Smirnov 	return imx8mq_reset_set(rcdev, id, false);
262c979dbf5SAndrey Smirnov }
263c979dbf5SAndrey Smirnov 
264c979dbf5SAndrey Smirnov static const struct imx7_src_variant variant_imx8mq = {
265c979dbf5SAndrey Smirnov 	.signals = imx8mq_src_signals,
266c979dbf5SAndrey Smirnov 	.signals_num = ARRAY_SIZE(imx8mq_src_signals),
267c979dbf5SAndrey Smirnov 	.ops = {
268c979dbf5SAndrey Smirnov 		.assert   = imx8mq_reset_assert,
269c979dbf5SAndrey Smirnov 		.deassert = imx8mq_reset_deassert,
270c979dbf5SAndrey Smirnov 	},
271c979dbf5SAndrey Smirnov };
272c979dbf5SAndrey Smirnov 
273e08672c0SAnson Huang static const struct imx7_src_signal imx8mp_src_signals[IMX8MP_RESET_NUM] = {
274e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_POR_RESET0]	= { SRC_A53RCR0, BIT(0) },
275e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_POR_RESET1]	= { SRC_A53RCR0, BIT(1) },
276e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_POR_RESET2]	= { SRC_A53RCR0, BIT(2) },
277e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_POR_RESET3]	= { SRC_A53RCR0, BIT(3) },
278e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_RESET0]		= { SRC_A53RCR0, BIT(4) },
279e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_RESET1]		= { SRC_A53RCR0, BIT(5) },
280e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_RESET2]		= { SRC_A53RCR0, BIT(6) },
281e08672c0SAnson Huang 	[IMX8MP_RESET_A53_CORE_RESET3]		= { SRC_A53RCR0, BIT(7) },
282e08672c0SAnson Huang 	[IMX8MP_RESET_A53_DBG_RESET0]		= { SRC_A53RCR0, BIT(8) },
283e08672c0SAnson Huang 	[IMX8MP_RESET_A53_DBG_RESET1]		= { SRC_A53RCR0, BIT(9) },
284e08672c0SAnson Huang 	[IMX8MP_RESET_A53_DBG_RESET2]		= { SRC_A53RCR0, BIT(10) },
285e08672c0SAnson Huang 	[IMX8MP_RESET_A53_DBG_RESET3]		= { SRC_A53RCR0, BIT(11) },
286e08672c0SAnson Huang 	[IMX8MP_RESET_A53_ETM_RESET0]		= { SRC_A53RCR0, BIT(12) },
287e08672c0SAnson Huang 	[IMX8MP_RESET_A53_ETM_RESET1]		= { SRC_A53RCR0, BIT(13) },
288e08672c0SAnson Huang 	[IMX8MP_RESET_A53_ETM_RESET2]		= { SRC_A53RCR0, BIT(14) },
289e08672c0SAnson Huang 	[IMX8MP_RESET_A53_ETM_RESET3]		= { SRC_A53RCR0, BIT(15) },
290e08672c0SAnson Huang 	[IMX8MP_RESET_A53_SOC_DBG_RESET]	= { SRC_A53RCR0, BIT(20) },
291e08672c0SAnson Huang 	[IMX8MP_RESET_A53_L2RESET]		= { SRC_A53RCR0, BIT(21) },
292e08672c0SAnson Huang 	[IMX8MP_RESET_SW_NON_SCLR_M7C_RST]	= { SRC_M4RCR, BIT(0) },
293e08672c0SAnson Huang 	[IMX8MP_RESET_OTG1_PHY_RESET]		= { SRC_USBOPHY1_RCR, BIT(0) },
294e08672c0SAnson Huang 	[IMX8MP_RESET_OTG2_PHY_RESET]		= { SRC_USBOPHY2_RCR, BIT(0) },
295e08672c0SAnson Huang 	[IMX8MP_RESET_SUPERMIX_RESET]		= { SRC_SUPERMIX_RCR, BIT(0) },
296e08672c0SAnson Huang 	[IMX8MP_RESET_AUDIOMIX_RESET]		= { SRC_AUDIOMIX_RCR, BIT(0) },
297e08672c0SAnson Huang 	[IMX8MP_RESET_MLMIX_RESET]		= { SRC_MLMIX_RCR, BIT(0) },
298e08672c0SAnson Huang 	[IMX8MP_RESET_PCIEPHY]			= { SRC_PCIEPHY_RCR, BIT(2) },
299e08672c0SAnson Huang 	[IMX8MP_RESET_PCIEPHY_PERST]		= { SRC_PCIEPHY_RCR, BIT(3) },
300e08672c0SAnson Huang 	[IMX8MP_RESET_PCIE_CTRL_APPS_EN]	= { SRC_PCIEPHY_RCR, BIT(6) },
301e08672c0SAnson Huang 	[IMX8MP_RESET_PCIE_CTRL_APPS_TURNOFF]	= { SRC_PCIEPHY_RCR, BIT(11) },
302e08672c0SAnson Huang 	[IMX8MP_RESET_HDMI_PHY_APB_RESET]	= { SRC_HDMI_RCR, BIT(0) },
303e08672c0SAnson Huang 	[IMX8MP_RESET_MEDIA_RESET]		= { SRC_DISP_RCR, BIT(0) },
304e08672c0SAnson Huang 	[IMX8MP_RESET_GPU2D_RESET]		= { SRC_GPU2D_RCR, BIT(0) },
305e08672c0SAnson Huang 	[IMX8MP_RESET_GPU3D_RESET]		= { SRC_GPU3D_RCR, BIT(0) },
306e08672c0SAnson Huang 	[IMX8MP_RESET_GPU_RESET]		= { SRC_GPU_RCR, BIT(0) },
307e08672c0SAnson Huang 	[IMX8MP_RESET_VPU_RESET]		= { SRC_VPU_RCR, BIT(0) },
308e08672c0SAnson Huang 	[IMX8MP_RESET_VPU_G1_RESET]		= { SRC_VPU_G1_RCR, BIT(0) },
309e08672c0SAnson Huang 	[IMX8MP_RESET_VPU_G2_RESET]		= { SRC_VPU_G2_RCR, BIT(0) },
310e08672c0SAnson Huang 	[IMX8MP_RESET_VPUVC8KE_RESET]		= { SRC_VPUVC8KE_RCR, BIT(0) },
311e08672c0SAnson Huang 	[IMX8MP_RESET_NOC_RESET]		= { SRC_NOC_RCR, BIT(0) },
312e08672c0SAnson Huang };
313e08672c0SAnson Huang 
imx8mp_reset_set(struct reset_controller_dev * rcdev,unsigned long id,bool assert)314e08672c0SAnson Huang static int imx8mp_reset_set(struct reset_controller_dev *rcdev,
315e08672c0SAnson Huang 			    unsigned long id, bool assert)
316e08672c0SAnson Huang {
317e08672c0SAnson Huang 	struct imx7_src *imx7src = to_imx7_src(rcdev);
318e08672c0SAnson Huang 	const unsigned int bit = imx7src->signals[id].bit;
319e08672c0SAnson Huang 	unsigned int value = assert ? bit : 0;
320e08672c0SAnson Huang 
321e08672c0SAnson Huang 	switch (id) {
322e08672c0SAnson Huang 	case IMX8MP_RESET_PCIEPHY:
323e08672c0SAnson Huang 		/*
324e08672c0SAnson Huang 		 * wait for more than 10us to release phy g_rst and
325e08672c0SAnson Huang 		 * btnrst
326e08672c0SAnson Huang 		 */
327e08672c0SAnson Huang 		if (!assert)
328e08672c0SAnson Huang 			udelay(10);
329e08672c0SAnson Huang 		break;
330e08672c0SAnson Huang 
331e08672c0SAnson Huang 	case IMX8MP_RESET_PCIE_CTRL_APPS_EN:
332051d9eb4SRichard Zhu 	case IMX8MP_RESET_PCIEPHY_PERST:
333e08672c0SAnson Huang 		value = assert ? 0 : bit;
334e08672c0SAnson Huang 		break;
335e08672c0SAnson Huang 	}
336e08672c0SAnson Huang 
337e08672c0SAnson Huang 	return imx7_reset_update(imx7src, id, value);
338e08672c0SAnson Huang }
339e08672c0SAnson Huang 
imx8mp_reset_assert(struct reset_controller_dev * rcdev,unsigned long id)340e08672c0SAnson Huang static int imx8mp_reset_assert(struct reset_controller_dev *rcdev,
341e08672c0SAnson Huang 			       unsigned long id)
342e08672c0SAnson Huang {
343e08672c0SAnson Huang 	return imx8mp_reset_set(rcdev, id, true);
344e08672c0SAnson Huang }
345e08672c0SAnson Huang 
imx8mp_reset_deassert(struct reset_controller_dev * rcdev,unsigned long id)346e08672c0SAnson Huang static int imx8mp_reset_deassert(struct reset_controller_dev *rcdev,
347e08672c0SAnson Huang 				 unsigned long id)
348e08672c0SAnson Huang {
349e08672c0SAnson Huang 	return imx8mp_reset_set(rcdev, id, false);
350e08672c0SAnson Huang }
351e08672c0SAnson Huang 
352e08672c0SAnson Huang static const struct imx7_src_variant variant_imx8mp = {
353e08672c0SAnson Huang 	.signals = imx8mp_src_signals,
354e08672c0SAnson Huang 	.signals_num = ARRAY_SIZE(imx8mp_src_signals),
355e08672c0SAnson Huang 	.ops = {
356e08672c0SAnson Huang 		.assert   = imx8mp_reset_assert,
357e08672c0SAnson Huang 		.deassert = imx8mp_reset_deassert,
358e08672c0SAnson Huang 	},
359e08672c0SAnson Huang };
360e08672c0SAnson Huang 
imx7_reset_probe(struct platform_device * pdev)361abf97755SAndrey Smirnov static int imx7_reset_probe(struct platform_device *pdev)
362abf97755SAndrey Smirnov {
363abf97755SAndrey Smirnov 	struct imx7_src *imx7src;
364abf97755SAndrey Smirnov 	struct device *dev = &pdev->dev;
365abf97755SAndrey Smirnov 	struct regmap_config config = { .name = "src" };
36610590358SAndrey Smirnov 	const struct imx7_src_variant *variant = of_device_get_match_data(dev);
367abf97755SAndrey Smirnov 
368abf97755SAndrey Smirnov 	imx7src = devm_kzalloc(dev, sizeof(*imx7src), GFP_KERNEL);
369abf97755SAndrey Smirnov 	if (!imx7src)
370abf97755SAndrey Smirnov 		return -ENOMEM;
371abf97755SAndrey Smirnov 
37210590358SAndrey Smirnov 	imx7src->signals = variant->signals;
373abf97755SAndrey Smirnov 	imx7src->regmap = syscon_node_to_regmap(dev->of_node);
374abf97755SAndrey Smirnov 	if (IS_ERR(imx7src->regmap)) {
375abf97755SAndrey Smirnov 		dev_err(dev, "Unable to get imx7-src regmap");
376abf97755SAndrey Smirnov 		return PTR_ERR(imx7src->regmap);
377abf97755SAndrey Smirnov 	}
378abf97755SAndrey Smirnov 	regmap_attach_dev(dev, imx7src->regmap, &config);
379abf97755SAndrey Smirnov 
380abf97755SAndrey Smirnov 	imx7src->rcdev.owner     = THIS_MODULE;
38110590358SAndrey Smirnov 	imx7src->rcdev.nr_resets = variant->signals_num;
38210590358SAndrey Smirnov 	imx7src->rcdev.ops       = &variant->ops;
383abf97755SAndrey Smirnov 	imx7src->rcdev.of_node   = dev->of_node;
384abf97755SAndrey Smirnov 
385abf97755SAndrey Smirnov 	return devm_reset_controller_register(dev, &imx7src->rcdev);
386abf97755SAndrey Smirnov }
387abf97755SAndrey Smirnov 
388abf97755SAndrey Smirnov static const struct of_device_id imx7_reset_dt_ids[] = {
38910590358SAndrey Smirnov 	{ .compatible = "fsl,imx7d-src", .data = &variant_imx7 },
390c979dbf5SAndrey Smirnov 	{ .compatible = "fsl,imx8mq-src", .data = &variant_imx8mq },
391e08672c0SAnson Huang 	{ .compatible = "fsl,imx8mp-src", .data = &variant_imx8mp },
392abf97755SAndrey Smirnov 	{ /* sentinel */ },
393abf97755SAndrey Smirnov };
394a442abbbSAnson Huang MODULE_DEVICE_TABLE(of, imx7_reset_dt_ids);
395abf97755SAndrey Smirnov 
396abf97755SAndrey Smirnov static struct platform_driver imx7_reset_driver = {
397abf97755SAndrey Smirnov 	.probe	= imx7_reset_probe,
398abf97755SAndrey Smirnov 	.driver = {
399abf97755SAndrey Smirnov 		.name		= KBUILD_MODNAME,
400abf97755SAndrey Smirnov 		.of_match_table	= imx7_reset_dt_ids,
401abf97755SAndrey Smirnov 	},
402abf97755SAndrey Smirnov };
403a442abbbSAnson Huang module_platform_driver(imx7_reset_driver);
404a442abbbSAnson Huang 
405a442abbbSAnson Huang MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
406a442abbbSAnson Huang MODULE_DESCRIPTION("NXP i.MX7 reset driver");
407a442abbbSAnson Huang MODULE_LICENSE("GPL v2");
408