mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Marco Felsch <m.felsch@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH] usb: i.MX: improve regulator handling
Date: Wed, 21 Oct 2020 07:49:07 +0200	[thread overview]
Message-ID: <20201021054907.sunblqmijd4jl6zn@pengutronix.de> (raw)
In-Reply-To: <20201020145844.4id6iyuihl3hkt3x@pengutronix.de>


[-- Attachment #1.1: Type: text/plain, Size: 4584 bytes --]

On Tue, Oct 20, 2020 at 04:58:44PM +0200, Marco Felsch wrote:
> On 20-10-20 16:28, Marco Felsch wrote:
> > On 20-10-20 16:09, Sascha Hauer wrote:
> > > On Tue, Oct 20, 2020 at 03:33:17PM +0200, Marco Felsch wrote:
> > > > Hi Uwe,
> > > > 
> > > > On 20-10-20 13:15, Uwe Kleine-König wrote:
> > > > > Instead of just ignoring errors related to regulator getting error out.
> > > > > In case there is no regulator in the device tree, regulator_get() returns
> > > > > the dummy regulator and not an error code, so the change is right for
> > > > > this situation, too.
> > > > > 
> > > > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> > > > > ---
> > > > >  drivers/usb/imx/chipidea-imx.c | 7 +++++--
> > > > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > > > > 
> > > > > diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
> > > > > index 786beede6d89..dd0e3c1a2a58 100644
> > > > > --- a/drivers/usb/imx/chipidea-imx.c
> > > > > +++ b/drivers/usb/imx/chipidea-imx.c
> > > > > @@ -267,8 +267,11 @@ static int imx_chipidea_probe(struct device_d *dev)
> > > > >  	}
> > > > >  
> > > > >  	ci->vbus = regulator_get(dev, "vbus");
> > > > > -	if (IS_ERR(ci->vbus))
> > > > > -		ci->vbus = NULL;
> > > > > +	if (IS_ERR(ci->vbus)) {
> > > > > +		ret = ERR_PTR(ci->vbus);
> > > > > +		dev_err(dev, "Cannot get vbus regulator: %s\n", strerror(-ret));
> > > > > +		return ret;
> > > > 
> > > > Returning the error here can cause problems with exisiting boards, e.g.
> > > > if the regulator support is missing for the specified vbus regulator.
> > > > This is often the case since we have very limited regulator support for
> > > > now.
> > > 
> > > But when there is a regulator we also have to control it, right?
> > 
> > So you need to add each regulator driver or worst case you need to add
> > PMIC drivers.

Right, as if you don't the hardware might be off and USB won't work
without a useful error message.

> > If I remember correctly, I added the same for mci which
> > broke a lot of boards. Later you reverted those commit. Now Oleksij
> > added the regulator support for the fec driver and people are starting 
> > to remove the phy-supply handle from the barebox-dt's (commit 84cf5cfa9a
> > ("ARM: dts: imx6qdl: pfla02: Remove fec phy-supply")). I'm not again

Looking at 84cf5cfa9a there is at least a comment missing about why this
property is deleted. Something like

diff --git a/arch/arm/dts/imx6qdl-phytec-pfla02.dtsi b/arch/arm/dts/imx6qdl-phytec-pfla02.dtsi
index b83511cb011f..7a12e2a06be4 100644
--- a/arch/arm/dts/imx6qdl-phytec-pfla02.dtsi
+++ b/arch/arm/dts/imx6qdl-phytec-pfla02.dtsi
@@ -84,6 +84,11 @@
 };
 
 &fec {
+	/*
+	 * barebox doesn't have a driver for the PMIC providing the phy-supply
+	 * (dlg,da9063). So remove the phy-supply property and rely on the
+	 * PMIC's reset default which has this supply enabled.
+	 */
 	/delete-property/ phy-supply;
 };
 

> > this patch, just wanted to show the consequences of it.
> 
> Sorry I have to correct myself, pls check the linux driver:
> 
> static int ci_get_platdata(struct device *dev,
> 			   struct ci_hdrc_platform_data *platdata)
> {
> 
> ...
> 
> /* Get the vbus regulator */
> platdata->reg_vbus = devm_regulator_get_optional(dev, "vbus");
> if (PTR_ERR(platdata->reg_vbus) == -EPROBE_DEFER) {
> 	return -EPROBE_DEFER;
> } else if (PTR_ERR(platdata->reg_vbus) == -ENODEV) {
> 	/* no vbus regulator is needed */
> 	platdata->reg_vbus = NULL;
> } else if (IS_ERR(platdata->reg_vbus)) {
> 	dev_err(dev, "Getting regulator error: %ld\n",
> 		PTR_ERR(platdata->reg_vbus));
> 	return PTR_ERR(platdata->reg_vbus);
> }

The difference between regulator_get and regulator_get_optional is that
the former doesn't return -ENODEV but yields the dummy regulator
instead. (Yes, this is the inversed semantic compared with
gpio_get_optional() and clk_get_optional().) So using
devm_regulator_get_optional and ignoring -ENODEV is kind of strange.  So
I think the above can be simplified to:

	platdata->reg_vbus = devm_regulator_get(dev, "vbus");
	if (IS_ERR(platdata->reg_vbus))
		return dev_err_probe(dev, PTR_ERR(platdata->reg_vbus),
				     "Failed to get vbus regulator\n");
	

and then it is more obvious that my barebox patch does the same.

Am I missing something?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2020-10-21  5:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-20 11:15 Uwe Kleine-König
2020-10-20 13:33 ` Marco Felsch
2020-10-20 14:09   ` Sascha Hauer
2020-10-20 14:28     ` Marco Felsch
2020-10-20 14:58       ` Marco Felsch
2020-10-21  5:49         ` Uwe Kleine-König [this message]
2020-10-21  6:07           ` Sascha Hauer
2020-10-21 14:29           ` Marco Felsch
2020-10-21 15:28             ` Marco Felsch
2020-10-21 19:05               ` Uwe Kleine-König
2020-10-21 10:05 ` Sascha Hauer
2020-10-21 12:03   ` Uwe Kleine-König
2020-10-21 12:31     ` Sascha Hauer

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=20201021054907.sunblqmijd4jl6zn@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=m.felsch@pengutronix.de \
    /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