@@ -4683,6 +4683,52 @@ static int dwc2_hsotg_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
return usb_phy_set_power(hsotg->uphy, mA);
}
+/**
+ * dwc2_hsotg_wakeup - send wakeup signal to the host
+ * @gadget: The usb gadget state
+ *
+ * If the gadget is in device mode and in the L1 or L2 state,
+ * it sends a wakeup signal to the host.
+ */
+static int dwc2_hsotg_wakeup(struct usb_gadget *gadget)
+{
+ struct dwc2_hsotg *hsotg = to_hsotg(gadget);
+ int ret = -1;
+ unsigned long flags;
+
+ spin_lock_irqsave(&hsotg->lock, flags);
+
+ if (!hsotg->remote_wakeup_allowed) {
+ dev_dbg(hsotg->dev,
+ "wakeup signalling skipped: is not allowed by host\n");
+ goto skip;
+ }
+ if (hsotg->lx_state != DWC2_L1 && hsotg->lx_state != DWC2_L2) {
+ dev_dbg(hsotg->dev,
+ "wakeup signalling skipped: gadget not in L1/L2 state\n");
+ goto skip;
+ }
+ if (!dwc2_is_device_mode(hsotg)) {
+ dev_dbg(hsotg->dev,
+ "wakeup signalling skipped: gadget not in device mode\n");
+ goto skip;
+ }
+
+ dev_dbg(hsotg->dev, "sending wakeup signal to the host");
+
+ dwc2_set_bit(hsotg, DCTL, DCTL_RMTWKUPSIG);
+ mdelay(10);
+ dwc2_clear_bit(hsotg, DCTL, DCTL_RMTWKUPSIG);
+
+ /* After the signalling, the USB core wakes up to L0 */
+ hsotg->lx_state = DWC2_L0;
+
+ ret = 0;
+skip:
+ spin_unlock_irqrestore(&hsotg->lock, flags);
+ return ret;
+}
+
static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = {
.get_frame = dwc2_hsotg_gadget_getframe,
.set_selfpowered = dwc2_hsotg_set_selfpowered,
@@ -4691,6 +4737,7 @@ static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = {
.pullup = dwc2_hsotg_pullup,
.vbus_session = dwc2_hsotg_vbus_session,
.vbus_draw = dwc2_hsotg_vbus_draw,
+ .wakeup = dwc2_hsotg_wakeup,
};
/**