From: Lucas Stach <l.stach@pengutronix.de>
To: Sean Cross <xobs@kosagi.com>
Cc: Rob Herring <robh+dt@kernel.org>, Pawel Moll <pawel.moll@arm.com>,
Mark Rutland <mark.rutland@arm.com>,
Ian Campbell <ijc+devicetree@hellion.org.uk>,
Kumar Gala <galak@codeaurora.org>,
Shawn Guo <shawn.guo@freescale.com>,
Bjorn Helgaas <bhelgaas@google.com>,
devicetree@vger.kernel.org, Richard Zhu <r65037@freescale.com>,
Grant Likely <grant.likely@linaro.org>,
linux-pci@vger.kernel.org, bunnie@kosagi.com
Subject: Re: [PATCH 1/2] PCI: imx6: Add power-supply support
Date: Fri, 19 Dec 2014 11:19:32 +0100 [thread overview]
Message-ID: <1418984372.2558.1.camel@pengutronix.de> (raw)
In-Reply-To: <1418976617-833-2-git-send-email-xobs@kosagi.com>
Am Freitag, den 19.12.2014, 16:10 +0800 schrieb Sean Cross:
> Some PCIe ports gate power to the slot. In order to prevent system lockup,
> these boards must enable power to the slot before attempting communication
> over the PCI bus.
>
> Signed-off-by: Sean Cross <xobs@kosagi.com>
> ---
> .../devicetree/bindings/pci/fsl,imx6q-pcie.txt | 3 +++
> drivers/pci/host/pci-imx6.c | 20 +++++++++++++++++++-
> 2 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt
> index 6fbba53..fe912bd 100644
> --- a/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt
> +++ b/Documentation/devicetree/bindings/pci/fsl,imx6q-pcie.txt
> @@ -13,6 +13,9 @@ Required properties:
> - clock-names: Must include the following additional entries:
> - "pcie_phy"
>
> +Optional properties:
> +- power-supply: A regulator that controls power to the port
This is a way too generic name. In order to provide the functionality
you are intending, this regulator needs to supply the whole bus
(remember not every board has just a single slot). It should be named
accordingly.
So I would expect this to look something like the following:
bus-supply: A regulator that controls main power to every device on the
bus.
> +
> Example:
>
> pcie@0x01000000 {
> diff --git a/drivers/pci/host/pci-imx6.c b/drivers/pci/host/pci-imx6.c
> index 69202d1..9c2140e 100644
> --- a/drivers/pci/host/pci-imx6.c
> +++ b/drivers/pci/host/pci-imx6.c
> @@ -22,6 +22,7 @@
> #include <linux/pci.h>
> #include <linux/platform_device.h>
> #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
> #include <linux/resource.h>
> #include <linux/signal.h>
> #include <linux/types.h>
> @@ -39,6 +40,7 @@ struct imx6_pcie {
> struct pcie_port pp;
> struct regmap *iomuxc_gpr;
> void __iomem *mem_base;
> + struct regulator *power_reg;
> };
>
> /* PCIe Root Complex registers (memory-mapped) */
> @@ -588,6 +590,19 @@ static int __init imx6_pcie_probe(struct platform_device *pdev)
> }
> }
>
> + /* Fetch power supply */
> + imx6_pcie->power_reg = devm_regulator_get(&pdev->dev, "power");
Use devm_regulator_get_optional instead.
> + if (IS_ERR(imx6_pcie->power_reg))
> + imx6_pcie->power_reg = 0;
This can go away if you use the above, but really? 0 to a pointer? I
know it isn't invalid, but it's also bad style.
You must handle -EPROBE_DEFER here instead.
> +
> + if (imx6_pcie->power_reg) {
> + ret = regulator_enable(imx6_pcie->power_reg);
> + if (ret) {
> + dev_err(&pdev->dev, "Unable to enable power regulator");
> + return ret;
> + }
> + }
> +
I'm not really comfortable with enabling directly at probe time, but
given our failure paths are horrible enough as they are right now I
agree that this is the sanest solution for now.
But please move both enabling and disabling at failure into
imx6_add_pcie_port().
> /* Fetch clocks */
> imx6_pcie->pcie_phy = devm_clk_get(&pdev->dev, "pcie_phy");
> if (IS_ERR(imx6_pcie->pcie_phy)) {
> @@ -619,8 +634,11 @@ static int __init imx6_pcie_probe(struct platform_device *pdev)
> }
>
> ret = imx6_add_pcie_port(pp, pdev);
> - if (ret < 0)
> + if (ret < 0) {
> + if (imx6_pcie->power_reg)
> + regulator_disable(imx6_pcie->power_reg);
> return ret;
> + }
>
> platform_set_drvdata(pdev, imx6_pcie);
> return 0;
Regards,
Lucas
--
Pengutronix e.K. | Lucas Stach |
Industrial Linux Solutions | http://www.pengutronix.de/ |
next prev parent reply other threads:[~2014-12-19 10:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-19 8:10 [PATCH 0/2] Add support for kosagi novena Sean Cross
2014-12-19 8:10 ` [PATCH 1/2] PCI: imx6: Add power-supply support Sean Cross
2014-12-19 10:19 ` Lucas Stach [this message]
2014-12-19 8:10 ` [PATCH 2/2] ARM: dts: imx6q: add Novena board Sean Cross
2014-12-19 10:32 ` Lucas Stach
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=1418984372.2558.1.camel@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=bhelgaas@google.com \
--cc=bunnie@kosagi.com \
--cc=devicetree@vger.kernel.org \
--cc=galak@codeaurora.org \
--cc=grant.likely@linaro.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linux-pci@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=r65037@freescale.com \
--cc=robh+dt@kernel.org \
--cc=shawn.guo@freescale.com \
--cc=xobs@kosagi.com \
/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: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).