From patchwork Mon May 27 13:49:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mayuresh Kulkarni X-Patchwork-Id: 2622961 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by patchwork2.kernel.org (Postfix) with ESMTP id DE4D3DFB78 for ; Tue, 28 May 2013 05:27:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EDB7E6131 for ; Mon, 27 May 2013 22:27:35 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org X-Greylist: delayed 307 seconds by postgrey-1.32 at gabe; Mon, 27 May 2013 06:54:52 PDT Received: from hqemgate16.nvidia.com (hqemgate16.nvidia.com [216.228.121.65]) by gabe.freedesktop.org (Postfix) with ESMTP id 7E0C8E609F for ; Mon, 27 May 2013 06:54:52 -0700 (PDT) Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate16.nvidia.com id ; Mon, 27 May 2013 06:49:44 -0700 Received: from hqemhub01.nvidia.com ([172.20.12.94]) by hqnvupgp07.nvidia.com (PGP Universal service); Mon, 27 May 2013 06:49:39 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Mon, 27 May 2013 06:49:39 -0700 Received: from mkulkarni-dt2.nvidia.com (172.20.144.16) by hqemhub01.nvidia.com (172.20.150.30) with Microsoft SMTP Server (TLS) id 8.3.298.1; Mon, 27 May 2013 06:49:43 -0700 From: Mayuresh Kulkarni To: , , , , , Subject: [PATCH] drm/tegra: add support for runtime pm Date: Mon, 27 May 2013 19:19:28 +0530 Message-ID: <1369662568-22390-1-git-send-email-mkulkarni@nvidia.com> X-Mailer: git-send-email 1.8.1.5 X-NVConfidentiality: public MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 27 May 2013 22:27:21 -0700 Cc: Mayuresh Kulkarni , linux-kernel@vger.kernel.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org Errors-To: dri-devel-bounces+patchwork-dri-devel=patchwork.kernel.org@lists.freedesktop.org - as of now host1x and gr2d module's clocks are enabled in their driver's .probe and never disabled - this commit adds support for runtime pm in host1x and gr2d drivers - during boot-up clocks are enabled in .probe and disabled on its exit - when new work is submitted, clocks are enabled in submit and disabled when submit completes - parent->child relation between host1x and gr2d ensures that host1x clock is also enabled before enabling gr2d clock and it is turned off after gr2d clock is turned off Signed-off-by: Mayuresh Kulkarni --- drivers/gpu/host1x/channel.c | 5 ++++ drivers/gpu/host1x/dev.c | 58 ++++++++++++++++++++++++++++++++++++++---- drivers/gpu/host1x/drm/gr2d.c | 59 ++++++++++++++++++++++++++++++++++++++----- drivers/gpu/host1x/intr.c | 9 +++++-- 4 files changed, 118 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/host1x/channel.c b/drivers/gpu/host1x/channel.c index 83ea51b..b71caec 100644 --- a/drivers/gpu/host1x/channel.c +++ b/drivers/gpu/host1x/channel.c @@ -18,6 +18,7 @@ #include #include +#include #include "channel.h" #include "dev.h" @@ -41,6 +42,10 @@ int host1x_job_submit(struct host1x_job *job) { struct host1x *host = dev_get_drvdata(job->channel->dev->parent); + /* enable clocks + * they will be disabled in action_submit_complete */ + pm_runtime_get_sync(job->channel->dev); + return host1x_hw_channel_submit(host, job); } diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 28e28a2..93d9d72 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -23,6 +23,7 @@ #include #include #include +#include #define CREATE_TRACE_POINTS #include @@ -143,11 +144,11 @@ static int host1x_probe(struct platform_device *pdev) return err; } - err = clk_prepare_enable(host->clk); - if (err < 0) { - dev_err(&pdev->dev, "failed to enable clock\n"); - return err; - } + /* enable runtime pm */ + pm_runtime_enable(&pdev->dev); + + /* enable clocks */ + pm_runtime_get_sync(&pdev->dev); err = host1x_syncpt_init(host); if (err) { @@ -165,6 +166,9 @@ static int host1x_probe(struct platform_device *pdev) host1x_drm_alloc(pdev); + /* disable clocks */ + pm_runtime_put(&pdev->dev); + return 0; fail_deinit_syncpt: @@ -183,6 +187,47 @@ static int __exit host1x_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_RUNTIME +static int host1x_runtime_suspend(struct device *dev) +{ + struct host1x *host; + + host = dev_get_drvdata(dev); + if (IS_ERR_OR_NULL(host)) + return -EINVAL; + + clk_disable_unprepare(host->clk); + + return 0; +} + +static int host1x_runtime_resume(struct device *dev) +{ + int err = 0; + struct host1x *host; + + host = dev_get_drvdata(dev); + if (IS_ERR_OR_NULL(host)) + return -EINVAL; + + err = clk_prepare_enable(host->clk); + if (err < 0) + dev_err(dev, "failed to enable clock\n"); + + return err; +} +#endif /* CONFIG_PM_RUNTIME */ + +#ifdef CONFIG_PM +static const struct dev_pm_ops host1x_pm_ops = { +#ifdef CONFIG_PM_RUNTIME + .runtime_suspend = host1x_runtime_suspend, + .runtime_resume = host1x_runtime_resume, +#endif +}; + +#endif /* CONFIG_PM */ + static struct platform_driver tegra_host1x_driver = { .probe = host1x_probe, .remove = __exit_p(host1x_remove), @@ -190,6 +235,9 @@ static struct platform_driver tegra_host1x_driver = { .owner = THIS_MODULE, .name = "tegra-host1x", .of_match_table = host1x_of_match, +#ifdef CONFIG_PM + .pm = &host1x_pm_ops, +#endif }, }; diff --git a/drivers/gpu/host1x/drm/gr2d.c b/drivers/gpu/host1x/drm/gr2d.c index 6a45ae0..172a654 100644 --- a/drivers/gpu/host1x/drm/gr2d.c +++ b/drivers/gpu/host1x/drm/gr2d.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "channel.h" #include "drm.h" @@ -271,11 +272,13 @@ static int gr2d_probe(struct platform_device *pdev) return PTR_ERR(gr2d->clk); } - err = clk_prepare_enable(gr2d->clk); - if (err) { - dev_err(dev, "cannot turn on clock\n"); - return err; - } + platform_set_drvdata(pdev, gr2d); + + /* enable runtime pm */ + pm_runtime_enable(&pdev->dev); + + /* enable clocks */ + pm_runtime_get_sync(&pdev->dev); gr2d->channel = host1x_channel_request(dev); if (!gr2d->channel) @@ -301,7 +304,8 @@ static int gr2d_probe(struct platform_device *pdev) gr2d_init_addr_reg_map(dev, gr2d); - platform_set_drvdata(pdev, gr2d); + /* disable clocks */ + pm_runtime_put(&pdev->dev); return 0; } @@ -328,6 +332,46 @@ static int __exit gr2d_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_PM_RUNTIME +static int gr2d_runtime_suspend(struct device *dev) +{ + struct gr2d *gr2d; + + gr2d = dev_get_drvdata(dev); + if (IS_ERR_OR_NULL(gr2d)) + return -EINVAL; + + clk_disable_unprepare(gr2d->clk); + + return 0; +} + +static int gr2d_runtime_resume(struct device *dev) +{ + int err = 0; + struct gr2d *gr2d; + + gr2d = dev_get_drvdata(dev); + if (IS_ERR_OR_NULL(gr2d)) + return -EINVAL; + + err = clk_prepare_enable(gr2d->clk); + if (err < 0) + dev_err(dev, "failed to enable clock\n"); + + return err; +} +#endif /* CONFIG_PM_RUNTIME */ + +#ifdef CONFIG_PM +static const struct dev_pm_ops gr2d_pm_ops = { +#ifdef CONFIG_PM_RUNTIME + .runtime_suspend = gr2d_runtime_suspend, + .runtime_resume = gr2d_runtime_resume, +#endif +}; +#endif /* CONFIG_PM */ + struct platform_driver tegra_gr2d_driver = { .probe = gr2d_probe, .remove = __exit_p(gr2d_remove), @@ -335,5 +379,8 @@ struct platform_driver tegra_gr2d_driver = { .owner = THIS_MODULE, .name = "gr2d", .of_match_table = gr2d_match, +#ifdef CONFIG_PM + .pm = &gr2d_pm_ops, +#endif } }; diff --git a/drivers/gpu/host1x/intr.c b/drivers/gpu/host1x/intr.c index 2491bf8..c23fb64 100644 --- a/drivers/gpu/host1x/intr.c +++ b/drivers/gpu/host1x/intr.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include "channel.h" @@ -109,14 +110,18 @@ static void reset_threshold_interrupt(struct host1x *host, static void action_submit_complete(struct host1x_waitlist *waiter) { + int completed = waiter->count; struct host1x_channel *channel = waiter->data; + /* disable clocks for all the submits that got completed in this lot */ + while (completed--) + pm_runtime_put(channel->dev); + host1x_cdma_update(&channel->cdma); - /* Add nr_completed to trace */ + /* Add nr_completed to trace */ trace_host1x_channel_submit_complete(dev_name(channel->dev), waiter->count, waiter->thresh); - } static void action_wakeup(struct host1x_waitlist *waiter)