Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp610299pxb; Tue, 15 Feb 2022 23:42:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4sYzMcPIt6xcfpTVm8sIlcv4f1jrRra1bPLoD7swpXWWHSmFJV3GQ0dTsKLZk2o4HTykJ X-Received: by 2002:a17:902:a586:b0:14d:81fe:6ecb with SMTP id az6-20020a170902a58600b0014d81fe6ecbmr1326317plb.76.1644997361000; Tue, 15 Feb 2022 23:42:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644997360; cv=none; d=google.com; s=arc-20160816; b=SQX9suqESGW9V6dtZeBTopOuuaYmIMzg5x9oCwa0Px7XhaFZW/XVKrudMjKM2V1WDn Zw67xSCblF2iGwLuXIP9z6CFz5FNtOZ9WXuHsH3Gglr1aDO+h1rKEb4aa9tpyl6Z927X QmV2372YU36EO7kWtl46haoMmSQXvmHhoE1IMi2pLeI2DNWWOsn58ERkarTx7/QStbUH 6+HdUxRxgFUyVwcVngGXGW4Kaj+dbUJh1o+A0fMB92GVI2TaQ7MSlbS2isSoo9Ixwt6f REw6yCz+1Q5hhREdCSl5gj0gr7wdz5QvAiOWVdSi2I1ZCB0aOrL2YsfHZ7me/duXy6A7 qoAA== 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=wPct5mPeqRLNRQNbWNiquNvQB80/Xz5qYbM/E+289Ro=; b=z0GyliulD44UYYz2p/C1gGBUzosrAUpgUdyS1ENLfVIfsfNtRWygGsx/Z5dc1PccUL lLnvilbBE2LVcVWjsPtrcs5GtmyCCLJWPGZBipiqRx7syeMJu+3UgSG6P2Pp4A51puy1 JJiUKDOS7MOp5S6GtnXYEvYp6S9tJHAUa5XIy9rkKgG1JBlwnS34OhmRvnlj9R8WjlJg 4+fADqrz3b5QAKLMxUUJ+93tryiTd+7uTu5/8Eud23SY7FxmtQYhVXV0OFBnZ7gX2icS ael1ZAwOHCmZZuZf+VPw6DUYeIr+PSSTe+F+rG8fxsbQ7bC1ZC1wk3KTU7DdEf1apaLc dR7g== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a14si10977963plh.214.2022.02.15.23.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 23:42:40 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D0B224F04; Tue, 15 Feb 2022 23:07:49 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229495AbiBPHH2 (ORCPT + 99 others); Wed, 16 Feb 2022 02:07:28 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:34026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbiBPHHX (ORCPT ); Wed, 16 Feb 2022 02:07:23 -0500 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C964255795; Tue, 15 Feb 2022 23:06:35 -0800 (PST) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id CE5AB1A02E9; Wed, 16 Feb 2022 07:52:55 +0100 (CET) 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 958601A1A58; Wed, 16 Feb 2022 07:52:55 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 5510A183AD6D; Wed, 16 Feb 2022 14:52:54 +0800 (+08) From: Richard Zhu To: l.stach@pengutronix.de, bhelgaas@google.com, broonie@kernel.org, lorenzo.pieralisi@arm.com, jingoohan1@gmail.com, festevam@gmail.com, francesco.dolcini@toradex.com Cc: hongxing.zhu@nxp.com, linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com Subject: [PATCH v7 5/8] PCI: imx6: Refine the regulator usage Date: Wed, 16 Feb 2022 14:21:00 +0800 Message-Id: <1644992463-14467-6-git-send-email-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1644992463-14467-1-git-send-email-hongxing.zhu@nxp.com> References: <1644992463-14467-1-git-send-email-hongxing.zhu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The driver should undo any enables it did itself. The regulator disable shouldn't be basing decisions on regulator_is_enabled(). To keep the balance of the regulator usage counter, disable the regulator just behind of imx6_pcie_assert_core_reset() in resume and shutdown. Signed-off-by: Richard Zhu --- drivers/pci/controller/dwc/pci-imx6.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c index 0aca762d88a3..242d8ef73c1e 100644 --- a/drivers/pci/controller/dwc/pci-imx6.c +++ b/drivers/pci/controller/dwc/pci-imx6.c @@ -369,8 +369,6 @@ static int imx6_pcie_attach_pd(struct device *dev) static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) { - struct device *dev = imx6_pcie->pci->dev; - switch (imx6_pcie->drvdata->variant) { case IMX7D: case IMX8MQ: @@ -400,14 +398,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) IMX6Q_GPR1_PCIE_REF_CLK_EN, 0 << 16); break; } - - if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { - int ret = regulator_disable(imx6_pcie->vpcie); - - if (ret) - dev_err(dev, "failed to disable vpcie regulator: %d\n", - ret); - } } static unsigned int imx6_pcie_grp_offset(const struct imx6_pcie *imx6_pcie) @@ -583,7 +573,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) struct device *dev = pci->dev; int ret, err; - if (imx6_pcie->vpcie && !regulator_is_enabled(imx6_pcie->vpcie)) { + if (imx6_pcie->vpcie) { ret = regulator_enable(imx6_pcie->vpcie); if (ret) { dev_err(dev, "failed to enable vpcie regulator: %d\n", @@ -656,7 +646,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) return 0; err_clks: - if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) { + if (imx6_pcie->vpcie) { ret = regulator_disable(imx6_pcie->vpcie); if (ret) dev_err(dev, "failed to disable vpcie regulator: %d\n", @@ -1028,6 +1018,9 @@ static int imx6_pcie_resume_noirq(struct device *dev) return 0; imx6_pcie_assert_core_reset(imx6_pcie); + if (imx6_pcie->vpcie) + regulator_disable(imx6_pcie->vpcie); + imx6_pcie_init_phy(imx6_pcie); imx6_pcie_deassert_core_reset(imx6_pcie); dw_pcie_setup_rc(pp); @@ -1261,6 +1254,8 @@ static void imx6_pcie_shutdown(struct platform_device *pdev) /* bring down link, so bootloader gets clean state in case of reboot */ imx6_pcie_assert_core_reset(imx6_pcie); + if (imx6_pcie->vpcie) + regulator_disable(imx6_pcie->vpcie); } static const struct imx6_pcie_drvdata drvdata[] = { -- 2.25.1