stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sam Protsenko <semen.protsenko@linaro.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org, Wesley Cheng <wcheng@codeaurora.org>
Subject: [PATCH 5.4 2/7] usb: dwc3: gadget: Allow runtime suspend if UDC unbinded
Date: Thu, 12 Aug 2021 20:16:47 +0300	[thread overview]
Message-ID: <20210812171652.23803-3-semen.protsenko@linaro.org> (raw)
In-Reply-To: <20210812171652.23803-1-semen.protsenko@linaro.org>

From: Wesley Cheng <wcheng@codeaurora.org>

[ Upstream commit 77adb8bdf4227257e26b7ff67272678e66a0b250 ]

The DWC3 runtime suspend routine checks for the USB connected parameter to
determine if the controller can enter into a low power state.  The
connected state is only set to false after receiving a disconnect event.
However, in the case of a device initiated disconnect (i.e. UDC unbind),
the controller is halted and a disconnect event is never generated.  Set
the connected flag to false if issuing a device initiated disconnect to
allow the controller to be suspended.

Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Link: https://lore.kernel.org/r/1609283136-22140-2-git-send-email-wcheng@codeaurora.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/dwc3/gadget.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 94c430dcce5d..bc655d637b86 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -2017,6 +2017,17 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 		}
 	}
 
+	/*
+	 * Check the return value for successful resume, or error.  For a
+	 * successful resume, the DWC3 runtime PM resume routine will handle
+	 * the run stop sequence, so avoid duplicate operations here.
+	 */
+	ret = pm_runtime_get_sync(dwc->dev);
+	if (!ret || ret < 0) {
+		pm_runtime_put(dwc->dev);
+		return 0;
+	}
+
 	/*
 	 * Synchronize any pending event handling before executing the controller
 	 * halt routine.
@@ -2055,10 +2066,12 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
 			dwc->ev_buf->lpos = (dwc->ev_buf->lpos + count) %
 						dwc->ev_buf->length;
 		}
+		dwc->connected = false;
 	}
 
 	ret = dwc3_gadget_run_stop(dwc, is_on, false);
 	spin_unlock_irqrestore(&dwc->lock, flags);
+	pm_runtime_put(dwc->dev);
 
 	return ret;
 }
-- 
2.30.2


  parent reply	other threads:[~2021-08-12 17:17 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 17:16 [PATCH 5.4 0/7] usb: dwc3: Fix DRD role switch Sam Protsenko
2021-08-12 17:16 ` [PATCH 5.4 1/7] usb: dwc3: Stop active transfers before halting the controller Sam Protsenko
2021-08-12 17:16 ` Sam Protsenko [this message]
2021-08-12 17:16 ` [PATCH 5.4 3/7] usb: dwc3: gadget: Restart DWC3 gadget when enabling pullup Sam Protsenko
2021-08-12 17:16 ` [PATCH 5.4 4/7] usb: dwc3: gadget: Prevent EP queuing while stopping transfers Sam Protsenko
2021-08-12 17:16 ` [PATCH 5.4 5/7] usb: dwc3: gadget: Clear DEP flags after stop transfers in ep disable Sam Protsenko
2021-08-12 17:16 ` [PATCH 5.4 6/7] usb: dwc3: gadget: Disable gadget IRQ during pullup disable Sam Protsenko
2021-08-12 17:16 ` [PATCH 5.4 7/7] usb: dwc3: gadget: Avoid runtime resume if disabling pullup Sam Protsenko
2021-08-13  8:49 ` [PATCH 5.4 0/7] usb: dwc3: Fix DRD role switch Greg Kroah-Hartman

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=20210812171652.23803-3-semen.protsenko@linaro.org \
    --to=semen.protsenko@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    --cc=wcheng@codeaurora.org \
    /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).