summaryrefslogtreecommitdiffstats
path: root/drivers/usb/phy
diff options
context:
space:
mode:
authorMaarten ter Huurne <maarten@treewalker.org>2016-02-28 16:34:16 +0100
committerFelipe Balbi <balbi@kernel.org>2016-03-04 15:14:47 +0200
commit2eafe93b92921308b624466b4c8a99bd1ace6e4f (patch)
treecdbe0aac33f1d5ac233a30def2d49bc89c3f22e2 /drivers/usb/phy
parentcff5638ef7852196879f9687e70d49ea291bbb33 (diff)
downloadlinux-2eafe93b92921308b624466b4c8a99bd1ace6e4f.tar.bz2
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: Maarten ter Huurne <maarten@treewalker.org> Signed-off-by: Felipe Balbi <balbi@kernel.org>
Diffstat (limited to 'drivers/usb/phy')
-rw-r--r--drivers/usb/phy/phy-generic.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 5320cb8642cb..980c9dee09eb 100644
--- a/drivers/usb/phy/phy-generic.c
+++ b/drivers/usb/phy/phy-generic.c
@@ -118,7 +118,8 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data)
status = USB_EVENT_VBUS;
otg->state = OTG_STATE_B_PERIPHERAL;
nop->phy.last_event = status;
- usb_gadget_vbus_connect(otg->gadget);
+ if (otg->gadget)
+ usb_gadget_vbus_connect(otg->gadget);
/* drawing a "unit load" is *always* OK, except for OTG */
nop_set_vbus_draw(nop, 100);
@@ -128,7 +129,8 @@ static irqreturn_t nop_gpio_vbus_thread(int irq, void *data)
} else {
nop_set_vbus_draw(nop, 0);
- usb_gadget_vbus_disconnect(otg->gadget);
+ if (otg->gadget)
+ usb_gadget_vbus_disconnect(otg->gadget);
status = USB_EVENT_NONE;
otg->state = OTG_STATE_B_IDLE;
nop->phy.last_event = status;
@@ -184,7 +186,10 @@ static int nop_set_peripheral(struct usb_otg *otg, struct usb_gadget *gadget)
}
otg->gadget = gadget;
- otg->state = OTG_STATE_B_IDLE;
+ if (otg->state == OTG_STATE_B_PERIPHERAL)
+ usb_gadget_vbus_connect(gadget);
+ else
+ otg->state = OTG_STATE_B_IDLE;
return 0;
}