Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6154792ybi; Sun, 7 Jul 2019 21:44:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwHKtNcP+rTLVQt85R46EI7PNY+RtW+eovYyWbxsWN8IgAqzwHWm1YXCqpBjxVDDEYuF67W X-Received: by 2002:a65:4045:: with SMTP id h5mr21595068pgp.247.1562561061356; Sun, 07 Jul 2019 21:44:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562561061; cv=none; d=google.com; s=arc-20160816; b=sh6Nz4ffbcrGNDfJ/vbwZ164oOCRJHgZsJwAm9pDjB54QI+++AErdnwEQDdv/12mwF qoeYVVy/ibmAIqfHN2v99IQRpO+/nKNOKpGUmgT9H1Yf0cxhjvCCG0gL9M0JAzUDsjCH juQQDS4fv7KEBpSMbqLIiTJMeuQBr1+EAgZncDAObQe1LDVRUXBtyUBUf9Y/OVoG28w5 w2KZps1g6Nkh2hoY27t5/YcPXcUM25/Rh7xJKfi30Y/QHKG7c5WgaxALkzDYbfOst9CR y138EfFbzoPGzBcXb7r3u5Wc5E6FfcT7fMMt5yZf6MPZ1/j/0S5AZUgnV5EAQE9D2xYJ WGzw== 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 :message-id:date:subject:cc:to:from; bh=+RLR4pyxcfX62JdTX84LqE4KSfbPAW43FiBuTeZ4bBQ=; b=tOlLVRiK0NtMVIkGe+8eXwdk9rzNPriS/0nGVw/ZesTdNU4YynlpJ7FlGEUD6lyjLA kz+2eE5QOd6tmjbLENSGUrtp61Howc6Servtk9iPsQvzhKTdirbD5S3Dhf/UZEmzifYG M8MOBtH72X2uC247VPOH9p5R6C96Xh0s/KeNi2Ne6MA0yfp+Szjq6qK/Bd4dH5VmmoMu R+g7UN92nvj/5qzwQw9MtTYOGRitWQ8v3PiEtsamO5vNj50hQXpqRGwPutNpzdglZ3h4 IL/ohNbO0RdjMuEvXSfPUyVHiVM23fkKzIiiILot8SEd49jWO7ksc0VuxTaWtJi9Pnfy nMMA== 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 f9si17247534pgc.510.2019.07.07.21.44.06; Sun, 07 Jul 2019 21:44:21 -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 S1727697AbfGHCov (ORCPT + 99 others); Sun, 7 Jul 2019 22:44:51 -0400 Received: from mga04.intel.com ([192.55.52.120]:3515 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726105AbfGHCov (ORCPT ); Sun, 7 Jul 2019 22:44:51 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Jul 2019 19:44:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,465,1557212400"; d="scan'208";a="340322921" Received: from hu.sh.intel.com ([10.239.158.51]) by orsmga005.jf.intel.com with ESMTP; 07 Jul 2019 19:44:49 -0700 From: "Chen, Hu" To: hdegoede@redhat.com Cc: hu1.chen@intel.com, Balaji , Greg Kroah-Hartman , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] usb: roles: Add PM callbacks Date: Mon, 8 Jul 2019 10:25:14 +0800 Message-Id: <20190708022514.7161-1-hu1.chen@intel.com> X-Mailer: git-send-email 2.22.0 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 issue: save the role during suspend and restore usb to that role during resume. Test: Run Android on UC6CAY, a NUC powered by Broxton. Access this NUC via "adb shell" from a host PC. After a suspend/resume cycle, the adb still works well. Signed-off-by: Chen, Hu Signed-off-by: Balaji diff --git a/drivers/usb/roles/intel-xhci-usb-role-switch.c b/drivers/usb/roles/intel-xhci-usb-role-switch.c index 277de96181f9..caa1cfab41cc 100644 --- a/drivers/usb/roles/intel-xhci-usb-role-switch.c +++ b/drivers/usb/roles/intel-xhci-usb-role-switch.c @@ -37,6 +37,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 +168,30 @@ 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) != data->role) { + if (intel_xhci_usb_set_role(dev, data->role) != 0) + dev_warn(dev, "Failed to set role during resume\n"); + } + + 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