[RFC 05/19] dwc3: gadget: enable/disable ep0 in dwc3_gadget_run_stop()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch adds ep0 enabling and disabling in dwc3_gadget_run_stop().
It's because this function now it used not only for pullup but also
for VBUS session control - feature used by OTG code during role switching.
In case of role switching ep0 have to be reinitialized, so doing it inside
dwc3_gadget_run_stop() function seems to be simplest solution.

This change allowed also to remove ep0 enable/disable code from
suspend/resume functions as this operation is already done by
dwc3_gadget_run_stop(), which is also called there.

Signed-off-by: Robert Baldyga <r.baldyga@xxxxxxxxxxx>
---
 drivers/usb/dwc3/gadget.c | 56 +++++++++++++++++++++++------------------------
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 80e43a6..4e73934 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1421,13 +1421,38 @@ static int dwc3_gadget_set_selfpowered(struct usb_gadget *g,
 	return 0;
 }
 
+static void dwc3_gadget_enable_irq(struct dwc3 *dwc);
+static void dwc3_gadget_disable_irq(struct dwc3 *dwc);
+
 static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 {
 	u32			reg;
 	u32			timeout = 500;
+	int			ret;
 
 	reg = dwc3_readl(dwc->regs, DWC3_DCTL);
 	if (is_on) {
+		ret = __dwc3_gadget_ep_enable(dwc->eps[0],
+			&dwc3_gadget_ep0_desc, NULL, false, false);
+		if (ret) {
+			dev_err(dwc->dev, "failed to enable %s\n",
+				dwc->eps[0]->name);
+			return ret;
+		}
+
+		ret = __dwc3_gadget_ep_enable(dwc->eps[1],
+			&dwc3_gadget_ep0_desc, NULL, false, false);
+		if (ret) {
+			dev_err(dwc->dev, "failed to enable %s\n",
+				dwc->eps[1]->name);
+			__dwc3_gadget_ep_disable(dwc->eps[0]);
+			return ret;
+		}
+
+		/* begin to receive SETUP packets */
+		dwc->ep0state = EP0_SETUP_PHASE;
+		dwc3_ep0_out_start(dwc);
+
 		if (dwc->revision <= DWC3_REVISION_187A) {
 			reg &= ~DWC3_DCTL_TRGTULST_MASK;
 			reg |= DWC3_DCTL_TRGTULST_RX_DET;
@@ -1442,6 +1467,9 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend)
 
 		dwc->pullups_connected = true;
 	} else {
+		__dwc3_gadget_ep_disable(dwc->eps[0]);
+		__dwc3_gadget_ep_disable(dwc->eps[1]);
+
 		reg &= ~DWC3_DCTL_RUN_STOP;
 
 		if (dwc->has_hibernation && !suspend)
@@ -2804,9 +2832,6 @@ int dwc3_gadget_suspend(struct dwc3 *dwc)
 		dwc3_gadget_run_stop(dwc, true, true);
 	}
 
-	__dwc3_gadget_ep_disable(dwc->eps[0]);
-	__dwc3_gadget_ep_disable(dwc->eps[1]);
-
 	dwc->dcfg = dwc3_readl(dwc->regs, DWC3_DCFG);
 
 	return 0;
@@ -2814,28 +2839,9 @@ int dwc3_gadget_suspend(struct dwc3 *dwc)
 
 int dwc3_gadget_resume(struct dwc3 *dwc)
 {
-	struct dwc3_ep		*dep;
-	int			ret;
-
 	/* Start with SuperSpeed Default */
 	dwc3_gadget_ep0_desc.wMaxPacketSize = cpu_to_le16(512);
 
-	dep = dwc->eps[0];
-	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
-			false);
-	if (ret)
-		goto err0;
-
-	dep = dwc->eps[1];
-	ret = __dwc3_gadget_ep_enable(dep, &dwc3_gadget_ep0_desc, NULL, false,
-			false);
-	if (ret)
-		goto err1;
-
-	/* begin to receive SETUP packets */
-	dwc->ep0state = EP0_SETUP_PHASE;
-	dwc3_ep0_out_start(dwc);
-
 	dwc3_writel(dwc->regs, DWC3_DCFG, dwc->dcfg);
 
 	if (dwc->pullups_connected) {
@@ -2844,10 +2850,4 @@ int dwc3_gadget_resume(struct dwc3 *dwc)
 	}
 
 	return 0;
-
-err1:
-	__dwc3_gadget_ep_disable(dwc->eps[0]);
-
-err0:
-	return ret;
 }
-- 
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




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux