From patchwork Thu Feb 27 19:49:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 25468 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 933F920543 for ; Thu, 27 Feb 2014 19:51:31 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id p10sf6544115pdj.7 for ; Thu, 27 Feb 2014 11:51:30 -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 :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=sWhm0RASHZ6bpX3/jciZFQ0P3/xHhNCZjg1ZDEwtHGo=; b=feWB8l7YbYljbN/wX9nj4XzMaIYDjHHPYCZdZNWRclpHiomVi2XCJgTztzxeRl57gU mskj/zcJaEneOfrP9Aixyi+miat4cRKMmgY62i8feCksBTxeuRakefsiaEExW88j5RbE 2DoJVpIkl5wImDRBsTw6Xl+0wiHxoKPR84WBQdW7/7CLObZ17nr/34sUu3KWkSnkpDf7 25fpDqfgvvRK0l+/U+xPK6vYViPhgDhVjlMmlZshUtfN83fCVjhuW6U64k1lpDS+qe3F J/RsT5Avoz5D+PMX/fF+0WbOYg46nie0Awg3oGAROnW+suf8HAwahwcKaY5aS/y66SUA 16tA== X-Gm-Message-State: ALoCoQmpAMLocU3FldcOdZInPl+wjtdTWeHMxt7qtoFdioqbbLeHD4MzPv6zHxba9PQ2m1ZVu3cN X-Received: by 10.66.222.105 with SMTP id ql9mr7517952pac.9.1393530690743; Thu, 27 Feb 2014 11:51:30 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.33.203 with SMTP id j69ls664302qgj.27.gmail; Thu, 27 Feb 2014 11:51:30 -0800 (PST) X-Received: by 10.52.230.105 with SMTP id sx9mr10328935vdc.10.1393530690579; Thu, 27 Feb 2014 11:51:30 -0800 (PST) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id av10si1552374ved.112.2014.02.27.11.51.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 11:51:30 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.171 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.171; Received: by mail-ve0-f171.google.com with SMTP id cz12so433354veb.16 for ; Thu, 27 Feb 2014 11:51:30 -0800 (PST) X-Received: by 10.58.170.69 with SMTP id ak5mr2835994vec.28.1393530690490; Thu, 27 Feb 2014 11:51:30 -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 u1csp1508vcs; Thu, 27 Feb 2014 11:51:29 -0800 (PST) X-Received: by 10.68.204.161 with SMTP id kz1mr15230272pbc.156.1393530688450; Thu, 27 Feb 2014 11:51:28 -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.28; Thu, 27 Feb 2014 11:51:28 -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 S1752480AbaB0Tv0 (ORCPT + 3 others); Thu, 27 Feb 2014 14:51:26 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:37700 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751729AbaB0TvZ (ORCPT ); Thu, 27 Feb 2014 14:51:25 -0500 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1RJpOdp009474 for ; Thu, 27 Feb 2014 13:51:24 -0600 Received: from DFLE73.ent.ti.com (dfle73.ent.ti.com [128.247.5.110]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1RJpOEN013600 for ; Thu, 27 Feb 2014 13:51:24 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE73.ent.ti.com (128.247.5.110) with Microsoft SMTP Server id 14.3.174.1; Thu, 27 Feb 2014 13:51:24 -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 s1RJpNTW022911; Thu, 27 Feb 2014 13:51:24 -0600 From: Felipe Balbi To: Linux USB Mailing List CC: Felipe Balbi Subject: [PATCH 1/8] usb: dwc3: keystone: add basic PM support Date: Thu, 27 Feb 2014 13:49:50 -0600 Message-ID: <1393530597-12259-1-git-send-email-balbi@ti.com> X-Mailer: git-send-email 1.9.0 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.171 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: , A bare-minimum PM implementation which will serve as building block for more complex PM implementation in the future. At the very least we will not leave clocks on unnecessarily when e.g. a user writes mem to /sys/power/state. Acked-by: Santosh Shilimkar Tested-by: WingMan Kwok Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-keystone.c | 106 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-keystone.c b/drivers/usb/dwc3/dwc3-keystone.c index 1fad161..06aa543 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,22 @@ 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); + goto err_irq; + } + irq = platform_get_irq(pdev, 0); if (irq < 0) { dev_err(&pdev->dev, "missing irq\n"); @@ -151,8 +161,11 @@ 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); + pm_runtime_disable(dev); + clk_unprepare(kdwc->clk); return error; } @@ -172,7 +185,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 +199,90 @@ static const struct of_device_id kdwc3_of_match[] = { }; MODULE_DEVICE_TABLE(of, kdwc3_of_match); +#ifdef CONFIG_PM +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); +} + +#ifdef CONFIG_PM_SLEEP +static int kdwc3_suspend(struct device *dev) +{ + struct dwc3_keystone *kdwc = dev_get_drvdata(dev); + + if (pm_runtime_suspended(dev)) + return 0; + + 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; +} +#endif /* CONFIG_PM_SLEEP */ + +#ifdef CONFIG_PM_RUNTIME +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); +} +#endif /* CONFIG_PM_RUNTIME */ +#endif /* CONFIG_PM */ + +static const struct dev_pm_ops kdwc3_dev_pm_ops = { +#ifdef CONFIG_PM + .prepare = kdwc3_prepare, + .complete = kdwc3_complete, +#endif /* CONFIG_PM */ + + 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, @@ -191,6 +290,7 @@ static struct platform_driver kdwc3_driver = { .name = "keystone-dwc3", .owner = THIS_MODULE, .of_match_table = kdwc3_of_match, + .pm = &kdwc3_dev_pm_ops, }, };