From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ED87FC433EF for ; Wed, 8 Jun 2022 07:45:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:Cc:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RidFTd0p3kj+pyvRT64U6A5x18sd7y2JE3l2L5XF8yA=; b=ow3AAWf+gX6W1v Rv4Whb0FVRScAgzONEmgn3dBoCC0mQ3FiZoegLWe6MSKMwyJ2RDiF1nXbKmFBlFlJJ0gGG1pE/qxJ tD4E332MsMr/PMVCrFZzZTw2N9x31f7E/m/SkezPHmXhZQSIzKXHM2F8OJb1Iz0Wfxe37xlYNKYq/ dg8vJ4iXUyMyr6QI04uQX2DpXQVP1WcMsk+PHhmdI8LWtz8sJwx1L0h3gymR9WygGeJIs6n2aMgRG FFDBO3LuYHAgsHXSIz5pPPGXZejqsLiYzqZ+kpmzmigaapmiuRXQ5LB9CZfKSzICxvmhWDdkIlxb7 l+tMVmfZLAJIwRGvQXvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyqN2-00BisO-Rt; Wed, 08 Jun 2022 07:44:53 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nyqMz-00Biqm-2J for linux-arm-kernel@lists.infradead.org; Wed, 08 Jun 2022 07:44:50 +0000 Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyqMr-0002o3-H8; Wed, 08 Jun 2022 09:44:41 +0200 Message-ID: <323f9352fcf22c040417b16e57647695a48c1395.camel@pengutronix.de> Subject: Re: [PATCH v9 7/8] PCI: imx6: Move the phy driver callbacks to the proper places From: Lucas Stach To: Richard Zhu , bhelgaas@google.com, robh+dt@kernel.org, broonie@kernel.org, lorenzo.pieralisi@arm.com, jingoohan1@gmail.com, festevam@gmail.com, francesco.dolcini@toradex.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com Date: Wed, 08 Jun 2022 09:44:40 +0200 In-Reply-To: <1651801629-30223-8-git-send-email-hongxing.zhu@nxp.com> References: <1651801629-30223-1-git-send-email-hongxing.zhu@nxp.com> <1651801629-30223-8-git-send-email-hongxing.zhu@nxp.com> User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220608_004449_166270_8D9A939D X-CRM114-Status: GOOD ( 28.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Am Freitag, dem 06.05.2022 um 09:47 +0800 schrieb Richard Zhu: > To make it more reasonable, move the phy_power_on/phy_init callbacks to > the proper places. > - move the phy_power_on() out of imx6_pcie_clk_enable(). > - move the phy_init() out of imx6_pcie_deassert_core_reset(). > > In order to save power consumption, turn off the clocks and regulators when > the imx6_pcie_host_init() return error. > > Signed-off-by: Richard Zhu > --- > drivers/pci/controller/dwc/pci-imx6.c | 77 +++++++++++++++++++++------ > 1 file changed, 61 insertions(+), 16 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index d122c12193a6..f0ffd9011975 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -497,14 +497,6 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie) > goto err_ref_clk; > } > > - switch (imx6_pcie->drvdata->variant) { > - case IMX8MM: > - if (phy_power_on(imx6_pcie->phy)) > - dev_err(dev, "unable to power on PHY\n"); > - break; > - default: > - break; > - } > /* allow the clocks to stabilize */ > usleep_range(200, 500); > return 0; > @@ -597,10 +589,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) > switch (imx6_pcie->drvdata->variant) { > case IMX8MQ: > reset_control_deassert(imx6_pcie->pciephy_reset); > - break; > case IMX8MM: > - if (phy_init(imx6_pcie->phy)) > - dev_err(dev, "waiting for phy ready timeout!\n"); This looks fishy. You now fall-through from the 8MQ case to the 8MM case, just to break there. Please move the 8MM case down to the 6QP case that also doesn't need to do anything here. > break; > case IMX7D: > reset_control_deassert(imx6_pcie->pciephy_reset); > @@ -918,15 +907,38 @@ static int imx6_pcie_host_init(struct pcie_port *pp) > > imx6_pcie_assert_core_reset(imx6_pcie); > imx6_pcie_init_phy(imx6_pcie); > + if (imx6_pcie->phy != NULL) { Same comment as on the last patch: drop the "!= NULL". > + ret = phy_power_on(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "pcie phy power up failed.\n"); > + return ret; > + } > + } > + > ret = imx6_pcie_deassert_core_reset(imx6_pcie); > if (ret < 0) { > dev_err(dev, "pcie host init failed: %d.\n", ret); > - return ret; > + goto err_exit0; This label is not very descriptive. Please rename to something like err_phy_off or something like that. > + } else if (imx6_pcie->phy != NULL) { The else path isn't needed here. If there was an error you already moved the contol flow to the error label. So drop the else and again have this block under a simple "if (imx6_pcie->phy)" statement. > + ret = phy_init(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "waiting for phy ready timeout!\n"); > + goto err_exit1; Again, please give those labels a more descriptive name. All of the above comments also apply to the changes in imx6_pcie_resume_noirq. Regards, Lucas > + } > } > > imx6_setup_phy_mpll(imx6_pcie); > > return 0; > + > +err_exit1: > + imx6_pcie_clk_disable(imx6_pcie); > + if (imx6_pcie->vpcie) > + regulator_disable(imx6_pcie->vpcie); > +err_exit0: > + if (imx6_pcie->phy != NULL) > + phy_power_off(imx6_pcie->phy); > + return ret; > } > > static const struct dw_pcie_host_ops imx6_pcie_host_ops = { > @@ -1031,14 +1043,47 @@ static int imx6_pcie_resume_noirq(struct device *dev) > regulator_disable(imx6_pcie->vpcie); > > imx6_pcie_init_phy(imx6_pcie); > - imx6_pcie_deassert_core_reset(imx6_pcie); > - dw_pcie_setup_rc(pp); > + if (imx6_pcie->phy != NULL) { > + ret = phy_power_on(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "pcie phy power up failed.\n"); > + return ret; > + } > + } > + > + ret = imx6_pcie_deassert_core_reset(imx6_pcie); > + if (ret < 0) { > + dev_err(dev, "pcie deassert core reset failed: %d.\n", ret); > + goto err_exit0; > + } else if (imx6_pcie->phy != NULL) { > + ret = phy_init(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "pcie phy init failed.\n"); > + goto err_exit1; > + } > + } > > + dw_pcie_setup_rc(pp); > ret = imx6_pcie_start_link(imx6_pcie->pci); > - if (ret < 0) > - dev_info(dev, "pcie link is down after resume.\n"); > + if (ret < 0) { > + /* > + * Return ret directly, since there are error exit > + * handle in imx6_pcie_start_link() > + */ > + dev_err(dev, "pcie link is down after resume.\n"); > + return ret; > + } > > return 0; > + > +err_exit1: > + imx6_pcie_clk_disable(imx6_pcie); > + if (imx6_pcie->vpcie) > + regulator_disable(imx6_pcie->vpcie); > +err_exit0: > + if (imx6_pcie->phy != NULL) > + phy_power_off(imx6_pcie->phy); > + return ret; > } > #endif > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 30B80CCA486 for ; Wed, 8 Jun 2022 08:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230452AbiFHIRl (ORCPT ); Wed, 8 Jun 2022 04:17:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230454AbiFHIQI (ORCPT ); Wed, 8 Jun 2022 04:16:08 -0400 Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BC3A65C2 for ; Wed, 8 Jun 2022 00:44:52 -0700 (PDT) Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=[IPv6:::1]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyqMr-0002o3-H8; Wed, 08 Jun 2022 09:44:41 +0200 Message-ID: <323f9352fcf22c040417b16e57647695a48c1395.camel@pengutronix.de> Subject: Re: [PATCH v9 7/8] PCI: imx6: Move the phy driver callbacks to the proper places From: Lucas Stach To: Richard Zhu , bhelgaas@google.com, robh+dt@kernel.org, broonie@kernel.org, lorenzo.pieralisi@arm.com, jingoohan1@gmail.com, festevam@gmail.com, francesco.dolcini@toradex.com Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kernel@pengutronix.de, linux-imx@nxp.com Date: Wed, 08 Jun 2022 09:44:40 +0200 In-Reply-To: <1651801629-30223-8-git-send-email-hongxing.zhu@nxp.com> References: <1651801629-30223-1-git-send-email-hongxing.zhu@nxp.com> <1651801629-30223-8-git-send-email-hongxing.zhu@nxp.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.40.4 (3.40.4-1.fc34) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Am Freitag, dem 06.05.2022 um 09:47 +0800 schrieb Richard Zhu: > To make it more reasonable, move the phy_power_on/phy_init callbacks to > the proper places. > - move the phy_power_on() out of imx6_pcie_clk_enable(). > - move the phy_init() out of imx6_pcie_deassert_core_reset(). > > In order to save power consumption, turn off the clocks and regulators when > the imx6_pcie_host_init() return error. > > Signed-off-by: Richard Zhu > --- > drivers/pci/controller/dwc/pci-imx6.c | 77 +++++++++++++++++++++------ > 1 file changed, 61 insertions(+), 16 deletions(-) > > diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c > index d122c12193a6..f0ffd9011975 100644 > --- a/drivers/pci/controller/dwc/pci-imx6.c > +++ b/drivers/pci/controller/dwc/pci-imx6.c > @@ -497,14 +497,6 @@ static int imx6_pcie_clk_enable(struct imx6_pcie *imx6_pcie) > goto err_ref_clk; > } > > - switch (imx6_pcie->drvdata->variant) { > - case IMX8MM: > - if (phy_power_on(imx6_pcie->phy)) > - dev_err(dev, "unable to power on PHY\n"); > - break; > - default: > - break; > - } > /* allow the clocks to stabilize */ > usleep_range(200, 500); > return 0; > @@ -597,10 +589,7 @@ static int imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie) > switch (imx6_pcie->drvdata->variant) { > case IMX8MQ: > reset_control_deassert(imx6_pcie->pciephy_reset); > - break; > case IMX8MM: > - if (phy_init(imx6_pcie->phy)) > - dev_err(dev, "waiting for phy ready timeout!\n"); This looks fishy. You now fall-through from the 8MQ case to the 8MM case, just to break there. Please move the 8MM case down to the 6QP case that also doesn't need to do anything here. > break; > case IMX7D: > reset_control_deassert(imx6_pcie->pciephy_reset); > @@ -918,15 +907,38 @@ static int imx6_pcie_host_init(struct pcie_port *pp) > > imx6_pcie_assert_core_reset(imx6_pcie); > imx6_pcie_init_phy(imx6_pcie); > + if (imx6_pcie->phy != NULL) { Same comment as on the last patch: drop the "!= NULL". > + ret = phy_power_on(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "pcie phy power up failed.\n"); > + return ret; > + } > + } > + > ret = imx6_pcie_deassert_core_reset(imx6_pcie); > if (ret < 0) { > dev_err(dev, "pcie host init failed: %d.\n", ret); > - return ret; > + goto err_exit0; This label is not very descriptive. Please rename to something like err_phy_off or something like that. > + } else if (imx6_pcie->phy != NULL) { The else path isn't needed here. If there was an error you already moved the contol flow to the error label. So drop the else and again have this block under a simple "if (imx6_pcie->phy)" statement. > + ret = phy_init(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "waiting for phy ready timeout!\n"); > + goto err_exit1; Again, please give those labels a more descriptive name. All of the above comments also apply to the changes in imx6_pcie_resume_noirq. Regards, Lucas > + } > } > > imx6_setup_phy_mpll(imx6_pcie); > > return 0; > + > +err_exit1: > + imx6_pcie_clk_disable(imx6_pcie); > + if (imx6_pcie->vpcie) > + regulator_disable(imx6_pcie->vpcie); > +err_exit0: > + if (imx6_pcie->phy != NULL) > + phy_power_off(imx6_pcie->phy); > + return ret; > } > > static const struct dw_pcie_host_ops imx6_pcie_host_ops = { > @@ -1031,14 +1043,47 @@ static int imx6_pcie_resume_noirq(struct device *dev) > regulator_disable(imx6_pcie->vpcie); > > imx6_pcie_init_phy(imx6_pcie); > - imx6_pcie_deassert_core_reset(imx6_pcie); > - dw_pcie_setup_rc(pp); > + if (imx6_pcie->phy != NULL) { > + ret = phy_power_on(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "pcie phy power up failed.\n"); > + return ret; > + } > + } > + > + ret = imx6_pcie_deassert_core_reset(imx6_pcie); > + if (ret < 0) { > + dev_err(dev, "pcie deassert core reset failed: %d.\n", ret); > + goto err_exit0; > + } else if (imx6_pcie->phy != NULL) { > + ret = phy_init(imx6_pcie->phy); > + if (ret) { > + dev_err(dev, "pcie phy init failed.\n"); > + goto err_exit1; > + } > + } > > + dw_pcie_setup_rc(pp); > ret = imx6_pcie_start_link(imx6_pcie->pci); > - if (ret < 0) > - dev_info(dev, "pcie link is down after resume.\n"); > + if (ret < 0) { > + /* > + * Return ret directly, since there are error exit > + * handle in imx6_pcie_start_link() > + */ > + dev_err(dev, "pcie link is down after resume.\n"); > + return ret; > + } > > return 0; > + > +err_exit1: > + imx6_pcie_clk_disable(imx6_pcie); > + if (imx6_pcie->vpcie) > + regulator_disable(imx6_pcie->vpcie); > +err_exit0: > + if (imx6_pcie->phy != NULL) > + phy_power_off(imx6_pcie->phy); > + return ret; > } > #endif >