linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>
To: Jules Maselbas <jmaselbas@kalray.eu>,
	Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] usb: dwc2: Try usb_get_phy_by_phandle instead of usb_get_phy
Date: Fri, 25 Dec 2020 11:41:04 +0000	[thread overview]
Message-ID: <d753fafc-a50a-d19b-d872-78f34dfa01ca@synopsys.com> (raw)
In-Reply-To: <20201216165935.9149-1-jmaselbas@kalray.eu>

Hi Jules,

On 12/16/2020 20:59, Jules Maselbas wrote:
> On probe the dwc2 driver tries two path to get an usb phy, first calling
> devm_phy_get() and secondly with devm_usb_get_phy().
> 
> However the current implementation of devm_phy_get() never return a valid
> phy for usb-nop-xceiv. And the current implementation of devm_usb_get_phy
> only check for phy that's has already been registered.
> 
> During boot, I see the dwc2 driver being probed before the usb-nop-xceiv
> probe, this means that during the dwc2 probe the function devm_usb_get_phy
> never finds the a phy (because it hasn't been registered yet) but never
> cause the dwc2 probe to defer.
> 
> I tried to follow what is done by dwc3_core_get_phy(): if the current
> device has an of_node then try to get the usb_phy by phandle instead of
> using devm_usb_get_phy(). This way when the probe order is not good the
> devm_usb_get_phy_by_phandle() function will return -EPROBE_DEFER.
> 
> Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
> --- 8< ---
> 
> A snippet of the device-tree source I am using:
>          &usb0 {
>                  phys = <&usb_phy0>;
>                  phy-names = "usb2-phy";
>          };
>          &usb_phy0 {
>                  #phy-cells = <0>;
>                  compatible = "usb-nop-xceiv";
>                  reset-gpios = <&gpio 0 GPIO_ACTIVE_LOW>;
>          };
> ---
>   drivers/usb/dwc2/platform.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index db9fd4bd1a38..b58ce996add7 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -251,7 +251,12 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg *hsotg)
>   	}
>   
>   	if (!hsotg->phy) {
> -		hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2);
> +		if (hsotg->dev->of_node)
> +			i = of_property_match_string(hsotg->dev->of_node, "phy-names", "usb2-phy");

According the device tree you have provided the value of "i" will always 
be "0".

> +		if (hsotg->dev->of_node && i >= 0)
> +			hsotg->uphy = devm_usb_get_phy_by_phandle(hsotg->dev, "phys", i);

Why do you use the value of "i" while in "<&usb_phy0>" you have only one 
phy. If you had several phy-names and the value of "i" gets more than 0, 
then based on your usb_phy0 "devm_usb_get_phy_by_phandle" function will 
return error. So, maybe it would be more correct (based on your device 
tree), to use below command
hsotg->uphy = devm_usb_get_phy_by_phandle(hsotg->dev, "phys", 0);

> +		else
> +			hsotg->uphy = devm_usb_get_phy(hsotg->dev, USB_PHY_TYPE_USB2);
>   		if (IS_ERR(hsotg->uphy)) {
>   			ret = PTR_ERR(hsotg->uphy);
>   			switch (ret) {
> 

Regards,
Artur

  reply	other threads:[~2020-12-25 11:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-16 16:59 [RFC PATCH] usb: dwc2: Try usb_get_phy_by_phandle instead of usb_get_phy Jules Maselbas
2020-12-25 11:41 ` Artur Petrosyan [this message]
2020-12-26 13:45   ` Jules Maselbas
2020-12-29  8:17     ` Artur Petrosyan

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=d753fafc-a50a-d19b-d872-78f34dfa01ca@synopsys.com \
    --to=arthur.petrosyan@synopsys.com \
    --cc=Minas.Harutyunyan@synopsys.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jmaselbas@kalray.eu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.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: 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).