Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp302941pxb; Fri, 15 Oct 2021 06:00:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxdnf4iJ1W+j+0kJR52VtyAjW4gwVjyXoBUJrluFWJMU/gGObs8AcAA9YvDfhcQg7+Czajy X-Received: by 2002:a17:90b:4f87:: with SMTP id qe7mr17154405pjb.29.1634302801413; Fri, 15 Oct 2021 06:00:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634302801; cv=none; d=google.com; s=arc-20160816; b=NBqZ2ZstzsrL8CBLRv15c1EtIRGch7QyG4sVAyno6TFwiinY6/yf6ckaH7yOIx52w7 KUNPPZKZahpRb6/kFqZPpf3kpfrEE9zjR+QP4fCL9BAb0kjST76AXsPrBFMDMhovfoTo /DVAJuYobXrSu2yDRAS2QIGieKWSFPGR4NpGHeH9ORdzNUIl7upunvHPAYOueBWQM5Mn Fu82AqbT5bkCq0wMeY6WKi0DJkez425RWpyAbUI1SIMlrGEkaOKq6eoFAznhdSKdfMfg bwtVQkWrnvOlNIa2aXP/HBhi/29O6rD8ayDwbu7RPPiRmYmr/3Mf6+rtDuoirtRKh0Pm K4gQ== 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=jDky8lQXVBNvdDN5Cm5Ik6vthHk4IN25pQIlkHdFkPU=; b=EH04XrZJIdce6xoMj5Jb9ZXhtmt3AKGf5RbQD9pakRRSpcIUCGSvWwOR7B8wbBR6Cb 3MryXUls0f6LCp98ahS6j1H3GEpoH91ngRSVVpJ1qDyLQjC8YlQatsZLql0VPDF+hmOk do3lpCc3wfFLGL16TAoxTF/RGBqrcCv5RVrf0qNO15Z330k07IyA3wJvmcfeHOnn5YYh kA3tKjKr1oNwJ8cAo/s+nnyDN2tlI3aCvqCAFgzmJcHi+MRruuZ68ms0XlAELAXeCyTC 7mGiVw80Z+RVCNLR0jQLSBOvY6VeQgzkB06OOQ0/wsnsIc1ijVCgB7Rrra30xElShbAt 5Pew== 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 z19si7874634pgi.588.2021.10.15.05.59.33; Fri, 15 Oct 2021 06:00:01 -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 S235556AbhJOGc4 (ORCPT + 99 others); Fri, 15 Oct 2021 02:32:56 -0400 Received: from inva021.nxp.com ([92.121.34.21]:50180 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235511AbhJOGcs (ORCPT ); Fri, 15 Oct 2021 02:32:48 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id F3E512016E9; Fri, 15 Oct 2021 08:30:41 +0200 (CEST) Received: from aprdc01srsp001v.ap-rdc01.nxp.com (aprdc01srsp001v.ap-rdc01.nxp.com [165.114.16.16]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id C60CF2016DF; Fri, 15 Oct 2021 08:30:41 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 8C6B8183ACDC; Fri, 15 Oct 2021 14:30:40 +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 4/5] PCI: imx6: Fix the clock reference handling unbalance when link never came up Date: Fri, 15 Oct 2021 14:05:40 +0800 Message-Id: <1634277941-6672-5-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 When link never came up, driver probe would be failed with error -110. To keep usage counter balance of the clocks, disable the previous enabled clocks when link is down. Move definitions of the imx6_pcie_clk_disable() function to the proper place. Because it wouldn't be used in imx6_pcie_suspend_noirq() only. Signed-off-by: Richard Zhu --- drivers/pci/controller/dwc/pci-imx6.c | 47 ++++++++++++++------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index cc837f8bf6d4..d6a5d99ffa52 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -514,6 +514,29 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie) return ret; } +static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) +{ + clk_disable_unprepare(imx6_pcie->pcie); + clk_disable_unprepare(imx6_pcie->pcie_phy); + clk_disable_unprepare(imx6_pcie->pcie_bus); + + switch (imx6_pcie->drvdata->variant) { + case IMX6SX: + clk_disable_unprepare(imx6_pcie->pcie_inbound_axi); + break; + case IMX7D: + regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, + IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, + IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); + break; + case IMX8MQ: + clk_disable_unprepare(imx6_pcie->pcie_aux); + break; + default: + break; + } +} + static void imx7d_pcie_wait_for_phy_pll_lock(struct imx6_pcie *imx6_pcie) { u32 val; @@ -853,6 +876,7 @@ static int imx6_pcie_start_link(struct dw_pcie *pci) dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG0), dw_pcie_readl_dbi(pci, PCIE_PORT_DEBUG1)); imx6_pcie_reset_phy(imx6_pcie); + imx6_pcie_clk_disable(imx6_pcie); if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) regulator_disable(imx6_pcie->vpcie); return ret; @@ -941,29 +965,6 @@ static void imx6_pcie_pm_turnoff(struct imx6_pcie *imx6_pcie) usleep_range(1000, 10000); } -static void imx6_pcie_clk_disable(struct imx6_pcie *imx6_pcie) -{ - clk_disable_unprepare(imx6_pcie->pcie); - clk_disable_unprepare(imx6_pcie->pcie_phy); - clk_disable_unprepare(imx6_pcie->pcie_bus); - - switch (imx6_pcie->drvdata->variant) { - case IMX6SX: - clk_disable_unprepare(imx6_pcie->pcie_inbound_axi); - break; - case IMX7D: - regmap_update_bits(imx6_pcie->iomuxc_gpr, IOMUXC_GPR12, - IMX7D_GPR12_PCIE_PHY_REFCLK_SEL, - IMX7D_GPR12_PCIE_PHY_REFCLK_SEL); - break; - case IMX8MQ: - clk_disable_unprepare(imx6_pcie->pcie_aux); - break; - default: - break; - } -} - static int imx6_pcie_suspend_noirq(struct device *dev) { struct imx6_pcie *imx6_pcie = dev_get_drvdata(dev); -- 2.25.1