提交 7a9ecba7 编写于 作者: E Eric Anholt 提交者: Zheng Zengkai

drm/v3d: Clock V3D down when not in use.

raspberrypi inclusion
category: feature
bugzilla: 50432

--------------------------------

My various attempts at re-enabling runtime PM have failed, so just
crank the clock down when V3D is idle to reduce power consumption.
Signed-off-by: NEric Anholt <eric@anholt.net>
Signed-off-by: NFang Yafen <yafen@iscas.ac.cn>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 9798aa29
...@@ -289,6 +289,21 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) ...@@ -289,6 +289,21 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
} }
} }
v3d->clk = devm_clk_get(dev, NULL);
if (IS_ERR(v3d->clk)) {
if (ret != -EPROBE_DEFER)
dev_err(dev, "Failed to get clock\n");
goto dev_free;
}
v3d->clk_up_rate = clk_get_rate(v3d->clk);
/* For downclocking, drop it to the minimum frequency we can get from
* the CPRMAN clock generator dividing off our parent. The divider is
* 4 bits, but ask for just higher than that so that rounding doesn't
* make cprman reject our rate.
*/
v3d->clk_down_rate =
(clk_get_rate(clk_get_parent(v3d->clk)) / (1 << 4)) + 10000;
if (v3d->ver < 41) { if (v3d->ver < 41) {
ret = map_regs(v3d, &v3d->gca_regs, "gca"); ret = map_regs(v3d, &v3d->gca_regs, "gca");
if (ret) if (ret)
...@@ -315,6 +330,9 @@ static int v3d_platform_drm_probe(struct platform_device *pdev) ...@@ -315,6 +330,9 @@ static int v3d_platform_drm_probe(struct platform_device *pdev)
if (ret) if (ret)
goto irq_disable; goto irq_disable;
ret = clk_set_rate(v3d->clk, v3d->clk_down_rate);
WARN_ON_ONCE(ret != 0);
return 0; return 0;
irq_disable: irq_disable:
......
...@@ -51,6 +51,12 @@ struct v3d_dev { ...@@ -51,6 +51,12 @@ struct v3d_dev {
void __iomem *bridge_regs; void __iomem *bridge_regs;
void __iomem *gca_regs; void __iomem *gca_regs;
struct clk *clk; struct clk *clk;
struct delayed_work clk_down_work;
unsigned long clk_up_rate, clk_down_rate;
struct mutex clk_lock;
u32 clk_refcount;
bool clk_up;
struct reset_control *reset; struct reset_control *reset;
/* Virtual and DMA addresses of the single shared page table. */ /* Virtual and DMA addresses of the single shared page table. */
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/clk.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
...@@ -18,6 +19,47 @@ ...@@ -18,6 +19,47 @@
#include "v3d_regs.h" #include "v3d_regs.h"
#include "v3d_trace.h" #include "v3d_trace.h"
static void
v3d_clock_down_work(struct work_struct *work)
{
struct v3d_dev *v3d =
container_of(work, struct v3d_dev, clk_down_work.work);
int ret;
ret = clk_set_rate(v3d->clk, v3d->clk_down_rate);
v3d->clk_up = false;
WARN_ON_ONCE(ret != 0);
}
static void
v3d_clock_up_get(struct v3d_dev *v3d)
{
mutex_lock(&v3d->clk_lock);
if (v3d->clk_refcount++ == 0) {
cancel_delayed_work_sync(&v3d->clk_down_work);
if (!v3d->clk_up) {
int ret;
ret = clk_set_rate(v3d->clk, v3d->clk_up_rate);
WARN_ON_ONCE(ret != 0);
v3d->clk_up = true;
}
}
mutex_unlock(&v3d->clk_lock);
}
static void
v3d_clock_up_put(struct v3d_dev *v3d)
{
mutex_lock(&v3d->clk_lock);
if (--v3d->clk_refcount == 0) {
schedule_delayed_work(&v3d->clk_down_work,
msecs_to_jiffies(100));
}
mutex_unlock(&v3d->clk_lock);
}
static void static void
v3d_init_core(struct v3d_dev *v3d, int core) v3d_init_core(struct v3d_dev *v3d, int core)
{ {
...@@ -354,6 +396,7 @@ v3d_job_free(struct kref *ref) ...@@ -354,6 +396,7 @@ v3d_job_free(struct kref *ref)
struct v3d_job *job = container_of(ref, struct v3d_job, refcount); struct v3d_job *job = container_of(ref, struct v3d_job, refcount);
unsigned long index; unsigned long index;
struct dma_fence *fence; struct dma_fence *fence;
struct v3d_dev *v3d = job->v3d;
int i; int i;
for (i = 0; i < job->bo_count; i++) { for (i = 0; i < job->bo_count; i++) {
...@@ -367,11 +410,7 @@ v3d_job_free(struct kref *ref) ...@@ -367,11 +410,7 @@ v3d_job_free(struct kref *ref)
} }
xa_destroy(&job->deps); xa_destroy(&job->deps);
dma_fence_put(job->irq_fence); v3d_clock_up_put(v3d);
dma_fence_put(job->done_fence);
pm_runtime_mark_last_busy(job->v3d->drm.dev);
pm_runtime_put_autosuspend(job->v3d->drm.dev);
kfree(job); kfree(job);
} }
...@@ -453,6 +492,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv, ...@@ -453,6 +492,7 @@ v3d_job_init(struct v3d_dev *v3d, struct drm_file *file_priv,
if (ret) if (ret)
goto fail; goto fail;
v3d_clock_up_get(v3d);
kref_init(&job->refcount); kref_init(&job->refcount);
return 0; return 0;
...@@ -879,6 +919,9 @@ v3d_gem_init(struct drm_device *dev) ...@@ -879,6 +919,9 @@ v3d_gem_init(struct drm_device *dev)
mutex_init(&v3d->sched_lock); mutex_init(&v3d->sched_lock);
mutex_init(&v3d->cache_clean_lock); mutex_init(&v3d->cache_clean_lock);
mutex_init(&v3d->clk_lock);
INIT_DELAYED_WORK(&v3d->clk_down_work, v3d_clock_down_work);
/* Note: We don't allocate address 0. Various bits of HW /* Note: We don't allocate address 0. Various bits of HW
* treat 0 as special, such as the occlusion query counters * treat 0 as special, such as the occlusion query counters
* where 0 means "disabled". * where 0 means "disabled".
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册