diff mbox

[RFC,V2,2/2] usb: hcd: Initialize USB phy if needed

Message ID 1383822869-20283-3-git-send-email-valentine.barshak@cogentembedded.com (mailing list archive)
State Superseded
Delegated to: Paul Mundt
Headers show

Commit Message

Valentine Barshak Nov. 7, 2013, 11:14 a.m. UTC
This adds external USB phy support to USB HCD driver that
allows to find and initialize external USB phy, bound to
the HCD, when the HCD is added.
The usb_add_hcd function returns -EPROBE_DEFER if the USB
phy, bound to the HCD, is not ready.
If no USB phy is bound, the HCD is initialized as usual.

Signed-off-by: Valentine Barshak <valentine.barshak@cogentembedded.com>
---
 drivers/usb/core/hcd.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Peter Chen Nov. 7, 2013, 1:06 p.m. UTC | #1
> 
> +#ifdef CONFIG_USB_PHY
> +	if (!hcd->phy) {
> +		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller,
> 0);
> +
> +		if (IS_ERR(phy)) {
> +			retval = PTR_ERR(phy);
> +			if (retval == -EPROBE_DEFER)
> +				return retval;
> +		} else {
> +			retval = usb_phy_init(phy);
> +			if (retval) {
> +				usb_put_phy(phy);
> +				return retval;
> +			}
> +			hcd->phy = phy;
> +			hcd->remove_phy = 1;
> +		}
> +	}
> +#endif
> +

If the platform doesn't has phy driver, and with CONFIG_USB_PHY enabled, it
will have problem for above code.

Peter 


--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Valentine Barshak Nov. 7, 2013, 2:50 p.m. UTC | #2
On 11/07/2013 05:06 PM, Peter Chen wrote:
>
>
>>
>> +#ifdef CONFIG_USB_PHY
>> +	if (!hcd->phy) {
>> +		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller,
>> 0);
>> +
>> +		if (IS_ERR(phy)) {
>> +			retval = PTR_ERR(phy);
>> +			if (retval == -EPROBE_DEFER)
>> +				return retval;
>> +		} else {
>> +			retval = usb_phy_init(phy);
>> +			if (retval) {
>> +				usb_put_phy(phy);
>> +				return retval;
>> +			}
>> +			hcd->phy = phy;
>> +			hcd->remove_phy = 1;
>> +		}
>> +	}
>> +#endif
>> +
>
> If the platform doesn't has phy driver, and with CONFIG_USB_PHY enabled, it
> will have problem for above code.
>

It shouldn't have any problems since there's no phy bound to the HCD in this case.
Thus, usb_get_phy_dev returns -ENODEV and the HCD will be added as usual.

> Peter

Thanks,
Val.

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alan Stern Nov. 7, 2013, 3:18 p.m. UTC | #3
On Thu, 7 Nov 2013, Valentine Barshak wrote:

> This adds external USB phy support to USB HCD driver that
> allows to find and initialize external USB phy, bound to
> the HCD, when the HCD is added.
> The usb_add_hcd function returns -EPROBE_DEFER if the USB
> phy, bound to the HCD, is not ready.
> If no USB phy is bound, the HCD is initialized as usual.
> 
> Signed-off-by: Valentine Barshak <valentine.barshak@cogentembedded.com>

Acked-by: Alan Stern <stern@rowland.harvard.edu>

--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Peter Chen Nov. 8, 2013, 1:44 a.m. UTC | #4
> >>
> >> +#ifdef CONFIG_USB_PHY
> >> +	if (!hcd->phy) {
> >> +		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller,
> >> 0);
> >> +
> >> +		if (IS_ERR(phy)) {
> >> +			retval = PTR_ERR(phy);
> >> +			if (retval == -EPROBE_DEFER)
> >> +				return retval;
> >> +		} else {
> >> +			retval = usb_phy_init(phy);
> >> +			if (retval) {
> >> +				usb_put_phy(phy);
> >> +				return retval;
> >> +			}
> >> +			hcd->phy = phy;
> >> +			hcd->remove_phy = 1;
> >> +		}
> >> +	}
> >> +#endif
> >> +
> >
> > If the platform doesn't has phy driver, and with CONFIG_USB_PHY enabled,
> it
> > will have problem for above code.
> >
> 
> It shouldn't have any problems since there's no phy bound to the HCD in
> this case.
> Thus, usb_get_phy_dev returns -ENODEV and the HCD will be added as usual.
> 
Yes, my fault. The retval will be override later.

Peter


--
To unsubscribe from this list: send the line "unsubscribe linux-sh" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d939521..fd09ec6 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -2597,6 +2597,26 @@  int usb_add_hcd(struct usb_hcd *hcd,
 	int retval;
 	struct usb_device *rhdev;
 
+#ifdef CONFIG_USB_PHY
+	if (!hcd->phy) {
+		struct usb_phy *phy = usb_get_phy_dev(hcd->self.controller, 0);
+
+		if (IS_ERR(phy)) {
+			retval = PTR_ERR(phy);
+			if (retval == -EPROBE_DEFER)
+				return retval;
+		} else {
+			retval = usb_phy_init(phy);
+			if (retval) {
+				usb_put_phy(phy);
+				return retval;
+			}
+			hcd->phy = phy;
+			hcd->remove_phy = 1;
+		}
+	}
+#endif
+
 	dev_info(hcd->self.controller, "%s\n", hcd->product_desc);
 
 	/* Keep old behaviour if authorized_default is not in [0, 1]. */