Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp303050pxb; Fri, 15 Oct 2021 06:00:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmq8V89qu0yZLZ8KOAystGhyvqGa0Ss/1hquj1x3RBiCL63a1eioZWBaojJrULRdd297Pd X-Received: by 2002:a17:906:254b:: with SMTP id j11mr6469961ejb.513.1634302807346; Fri, 15 Oct 2021 06:00:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634302807; cv=none; d=google.com; s=arc-20160816; b=ysRYCcj2Hprk3GFhTq01Dvmx17PDJGbWzxA32LoH1R1kWu9vPUdgHUpC/PA4i1WPz1 2P2s9xOG0k7UxqjDy9UwnN7YpBK/EOPdNQY9+Rd5alo4BFjqmrSv4fvEOg35qGaWUd0l 5f9I+7/MVEBECE5uzvfZkzSNjaDGCw8WiaXiKUlguXCVsjirZCCCO14+b8NHP5J1LhM2 GNeJgt5Jb1tXagyE85fDw10390CqA9C9eTp4Wpq8+NhJ7rus8LiIPCwLxffL0amk+E9o qmVWd69sgnu2spp9GVRRwVyKvKVcwoiS90CuETtvZ6a4sVC1uJaDJx7ZGUN+FBlmotDQ eNVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=dRYUC21lb28x7YXC5v1JiSyI0I6dJQWtzCwIJwW8Yak=; b=NGt/P+VMMjO9+stGKhXZ/uLKMVdEZ7Xn+CjL2Ox4Q762Jrzv+zofU56Eyi4niNIQfh O1Dijk9nVzDJ0XrGimIM/V9j/PqO5SKH1C9I0CVY2WEst4b+sm/VSEGYy0fhoz9BxbaP jTKSoWWkQ65YucDTF1cLT2zIGVYc3I/jRxYJfmF8IczfZ5f1Voh8PkTPOen59e3CM1Fa RuEPLGJUsxnppx/plu3NYke4dG/B0O7IWrDogxQqYzeV1VJF/0o/CK/UHdaO30aDkFno mbWc1wQSGre9hVky+edeWSm3sZreBlyxVXa7aXAsVsifieV0kGax/cZBUT4QUsBp1cjq RwWg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si11917554edb.295.2021.10.15.05.59.18; Fri, 15 Oct 2021 06:00:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235546AbhJOGcw (ORCPT + 99 others); Fri, 15 Oct 2021 02:32:52 -0400 Received: from inva020.nxp.com ([92.121.34.13]:37216 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232562AbhJOGcr (ORCPT ); Fri, 15 Oct 2021 02:32:47 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 858D71A15D7; Fri, 15 Oct 2021 08:30:39 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 2360D1A04B9; Fri, 15 Oct 2021 08:30:39 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 8EA07183ACDC; Fri, 15 Oct 2021 14:30:37 +0800 (+08) From: Richard Zhu To: l.stach@pengutronix.de, bhelgaas@google.com, lorenzo.pieralisi@arm.com Cc: linux-pci@vger.kernel.org, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, Richard Zhu Subject: [RESEND v2 1/5] PCI: imx6: Encapsulate the clock enable into one standalone function Date: Fri, 15 Oct 2021 14:05:37 +0800 Message-Id: <1634277941-6672-2-git-send-email-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1634277941-6672-1-git-send-email-hongxing.zhu@nxp.com> References: <1634277941-6672-1-git-send-email-hongxing.zhu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org No function changes, just encapsulate the i.MX PCIe clocks enable operations into one standalone function Signed-off-by: Richard Zhu --- drivers/pci/controller/dwc/pci-imx6.c | 79 ++++++++++++++++----------- 1 file changed, 48 insertions(+), 31 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 26f49f797b0f..1fa1dba6da81 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -470,38 +470,16 @@ static int imx6_pcie_enable_ref_clk(struct imx6_pcie *imx6_pcie) return ret; } -static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie) -{ - u32 val; - struct device *dev = imx6_pcie->pci->dev; - - if (regmap_read_poll_timeout(imx6_pcie->iomuxc_gpr, - IOMUXC_GPR22, val, - val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED, - PHY_PLL_LOCK_WAIT_USLEEP_MAX, - PHY_PLL_LOCK_WAIT_TIMEOUT)) - dev_err(dev, "PCIe PLL lock timeout\n"); -} - -static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) +static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie) { struct dw_pcie *pci = imx6_pcie->pci; struct device *dev = pci->dev; int ret; - if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) { - ret = regulator_enable(imx6_pcie->vpcie); - if (ret) { - dev_err(dev, "failed to enable vpcie regulator: %d\n", - ret); - return; - } - } - ret = clk_prepare_enable(imx6_pcie->pcie_phy); if (ret) { dev_err(dev, "unable to enable pcie_phy clock\n"); - goto err_pcie_phy; + return ret; } ret = clk_prepare_enable(imx6_pcie->pcie_bus); @@ -524,6 +502,51 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) /* allow the clocks to stabilize */ usleep_range(200, 500); + return 0; + +err_ref_clk: + clk_disable_unprepare(imx6_pcie->pcie); +err_pcie: + clk_disable_unprepare(imx6_pcie->pcie_bus); +err_pcie_bus: + clk_disable_unprepare(imx6_pcie->pcie_phy); + + return ret; +} + +static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie) +{ + u32 val; + struct device *dev = imx6_pcie->pci->dev; + + if (regmap_read_poll_timeout(imx6_pcie->iomuxc_gpr, + IOMUXC_GPR22, val, + val & IMX7D_GPR22_PCIE_PHY_PLL_LOCKED, + PHY_PLL_LOCK_WAIT_USLEEP_MAX, + PHY_PLL_LOCK_WAIT_TIMEOUT)) + dev_err(dev, "PCIe PLL lock timeout\n"); +} + +static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) +{ + struct dw_pcie *pci = imx6_pcie->pci; + struct device *dev = pci->dev; + int ret; + + if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) { + ret = regulator_enable(imx6_pcie->vpcie); + if (ret) { + dev_err(dev, "failed to enable vpcie regulator: %d\n", + ret); + return; + } + } + + ret = imx6_pcie_clk_enable(imx6_pcie); + if (ret) { + dev_err(dev, "unable to enable pcie clocks\n"); + goto err_clks; + } /* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid(imx6_pcie->reset_gpio)) { @@ -578,13 +601,7 @@ static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) return; -err_ref_clk: - clk_disable_unprepare(imx6_pcie->pcie); -err_pcie: - clk_disable_unprepare(imx6_pcie->pcie_bus); -err_pcie_bus: - clk_disable_unprepare(imx6_pcie->pcie_phy); -err_pcie_phy: +err_clks: if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { ret = regulator_disable(imx6_pcie->vpcie); if (ret) -- 2.25.1