Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7764667ybi; Tue, 9 Jul 2019 04:03:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzqUGYRXz1CC6q4tfSoFMrgw1frYB6gtE+RvSYeO+u9Xdp5KolIE67+KxL2MnCvBAlpFjb2 X-Received: by 2002:a17:90a:22aa:: with SMTP id s39mr31893130pjc.39.1562670186408; Tue, 09 Jul 2019 04:03:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562670186; cv=none; d=google.com; s=arc-20160816; b=FDUtm2sVR4/q8dq4qy49RCZ3aPuw3CcSSmo9rB/DfO7PmZRoqvt/CE1V5yH4cR4zc1 WngSrsmTg6uhkBVzDT2b0uPzbgpy5qvIhOV9U/QN437PC9ghT7irX4qTcgPm4yjxZbpH Lx2QKCnkRE+QOP+TfqaIS46BJ68iYUKYUXvQ/jM0mKVAOZ9TgTUW6ZjSvLKOz+AA3BhU WiLIdSnKE8FsHsURNOQwxwHaAZ7cyClOQB40IYmY5sqDvxROaIU57sZz9MZdALdwnKo6 /YjblsO9r5cj4fEvdkWMQSLobpx7O+ZHJDmyMCuE2FUEbhAp6CZM+U1ezG2lcsnLTr9j NooA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=/UNfZLhuTWymTVesnT6RUKHdODJ3xcfzBH8AU09sJ90=; b=iZznQi8Mu/sj+8aREaPvlwHFdArar8AO0QsO/m0xiDU7jmFPAYERNZRFN3Dh+lgplr TQkBnU1S/paw5FdHd42nHzGvFUIpdP3n0WYhcE7bEAx4bRcr20MhLoTVpl61yfzsKU9E wBSGEml1+ULA0SrCe/B10a2YMI68CGuTDQFJFMqrrfkjbV1Ar8oq96nooR4eGRKACBO/ MjqNdqqiJ0hpQ8Vv7GHUok6+B/i53hCfkFFfgutbQ9ywDGjW1OBxfaxLp3aq1rm8BF/I zvd/sMiVnBSprs/xnAA2255/SqZ1uoJ15uzU4dgzO91LgXSehM8+/jYAKe5l4exhvKBZ OQIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y12si17726937pfg.260.2019.07.09.04.02.47; Tue, 09 Jul 2019 04:03:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726679AbfGIKuM (ORCPT + 99 others); Tue, 9 Jul 2019 06:50:12 -0400 Received: from mga02.intel.com ([134.134.136.20]:28940 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726628AbfGIKuL (ORCPT ); Tue, 9 Jul 2019 06:50:11 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jul 2019 03:50:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,470,1557212400"; d="scan'208";a="316996020" Received: from hu.sh.intel.com ([10.239.158.51]) by orsmga004.jf.intel.com with ESMTP; 09 Jul 2019 03:50:02 -0700 From: "Chen, Hu" To: hdegoede@redhat.com Cc: hu1.chen@intel.com, m.balaji@intel.com, Greg Kroah-Hartman , 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 Message-Id: <20190709103025.25761-1-hu1.chen@intel.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <8d304bb6-9849-ea77-3bd6-fe378de78ce7@redhat.com> References: <8d304bb6-9849-ea77-3bd6-fe378de78ce7@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Balaji --- 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 #include #include +#include /* 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