All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spi: davinci: Use correct length parameter to dma_map_single calls
@ 2011-03-13 14:34 Michael Williamson
       [not found] ` <1300026862-1179-1-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Michael Williamson @ 2011-03-13 14:34 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f

The davinci spi driver provides an option to use DMA transfers for
data.  In the dma_map_single() call, the driver is passing the
number of words to be transfered for the mapping size.  It should
be the number of bytes.

Signed-off-by: Michael Williamson <michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
---
Note: I only have 8 bit devices to test with, so I can only confirm this
patch does not break such a configuration.

 drivers/spi/davinci_spi.c |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
index 166a879..037ba82 100644
--- a/drivers/spi/davinci_spi.c
+++ b/drivers/spi/davinci_spi.c
@@ -591,10 +591,10 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 
 		if (t->tx_buf) {
 			t->tx_dma = dma_map_single(&spi->dev, (void *)t->tx_buf,
-						dspi->wcount, DMA_TO_DEVICE);
+						t->len, DMA_TO_DEVICE);
 			if (dma_mapping_error(&spi->dev, t->tx_dma)) {
 				dev_dbg(sdev, "Unable to DMA map %d bytes"
-						"TX buffer\n", dspi->wcount);
+						"TX buffer\n", t->len);
 				return -ENOMEM;
 			}
 		}
@@ -624,7 +624,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 
 		if (t->rx_buf) {
 			rx_buf = t->rx_buf;
-			rx_buf_count = dspi->rcount;
+			rx_buf_count = t->len;
 		} else {
 			rx_buf = dspi->rx_tmp_buf;
 			rx_buf_count = sizeof(dspi->rx_tmp_buf);
@@ -636,7 +636,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 			dev_dbg(sdev, "Couldn't DMA map a %d bytes RX buffer\n",
 								rx_buf_count);
 			if (t->tx_buf)
-				dma_unmap_single(NULL, t->tx_dma, dspi->wcount,
+				dma_unmap_single(NULL, t->tx_dma, t->len,
 								DMA_TO_DEVICE);
 			return -ENOMEM;
 		}
@@ -675,7 +675,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 	if (spicfg->io_type == SPI_IO_TYPE_DMA) {
 
 		if (t->tx_buf)
-			dma_unmap_single(NULL, t->tx_dma, dspi->wcount,
+			dma_unmap_single(NULL, t->tx_dma, t->len,
 								DMA_TO_DEVICE);
 
 		dma_unmap_single(NULL, t->rx_dma, rx_buf_count,
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH] spi: davinci: Support DMA transfers larger than 65535 words
       [not found] ` <1300026862-1179-1-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
@ 2011-03-13 14:34   ` Michael Williamson
       [not found]     ` <1300026862-1179-2-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
  2011-03-14 19:18   ` [PATCH] spi: davinci: Use correct length parameter to dma_map_single calls Grant Likely
  1 sibling, 1 reply; 6+ messages in thread
From: Michael Williamson @ 2011-03-13 14:34 UTC (permalink / raw)
  To: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f

The current davinci SPI driver, in DMA mode, is limited to 65535
words for a single transfer.  Modify the driver by configuring a
3 dimensional EDMA transfer to support up to 65535x65535
words.

Signed-off-by: Michael Williamson <michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
---
This patch is an attempt to address the issue raised here:

http://comments.gmane.org/gmane.linux.davinci/20581

Tested with:
dd if=/dev/mtd7 of=/tmp/test.1K bs=1024 count=1024
dd if=/dev/mtd7 of=/tmp/test.64K bs=65536 count=16
dd if=/dev/mtd7 of=/tmp/test.128K bs=131072 count=8
md5sum /tmp/test*

 drivers/spi/davinci_spi.c |   33 +++++++++++++++++++++++++--------
 1 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
index 037ba82..411cc32 100644
--- a/drivers/spi/davinci_spi.c
+++ b/drivers/spi/davinci_spi.c
@@ -571,6 +571,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 		unsigned long tx_reg, rx_reg;
 		struct edmacc_param param;
 		void *rx_buf;
+		int b, c;
 
 		dma = &dspi->dma;
 
@@ -599,14 +600,30 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 			}
 		}
 
+		/*
+		 * If number of words is greater than 65535, then we need
+		 * to configure a 3 dimension transfer.  Use the BCNTRLD
+		 * feature to allow for transfers that aren't even multiples
+		 * of 65535 (or any other possible b size) by first transferring
+		 * the remainder amount then grabbing the next N blocks of
+		 * 65535 words.
+		 */
+
+		c = dspi->wcount/(SZ_64K-1);	/* N 65535 count Blocks */
+		b = dspi->wcount-c*(SZ_64K-1);	/* Remainder */
+		if (b)
+			c++;
+		else
+			b = SZ_64K-1;
+
 		param.opt = TCINTEN | EDMA_TCC(dma->tx_channel);
 		param.src = t->tx_buf ? t->tx_dma : tx_reg;
-		param.a_b_cnt = dspi->wcount << 16 | data_type;
+		param.a_b_cnt = b << 16 | data_type;
 		param.dst = tx_reg;
 		param.src_dst_bidx = t->tx_buf ? data_type : 0;
-		param.link_bcntrld = 0xffff;
-		param.src_dst_cidx = 0;
-		param.ccnt = 1;
+		param.link_bcntrld = 0xffffffff;
+		param.src_dst_cidx = t->tx_buf ? data_type : 0;
+		param.ccnt = c;
 		edma_write_slot(dma->tx_channel, &param);
 		edma_link(dma->tx_channel, dma->dummy_param_slot);
 
@@ -643,12 +660,12 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
 
 		param.opt = TCINTEN | EDMA_TCC(dma->rx_channel);
 		param.src = rx_reg;
-		param.a_b_cnt = dspi->rcount << 16 | data_type;
+		param.a_b_cnt = b << 16 | data_type;
 		param.dst = t->rx_dma;
 		param.src_dst_bidx = (t->rx_buf ? data_type : 0) << 16;
-		param.link_bcntrld = 0xffff;
-		param.src_dst_cidx = 0;
-		param.ccnt = 1;
+		param.link_bcntrld = 0xffffffff;
+		param.src_dst_cidx = (t->rx_buf ? data_type : 0) << 16;
+		param.ccnt = c;
 		edma_write_slot(dma->rx_channel, &param);
 
 		if (pdata->cshold_bug)
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: davinci: Support DMA transfers larger than 65535 words
       [not found]     ` <1300026862-1179-2-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
@ 2011-03-14  9:33       ` Stefano Babic
  2011-03-14 10:25       ` Sergei Shtylyov
  1 sibling, 0 replies; 6+ messages in thread
From: Stefano Babic @ 2011-03-14  9:33 UTC (permalink / raw)
  To: Michael Williamson
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f

On 03/13/2011 03:34 PM, Michael Williamson wrote:
> The current davinci SPI driver, in DMA mode, is limited to 65535
> words for a single transfer.  Modify the driver by configuring a
> 3 dimensional EDMA transfer to support up to 65535x65535
> words.
> 
> Signed-off-by: Michael Williamson <michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
> ---
> This patch is an attempt to address the issue raised here:
> 
> http://comments.gmane.org/gmane.linux.davinci/20581
> 

Thanks to fix this issue ! Tested on a OMAP-L138 board.

Tested-by: Stefano Babic <sbabic-ynQEQJNshbs@public.gmane.org>

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office-ynQEQJNshbs@public.gmane.org
=====================================================================

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: davinci: Support DMA transfers larger than 65535 words
       [not found]     ` <1300026862-1179-2-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
  2011-03-14  9:33       ` Stefano Babic
@ 2011-03-14 10:25       ` Sergei Shtylyov
       [not found]         ` <4D7DED07.7020000-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
  1 sibling, 1 reply; 6+ messages in thread
From: Sergei Shtylyov @ 2011-03-14 10:25 UTC (permalink / raw)
  To: Michael Williamson
  Cc: grant.likely-s3s/WqlpOiPyB63q8FvJNQ,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f

Hello.

On 13-03-2011 17:34, Michael Williamson wrote:

> The current davinci SPI driver, in DMA mode, is limited to 65535
> words for a single transfer.  Modify the driver by configuring a
> 3 dimensional EDMA transfer to support up to 65535x65535
> words.

> Signed-off-by: Michael Williamson<michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
[...]

> diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
> index 037ba82..411cc32 100644
> --- a/drivers/spi/davinci_spi.c
> +++ b/drivers/spi/davinci_spi.c
[...]
> @@ -599,14 +600,30 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
>   			}
>   		}
>
> +		/*
> +		 * If number of words is greater than 65535, then we need
> +		 * to configure a 3 dimension transfer.  Use the BCNTRLD
> +		 * feature to allow for transfers that aren't even multiples
> +		 * of 65535 (or any other possible b size) by first transferring
> +		 * the remainder amount then grabbing the next N blocks of
> +		 * 65535 words.
> +		 */
> +
> +		c = dspi->wcount/(SZ_64K-1);	/* N 65535 count Blocks */
> +		b = dspi->wcount-c*(SZ_64K-1);	/* Remainder */

    The driver style (and general Linux kernel style) assumes spaces around 
operators.

WRB, Sergei

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: davinci: Support DMA transfers larger than 65535 words
       [not found]         ` <4D7DED07.7020000-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
@ 2011-03-14 11:06           ` Michael Williamson
  0 siblings, 0 replies; 6+ messages in thread
From: Michael Williamson @ 2011-03-14 11:06 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f

On 3/14/2011 6:25 AM, Sergei Shtylyov wrote:

> Hello.
>
> On 13-03-2011 17:34, Michael Williamson wrote:
>
>> The current davinci SPI driver, in DMA mode, is limited to 65535
>> words for a single transfer.  Modify the driver by configuring a
>> 3 dimensional EDMA transfer to support up to 65535x65535
>> words.
>
>> Signed-off-by: Michael Williamson<michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
> [...]
>
>> diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
>> index 037ba82..411cc32 100644
>> --- a/drivers/spi/davinci_spi.c
>> +++ b/drivers/spi/davinci_spi.c
> [...]
>> @@ -599,14 +600,30 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
>>               }
>>           }
>>
>> +        /*
>> +         * If number of words is greater than 65535, then we need
>> +         * to configure a 3 dimension transfer.  Use the BCNTRLD
>> +         * feature to allow for transfers that aren't even multiples
>> +         * of 65535 (or any other possible b size) by first transferring
>> +         * the remainder amount then grabbing the next N blocks of
>> +         * 65535 words.
>> +         */
>> +
>> +        c = dspi->wcount/(SZ_64K-1);    /* N 65535 count Blocks */
>> +        b = dspi->wcount-c*(SZ_64K-1);    /* Remainder */
>
>    The driver style (and general Linux kernel style) assumes spaces around operators.



Sure enough.  I am relying on checkpatch.pl too much.  I will fix and
re-post.  Thanks for the style check.

>
> WRB, Sergei





------------------------------------------------------------------------------
Colocation vs. Managed Hosting
A question and answer guide to determining the best fit
for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] spi: davinci: Use correct length parameter to dma_map_single calls
       [not found] ` <1300026862-1179-1-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
  2011-03-13 14:34   ` [PATCH] spi: davinci: Support DMA transfers larger than 65535 words Michael Williamson
@ 2011-03-14 19:18   ` Grant Likely
  1 sibling, 0 replies; 6+ messages in thread
From: Grant Likely @ 2011-03-14 19:18 UTC (permalink / raw)
  To: Michael Williamson
  Cc: spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f,
	davinci-linux-open-source-VycZQUHpC/PFrsHnngEfi1aTQe2KTcn/,
	dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f

On Sun, Mar 13, 2011 at 10:34:21AM -0400, Michael Williamson wrote:
> The davinci spi driver provides an option to use DMA transfers for
> data.  In the dma_map_single() call, the driver is passing the
> number of words to be transfered for the mapping size.  It should
> be the number of bytes.
> 
> Signed-off-by: Michael Williamson <michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>

Applied, thanks

g.

> ---
> Note: I only have 8 bit devices to test with, so I can only confirm this
> patch does not break such a configuration.
> 
>  drivers/spi/davinci_spi.c |   10 +++++-----
>  1 files changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c
> index 166a879..037ba82 100644
> --- a/drivers/spi/davinci_spi.c
> +++ b/drivers/spi/davinci_spi.c
> @@ -591,10 +591,10 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
>  
>  		if (t->tx_buf) {
>  			t->tx_dma = dma_map_single(&spi->dev, (void *)t->tx_buf,
> -						dspi->wcount, DMA_TO_DEVICE);
> +						t->len, DMA_TO_DEVICE);
>  			if (dma_mapping_error(&spi->dev, t->tx_dma)) {
>  				dev_dbg(sdev, "Unable to DMA map %d bytes"
> -						"TX buffer\n", dspi->wcount);
> +						"TX buffer\n", t->len);
>  				return -ENOMEM;
>  			}
>  		}
> @@ -624,7 +624,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
>  
>  		if (t->rx_buf) {
>  			rx_buf = t->rx_buf;
> -			rx_buf_count = dspi->rcount;
> +			rx_buf_count = t->len;
>  		} else {
>  			rx_buf = dspi->rx_tmp_buf;
>  			rx_buf_count = sizeof(dspi->rx_tmp_buf);
> @@ -636,7 +636,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
>  			dev_dbg(sdev, "Couldn't DMA map a %d bytes RX buffer\n",
>  								rx_buf_count);
>  			if (t->tx_buf)
> -				dma_unmap_single(NULL, t->tx_dma, dspi->wcount,
> +				dma_unmap_single(NULL, t->tx_dma, t->len,
>  								DMA_TO_DEVICE);
>  			return -ENOMEM;
>  		}
> @@ -675,7 +675,7 @@ static int davinci_spi_bufs(struct spi_device *spi, struct spi_transfer *t)
>  	if (spicfg->io_type == SPI_IO_TYPE_DMA) {
>  
>  		if (t->tx_buf)
> -			dma_unmap_single(NULL, t->tx_dma, dspi->wcount,
> +			dma_unmap_single(NULL, t->tx_dma, t->len,
>  								DMA_TO_DEVICE);
>  
>  		dma_unmap_single(NULL, t->rx_dma, rx_buf_count,
> -- 
> 1.7.0.4
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-03-14 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-13 14:34 [PATCH] spi: davinci: Use correct length parameter to dma_map_single calls Michael Williamson
     [not found] ` <1300026862-1179-1-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
2011-03-13 14:34   ` [PATCH] spi: davinci: Support DMA transfers larger than 65535 words Michael Williamson
     [not found]     ` <1300026862-1179-2-git-send-email-michael.williamson-wZX4cNJlHJ2sVWG7oymsAA@public.gmane.org>
2011-03-14  9:33       ` Stefano Babic
2011-03-14 10:25       ` Sergei Shtylyov
     [not found]         ` <4D7DED07.7020000-Igf4POYTYCDQT0dZR+AlfA@public.gmane.org>
2011-03-14 11:06           ` Michael Williamson
2011-03-14 19:18   ` [PATCH] spi: davinci: Use correct length parameter to dma_map_single calls Grant Likely

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.