All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yu Wang <yu1.wang@intel.com>
To: linux-usb@vger.kernel.org
Cc: hdegoede@redhat.com, heikki.krogerus@linux.intel.com,
	Yu Wang <yu1.wang@intel.com>
Subject: usb: roles: intel_xhci: Determine current role by DUAL_ROLE_CFG1
Date: Sat, 29 Sep 2018 22:26:20 +0800	[thread overview]
Message-ID: <1538231180-28569-1-git-send-email-yu1.wang@intel.com> (raw)

The USB PHY mux switch depend on both USB2/USB3 PHY state and xHCI/xDCI
controller state. The role can't be switched if related states haven't
satisfied. That is why we need to poll the DUAL_ROLE_CFG1 to check if
the role switched successful or not.

So the SW_IDPIN and SW_VBUS_VALID bits can't determine the current
acting role.

This patch changes the logic for getting role logic.

Signed-off-by: Yu Wang <yu1.wang@intel.com>
---
 drivers/usb/roles/intel-xhci-usb-role-switch.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/roles/intel-xhci-usb-role-switch.c b/drivers/usb/roles/intel-xhci-usb-role-switch.c
index 1fb3dd0..c118c9a 100644
--- a/drivers/usb/roles/intel-xhci-usb-role-switch.c
+++ b/drivers/usb/roles/intel-xhci-usb-role-switch.c
@@ -110,14 +110,18 @@ static enum usb_role intel_xhci_usb_get_role(struct device *dev)
 
 	pm_runtime_get_sync(dev);
 	val = readl(data->base + DUAL_ROLE_CFG0);
-	pm_runtime_put(dev);
 
-	if (!(val & SW_IDPIN))
-		role = USB_ROLE_HOST;
-	else if (val & SW_VBUS_VALID)
-		role = USB_ROLE_DEVICE;
-	else
+	if ((val & SW_IDPIN) && !(val & SW_VBUS_VALID))
 		role = USB_ROLE_NONE;
+	else {
+		val = readl(data->base + DUAL_ROLE_CFG1);
+		if (val & HOST_MODE)
+			role = USB_ROLE_HOST;
+		else
+			role = USB_ROLE_DEVICE;
+	}
+
+	pm_runtime_put(dev);
 
 	return role;
 }

             reply	other threads:[~2018-09-29 14:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-29 14:26 Yu Wang [this message]
2018-10-01 14:23 usb: roles: intel_xhci: Determine current role by DUAL_ROLE_CFG1 Hans de Goede
2018-10-01 15:15 Hans de Goede
2018-10-01 15:30 Heikki Krogerus
2018-10-10 14:20 Hans de Goede
2018-10-11  6:36 Heikki Krogerus

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=1538231180-28569-1-git-send-email-yu1.wang@intel.com \
    --to=yu1.wang@intel.com \
    --cc=hdegoede@redhat.com \
    --cc=heikki.krogerus@linux.intel.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.