From patchwork Thu Dec 12 21:38:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 3334861 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8EBE0C0D4A for ; Thu, 12 Dec 2013 22:24:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AA7CE207DD for ; Thu, 12 Dec 2013 22:24:50 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7E996207D6 for ; Thu, 12 Dec 2013 22:24:49 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrE0p-0001IL-AV; Thu, 12 Dec 2013 21:41:40 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrE08-00034m-5T; Thu, 12 Dec 2013 21:40:56 +0000 Received: from bear.ext.ti.com ([192.94.94.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VrDyv-0002vp-1X for linux-arm-kernel@lists.infradead.org; Thu, 12 Dec 2013 21:39:47 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id rBCLdGh6004734; Thu, 12 Dec 2013 15:39:16 -0600 Received: from DLEE70.ent.ti.com (dlee70.ent.ti.com [157.170.170.113]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBCLdGBv025931; Thu, 12 Dec 2013 15:39:16 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.2.342.3; Thu, 12 Dec 2013 15:39:16 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id rBCLdGhB009858; Thu, 12 Dec 2013 15:39:16 -0600 From: Felipe Balbi To: Linux USB Mailing List Subject: [PATCH 1/7] usb: dwc3: keystone: add basic PM support Date: Thu, 12 Dec 2013 15:38:39 -0600 Message-ID: <1386884325-11440-2-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.8.4.GIT In-Reply-To: <1386884325-11440-1-git-send-email-balbi@ti.com> References: <1386884325-11440-1-git-send-email-balbi@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131212_163941_276754_A91EB07F X-CRM114-Status: GOOD ( 14.08 ) X-Spam-Score: -6.9 (------) Cc: linux-samsung-soc@vger.kernel.org, w-kwok2@ti.com, Felipe Balbi , kgene.kim@samsung.com, Santosh Shilimkar , Linux OMAP Mailing List , Linux ARM Kernel Mailing List X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A bare-minimum PM implementation which will server as building block for more complex PM implementation in the future. At the least will not leave clocks on unnecessarily when e.g. a user write mem to /sys/power/state. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-keystone.c | 97 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 94 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c index 1fad161..361437f 100644 --- a/drivers/usb/dwc3/dwc3-keystone.c +++ b/drivers/usb/dwc3/dwc3-keystone.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -118,13 +119,23 @@ static int kdwc3_probe(struct platform_device *pdev) kdwc->clk = devm_clk_get(kdwc->dev, "usb"); - error = clk_prepare_enable(kdwc->clk); + error = clk_prepare(kdwc->clk); if (error < 0) { dev_dbg(kdwc->dev, "unable to enable usb clock, err %d\n", error); return error; } + pm_runtime_enable(dev); + + error = pm_runtime_get_sync(dev); + if (error < 0) { + dev_dbg(dev, "unable to pm_runtime_get_sync(), err %d\n", + error); + pm_runtime_put_sync(dev); + goto err_runtime_get; + } + irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "missing irq\n"); @@ -151,8 +162,13 @@ static int kdwc3_probe(struct platform_device *pdev) err_core: kdwc3_disable_irqs(kdwc); + err_irq: - clk_disable_unprepare(kdwc->clk); + pm_runtime_put_sync(dev); + +err_runtime_get: + pm_runtime_disable(dev); + clk_unprepare(kdwc->clk); return error; } @@ -172,7 +188,9 @@ static int kdwc3_remove(struct platform_device *pdev) kdwc3_disable_irqs(kdwc); device_for_each_child(&pdev->dev, NULL, kdwc3_remove_core); - clk_disable_unprepare(kdwc->clk); + pm_runtime_put_sync(&pdev->dev); + pm_runtime_disable(&pdev->dev); + clk_unprepare(kdwc->clk); platform_set_drvdata(pdev, NULL); return 0; @@ -184,6 +202,79 @@ static const struct of_device_id kdwc3_of_match[] = { }; MODULE_DEVICE_TABLE(of, kdwc3_of_match); +static int __kdwc3_suspend(struct dwc3_keystone *kdwc) +{ + clk_disable(kdwc->clk); + + return 0; +} + +static int __kdwc3_resume(struct dwc3_keystone *kdwc) +{ + return clk_enable(kdwc->clk); +} + +static int kdwc3_prepare(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + + kdwc3_disable_irqs(kdwc); + + return 0; +} + +static void kdwc3_complete(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + + kdwc3_enable_irqs(kdwc); +} + +static int kdwc3_suspend(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + + return __kdwc3_suspend(kdwc); +} + +static int kdwc3_resume(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + int ret; + + ret = __kdwc3_resume(kdwc); + if (ret) + return ret; + + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_enable(dev); + + return 0; +} + +static int kdwc3_runtime_suspend(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + + return __kdwc3_suspend(kdwc); +} + +static int kdwc3_runtime_resume(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + + return __kdwc3_resume(kdwc); +} + +static const struct dev_pm_ops kdwc3_dev_pm_ops = { + .prepare = kdwc3_prepare, + .complete = kdwc3_complete, + + SET_SYSTEM_SLEEP_PM_OPS(kdwc3_suspend, kdwc3_resume) + SET_RUNTIME_PM_OPS(kdwc3_runtime_suspend, kdwc3_runtime_resume, NULL) +}; + static struct platform_driver kdwc3_driver = { .probe = kdwc3_probe, .remove = kdwc3_remove,