mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@kalray.eu>
To: Sascha Hauer <sha@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy
Date: Fri, 11 Dec 2020 17:21:10 +0100	[thread overview]
Message-ID: <20201211162110.th725gs3ddrcyp5s@tellis.lin.mbt.kalray.eu> (raw)
In-Reply-To: <20201211153608.GB3977@pengutronix.de>

Hi Sascha,

On Fri, Dec 11, 2020 at 04:36:08PM +0100, Sascha Hauer wrote:
> On Thu, Dec 10, 2020 at 11:31:01AM +0100, Jules Maselbas wrote:
> > Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> > ---
> >  drivers/usb/dwc2/core.h |  2 ++
> >  drivers/usb/dwc2/dwc2.c | 24 ++++++++++++++++++++++++
> >  drivers/usb/dwc2/dwc2.h |  1 +
> >  3 files changed, 27 insertions(+)
> > 
> > diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> > index 090ca15fe..b9845b552 100644
> > --- a/drivers/usb/dwc2/core.h
> > +++ b/drivers/usb/dwc2/core.h
> > @@ -466,6 +466,8 @@ struct dwc2 {
> >  	struct dwc2_hw_params hw_params;
> >  	struct dwc2_core_params params;
> >  
> > +	struct phy *phy; /* optional */
> > +
> >  #ifdef CONFIG_USB_DWC2_HOST
> >  	struct usb_host host;
> >  	u8 in_data_toggle[MAX_DEVICE][MAX_ENDPOINT];
> > diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
> > index 282e6754b..9ab3b5b53 100644
> > --- a/drivers/usb/dwc2/dwc2.c
> > +++ b/drivers/usb/dwc2/dwc2.c
> > @@ -50,6 +50,20 @@ static int dwc2_probe(struct device_d *dev)
> >  	dwc2->regs = IOMEM(iores->start);
> >  	dwc2->dev = dev;
> >  
> > +	dwc2->phy = phy_optional_get(dev, "usb2-phy");
> > +	if (IS_ERR(dwc2->phy)) {
> > +		ret = PTR_ERR(dwc2->phy);
> > +		return ret;
> > +	}
> > +
> > +	if (dwc2->phy) {
> > +		ret = phy_power_on(dwc2->phy);
> > +		if (ret == 0)
> > +			ret = phy_init(dwc2->phy);
> > +		if (ret)
> > +			goto error;
> > +	}
> 
> Just like with clocks a NULL pointer is handled like a dummy phy, you
> can drop the if (dwc2->phy) tests here.
Alright, I'll remove theses ifs.

> 
> Shouldn't phy_init() called before phy_power_on()? At least that's the
> order I find in the Kernel in several places.
Indeed, from what I've seen it is mostly phy_power_on and then phy_init.
However in the dwc2 driver in Linux's kernel, it is done the other way
around, see the function __dwc2_lowlevel_hw_enable in dwc2/platform.c [1]

I don't fully understand the phy api. My assumption was that phy_power_on
is used to power the phy interface, and that phy_init does initialisation
of the phy device such as toggling the reset pin as done by usb-nop-xceiv.

That's why I thought it was correct to first power on the phy and then do
initilisation. But I may have missunderstand both functions. Any insight
is more than welcome as I am new to this.

[1] https://elixir.bootlin.com/linux/latest/source/drivers/usb/dwc2/platform.c#L145

> >  	dwc2_gadget_uninit(dwc2);
> > +
> > +	if (dwc2->phy) {
> > +		ret = phy_exit(dwc2->phy);
> > +		if (ret == 0)
> > +			phy_power_off(dwc2->phy);
> > +	}
> 
> Likewise phy_power_off() before phy_exit().


---
Jules


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

  reply	other threads:[~2020-12-11 16:21 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-10 10:31 Jules Maselbas
2020-12-10 10:31 ` [PATCH v2 2/4] usb: dwc2: Remove unnecessary functions declaration Jules Maselbas
2020-12-10 10:31 ` [PATCH v2 3/4] usb: dwc2: Fix dr_mode check in dwc2_get_dr_mode Jules Maselbas
2020-12-10 10:31 ` [PATCH v2 4/4] usb: dwc2: Rename dwc2_core_snpsid to dwc2_check_core_version Jules Maselbas
2020-12-11 15:36 ` [PATCH v2 1/4] usb: dwc2: Add support for optional usb phy Sascha Hauer
2020-12-11 16:21   ` Jules Maselbas [this message]
2020-12-14 11:03 ` [PATCH v2] fixup! " Jules Maselbas
2020-12-16  8:21 ` [PATCH v2 1/4] " 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=20201211162110.th725gs3ddrcyp5s@tellis.lin.mbt.kalray.eu \
    --to=jmaselbas@kalray.eu \
    --cc=barebox@lists.infradead.org \
    --cc=sha@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