mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jules Maselbas <jmaselbas@kalray.eu>
To: "Daniel Brát" <danek.brat@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 1/2] usb: dwc2: Make having a phy optional
Date: Wed, 8 Sep 2021 10:50:19 +0200	[thread overview]
Message-ID: <20210908085019.GB8023@tellis.lin.mbt.kalray.eu> (raw)
In-Reply-To: <20210908074622.3271-2-danek.brat@gmail.com>

Hi Daniel,

On Wed, Sep 08, 2021 at 09:46:21AM +0200, Daniel Brát wrote:
> Despite using 'phy_optional_get' to get a 'usb2_phy' inside its probe,
> the driver would fail if it didnt find it. Also, there is no Kconfig
> dependency on 'CONFIG_GENERIC_PHY', so without it defined te phy
> functions are unimplemented and always return -ENOSYS making dwc2 probe
> always fail too. Since the 'dwc2->phy' is optional, the driver was
> modified to reflect this.
> Tested working on Raspberry Pi 3B+.
> 
> Signed-off-by: Daniel Brát <danek.brat@gmail.com>
> ---
>  drivers/usb/dwc2/dwc2.c | 38 ++++++++++++++++++++++----------------
>  1 file changed, 22 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/dwc2.c b/drivers/usb/dwc2/dwc2.c
> index 9893977b8..8f3f8da00 100644
> --- a/drivers/usb/dwc2/dwc2.c
> +++ b/drivers/usb/dwc2/dwc2.c
> @@ -72,20 +72,22 @@ static int dwc2_probe(struct device_d *dev)
>  	if (ret)
>  		goto clk_disable;
>  
> -	dwc2->phy = phy_optional_get(dev, "usb2-phy");
> -	if (IS_ERR(dwc2->phy)) {
> -		ret = PTR_ERR(dwc2->phy);
> -		goto clk_disable;
> +	if (IS_ENABLED(CONFIG_GENERIC_PHY)) {
> +		dwc2->phy = phy_optional_get(dev, "usb2-phy");
> +		if (!dwc2->phy || IS_ERR(dwc2->phy)) {
I think a better way to fix this would be have phy_optional_get to
return NULL when CONFIG_GENERIC_PHY is not enabled. That way this
fix is not limited to dwc2 driver.

NULL is an expected return value for phy_optional_get when there is
no phy, so that must not cause any issue in the driver.

> +			dev_warn(dev, "Didnt find any 'usb2-phy'\n");
> +			dwc2->phy = NULL;
> +		} else {
> +			ret = phy_power_on(dwc2->phy);
> +			if (ret)
> +				goto clk_disable;
> +
> +			ret = phy_init(dwc2->phy);
> +			if (ret)
> +				goto phy_power_off;
> +		}
>  	}
>  
> -	ret = phy_power_on(dwc2->phy);
> -	if (ret)
> -		goto clk_disable;
> -
> -	ret = phy_init(dwc2->phy);
> -	if (ret)
> -		goto phy_power_off;
> -
>  	ret = dwc2_check_core_version(dwc2);
>  	if (ret)
>  		goto error;
> @@ -120,9 +122,11 @@ static int dwc2_probe(struct device_d *dev)
>  
>  	return 0;
>  error:
> -	phy_exit(dwc2->phy);
> +	if (dwc2->phy)
> +		phy_exit(dwc2->phy);
This is not needed as phy_exit already tests for NULL phy.

>  phy_power_off:
> -	phy_power_off(dwc2->phy);
> +	if (dwc2->phy)
> +		phy_power_off(dwc2->phy);
Same for phy_power_off

>  clk_disable:
>  	clk_disable(dwc2->clk);
>  clk_put:
> @@ -140,8 +144,10 @@ static void dwc2_remove(struct device_d *dev)
>  	dwc2_host_uninit(dwc2);
>  	dwc2_gadget_uninit(dwc2);
>  
> -	phy_exit(dwc2->phy);
> -	phy_power_off(dwc2->phy);
> +	if (dwc2->phy) {
> +		phy_exit(dwc2->phy);
> +		phy_power_off(dwc2->phy);
> +	}
Same as above

>  }
>  
>  static const struct of_device_id dwc2_platform_dt_ids[] = {
> -- 
> 2.17.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 
> 
> To declare a filtering error, please use the following link : https://www.security-mail.net/reporter.php?mid=6017.61386e3c.c78.0&r=jmaselbas%40kalray.eu&s=barebox-bounces%2Bjmaselbas%3Dkalray.eu%40lists.infradead.org&o=%5BPATCH+1%2F2%5D+usb%3A+dwc2%3A+Make+having+a+phy+optional&verdict=C&c=a2cb297eefa99425f437bd1e182a2eb5ba1e58f8
> 





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

  reply	other threads:[~2021-09-08  8:51 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-08  7:46 [PATCH 0/2] usb: dwc2: fix phy dependecy Daniel Brát
2021-09-08  7:46 ` [PATCH 1/2] usb: dwc2: Make having a phy optional Daniel Brát
2021-09-08  8:50   ` Jules Maselbas [this message]
2021-09-08 12:58     ` [PATCH 1/2 v2] " Daniel Brát
2021-10-04 10:06       ` Sascha Hauer
2021-10-19 16:16       ` Jules Maselbas
2021-10-20  9:07         ` Daniel Brát
2021-10-20  9:48           ` Jules Maselbas
2021-09-08  7:46 ` [PATCH 2/2] ARM: rpi_defconfig: Enable PHY core for dwc2 usb driver Daniel Brát

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=20210908085019.GB8023@tellis.lin.mbt.kalray.eu \
    --to=jmaselbas@kalray.eu \
    --cc=barebox@lists.infradead.org \
    --cc=danek.brat@gmail.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