diff mbox series

usb: musb: Disable pullup in gadget setup

Message ID 20190404093743.6470-1-paul@crapouillou.net (mailing list archive)
State New, archived
Headers show
Series usb: musb: Disable pullup in gadget setup | expand

Commit Message

Paul Cercueil April 4, 2019, 9:37 a.m. UTC
The pullup may be already enabled before the driver is initialized.
It has to be disabled at init time, as we cannot guarantee that a gadget
driver will be bound to the UDC.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/usb/musb/musb_gadget.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Bin Liu April 4, 2019, 4:10 p.m. UTC | #1
On Thu, Apr 04, 2019 at 11:37:43AM +0200, Paul Cercueil wrote:
> The pullup may be already enabled before the driver is initialized.
> It has to be disabled at init time, as we cannot guarantee that a gadget
> driver will be bound to the UDC.
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  drivers/usb/musb/musb_gadget.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> index ffe462a657b1..094dc59c834c 100644
> --- a/drivers/usb/musb/musb_gadget.c
> +++ b/drivers/usb/musb/musb_gadget.c
> @@ -1794,6 +1794,7 @@ int musb_gadget_setup(struct musb *musb)
>  
>  	musb->is_active = 0;
>  	musb_platform_try_idle(musb, 0);
> +	musb_pullup(musb, 0);
>  
>  	status = usb_add_gadget_udc(musb->controller, &musb->g);
>  	if (status)

Applied.

Thanks,
-Bin.
Bin Liu April 30, 2019, 3:05 p.m. UTC | #2
Hi Paul,

On Thu, Apr 04, 2019 at 11:10:46AM -0500, Bin Liu wrote:
> On Thu, Apr 04, 2019 at 11:37:43AM +0200, Paul Cercueil wrote:
> > The pullup may be already enabled before the driver is initialized.
> > It has to be disabled at init time, as we cannot guarantee that a gadget
> > driver will be bound to the UDC.
> > 
> > Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> > ---
> >  drivers/usb/musb/musb_gadget.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> > index ffe462a657b1..094dc59c834c 100644
> > --- a/drivers/usb/musb/musb_gadget.c
> > +++ b/drivers/usb/musb/musb_gadget.c
> > @@ -1794,6 +1794,7 @@ int musb_gadget_setup(struct musb *musb)
> >  
> >  	musb->is_active = 0;
> >  	musb_platform_try_idle(musb, 0);
> > +	musb_pullup(musb, 0);
> >  
> >  	status = usb_add_gadget_udc(musb->controller, &musb->g);
> >  	if (status)
> 
> Applied.

Sorry, I have dropped this patch from my tree. I realized the gadget
core already defines callbacks to control the pullup. I think the
proper fix should be calling usb_udc_vbus_handler() in musb gadget or
glue layers.

-Bin.
Bin Liu April 30, 2019, 3:10 p.m. UTC | #3
On Tue, Apr 30, 2019 at 10:05:06AM -0500, Bin Liu wrote:
> Hi Paul,
> 
> On Thu, Apr 04, 2019 at 11:10:46AM -0500, Bin Liu wrote:
> > On Thu, Apr 04, 2019 at 11:37:43AM +0200, Paul Cercueil wrote:
> > > The pullup may be already enabled before the driver is initialized.
> > > It has to be disabled at init time, as we cannot guarantee that a gadget
> > > driver will be bound to the UDC.
> > > 
> > > Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> > > ---
> > >  drivers/usb/musb/musb_gadget.c | 1 +
> > >  1 file changed, 1 insertion(+)
> > > 
> > > diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> > > index ffe462a657b1..094dc59c834c 100644
> > > --- a/drivers/usb/musb/musb_gadget.c
> > > +++ b/drivers/usb/musb/musb_gadget.c
> > > @@ -1794,6 +1794,7 @@ int musb_gadget_setup(struct musb *musb)
> > >  
> > >  	musb->is_active = 0;
> > >  	musb_platform_try_idle(musb, 0);
> > > +	musb_pullup(musb, 0);
> > >  
> > >  	status = usb_add_gadget_udc(musb->controller, &musb->g);
> > >  	if (status)
> > 
> > Applied.
> 
> Sorry, I have dropped this patch from my tree. I realized the gadget
> core already defines callbacks to control the pullup. I think the
> proper fix should be calling usb_udc_vbus_handler() in musb gadget or
> glue layers.

Basically besides the problem your patch tries to fix, there is another
problem related to the pullup, which is enabled right after bind a
gadget driver, regardless of vbus status. This violates the USB Spec.
Implementing the udc core callbacks should fix both issues.

-Bin.
Paul Cercueil July 15, 2019, 6:05 a.m. UTC | #4
Hi Bin,


Le mar. 30 avril 2019 à 11:05, Bin Liu <b-liu@ti.com> a écrit :
> Hi Paul,
> 
> On Thu, Apr 04, 2019 at 11:10:46AM -0500, Bin Liu wrote:
>>  On Thu, Apr 04, 2019 at 11:37:43AM +0200, Paul Cercueil wrote:
>>  > The pullup may be already enabled before the driver is 
>> initialized.
>>  > It has to be disabled at init time, as we cannot guarantee that a 
>> gadget
>>  > driver will be bound to the UDC.
>>  >
>>  > Signed-off-by: Paul Cercueil <paul@crapouillou.net>
>>  > ---
>>  >  drivers/usb/musb/musb_gadget.c | 1 +
>>  >  1 file changed, 1 insertion(+)
>>  >
>>  > diff --git a/drivers/usb/musb/musb_gadget.c 
>> b/drivers/usb/musb/musb_gadget.c
>>  > index ffe462a657b1..094dc59c834c 100644
>>  > --- a/drivers/usb/musb/musb_gadget.c
>>  > +++ b/drivers/usb/musb/musb_gadget.c
>>  > @@ -1794,6 +1794,7 @@ int musb_gadget_setup(struct musb *musb)
>>  >
>>  >  	musb->is_active = 0;
>>  >  	musb_platform_try_idle(musb, 0);
>>  > +	musb_pullup(musb, 0);
>>  >
>>  >  	status = usb_add_gadget_udc(musb->controller, &musb->g);
>>  >  	if (status)
>> 
>>  Applied.
> 
> Sorry, I have dropped this patch from my tree. I realized the gadget
> core already defines callbacks to control the pullup. I think the
> proper fix should be calling usb_udc_vbus_handler() in musb gadget or
> glue layers.
> 
> -Bin.

usb_udc_vbus_handler() requires a usb_gadget *, I don't see where I can
get that from the struct musb.

Besides, the point is to have the pullup disabled before a gadget is 
bound,
so I don't understand why you suggest that?

-Paul
diff mbox series

Patch

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index ffe462a657b1..094dc59c834c 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1794,6 +1794,7 @@  int musb_gadget_setup(struct musb *musb)
 
 	musb->is_active = 0;
 	musb_platform_try_idle(musb, 0);
+	musb_pullup(musb, 0);
 
 	status = usb_add_gadget_udc(musb->controller, &musb->g);
 	if (status)