Linux USB
 help / color / mirror / Atom feed
From: Sven Peter <sven@svenpeter.dev>
To: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Sven Peter <sven@svenpeter.dev>,
	Felipe Balbi <felipe.balbi@linux.intel.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] usb: dwc3: core: configure PHY before initializing host in dwc3_set_mode
Date: Sat, 12 Nov 2022 11:25:06 +0100	[thread overview]
Message-ID: <20221112102506.34990-1-sven@svenpeter.dev> (raw)

Usually, first the PHY is set to the correct mode and then the host or
device side of the controller is initialized afterwards. Otherwise a PHY
that's already used has to be reconfigured.
dwc3_core_init_mode() does this correctly for both host and device and
__dwc3_set_mode() does it correctly when switching to device mode.
When setting up host mode however it first initializes xhci and only
then changes the PHY's mode. Let's also do the operations in the correct
order here.

Fixes: 958d1a4c40dd ("usb: dwc3: core: program PHY for proper DRD modes")
Signed-off-by: Sven Peter <sven@svenpeter.dev>
---
 drivers/usb/dwc3/core.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index ad4d644e21a4..759d23d908fa 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -212,14 +212,15 @@ static void __dwc3_set_mode(struct work_struct *work)
 
 	switch (dwc->desired_dr_role) {
 	case DWC3_GCTL_PRTCAP_HOST:
+		if (dwc->usb2_phy)
+			otg_set_vbus(dwc->usb2_phy->otg, true);
+		phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
+		phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
+
 		ret = dwc3_host_init(dwc);
 		if (ret) {
 			dev_err(dwc->dev, "failed to initialize host\n");
 		} else {
-			if (dwc->usb2_phy)
-				otg_set_vbus(dwc->usb2_phy->otg, true);
-			phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
-			phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
 			if (dwc->dis_split_quirk) {
 				reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
 				reg |= DWC3_GUCTL3_SPLITDISABLE;
-- 
2.25.1


             reply	other threads:[~2022-11-12 10:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-12 10:25 Sven Peter [this message]
2022-11-12 22:15 ` [PATCH] usb: dwc3: core: configure PHY before initializing host in dwc3_set_mode Ferry Toth
2022-11-12 22:46   ` Sven Peter
2022-11-12 23:07     ` Ferry Toth
2022-11-12 23:11       ` Sven Peter

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=20221112102506.34990-1-sven@svenpeter.dev \
    --to=sven@svenpeter.dev \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=felipe.balbi@linux.intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.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