Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp2346944pxm; Thu, 24 Feb 2022 23:27:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyqrXEPTvx1GlURV3yfyuwgl+9bVKfL4MR4D8zOy/nhsOHh/AiWLfx+2VNgv2JqMB4JE7Le X-Received: by 2002:a50:9ea8:0:b0:3e2:9df7:3a6c with SMTP id a37-20020a509ea8000000b003e29df73a6cmr5769069edf.384.1645774077129; Thu, 24 Feb 2022 23:27:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645774077; cv=none; d=google.com; s=arc-20160816; b=lHQyh0v15W8yiWbZ97F8EOwXv+qI1nw6v8MaKLtVgBaZYStku8dsbGpLPGLBDyquFj imqBV4HpqhjcYrFxRNLwg+q5SVjd/s5kekFGS6ga/NFZ7q1kfWAmsypHlFFQn4tKNcvy FKJR0duHAL2bFE3H9F1/EkiF0KoV+4jFaNMqxeQ6+Lzan9hwEXFGFNfpZosNEuPsv/+1 zV/1Dj67GsdJh2zNDs1hxXw/q7tN7b7yOH2XAkgzcqE0jmPJVWyKHy15mMalpwScXdu2 ehTlUf3RKYH/8WMH3PCqhKK7KMZNlJWzfXdgKOmiShIATcwadEctQM/4jxkLkheUYkVa NWyw== 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=bjQmNDe7/H12rLOXQ6TgGSgmEIQ3nYQICkEf+PBlZqs=; b=yqc8ecPT0g0bTxlaCnx83AD9N8c7fWscCeIV1+rsTH2ruAUcyBbudPQjdXbDgcxkhD 4uGA+84Wou5fr2AL7dLAWxquotV7c11ua/kwtxpGkhTIgkgZ16qB2kPNxbTjRNFZqj3g M0E+53aEs/X2JqtPz89l/fU47ZTm0wOzLBz/K4PhPwC2oLY59tsgPImajy91RO5Mhgdo /1zlPD3y3U+OF3WWGyHbxPwYdwPcRlh4Zu5bw8+m8soG9p0mMyAYYY0l6a3F85XvIMm8 PWPKpe8jGTlj9VfAs4cAK17ES9B+nGQYLWj2DTk9+UlhQ9eC4Eh0sRSmMml6+fYa7niY MOaw== 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 h12-20020a05640250cc00b00412f1130395si1962099edb.191.2022.02.24.23.27.34; Thu, 24 Feb 2022 23:27:57 -0800 (PST) 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 S237240AbiBYDxp (ORCPT + 99 others); Thu, 24 Feb 2022 22:53:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237205AbiBYDxc (ORCPT ); Thu, 24 Feb 2022 22:53:32 -0500 Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 214EE199E3B; Thu, 24 Feb 2022 19:53:01 -0800 (PST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id B71DF2013CC; Fri, 25 Feb 2022 04:52:59 +0100 (CET) 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 7FAA3201161; Fri, 25 Feb 2022 04:52:59 +0100 (CET) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by aprdc01srsp001v.ap-rdc01.nxp.com (Postfix) with ESMTP id DE991183AC97; Fri, 25 Feb 2022 11:52:57 +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 v8 5/8] PCI: imx6: Refine the regulator usage Date: Fri, 25 Feb 2022 11:44:24 +0800 Message-Id: <1645760667-10510-6-git-send-email-hongxing.zhu@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1645760667-10510-1-git-send-email-hongxing.zhu@nxp.com> References: <1645760667-10510-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(). 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 0f1b8c873a4a..160a0bd02098 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) @@ -584,7 +574,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", @@ -657,7 +647,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", @@ -1029,6 +1019,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); @@ -1262,6 +1255,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