linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Herrenschmidt <benh@kernel.crashing.org>
To: linux-usb@vger.kernel.org
Cc: balbi@kernel.org, Joel Stanley <joel@jms.id.au>,
	Alan Stern <stern@rowland.harvard.edu>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>
Subject: [PATCH 07/10] usb: gadget: aspeed: Rework the reset logic
Date: Sat,  6 Jul 2019 10:53:42 +1000	[thread overview]
Message-ID: <20190706005345.18131-8-benh@kernel.crashing.org> (raw)
In-Reply-To: <20190706005345.18131-1-benh@kernel.crashing.org>

We had some dodgy code using the speed setting to decide whether a
port reset would reset the device or just enable it.

Instead, if the device is disabled and has a gadget attached, a
reset will enable it. If it's already enabled, a reset will
reset it.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---
 drivers/usb/gadget/udc/aspeed-vhub/dev.c | 58 +++++++++++-------------
 1 file changed, 27 insertions(+), 31 deletions(-)

diff --git a/drivers/usb/gadget/udc/aspeed-vhub/dev.c b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
index 5f7e3b6de531..79d3cb6bd2e7 100644
--- a/drivers/usb/gadget/udc/aspeed-vhub/dev.c
+++ b/drivers/usb/gadget/udc/aspeed-vhub/dev.c
@@ -50,7 +50,7 @@ void ast_vhub_dev_irq(struct ast_vhub_dev *d)
 
 static void ast_vhub_dev_enable(struct ast_vhub_dev *d)
 {
-	u32 reg, hmsk;
+	u32 reg, hmsk, i;
 
 	if (d->enabled)
 		return;
@@ -76,6 +76,20 @@ static void ast_vhub_dev_enable(struct ast_vhub_dev *d)
 	/* Set EP0 DMA buffer address */
 	writel(d->ep0.buf_dma, d->regs + AST_VHUB_DEV_EP0_DATA);
 
+	/* Clear stall on all EPs */
+	for (i = 0; i < AST_VHUB_NUM_GEN_EPs; i++) {
+		struct ast_vhub_ep *ep = d->epns[i];
+
+		if (ep && (ep->epn.stalled || ep->epn.wedged)) {
+			ep->epn.stalled = false;
+			ep->epn.wedged = false;
+			ast_vhub_update_epn_stall(ep);
+		}
+	}
+
+	/* Additional cleanups */
+	d->wakeup_en = false;
+	d->suspended = false;
 	d->enabled = true;
 }
 
@@ -477,46 +491,28 @@ void ast_vhub_dev_resume(struct ast_vhub_dev *d)
 
 void ast_vhub_dev_reset(struct ast_vhub_dev *d)
 {
-	/*
-	 * If speed is not set, we enable the port. If it is,
-	 * send reset to the gadget and reset "speed".
-	 *
-	 * Speed is an indication that we have got the first
-	 * setup packet to the device.
-	 */
-	if (d->gadget.speed == USB_SPEED_UNKNOWN && !d->enabled) {
-		DDBG(d, "Reset at unknown speed of disabled device, enabling...\n");
-		ast_vhub_dev_enable(d);
-		d->suspended = false;
+	/* No driver, just disable the device and return */
+	if (!d->driver) {
+		ast_vhub_dev_disable(d);
+		return;
 	}
-	if (d->gadget.speed != USB_SPEED_UNKNOWN && d->driver) {
-		unsigned int i;
 
-		DDBG(d, "Reset at known speed of bound device, resetting...\n");
+	/* If the port isn't enabled, just enable it */
+	if (!d->enabled) {
+		DDBG(d, "Reset of disabled device, enabling...\n");
+		ast_vhub_dev_enable(d);
+	} else {
+		DDBG(d, "Reset of enabled device, resetting...\n");
 		spin_unlock(&d->vhub->lock);
-		d->driver->reset(&d->gadget);
+		usb_gadget_udc_reset(&d->gadget, d->driver);
 		spin_lock(&d->vhub->lock);
 
 		/*
-		 * Disable/re-enable HW, this will clear the address
+		 * Disable and maybe re-enable HW, this will clear the address
 		 * and speed setting.
 		 */
 		ast_vhub_dev_disable(d);
 		ast_vhub_dev_enable(d);
-
-		/* Clear stall on all EPs */
-		for (i = 0; i < AST_VHUB_NUM_GEN_EPs; i++) {
-			struct ast_vhub_ep *ep = d->epns[i];
-
-			if (ep && ep->epn.stalled) {
-				ep->epn.stalled = false;
-				ast_vhub_update_epn_stall(ep);
-			}
-		}
-
-		/* Additional cleanups */
-		d->wakeup_en = false;
-		d->suspended = false;
 	}
 }
 
-- 
2.17.1


  parent reply	other threads:[~2019-07-06  0:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-06  0:53 [PATCH 00/10] usb: gadget: aspeed: Bug fixes Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 01/10] usb: gadget: aspeed: Don't set port enable change bit on reset Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 02/10] usb: gadget: aspeed: Cleanup EP0 state on port reset Benjamin Herrenschmidt
2019-07-06  8:11   ` Sergei Shtylyov
2019-07-06 12:34     ` Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 03/10] usb: gadget: aspeed: Fix EP0 stall handling Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 04/10] usb: gadget: aspeed: Improve debugging when nuking Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 05/10] usb: gadget: aspeed: Don't reject requests on suspended devices Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 06/10] usb: gadget: aspeed: Check suspend/resume callback existence Benjamin Herrenschmidt
2019-07-06  0:53 ` Benjamin Herrenschmidt [this message]
2019-07-06  0:53 ` [PATCH 08/10] usb: gadget: aspeed: Remove unused "suspended" flag Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 09/10] usb: Add definitions for the USB2.0 hub TT requests Benjamin Herrenschmidt
2019-07-06  0:53 ` [PATCH 10/10] usb: gadget: aspeed: Implement dummy " Benjamin Herrenschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190706005345.18131-8-benh@kernel.crashing.org \
    --to=benh@kernel.crashing.org \
    --cc=balbi@kernel.org \
    --cc=joel@jms.id.au \
    --cc=linux-usb@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).