18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2017, Impinj, Inc. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * i.MX7 System Reset Controller (SRC) driver 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Andrey Smirnov <andrew.smirnov@gmail.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h> 118c2ecf20Sopenharmony_ci#include <linux/module.h> 128c2ecf20Sopenharmony_ci#include <linux/of_device.h> 138c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 148c2ecf20Sopenharmony_ci#include <linux/reset-controller.h> 158c2ecf20Sopenharmony_ci#include <linux/regmap.h> 168c2ecf20Sopenharmony_ci#include <dt-bindings/reset/imx7-reset.h> 178c2ecf20Sopenharmony_ci#include <dt-bindings/reset/imx8mq-reset.h> 188c2ecf20Sopenharmony_ci#include <dt-bindings/reset/imx8mp-reset.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_cistruct imx7_src_signal { 218c2ecf20Sopenharmony_ci unsigned int offset, bit; 228c2ecf20Sopenharmony_ci}; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistruct imx7_src_variant { 258c2ecf20Sopenharmony_ci const struct imx7_src_signal *signals; 268c2ecf20Sopenharmony_ci unsigned int signals_num; 278c2ecf20Sopenharmony_ci struct reset_control_ops ops; 288c2ecf20Sopenharmony_ci}; 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistruct imx7_src { 318c2ecf20Sopenharmony_ci struct reset_controller_dev rcdev; 328c2ecf20Sopenharmony_ci struct regmap *regmap; 338c2ecf20Sopenharmony_ci const struct imx7_src_signal *signals; 348c2ecf20Sopenharmony_ci}; 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_cienum imx7_src_registers { 378c2ecf20Sopenharmony_ci SRC_A7RCR0 = 0x0004, 388c2ecf20Sopenharmony_ci SRC_M4RCR = 0x000c, 398c2ecf20Sopenharmony_ci SRC_ERCR = 0x0014, 408c2ecf20Sopenharmony_ci SRC_HSICPHY_RCR = 0x001c, 418c2ecf20Sopenharmony_ci SRC_USBOPHY1_RCR = 0x0020, 428c2ecf20Sopenharmony_ci SRC_USBOPHY2_RCR = 0x0024, 438c2ecf20Sopenharmony_ci SRC_MIPIPHY_RCR = 0x0028, 448c2ecf20Sopenharmony_ci SRC_PCIEPHY_RCR = 0x002c, 458c2ecf20Sopenharmony_ci SRC_DDRC_RCR = 0x1000, 468c2ecf20Sopenharmony_ci}; 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_cistatic int imx7_reset_update(struct imx7_src *imx7src, 498c2ecf20Sopenharmony_ci unsigned long id, unsigned int value) 508c2ecf20Sopenharmony_ci{ 518c2ecf20Sopenharmony_ci const struct imx7_src_signal *signal = &imx7src->signals[id]; 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci return regmap_update_bits(imx7src->regmap, 548c2ecf20Sopenharmony_ci signal->offset, signal->bit, value); 558c2ecf20Sopenharmony_ci} 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic const struct imx7_src_signal imx7_src_signals[IMX7_RESET_NUM] = { 588c2ecf20Sopenharmony_ci [IMX7_RESET_A7_CORE_POR_RESET0] = { SRC_A7RCR0, BIT(0) }, 598c2ecf20Sopenharmony_ci [IMX7_RESET_A7_CORE_POR_RESET1] = { SRC_A7RCR0, BIT(1) }, 608c2ecf20Sopenharmony_ci [IMX7_RESET_A7_CORE_RESET0] = { SRC_A7RCR0, BIT(4) }, 618c2ecf20Sopenharmony_ci [IMX7_RESET_A7_CORE_RESET1] = { SRC_A7RCR0, BIT(5) }, 628c2ecf20Sopenharmony_ci [IMX7_RESET_A7_DBG_RESET0] = { SRC_A7RCR0, BIT(8) }, 638c2ecf20Sopenharmony_ci [IMX7_RESET_A7_DBG_RESET1] = { SRC_A7RCR0, BIT(9) }, 648c2ecf20Sopenharmony_ci [IMX7_RESET_A7_ETM_RESET0] = { SRC_A7RCR0, BIT(12) }, 658c2ecf20Sopenharmony_ci [IMX7_RESET_A7_ETM_RESET1] = { SRC_A7RCR0, BIT(13) }, 668c2ecf20Sopenharmony_ci [IMX7_RESET_A7_SOC_DBG_RESET] = { SRC_A7RCR0, BIT(20) }, 678c2ecf20Sopenharmony_ci [IMX7_RESET_A7_L2RESET] = { SRC_A7RCR0, BIT(21) }, 688c2ecf20Sopenharmony_ci [IMX7_RESET_SW_M4C_RST] = { SRC_M4RCR, BIT(1) }, 698c2ecf20Sopenharmony_ci [IMX7_RESET_SW_M4P_RST] = { SRC_M4RCR, BIT(2) }, 708c2ecf20Sopenharmony_ci [IMX7_RESET_EIM_RST] = { SRC_ERCR, BIT(0) }, 718c2ecf20Sopenharmony_ci [IMX7_RESET_HSICPHY_PORT_RST] = { SRC_HSICPHY_RCR, BIT(1) }, 728c2ecf20Sopenharmony_ci [IMX7_RESET_USBPHY1_POR] = { SRC_USBOPHY1_RCR, BIT(0) }, 738c2ecf20Sopenharmony_ci [IMX7_RESET_USBPHY1_PORT_RST] = { SRC_USBOPHY1_RCR, BIT(1) }, 748c2ecf20Sopenharmony_ci [IMX7_RESET_USBPHY2_POR] = { SRC_USBOPHY2_RCR, BIT(0) }, 758c2ecf20Sopenharmony_ci [IMX7_RESET_USBPHY2_PORT_RST] = { SRC_USBOPHY2_RCR, BIT(1) }, 768c2ecf20Sopenharmony_ci [IMX7_RESET_MIPI_PHY_MRST] = { SRC_MIPIPHY_RCR, BIT(1) }, 778c2ecf20Sopenharmony_ci [IMX7_RESET_MIPI_PHY_SRST] = { SRC_MIPIPHY_RCR, BIT(2) }, 788c2ecf20Sopenharmony_ci [IMX7_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR, BIT(2) | BIT(1) }, 798c2ecf20Sopenharmony_ci [IMX7_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) }, 808c2ecf20Sopenharmony_ci [IMX7_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) }, 818c2ecf20Sopenharmony_ci [IMX7_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) }, 828c2ecf20Sopenharmony_ci [IMX7_RESET_DDRC_PRST] = { SRC_DDRC_RCR, BIT(0) }, 838c2ecf20Sopenharmony_ci [IMX7_RESET_DDRC_CORE_RST] = { SRC_DDRC_RCR, BIT(1) }, 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_cistatic struct imx7_src *to_imx7_src(struct reset_controller_dev *rcdev) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci return container_of(rcdev, struct imx7_src, rcdev); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_cistatic int imx7_reset_set(struct reset_controller_dev *rcdev, 928c2ecf20Sopenharmony_ci unsigned long id, bool assert) 938c2ecf20Sopenharmony_ci{ 948c2ecf20Sopenharmony_ci struct imx7_src *imx7src = to_imx7_src(rcdev); 958c2ecf20Sopenharmony_ci const unsigned int bit = imx7src->signals[id].bit; 968c2ecf20Sopenharmony_ci unsigned int value = assert ? bit : 0; 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci switch (id) { 998c2ecf20Sopenharmony_ci case IMX7_RESET_PCIEPHY: 1008c2ecf20Sopenharmony_ci /* 1018c2ecf20Sopenharmony_ci * wait for more than 10us to release phy g_rst and 1028c2ecf20Sopenharmony_ci * btnrst 1038c2ecf20Sopenharmony_ci */ 1048c2ecf20Sopenharmony_ci if (!assert) 1058c2ecf20Sopenharmony_ci udelay(10); 1068c2ecf20Sopenharmony_ci break; 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_ci case IMX7_RESET_PCIE_CTRL_APPS_EN: 1098c2ecf20Sopenharmony_ci value = assert ? 0 : bit; 1108c2ecf20Sopenharmony_ci break; 1118c2ecf20Sopenharmony_ci } 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci return imx7_reset_update(imx7src, id, value); 1148c2ecf20Sopenharmony_ci} 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_cistatic int imx7_reset_assert(struct reset_controller_dev *rcdev, 1178c2ecf20Sopenharmony_ci unsigned long id) 1188c2ecf20Sopenharmony_ci{ 1198c2ecf20Sopenharmony_ci return imx7_reset_set(rcdev, id, true); 1208c2ecf20Sopenharmony_ci} 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_cistatic int imx7_reset_deassert(struct reset_controller_dev *rcdev, 1238c2ecf20Sopenharmony_ci unsigned long id) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci return imx7_reset_set(rcdev, id, false); 1268c2ecf20Sopenharmony_ci} 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistatic const struct imx7_src_variant variant_imx7 = { 1298c2ecf20Sopenharmony_ci .signals = imx7_src_signals, 1308c2ecf20Sopenharmony_ci .signals_num = ARRAY_SIZE(imx7_src_signals), 1318c2ecf20Sopenharmony_ci .ops = { 1328c2ecf20Sopenharmony_ci .assert = imx7_reset_assert, 1338c2ecf20Sopenharmony_ci .deassert = imx7_reset_deassert, 1348c2ecf20Sopenharmony_ci }, 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cienum imx8mq_src_registers { 1388c2ecf20Sopenharmony_ci SRC_A53RCR0 = 0x0004, 1398c2ecf20Sopenharmony_ci SRC_HDMI_RCR = 0x0030, 1408c2ecf20Sopenharmony_ci SRC_DISP_RCR = 0x0034, 1418c2ecf20Sopenharmony_ci SRC_GPU_RCR = 0x0040, 1428c2ecf20Sopenharmony_ci SRC_VPU_RCR = 0x0044, 1438c2ecf20Sopenharmony_ci SRC_PCIE2_RCR = 0x0048, 1448c2ecf20Sopenharmony_ci SRC_MIPIPHY1_RCR = 0x004c, 1458c2ecf20Sopenharmony_ci SRC_MIPIPHY2_RCR = 0x0050, 1468c2ecf20Sopenharmony_ci SRC_DDRC2_RCR = 0x1004, 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cienum imx8mp_src_registers { 1508c2ecf20Sopenharmony_ci SRC_SUPERMIX_RCR = 0x0018, 1518c2ecf20Sopenharmony_ci SRC_AUDIOMIX_RCR = 0x001c, 1528c2ecf20Sopenharmony_ci SRC_MLMIX_RCR = 0x0028, 1538c2ecf20Sopenharmony_ci SRC_GPU2D_RCR = 0x0038, 1548c2ecf20Sopenharmony_ci SRC_GPU3D_RCR = 0x003c, 1558c2ecf20Sopenharmony_ci SRC_VPU_G1_RCR = 0x0048, 1568c2ecf20Sopenharmony_ci SRC_VPU_G2_RCR = 0x004c, 1578c2ecf20Sopenharmony_ci SRC_VPUVC8KE_RCR = 0x0050, 1588c2ecf20Sopenharmony_ci SRC_NOC_RCR = 0x0054, 1598c2ecf20Sopenharmony_ci}; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_cistatic const struct imx7_src_signal imx8mq_src_signals[IMX8MQ_RESET_NUM] = { 1628c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_POR_RESET0] = { SRC_A53RCR0, BIT(0) }, 1638c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_POR_RESET1] = { SRC_A53RCR0, BIT(1) }, 1648c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_POR_RESET2] = { SRC_A53RCR0, BIT(2) }, 1658c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_POR_RESET3] = { SRC_A53RCR0, BIT(3) }, 1668c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_RESET0] = { SRC_A53RCR0, BIT(4) }, 1678c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_RESET1] = { SRC_A53RCR0, BIT(5) }, 1688c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_RESET2] = { SRC_A53RCR0, BIT(6) }, 1698c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_CORE_RESET3] = { SRC_A53RCR0, BIT(7) }, 1708c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_DBG_RESET0] = { SRC_A53RCR0, BIT(8) }, 1718c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_DBG_RESET1] = { SRC_A53RCR0, BIT(9) }, 1728c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_DBG_RESET2] = { SRC_A53RCR0, BIT(10) }, 1738c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_DBG_RESET3] = { SRC_A53RCR0, BIT(11) }, 1748c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_ETM_RESET0] = { SRC_A53RCR0, BIT(12) }, 1758c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_ETM_RESET1] = { SRC_A53RCR0, BIT(13) }, 1768c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_ETM_RESET2] = { SRC_A53RCR0, BIT(14) }, 1778c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_ETM_RESET3] = { SRC_A53RCR0, BIT(15) }, 1788c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_SOC_DBG_RESET] = { SRC_A53RCR0, BIT(20) }, 1798c2ecf20Sopenharmony_ci [IMX8MQ_RESET_A53_L2RESET] = { SRC_A53RCR0, BIT(21) }, 1808c2ecf20Sopenharmony_ci [IMX8MQ_RESET_SW_NON_SCLR_M4C_RST] = { SRC_M4RCR, BIT(0) }, 1818c2ecf20Sopenharmony_ci [IMX8MQ_RESET_SW_M4C_RST] = { SRC_M4RCR, BIT(1) }, 1828c2ecf20Sopenharmony_ci [IMX8MQ_RESET_SW_M4P_RST] = { SRC_M4RCR, BIT(2) }, 1838c2ecf20Sopenharmony_ci [IMX8MQ_RESET_M4_ENABLE] = { SRC_M4RCR, BIT(3) }, 1848c2ecf20Sopenharmony_ci [IMX8MQ_RESET_OTG1_PHY_RESET] = { SRC_USBOPHY1_RCR, BIT(0) }, 1858c2ecf20Sopenharmony_ci [IMX8MQ_RESET_OTG2_PHY_RESET] = { SRC_USBOPHY2_RCR, BIT(0) }, 1868c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N] = { SRC_MIPIPHY_RCR, BIT(1) }, 1878c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_DSI_RESET_N] = { SRC_MIPIPHY_RCR, BIT(2) }, 1888c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N] = { SRC_MIPIPHY_RCR, BIT(3) }, 1898c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N] = { SRC_MIPIPHY_RCR, BIT(4) }, 1908c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N] = { SRC_MIPIPHY_RCR, BIT(5) }, 1918c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR, 1928c2ecf20Sopenharmony_ci BIT(2) | BIT(1) }, 1938c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) }, 1948c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) }, 1958c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) }, 1968c2ecf20Sopenharmony_ci [IMX8MQ_RESET_HDMI_PHY_APB_RESET] = { SRC_HDMI_RCR, BIT(0) }, 1978c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DISP_RESET] = { SRC_DISP_RCR, BIT(0) }, 1988c2ecf20Sopenharmony_ci [IMX8MQ_RESET_GPU_RESET] = { SRC_GPU_RCR, BIT(0) }, 1998c2ecf20Sopenharmony_ci [IMX8MQ_RESET_VPU_RESET] = { SRC_VPU_RCR, BIT(0) }, 2008c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIEPHY2] = { SRC_PCIE2_RCR, 2018c2ecf20Sopenharmony_ci BIT(2) | BIT(1) }, 2028c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIEPHY2_PERST] = { SRC_PCIE2_RCR, BIT(3) }, 2038c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIE2_CTRL_APPS_EN] = { SRC_PCIE2_RCR, BIT(6) }, 2048c2ecf20Sopenharmony_ci [IMX8MQ_RESET_PCIE2_CTRL_APPS_TURNOFF] = { SRC_PCIE2_RCR, BIT(11) }, 2058c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_CSI1_CORE_RESET] = { SRC_MIPIPHY1_RCR, BIT(0) }, 2068c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_CSI1_PHY_REF_RESET] = { SRC_MIPIPHY1_RCR, BIT(1) }, 2078c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_CSI1_ESC_RESET] = { SRC_MIPIPHY1_RCR, BIT(2) }, 2088c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_CSI2_CORE_RESET] = { SRC_MIPIPHY2_RCR, BIT(0) }, 2098c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_CSI2_PHY_REF_RESET] = { SRC_MIPIPHY2_RCR, BIT(1) }, 2108c2ecf20Sopenharmony_ci [IMX8MQ_RESET_MIPI_CSI2_ESC_RESET] = { SRC_MIPIPHY2_RCR, BIT(2) }, 2118c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DDRC1_PRST] = { SRC_DDRC_RCR, BIT(0) }, 2128c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DDRC1_CORE_RESET] = { SRC_DDRC_RCR, BIT(1) }, 2138c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DDRC1_PHY_RESET] = { SRC_DDRC_RCR, BIT(2) }, 2148c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DDRC2_PHY_RESET] = { SRC_DDRC2_RCR, BIT(0) }, 2158c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DDRC2_CORE_RESET] = { SRC_DDRC2_RCR, BIT(1) }, 2168c2ecf20Sopenharmony_ci [IMX8MQ_RESET_DDRC2_PRST] = { SRC_DDRC2_RCR, BIT(2) }, 2178c2ecf20Sopenharmony_ci}; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_cistatic int imx8mq_reset_set(struct reset_controller_dev *rcdev, 2208c2ecf20Sopenharmony_ci unsigned long id, bool assert) 2218c2ecf20Sopenharmony_ci{ 2228c2ecf20Sopenharmony_ci struct imx7_src *imx7src = to_imx7_src(rcdev); 2238c2ecf20Sopenharmony_ci const unsigned int bit = imx7src->signals[id].bit; 2248c2ecf20Sopenharmony_ci unsigned int value = assert ? bit : 0; 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_ci switch (id) { 2278c2ecf20Sopenharmony_ci case IMX8MQ_RESET_PCIEPHY: 2288c2ecf20Sopenharmony_ci case IMX8MQ_RESET_PCIEPHY2: 2298c2ecf20Sopenharmony_ci /* 2308c2ecf20Sopenharmony_ci * wait for more than 10us to release phy g_rst and 2318c2ecf20Sopenharmony_ci * btnrst 2328c2ecf20Sopenharmony_ci */ 2338c2ecf20Sopenharmony_ci if (!assert) 2348c2ecf20Sopenharmony_ci udelay(10); 2358c2ecf20Sopenharmony_ci break; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci case IMX8MQ_RESET_PCIE_CTRL_APPS_EN: 2388c2ecf20Sopenharmony_ci case IMX8MQ_RESET_PCIE2_CTRL_APPS_EN: 2398c2ecf20Sopenharmony_ci case IMX8MQ_RESET_MIPI_DSI_PCLK_RESET_N: 2408c2ecf20Sopenharmony_ci case IMX8MQ_RESET_MIPI_DSI_ESC_RESET_N: 2418c2ecf20Sopenharmony_ci case IMX8MQ_RESET_MIPI_DSI_DPI_RESET_N: 2428c2ecf20Sopenharmony_ci case IMX8MQ_RESET_MIPI_DSI_RESET_N: 2438c2ecf20Sopenharmony_ci case IMX8MQ_RESET_MIPI_DSI_RESET_BYTE_N: 2448c2ecf20Sopenharmony_ci case IMX8MQ_RESET_M4_ENABLE: 2458c2ecf20Sopenharmony_ci value = assert ? 0 : bit; 2468c2ecf20Sopenharmony_ci break; 2478c2ecf20Sopenharmony_ci } 2488c2ecf20Sopenharmony_ci 2498c2ecf20Sopenharmony_ci return imx7_reset_update(imx7src, id, value); 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_cistatic int imx8mq_reset_assert(struct reset_controller_dev *rcdev, 2538c2ecf20Sopenharmony_ci unsigned long id) 2548c2ecf20Sopenharmony_ci{ 2558c2ecf20Sopenharmony_ci return imx8mq_reset_set(rcdev, id, true); 2568c2ecf20Sopenharmony_ci} 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_cistatic int imx8mq_reset_deassert(struct reset_controller_dev *rcdev, 2598c2ecf20Sopenharmony_ci unsigned long id) 2608c2ecf20Sopenharmony_ci{ 2618c2ecf20Sopenharmony_ci return imx8mq_reset_set(rcdev, id, false); 2628c2ecf20Sopenharmony_ci} 2638c2ecf20Sopenharmony_ci 2648c2ecf20Sopenharmony_cistatic const struct imx7_src_variant variant_imx8mq = { 2658c2ecf20Sopenharmony_ci .signals = imx8mq_src_signals, 2668c2ecf20Sopenharmony_ci .signals_num = ARRAY_SIZE(imx8mq_src_signals), 2678c2ecf20Sopenharmony_ci .ops = { 2688c2ecf20Sopenharmony_ci .assert = imx8mq_reset_assert, 2698c2ecf20Sopenharmony_ci .deassert = imx8mq_reset_deassert, 2708c2ecf20Sopenharmony_ci }, 2718c2ecf20Sopenharmony_ci}; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_cistatic const struct imx7_src_signal imx8mp_src_signals[IMX8MP_RESET_NUM] = { 2748c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_POR_RESET0] = { SRC_A53RCR0, BIT(0) }, 2758c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_POR_RESET1] = { SRC_A53RCR0, BIT(1) }, 2768c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_POR_RESET2] = { SRC_A53RCR0, BIT(2) }, 2778c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_POR_RESET3] = { SRC_A53RCR0, BIT(3) }, 2788c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_RESET0] = { SRC_A53RCR0, BIT(4) }, 2798c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_RESET1] = { SRC_A53RCR0, BIT(5) }, 2808c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_RESET2] = { SRC_A53RCR0, BIT(6) }, 2818c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_CORE_RESET3] = { SRC_A53RCR0, BIT(7) }, 2828c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_DBG_RESET0] = { SRC_A53RCR0, BIT(8) }, 2838c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_DBG_RESET1] = { SRC_A53RCR0, BIT(9) }, 2848c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_DBG_RESET2] = { SRC_A53RCR0, BIT(10) }, 2858c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_DBG_RESET3] = { SRC_A53RCR0, BIT(11) }, 2868c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_ETM_RESET0] = { SRC_A53RCR0, BIT(12) }, 2878c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_ETM_RESET1] = { SRC_A53RCR0, BIT(13) }, 2888c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_ETM_RESET2] = { SRC_A53RCR0, BIT(14) }, 2898c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_ETM_RESET3] = { SRC_A53RCR0, BIT(15) }, 2908c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_SOC_DBG_RESET] = { SRC_A53RCR0, BIT(20) }, 2918c2ecf20Sopenharmony_ci [IMX8MP_RESET_A53_L2RESET] = { SRC_A53RCR0, BIT(21) }, 2928c2ecf20Sopenharmony_ci [IMX8MP_RESET_SW_NON_SCLR_M7C_RST] = { SRC_M4RCR, BIT(0) }, 2938c2ecf20Sopenharmony_ci [IMX8MP_RESET_OTG1_PHY_RESET] = { SRC_USBOPHY1_RCR, BIT(0) }, 2948c2ecf20Sopenharmony_ci [IMX8MP_RESET_OTG2_PHY_RESET] = { SRC_USBOPHY2_RCR, BIT(0) }, 2958c2ecf20Sopenharmony_ci [IMX8MP_RESET_SUPERMIX_RESET] = { SRC_SUPERMIX_RCR, BIT(0) }, 2968c2ecf20Sopenharmony_ci [IMX8MP_RESET_AUDIOMIX_RESET] = { SRC_AUDIOMIX_RCR, BIT(0) }, 2978c2ecf20Sopenharmony_ci [IMX8MP_RESET_MLMIX_RESET] = { SRC_MLMIX_RCR, BIT(0) }, 2988c2ecf20Sopenharmony_ci [IMX8MP_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR, BIT(2) }, 2998c2ecf20Sopenharmony_ci [IMX8MP_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) }, 3008c2ecf20Sopenharmony_ci [IMX8MP_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) }, 3018c2ecf20Sopenharmony_ci [IMX8MP_RESET_PCIE_CTRL_APPS_TURNOFF] = { SRC_PCIEPHY_RCR, BIT(11) }, 3028c2ecf20Sopenharmony_ci [IMX8MP_RESET_HDMI_PHY_APB_RESET] = { SRC_HDMI_RCR, BIT(0) }, 3038c2ecf20Sopenharmony_ci [IMX8MP_RESET_MEDIA_RESET] = { SRC_DISP_RCR, BIT(0) }, 3048c2ecf20Sopenharmony_ci [IMX8MP_RESET_GPU2D_RESET] = { SRC_GPU2D_RCR, BIT(0) }, 3058c2ecf20Sopenharmony_ci [IMX8MP_RESET_GPU3D_RESET] = { SRC_GPU3D_RCR, BIT(0) }, 3068c2ecf20Sopenharmony_ci [IMX8MP_RESET_GPU_RESET] = { SRC_GPU_RCR, BIT(0) }, 3078c2ecf20Sopenharmony_ci [IMX8MP_RESET_VPU_RESET] = { SRC_VPU_RCR, BIT(0) }, 3088c2ecf20Sopenharmony_ci [IMX8MP_RESET_VPU_G1_RESET] = { SRC_VPU_G1_RCR, BIT(0) }, 3098c2ecf20Sopenharmony_ci [IMX8MP_RESET_VPU_G2_RESET] = { SRC_VPU_G2_RCR, BIT(0) }, 3108c2ecf20Sopenharmony_ci [IMX8MP_RESET_VPUVC8KE_RESET] = { SRC_VPUVC8KE_RCR, BIT(0) }, 3118c2ecf20Sopenharmony_ci [IMX8MP_RESET_NOC_RESET] = { SRC_NOC_RCR, BIT(0) }, 3128c2ecf20Sopenharmony_ci}; 3138c2ecf20Sopenharmony_ci 3148c2ecf20Sopenharmony_cistatic int imx8mp_reset_set(struct reset_controller_dev *rcdev, 3158c2ecf20Sopenharmony_ci unsigned long id, bool assert) 3168c2ecf20Sopenharmony_ci{ 3178c2ecf20Sopenharmony_ci struct imx7_src *imx7src = to_imx7_src(rcdev); 3188c2ecf20Sopenharmony_ci const unsigned int bit = imx7src->signals[id].bit; 3198c2ecf20Sopenharmony_ci unsigned int value = assert ? bit : 0; 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci switch (id) { 3228c2ecf20Sopenharmony_ci case IMX8MP_RESET_PCIEPHY: 3238c2ecf20Sopenharmony_ci /* 3248c2ecf20Sopenharmony_ci * wait for more than 10us to release phy g_rst and 3258c2ecf20Sopenharmony_ci * btnrst 3268c2ecf20Sopenharmony_ci */ 3278c2ecf20Sopenharmony_ci if (!assert) 3288c2ecf20Sopenharmony_ci udelay(10); 3298c2ecf20Sopenharmony_ci break; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci case IMX8MP_RESET_PCIE_CTRL_APPS_EN: 3328c2ecf20Sopenharmony_ci case IMX8MP_RESET_PCIEPHY_PERST: 3338c2ecf20Sopenharmony_ci value = assert ? 0 : bit; 3348c2ecf20Sopenharmony_ci break; 3358c2ecf20Sopenharmony_ci } 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci return imx7_reset_update(imx7src, id, value); 3388c2ecf20Sopenharmony_ci} 3398c2ecf20Sopenharmony_ci 3408c2ecf20Sopenharmony_cistatic int imx8mp_reset_assert(struct reset_controller_dev *rcdev, 3418c2ecf20Sopenharmony_ci unsigned long id) 3428c2ecf20Sopenharmony_ci{ 3438c2ecf20Sopenharmony_ci return imx8mp_reset_set(rcdev, id, true); 3448c2ecf20Sopenharmony_ci} 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_cistatic int imx8mp_reset_deassert(struct reset_controller_dev *rcdev, 3478c2ecf20Sopenharmony_ci unsigned long id) 3488c2ecf20Sopenharmony_ci{ 3498c2ecf20Sopenharmony_ci return imx8mp_reset_set(rcdev, id, false); 3508c2ecf20Sopenharmony_ci} 3518c2ecf20Sopenharmony_ci 3528c2ecf20Sopenharmony_cistatic const struct imx7_src_variant variant_imx8mp = { 3538c2ecf20Sopenharmony_ci .signals = imx8mp_src_signals, 3548c2ecf20Sopenharmony_ci .signals_num = ARRAY_SIZE(imx8mp_src_signals), 3558c2ecf20Sopenharmony_ci .ops = { 3568c2ecf20Sopenharmony_ci .assert = imx8mp_reset_assert, 3578c2ecf20Sopenharmony_ci .deassert = imx8mp_reset_deassert, 3588c2ecf20Sopenharmony_ci }, 3598c2ecf20Sopenharmony_ci}; 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_cistatic int imx7_reset_probe(struct platform_device *pdev) 3628c2ecf20Sopenharmony_ci{ 3638c2ecf20Sopenharmony_ci struct imx7_src *imx7src; 3648c2ecf20Sopenharmony_ci struct device *dev = &pdev->dev; 3658c2ecf20Sopenharmony_ci struct regmap_config config = { .name = "src" }; 3668c2ecf20Sopenharmony_ci const struct imx7_src_variant *variant = of_device_get_match_data(dev); 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci imx7src = devm_kzalloc(dev, sizeof(*imx7src), GFP_KERNEL); 3698c2ecf20Sopenharmony_ci if (!imx7src) 3708c2ecf20Sopenharmony_ci return -ENOMEM; 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_ci imx7src->signals = variant->signals; 3738c2ecf20Sopenharmony_ci imx7src->regmap = syscon_node_to_regmap(dev->of_node); 3748c2ecf20Sopenharmony_ci if (IS_ERR(imx7src->regmap)) { 3758c2ecf20Sopenharmony_ci dev_err(dev, "Unable to get imx7-src regmap"); 3768c2ecf20Sopenharmony_ci return PTR_ERR(imx7src->regmap); 3778c2ecf20Sopenharmony_ci } 3788c2ecf20Sopenharmony_ci regmap_attach_dev(dev, imx7src->regmap, &config); 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_ci imx7src->rcdev.owner = THIS_MODULE; 3818c2ecf20Sopenharmony_ci imx7src->rcdev.nr_resets = variant->signals_num; 3828c2ecf20Sopenharmony_ci imx7src->rcdev.ops = &variant->ops; 3838c2ecf20Sopenharmony_ci imx7src->rcdev.of_node = dev->of_node; 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci return devm_reset_controller_register(dev, &imx7src->rcdev); 3868c2ecf20Sopenharmony_ci} 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_cistatic const struct of_device_id imx7_reset_dt_ids[] = { 3898c2ecf20Sopenharmony_ci { .compatible = "fsl,imx7d-src", .data = &variant_imx7 }, 3908c2ecf20Sopenharmony_ci { .compatible = "fsl,imx8mq-src", .data = &variant_imx8mq }, 3918c2ecf20Sopenharmony_ci { .compatible = "fsl,imx8mp-src", .data = &variant_imx8mp }, 3928c2ecf20Sopenharmony_ci { /* sentinel */ }, 3938c2ecf20Sopenharmony_ci}; 3948c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, imx7_reset_dt_ids); 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_cistatic struct platform_driver imx7_reset_driver = { 3978c2ecf20Sopenharmony_ci .probe = imx7_reset_probe, 3988c2ecf20Sopenharmony_ci .driver = { 3998c2ecf20Sopenharmony_ci .name = KBUILD_MODNAME, 4008c2ecf20Sopenharmony_ci .of_match_table = imx7_reset_dt_ids, 4018c2ecf20Sopenharmony_ci }, 4028c2ecf20Sopenharmony_ci}; 4038c2ecf20Sopenharmony_cimodule_platform_driver(imx7_reset_driver); 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ciMODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>"); 4068c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("NXP i.MX7 reset driver"); 4078c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 408