diff mbox

[PATCHv3,2/4] drm/tegra: Add runtime pm support for gr2d

Message ID 1380024325-18280-3-git-send-email-amerilainen@nvidia.com (mailing list archive)
State New, archived
Headers show

Commit Message

Arto Merilainen Sept. 24, 2013, 12:05 p.m. UTC
From: Mayuresh Kulkarni <mkulkarni@nvidia.com>

This far we have enabled gr2d clock on device probe and disabled
it on device deinitialisation. This patch adds runtime pm support
for the hardware unit allowing dynamic power management. If pm
runtime is not enabled, gr2d clock is enabled in device probe and
disabled in remove.

Signed-off-by: Mayuresh Kulkarni <mkulkarni@nvidia.com>
Signed-off-by: Arto Merilainen <amerilainen@nvidia.com>
---
 drivers/gpu/host1x/drm/gr2d.c | 57 +++++++++++++++++++++++++++++++++++++++----
 drivers/gpu/host1x/job.c      |  5 ++--
 2 files changed, 55 insertions(+), 7 deletions(-)

Comments

Stephen Warren Oct. 1, 2013, 6:14 p.m. UTC | #1
On 09/24/2013 06:05 AM, Arto Merilainen wrote:
> From: Mayuresh Kulkarni <mkulkarni@nvidia.com>
> 
> This far we have enabled gr2d clock on device probe and disabled
> it on device deinitialisation. This patch adds runtime pm support
> for the hardware unit allowing dynamic power management. If pm
> runtime is not enabled, gr2d clock is enabled in device probe and

> diff --git a/drivers/gpu/host1x/drm/gr2d.c b/drivers/gpu/host1x/drm/gr2d.c

> @@ -327,11 +336,48 @@ static int __exit gr2d_remove(struct platform_device *pdev)
>  		host1x_syncpt_free(gr2d->client.syncpts[i]);
>  
>  	host1x_channel_free(gr2d->channel);
> +
> +	if (pm_runtime_enabled(&pdev->dev))
> +		pm_runtime_disable(&pdev->dev);
> +	else
> +		gr2d_runtime_suspend(&pdev->dev);

This code is slightly different to the code in e.g.
sound/soc/tegra/tegra20_i2s.c:remove(), whereas the code in probe() is
identical. I'm not sure whether there's some advantage in this version?
If so, perhaps the sound drivers should be updated to be consistent. If
not, perhaps this driver should do the same thing as the I2S driver, so
we keep the drivers consistent, and provide the same "example" code
everywhere.

> +static int gr2d_runtime_suspend(struct device *dev)
> +{
> +	struct gr2d *gr2d;
> +
> +	gr2d = dev_get_drvdata(dev);
> +	if (!gr2d)
> +		return -EINVAL;

Presumably, gr2d will never be NULL here, unless there's some chronic
bug. Can't we re-write those last 5 lines as simply:

	struct gr2d *grd2 = dev_get_drvdata(dev);

If that's not valid, we should probably update the audio drivers (and
perhaps others) too.
Arto Merilainen Oct. 2, 2013, 5:40 a.m. UTC | #2
On 10/01/2013 09:14 PM, Stephen Warren wrote:
> On 09/24/2013 06:05 AM, Arto Merilainen wrote:
>> diff --git a/drivers/gpu/host1x/drm/gr2d.c b/drivers/gpu/host1x/drm/gr2d.c
>
>> @@ -327,11 +336,48 @@ static int __exit gr2d_remove(struct platform_device *pdev)
>>   		host1x_syncpt_free(gr2d->client.syncpts[i]);
>>
>>   	host1x_channel_free(gr2d->channel);
>> +
>> +	if (pm_runtime_enabled(&pdev->dev))
>> +		pm_runtime_disable(&pdev->dev);
>> +	else
>> +		gr2d_runtime_suspend(&pdev->dev);
>
> This code is slightly different to the code in e.g.
> sound/soc/tegra/tegra20_i2s.c:remove(), whereas the code in probe() is
> identical. I'm not sure whether there's some advantage in this version?
> If so, perhaps the sound drivers should be updated to be consistent. If
> not, perhaps this driver should do the same thing as the I2S driver, so
> we keep the drivers consistent, and provide the same "example" code
> everywhere.

Hmm. I cannot immediately see any advantage in this version... I will 
update the patch.

>
>> +static int gr2d_runtime_suspend(struct device *dev)
>> +{
>> +	struct gr2d *gr2d;
>> +
>> +	gr2d = dev_get_drvdata(dev);
>> +	if (!gr2d)
>> +		return -EINVAL;
>
> Presumably, gr2d will never be NULL here, unless there's some chronic
> bug. Can't we re-write those last 5 lines as simply:
>
> 	struct gr2d *grd2 = dev_get_drvdata(dev);
>
> If that's not valid, we should probably update the audio drivers (and
> perhaps others) too.

I think you are correct. I cannot see any reason why that check is required.

- Arto
diff mbox

Patch

diff --git a/drivers/gpu/host1x/drm/gr2d.c b/drivers/gpu/host1x/drm/gr2d.c
index 27ffcf1..8d92925 100644
--- a/drivers/gpu/host1x/drm/gr2d.c
+++ b/drivers/gpu/host1x/drm/gr2d.c
@@ -22,6 +22,7 @@ 
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/clk.h>
+#include <linux/pm_runtime.h>
 
 #include "channel.h"
 #include "drm.h"
@@ -45,6 +46,8 @@  static inline struct gr2d *to_gr2d(struct host1x_client *client)
 }
 
 static int gr2d_is_addr_reg(struct device *dev, u32 class, u32 reg);
+static int gr2d_runtime_suspend(struct device *dev);
+static int gr2d_runtime_resume(struct device *dev);
 
 static int gr2d_client_init(struct host1x_client *client,
 			    struct drm_device *drm)
@@ -275,12 +278,18 @@  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;
+	/* pm runtime accesses the clock through driver data */
+	platform_set_drvdata(pdev, gr2d);
+
+	pm_runtime_enable(&pdev->dev);
+	if (!pm_runtime_enabled(&pdev->dev)) {
+		err = gr2d_runtime_resume(&pdev->dev);
+		if (err < 0)
+			return err;
 	}
 
+	pm_runtime_get_sync(&pdev->dev);
+
 	gr2d->channel = host1x_channel_request(dev);
 	if (!gr2d->channel)
 		return -ENOMEM;
@@ -305,7 +314,7 @@  static int gr2d_probe(struct platform_device *pdev)
 
 	gr2d_init_addr_reg_map(dev, gr2d);
 
-	platform_set_drvdata(pdev, gr2d);
+	pm_runtime_put(&pdev->dev);
 
 	return 0;
 }
@@ -327,11 +336,48 @@  static int __exit gr2d_remove(struct platform_device *pdev)
 		host1x_syncpt_free(gr2d->client.syncpts[i]);
 
 	host1x_channel_free(gr2d->channel);
+
+	if (pm_runtime_enabled(&pdev->dev))
+		pm_runtime_disable(&pdev->dev);
+	else
+		gr2d_runtime_suspend(&pdev->dev);
+
+	return 0;
+}
+
+static int gr2d_runtime_suspend(struct device *dev)
+{
+	struct gr2d *gr2d;
+
+	gr2d = dev_get_drvdata(dev);
+	if (!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 (!gr2d)
+		return -EINVAL;
+
+	err = clk_prepare_enable(gr2d->clk);
+	if (err < 0)
+		dev_err(dev, "failed to enable clock\n");
+
+	return err;
+}
+
+static const struct dev_pm_ops gr2d_pm_ops = {
+	SET_RUNTIME_PM_OPS(gr2d_runtime_suspend, gr2d_runtime_resume, NULL)
+};
+
 struct platform_driver tegra_gr2d_driver = {
 	.probe = gr2d_probe,
 	.remove = __exit_p(gr2d_remove),
@@ -339,5 +385,6 @@  struct platform_driver tegra_gr2d_driver = {
 		.owner = THIS_MODULE,
 		.name = "gr2d",
 		.of_match_table = gr2d_match,
+		.pm = &gr2d_pm_ops,
 	}
 };
diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c
index 3928b4e..e4148e0 100644
--- a/drivers/gpu/host1x/job.c
+++ b/drivers/gpu/host1x/job.c
@@ -23,6 +23,7 @@ 
 #include <linux/scatterlist.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/pm_runtime.h>
 #include <trace/events/host1x.h>
 
 #include "channel.h"
@@ -589,11 +590,11 @@  void host1x_job_dump(struct device *dev, struct host1x_job *job)
 int host1x_job_submit(struct host1x_job *job)
 {
 	struct host1x *host = dev_get_drvdata(job->channel->dev->parent);
-
+	pm_runtime_get_sync(job->channel->dev);
 	return host1x_hw_channel_submit(host, job);
 }
 
 int host1x_job_complete(struct host1x_job *job)
 {
-	return 0;
+	return pm_runtime_put(job->channel->dev);
 }