Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp276530iog; Mon, 13 Jun 2022 02:25:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxyoASYoZnUHvjiknhf4oZ9/CvE6IlggnYA0CfFJV4+XqFUMEErr+aeobgha3pDb70rDW15 X-Received: by 2002:a17:902:a618:b0:168:9ef0:fb82 with SMTP id u24-20020a170902a61800b001689ef0fb82mr24371873plq.144.1655112315898; Mon, 13 Jun 2022 02:25:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655112315; cv=none; d=google.com; s=arc-20160816; b=gv0aX5J2af+uE1G56rVwEZ6qJ+Gd3R0OM29eoUwpf/aPP3MwgrNfmiLAyBFDsTwEjM t5s+jyzNcacgenHB1zx4Fuq/5QDiKjKlgaiC2z4f+OGT1WuhYkeQJ5koXRirFeuBBVHs 74SCn/Gk//pxrXT3VkK8w+VFurySRtu2zat9Mgy2H7Nca8s1bZQAOQt9EnhsZlPGN0Pu 6hItluIfSQXQO1ho6xmuRkI9zfS/XbJ1QjeMN2C/9dFzoNajIhlJSSXUuyMWdX+Vn74O jqDmX2CLp1KTuuTS+T0kswuRBPslTPc5ZqvoikaynX73tRMlJ402uhiQatzyU6AeFRBi wLJA== 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=VnVknPwebHIHhgdxBHP9nVhdsBqyDjIJivOMQtgd78I=; b=fBVMHl8gDfxWhs33KNsy504dqjGhUCaePs3RW2t8DfZJS9L/Xu/Qix0qr4m7U+q4db gvbAoIkkTCOzY0Otjtlb594wm13HKtsLnnjWooIawxF5wAe/grEDN/8oLa5lnUfQkzz0 N87qbOP6SKKP2FVwOM0piumGmsWx/LUdKK091eBkt+tFBPZ7+QPEclLEvhdtbYaoms/n aVRbGp5qOX0pnTfAMMn1UDqP1e0W/YufYaNFqXrjYZOYPRPfv3WQuhONuALWb8aCPPPl ikBRJXbpmZHL+M5J2N8hHJ7D0FfRaaWxmscvMM+1S+C8niN3WcWnK8AZxdcTXHeYi4EI m0xQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a635308000000b003fd2121ace3si8725385pgb.237.2022.06.13.02.25.03; Mon, 13 Jun 2022 02:25:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S240535AbiFMJJk (ORCPT + 99 others); Mon, 13 Jun 2022 05:09:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240259AbiFMJJd (ORCPT ); Mon, 13 Jun 2022 05:09:33 -0400 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 237A210DA; Mon, 13 Jun 2022 02:09:32 -0700 (PDT) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id CA51C1A1D87; Mon, 13 Jun 2022 11:09:30 +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 814861A0B6F; Mon, 13 Jun 2022 11:09:30 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id AEDF6180219B; Mon, 13 Jun 2022 17:09:28 +0800 (+08) From: Richard Zhu To: l.stach@pengutronix.de, bhelgaas@google.com, robh+dt@kernel.org, broonie@kernel.org, lorenzo.pieralisi@arm.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 v10 5/7] PCI: imx6: Turn off regulator when the system is in suspend mode Date: Mon, 13 Jun 2022 16:55:36 +0800 Message-Id: <1655110538-10914-6-git-send-email-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1655110538-10914-1-git-send-email-hongxing.zhu@nxp.com> References: <1655110538-10914-1-git-send-email-hongxing.zhu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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(). Move the regulator_disable to the suspend function, turn off regulator when the system is in suspend mode. To keep the balance of the regulator usage counter, disable the regulator in 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 8002d98036e8..c02748393aac 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) @@ -580,7 +570,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", @@ -653,7 +643,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", @@ -1013,6 +1003,9 @@ static int imx6_pcie_suspend_noirq(struct device *dev) break; } + if (imx6_pcie->vpcie) + regulator_disable(imx6_pcie->vpcie); + return 0; } @@ -1259,6 +1252,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