Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp4121240rba; Tue, 2 Apr 2024 08:10:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUJxDLLPCT2FECMjc/0W9eGpKUZwLHTGqdhD+LG3aR23/GZDP3vWJ016hD+1DUlTpa3dQ5AcyY0DxXwa/HSxuLwMG5sbcZ2rPb+Q6hUSQ== X-Google-Smtp-Source: AGHT+IEHCpuBBoncJP6m3ae+AeCLPLa07hZWTkv+LOlXfbtW5Pt5or6N1BmpN4zuwa5nLnfmQFH2 X-Received: by 2002:a05:6a21:6d8e:b0:1a5:6a5f:b0b9 with SMTP id wl14-20020a056a216d8e00b001a56a5fb0b9mr12128054pzb.48.1712070622274; Tue, 02 Apr 2024 08:10:22 -0700 (PDT) Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id v7-20020a631507000000b005f0be94d560si1020274pgl.161.2024.04.02.08.10.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 08:10:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128149-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=s2mao6s+; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-128149-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128149-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E91CFB28007 for ; Tue, 2 Apr 2024 14:36:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 998D2133991; Tue, 2 Apr 2024 14:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="s2mao6s+" Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2126.outbound.protection.outlook.com [40.107.22.126]) (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 7DE7412BF3A; Tue, 2 Apr 2024 14:34:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.22.126 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712068473; cv=fail; b=JcMCEhjwAdWUtebb/YjDHTDSbYYhyhyOTHfHsZGtts4+WKEFhzSJCs7ZHLH0wD64khWt0k6H6Lyqc9T05dRe+5WlEkXMdcm/O6eMwFEJ4dPEvmJfM2bcmx+JD7J2C/5ldpNpiYyUVnbiJRQpooR2dVciiUF1RPWfmLBOxjs5r8E= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712068473; c=relaxed/simple; bh=Zkat84ae4D6SJKi9k9YgxhUo2QzbOldgU2Uww6OuZ8w=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=cpo3OKGfmGQX52VH3FRG0K5NQFNp11YmgGzdY8bWYmqlP0v8oRkCn02nwVd1uNthqV2rx4u9/YUGlm6jMl797H20YBK1w/51cmzq0mVnth3BKxT8CmBUBDyl7tRXQ7DBhUVDvky31QONsnAQq+zC2ZovL9iv9n/ieOVaDk+/mac= 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=s2mao6s+; arc=fail smtp.client-ip=40.107.22.126 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 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LNdZJRby9zoUKj6k95n3aDInG9kIW01diZkNv0PIQPqEkOWglyHL/lNef8ZChqz6qOA65OZ1SO/fTWjd/bPyH/PYv8yXIerhK3ohWee9xE0VYXMooPX0Y03fBO5cDjAExMbFYC+9FPnmotq7p6UOqIffbRB0ODXVCfjs6G2KqsZl7FZKU1ilQrcIb8dZ7IHHb31KQyBv6pLSvO+xxaeN7Rt1a+sSU3ZDq0QQOXId3q6NK7oADRpAG8vzsZJZRmyxdMXKVQc5WtPGQD+wgbsoiu6ujOOzGbvC9Sog/PpK7oAsr5mmet8jDtZZqxjWRPb3vYkB7dzJ/yZ1+QAgnhThXw== 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=MMvuhnK89TFLqeVqTbSme4IZrMraiLpWEPVOPWW1QQE=; b=mpMOmHz7oONOtv9EM7eujh/y+/YOz/mob6swI86mt4JImHEA4XwI7hbdgV/93CPUlbM0ccP8G3MnO83DfUruQHRsYEFtcqMWJLu4t1XdYw9iPHp7r32caLCac9ucRXcuxXTT2gYfXB0eSytKXIt0eXDkfAityLGjvnatVwKsFNvCj4CXYfntbPy9HbWwRvVng/LFwNGDrxGnH4iwNdzj4Xo7PeUMnivlxRBffAAoDQRc6B5PAGScAXj+nc5RjJ5/bkkFOcFQU8XAQSgmT2svIYcXofID1wpqZu/GsEmy+irVYrjTD86+JvR1lUl/lZWczKvHsdYdPMnphYbeiKeM7w== 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=MMvuhnK89TFLqeVqTbSme4IZrMraiLpWEPVOPWW1QQE=; b=s2mao6s+TNzgO1DprVi1Hf40gwGcT61FOTl/WH1lgHgMcKsyewNplHb19JqvrRqwCEcANFiU7Mx1bsVqE8ISoru1IF39v+nmL3fxc1N68lH/N6hVTyfWoVqv66m1RvwYleluSs3SIzZXwlgHF0bXgzeG8bMfXQNcg/q+ejoYZwk= Received: from PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) by PAXPR04MB8926.eurprd04.prod.outlook.com (2603:10a6:102:20d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Tue, 2 Apr 2024 14:34:28 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::3168:91:27c6:edf6]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::3168:91:27c6:edf6%3]) with mapi id 15.20.7409.042; Tue, 2 Apr 2024 14:34:28 +0000 From: Frank Li Date: Tue, 02 Apr 2024 10:33:42 -0400 Subject: [PATCH v3 06/11] PCI: imx: Simplify switch-case logic by involve set_ref_clk callback Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240402-pci2_upstream-v3-6-803414bdb430@nxp.com> References: <20240402-pci2_upstream-v3-0-803414bdb430@nxp.com> In-Reply-To: <20240402-pci2_upstream-v3-0-803414bdb430@nxp.com> To: Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=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=1712068432; l=8518; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=Zkat84ae4D6SJKi9k9YgxhUo2QzbOldgU2Uww6OuZ8w=; b=shQ8QZKR8yRWA88UqsG+XTX+cBOG+AdO6vSvuEjsbquiPESZYMJHF2vB11UR7YZbGsW1vOT4s n/IOsEsqO14DI81quZJva1IMwp+i6iBjPiFsAMLpgk2+QH/aF5k6GA7 X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: PH7PR17CA0011.namprd17.prod.outlook.com (2603:10b6:510:324::20) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|PAXPR04MB8926:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XSTfYK74N/rtFJkI2ez7Jm9zfSyaaD/8+SVpyMeRlRABuq9najvxX36IUYqrXCVEK24lpVWQBpjCqJf3/84YnPe2WloisY9MtUcEMcrefRuTKJrMxLHl53Am5CJ9L5kn9w36y7OuGXkthHibbzVaiTpMiy03yocmqG+aoqomaRcEwuxsqPwtYkOVZsbNTxK8Sc2Ymp9qszpbZxmW07roVb4dkeRDvsyZ3T5PMAU7RFW8h0EiSh1sNE9PIKhcmExOVnHx30/q1/Qa3FmR6Y7tFobLKDZF89nEwQCgeIPJm2ThfoS1DDt64AuqsCrUySy+2lO2XdFaCVKzO/C2dUtBPUiZdsD4we++danEtF51M3sOmcfzvfkjBBc+k+kkiFmYBd0UxgbYD9mBC8lvU8bhEDz+lGv8+bqNy3ZPEdnKUi6wWDo+oW8flQHN0VXnhIFpKyhkfHqo/5+/PlNXSoF7c/SQ2Fef0knHjj6Z/T+rJPtg7wAB3JX8apOyqTwohx7emlWZ75DMYWezszlV3EEg9LqBljtn0mFrsm+KX5Bu9WLGx10G6DCxV8WbNOasmsFBZmO4Q/hzeKqQEz5r3TkPPycLzXtErYtqiFN+I7p33kkSejC4kWMl3AvOpmIBdFzeYc0zFzzW12cA6O0B2EBlkGbT0bijAYOAxKsmWOMJAqdmM94zbT0G824iR3QqB9ir5b9ffmbaaMX+7xziUGP21RWX3Uf+uQuCoi3HFd++oAs= 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:(13230031)(1800799015)(52116005)(7416005)(376005)(366007)(921011)(38350700005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?S1ZGZHN4dEZ2c01lcXRwSEhjMzNJWXlmL0xid1JLbDl3Z242RHl4M2pWWDBR?= =?utf-8?B?NS81VlZDemxnYlRUQkZLaVBRRXBzdFdVdS9KTlN1QXpJaUZxdmxQVEl4Wlh4?= =?utf-8?B?WHM0THl0VlFpVGFQTkppczdFVWNUVjRjT1JoRytpUXhFYnp5RE9ZRTJnZ2VV?= =?utf-8?B?Z2dRNXpDdVVSUGdRbWlZUVZUaFR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?utf-8?B?RFVzYkVtY2xCTG5tRTE1RE91L011WnNhVlhzWHR6TkQ1bVhPY29pOGcrbUtL?= =?utf-8?B?aCt6MXZSMVdQWk5wN0pXeng3aXZuOHBUcDdpb01GRmhucERJbzBwY0ErV2J3?= =?utf-8?Q?/uzI=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d1c0610f-578e-4831-7608-08dc5322005d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Apr 2024 14:34:28.1311 (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: SMhYZraARkPrZK5ndgrV2EskqctmhilG8hNeRpTKbetHxFEbIG7FXQCJ8s/vA7g9fjItza8slk9fXrxRD2DW7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8926 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/pcie-imx.c | 119 ++++++++++++++++------------------ 1 file changed, 55 insertions(+), 64 deletions(-) diff --git a/drivers/pci/controller/dwc/pcie-imx.c b/drivers/pci/controller/dwc/pcie-imx.c index e93070d60df52..77dae5c3f7057 100644 --- a/drivers/pci/controller/dwc/pcie-imx.c +++ b/drivers/pci/controller/dwc/pcie-imx.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,77 +586,54 @@ 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 - * reset time is too short, cannot meet the requirement. - * add one ~10us delay here. + * the async reset input need ref clock to sync internally, when the ref clock comes + * after reset, internal synced reset time is too short, cannot meet the + * requirement.add one ~10us delay here. */ 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 +646,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, "unable to enable pcie ref clock\n"); + goto err_ref_clk; + } } /* allow the clocks to stabilize */ @@ -686,7 +666,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); } @@ -1465,6 +1446,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, @@ -1479,6 +1461,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, @@ -1494,6 +1477,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, @@ -1506,6 +1490,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, @@ -1519,6 +1504,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, @@ -1530,6 +1516,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, @@ -1541,6 +1528,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, @@ -1567,6 +1555,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, @@ -1579,6 +1568,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, @@ -1591,6 +1581,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, -- 2.34.1