linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Chen, Hu" <hu1.chen@intel.com>
To: hdegoede@redhat.com
Cc: hu1.chen@intel.com, m.balaji@intel.com,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] usb: roles: Add PM callbacks
Date: Tue,  9 Jul 2019 18:30:25 +0800	[thread overview]
Message-ID: <20190709103025.25761-1-hu1.chen@intel.com> (raw)
In-Reply-To: <8d304bb6-9849-ea77-3bd6-fe378de78ce7@redhat.com>

On some Broxton NUC, the usb role is lost after S3 (it becomes "none").
Add PM callbacks to address this. In .suspend, save the role. In
.resume, restore usb role to saved one if it's lost.

Tests:
Run Android on UC6CAY, a NUC powered by Broxton. The usb port near to
the power button is switchable.
- as device. Access the NUC via "adb shell" from a host PC. Adb works
after S3 cycle.
- as host. Mouse works on that usb port after S3 cycle.

Without this fix, both of tests fails.

Signed-off-by: Chen, Hu <hu1.chen@intel.com>
Signed-off-by: Balaji <m.balaji@intel.com>
---
v2: The role maybe changed by ISR or firmware etc. between .suspend and
.resume (Hans).
 .../usb/roles/intel-xhci-usb-role-switch.c    | 27 +++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/drivers/usb/roles/intel-xhci-usb-role-switch.c b/drivers/usb/roles/intel-xhci-usb-role-switch.c
index 277de96181f9..e830299c401e 100644
--- a/drivers/usb/roles/intel-xhci-usb-role-switch.c
+++ b/drivers/usb/roles/intel-xhci-usb-role-switch.c
@@ -20,6 +20,7 @@
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/usb/role.h>
+#include <linux/power_supply.h>
 
 /* register definition */
 #define DUAL_ROLE_CFG0			0x68
@@ -37,6 +38,7 @@
 struct intel_xhci_usb_data {
 	struct usb_role_switch *role_sw;
 	void __iomem *base;
+	enum usb_role role;
 };
 
 static int intel_xhci_usb_set_role(struct device *dev, enum usb_role role)
@@ -167,6 +169,29 @@ static int intel_xhci_usb_remove(struct platform_device *pdev)
 	return 0;
 }
 
+static int intel_xhci_usb_suspend(struct platform_device *pdev,
+				  pm_message_t state)
+{
+	struct intel_xhci_usb_data *data = platform_get_drvdata(pdev);
+	struct device *dev = &pdev->dev;
+
+	data->role = intel_xhci_usb_get_role(dev);
+
+	return 0;
+}
+
+static int intel_xhci_usb_resume(struct platform_device *pdev)
+{
+	struct intel_xhci_usb_data *data = platform_get_drvdata(pdev);
+	struct device *dev = &pdev->dev;
+
+	if (intel_xhci_usb_get_role(dev) == USB_ROLE_NONE &&
+	    power_supply_is_system_supplied())
+		intel_xhci_usb_set_role(dev, data->role);
+
+	return 0;
+}
+
 static const struct platform_device_id intel_xhci_usb_table[] = {
 	{ .name = DRV_NAME },
 	{}
@@ -180,6 +205,8 @@ static struct platform_driver intel_xhci_usb_driver = {
 	.id_table = intel_xhci_usb_table,
 	.probe = intel_xhci_usb_probe,
 	.remove = intel_xhci_usb_remove,
+	.suspend = intel_xhci_usb_suspend,
+	.resume = intel_xhci_usb_resume,
 };
 
 module_platform_driver(intel_xhci_usb_driver);
-- 
2.22.0


      reply	other threads:[~2019-07-09 10:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-08  2:25 [PATCH] usb: roles: Add PM callbacks Chen, Hu
2019-07-08  8:30 ` Sergei Shtylyov
2019-07-08 14:10 ` Hans de Goede
2019-07-09 10:30   ` Chen, Hu [this message]

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=20190709103025.25761-1-hu1.chen@intel.com \
    --to=hu1.chen@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hdegoede@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.balaji@intel.com \
    /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).