From patchwork Thu Apr 13 08:59:54 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: 97357 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp625502qgf; Thu, 13 Apr 2017 02:00:28 -0700 (PDT) X-Received: by 10.98.215.23 with SMTP id b23mr2186451pfh.87.1492074028035; Thu, 13 Apr 2017 02:00:28 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si23314714pfj.115.2017.04.13.02.00.27; Thu, 13 Apr 2017 02:00:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756078AbdDMJAZ (ORCPT + 4 others); Thu, 13 Apr 2017 05:00:25 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:34209 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751503AbdDMJAV (ORCPT ); Thu, 13 Apr 2017 05:00:21 -0400 Received: by mail-pg0-f54.google.com with SMTP id 21so27719903pgg.1 for ; Thu, 13 Apr 2017 02:00:20 -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=NcRsYFZa0cUP5yDkVrgIoXaO1dupQlaswjXT/9cv7Oc=; b=BJJzhZNhBRqFUkB0b7UdK6cgPu/JXl0M6Y9HvUv5AGs3g5Tczb/Dr2gRqqCvMY8Rsc KKGYe76QknC8iKhnvAZhCAD+YR7luMfZeAwoqlHznKnVmOU1yf9I2g6Kx4/O7puspmq4 /2PgFoodoDEH9YpcnIv+UKPOnh+er6LUQrK+g= 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=NcRsYFZa0cUP5yDkVrgIoXaO1dupQlaswjXT/9cv7Oc=; b=QRsm04C34Mp2vqkZt2/5N3wqNZTpFJOZfWTEHMIQtrHeKoPlkJgOnHJI9bnmpT32n/ Y+WOtKgjlxw88FeZ1+99LQxxucN8VtWd/mW6RrNGE7vnKtT6eGKPtV+VAdGi/Iryw8mY LEEZpxBlHHTcQGjrBIAgFKlMNO7vsX9735F8cN9WSQfX1d9Zi1PLCqTatPAyAvImv4z5 34wi39YXZvOu8RpkuRuWM1iQWiwQEVA9iRAS3aA/0pNN5l1t8VF/46ke7VSSUWFCYjO+ h9dWud7KgT0lpmJTkjpuoR945XYHOh7khtHdoaWtJ6lShMv9s0Nlu8gcnQYIqdWgOsFw B3HQ== X-Gm-Message-State: AN3rC/4AXPEP68Rx4uuPD/eMhNkb/XRCIslTwV/hmaltf6cxFGLe5jUM gTpmstqxUOik5Ijj X-Received: by 10.84.138.193 with SMTP id 59mr2808110plp.167.1492074020307; Thu, 13 Apr 2017 02:00:20 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.82]) by smtp.gmail.com with ESMTPSA id s11sm41175856pgc.61.2017.04.13.02.00.17 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 13 Apr 2017 02:00:19 -0700 (PDT) From: Baolin Wang To: mathias.nyman@intel.com Cc: gregkh@linuxfoundation.org, broonie@kernel.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org Subject: [PATCH v2] usb: host: plat: Enable xHCI plat runtime PM Date: Thu, 13 Apr 2017 16:59:54 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Enable the xHCI plat runtime PM for parent device to suspend/resume xHCI. Also call pm_runtime_forbid() in probe() function to force users to explicitly enable runtime pm using power/control in sysfs, in case some parent devices didn't implement runtime PM callbacks. Signed-off-by: Baolin Wang --- Changes since v1: - Rebase on Mathias's next branch. --- drivers/usb/host/xhci-plat.c | 53 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 62e71b8..e19b257 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -197,10 +197,16 @@ static int xhci_plat_probe(struct platform_device *pdev) return ret; } + pm_runtime_set_active(&pdev->dev); + pm_runtime_enable(&pdev->dev); + pm_runtime_get_noresume(&pdev->dev); + hcd = __usb_create_hcd(driver, sysdev, &pdev->dev, dev_name(&pdev->dev), NULL); - if (!hcd) - return -ENOMEM; + if (!hcd) { + ret = -ENOMEM; + goto disable_runtime; + } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); hcd->regs = devm_ioremap_resource(&pdev->dev, res); @@ -278,6 +284,13 @@ static int xhci_plat_probe(struct platform_device *pdev) goto dealloc_usb2_hcd; device_enable_async_suspend(&pdev->dev); + pm_runtime_put_noidle(&pdev->dev); + + /* + * Prevent runtime pm from being on as default, users should enable + * runtime pm using power/control in sysfs. + */ + pm_runtime_forbid(&pdev->dev); return 0; @@ -298,6 +311,10 @@ static int xhci_plat_probe(struct platform_device *pdev) put_hcd: usb_put_hcd(hcd); +disable_runtime: + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); + return ret; } @@ -318,6 +335,9 @@ static int xhci_plat_remove(struct platform_device *dev) if (!IS_ERR(clk)) clk_disable_unprepare(clk); usb_put_hcd(hcd); + + pm_runtime_set_suspended(&dev->dev); + pm_runtime_disable(&dev->dev); return 0; } @@ -346,14 +366,33 @@ static int xhci_plat_resume(struct device *dev) return xhci_resume(xhci, 0); } +#endif /* CONFIG_PM_SLEEP */ + +#ifdef CONFIG_PM +static int xhci_plat_runtime_suspend(struct device *dev) +{ + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + + return xhci_suspend(xhci, device_may_wakeup(dev)); +} + +static int xhci_plat_runtime_resume(struct device *dev) +{ + struct usb_hcd *hcd = dev_get_drvdata(dev); + struct xhci_hcd *xhci = hcd_to_xhci(hcd); + + return xhci_resume(xhci, 0); +} +#endif /* CONFIG_PM */ static const struct dev_pm_ops xhci_plat_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(xhci_plat_suspend, xhci_plat_resume) + + SET_RUNTIME_PM_OPS(xhci_plat_runtime_suspend, + xhci_plat_runtime_resume, + NULL) }; -#define DEV_PM_OPS (&xhci_plat_pm_ops) -#else -#define DEV_PM_OPS NULL -#endif /* CONFIG_PM */ static const struct acpi_device_id usb_xhci_acpi_match[] = { /* XHCI-compliant USB Controller */ @@ -368,7 +407,7 @@ static int xhci_plat_resume(struct device *dev) .shutdown = usb_hcd_platform_shutdown, .driver = { .name = "xhci-hcd", - .pm = DEV_PM_OPS, + .pm = &xhci_plat_pm_ops, .of_match_table = of_match_ptr(usb_xhci_of_match), .acpi_match_table = ACPI_PTR(usb_xhci_acpi_match), },