Skip to content

Commit

Permalink
usb: musb: call musb_start() only once in OTG mode
Browse files Browse the repository at this point in the history
In commit 001dd84 ("usb: musb: start musb on the udc side, too") it was
ensured that the state engine is started also in OTG mode after a
removal / insertion of the gadget.
Unfortunately this change also introduced a bug: If the device is
configured as OTG and it connected with a remote host _without_ loading
a gadget then we bug() later (because musb->otg->gadget is not
initialized).
Initially I assumed it might be nice to have the host part of musb in
OTG mode working without having a gadget loaded. This bug and fact that
it wasn't working like this before the host/gadget split made me realize
that this was a silly idea.
This patch now introduces back the old behavior where in OTG mode the
host mode is only working after the gadget has been loaded.

Cc: stable@vger.kernel.org # v3.11
Cc: Daniel Mack <zonque@gmail.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Felipe Balbi <balbi@ti.com>
  • Loading branch information
Sebastian Andrzej Siewior authored and Felipe Balbi committed Oct 17, 2013
1 parent 811f330 commit ae44df2
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion drivers/usb/musb/musb_virthub.c
Expand Up @@ -266,6 +266,23 @@ int musb_hub_status_data(struct usb_hcd *hcd, char *buf)
return retval;
}

static int musb_has_gadget(struct musb *musb)
{
/*
* In host-only mode we start a connection right away. In OTG mode
* we have to wait until we loaded a gadget. We don't really need a
* gadget if we operate as a host but we should not start a session
* as a device without a gadget or else we explode.
*/
#ifdef CONFIG_USB_MUSB_HOST
return 1;
#else
if (musb->port_mode == MUSB_PORT_MODE_HOST)
return 1;
return musb->g.dev.driver != NULL;
#endif
}

int musb_hub_control(
struct usb_hcd *hcd,
u16 typeReq,
Expand Down Expand Up @@ -408,7 +425,7 @@ int musb_hub_control(
* initialization logic, e.g. for OTG, or change any
* logic relating to VBUS power-up.
*/
if (!hcd->self.is_b_host)
if (!hcd->self.is_b_host && musb_has_gadget(musb))
musb_start(musb);
break;
case USB_PORT_FEAT_RESET:
Expand Down

0 comments on commit ae44df2

Please sign in to comment.