diff mbox

[v2,3/4] gpu: host1x: add runtime pm support for dc

Message ID 1371117218-2326-4-git-send-email-mkulkarni@nvidia.com
State Not Applicable, archived
Headers show

Commit Message

Mayuresh Kulkarni June 13, 2013, 9:53 a.m. UTC
As of now, the dc clock is enabled in its .probe via
runtime pm and disabled in .remove

Signed-off-by: Mayuresh Kulkarni <mkulkarni@nvidia.com>
---
 drivers/gpu/host1x/drm/dc.c | 60 +++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 55 insertions(+), 5 deletions(-)

Comments

Thierry Reding June 13, 2013, 6:49 p.m. UTC | #1
On Thu, Jun 13, 2013 at 03:23:37PM +0530, Mayuresh Kulkarni wrote:
[...]
> diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
[...]
> @@ -1128,9 +1129,7 @@ static int tegra_dc_probe(struct platform_device *pdev)
>  		return PTR_ERR(dc->clk);
>  	}
>  
> -	err = clk_prepare_enable(dc->clk);
> -	if (err < 0)
> -		return err;
> +	platform_set_drvdata(pdev, dc);

Why do you move the call to platform_set_drvdata() up here?

Thierry
Stephen Warren June 13, 2013, 7:09 p.m. UTC | #2
On 06/13/2013 12:49 PM, Thierry Reding wrote:
> On Thu, Jun 13, 2013 at 03:23:37PM +0530, Mayuresh Kulkarni wrote: 
> [...]
>> diff --git a/drivers/gpu/host1x/drm/dc.c
>> b/drivers/gpu/host1x/drm/dc.c
> [...]
>> @@ -1128,9 +1129,7 @@ static int tegra_dc_probe(struct
>> platform_device *pdev) return PTR_ERR(dc->clk); }
>> 
>> -	err = clk_prepare_enable(dc->clk); -	if (err < 0) -		return
>> err; +	platform_set_drvdata(pdev, dc);
> 
> Why do you move the call to platform_set_drvdata() up here?

Presumably the suspend/resume functions need to get the value out of
the device they're passed, so it needs to be set up early?

--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mayuresh Kulkarni June 14, 2013, 2:48 p.m. UTC | #3
On Friday 14 June 2013 12:39 AM, Stephen Warren wrote:
> On 06/13/2013 12:49 PM, Thierry Reding wrote:
>> On Thu, Jun 13, 2013 at 03:23:37PM +0530, Mayuresh Kulkarni wrote:
>> [...]
>>> diff --git a/drivers/gpu/host1x/drm/dc.c
>>> b/drivers/gpu/host1x/drm/dc.c
>> [...]
>>> @@ -1128,9 +1129,7 @@ static int tegra_dc_probe(struct
>>> platform_device *pdev) return PTR_ERR(dc->clk); }
>>>
>>> -	err = clk_prepare_enable(dc->clk); -	if (err < 0) -		return
>>> err; +	platform_set_drvdata(pdev, dc);
>>
>> Why do you move the call to platform_set_drvdata() up here?
>
> Presumably the suspend/resume functions need to get the value out of
> the device they're passed, so it needs to be set up early?
>

Yes that is correct, Stephen. The run-time pm call-backs need 2 things: 
correct driver data pointer and correct clock pointer within it. Hence I 
had to move this line upper in sequence.

Same is applicable to gr2d and host1x patches as well.
--
To unsubscribe from this list: send the line "unsubscribe linux-tegra" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
index 5360e5a..8e669a9 100644
--- a/drivers/gpu/host1x/drm/dc.c
+++ b/drivers/gpu/host1x/drm/dc.c
@@ -13,6 +13,7 @@ 
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/clk/tegra.h>
+#include <linux/pm_runtime.h>
 
 #include "host1x_client.h"
 #include "dc.h"
@@ -1128,9 +1129,7 @@  static int tegra_dc_probe(struct platform_device *pdev)
 		return PTR_ERR(dc->clk);
 	}
 
-	err = clk_prepare_enable(dc->clk);
-	if (err < 0)
-		return err;
+	platform_set_drvdata(pdev, dc);
 
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	dc->regs = devm_ioremap_resource(&pdev->dev, regs);
@@ -1147,6 +1146,15 @@  static int tegra_dc_probe(struct platform_device *pdev)
 	dc->client.ops = &dc_client_ops;
 	dc->client.dev = &pdev->dev;
 
+#ifdef CONFIG_PM_RUNTIME
+	pm_runtime_enable(&pdev->dev);
+	pm_runtime_get_sync(&pdev->dev);
+#else
+	err = clk_prepare_enable(dc->clk);
+	if (err < 0)
+		return err;
+#endif
+
 	err = tegra_dc_rgb_probe(dc);
 	if (err < 0 && err != -ENODEV) {
 		dev_err(&pdev->dev, "failed to probe RGB output: %d\n", err);
@@ -1160,8 +1168,6 @@  static int tegra_dc_probe(struct platform_device *pdev)
 		return err;
 	}
 
-	platform_set_drvdata(pdev, dc);
-
 	return 0;
 }
 
@@ -1178,11 +1184,52 @@  static int tegra_dc_remove(struct platform_device *pdev)
 		return err;
 	}
 
+#ifdef CONFIG_PM_RUNTIME
+	pm_runtime_put(&pdev->dev);
+	pm_runtime_disable(&pdev->dev);
+#endif
+
+	return 0;
+}
+
+#ifdef CONFIG_PM_RUNTIME
+static int tegra_dc_runtime_suspend(struct device *dev)
+{
+	struct tegra_dc *dc;
+
+	dc = dev_get_drvdata(dev);
+	if (!dc)
+		return -EINVAL;
+
 	clk_disable_unprepare(dc->clk);
 
 	return 0;
 }
 
+static int tegra_dc_runtime_resume(struct device *dev)
+{
+	int err = 0;
+	struct tegra_dc *dc;
+
+	dc = dev_get_drvdata(dev);
+	if (!dc)
+		return -EINVAL;
+
+	err = clk_prepare_enable(dc->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 tegra_dc_pm_ops = {
+	SET_RUNTIME_PM_OPS(tegra_dc_runtime_suspend,
+		tegra_dc_runtime_resume, NULL)
+};
+#endif
+
 static struct of_device_id tegra_dc_of_match[] = {
 	{ .compatible = "nvidia,tegra30-dc", },
 	{ .compatible = "nvidia,tegra20-dc", },
@@ -1194,6 +1241,9 @@  struct platform_driver tegra_dc_driver = {
 		.name = "tegra-dc",
 		.owner = THIS_MODULE,
 		.of_match_table = tegra_dc_of_match,
+#ifdef CONFIG_PM
+		.pm = &tegra_dc_pm_ops,
+#endif
 	},
 	.probe = tegra_dc_probe,
 	.remove = tegra_dc_remove,