From patchwork Fri Jul 21 06:58:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 108457 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp452268qge; Thu, 20 Jul 2017 23:59:17 -0700 (PDT) X-Received: by 10.99.36.198 with SMTP id k189mr6393823pgk.230.1500620357492; Thu, 20 Jul 2017 23:59:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500620357; cv=none; d=google.com; s=arc-20160816; b=vqHlNUKQYPgRSmD75oAkiEZU1uXNiB6SDJ5zRHlxMoXYB/Wk2K5ShLcqm2lqU+LQ15 C0K66sFR2x0p9C6K/z61YBpEI3gPPcGlWHKAYa2kWYLOONTHQlC8L9t3QnBofB3xhPUd JhBY2Y5ch3bRzBto9m9UpOnThfuCqL+0/UKKlFIYlnW3W6BqLxL3Gy6Amz+7WgLtFBtY AK0ikupzFQWiX5HHMGWx/HYfSfIGc+lv917gCy7vLdQ+vxGu/qZ9UEksEXWFQdlL8Adw kjVOk8jtvFOKOGhbQwXAEXe3Cmrd64AyywIReQZiBzhuHuFarxAeuitE29tk0WSQ/RTv +KtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=xSB3kQz/GNPZLbpSAQ7534U+TwErs9Cet86L2jyJWIA=; b=ta1c0OVN7qU/qYEy2BBZOcI1NU/8bjdandjPK3JPIDFCrQqUsXnHjFcNt/lIYUkaOR LA0taSKKTZev+liqX3axxO4qa+uYfXcBlbgonBlVYoFoXNfiNS5RmfmMaeWpbo8kAxtD N6/d0SF9kiTkG9q5B5n1+I78xho5GdBB/+wwRIVcJmVc0o+2b3nZhKPaATyE9gs65Inl Gl/FwAFWesPjimmo1BsjoIFGxHg1QNlvenh3nntQrEsZXREPsZDAnY82vitlnvPNM2rb jxFjDsnZNNDfSvY6Ons7UJ0YYLhRjVcwdOq/ja0l/NSftKdYcUQ5f3gtWP1BW3Z2zVVx G/2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=fEs57G24; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si1208910plb.96.2017.07.20.23.59.17; Thu, 20 Jul 2017 23:59:17 -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; dkim=pass header.i=@linaro.org header.b=fEs57G24; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753317AbdGUG7P (ORCPT + 25 others); Fri, 21 Jul 2017 02:59:15 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:32939 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751611AbdGUG7M (ORCPT ); Fri, 21 Jul 2017 02:59:12 -0400 Received: by mail-pg0-f41.google.com with SMTP id k14so25053646pgr.0 for ; Thu, 20 Jul 2017 23:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=xSB3kQz/GNPZLbpSAQ7534U+TwErs9Cet86L2jyJWIA=; b=fEs57G24SI1aFKlPfv4J+71nOcUQYeP299kY7T1YKD1/BN17+RUWkcAESTgOBG5oB6 wlyTb78e3qU31GaZ6DxRyf5kIROklY1iWs73VrEoqWqUlJ1+7WsE1RkLE8EVj77aJeGh 94GbhznrHpHKub1VVRAdzGKUxyrcNnn3SORkw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=xSB3kQz/GNPZLbpSAQ7534U+TwErs9Cet86L2jyJWIA=; b=HdTeawOcH7UUAYEcNEd+SVdGvW73oaceGlhFtGJ3ASN67awmawOtoXd6La/iG+eECl 9u7V5e/ud9pQsSlMMyGNiRxsMEHoUIGhk8mczFBd05Vu3Ya76VsRv8jOqziHZNXROALn Yit6xVqkTlbH89Q/cU/BmkrMwaVDrYWEyDiXmKpQO4E+Lxvbq+88qQ6U/5TRd3XyY3S6 W0zBvf9/SNiGBT4NcXgSF+6CBYJYiQdqsGlPs3MJIcsIJX0v0qmMxQdpWszURAcpt5I0 Vx9srfACQBJ/q/F+tzHFX1qwxvqKMkaVLcc9xIZOQ/bc3Ce/A2UKC/2Z2jj6oo/0xamL diog== X-Gm-Message-State: AIVw113tFJmNNZVDTRWgUynVdVFlnuaCiO7dxXW8TfDuqFySruhJQPPy Im38wuiflxtpPcK8 X-Received: by 10.98.67.147 with SMTP id l19mr6396739pfi.198.1500620352287; Thu, 20 Jul 2017 23:59:12 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id z15sm4132961pfl.125.2017.07.20.23.59.08 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jul 2017 23:59:11 -0700 (PDT) From: Baolin Wang To: balbi@kernel.org, gregkh@linuxfoundation.org Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, mgautam@codeaurora.org, broonie@kernel.org, baolin.wang@linaro.org Subject: [PATCH] usb: dwc3: Support the dwc3 host suspend/resume Date: Fri, 21 Jul 2017 14:58:48 +0800 Message-Id: <2086ce508be1c1d75d47c892a5be9593b12fa6f3.1500619870.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For some mobile devices with strict power management, we also want to suspend the host when the slave was detached for power saving. Thus adding the host suspend/resume functions to support this requirement. We will issue the pm_suspend_ignore_children() for the dwc3 device, since we will resume the child device (xHCI device) in runtime resume callback (dwc3_host_resume()) of dwc3 device, now the dwc3 device's runtime state is not RPM_ACTIVE, which will block to resume its child device (xHCI device). Add ignore children flag can avoid this situation. Signed-off-by: Baolin Wang --- drivers/usb/dwc3/core.c | 26 +++++++++++++++++++++++++- drivers/usb/dwc3/core.h | 7 +++++++ drivers/usb/dwc3/host.c | 15 +++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 326b302..2be7ddc 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1193,6 +1193,7 @@ static int dwc3_probe(struct platform_device *pdev) pm_runtime_use_autosuspend(dev); pm_runtime_set_autosuspend_delay(dev, DWC3_DEFAULT_AUTOSUSPEND_DELAY); pm_runtime_enable(dev); + pm_suspend_ignore_children(dev, true); ret = pm_runtime_get_sync(dev); if (ret < 0) goto err1; @@ -1292,15 +1293,27 @@ static int dwc3_remove(struct platform_device *pdev) static int dwc3_suspend_common(struct dwc3 *dwc) { unsigned long flags; + int ret; switch (dwc->dr_mode) { case USB_DR_MODE_PERIPHERAL: + spin_lock_irqsave(&dwc->lock, flags); + dwc3_gadget_suspend(dwc); + spin_unlock_irqrestore(&dwc->lock, flags); + break; case USB_DR_MODE_OTG: + ret = dwc3_host_suspend(dwc); + if (ret) + return ret; + spin_lock_irqsave(&dwc->lock, flags); dwc3_gadget_suspend(dwc); spin_unlock_irqrestore(&dwc->lock, flags); break; case USB_DR_MODE_HOST: + ret = dwc3_host_suspend(dwc); + if (ret) + return ret; default: /* do nothing */ break; @@ -1322,12 +1335,23 @@ static int dwc3_resume_common(struct dwc3 *dwc) switch (dwc->dr_mode) { case USB_DR_MODE_PERIPHERAL: + spin_lock_irqsave(&dwc->lock, flags); + dwc3_gadget_resume(dwc); + spin_unlock_irqrestore(&dwc->lock, flags); + break; case USB_DR_MODE_OTG: + ret = dwc3_host_resume(dwc); + if (ret) + return ret; + spin_lock_irqsave(&dwc->lock, flags); dwc3_gadget_resume(dwc); spin_unlock_irqrestore(&dwc->lock, flags); - /* FALLTHROUGH */ + break; case USB_DR_MODE_HOST: + ret = dwc3_host_resume(dwc); + if (ret) + return ret; default: /* do nothing */ break; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index ea910ac..9b5a4eb 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1193,11 +1193,18 @@ static inline bool dwc3_is_usb31(struct dwc3 *dwc) #if IS_ENABLED(CONFIG_USB_DWC3_HOST) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) int dwc3_host_init(struct dwc3 *dwc); void dwc3_host_exit(struct dwc3 *dwc); +int dwc3_host_suspend(struct dwc3 *dwc); +int dwc3_host_resume(struct dwc3 *dwc); #else static inline int dwc3_host_init(struct dwc3 *dwc) { return 0; } static inline void dwc3_host_exit(struct dwc3 *dwc) { } + +static inline int dwc3_host_suspend(struct dwc3 *dwc) +{ return 0; } +static inline int dwc3_host_resume(struct dwc3 *dwc) +{ return 0; } #endif #if IS_ENABLED(CONFIG_USB_DWC3_GADGET) || IS_ENABLED(CONFIG_USB_DWC3_DUAL_ROLE) diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index 76f0b0d..3fa4414 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -16,6 +16,7 @@ */ #include +#include #include "core.h" @@ -151,3 +152,17 @@ void dwc3_host_exit(struct dwc3 *dwc) dev_name(dwc->dev)); platform_device_unregister(dwc->xhci); } + +int dwc3_host_suspend(struct dwc3 *dwc) +{ + struct device *xhci = &dwc->xhci->dev; + + return pm_runtime_suspend(xhci); +} + +int dwc3_host_resume(struct dwc3 *dwc) +{ + struct device *xhci = &dwc->xhci->dev; + + return pm_runtime_resume(xhci); +}