From patchwork Thu Feb 27 19:49:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 25471 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id A926B20543 for ; Thu, 27 Feb 2014 19:51:35 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id n16sf10552772oag.9 for ; Thu, 27 Feb 2014 11:51:35 -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=nuwLBaXmK2M/Yuamhxs3eSH7TImSTT4o/gsbzN+uvW4=; b=CvwJRQWL3b9I/BV8EUiKAHp6AnLFKgeoWMaq0D6U+W7cmTGMa1FQSGknVKWkDpqcz+ So2jLuBaTy2b5ozn9vjQj18LWqrR98YxJgkhV3nmxJ6P0ntQObLHxhxnEsc+8niyZSIb 1M8XvZVOONAMRoljSSXsGkmpNDIwBV+SciZAgODrvZ/JvEBEsrp23vPpmsh22s37cRLQ DqGLq9VvcHhaCbPvTtcVoVactoxIgKPG3OiYKPGRf8kGPoijUaTqiELOoDIsSn+x3c8x E3yjhNrIzSkoQbgafGLfa2ox+zzNhBR3wU8u6RX5HN/k9gtdmxgj7ZZSgAupZG0VCtZO IVGQ== X-Gm-Message-State: ALoCoQnGEOERj2LGLHigAKTrc9EXgy1J64alr5nmq4e0ENY2NzzCJbP4dkfosJQaGI9QmgdaC52+ X-Received: by 10.182.60.37 with SMTP id e5mr4839969obr.30.1393530695263; Thu, 27 Feb 2014 11:51:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.75 with SMTP id i69ls745730qgd.66.gmail; Thu, 27 Feb 2014 11:51:35 -0800 (PST) X-Received: by 10.52.81.66 with SMTP id y2mr10129745vdx.23.1393530695118; Thu, 27 Feb 2014 11:51:35 -0800 (PST) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id u1si1559577vek.29.2014.02.27.11.51.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 11:51:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id lf12so3015088vcb.17 for ; Thu, 27 Feb 2014 11:51:35 -0800 (PST) X-Received: by 10.220.67.18 with SMTP id p18mr12190801vci.14.1393530694975; Thu, 27 Feb 2014 11:51:34 -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 u1csp1514vcs; Thu, 27 Feb 2014 11:51:34 -0800 (PST) X-Received: by 10.68.197.36 with SMTP id ir4mr15063147pbc.46.1393530694023; Thu, 27 Feb 2014 11:51:34 -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.33; Thu, 27 Feb 2014 11:51:33 -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 S1753029AbaB0Tvb (ORCPT + 3 others); Thu, 27 Feb 2014 14:51:31 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:37706 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752757AbaB0Tv3 (ORCPT ); Thu, 27 Feb 2014 14:51:29 -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 s1RJpTnL009483 for ; Thu, 27 Feb 2014 13:51:29 -0600 Received: from DLEE70.ent.ti.com (dlemailx.itg.ti.com [157.170.170.113]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1RJpTPG013652 for ; Thu, 27 Feb 2014 13:51:29 -0600 Received: from dlep33.itg.ti.com (157.170.170.75) by DLEE70.ent.ti.com (157.170.170.113) with Microsoft SMTP Server id 14.3.174.1; Thu, 27 Feb 2014 13:51:29 -0600 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1RJpSET020708; Thu, 27 Feb 2014 13:51:29 -0600 From: Felipe Balbi To: Linux USB Mailing List CC: Felipe Balbi Subject: [PATCH 6/8] usb: dwc3: exynos: add basic pm_runtime support Date: Thu, 27 Feb 2014 13:49:55 -0600 Message-ID: <1393530597-12259-6-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.220.172 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: , move clock calls to pm_runtime callbacks and fix ifdeffery around PM-related callbacks. Signed-off-by: Felipe Balbi --- drivers/usb/dwc3/dwc3-exynos.c | 78 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 14 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-exynos.c b/drivers/usb/dwc3/dwc3-exynos.c index 28c8ad7..8479bb8 100644 --- a/drivers/usb/dwc3/dwc3-exynos.c +++ b/drivers/usb/dwc3/dwc3-exynos.c @@ -142,24 +142,40 @@ static int dwc3_exynos_probe(struct platform_device *pdev) exynos->dev = dev; exynos->clk = clk; - clk_prepare_enable(exynos->clk); + ret = clk_prepare(exynos->clk); + if (ret) { + dev_err(dev, "failed to prepare clock\n"); + goto err2; + } + + pm_runtime_enable(dev); + ret = pm_runtime_get_sync(dev); + if (ret) { + dev_err(dev, "failed to enable dwc3 device\n"); + goto err3; + } if (node) { ret = of_platform_populate(node, NULL, NULL, dev); if (ret) { dev_err(dev, "failed to add dwc3 core\n"); - goto err2; + goto err3; } } else { dev_err(dev, "no device node, failed to add dwc3 core\n"); ret = -ENODEV; - goto err2; + goto err3; } return 0; +err3: + pm_runtime_put_sync(dev); + pm_runtime_disable(dev); + err2: - clk_disable_unprepare(clk); + clk_unprepare(clk); + err1: return ret; } @@ -172,7 +188,9 @@ static int dwc3_exynos_remove(struct platform_device *pdev) platform_device_unregister(exynos->usb2_phy); platform_device_unregister(exynos->usb3_phy); - clk_disable_unprepare(exynos->clk); + pm_runtime_put_sync(exynos->dev); + pm_runtime_disable(exynos->dev); + clk_unprepare(exynos->clk); return 0; } @@ -185,21 +203,38 @@ static const struct of_device_id exynos_dwc3_match[] = { MODULE_DEVICE_TABLE(of, exynos_dwc3_match); #endif +#ifdef CONFIG_PM +static int __dwc3_exynos_suspend(struct dwc3_exynos *exynos) +{ + clk_disable(exynos->clk); + + return 0; +} + +static int __dwc3_exynos_resume(struct dwc3_exynos *exynos) +{ + return clk_enable(exynos->clk); +} + #ifdef CONFIG_PM_SLEEP static int dwc3_exynos_suspend(struct device *dev) { struct dwc3_exynos *exynos = dev_get_drvdata(dev); - clk_disable(exynos->clk); + if (pm_runtime_suspended(dev)) + return 0; - return 0; + return __dwc3_exynos_suspend(exynos); } static int dwc3_exynos_resume(struct device *dev) { struct dwc3_exynos *exynos = dev_get_drvdata(dev); + int ret; - clk_enable(exynos->clk); + ret = __dwc3_exynos_resume(exynos); + if (ret) + return ret; /* runtime set active to reflect active state. */ pm_runtime_disable(dev); @@ -208,23 +243,38 @@ static int dwc3_exynos_resume(struct device *dev) return 0; } +#endif /* CONFIG_PM_SLEEP */ + +#ifdef CONFIG_PM_RUNTIME +static int dwc3_exynos_runtime_suspend(struct device *dev) +{ + struct dwc3_exynos *exynos = dev_get_drvdata(dev); + + return __dwc3_exynos_suspend(exynos); +} + +static int dwc3_exynos_runtime_resume(struct device *dev) +{ + struct dwc3_exynos *exynos = dev_get_drvdata(dev); + + return __dwc3_exynos_resume(exynos); +} +#endif /* CONFIG_PM_RUNTIME */ +#endif /* CONFIG_PM */ static const struct dev_pm_ops dwc3_exynos_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(dwc3_exynos_suspend, dwc3_exynos_resume) + SET_RUNTIME_PM_OPS(dwc3_exynos_runtime_suspend, + dwc3_exynos_runtime_resume, NULL) }; -#define DEV_PM_OPS (&dwc3_exynos_dev_pm_ops) -#else -#define DEV_PM_OPS NULL -#endif /* CONFIG_PM_SLEEP */ - static struct platform_driver dwc3_exynos_driver = { .probe = dwc3_exynos_probe, .remove = dwc3_exynos_remove, .driver = { .name = "exynos-dwc3", .of_match_table = of_match_ptr(exynos_dwc3_match), - .pm = DEV_PM_OPS, + .pm = &dwc3_exynos_dev_pm_ops, }, };