Re: [RFC PATCH] usb: dwc2: Try usb_get_phy_by_phandle instead of usb_get_phy
From: Artur Petrosyan
Date: Tue Dec 29 2020 - 03:20:28 EST
Hi Jules,
On 12/26/2020 17:45, Jules Maselbas wrote:
> Hi Artur,
>
> On Fri, Dec 25, 2020 at 11:41:04AM +0000, Artur Petrosyan wrote:
>>> @@ -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".
> Yes
>
>>> + 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);
> Yes I could use 0 instead of i, but I would like this to work not only
> for my case where the "usb2-phy" phandle comes first.
>
> I've tried to follow what's done in phy-core.c, as done by the function
> phy_get. Where it first call "of_property_match_string" and then get the
> phy with the matched index.
>
> I don't see how, in my case, the function "devm_usb_get_phy_by_phandle" can
> be called with i greater than 0, and returning an error.
I have noticed that there might be no need to check for "i >= 0" at all
because "of_parse_phandle()" function has a check for index to not be
less then 0.
>
> Best,
> Jules
>
Regards,
Artur