From: Lucas Stach <l.stach@pengutronix.de> To: Richard Zhu <hongxing.zhu@nxp.com>, 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 Subject: Re: [PATCH v9 7/8] PCI: imx6: Move the phy driver callbacks to the proper places Date: Wed, 08 Jun 2022 09:44:40 +0200 [thread overview] Message-ID: <323f9352fcf22c040417b16e57647695a48c1395.camel@pengutronix.de> (raw) In-Reply-To: <1651801629-30223-8-git-send-email-hongxing.zhu@nxp.com> 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 <hongxing.zhu@nxp.com> > --- > 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
WARNING: multiple messages have this Message-ID (diff)
From: Lucas Stach <l.stach@pengutronix.de> To: Richard Zhu <hongxing.zhu@nxp.com>, 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 Subject: Re: [PATCH v9 7/8] PCI: imx6: Move the phy driver callbacks to the proper places Date: Wed, 08 Jun 2022 09:44:40 +0200 [thread overview] Message-ID: <323f9352fcf22c040417b16e57647695a48c1395.camel@pengutronix.de> (raw) In-Reply-To: <1651801629-30223-8-git-send-email-hongxing.zhu@nxp.com> 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 <hongxing.zhu@nxp.com> > --- > 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 >
next prev parent reply other threads:[~2022-06-08 7:45 UTC|newest] Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-05-06 1:47 [PATCH v9 0/8] PCI: imx6: refine codes and add compliance tests mode support Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-05-06 1:47 ` [PATCH v9 1/8] PCI: imx6: Encapsulate the clock enable into one standalone function Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 18:51 ` Bjorn Helgaas 2022-06-08 18:51 ` Bjorn Helgaas 2022-06-09 6:18 ` Hongxing Zhu 2022-06-09 6:18 ` Hongxing Zhu 2022-05-06 1:47 ` [PATCH v9 2/8] PCI: imx6: Add the error propagation from host_init Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 18:53 ` Bjorn Helgaas 2022-06-08 18:53 ` Bjorn Helgaas 2022-06-09 6:19 ` Hongxing Zhu 2022-06-09 6:19 ` Hongxing Zhu 2022-05-06 1:47 ` [PATCH v9 3/8] PCI: imx6: Move imx6_pcie_clk_disable() earlier Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 7:14 ` Lucas Stach 2022-06-08 7:14 ` Lucas Stach 2022-05-06 1:47 ` [PATCH v9 4/8] PCI: imx6: Disable iMX6QDL PCIe REF clock when disable PCIe clocks Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 7:18 ` Lucas Stach 2022-06-08 7:18 ` Lucas Stach 2022-05-06 1:47 ` [PATCH v9 5/8] PCI: imx6: Refine the regulator usage Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 7:26 ` Lucas Stach 2022-06-08 7:26 ` Lucas Stach 2022-06-09 6:17 ` Hongxing Zhu 2022-06-09 6:17 ` Hongxing Zhu 2022-06-09 7:47 ` Lucas Stach 2022-06-09 7:47 ` Lucas Stach 2022-06-09 7:54 ` Hongxing Zhu 2022-06-09 7:54 ` Hongxing Zhu 2022-06-08 18:54 ` Bjorn Helgaas 2022-06-08 18:54 ` Bjorn Helgaas 2022-06-09 6:19 ` Hongxing Zhu 2022-06-09 6:19 ` Hongxing Zhu 2022-06-09 17:20 ` Bjorn Helgaas 2022-06-09 17:20 ` Bjorn Helgaas 2022-06-10 7:09 ` Hongxing Zhu 2022-06-10 7:09 ` Hongxing Zhu 2022-05-06 1:47 ` [PATCH v9 6/8] PCI: imx6: Disable clocks and regulators after link is down Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 7:35 ` Lucas Stach 2022-06-08 7:35 ` Lucas Stach 2022-06-09 6:17 ` Hongxing Zhu 2022-06-09 6:17 ` Hongxing Zhu 2022-06-09 7:53 ` Francesco Dolcini 2022-06-09 7:53 ` Francesco Dolcini 2022-06-09 8:36 ` Hongxing Zhu 2022-06-09 8:36 ` Hongxing Zhu 2022-06-09 7:55 ` Lucas Stach 2022-06-09 7:55 ` Lucas Stach 2022-06-09 8:30 ` Hongxing Zhu 2022-06-09 8:30 ` Hongxing Zhu 2022-05-06 1:47 ` [PATCH v9 7/8] PCI: imx6: Move the phy driver callbacks to the proper places Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 7:44 ` Lucas Stach [this message] 2022-06-08 7:44 ` Lucas Stach 2022-06-09 6:18 ` Hongxing Zhu 2022-06-09 6:18 ` Hongxing Zhu 2022-06-08 18:57 ` Bjorn Helgaas 2022-06-08 18:57 ` Bjorn Helgaas 2022-06-09 6:20 ` Hongxing Zhu 2022-06-09 6:20 ` Hongxing Zhu 2022-06-09 16:25 ` Bjorn Helgaas 2022-06-09 16:25 ` Bjorn Helgaas 2022-06-10 6:51 ` Hongxing Zhu 2022-06-10 6:51 ` Hongxing Zhu 2022-05-06 1:47 ` [PATCH v9 8/8] PCI: imx6: Add compliance tests mode support Richard Zhu 2022-05-06 1:47 ` Richard Zhu 2022-06-08 7:48 ` Lucas Stach 2022-06-08 7:48 ` Lucas Stach 2022-06-09 6:18 ` Hongxing Zhu 2022-06-09 6:18 ` Hongxing Zhu
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=323f9352fcf22c040417b16e57647695a48c1395.camel@pengutronix.de \ --to=l.stach@pengutronix.de \ --cc=bhelgaas@google.com \ --cc=broonie@kernel.org \ --cc=festevam@gmail.com \ --cc=francesco.dolcini@toradex.com \ --cc=hongxing.zhu@nxp.com \ --cc=jingoohan1@gmail.com \ --cc=kernel@pengutronix.de \ --cc=linux-arm-kernel@lists.infradead.org \ --cc=linux-imx@nxp.com \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-pci@vger.kernel.org \ --cc=lorenzo.pieralisi@arm.com \ --cc=robh+dt@kernel.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.