This patch adds .vbus_session callback to usb_gadget_ops. VBUS session handling is necessary for OTG mode. VBUS control is performed during OTG finite-state machine state switching. Signed-off-by: Robert Baldyga <r.baldyga@xxxxxxxxxxx> --- drivers/usb/dwc3/core.h | 1 + drivers/usb/dwc3/gadget.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index fdab715..e00d46e 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -828,6 +828,7 @@ struct dwc3 { unsigned tx_de_emphasis_quirk:1; unsigned tx_de_emphasis:2; + unsigned vbus_session:1; }; /* -------------------------------------------------------------------------- */ diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 8946c32..80e43a6 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -1475,12 +1475,39 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) return 0; } +static int dwc3_gadget_vbus_session(struct usb_gadget *g, int is_active) +{ + struct dwc3 *dwc = gadget_to_dwc(g); + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&dwc->lock, flags); + + /* Mark that the vbus was powered */ + dwc->vbus_session = !!is_active; + + /* + * Check if upper level usb_gadget_driver was already registered with + * this udc controller driver (if dwc3_gadget_start was called) + */ + if (dwc->gadget_driver) + ret = dwc3_gadget_run_stop(dwc, dwc->vbus_session, false); + + spin_unlock_irqrestore(&dwc->lock, flags); + + return ret; +} + static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on) { struct dwc3 *dwc = gadget_to_dwc(g); unsigned long flags; int ret; + /* Need to wait for vbus_session(on) from otg driver */ + if (dwc->dotg && !dwc->vbus_session) + return 0; + is_on = !!is_on; spin_lock_irqsave(&dwc->lock, flags); @@ -1657,6 +1684,7 @@ static const struct usb_gadget_ops dwc3_gadget_ops = { .get_frame = dwc3_gadget_get_frame, .wakeup = dwc3_gadget_wakeup, .set_selfpowered = dwc3_gadget_set_selfpowered, + .vbus_session = dwc3_gadget_vbus_session, .pullup = dwc3_gadget_pullup, .udc_start = dwc3_gadget_start, .udc_stop = dwc3_gadget_stop, -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html