From: HS Liao <hs.liao-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
To: Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Matthias Brugger
<matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Jassi Brar
<jassisinghbrar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Daniel Kurtz <djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
Sascha Hauer <s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org,
Sascha Hauer <kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
Philipp Zabel <p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>,
Nicolas Boichat
<drinkcat-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
CK HU <ck.hu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
cawa cheng <cawa.cheng-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Bibby Hsieh <bibby.hsieh-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
YT Shen <yt.shen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Daoyuan Huang
<daoyuan.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Damon Chu <damon.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Josh-YC Liu <josh-yc.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Glory Hung <glory.hung-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Jiaguang Zhang
<jiaguang.zhang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>,
Dennis-YC Hsieh
<dennis-yc.hsieh-NuS5LvNUpcLQFizaE/u3fw@public.gmane.org>
Subject: [PATCH v14 4/4] CMDQ: save more energy in idle
Date: Mon, 5 Sep 2016 09:44:45 +0800 [thread overview]
Message-ID: <1473039885-24009-5-git-send-email-hs.liao@mediatek.com> (raw)
In-Reply-To: <1473039885-24009-1-git-send-email-hs.liao-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
Use clk_disable_unprepare instead of clk_disable to save more energy
when CMDQ is idle.
Signed-off-by: HS Liao <hs.liao-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
---
drivers/mailbox/mtk-cmdq.c | 54 +++++++++++++++++++++++++++++++++++++++-------
1 file changed, 46 insertions(+), 8 deletions(-)
diff --git a/drivers/mailbox/mtk-cmdq.c b/drivers/mailbox/mtk-cmdq.c
index daf5561..0bf30cb 100644
--- a/drivers/mailbox/mtk-cmdq.c
+++ b/drivers/mailbox/mtk-cmdq.c
@@ -29,6 +29,7 @@
#include <linux/spinlock.h>
#include <linux/suspend.h>
#include <linux/timer.h>
+#include <linux/workqueue.h>
#define CMDQ_THR_MAX_COUNT 3 /* main, sub, general(misc) */
#define CMDQ_INST_SIZE 8 /* instruction is 64-bit */
@@ -130,10 +131,16 @@ struct cmdq_task {
struct cmdq_task_cb cb;
};
+struct cmdq_clk_release {
+ struct cmdq *cmdq;
+ struct work_struct release_work;
+};
+
struct cmdq {
struct mbox_controller mbox;
void __iomem *base;
u32 irq;
+ struct workqueue_struct *clk_release_wq;
struct cmdq_thread thread[CMDQ_THR_MAX_COUNT];
struct mutex task_mutex;
struct clk *clock;
@@ -279,11 +286,19 @@ static void cmdq_thread_wait_end(struct cmdq_thread *thread,
static void cmdq_task_exec(struct cmdq_task *task, struct cmdq_thread *thread)
{
struct cmdq *cmdq = task->cmdq;
- unsigned long curr_pa, end_pa;
+ unsigned long curr_pa, end_pa, flags;
task->thread = thread;
if (list_empty(&thread->task_busy_list)) {
- WARN_ON(clk_enable(cmdq->clock) < 0);
+ /*
+ * Unlock for clk prepare (sleeping function).
+ * We are safe to do that since we have task_mutex and
+ * only flush will add task.
+ */
+ spin_unlock_irqrestore(&thread->chan->lock, flags);
+ WARN_ON(clk_prepare_enable(cmdq->clock) < 0);
+ spin_lock_irqsave(&thread->chan->lock, flags);
+
WARN_ON(cmdq_thread_reset(cmdq, thread) < 0);
writel(task->pa_base, thread->base + CMDQ_THR_CURR_ADDR);
@@ -365,6 +380,26 @@ static void cmdq_task_handle_error(struct cmdq_task *task)
cmdq_thread_resume(thread);
}
+static void cmdq_clk_release_work(struct work_struct *work_item)
+{
+ struct cmdq_clk_release *clk_release = container_of(work_item,
+ struct cmdq_clk_release, release_work);
+ struct cmdq *cmdq = clk_release->cmdq;
+
+ clk_disable_unprepare(cmdq->clock);
+ kfree(clk_release);
+}
+
+static void cmdq_clk_release_schedule(struct cmdq *cmdq)
+{
+ struct cmdq_clk_release *clk_release;
+
+ clk_release = kmalloc(sizeof(*clk_release), GFP_ATOMIC);
+ clk_release->cmdq = cmdq;
+ INIT_WORK(&clk_release->release_work, cmdq_clk_release_work);
+ queue_work(cmdq->clk_release_wq, &clk_release->release_work);
+}
+
static void cmdq_thread_irq_handler(struct cmdq *cmdq,
struct cmdq_thread *thread)
{
@@ -414,7 +449,7 @@ static void cmdq_thread_irq_handler(struct cmdq *cmdq,
if (list_empty(&thread->task_busy_list)) {
cmdq_thread_disable(cmdq, thread);
- clk_disable(cmdq->clock);
+ cmdq_clk_release_schedule(cmdq);
} else {
mod_timer(&thread->timeout,
jiffies + msecs_to_jiffies(CMDQ_TIMEOUT_MS));
@@ -473,7 +508,7 @@ static void cmdq_thread_handle_timeout(unsigned long data)
cmdq_thread_resume(thread);
cmdq_thread_disable(cmdq, thread);
- clk_disable(cmdq->clock);
+ cmdq_clk_release_schedule(cmdq);
spin_unlock_irqrestore(&thread->chan->lock, flags);
}
@@ -761,7 +796,7 @@ static int cmdq_suspend(struct device *dev)
msleep(20);
}
- clk_unprepare(cmdq->clock);
+ flush_workqueue(cmdq->clk_release_wq);
return 0;
}
@@ -769,7 +804,6 @@ static int cmdq_resume(struct device *dev)
{
struct cmdq *cmdq = dev_get_drvdata(dev);
- WARN_ON(clk_prepare(cmdq->clock) < 0);
cmdq->suspended = false;
return 0;
}
@@ -778,8 +812,8 @@ static int cmdq_remove(struct platform_device *pdev)
{
struct cmdq *cmdq = platform_get_drvdata(pdev);
+ destroy_workqueue(cmdq->clk_release_wq);
mbox_controller_unregister(&cmdq->mbox);
- clk_unprepare(cmdq->clock);
return 0;
}
@@ -898,8 +932,12 @@ static int cmdq_probe(struct platform_device *pdev)
return err;
}
+ cmdq->clk_release_wq = alloc_ordered_workqueue(
+ "%s", WQ_MEM_RECLAIM | WQ_HIGHPRI,
+ "cmdq_clk_release");
+
platform_set_drvdata(pdev, cmdq);
- WARN_ON(clk_prepare(cmdq->clock) < 0);
+
return 0;
}
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-09-05 1:44 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-05 1:44 [PATCH v14 0/4] Mediatek MT8173 CMDQ support HS Liao
2016-09-05 1:44 ` [PATCH v14 1/4] dt-bindings: soc: Add documentation for the MediaTek GCE unit HS Liao
2016-09-05 1:44 ` [PATCH v14 2/4] CMDQ: Mediatek CMDQ driver HS Liao
2016-09-22 8:17 ` Jassi Brar
2016-09-23 9:28 ` Horng-Shyang Liao
2016-09-30 8:56 ` Horng-Shyang Liao
2016-09-30 3:06 ` CK Hu
2016-09-30 8:56 ` Horng-Shyang Liao
2016-09-30 9:11 ` CK Hu
2016-09-30 9:47 ` Horng-Shyang Liao
2016-10-05 2:54 ` Horng-Shyang Liao
2016-10-05 3:37 ` Jassi Brar
2016-10-05 12:31 ` Horng-Shyang Liao
2016-10-05 14:43 ` Jassi Brar
2016-10-06 13:01 ` Horng-Shyang Liao
2016-10-06 13:10 ` Jassi Brar
[not found] ` <CAJe_ZheptRQSmQp2gagqUyXqkOpi1qaTo8QPDTFpQ-+62B6kUw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-10-11 2:40 ` Horng-Shyang Liao
2016-10-11 4:19 ` Jassi Brar
[not found] ` <1473039885-24009-1-git-send-email-hs.liao-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-09-05 1:44 ` [PATCH v14 3/4] arm64: dts: mt8173: Add GCE node HS Liao
2016-09-05 1:44 ` HS Liao [this message]
[not found] ` <1473039885-24009-5-git-send-email-hs.liao-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org>
2016-09-22 7:52 ` [PATCH v14 4/4] CMDQ: save more energy in idle Jassi Brar
2016-09-23 9:28 ` Horng-Shyang Liao
2016-09-30 8:56 ` Horng-Shyang Liao
2016-09-30 9:01 ` Matthias Brugger
2016-09-19 6:43 ` [PATCH v14 0/4] Mediatek MT8173 CMDQ support Horng-Shyang Liao
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1473039885-24009-5-git-send-email-hs.liao@mediatek.com \
--to=hs.liao-nus5lvnupcjwk0htik3j/w@public.gmane.org \
--cc=bibby.hsieh-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=cawa.cheng-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=ck.hu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=damon.chu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=daoyuan.huang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=dennis-yc.hsieh-NuS5LvNUpcLQFizaE/u3fw@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=djkurtz-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=drinkcat-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
--cc=glory.hung-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=jassisinghbrar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=jiaguang.zhang-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=josh-yc.liu-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-mediatek-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=matthias.bgg-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=p.zabel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=s.hauer-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
--cc=srv_heupstream-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
--cc=yt.shen-NuS5LvNUpcJWk0Htik3J/w@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).