diff mbox

[RFC,2/2] usb: hcd: Introduce CONFIG_USB_HCD_EXTERNAL_PHY option

Message ID 1383683607-28119-3-git-send-email-valentine.barshak@cogentembedded.com (mailing list archive)
State Awaiting Upstream
Headers show

Commit Message

Valentine Barshak Nov. 5, 2013, 8:33 p.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 ++++++++++++++++++++
 drivers/usb/host/Kconfig | 11 +++++++++++
 2 files changed, 31 insertions(+)

Comments

Felipe Balbi Nov. 6, 2013, 3:47 p.m. UTC | #1
Hi,

On Wed, Nov 06, 2013 at 12:33:27AM +0400, 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>
> ---
>  drivers/usb/core/hcd.c   | 20 ++++++++++++++++++++
>  drivers/usb/host/Kconfig | 11 +++++++++++
>  2 files changed, 31 insertions(+)
> 
> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> index d939521..da9c4ba 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_HCD_EXTERNAL_PHY

I think here would be a nicer location for a flag:

if (hcd->has_external_phy) {
	phy = usb_get_phy_dev();

	....
}

that flag would get set by the glue driver (ehci-omap, ehci-msm,
ohci-omap, etc), where necessary.
Alan Stern Nov. 6, 2013, 4:39 p.m. UTC | #2
On Wed, 6 Nov 2013, Felipe Balbi wrote:

> Hi,
> 
> On Wed, Nov 06, 2013 at 12:33:27AM +0400, 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>
> > ---
> >  drivers/usb/core/hcd.c   | 20 ++++++++++++++++++++
> >  drivers/usb/host/Kconfig | 11 +++++++++++
> >  2 files changed, 31 insertions(+)
> > 
> > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> > index d939521..da9c4ba 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_HCD_EXTERNAL_PHY

I don't see any reason to add a new Kconfig symbol.  Just use "#ifdef 
USB_PHY" instead.

> I think here would be a nicer location for a flag:
> 
> if (hcd->has_external_phy) {
> 	phy = usb_get_phy_dev();
> 
> 	....
> }
> 
> that flag would get set by the glue driver (ehci-omap, ehci-msm,
> ohci-omap, etc), where necessary.

The problem Valentine is facing is that the glue driver doesn't know
whether or not to set the flag.  The way he set it up, the decision is
pushed down into usb_get_phy_dev, which ought to have enough
information.

Alan Stern

--
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. 6, 2013, 4:47 p.m. UTC | #3
On 11/06/2013 08:39 PM, Alan Stern wrote:
> On Wed, 6 Nov 2013, Felipe Balbi wrote:
>
>> Hi,
>>
>> On Wed, Nov 06, 2013 at 12:33:27AM +0400, 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>
>>> ---
>>>   drivers/usb/core/hcd.c   | 20 ++++++++++++++++++++
>>>   drivers/usb/host/Kconfig | 11 +++++++++++
>>>   2 files changed, 31 insertions(+)
>>>
>>> diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
>>> index d939521..da9c4ba 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_HCD_EXTERNAL_PHY
>
> I don't see any reason to add a new Kconfig symbol.  Just use "#ifdef
> USB_PHY" instead.

I just thought that most of the drivers would not need this code,
so I added a config option which can be enabled only if necessary.
I'll remove and use USB_PHY instead. Thanks.

>
>> I think here would be a nicer location for a flag:
>>
>> if (hcd->has_external_phy) {
>> 	phy = usb_get_phy_dev();
>>
>> 	....
>> }
>>
>> that flag would get set by the glue driver (ehci-omap, ehci-msm,
>> ohci-omap, etc), where necessary.
>
> The problem Valentine is facing is that the glue driver doesn't know
> whether or not to set the flag.  The way he set it up, the decision is
> pushed down into usb_get_phy_dev, which ought to have enough
> information.

Exactly.

>
> Alan Stern
>

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
Felipe Balbi Nov. 6, 2013, 5:05 p.m. UTC | #4
On Wed, Nov 06, 2013 at 08:47:36PM +0400, Valentine wrote:
> On 11/06/2013 08:39 PM, Alan Stern wrote:
> >On Wed, 6 Nov 2013, Felipe Balbi wrote:
> >
> >>Hi,
> >>
> >>On Wed, Nov 06, 2013 at 12:33:27AM +0400, 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>
> >>>---
> >>>  drivers/usb/core/hcd.c   | 20 ++++++++++++++++++++
> >>>  drivers/usb/host/Kconfig | 11 +++++++++++
> >>>  2 files changed, 31 insertions(+)
> >>>
> >>>diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> >>>index d939521..da9c4ba 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_HCD_EXTERNAL_PHY
> >
> >I don't see any reason to add a new Kconfig symbol.  Just use "#ifdef
> >USB_PHY" instead.
> 
> I just thought that most of the drivers would not need this code,
> so I added a config option which can be enabled only if necessary.
> I'll remove and use USB_PHY instead. Thanks.
> 
> >
> >>I think here would be a nicer location for a flag:
> >>
> >>if (hcd->has_external_phy) {
> >>	phy = usb_get_phy_dev();
> >>
> >>	....
> >>}
> >>
> >>that flag would get set by the glue driver (ehci-omap, ehci-msm,
> >>ohci-omap, etc), where necessary.
> >
> >The problem Valentine is facing is that the glue driver doesn't know
> >whether or not to set the flag.  The way he set it up, the decision is
> >pushed down into usb_get_phy_dev, which ought to have enough
> >information.
> 
> Exactly.

got it ;-)
diff mbox

Patch

diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index d939521..da9c4ba 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_HCD_EXTERNAL_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]. */
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index b3f20d7..2e1f2b0 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -706,3 +706,14 @@  config USB_HCD_TEST_MODE
 	  This option is of interest only to developers who need to validate
 	  their USB hardware designs.  It is not needed for normal use.  If
 	  unsure, say N.
+
+config USB_HCD_EXTERNAL_PHY
+	bool "Set up external USB phy bound to the USB HCD"
+	select USB_PHY
+	---help---
+	  Some USB host controllers require an external USB phy.
+	  This adds generic USB phy support to the USB HCD driver.
+	  When the HCD is being initialized, the HC driver searches
+	  for a USB phy, bound to the HCD. If no USB phy is bound
+	  to the HCD, the HCD is initialized as usual.
+	  If unsure, say N.