From patchwork Mon Jun 15 16:21:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 6610651 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B0A399F1C1 for ; Mon, 15 Jun 2015 16:26:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C4D522076D for ; Mon, 15 Jun 2015 16:26:37 +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 C6D5620769 for ; Mon, 15 Jun 2015 16:26:36 +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 1Z4XAx-00007D-7p; Mon, 15 Jun 2015 16:23:55 +0000 Received: from mail-ie0-x235.google.com ([2607:f8b0:4001:c03::235]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z4X9R-0007KX-UL for linux-arm-kernel@lists.infradead.org; Mon, 15 Jun 2015 16:22:23 +0000 Received: by iebmu5 with SMTP id mu5so65926819ieb.1 for ; Mon, 15 Jun 2015 09:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=KlMO9NSld4kDCvOlLkRMaESNyS0JpesOruqk1Ws2Zc4=; b=fx1cEKLdd0r2FGntXMx9FCwiLY1dwvtXNn6r6rhTL3ln1cu+Gv7b/DMDeERJKQiyMt D1JYjrgi9fkbSvo1bj2O9G8U6DE0oOgS+7kicIxSvQ0pDstngvENPhEaZLNzNxux11eU 1n9G5UPoVrYTLEWWICqT+J6dDhHm26wnPYLBW32LZVPn7VmX0kN2sqtONDT5D1XgfiPI TB865RbWpQhS2ZbTU//Ei+dCq/XOFmbKEsj2JB4HRSJBvJXPPV0mPmTEHZSnokrNI/IA ltkwC839PIL6ohdwiGvaT9IK+2p0vQhq5V1fukWsYtp/2FfgK5fFJCAkfa+LLg6L9JCr tD7A== X-Received: by 10.50.142.9 with SMTP id rs9mr21696770igb.17.1434385317346; Mon, 15 Jun 2015 09:21:57 -0700 (PDT) Received: from localhost.localdomain (68-185-59-186.static.knwc.wa.charter.com. [68.185.59.186]) by mx.google.com with ESMTPSA id b15sm7886701igm.12.2015.06.15.09.21.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Jun 2015 09:21:56 -0700 (PDT) From: Joshua Clayton To: Vinod Koul Subject: [PATCH 10/10] dma: imx-sdma: extract sdma_set_buffer_descriptor() Date: Mon, 15 Jun 2015 09:21:45 -0700 Message-Id: <1434385305-4748-1-git-send-email-stillcompiling@gmail.com> X-Mailer: git-send-email 2.1.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150615_092222_061014_7DA87142 X-CRM114-Status: GOOD ( 15.74 ) X-Spam-Score: -0.8 (/) Cc: Joshua Clayton , linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, Dan Williams , Shawn Guo , linux-arm-kernel@lists.infradead.org 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=-4.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, 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 extract common per/buffer descriptor setup from dma prep functions Signed-off-by: Joshua Clayton --- drivers/dma/imx-sdma.c | 111 ++++++++++++++++++++++++------------------------- 1 file changed, 54 insertions(+), 57 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index dfebef9..13a3574 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -1046,6 +1046,50 @@ int sdma_prep_common(struct sdma_channel *sdmac, int buf_count, return sdma_load_context(sdmac); } +int sdma_set_buffer_descriptor(struct sdma_channel *sdmac, + struct sdma_buffer_descriptor *bd, u32 addr, + int len, u32 status) +{ + struct sdma_engine *sdma = to_sdma_engine(sdmac); + + bd->buffer_addr = addr; + + if (len > 0xffff) { + dev_err(sdma->dev, "SDMA channel %d: maximum buffer description size exceeded: %d > %d\n", + sdmac->channel, len, 0xffff); + return -EINVAL; + } + + bd->mode.count = len; + + switch (sdmac->word_size) { + case DMA_SLAVE_BUSWIDTH_4_BYTES: + bd->mode.command = 0; + if (len & 3 || addr & 3) + return -EFAULT; + break; + case DMA_SLAVE_BUSWIDTH_2_BYTES: + bd->mode.command = 2; + if (len & 1 || addr & 1) + return -EFAULT; + break; + case DMA_SLAVE_BUSWIDTH_1_BYTE: + bd->mode.command = 1; + break; + default: + return -EFAULT; + } + + dev_dbg(sdma->dev, "count: %d dma: %#llx %s%s\n", + len, (u64)addr, + status & BD_WRAP ? "wrap" : "", + status & BD_INTR ? " intr" : ""); + + bd->mode.status = status; + + return 0; +} + static void sdma_free_chan_resources(struct dma_chan *chan) { struct sdma_channel *sdmac = to_sdma_chan(chan); @@ -1077,7 +1121,7 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( { struct sdma_channel *sdmac = to_sdma_chan(chan); struct sdma_engine *sdma = to_sdma_engine(sdmac); - int ret, i, count; + int ret, i; int channel = sdmac->channel; struct scatterlist *sg; @@ -1090,41 +1134,9 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( sdmac->chn_count = 0; for_each_sg(sgl, sg, sg_len, i) { - struct sdma_buffer_descriptor *bd = &sdmac->bd[i]; int param; - bd->buffer_addr = sg->dma_address; - - count = sg_dma_len(sg); - - if (count > 0xffff) { - dev_err(sdma->dev, "SDMA channel %d: maximum bytes for sg entry exceeded: %d > %d\n", - channel, count, 0xffff); - ret = -EINVAL; - goto err_out; - } - - bd->mode.count = count; - sdmac->chn_count += count; - - switch (sdmac->word_size) { - case DMA_SLAVE_BUSWIDTH_4_BYTES: - bd->mode.command = 0; - if (count & 3 || sg->dma_address & 3) - return NULL; - break; - case DMA_SLAVE_BUSWIDTH_2_BYTES: - bd->mode.command = 2; - if (count & 1 || sg->dma_address & 1) - return NULL; - break; - case DMA_SLAVE_BUSWIDTH_1_BYTE: - bd->mode.command = 1; - break; - default: - return NULL; - } - + sdmac->chn_count += sg_dma_len(sg); param = BD_DONE | BD_EXTD | BD_CONT; if (i + 1 == sg_len) { @@ -1133,12 +1145,10 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( param &= ~BD_CONT; } - dev_dbg(sdma->dev, "entry %d: count: %d dma: %#llx %s%s\n", - i, count, (u64)sg->dma_address, - param & BD_WRAP ? "wrap" : "", - param & BD_INTR ? " intr" : ""); - - bd->mode.status = param; + ret = sdma_set_buffer_descriptor(sdmac, &sdmac->bd[i], + sg->dma_address, sg_dma_len(sg), param); + if (ret) + goto err_out; } sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys; @@ -1167,28 +1177,15 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic( sdmac->flags |= IMX_DMA_SG_LOOP; for (i = 0; i < num_periods; i++) { - struct sdma_buffer_descriptor *bd = &sdmac->bd[i]; int param; - - bd->buffer_addr = dma_addr; - - bd->mode.count = period_len; - - if (sdmac->word_size == DMA_SLAVE_BUSWIDTH_4_BYTES) - bd->mode.command = 0; - else - bd->mode.command = sdmac->word_size; - param = BD_DONE | BD_EXTD | BD_CONT | BD_INTR; if (i + 1 == num_periods) param |= BD_WRAP; - dev_dbg(sdma->dev, "entry %d: count: %d dma: %#llx %s%s\n", - i, period_len, (u64)dma_addr, - param & BD_WRAP ? "wrap" : "", - param & BD_INTR ? " intr" : ""); - - bd->mode.status = param; + ret = sdma_set_buffer_descriptor(sdmac, &sdmac->bd[i], + dma_addr, sdmac->period_len, param); + if (ret) + goto err_out; dma_addr += period_len; }