This series adds runtime pm support for host1x, gr2d and dc. It retains the current behaviour if CONFIG_PM_RUNTIME is not enabled.
The gr2d clock is enabled when a new job is submitted and disabled when the work is done. Due to parent->child relations between host1x->gr2d, this scheme enables and disables host1x clock.
For dc, the clocks are enabled in .probe and disabled in .remove via runtime pm instead of direct clock APIs.
Mayuresh is unfortunately not available to continue with the series and hence I will continue working on the patches.
Changes in v3: - Rebased patches on top of 3.12-rc2 - Removed unnecessary #ifdefs - Added descriptions to commit messages - If runtime pm is disabled, the code calls suspend/resume functions for enabling/disabling the clocks instead of repeating the functions
Mayuresh Kulkarni (4): gpu: host1x: shuffle job APIs drm/tegra: Add runtime pm support for gr2d drm/tegra: Add runtime pm support for dc gpu: host1x: Add runtime pm support for host1x
drivers/gpu/host1x/cdma.c | 2 ++ drivers/gpu/host1x/channel.c | 8 ------ drivers/gpu/host1x/channel.h | 1 - drivers/gpu/host1x/dev.c | 57 +++++++++++++++++++++++++++++++++++++++--- drivers/gpu/host1x/drm/dc.c | 58 +++++++++++++++++++++++++++++++++++++++---- drivers/gpu/host1x/drm/gr2d.c | 57 ++++++++++++++++++++++++++++++++++++++---- drivers/gpu/host1x/job.c | 13 ++++++++++ drivers/gpu/host1x/job.h | 3 +++ 8 files changed, 176 insertions(+), 23 deletions(-)
From: Mayuresh Kulkarni mkulkarni@nvidia.com
This patch moves function host1x_job_submit() to job.c file where all other host1x_job_* functions are placed. This patch also introduces function host1x_job_complete().
Signed-off-by: Mayuresh Kulkarni mkulkarni@nvidia.com Signed-off-by: Arto Merilainen amerilainen@nvidia.com --- drivers/gpu/host1x/cdma.c | 2 ++ drivers/gpu/host1x/channel.c | 8 -------- drivers/gpu/host1x/channel.h | 1 - drivers/gpu/host1x/job.c | 12 ++++++++++++ drivers/gpu/host1x/job.h | 3 +++ 5 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/host1x/cdma.c b/drivers/gpu/host1x/cdma.c index de72172..910087b 100644 --- a/drivers/gpu/host1x/cdma.c +++ b/drivers/gpu/host1x/cdma.c @@ -252,6 +252,8 @@ static void update_cdma_locked(struct host1x_cdma *cdma) signal = true; }
+ host1x_job_complete(job); + list_del(&job->list); host1x_job_put(job); } diff --git a/drivers/gpu/host1x/channel.c b/drivers/gpu/host1x/channel.c index 83ea51b..c381441 100644 --- a/drivers/gpu/host1x/channel.c +++ b/drivers/gpu/host1x/channel.c @@ -21,7 +21,6 @@
#include "channel.h" #include "dev.h" -#include "job.h"
/* Constructor for the host1x device list */ int host1x_channel_list_init(struct host1x *host) @@ -37,13 +36,6 @@ int host1x_channel_list_init(struct host1x *host) return 0; }
-int host1x_job_submit(struct host1x_job *job) -{ - struct host1x *host = dev_get_drvdata(job->channel->dev->parent); - - return host1x_hw_channel_submit(host, job); -} - struct host1x_channel *host1x_channel_get(struct host1x_channel *channel) { int err = 0; diff --git a/drivers/gpu/host1x/channel.h b/drivers/gpu/host1x/channel.h index 48723b8..8401f25 100644 --- a/drivers/gpu/host1x/channel.h +++ b/drivers/gpu/host1x/channel.h @@ -44,7 +44,6 @@ struct host1x_channel *host1x_channel_request(struct device *dev); void host1x_channel_free(struct host1x_channel *channel); struct host1x_channel *host1x_channel_get(struct host1x_channel *channel); void host1x_channel_put(struct host1x_channel *channel); -int host1x_job_submit(struct host1x_job *job);
#define host1x_for_each_channel(host, channel) \ list_for_each_entry(channel, &host->chlist.list, list) diff --git a/drivers/gpu/host1x/job.c b/drivers/gpu/host1x/job.c index c4e1050..3928b4e 100644 --- a/drivers/gpu/host1x/job.c +++ b/drivers/gpu/host1x/job.c @@ -585,3 +585,15 @@ void host1x_job_dump(struct device *dev, struct host1x_job *job) dev_dbg(dev, " NUM_SLOTS %d\n", job->num_slots); dev_dbg(dev, " NUM_HANDLES %d\n", job->num_unpins); } + +int host1x_job_submit(struct host1x_job *job) +{ + struct host1x *host = dev_get_drvdata(job->channel->dev->parent); + + return host1x_hw_channel_submit(host, job); +} + +int host1x_job_complete(struct host1x_job *job) +{ + return 0; +} diff --git a/drivers/gpu/host1x/job.h b/drivers/gpu/host1x/job.h index fba45f2..e0249c3 100644 --- a/drivers/gpu/host1x/job.h +++ b/drivers/gpu/host1x/job.h @@ -159,4 +159,7 @@ void host1x_job_unpin(struct host1x_job *job); */ void host1x_job_dump(struct device *dev, struct host1x_job *job);
+int host1x_job_submit(struct host1x_job *job); +int host1x_job_complete(struct host1x_job *job); + #endif
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(-)
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); }
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.
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
From: Mayuresh Kulkarni mkulkarni@nvidia.com
This patch adds initial runtime pm support for Tegra display controller. As of now, the dc clock is enabled in device probe via runtime pm and disabled in device remove. In case pm runtime is not configured, we simply enable the clock in device probe (..and disable it in remove).
Signed-off-by: Mayuresh Kulkarni mkulkarni@nvidia.com Signed-off-by: Arto Merilainen amerilainen@nvidia.com --- drivers/gpu/host1x/drm/dc.c | 58 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c index b1a05ad..6d1d5fc 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" @@ -24,6 +25,9 @@ struct tegra_plane { unsigned int index; };
+static int tegra_dc_runtime_suspend(struct device *dev); +static int tegra_dc_runtime_resume(struct device *dev); + static inline struct tegra_plane *to_tegra_plane(struct drm_plane *plane) { return container_of(plane, struct tegra_plane, base); @@ -1128,9 +1132,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 +1149,15 @@ static int tegra_dc_probe(struct platform_device *pdev) dc->client.ops = &dc_client_ops; dc->client.dev = &pdev->dev;
+ pm_runtime_enable(&pdev->dev); + if (!pm_runtime_enabled(&pdev->dev)) { + err = tegra_dc_runtime_resume(&pdev->dev); + if (err < 0) + return err; + } + + pm_runtime_get_sync(&pdev->dev); + 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 +1171,6 @@ static int tegra_dc_probe(struct platform_device *pdev) return err; }
- platform_set_drvdata(pdev, dc); - return 0; }
@@ -1178,11 +1187,49 @@ static int tegra_dc_remove(struct platform_device *pdev) return err; }
+ pm_runtime_put(&pdev->dev); + if (pm_runtime_enabled(&pdev->dev)) + pm_runtime_disable(&pdev->dev); + else + tegra_dc_runtime_suspend(&pdev->dev); + + return 0; +} + +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; +} + +static const struct dev_pm_ops tegra_dc_pm_ops = { + SET_RUNTIME_PM_OPS(tegra_dc_runtime_suspend, + tegra_dc_runtime_resume, NULL) +}; + static struct of_device_id tegra_dc_of_match[] = { { .compatible = "nvidia,tegra30-dc", }, { .compatible = "nvidia,tegra20-dc", }, @@ -1194,6 +1241,7 @@ struct platform_driver tegra_dc_driver = { .name = "tegra-dc", .owner = THIS_MODULE, .of_match_table = tegra_dc_of_match, + .pm = &tegra_dc_pm_ops, }, .probe = tegra_dc_probe, .remove = tegra_dc_remove,
From: Mayuresh Kulkarni mkulkarni@nvidia.com
This patch adds runtime pm support for host1x hardware unit. This allows host1x clock to be turned off when it is idle. If pm runtime is not configured, we enable host1x clock in device probe and disable it in remove.
Signed-off-by: Mayuresh Kulkarni mkulkarni@nvidia.com Signed-off-by: Arto Merilainen amerilainen@nvidia.com --- drivers/gpu/host1x/dev.c | 57 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-)
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c index 4716302..5f0b91e 100644 --- a/drivers/gpu/host1x/dev.c +++ b/drivers/gpu/host1x/dev.c @@ -23,6 +23,7 @@ #include <linux/of_device.h> #include <linux/clk.h> #include <linux/io.h> +#include <linux/pm_runtime.h>
#define CREATE_TRACE_POINTS #include <trace/events/host1x.h> @@ -34,6 +35,9 @@ #include "hw/host1x01.h" #include "host1x_client.h"
+static int host1x_runtime_suspend(struct device *dev); +static int host1x_runtime_resume(struct device *dev); + void host1x_set_drm_data(struct device *dev, void *data) { struct host1x *host1x = dev_get_drvdata(dev); @@ -143,12 +147,15 @@ 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; + pm_runtime_enable(&pdev->dev); + if (!pm_runtime_enabled(&pdev->dev)) { + err = host1x_runtime_resume(&pdev->dev); + if (err < 0) + return err; }
+ pm_runtime_get_sync(&pdev->dev); + err = host1x_syncpt_init(host); if (err) { dev_err(&pdev->dev, "failed to initialize syncpts\n"); @@ -165,10 +172,14 @@ static int host1x_probe(struct platform_device *pdev)
host1x_drm_alloc(pdev);
+ pm_runtime_put(&pdev->dev); + return 0;
fail_deinit_syncpt: host1x_syncpt_deinit(host); + pm_runtime_put(&pdev->dev); + pm_runtime_disable(&pdev->dev); return err; }
@@ -178,11 +189,48 @@ static int __exit host1x_remove(struct platform_device *pdev)
host1x_intr_deinit(host); host1x_syncpt_deinit(host); + + if (pm_runtime_enabled(&pdev->dev)) + pm_runtime_disable(&pdev->dev); + else + host1x_runtime_suspend(&pdev->dev); + + return 0; +} + +static int host1x_runtime_suspend(struct device *dev) +{ + struct host1x *host; + + host = dev_get_drvdata(dev); + if (!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 (!host) + return -EINVAL; + + err = clk_prepare_enable(host->clk); + if (err < 0) + dev_err(dev, "failed to enable clock\n"); + + return err; +} + +static const struct dev_pm_ops host1x_pm_ops = { + SET_RUNTIME_PM_OPS(host1x_runtime_suspend, host1x_runtime_resume, NULL) +}; + static struct platform_driver tegra_host1x_driver = { .probe = host1x_probe, .remove = __exit_p(host1x_remove), @@ -190,6 +238,7 @@ static struct platform_driver tegra_host1x_driver = { .owner = THIS_MODULE, .name = "tegra-host1x", .of_match_table = host1x_of_match, + .pm = &host1x_pm_ops, }, };
On 09/24/2013 06:05 AM, Arto Merilainen wrote:
From: Mayuresh Kulkarni mkulkarni@nvidia.com
This patch adds runtime pm support for host1x hardware unit. This allows host1x clock to be turned off when it is idle. If pm runtime is not configured, we enable host1x clock in device probe and disable it in remove.
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
+static int host1x_runtime_suspend(struct device *dev); +static int host1x_runtime_resume(struct device *dev);
You could avoid having these prototypes by simply putting the function bodies earlier on in the file, somewhere before they're used. I don't care much either way, but I've certainly seen some people care about this and ask for them to be moved.
On 10/01/2013 09:17 PM, Stephen Warren wrote:
On 09/24/2013 06:05 AM, Arto Merilainen wrote:
From: Mayuresh Kulkarni mkulkarni@nvidia.com
This patch adds runtime pm support for host1x hardware unit. This allows host1x clock to be turned off when it is idle. If pm runtime is not configured, we enable host1x clock in device probe and disable it in remove.
diff --git a/drivers/gpu/host1x/dev.c b/drivers/gpu/host1x/dev.c
+static int host1x_runtime_suspend(struct device *dev); +static int host1x_runtime_resume(struct device *dev);
You could avoid having these prototypes by simply putting the function bodies earlier on in the file, somewhere before they're used. I don't care much either way, but I've certainly seen some people care about this and ask for them to be moved.
Will fix.
- Arto
dri-devel@lists.freedesktop.org