Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (c) 2017, Impinj, Inc. |
| 4 | */ |
| 5 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 6 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 7 | #include <malloc.h> |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 8 | #include <asm/io.h> |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <dt-bindings/reset/imx7-reset.h> |
Sumit Garg | 41e0ad5 | 2024-03-21 20:24:59 +0530 | [diff] [blame] | 11 | #include <dt-bindings/reset/imx8mp-reset.h> |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 12 | #include <dt-bindings/reset/imx8mq-reset.h> |
| 13 | #include <reset-uclass.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 15 | #include <linux/delay.h> |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 16 | |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 17 | struct imx_reset_priv { |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 18 | void __iomem *base; |
| 19 | struct reset_ops ops; |
| 20 | }; |
| 21 | |
| 22 | struct imx7_src_signal { |
| 23 | unsigned int offset, bit; |
| 24 | }; |
| 25 | |
| 26 | enum 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 | |
| 38 | static 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 Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 67 | static int imx7_reset_deassert(struct reset_ctl *rst) |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 68 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 69 | struct imx_reset_priv *priv = dev_get_priv(rst->dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 70 | 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 Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 98 | static int imx7_reset_assert(struct reset_ctl *rst) |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 99 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 100 | struct imx_reset_priv *priv = dev_get_priv(rst->dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 101 | 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 | |
| 121 | enum 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 | |
| 133 | static 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 Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 188 | static int imx8mq_reset_deassert(struct reset_ctl *rst) |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 189 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 190 | struct imx_reset_priv *priv = dev_get_priv(rst->dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 191 | 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 Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 226 | static int imx8mq_reset_assert(struct reset_ctl *rst) |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 227 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 228 | struct imx_reset_priv *priv = dev_get_priv(rst->dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 229 | 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 Garg | 41e0ad5 | 2024-03-21 20:24:59 +0530 | [diff] [blame] | 255 | enum 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 | |
| 267 | static 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 | |
| 308 | static 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 | |
| 341 | static int imx8mp_reset_assert(struct reset_ctl *rst) |
| 342 | { |
| 343 | return imx8mp_reset_set(rst, true); |
| 344 | } |
| 345 | |
| 346 | static int imx8mp_reset_deassert(struct reset_ctl *rst) |
| 347 | { |
| 348 | return imx8mp_reset_set(rst, false); |
| 349 | } |
| 350 | |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 351 | static int imx_reset_assert(struct reset_ctl *rst) |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 352 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 353 | struct imx_reset_priv *priv = dev_get_priv(rst->dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 354 | return priv->ops.rst_assert(rst); |
| 355 | } |
| 356 | |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 357 | static int imx_reset_deassert(struct reset_ctl *rst) |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 358 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 359 | struct imx_reset_priv *priv = dev_get_priv(rst->dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 360 | return priv->ops.rst_deassert(rst); |
| 361 | } |
| 362 | |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 363 | static const struct reset_ops imx7_reset_reset_ops = { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 364 | .rst_assert = imx_reset_assert, |
| 365 | .rst_deassert = imx_reset_deassert, |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 366 | }; |
| 367 | |
| 368 | static const struct udevice_id imx7_reset_ids[] = { |
| 369 | { .compatible = "fsl,imx7d-src" }, |
| 370 | { .compatible = "fsl,imx8mq-src" }, |
Sumit Garg | 41e0ad5 | 2024-03-21 20:24:59 +0530 | [diff] [blame] | 371 | { .compatible = "fsl,imx8mp-src" }, |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 372 | { } |
| 373 | }; |
| 374 | |
| 375 | static int imx7_reset_probe(struct udevice *dev) |
| 376 | { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 377 | struct imx_reset_priv *priv = dev_get_priv(dev); |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 378 | |
| 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 Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 384 | priv->ops.rst_assert = imx8mq_reset_assert; |
| 385 | priv->ops.rst_deassert = imx8mq_reset_deassert; |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 386 | } else if (device_is_compatible(dev, "fsl,imx7d-src")) { |
Sumit Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 387 | priv->ops.rst_assert = imx7_reset_assert; |
| 388 | priv->ops.rst_deassert = imx7_reset_deassert; |
Sumit Garg | 41e0ad5 | 2024-03-21 20:24:59 +0530 | [diff] [blame] | 389 | } 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 Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | U_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 Garg | 9ab2ffa | 2024-03-21 20:24:58 +0530 | [diff] [blame] | 403 | .priv_auto = sizeof(struct imx_reset_priv), |
Patrick Wildt | dbc644f | 2019-10-03 16:08:35 +0200 | [diff] [blame] | 404 | }; |