From patchwork Mon Jun 17 20:16:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13701384 Received: from EUR03-VI1-obe.outbound.protection.outlook.com (mail-vi1eur03on2058.outbound.protection.outlook.com [40.107.103.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BBCC198E9E for ; Mon, 17 Jun 2024 20:17:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.103.58 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718655459; cv=fail; b=ID3eUqE9wBoCKRxyHcAfFK+rpXfSeri1QOonyttyxbnu1tbS0qwdiNsie+ZGnqif9oduZfKQDRcR4QAJj7K7YQ8IpvXY2/Ub91+UH+KBGphWEvyFuuLWFRPHKqZ+PRKFwg7FzkB3hk03SkM+LgJ34FGmqCZ3xXGC4uIPJmTfzGw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718655459; c=relaxed/simple; bh=AfTVrCLrEti1105wDAcVWo6jI2pjgIWKJzNX5Ep+/9w=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=M22zAOtMKDH237kM8Prk412YuuzR03VAolZddEIPOc7Uvs9gds9inXd6X3PL5qpvpgGXjBLD0P17AtzG06qcHsSJoRc/CEkSTnRplDwd/q0vYWEbzRAXdDaUXaApsHnYtvDoUj5lCpe6YuX6oYmt0jpkSNCCW0bxiHPtd+0o0oo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=LRBotwml; arc=fail smtp.client-ip=40.107.103.58 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="LRBotwml" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hedIVkg2El+B0dZN6ylBwMn4jMFw7MZYdvKR6t8CTk7mIzL45MUdBfqT3W4Odg6CXgWnpQNcz4JAIe+1hPbe2RKznTBZb/rm5Gq9Ima4CkL5L2ImyrFZlu0ZTj3wNJA2tVPFkZi1jtbMTe/T6voi2tZTzJIxzvqzjo2+n8EPGcijp0FUo0IGlWXm1bU/gz7BinJ09AaJPPQX5xfSAIML1tv8DFjrsdnyBtzlnGh11SlnaFo8h1UvsUQmjNtgULJjHILxD1Tk7fPxHpDVGtRxpt9LgkNk/feht86Yo26biGBbPmvXI4cuYuxHGHr7LtZsJqS9Ek5H35rxjVIvCgRqFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BFZ9y59NHvkPdCbZdfCtsYWQoubEyRTUZZdNbOF+uvs=; b=iYK9MImEKSyDpboKcRFA/PCszi4Izq7NCBOmR+1xorUMjmLv3vT5KcVn/O8BPIbiW0RfaBeRmU2Gm02snZLu+X3M9zT6P15hDG8Xpx831Lfjy8hW8VR+JPYCL6ZGPh+5FEH0/KTD0vP2TzzXLEsazlifxL5tG4M+yp2U7VzAlOtRq0vlXAu+IbrNTgsCuVGwFMzF3HhuED3CCOIr9gLea/E+qyIEEHUCyHjWHc7qLWNICcJ4drd+ukXf8RVgOoEgDrIgzaILprDwG9kSyfbULr2sdcqAJezIOHDxNh0zE0wNI1diLVpHcv/kV3TmNELYc+sKEUGoHkXyntJo0Qv5Kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=BFZ9y59NHvkPdCbZdfCtsYWQoubEyRTUZZdNbOF+uvs=; b=LRBotwmlZHkreOaahvdfj3XurXFdMiWHK7MufhY41XsMcjrshT01rT9++7LKdewI9nEearDil1qHrDsEy29E8diPkX5C5zhIxRIaZ+16Ln0XuyOTmm7J2XBAu5QDkmOUH7tVj7ghKbA4g7qkjFosOnEkyKMUcAvLu7ADbRxlNVg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PA4PR04MB7997.eurprd04.prod.outlook.com (2603:10a6:102:c9::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7677.30; Mon, 17 Jun 2024 20:17:35 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%2]) with mapi id 15.20.7677.030; Mon, 17 Jun 2024 20:17:35 +0000 From: Frank Li Date: Mon, 17 Jun 2024 16:16:40 -0400 Subject: [PATCH v6 04/10] PCI: imx6: Introduce SoC specific callbacks for controlling REFCLK Message-Id: <20240617-pci2_upstream-v6-4-e0821238f997@nxp.com> References: <20240617-pci2_upstream-v6-0-e0821238f997@nxp.com> In-Reply-To: <20240617-pci2_upstream-v6-0-e0821238f997@nxp.com> To: Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy?= =?utf-8?q?=C5=84ski?= , Rob Herring , Bjorn Helgaas , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Philipp Zabel , Liam Girdwood , Mark Brown , Manivannan Sadhasivam , Krzysztof Kozlowski , Conor Dooley Cc: linux-pci@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, devicetree@vger.kernel.org, Frank Li X-Mailer: b4 0.13-dev-e586c X-Developer-Signature: v=1; a=ed25519-sha256; t=1718655424; l=8294; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=AfTVrCLrEti1105wDAcVWo6jI2pjgIWKJzNX5Ep+/9w=; b=1Jmd0QbXMPxXo3v3/vatM08XLdpHfMiGbqmJnhHDVAXFbCE2KLER23dNPPZDb0nCj74uRnziJ VBowt2kmJrdD60z5T8ImK/30Qg7gxFz4YFzfeOge6jJtzkg98mKWqNX X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR05CA0116.namprd05.prod.outlook.com (2603:10b6:a03:334::31) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PA4PR04MB7997:EE_ X-MS-Office365-Filtering-Correlation-Id: 99f2cad9-2e60-45f0-f5e3-08dc8f0a86b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230037|376011|7416011|1800799021|366013|52116011|38350700011|921017; X-Microsoft-Antispam-Message-Info: =?utf-8?q?v0DG3AYuIJvcVpA0fobPNL/f3px4tNQ?=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6kw?= =?utf-8?q?KGqJAppzWHcSvOyQDBLRQErUA0DF/Om7ltGlY8OXZssq++eUSlI0PEEasBPClbF59?= =?utf-8?q?aUx9wAph8jZ7kZUQQrSBXopTZd5+3L7hPGxlF9SvEvoxrEWeeRZIsPdsUV7I8v6oQ?= =?utf-8?q?TGWow1iYTXIH/WI1nP+fNVFuSpfsSGLw0BFp4jE6DDmUVYgjKT1JHQnJQ16KLkCPZ?= =?utf-8?q?niSpOBndS4J5LdFJbAEYwIWLZ0nXKSiC6u54h4Raa2EDsJyRcVbRAgCkVXEVKDyfE?= =?utf-8?q?RuHLD3GgUgjhHywhWJNgFbpu11XU7Ihv/KYnkur7kZDBU1sMwOd0Pyf5Jc1OJuwUg?= =?utf-8?q?b9Z0gtXzCoY6dGTRnD8RT+WCOpEtQci5107iQDKb79Xm0U4rxWG3/JpKyGmilyH/X?= =?utf-8?q?rPEuk4GaI9QHoG8N+CIcoZIrisoghGAvm6jHgAMWpSYTDMnUFaxyGMOlw6qDnvWLq?= =?utf-8?q?f0tzeotvEeS4?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9642.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230037)(376011)(7416011)(1800799021)(366013)(52116011)(38350700011)(921017);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?2XA8hYVckA1MzqM5kA7RaGcwJ2iE?= =?utf-8?q?WGUlN2/OdimQZ9OXJUu5rlQTxjYAlPWi1lWyIuhwSiNOUlOoxCSWKIHbtW3Q8xxV+?= =?utf-8?q?MoaNdRPDQxBbMcEErNLcCJVFtUKJZxTQ+El5oi8V5Dw2m/KqzNzCbmRA7Mc8bIl39?= =?utf-8?q?lT7mA0rn21kZjXe02/IRL5PAVicolRBnICbHtqgffSW2B4bsUBPVvcdvPee7gNX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Qs?= =?utf-8?q?8vhZzrR4VTMX1U8r9CVEn48t6EU7zlx7fecoGg6ZldwyDcNcILjNeoZ6R0gQgErLh?= =?utf-8?q?ZACeIo18LGcX9AJizeI274jaCMLcBoztLiGwK6CAiPa82JIyyBmImb5mU7tiR0bCZ?= =?utf-8?q?wMuT2VEWsEw+zkeinRhlrvGsMjWDXRfKm+kMNj1gB74CYDtAAmVTs1NW9aRtljbjR?= =?utf-8?q?gJGBPRjHCEx8qI5e+iV/tYlev5ZPNTQF9r56jm2WwOVASN6rTVeGWCp/yWNdZR9fO?= =?utf-8?q?V0hywvBKHoFxkC06cmXs6CMeQ5nOHqmpvArLNrMcI6GGVLYXWmp5u+X2GzvkmIsLi?= =?utf-8?q?AErjgYqsnMZWkhXFpnV/GFCEBqWx1zLesA9dfYl2iHd1qq8YptlSUzgXJBF0Z9wPT?= =?utf-8?q?3KWl8qCgwk3ry1HcI/o/Tb/lvN0W/4+CK3Ysq+3ntzFslnH5iaMAyVXIRRQiTgf+E?= =?utf-8?q?N+pIrJhpVUqw?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99f2cad9-2e60-45f0-f5e3-08dc8f0a86b3 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jun 2024 20:17:35.3014 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: pzm01p0+tQuhhHiE5K5vT8eYvPR86iAPH/n9AGoPct2rK1bvLgIqtcavIRTvoCHalQFKYYN4Nar3BNrtDTMf6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7997 Instead of using the switch case statement to enable/disable the reference clock handled by this driver itself, let's introduce a new callback set_ref_clk() and define it for platforms that require it. This simplifies the code. Signed-off-by: Frank Li --- drivers/pci/controller/dwc/pci-imx6.c | 112 ++++++++++++++++------------------ 1 file changed, 52 insertions(+), 60 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 47134e2dfecf2..ff9d0098294fa 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -103,6 +103,7 @@ struct imx_pcie_drvdata { const u32 mode_mask[IMX_PCIE_MAX_INSTANCES]; const struct pci_epc_features *epc_features; int (*init_phy)(struct imx_pcie *pcie); + int (*set_ref_clk)(struct imx_pcie *pcie, bool enable); }; struct imx_pcie { @@ -585,21 +586,19 @@ static int imx_pcie_attach_pd(struct device *dev) return 0; } -static int imx_pcie_enable_ref_clk(struct imx_pcie *imx_pcie) +static int imx6sx_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) { - unsigned int offset; - int ret = 0; + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX6SX_GPR12_PCIE_TEST_POWERDOWN, + enable ? 0 : IMX6SX_GPR12_PCIE_TEST_POWERDOWN); - switch (imx_pcie->drvdata->variant) { - case IMX6SX: - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, - IMX6SX_GPR12_PCIE_TEST_POWERDOWN, 0); - break; - case IMX6QP: - case IMX6Q: + return 0; +} + +static int imx6q_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) +{ + if (enable) { /* power up core phy and enable ref clock */ - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, - IMX6Q_GPR1_PCIE_TEST_PD, 0 << 18); + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD, 0); /* * the async reset input need ref clock to sync internally, * when the ref clock comes after reset, internal synced @@ -608,54 +607,34 @@ static int imx_pcie_enable_ref_clk(struct imx_pcie *imx_pcie) */ usleep_range(10, 100); regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, - IMX6Q_GPR1_PCIE_REF_CLK_EN, 1 << 16); - break; - case IMX7D: - case IMX95: - case IMX95_EP: - break; - case IMX8MM: - case IMX8MM_EP: - case IMX8MQ: - case IMX8MQ_EP: - case IMX8MP: - case IMX8MP_EP: - offset = imx_pcie_grp_offset(imx_pcie); - /* - * Set the over ride low and enabled - * make sure that REF_CLK is turned on. - */ - regmap_update_bits(imx_pcie->iomuxc_gpr, offset, - IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE, - 0); - regmap_update_bits(imx_pcie->iomuxc_gpr, offset, - IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN, - IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN); - break; + IMX6Q_GPR1_PCIE_REF_CLK_EN, IMX6Q_GPR1_PCIE_REF_CLK_EN); + } else { + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, + IMX6Q_GPR1_PCIE_REF_CLK_EN, 0); + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, + IMX6Q_GPR1_PCIE_TEST_PD, IMX6Q_GPR1_PCIE_TEST_PD); } - return ret; + return 0; } -static void imx_pcie_disable_ref_clk(struct imx_pcie *imx_pcie) +static int imx8mm_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) { - switch (imx_pcie->drvdata->variant) { - case IMX6QP: - case IMX6Q: - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, - IMX6Q_GPR1_PCIE_REF_CLK_EN, 0); - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, - IMX6Q_GPR1_PCIE_TEST_PD, - IMX6Q_GPR1_PCIE_TEST_PD); - break; - case IMX7D: - regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, - IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, - IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); - break; - default: - break; - } + int offset = imx_pcie_grp_offset(imx_pcie); + + /* Set the over ride low and enabled make sure that REF_CLK is turned on.*/ + regmap_update_bits(imx_pcie->iomuxc_gpr, offset, IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE, + enable ? 0 : IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE); + regmap_update_bits(imx_pcie->iomuxc_gpr, offset, IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN, + enable ? IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN : 0); + return 0; +} + +static int imx7d_pcie_set_ref_clk(struct imx_pcie *imx_pcie, bool enable) +{ + regmap_update_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, + enable ? 0 : IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); + return 0; } static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) @@ -668,10 +647,12 @@ static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) if (ret) return ret; - ret = imx_pcie_enable_ref_clk(imx_pcie); - if (ret) { - dev_err(dev, "unable to enable pcie ref clock\n"); - goto err_ref_clk; + if (imx_pcie->drvdata->set_ref_clk) { + ret = imx_pcie->drvdata->set_ref_clk(imx_pcie, true); + if (ret) { + dev_err(dev, "Failed to enable PCIe REFCLK\n"); + goto err_ref_clk; + } } /* allow the clocks to stabilize */ @@ -686,7 +667,8 @@ static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) static void imx_pcie_clk_disable(struct imx_pcie *imx_pcie) { - imx_pcie_disable_ref_clk(imx_pcie); + if (imx_pcie->drvdata->set_ref_clk) + imx_pcie->drvdata->set_ref_clk(imx_pcie, false); clk_bulk_disable_unprepare(imx_pcie->drvdata->clks_cnt, imx_pcie->clks); } @@ -1475,6 +1457,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, .init_phy = imx_pcie_init_phy, + .set_ref_clk = imx6q_pcie_set_ref_clk, }, [IMX6SX] = { .variant = IMX6SX, @@ -1489,6 +1472,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, .init_phy = imx6sx_pcie_init_phy, + .set_ref_clk = imx6sx_pcie_set_ref_clk, }, [IMX6QP] = { .variant = IMX6QP, @@ -1504,6 +1488,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, .init_phy = imx_pcie_init_phy, + .set_ref_clk = imx6q_pcie_set_ref_clk, }, [IMX7D] = { .variant = IMX7D, @@ -1516,6 +1501,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, .init_phy = imx7d_pcie_init_phy, + .set_ref_clk = imx7d_pcie_set_ref_clk, }, [IMX8MQ] = { .variant = IMX8MQ, @@ -1529,6 +1515,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[1] = IOMUXC_GPR12, .mode_mask[1] = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, .init_phy = imx8mq_pcie_init_phy, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX8MM] = { .variant = IMX8MM, @@ -1540,6 +1527,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .clks_cnt = ARRAY_SIZE(imx8mm_clks), .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX8MP] = { .variant = IMX8MP, @@ -1551,6 +1539,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .clks_cnt = ARRAY_SIZE(imx8mm_clks), .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX95] = { .variant = IMX95, @@ -1577,6 +1566,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_mask[1] = IMX8MQ_GPR12_PCIE2_CTRL_DEVICE_TYPE, .epc_features = &imx8m_pcie_epc_features, .init_phy = imx8mq_pcie_init_phy, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX8MM_EP] = { .variant = IMX8MM_EP, @@ -1589,6 +1579,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, .epc_features = &imx8m_pcie_epc_features, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX8MP_EP] = { .variant = IMX8MP_EP, @@ -1601,6 +1592,7 @@ static const struct imx_pcie_drvdata drvdata[] = { .mode_off[0] = IOMUXC_GPR12, .mode_mask[0] = IMX6Q_GPR12_DEVICE_TYPE, .epc_features = &imx8m_pcie_epc_features, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX95_EP] = { .variant = IMX95_EP,