From patchwork Tue Nov 1 11:28:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hs.liao@mediatek.com X-Patchwork-Id: 9407209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 54FFA60585 for ; Tue, 1 Nov 2016 11:30:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BFD42973C for ; Tue, 1 Nov 2016 11:30:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D3FC29843; Tue, 1 Nov 2016 11:30:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 39D7B2973C for ; Tue, 1 Nov 2016 11:30:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1XGm-0001CD-FY; Tue, 01 Nov 2016 11:30:20 +0000 Received: from [210.61.82.183] (helo=mailgw01.mediatek.com) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c1XGG-0008Iv-Od; Tue, 01 Nov 2016 11:29:56 +0000 Received: from mtkhts07.mediatek.inc [(172.21.101.69)] by mailgw01.mediatek.com (envelope-from ) (mhqrelay.mediatek.com ESMTP with TLS) with ESMTP id 2028489936; Tue, 01 Nov 2016 19:29:23 +0800 Received: from mtkslt205.mediatek.inc (10.21.15.75) by mtkhts07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 14.3.266.1; Tue, 1 Nov 2016 19:29:21 +0800 From: HS Liao To: Rob Herring , Matthias Brugger , Jassi Brar Subject: [PATCH v16 4/5] CMDQ: suspend and resume Date: Tue, 1 Nov 2016 19:28:17 +0800 Message-ID: <1477999698-6288-5-git-send-email-hs.liao@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1477999698-6288-1-git-send-email-hs.liao@mediatek.com> References: <1477999698-6288-1-git-send-email-hs.liao@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161101_042949_421316_82A2EA94 X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Monica Wang , Jiaguang Zhang , Nicolas Boichat , cawa cheng , HS Liao , Bibby Hsieh , YT Shen , Damon Chu , devicetree@vger.kernel.org, Sascha Hauer , Daoyuan Huang , Sascha Hauer , Glory Hung , CK HU , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, srv_heupstream@mediatek.com, Josh-YC Liu , linux-kernel@vger.kernel.org, Dennis-YC Hsieh , Philipp Zabel Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP take suspend and resume into consideration Signed-off-by: HS Liao --- drivers/mailbox/mtk-cmdq-mailbox.c | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/drivers/mailbox/mtk-cmdq-mailbox.c b/drivers/mailbox/mtk-cmdq-mailbox.c index d086fd8..747bcd3 100644 --- a/drivers/mailbox/mtk-cmdq-mailbox.c +++ b/drivers/mailbox/mtk-cmdq-mailbox.c @@ -81,6 +81,7 @@ struct cmdq { u32 irq; struct cmdq_thread thread[CMDQ_THR_MAX_COUNT]; struct clk *clock; + bool suspended; }; static int cmdq_thread_suspend(struct cmdq *cmdq, struct cmdq_thread *thread) @@ -206,6 +207,9 @@ static void cmdq_task_exec(struct cmdq_pkt *pkt, struct cmdq_thread *thread) cmdq = dev_get_drvdata(thread->chan->mbox->dev); + /* Client should not flush new tasks if suspended. */ + WARN_ON(cmdq->suspended); + task = kzalloc(sizeof(*task), GFP_ATOMIC); task->cmdq = cmdq; INIT_LIST_HEAD(&task->list_entry); @@ -409,6 +413,39 @@ static void cmdq_thread_handle_timeout(unsigned long data) spin_unlock_irqrestore(&thread->chan->lock, flags); } +static int cmdq_suspend(struct device *dev) +{ + struct cmdq *cmdq = dev_get_drvdata(dev); + struct cmdq_thread *thread; + int i; + bool task_running = false; + + cmdq->suspended = true; + + for (i = 0; i < ARRAY_SIZE(cmdq->thread); i++) { + thread = &cmdq->thread[i]; + if (!list_empty(&thread->task_busy_list)) { + task_running = true; + break; + } + } + + if (task_running) + dev_warn(dev, "exist running task(s) in suspend\n"); + + clk_unprepare(cmdq->clock); + return 0; +} + +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; +} + static int cmdq_remove(struct platform_device *pdev) { struct cmdq *cmdq = platform_get_drvdata(pdev); @@ -532,9 +569,15 @@ static int cmdq_probe(struct platform_device *pdev) platform_set_drvdata(pdev, cmdq); WARN_ON(clk_prepare(cmdq->clock) < 0); + return 0; } +static const struct dev_pm_ops cmdq_pm_ops = { + .suspend = cmdq_suspend, + .resume = cmdq_resume, +}; + static const struct of_device_id cmdq_of_ids[] = { {.compatible = "mediatek,mt8173-gce",}, {} @@ -545,6 +588,7 @@ static int cmdq_probe(struct platform_device *pdev) .remove = cmdq_remove, .driver = { .name = "mtk_cmdq", + .pm = &cmdq_pm_ops, .of_match_table = cmdq_of_ids, } };