All of lore.kernel.org
 help / color / mirror / Atom feed
From: stillcompiling@gmail.com (Joshua Clayton)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 10/10] dma: imx-sdma: extract sdma_set_buffer_descriptor()
Date: Mon, 15 Jun 2015 09:21:45 -0700	[thread overview]
Message-ID: <1434385305-4748-1-git-send-email-stillcompiling@gmail.com> (raw)

extract common per/buffer descriptor setup
from dma prep functions

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
---
 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;
 	}
-- 
2.1.4

WARNING: multiple messages have this Message-ID (diff)
From: Joshua Clayton <stillcompiling@gmail.com>
To: Vinod Koul <vinod.koul@intel.com>
Cc: Joshua Clayton <stillcompiling@gmail.com>,
	Dan Williams <dan.j.williams@intel.com>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Shawn Guo <shawn.guo@linaro.org>
Subject: [PATCH 10/10] dma: imx-sdma: extract sdma_set_buffer_descriptor()
Date: Mon, 15 Jun 2015 09:21:45 -0700	[thread overview]
Message-ID: <1434385305-4748-1-git-send-email-stillcompiling@gmail.com> (raw)

extract common per/buffer descriptor setup
from dma prep functions

Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
---
 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;
 	}
-- 
2.1.4


             reply	other threads:[~2015-06-15 16:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-15 16:21 Joshua Clayton [this message]
2015-06-15 16:21 ` [PATCH 10/10] dma: imx-sdma: extract sdma_set_buffer_descriptor() Joshua Clayton

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=1434385305-4748-1-git-send-email-stillcompiling@gmail.com \
    --to=stillcompiling@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.