From patchwork Thu Feb 27 19:49:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 25469 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f70.google.com (mail-pa0-f70.google.com [209.85.220.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9F20C20543 for ; Thu, 27 Feb 2014 19:51:32 +0000 (UTC) Received: by mail-pa0-f70.google.com with SMTP id kx10sf6661131pab.9 for ; Thu, 27 Feb 2014 11:51:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=fxiYmaxGr1+NGTYflwO2cVN2YBqBtSnqezXYFSygaDM=; b=U7fyOAkgU0PkRgf63+x7OhdB410Ad7/88r6TN/sSl6+vV+CsBENVN+YzUrpiRDRq6i oERYAnNodb5ym8zEAVHkWqFHz0N2MWpfqYpCtS+v0RM71DG6ODwhTmZejlf6ZV5m9vKy oeEDcFVhaAL3RUyr4uw9xMfdLctSXYZc5C0U0dW0g+dA5VTnk7v2w6SdNoLymYzEnREt CLwLYveUmUEVxhQEnnsh9CAomoqfyF9veVRbs/Q5kmoordddC0JHGFrQC3ITAWd01gS/ OkuUp+5jNTZpTqUUzxv9uS/qSwVNei15lq4eb8pzalXCTq4VRFS1OKQQrggYhEqhU7Ig 4VUA== X-Gm-Message-State: ALoCoQkIKl1WB8hBtjs58p27acgqFh8oNCRZ+5YBy//HMbGqlLLvXqwbR6rFs0F2fvfAEBjLwEOO X-Received: by 10.66.159.36 with SMTP id wz4mr6654582pab.14.1393530691853; Thu, 27 Feb 2014 11:51:31 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.30.8 with SMTP id c8ls793368qgc.56.gmail; Thu, 27 Feb 2014 11:51:31 -0800 (PST) X-Received: by 10.53.0.230 with SMTP id bb6mr2208987vdd.39.1393530691735; Thu, 27 Feb 2014 11:51:31 -0800 (PST) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id cz20si1550666veb.129.2014.02.27.11.51.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 11:51:31 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id oy12so4317316veb.6 for ; Thu, 27 Feb 2014 11:51:31 -0800 (PST) X-Received: by 10.220.147.16 with SMTP id j16mr2823993vcv.28.1393530691631; Thu, 27 Feb 2014 11:51:31 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.130.193 with SMTP id u1csp1510vcs; Thu, 27 Feb 2014 11:51:31 -0800 (PST) X-Received: by 10.68.66.1 with SMTP id b1mr15090834pbt.43.1393530690717; Thu, 27 Feb 2014 11:51:30 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tg2si5685914pbc.143.2014.02.27.11.51.30; Thu, 27 Feb 2014 11:51:30 -0800 (PST) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751573AbaB0Tv2 (ORCPT + 3 others); Thu, 27 Feb 2014 14:51:28 -0500 Received: from bear.ext.ti.com ([192.94.94.41]:57339 "EHLO bear.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbaB0Tv0 (ORCPT ); Thu, 27 Feb 2014 14:51:26 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1RJpQhm025397 for ; Thu, 27 Feb 2014 13:51:26 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1RJpQJA026853 for ; Thu, 27 Feb 2014 13:51:26 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 27 Feb 2014 13:51:26 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1RJpP6f023770; Thu, 27 Feb 2014 13:51:26 -0600 From: Felipe Balbi To: Linux USB Mailing List CC: Felipe Balbi Subject: [PATCH 3/8] usb: dwc3: pci: add pm_runtime support Date: Thu, 27 Feb 2014 13:49:52 -0600 Message-ID: <1393530597-12259-3-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1393530597-12259-1-git-send-email-balbi@ti.com> References: <1393530597-12259-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 Sender: linux-usb-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: balbi@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , teach the PCI glue about pm_runtime so that it's easier to teach dwc3 core about it later. No functional changes otherwise. Tested-by: David Cohen Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-pci.c | 73 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c index f393c18..3ae1c84 100644 --- a/drivers/usb/dwc3/dwc3-pci.c +++ b/drivers/usb/dwc3/dwc3-pci.c @@ -110,18 +110,17 @@ static int dwc3_pci_probe(struct pci_dev *pci, glue->dev = dev; - ret = pci_enable_device(pci); + pm_runtime_enable(dev); + ret = pm_runtime_get_sync(dev); if (ret) { dev_err(dev, "failed to enable pci device\n"); return -ENODEV; } - pci_set_master(pci); - ret = dwc3_pci_register_phys(glue); if (ret) { dev_err(dev, "couldn't register PHYs\n"); - return ret; + goto err1; } dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); @@ -168,7 +167,8 @@ static int dwc3_pci_probe(struct pci_dev *pci, err3: platform_device_put(dwc3); err1: - pci_disable_device(pci); + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); return ret; } @@ -176,11 +176,13 @@ err1: static void dwc3_pci_remove(struct pci_dev *pci) { struct dwc3_pci *glue = pci_get_drvdata(pci); + struct device *dev = &pci->dev; platform_device_unregister(glue->dwc3); platform_device_unregister(glue->usb2_phy); platform_device_unregister(glue->usb3_phy); - pci_disable_device(pci); + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); } static const struct pci_device_id dwc3_pci_id_table[] = { @@ -194,24 +196,21 @@ static const struct pci_device_id dwc3_pci_id_table[] = { }; MODULE_DEVICE_TABLE(pci, dwc3_pci_id_table); -#ifdef CONFIG_PM_SLEEP -static int dwc3_pci_suspend(struct device *dev) +#ifdef CONFIG_PM +static int __dwc3_pci_suspend(struct pci_dev *pci) { - struct pci_dev *pci = to_pci_dev(dev); - pci_disable_device(pci); return 0; } -static int dwc3_pci_resume(struct device *dev) +static int __dwc3_pci_resume(struct pci_dev *pci) { - struct pci_dev *pci = to_pci_dev(dev); - int ret; + int ret; ret = pci_enable_device(pci); if (ret) { - dev_err(dev, "can't re-enable device --> %d\n", ret); + dev_err(&pci->dev, "can't re-enable device --> %d\n", ret); return ret; } @@ -219,10 +218,56 @@ static int dwc3_pci_resume(struct device *dev) return 0; } + +#ifdef CONFIG_PM +static int dwc3_pci_suspend(struct device *dev) +{ + struct pci_dev *pci = to_pci_dev(dev); + + if (pm_runtime_suspended(dev)) + return 0; + + return __dwc3_pci_suspend(pci); +} + +static int dwc3_pci_resume(struct device *dev) +{ + struct pci_dev *pci = to_pci_dev(dev); + int ret; + + ret = __dwc3_pci_resume(pci); + if (ret) + return ret; + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_disable(dev); + + return 0; +} #endif /* CONFIG_PM_SLEEP */ +#ifdef CONFIG_PM_RUNTIME +static int dwc3_pci_runtime_suspend(struct device *dev) +{ + struct pci_dev *pci = to_pci_dev(dev); + + return __dwc3_pci_suspend(pci); +} + +static int dwc3_pci_runtime_resume(struct device *dev) +{ + struct pci_dev *pci = to_pci_dev(dev); + + return __dwc3_pci_resume(pci); +} +#endif /* CONFIG_PM_RUNTIME */ +#endif /* CONFIG_PM */ + static const struct dev_pm_ops dwc3_pci_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(dwc3_pci_suspend, dwc3_pci_resume) + SET_RUNTIME_PM_OPS(dwc3_pci_runtime_suspend, dwc3_pci_runtime_resume, + NULL) }; static struct pci_driver dwc3_pci_driver = {