Commit 2eafe93b authored by Maarten ter Huurne's avatar Maarten ter Huurne Committed by Felipe Balbi

usb: phy: generic: Handle late registration of gadget

It is possible for the VBUS detect GPIO interrupt to occur before
nop_set_peripheral() is called, in which case otg->gadget is NULL.
Signed-off-by: default avatarMaarten ter Huurne <maarten@treewalker.org>
Signed-off-by: default avatarFelipe Balbi <balbi@kernel.org>
parent cff5638e
...@@ -118,6 +118,7 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data) ...@@ -118,6 +118,7 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data)
status = USB_EVENT_VBUS; status = USB_EVENT_VBUS;
otg->state = OTG_STATE_B_PERIPHERAL; otg->state = OTG_STATE_B_PERIPHERAL;
nop->phy.last_event = status; nop->phy.last_event = status;
if (otg->gadget)
usb_gadget_vbus_connect(otg->gadget); usb_gadget_vbus_connect(otg->gadget);
/* drawing a "unit load" is *always* OK, except for OTG */ /* drawing a "unit load" is *always* OK, except for OTG */
...@@ -128,6 +129,7 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data) ...@@ -128,6 +129,7 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data)
} else { } else {
nop_set_vbus_draw(nop, 0); nop_set_vbus_draw(nop, 0);
if (otg->gadget)
usb_gadget_vbus_disconnect(otg->gadget); usb_gadget_vbus_disconnect(otg->gadget);
status = USB_EVENT_NONE; status = USB_EVENT_NONE;
otg->state = OTG_STATE_B_IDLE; otg->state = OTG_STATE_B_IDLE;
...@@ -184,6 +186,9 @@ static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget) ...@@ -184,6 +186,9 @@ static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
} }
otg->gadget = gadget; otg->gadget = gadget;
if (otg->state == OTG_STATE_B_PERIPHERAL)
usb_gadget_vbus_connect(gadget);
else
otg->state = OTG_STATE_B_IDLE; otg->state = OTG_STATE_B_IDLE;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment