Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1176255iog; Tue, 14 Jun 2022 00:14:54 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v9LjPSxytYk6VMd4cPa1tB1s/Tnm1+HJxHTDGOsZkXDsXp1Qd3ufkIob+GCbrMp3I93B4c X-Received: by 2002:a17:90b:1a88:b0:1e8:a0e2:fa15 with SMTP id ng8-20020a17090b1a8800b001e8a0e2fa15mr3007734pjb.83.1655190894061; Tue, 14 Jun 2022 00:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655190894; cv=none; d=google.com; s=arc-20160816; b=GkTJkIaHY+7VvBL+1qu4ZSCMQBUNci8giy1n88lEAZTFtAzT8YzMVlk8sZvEZOZvr5 gOfPuuFLcXm/UXok9nyGeMKIVgct1bJcNh9F/EiB/NBjLTEI2lIm7qEQJzBkMzEEueUq hx/7Rlhq1uO7Qyhgkfs4FcvFzIvL+8K/tvBTZYbw/3Dn1LKUSpfPl22oI3wVEdxKbgOl gYWEnPNLzu+vSRU/H07cxoCNRR2iX/Pimpy7NQlgNVF0psi779Yy1kQNuxhYSWMzGjBH NTVkHGBiyW5Z5hWBjbnMdHG+nvNjrDX3cUPHcH8y5HZKworsf1uBzILVOb+CjDP0VB3r 3R3w== 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=+xUL+Wk99Gg1ipb1LDjTRcuuhHQfbM6zOyacfl26DDk=; b=yfK4p/l/yZes6nr/juyKEXGhdHuaFdej27IVtLTK4pqd2MuxAEsb/vOlrA9kwIVKfi aRSLmiBiE+MzDg81KEhu2iBzC7XRHSJ1Gu8ZQXNIP3QIxFj+CcFsHRZBhEidMbwdjOSd yW52G49MoozbSGFpwvLbQQE4h/aTGJwSZ9Lt7oBCJMTKcLjRWrSGSXWDGjfkLDbiciVb c8P7NI7Iwx4gD9OF2zp/HKVArGf187+UPf2B2mmESrpJcsl3GRwBChLBmKA92OpRP9C2 AfegjqXJKOiZlXsRmrhziYxdRaKH87GhMrXxSY2ulGFD1PkguyO6XR5VQ+09QE6yUPfP dscg== 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 s22-20020a056a0008d600b005228bc3d412si5290495pfu.150.2022.06.14.00.14.41; Tue, 14 Jun 2022 00:14:54 -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 S1353847AbiFNHN2 (ORCPT + 99 others); Tue, 14 Jun 2022 03:13:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353510AbiFNHNB (ORCPT ); Tue, 14 Jun 2022 03:13:01 -0400 Received: from inva020.nxp.com (inva020.nxp.com [92.121.34.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 957C414087; Tue, 14 Jun 2022 00:12:58 -0700 (PDT) Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id E02811A276D; Tue, 14 Jun 2022 09:12:56 +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 A8A711A2788; Tue, 14 Jun 2022 09:12:56 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id 1440C180222A; Tue, 14 Jun 2022 15:12:55 +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 v11 5/8] PCI: imx6: Turn off regulator when the system is in suspend mode Date: Tue, 14 Jun 2022 14:58:59 +0800 Message-Id: <1655189942-12678-6-git-send-email-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1655189942-12678-1-git-send-email-hongxing.zhu@nxp.com> References: <1655189942-12678-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 368e14e9cade..c05974abd954 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: @@ -401,14 +399,6 @@ static void imx6_pcie_assert_core_reset(struct imx6_pcie *imx6_pcie) 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); - } - /* Some boards don't have PCIe reset GPIO. */ if (gpio_is_valid(imx6_pcie->reset_gpio)) gpio_set_value_cansleep(imx6_pcie->reset_gpio, @@ -585,7 +575,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", @@ -658,7 +648,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", @@ -1018,6 +1008,9 @@ static int imx6_pcie_suspend_noirq(struct device *dev) break; } + if (imx6_pcie->vpcie) + regulator_disable(imx6_pcie->vpcie); + return 0; } @@ -1264,6 +1257,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