Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1345320 > unrolled thread

[PATCH] usb: phy: generic: Handle late registration of gadget

Started byMaarten ter Huurne <maarten@treewalker.org>
First post2016-02-28 16:40 +0100
Last post2016-03-01 12:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] usb: phy: generic: Handle late registration of gadget Maarten ter Huurne <maarten@treewalker.org> - 2016-02-28 16:40 +0100
    Re: [PATCH] usb: phy: generic: Handle late registration of gadget Felipe Balbi <balbi@kernel.org> - 2016-03-01 12:50 +0100

#1345320 — [PATCH] usb: phy: generic: Handle late registration of gadget

FromMaarten ter Huurne <maarten@treewalker.org>
Date2016-02-28 16:40 +0100
Subject[PATCH] usb: phy: generic: Handle late registration of gadget
Message-ID<r7bBT-4yM-1@gated-at.bofh.it>
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>
---
 drivers/usb/phy/phy-generic.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-generic.c b/drivers/usb/phy/phy-generic.c
index 5320cb8..980c9de 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;
 }
 
-- 
2.6.2

[toc] | [next] | [standalone]


#1346544

FromFelipe Balbi <balbi@kernel.org>
Date2016-03-01 12:50 +0100
Message-ID<r7QYp-af-3@gated-at.bofh.it>
In reply to#1345320

[Multipart message — attachments visible in raw view] — view raw

Hi,

Maarten ter Huurne <maarten@treewalker.org> writes:
> 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>

wonder if it would be best to guarantee this doesn't happen in the first
place, but I guess that would be too complex anyhow. I'll apply this as
is for now.

-- 
balbi

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web