From patchwork Mon Jul 29 20:18:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 13745681 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2082.outbound.protection.outlook.com [40.107.21.82]) (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 70B5918D4D4; Mon, 29 Jul 2024 20:19:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722284358; cv=fail; b=V3K5sy81BoTCZsp3cPUeeZUp7n+0UdXZrfWBPq8hq3EZawjf07DLyxnbdfpbroG/+ivPpg9iq+BivJQ2GuLsFAaz++3/mZbaeiu8aykBl4J+ErkDyPvzjXOHTPkA8Y/47Quxbp98NCeytvZCwrmNA3CN8EDb0ry29KtFWTK/CLQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722284358; c=relaxed/simple; bh=5Evp9ziK4xKXtiMCIUDV8Eu+6RTJQAatje71eLFFOgM=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=p8l6VCrezzvZi4ZgVO6sMGSa8G+yUlQcMqNRAQR43Sfr0XArbozmBbb9dCF82sC2vKVmrkWLOdU7RoRS/OpKqqL/6KxRZJDmXRiV5OlDRO+C4YXrX+omW7kfMw28kaEmGxDqpNB304iFitipc3tM4oi+te5vMUWXNfgU7cyZP4Q= 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 (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=d3M+Silf; arc=fail smtp.client-ip=40.107.21.82 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 (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="d3M+Silf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gU017VpOfcaIzgKfzUbHtNloKgimrFpeKPW1/GVhJTdXusOZ2pgy1YH4E5cM69ft4Pk/ur9xktRL2nWOLZe94qlN62dSA4BJ3xmhldKXcMiprdiE/f9ljPxV5tte9rXPjDqi/miRK8I4lqan0no9Gb4pHe/5YD/yWV+lsA9idllpSQPFmum8IJDUZb772z1e2V3P1PTVejJydspQFgZzx0F4p9ELMoFmRseaKNEg7MNUwkH+F9xG3sPXumSbz4tPKPgtjJLXYS/W3+8pvSL4jmqqnkeOMPmfhjagBMPBNth/4HSE4oVph5EryCQgrLuySoDLWCZUf2wHka/Hb3lEig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=IsJJOmwynhIuDvRKjtQeHGM+tPXYlKvgSIKyn7vsea4=; b=wyDXPQVv/JLTSrYlc7r3ltDtFtEO8XYWXFCOqQgbFM+Lb4Rt5WcRdXe/Emil9s8RDPwbrNkZESJDcXOyUo46/v4HogQFOmRYRWxMuYNc5n/9zsNVuzyi0rnGDGJga6pVWvjWEXCzUv8Y48YRYtI8gaWecH5SYJxGDgdxJzoRDHG9ovBi0BD34Ddj1/m7hHU6ds0R6Ln56puDurh8s77mKZ07i6wE6E9Frq6e0/snpSx90YBuwR0sx2prCYEuQgm3+SNtLxWkEMYyOR8TYtTpTgczlkumXk808ZwiX7dmTkN6TnZFstLKXV26cQTw6MAFbJsKobzl7UBuiP1CDc3SYA== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IsJJOmwynhIuDvRKjtQeHGM+tPXYlKvgSIKyn7vsea4=; b=d3M+SilfZunZYr+q/ak/IRy+Tq3LevbKm1VxYyu1onOIY7NbOlGoaayLS64ZT/kVL3f+wfF4R+1uNBii6c9Y1LDqKHKAwTZy+KQtXYexAJGNCLBDyUpF7DEl9G3XMLprP9angrr0f53ulv7BGxmjPOL41ymXx2cBSnMUMyDJ94AaB9G4wuaFfQVq0LkWNpZMFyomQuPoztluRZOe+DLU56ZIV/uzYhi9cZOEQCT27wdifu4C4WnYLolfC1ydzwOrkv6wVEyocY1ntO/N7ANDcf5zeAhSBru1WxjdD1iOD2hZdl5Q3Km1UGpybSPghYW0eIsng5PAUSzhBfjTgOMgtg== 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 DBAPR04MB7382.eurprd04.prod.outlook.com (2603:10a6:10:1ab::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7807.27; Mon, 29 Jul 2024 20:19:12 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9126:a61e:341d:4b06%5]) with mapi id 15.20.7807.026; Mon, 29 Jul 2024 20:19:12 +0000 From: Frank Li Date: Mon, 29 Jul 2024 16:18:12 -0400 Subject: [PATCH v8 05/11] PCI: imx6: Introduce SoC specific callbacks for controlling REFCLK Message-Id: <20240729-pci2_upstream-v8-5-b68ee5ef2b4d@nxp.com> References: <20240729-pci2_upstream-v8-0-b68ee5ef2b4d@nxp.com> In-Reply-To: <20240729-pci2_upstream-v8-0-b68ee5ef2b4d@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=1722284317; l=8140; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=5Evp9ziK4xKXtiMCIUDV8Eu+6RTJQAatje71eLFFOgM=; b=oMuCrSj1c6X64c6fycFt1hs9EWif3NHWbQGySfIbz8otS19MrLFWamFei1nWPmeHjz+0F/CMA D8kJTLl8n+FD3slBN6r+NR/jhs9yzhgWg+m3fYJDKcyjKIbaCVyYYhC X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: SJ0PR03CA0069.namprd03.prod.outlook.com (2603:10b6:a03:331::14) To PAXPR04MB9642.eurprd04.prod.outlook.com (2603:10a6:102:240::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9642:EE_|DBAPR04MB7382:EE_ X-MS-Office365-Filtering-Correlation-Id: fa3f4afd-7fb4-4451-b7fc-08dcb00bb5d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|52116014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: =?utf-8?q?vAeM/WWITL80QIs+7S+ogdUST+9ZrIq?= =?utf-8?q?ySk6dC+WClSyj/JMqOSr7Sxt8WfYfHHMkdow1JBEY3L9jA1InMieQyeswrWS17xY4?= =?utf-8?q?Li3J5o5daSSHEE7nRyzESeLm+lrGh60RxMTRqll91LD+uvdAhDshGH2uAZLgXJ7z4?= =?utf-8?q?y4UaCkgInBcblvnWwLYmWbZQkopBF2pENRsM74YTHSdwctc/DG3g0QljQ41o3y07d?= =?utf-8?q?frXibUZtWYEGkL/lRpXBFhwQSzLzW58XGij+XfM8vU7LezM2aZ+Ofz2ZhFmY4LZ3t?= =?utf-8?q?QiK7QErf2d6cGyYRRUo8QcuqkRCeCiUtlSlMhC5pldW2EajHNUUFzQIZqH7iPUy9v?= =?utf-8?q?TMPX6Oa/WpziAl38kzMNJErUZj1HrGi0nbgKwrZy5raa+dULCIXux4RajiVBFuaBX?= =?utf-8?q?gxZ4NSMkMWXxoy2KPa9MwHryYyULxRcZCV6dgPI9urubGvzRbJO6GKMIx/Hbw1HRo?= =?utf-8?q?sHDiJSkQvsLkY+y2VuzAki63/1wMp3ZGbIBY4rASad9kfmI6uxpsCKy3knIm+B3j3?= =?utf-8?q?ucPqEs+nFrNgDUQja1lmkvzAssF5GQggPX6idxRFlMM1WsWGpY1uM56i0R1JhqU3W?= =?utf-8?q?THzDxC/cGqueb3t209zvmkBUizFWmCh4HAx3v4SnPdO2MIgnObpe38p9i6/NpyX/z?= =?utf-8?q?PAaQ5OtPMwR6zfDdBRu8S8KLlSzV/d+KYjqEwFdoellya+L/hRfDyu7xpeDMbDCze?= =?utf-8?q?1QVjA34Fa59VnYwdPCucXruENRN6311HRktqF32r6tCGXuJV/2ISOqp1rJMZaOltb?= =?utf-8?q?4ntytcaqrJwriIA9UXzRPVDl0TmiXIigFZT2/AoanhtEYQ9fx3wzXSP1ErwzfKspk?= =?utf-8?q?0/2/fJ+xclFBgpq3MK4/h0aN8hbBv1ndVf5+bejjRIwJAwp7H2XFAOeKs6ve+Ed+m?= =?utf-8?q?bFMLaK95sXebx48PQny/vzFXpYm97teDbDlAx+NeDQqZH73kynhTO2fmDYWQIHJ6b?= =?utf-8?q?QmpMStMPZkNqNQLUal2F3bW9SrJzZVKNwp3HsgEhC2ZccGpNrV/2zepFdGfcMzeuw?= =?utf-8?q?ohO2TJBMPTu/VxKyRVfmdhMUnnq3rv1TKxEucLUXK/snp4LqZ4wdJQ3rS9rSVaJMN?= =?utf-8?q?HGS/uvb6KuzWV3zlMS90Ly51I4rz5KCG60X2eGrO0HdEfLfohH9Ic94eVH1qZtv+u?= =?utf-8?q?qhb/5mDY9BQwI4JALPr8JRSJpQF4DDRF1yjkXM89HuEII8Ujug/IQS/5TE0OYquHS?= =?utf-8?q?aYKuIBox0fYrci9I6qm3ICnpKAxDRRrY4pEgbCFTDoZykPCwig43KYRpnCHGxXwJD?= =?utf-8?q?CHoVMtRIVaWtANn9tRL9a17R7Trj8LWxkdXV24K2hLgZFHACLsnB2AYM9VTDRrknw?= =?utf-8?q?M4EbN1OecJ7GyXHhEgsYF+RA/oLvB9H85PSxtlgMGwqVZPADXwaJKxk=3D?= 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:(13230040)(376014)(7416014)(366016)(52116014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?fT4z5UjHLt63ZQiZTPcw36GzFdLe?= =?utf-8?q?P3hQenbh2gf0jwKtmh3Rpshzvcgf/rjsQh3L0lKnBarIJkbzf0CPgqOVGlfW+Yv55?= =?utf-8?q?+EIcksSAEkthMx7l7Z9dmy9UJZZWxAOVnMBpTy2lHGjOroGBeYTvMqk9tzM9X+atT?= =?utf-8?q?4xX7MBUhMHI2U6IMy1MFHzKChGGLJAKUuJ5sIxyECbs5iRe3fWc/7RC8M+BUViIPr?= =?utf-8?q?0Jl8TL5sIlH/x4LqQklUSPmEA4Jv28XNbIcvNFr0DPLv0Vapxi0vzgOfgB1icWp9X?= =?utf-8?q?Lp+gh5R7Wai+4dWG8s4Hf1eVuAUEDn3ntX4YHfCToxlezCEAhNUKV3cQdls9+ySyD?= =?utf-8?q?MFbn55XbLCz2WMhK278iT6JGsOO1Wa/T31/xmdbD+kyT1PObweL51I+f1E4jrW9J3?= =?utf-8?q?/pzHs6OtFkV5HMLlywGNKLWeurDyCPiuS/VGWJFhRDnzj4fPgjOhuC944OVYD8Fmc?= =?utf-8?q?suI6u6axKDsHvSNcE1ZCqUYlbQ/PEzShWpwQRFcCEn7JeyIje4cYij2RK4mJQ3Zkm?= =?utf-8?q?oznqXAbohYnJjDRG+aM68/3touwcMlEtgmwS64yUtosw5+1YMgXJj2t0JpAORz9Rq?= =?utf-8?q?03YzNSWY3+9190ViEAtbG8oKHGPEXKaSXdcdQJt9NTn1Z0fEtSVb8QANsVzSU+9yg?= =?utf-8?q?JpxShAQ+FqFdU6KEK4oc9CmpNYY2BiZ/SkdyX45gEAU/taXtt9mGukQCdQMoJW/sA?= =?utf-8?q?7PVSET2SpKhfPggrIbs6wpNK82wK+OONTqq+SPtv+j08SCQ3AKwcUWLXOsKFKu2hV?= =?utf-8?q?VJU3l4o1TD/VwrRbTprpIuaSMR0BVIKksT4wTaR3YNx/RHr1bCbSK/or3L3bxi9KJ?= =?utf-8?q?y8MBwrtY3juik8Mxn59gGKogXlsTeRZRv52J78v0y3Zu72uSlRbly0REWSiSq3PiD?= =?utf-8?q?yMXGIqpNFrqGtQWm9muo4Qz98TnBD17mNBW9RZbwqkjuNmrTWc9nyAolRySAl3CC7?= =?utf-8?q?cFGD5qsluBnjNqWQNiNrvfbxlHwS92I6DTdypkU6lp6Np2v0pffF+5fhuCidlD1dh?= =?utf-8?q?8nBRZEDYdSX4JnZGxgZEF83/44RNrBUBGIBDYoeoAlOWaMUSLIbIrB9DK8lxzZyNB?= =?utf-8?q?HZnVrElarKzurGneN//330ax+QQrck4uijrXQQimDMAkaO5x1IBsXm+CnjPsv7hcF?= =?utf-8?q?szGa2CLW+6UCrMp7VTardIlENpb+JkYbvpCgDr1oq93UgFV0wjt5nfAho9ARh7Wpn?= =?utf-8?q?MB4j/fVDwifqtRMxirbxVKvcoONAiB5sDXsOdxGnH/Bdsv73nT11vTSKmBAOhJ4Gz?= =?utf-8?q?00a8253pRUQ0Ka1pkFu0WXMMODdpEXYErvZKdxXQumofGojjobX3oKUYdOM/ialGL?= =?utf-8?q?AD1YIhIXuwb+RAejdj9Sk35k/DOjBbNPPM0B1ucCxarZX2GuId2vRTi59b6ISuZCH?= =?utf-8?q?KkRK94ABVwlIA61s6XSaGOTUwBvFiZqfsgeqKs51lYYO8d/kzg2msNqM6fJe8fYww?= =?utf-8?q?jENZNo6ele5zqSHy/9SiP9nIQ+rmQlamrW6AiiXamPTIQpw8Yov/FawvUvXdRe1v2?= =?utf-8?q?13ZZbW3yLn2t?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fa3f4afd-7fb4-4451-b7fc-08dcb00bb5d1 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2024 20:19:12.2021 (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: heAMAOzR/MBjS08ZSPg6Q8QoUS1+HQoXFVwqqViTESu1DSf8SQr/lwAtbzHWLtcEz3W9ieo6kF7beoy247CN9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7382 Instead of using the switch case statement to enable/disable the reference clock handled by this driver itself, let's introduce a new callback enable_ref_clk() and define it for platforms that require it. This simplifies the code. Signed-off-by: Frank Li Reviewed-by: Manivannan Sadhasivam --- drivers/pci/controller/dwc/pci-imx6.c | 111 ++++++++++++++++------------------ 1 file changed, 51 insertions(+), 60 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 443c7c75f2842..b68a817ccc86b 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -102,6 +102,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 (*enable_ref_clk)(struct imx_pcie *pcie, bool enable); }; struct imx_pcie { @@ -583,21 +584,20 @@ 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_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) { - unsigned int offset; - int ret = 0; + if (enable) + regmap_clear_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, + 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_enable_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_clear_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_TEST_PD); /* * the async reset input need ref clock to sync internally, * when the ref clock comes after reset, internal synced @@ -605,55 +605,33 @@ static int imx_pcie_enable_ref_clk(struct imx_pcie *imx_pcie) * 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; + regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_REF_CLK_EN); + } else { + regmap_clear_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, IMX6Q_GPR1_PCIE_REF_CLK_EN); + regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR1, 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_enable_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); + + if (enable) { + regmap_clear_bits(imx_pcie->iomuxc_gpr, offset, IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE); + regmap_set_bits(imx_pcie->iomuxc_gpr, offset, IMX8MQ_GPR_PCIE_CLK_REQ_OVERRIDE_EN); } + + return 0; +} + +static int imx7d_pcie_enable_ref_clk(struct imx_pcie *imx_pcie, bool enable) +{ + if (!enable) + regmap_set_bits(imx_pcie->iomuxc_gpr, IOMUXC_GPR12, + IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); + return 0; } static int imx_pcie_clk_enable(struct imx_pcie *imx_pcie) @@ -666,10 +644,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->enable_ref_clk) { + ret = imx_pcie->drvdata->enable_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 */ @@ -684,7 +664,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->enable_ref_clk) + imx_pcie->drvdata->enable_ref_clk(imx_pcie, false); clk_bulk_disable_unprepare(imx_pcie->drvdata->clks_cnt, imx_pcie->clks); } @@ -1460,6 +1441,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, + .enable_ref_clk = imx6q_pcie_enable_ref_clk, }, [IMX6SX] = { .variant = IMX6SX, @@ -1474,6 +1456,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, + .enable_ref_clk = imx6sx_pcie_enable_ref_clk, }, [IMX6QP] = { .variant = IMX6QP, @@ -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 = imx_pcie_init_phy, + .enable_ref_clk = imx6q_pcie_enable_ref_clk, }, [IMX7D] = { .variant = IMX7D, @@ -1501,6 +1485,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, + .enable_ref_clk = imx7d_pcie_enable_ref_clk, }, [IMX8MQ] = { .variant = IMX8MQ, @@ -1514,6 +1499,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, + .enable_ref_clk = imx8mm_pcie_enable_ref_clk, }, [IMX8MM] = { .variant = IMX8MM, @@ -1525,6 +1511,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, + .enable_ref_clk = imx8mm_pcie_enable_ref_clk, }, [IMX8MP] = { .variant = IMX8MP, @@ -1536,6 +1523,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, + .enable_ref_clk = imx8mm_pcie_enable_ref_clk, }, [IMX95] = { .variant = IMX95, @@ -1562,6 +1550,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, + .enable_ref_clk = imx8mm_pcie_enable_ref_clk, }, [IMX8MM_EP] = { .variant = IMX8MM_EP, @@ -1574,6 +1563,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, + .enable_ref_clk = imx8mm_pcie_enable_ref_clk, }, [IMX8MP_EP] = { .variant = IMX8MP_EP, @@ -1586,6 +1576,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, + .enable_ref_clk = imx8mm_pcie_enable_ref_clk, }, [IMX95_EP] = { .variant = IMX95_EP,