From patchwork Wed Nov 26 09:44:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Padmavathi Venna X-Patchwork-Id: 5384571 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id B4CADC11AC for ; Wed, 26 Nov 2014 09:54:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CF25720145 for ; Wed, 26 Nov 2014 09:54:48 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D94CE20121 for ; Wed, 26 Nov 2014 09:54:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtZGo-0007rG-UY; Wed, 26 Nov 2014 09:52:22 +0000 Received: from mailout4.samsung.com ([203.254.224.34]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XtZGj-0007pT-Mg for linux-arm-kernel@lists.infradead.org; Wed, 26 Nov 2014 09:52:20 +0000 Received: from epcpsbgr5.samsung.com (u145.gpu120.samsung.co.kr [203.254.230.145]) by mailout4.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0NFN00I2B4Q0MT20@mailout4.samsung.com> for linux-arm-kernel@lists.infradead.org; Wed, 26 Nov 2014 18:51:36 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.122]) by epcpsbgr5.samsung.com (EPCPMTA) with SMTP id 32.B0.19034.8A2A5745; Wed, 26 Nov 2014 18:51:36 +0900 (KST) X-AuditID: cbfee691-f79b86d000004a5a-4a-5475a2a890d9 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 79.57.09430.8A2A5745; Wed, 26 Nov 2014 18:51:36 +0900 (KST) Received: from chromebld-server.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0NFN00JK14P7Y390@mmp1.samsung.com>; Wed, 26 Nov 2014 18:51:35 +0900 (KST) From: Padmavathi Venna To: linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, dmaengine@vger.kernel.org Subject: [PATCH] dmaengine: pl330: Set residue in tx_status callback Date: Wed, 26 Nov 2014 15:14:55 +0530 Message-id: <1416995095-13763-1-git-send-email-padma.v@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrILMWRmVeSWpSXmKPExsWyRsSkSnfFotIQg9WzBC2mPnzCZjH/xC02 i9VT/7JaLJk8n9Vi0+NrrBYzzu9jsnjZt5/Fgd1jdsNFFo/Fe14yeWxa1cnmsXlJvceSN4dY PT5vkgtgi+KySUnNySxLLdK3S+DKOLTrMVNBk3TFm+teDYxTxLoYOTkkBEwk/u5Ywwhhi0lc uLeerYuRi0NIYCmjxLsL85hgip6sucUMYgsJLGKUaFjPDlE0gUmi+/VJIIeDg01AR6LlrAuI KSKQIbHvtjhIObNAosSnTXvBWoUFXCRWXV7MAmKzCKhKzPu8hhmknFfAWWL5TWEQU0JAQWLO JBuIpc3sEvun20FUC0h8m3yIBaJEVmLTAWaIEkmJgytusExgFFzAyLCKUTS1ILmgOCm9yFSv ODG3uDQvXS85P3cTIzBkT/97NnEH4/0D1ocYBTgYlXh4I6VKQ4RYE8uKK3MPMZoCbZjILCWa nA+MjLySeENjMyMLUxNTYyNzSzMlcV4d6Z/BQgLpiSWp2ampB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filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141126_015217_900800_0E30B97B X-CRM114-Status: GOOD ( 14.75 ) X-Spam-Score: -4.9 (----) Cc: vinod.koul@intel.com, Dylan Reid , broonie@kernel.org, lars@metafoo.de X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fill txstate.residue with the amount of bytes remaining in the current transfer if the transfer is not complete. This will be of particular use to i2s DMA transfers, providing more accurate hw_ptr values to ASoC. I had taken the code from Dylan Reid patch from the below link and modified according to the current dmaengine framework. http://comments.gmane.org/gmane.linux.kernel.samsung-soc/23007 Cc: Dylan Reid Signed-off-by: Padmavathi Venna --- This patch has been tested for audio playback on exynos5420 peach-pit. drivers/dma/pl330.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 65 insertions(+), 2 deletions(-) diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c index b7493d2..db880ae 100644 --- a/drivers/dma/pl330.c +++ b/drivers/dma/pl330.c @@ -2182,11 +2182,74 @@ static void pl330_free_chan_resources(struct dma_chan *chan) pm_runtime_put_autosuspend(pch->dmac->ddma.dev); } +static inline int +pl330_src_addr_in_desc(struct dma_pl330_desc *desc, unsigned int sar) +{ + return ((desc->px.src_addr <= sar) && + (sar <= (desc->px.src_addr + desc->px.bytes))); +} + +static inline int +pl330_dst_addr_in_desc(struct dma_pl330_desc *desc, unsigned int dar) +{ + return ((desc->px.dst_addr <= dar) && + (dar <= (desc->px.dst_addr + desc->px.bytes))); +} + static enum dma_status pl330_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) { - return dma_cookie_status(chan, cookie, txstate); + dma_addr_t sar, dar; + struct dma_pl330_chan *pch = to_pchan(chan); + void __iomem *regs = pch->dmac->base; + struct pl330_thread *thrd = pch->thread; + struct dma_pl330_desc *desc; + unsigned int residue = 0; + unsigned long flags; + bool first = true; + dma_cookie_t first_c, current_c; + dma_cookie_t used; + enum dma_status ret; + + ret = dma_cookie_status(chan, cookie, txstate); + if (ret == DMA_COMPLETE || !txstate) + return ret; + + used = txstate->used; + + spin_lock_irqsave(&pch->lock, flags); + sar = readl(regs + SA(thrd->id)); + dar = readl(regs + DA(thrd->id)); + + list_for_each_entry(desc, &pch->work_list, node) { + if (desc->status == BUSY) { + current_c = desc->txd.cookie; + if (first) { + first_c = desc->txd.cookie; + first = false; + } + + if (first_c < current_c) + residue += desc->px.bytes; + else { + if (desc->rqcfg.src_inc && pl330_src_addr_in_desc(desc, sar)) { + residue += desc->px.bytes; + residue -= sar - desc->px.src_addr; + } else if (desc->rqcfg.dst_inc && pl330_dst_addr_in_desc(desc, dar)) { + residue += desc->px.bytes; + residue -= dar - desc->px.dst_addr; + } + } + } else if (desc->status == PREP) + residue += desc->px.bytes; + + if (desc->txd.cookie == used) + break; + } + spin_unlock_irqrestore(&pch->lock, flags); + dma_set_residue(txstate, residue); + return ret; } static void pl330_issue_pending(struct dma_chan *chan) @@ -2631,7 +2694,7 @@ static int pl330_dma_device_slave_caps(struct dma_chan *dchan, caps->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); caps->cmd_pause = false; caps->cmd_terminate = true; - caps->residue_granularity = DMA_RESIDUE_GRANULARITY_DESCRIPTOR; + caps->residue_granularity = DMA_RESIDUE_GRANULARITY_SEGMENT; return 0; }