From patchwork Tue Feb 27 21:47:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Li X-Patchwork-Id: 207455 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2983654dyb; Tue, 27 Feb 2024 13:49:21 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXMTUUpAsK130Pl/fqUvT0j4tUlbeu7MW74fx4K6iGTidVaKh2jZlu317I5sy64Ewo4elTQLbOE9wWoz2Uaaa+fQ1+qZA== X-Google-Smtp-Source: AGHT+IHolC6WBcos1rj1aehwWWnEYg5vxqpLaxNRRyZ1x5qBQkChTPhLtAMcxPd3pX9tUnlfVz7f X-Received: by 2002:a17:90a:e2c7:b0:299:35ea:cfb5 with SMTP id fr7-20020a17090ae2c700b0029935eacfb5mr8779562pjb.2.1709070561031; Tue, 27 Feb 2024 13:49:21 -0800 (PST) Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id l11-20020a17090a49cb00b0029724b7788fsi40473pjm.9.2024.02.27.13.49.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 13:49:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-84067-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=S92c4uMF; arc=fail (signature failed); spf=pass (google.com: domain of linux-kernel+bounces-84067-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-84067-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BDE0D28840B for ; Tue, 27 Feb 2024 21:49:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DF9B0157E74; Tue, 27 Feb 2024 21:48:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="S92c4uMF" Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2057.outbound.protection.outlook.com [40.107.21.57]) (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 D65CF1552F7; Tue, 27 Feb 2024 21:47:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.21.57 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709070477; cv=fail; b=sesdjGLuAfNbFEPsbLR/xKc8tqoAUsBakkR6uUd0/FWgD/Hf5Gv+xBHCc3X5bMCXzQC3vpfivzABoxRLfqBvhHm0gEXdoUyeaiK/pcGwg9zPeted6Y/+VXNcVHCsow2u0mrvZSD8LINarMxu1TB5nIvLEBHlBkyyc6r6yNZm01g= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709070477; c=relaxed/simple; bh=cn/ufN623D22XcRlM3N35TFCdHgjo7eM67GEijjta8s=; h=From:Date:Subject:Content-Type:Message-Id:References:In-Reply-To: To:Cc:MIME-Version; b=s8b2i7jEr4kBHmwBldeaUOrzK/SENr/y0olD2Zj5DfIFKu3F1fnC6SSf1bdeZCXlmqMxHIppy8mXTDaBYQFjAsqKRt5MZPf5BWLK4U5ccXR0UmLJllREM8Hr6nGfn7/4ctRCAH+retu5q6g/WHxU8qkqF3gixYitm1W5Ox31PuQ= 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=S92c4uMF; arc=fail smtp.client-ip=40.107.21.57 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=i9NKSOSc6iusRKS/Abs24Iem1nJ8XCgtCIbFkcSoqGazhQp2LKVu0qET9qdvb9VHDuDwx18WsIX+97VCxUYhg0LP6MsduqlEmJq/A8S7srIZGMk88hYcpodMXmqA9MGOb+JfbfI/nfXfGLKQNH3FVKs9lLg1iFjdZBDal2A9m6jh/q1nwSNqIGg2bsHLF6KK6srgY5sGSAbTFfwo1H1+M4N0nJIqZjuIaB8e7Ss6Ck/+haI+AVH/duiSsgqJQMLJiQMICKkopmB5Hbkmv+wcQRAukBiur0XL1Sy8Q7jawcgXhRH9VoUuE+zzxD94AWFv8VOQ017SI9a6+mjiRgzjLQ== 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=O9NwUPHoYMcETkXgNCojiyj5+UdKPIeBtSfBhZUFfuo=; b=Qk8lAj/UjvMu+y8YmVuuYRKaHF2Nj47uX04O2qCEbpvbU/EQh9NpV/OIYj1QLujPiFpq4W8A5x7vjvLy0lqL6D6p55JOxLd/2yVDxuyr4eMLetQVBbURBXQeURNBYc/9bjTHNRX5N2FuiMAy6fE9PAMn5nvMWWIQO2fRXyVdROBLMxhW2tPbiIW6HQqNr00oQXNO9SofH5oe5uP0S9wuHzHHEsa41GiEEKAJE0OP82IsC6WjNZ7c+QOyim7IUXrYDV3ICcFs/FqsXwlBwK4kld+wfmLuZNfaRGat8PkG1cAA+pKQs621xNkVOPNMZ4f0cPoUmcPQ9D4+yNKFYuN1NQ== 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=O9NwUPHoYMcETkXgNCojiyj5+UdKPIeBtSfBhZUFfuo=; b=S92c4uMFynNSR2cf6L7ZDbtWKtLXVlH4GSDMu6L5Q0jrCVyoGEQU+MunKwLZLC5WtuRT85dYAjzlEwlGOCWuZ/FAn+AB3iznGE7D1MP914QxzmmxlwFjycF2qr7XKMLfplSZzXBcDCVjZLFLRMaTcusIUpEGkgG0IEct1KJ35VY= 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 VI1PR04MB7056.eurprd04.prod.outlook.com (2603:10a6:800:12c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Tue, 27 Feb 2024 21:47:51 +0000 Received: from PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9af4:87e:d74:94aa]) by PAXPR04MB9642.eurprd04.prod.outlook.com ([fe80::9af4:87e:d74:94aa%7]) with mapi id 15.20.7316.035; Tue, 27 Feb 2024 21:47:51 +0000 From: Frank Li Date: Tue, 27 Feb 2024 16:47:11 -0500 Subject: [PATCH 4/6] PCI: imx: Simplify switch-case logic by involve set_ref_clk callback Message-Id: <20240227-pci2_upstream-v1-4-b952f8333606@nxp.com> References: <20240227-pci2_upstream-v1-0-b952f8333606@nxp.com> In-Reply-To: <20240227-pci2_upstream-v1-0-b952f8333606@nxp.com> To: Richard Zhu , Lucas Stach , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84?= =?utf-8?q?ski?= , Rob Herring , Bjorn Helgaas , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Philipp Zabel , Liam Girdwood , Mark Brown 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, Frank Li X-Mailer: b4 0.13-dev-c87ef X-Developer-Signature: v=1; a=ed25519-sha256; t=1709070448; l=8514; i=Frank.Li@nxp.com; s=20240130; h=from:subject:message-id; bh=cn/ufN623D22XcRlM3N35TFCdHgjo7eM67GEijjta8s=; b=UXlwlz3Xv717sRD52OM1TRqCgJjSfwkHQbd3CGFzlt2RMMQX9xBAZ4Hk8nOGcdhWKGcgcVLDR FYT7VAPiz0+B3nCLSgfIAow7vmQlGcCHPzSC7wSe0pR0x7cHeEC6oFn X-Developer-Key: i=Frank.Li@nxp.com; a=ed25519; pk=I0L1sDUfPxpAkRvPKy7MdauTuSENRq+DnA+G4qcS94Q= X-ClientProxiedBy: BYAPR11CA0050.namprd11.prod.outlook.com (2603:10b6:a03:80::27) 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_|VI1PR04MB7056:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c6e0f52-be8a-4979-e4e7-08dc37ddbf4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ju585KNPUwSscCkSy5A8M5PeSQ4HNhL+rBWcX5Y51Uhjzu7iZ9cz4yL1VcwAvS8hIkiPWkwkz6LxxoAdOjoWhwPLbgdHSwTh8IRUrcDl8IYDF5mnTcrAyo2DxPTHQhqrgeURyXIVGuwYnz8fpUe3GOxFd5qd7jPA37tTbILAYRF6QqlLBToobr9EXS4AJe1qbWgJbQy/IT1RcynjLucYT2CNIWN8Jc4tKF0dInKxmzsTN3SpgUEDVvstsGjBi669TX4GjV1cz3e0rV2X7gVnzIkZBfwPiFyTLCzJU6hTB+khuNVzfxR/w1aOxpcMSGy0s0s2uWS/C3IG9eB/s/GupTJq0n4VALbPqyKR3zjEAuv9L5j3NCYNjuTedy4B1fYENaYufIdBUfcqu7B/HDidhlRjNDt0bL9k4TOElUe9Mo7VWK3Fb37UyC/BY0DB/DDpgWjecGK9VCH1PgtI3BST1T68/BK0bx6LJQ2cND2qk/wHWmP4Ehxk8H5bEObBDxJwAkmFLIF7frKybOAa/0w2Ul7MGqKcAtSxI0qhuYoQ8B4P7VK6AuvJ/caglfKwoJ57pLgJkf1vqxlq4fK9ormMeqap55WU+EFAHBqHzdzK+YEDpePaPhkjYUqOaDJuwmeSQwRnWhwU01NWCVzZEP8X7Dlgkuz784aq6hJXuu7b3psrBDGWAPCIigo8fdlqM1ZHMllV3kZIS1nuHlbNjYn796x62vVAAgMDWySt4568VcI= 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)(921011)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?7ugf6/TXxOz1g+69D0x9Ft7HN2R6?= =?utf-8?q?Dr/ala8P46IzZ630vPA+bDkCQqTj8U6uD+Irazg0u4ozgze6s95BSng1iHUowQEp3?= =?utf-8?q?fnOBFuJoP6tHIxjTwxvvdp5f0fAahmKN2WrkcgQhQpaaEpAy7FZTInwTbQD8ENXu8?= =?utf-8?q?NZm4qwa6aVNHgb/HZQp0lpgQsVMnJUpm6UncFgN/BMOQr6LQIhtbGie1xn2isaCPc?= =?utf-8?q?aH/OjPCpZBhkRJR1YjSkD0YdH/K/AEuObeV/OG0iNBC/Z+e2KDddf+dWmnYndsWzk?= =?utf-8?q?nyLAGQwrlOZqBTET00Wxm08vXbBQtsACU2Jq3c3bCRB+423h38KW1XV14+zKQ51sm?= =?utf-8?q?XevVe60XBztQ7RdqYg+uJKrH6AFsuEKoDeEqETP+1bFkuWxeEPaiRmQuR4YT3i+Tz?= =?utf-8?q?SBJVgGqh6fMf8Ot8Nyjc+8WRETMlO6qIAFWeru2QkDGOOGjmwFc9z7/oMD/2WImXc?= =?utf-8?q?YTi3eaUflrphhicP0p/ZnSyLREwVmX82zsQSbEmKqcyhXYRtlhK2yWR2zoc8W9Fwo?= =?utf-8?q?7PfoUI4tE4Hzr4nMRQQcmhCGRHMrRQAypCKXJNWK37C8LAzPIwgRVEx4t3X1kw736?= =?utf-8?q?VLAt75TtGPu+gEr9OYF2jV9WHrMUwLxYMXgiYMpYXXT0pV4h/iCXP11viWW69L2Xp?= =?utf-8?q?+ecoACrHeQzq5pREIIca8OfJP8qZWTs/m+ZKiAULabmSqBqKMEsMOLrousJpwXs9d?= =?utf-8?q?tfGbceT6UfM92Do38x1+H7Oahv2I188TG5eNzAemIDSXehLVo4BMTfr0kJWQr84g5?= =?utf-8?q?eimuW+cJb6aC/KGaLR4Odf09lhntwNdJPuaiKymdrrHv6W8vzjplxmPPwCWBBL+H+?= =?utf-8?q?U45d75v4xn4zk6Psdur+8VTTqWRyL2eTGw1r62B8veMAnY7ky6ffSNpdegXbmHFtp?= =?utf-8?q?zA5Rze/LAY5odNJe1mkhn3+Zp2Z3SD13Ceu8ryBoE/VV0gyMuHQEh3sFy19yau6Hx?= =?utf-8?q?nzH/FgaicDyFjI2CS5yp5KaZsGmsRGo9wtGP7jIomm4fWk1d+B93FDxX1MKMg6Tnw?= =?utf-8?q?SM8kdBGxAEwnFJf+weOusfWwRb7cvMA4GC5WaWnJX8lwvgTcCDDICNKf2vFS2prHb?= =?utf-8?q?OO+bmHPYbjNXw2EtH/ky3dkUFNIwiy/9EOdrvXcZeB3Z3pCC71gL0bsoQp5flLaEH?= =?utf-8?q?fiIH1ogS1ixVJsC53ApRNlcZ3QhVltlZaobYmmxTLXErPW+nyKURgNTfYz5BEupD5?= =?utf-8?q?vpcveU39C2ohxZh9ifiQWGmbBR5+mxcKsS+KyJ5qeyExCFcEZ6C7GmxB4XpxE/sWd?= =?utf-8?q?w+iOjcdKUCMpVcsL9gSqEANoFuqzWeUpxIhmxFXbDhwam8yddkUww5Fw4NVYHE6a9?= =?utf-8?q?Fo6Q1TVvcPApR2kLtsJeCVNn4JI9L0vblLNCtmQ7nJp5Xpj2uvdfp5Crfc0W9QynP?= =?utf-8?q?Bz1nN11aVIMKVC6kyM8HIh1O21ejps3A0B/797TnZ1Qy3IQtQ7NSxZ8r+UPfL0GYF?= =?utf-8?q?n46w8IcO4M0nZTfx3o40Gp7JfFNr7xP8zPvVo66dPCfvfy8qpIDxaXoGXMxwECpPf?= =?utf-8?q?aC6YiXlqUvfW?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c6e0f52-be8a-4979-e4e7-08dc37ddbf4d X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9642.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2024 21:47:51.8577 (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: yF5Z3jUtvkv/pyu5AlzpUOzfLP6AjMvO+lIv6sRZCxTPsK7I5pZyBHjYU6FClVa0TgI951kzxJ1U/td2tDhjvw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7056 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792090372435930075 X-GMAIL-MSGID: 1792090372435930075 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-imx.c | 119 ++++++++++++++++------------------- 1 file changed, 55 insertions(+), 64 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx.c b/drivers/pci/controller/dwc/pci-imx.c index e646ad70a2a5e..a63ce171ede8f 100644 --- a/drivers/pci/controller/dwc/pci-imx.c +++ b/drivers/pci/controller/dwc/pci-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); } @@ -1462,6 +1443,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, @@ -1476,6 +1458,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, @@ -1491,6 +1474,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, @@ -1503,6 +1487,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, @@ -1516,6 +1501,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, @@ -1527,6 +1513,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, @@ -1538,6 +1525,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, @@ -1564,6 +1552,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, @@ -1575,6 +1564,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, @@ -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, + .set_ref_clk = imx8mm_pcie_set_ref_clk, }, [IMX95_EP] = { .variant = IMX95_EP,