From patchwork Mon Jun 15 16:19:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Clayton X-Patchwork-Id: 6610631 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1436AC0020 for ; Mon, 15 Jun 2015 16:26:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 270E92076B for ; Mon, 15 Jun 2015 16:26:05 +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 2942F20768 for ; Mon, 15 Jun 2015 16:26:04 +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 1Z4X9y-0007ud-Py; Mon, 15 Jun 2015 16:22:54 +0000 Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z4X6y-0004wV-97 for linux-arm-kernel@lists.infradead.org; Mon, 15 Jun 2015 16:19:49 +0000 Received: by pacyx8 with SMTP id yx8so68536040pac.2 for ; Mon, 15 Jun 2015 09:19:27 -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:in-reply-to:references; bh=Pyot6BS6mTlghBj8j2BiT+pXCe1cPu5WHAdp+aV+HSw=; b=lWaiH+ZKN6BuckdzdJZ+37FBTJ9txGHCd2U+nSsGvejapy4Sw74RqtyZUvR/7B8O0W vzgz7rA3Fzz3aXTG9dJ/zbeLOre/wQNEGxiuqJhgoT3IPaYxpxPuH9lUREYwhpCsV2bA je/9P7KijYzN1YncNSiurAuNiPJixkEKs5zUIASUVoh/nWmlB/0hZbsFDfoet30eQlXb lK3FScMljJwqXKuW635Ks+qXxuaxB0BBHPksuiGib1G4dQa2cQ6gW2E5asRoyXOBqxoD lEaFsPm+4Y5HGnNAbVdml9qZVfbX+6DrhCRKT8zofLjZy0phwJHbgbTTTv0ao4ZLliXC 7pUg== X-Received: by 10.70.54.164 with SMTP id k4mr50297265pdp.61.1434385167195; Mon, 15 Jun 2015 09:19:27 -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 qg5sm12717637pdb.13.2015.06.15.09.19.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Jun 2015 09:19:26 -0700 (PDT) From: Joshua Clayton To: Vinod Koul Subject: [PATCH 08/10] dma: imx-sdma: extract common sdma prep code Date: Mon, 15 Jun 2015 09:19:03 -0700 Message-Id: <1434385144-4432-9-git-send-email-stillcompiling@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1434385144-4432-1-git-send-email-stillcompiling@gmail.com> References: <1434385144-4432-1-git-send-email-stillcompiling@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150615_091948_420247_1F5C51DE X-CRM114-Status: GOOD ( 15.92 ) 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 the code that is equivalent between the slave and cyclic sdma functions. Add some better errors for failure conditions. Signed-off-by: Joshua Clayton --- drivers/dma/imx-sdma.c | 76 +++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c index c9badd4..4d447be 100644 --- a/drivers/dma/imx-sdma.c +++ b/drivers/dma/imx-sdma.c @@ -1018,6 +1018,34 @@ static int sdma_alloc_chan_resources(struct dma_chan *chan) return 0; } +int sdma_prep_common(struct sdma_channel *sdmac, int buf_count, + enum dma_transfer_direction direction) +{ + struct sdma_engine *sdma = to_sdma_engine(sdmac); + + if (sdmac->status == DMA_IN_PROGRESS) { + dev_err(sdma->dev, "SDMA channel %d: dma already in progress\n", + sdmac->channel); + return -EBUSY; + } + + sdmac->status = DMA_IN_PROGRESS; + sdmac->buf_tail = 0; + sdmac->direction = direction; + + dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n", + buf_count, sdmac->channel); + + if (buf_count > NUM_BD) { + dev_err(sdma->dev, "SDMA channel %d: maximum number of buffers exceeded: %d > %d\n", + sdmac->channel, buf_count, NUM_BD); + return -EINVAL; + } + sdmac->num_bd = buf_count; + + return sdma_load_context(sdmac); +} + static void sdma_free_chan_resources(struct dma_chan *chan) { struct sdma_channel *sdmac = to_sdma_chan(chan); @@ -1053,28 +1081,12 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( int channel = sdmac->channel; struct scatterlist *sg; - if (sdmac->status == DMA_IN_PROGRESS) - return NULL; - sdmac->status = DMA_IN_PROGRESS; - - sdmac->flags = 0; - - sdmac->buf_tail = 0; - - dev_dbg(sdma->dev, "setting up %d entries for channel %d.\n", - sg_len, channel); - - sdmac->direction = direction; - ret = sdma_load_context(sdmac); + ret = sdma_prep_common(sdmac, sg_len, direction); if (ret) goto err_out; - if (sg_len > NUM_BD) { - dev_err(sdma->dev, "SDMA channel %d: maximum number of sg exceeded: %d > %d\n", - channel, sg_len, NUM_BD); - ret = -EINVAL; - goto err_out; - } + sdmac->flags = 0; + sdmac->chn_count = 0; for_each_sg(sgl, sg, sg_len, i) { @@ -1129,7 +1141,6 @@ static struct dma_async_tx_descriptor *sdma_prep_slave_sg( bd->mode.status = param; } - sdmac->num_bd = sg_len; sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys; return &sdmac->desc; @@ -1149,33 +1160,11 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic( int channel = sdmac->channel; int ret, i = 0, buf = 0; - dev_dbg(sdma->dev, "%s channel: %d\n", __func__, channel); - - if (sdmac->status == DMA_IN_PROGRESS) - return NULL; - - sdmac->status = DMA_IN_PROGRESS; + sdma_prep_common(sdmac, buf_len / period_len, direction); - sdmac->buf_tail = 0; sdmac->period_len = period_len; sdmac->flags |= IMX_DMA_SG_LOOP; - sdmac->direction = direction; - ret = sdma_load_context(sdmac); - if (ret) - goto err_out; - - if (num_periods > NUM_BD) { - dev_err(sdma->dev, "SDMA channel %d: maximum number of sg exceeded: %d > %d\n", - channel, num_periods, NUM_BD); - goto err_out; - } - - if (period_len > 0xffff) { - dev_err(sdma->dev, "SDMA channel %d: maximum period size exceeded: %d > %d\n", - channel, period_len, 0xffff); - goto err_out; - } while (buf < buf_len) { struct sdma_buffer_descriptor *bd = &sdmac->bd[i]; @@ -1207,7 +1196,6 @@ static struct dma_async_tx_descriptor *sdma_prep_dma_cyclic( i++; } - sdmac->num_bd = num_periods; sdma->channel_control[channel].current_bd_ptr = sdmac->bd_phys; return &sdmac->desc;