All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bryan Wu <cooloney@kernel.org>
To: dbrownell@users.sourceforge.net, spi-devel-general@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org,
	Mike Frysinger <vapier.adi@gmail.com>,
	Bryan Wu <cooloney@kernel.org>
Subject: [PATCH 12/16] Blackfin SPI Driver: get dma working for SPI flashes
Date: Tue, 18 Nov 2008 15:52:36 +0800	[thread overview]
Message-ID: <1226994760-4301-13-git-send-email-cooloney@kernel.org> (raw)
In-Reply-To: <1226994760-4301-1-git-send-email-cooloney@kernel.org>

From: Mike Frysinger <vapier.adi@gmail.com>

When using a BF533-STAMP here with a W25X10 SPI flash. It works fine when
enable_dma is disabled, but doesn't work at all when turning DMA on.
We get just 0xff bytes back when trying to read the device.

If change the code around so that it programs the SPI first and then
enables DMA, it seems to work a lot better ...

Signed-off-by: Mike Frysinger <vapier.adi@gmail.com>
Signed-off-by: Bryan Wu <cooloney@kernel.org>
---
 drivers/spi/spi_bfin5xx.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index fba77c2..5cd4873 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -760,11 +760,10 @@ static void pump_transfers(unsigned long data)
 	if (!full_duplex && drv_data->cur_chip->enable_dma
 				&& drv_data->len > 6) {
 
-		unsigned long dma_start_addr;
+		unsigned long dma_start_addr, flags;
 
 		disable_dma(drv_data->dma_channel);
 		clear_dma_irqstat(drv_data->dma_channel);
-		bfin_spi_disable(drv_data);
 
 		/* config dma channel */
 		dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
@@ -795,8 +794,7 @@ static void pump_transfers(unsigned long data)
 			enable_dma(drv_data->dma_channel);
 
 			/* start SPI transfer */
-			write_CTRL(drv_data,
-				(cr | BIT_CTL_TIMOD_DMA_TX | BIT_CTL_ENABLE));
+			write_CTRL(drv_data, cr | BIT_CTL_TIMOD_DMA_TX);
 
 			/* just return here, there can only be one transfer
 			 * in this mode
@@ -838,14 +836,22 @@ static void pump_transfers(unsigned long data)
 		} else
 			BUG();
 
-		/* start dma */
-		dma_enable_irq(drv_data->dma_channel);
-		set_dma_config(drv_data->dma_channel, dma_config);
+		/* oh man, here there be monsters ... and i dont mean the
+		 * fluffy cute ones from pixar, i mean the kind that'll eat
+		 * your data, kick your dog, and love it all.  do *not* try
+		 * and change these lines unless you (1) heavily test DMA
+		 * with SPI flashes on a loaded system (e.g. ping floods),
+		 * (2) know just how broken the DMA engine interaction with
+		 * the SPI peripheral is, and (3) have someone else to blame
+		 * when you screw it all up anyways.
+		 */
 		set_dma_start_addr(drv_data->dma_channel, dma_start_addr);
+		set_dma_config(drv_data->dma_channel, dma_config);
+		local_irq_save(flags);
 		enable_dma(drv_data->dma_channel);
-
-		/* start SPI transfer */
-		write_CTRL(drv_data, (cr | BIT_CTL_ENABLE));
+		write_CTRL(drv_data, cr);
+		dma_enable_irq(drv_data->dma_channel);
+		local_irq_restore(flags);
 
 	} else {
 		/* IO mode write then read */
-- 
1.5.6.3

WARNING: multiple messages have this Message-ID (diff)
From: Bryan Wu <cooloney-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: dbrownell-Rn4VEauK+AKRv+LV9MX5uipxlwaOVQ5f@public.gmane.org,
	spi-devel-general-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Mike Frysinger
	<vapier.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Subject: [PATCH 12/16] Blackfin SPI Driver: get dma working for SPI flashes
Date: Tue, 18 Nov 2008 15:52:36 +0800	[thread overview]
Message-ID: <1226994760-4301-13-git-send-email-cooloney@kernel.org> (raw)
In-Reply-To: <1226994760-4301-1-git-send-email-cooloney-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

From: Mike Frysinger <vapier.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

When using a BF533-STAMP here with a W25X10 SPI flash. It works fine when
enable_dma is disabled, but doesn't work at all when turning DMA on.
We get just 0xff bytes back when trying to read the device.

If change the code around so that it programs the SPI first and then
enables DMA, it seems to work a lot better ...

Signed-off-by: Mike Frysinger <vapier.adi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Signed-off-by: Bryan Wu <cooloney-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 drivers/spi/spi_bfin5xx.c |   26 ++++++++++++++++----------
 1 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index fba77c2..5cd4873 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -760,11 +760,10 @@ static void pump_transfers(unsigned long data)
 	if (!full_duplex && drv_data->cur_chip->enable_dma
 				&& drv_data->len > 6) {
 
-		unsigned long dma_start_addr;
+		unsigned long dma_start_addr, flags;
 
 		disable_dma(drv_data->dma_channel);
 		clear_dma_irqstat(drv_data->dma_channel);
-		bfin_spi_disable(drv_data);
 
 		/* config dma channel */
 		dev_dbg(&drv_data->pdev->dev, "doing dma transfer\n");
@@ -795,8 +794,7 @@ static void pump_transfers(unsigned long data)
 			enable_dma(drv_data->dma_channel);
 
 			/* start SPI transfer */
-			write_CTRL(drv_data,
-				(cr | BIT_CTL_TIMOD_DMA_TX | BIT_CTL_ENABLE));
+			write_CTRL(drv_data, cr | BIT_CTL_TIMOD_DMA_TX);
 
 			/* just return here, there can only be one transfer
 			 * in this mode
@@ -838,14 +836,22 @@ static void pump_transfers(unsigned long data)
 		} else
 			BUG();
 
-		/* start dma */
-		dma_enable_irq(drv_data->dma_channel);
-		set_dma_config(drv_data->dma_channel, dma_config);
+		/* oh man, here there be monsters ... and i dont mean the
+		 * fluffy cute ones from pixar, i mean the kind that'll eat
+		 * your data, kick your dog, and love it all.  do *not* try
+		 * and change these lines unless you (1) heavily test DMA
+		 * with SPI flashes on a loaded system (e.g. ping floods),
+		 * (2) know just how broken the DMA engine interaction with
+		 * the SPI peripheral is, and (3) have someone else to blame
+		 * when you screw it all up anyways.
+		 */
 		set_dma_start_addr(drv_data->dma_channel, dma_start_addr);
+		set_dma_config(drv_data->dma_channel, dma_config);
+		local_irq_save(flags);
 		enable_dma(drv_data->dma_channel);
-
-		/* start SPI transfer */
-		write_CTRL(drv_data, (cr | BIT_CTL_ENABLE));
+		write_CTRL(drv_data, cr);
+		dma_enable_irq(drv_data->dma_channel);
+		local_irq_restore(flags);
 
 	} else {
 		/* IO mode write then read */
-- 
1.5.6.3

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

  parent reply	other threads:[~2008-11-18  7:54 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-18  7:52 Bryan Wu
2008-11-18  7:52 ` (no subject) Bryan Wu
2008-11-18  7:52 ` [PATCH 01/16] Blackfin SPI Driver: ensure cache coherency before doing DMA Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:24   ` David Brownell
2008-11-20 20:24     ` David Brownell
2008-11-20 20:58     ` Mike Frysinger
2008-11-20 20:58       ` Mike Frysinger
2008-11-20 21:47       ` David Brownell
2008-11-20 21:47         ` David Brownell
2008-11-20 21:57         ` Mike Frysinger
2008-11-20 21:57           ` Mike Frysinger
2008-11-20 22:05           ` David Brownell
2008-11-20 22:05             ` David Brownell
2009-02-05  9:30             ` Bryan Wu
2009-02-05  9:30               ` Bryan Wu
2009-02-05 23:51               ` David Brownell
2009-02-06  2:31                 ` Bryan Wu
2009-02-06  2:31                   ` Bryan Wu
2008-11-18  7:52 ` [PATCH 02/16] Blackfin SPI Driver: Fix erroneous SPI Clock divisor calculation Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:25   ` David Brownell
2008-11-20 20:25     ` David Brownell
2008-11-18  7:52 ` [PATCH 03/16] Blackfin SPI Driver: move bfin_addr_dcachable() and friends into the cacheflush header where it belongs Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:26   ` David Brownell
2008-11-20 20:26     ` David Brownell
2008-11-18  7:52 ` [PATCH 04/16] Blackfin SPI Driver: use len_in_bytes when we care about the number of bytes transferred Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:25   ` David Brownell
2008-11-20 20:25     ` David Brownell
2008-11-18  7:52 ` [PATCH 05/16] Blackfin SPI Driver: pass DMA overflow error to the higher level Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:29   ` David Brownell
2008-11-20 20:29     ` David Brownell
2008-11-18  7:52 ` [PATCH 06/16] Blackfin SPI Driver: unify duplicated code in dma read/write paths Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:32   ` David Brownell
2008-11-20 20:32     ` David Brownell
2008-11-18  7:52 ` [PATCH 07/16] Blackfin SPI Driver: drop bogus cast and touchup dma label Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:34   ` David Brownell
2008-11-20 20:34     ` David Brownell
2008-11-18  7:52 ` [PATCH 08/16] Blackfin SPI Driver: add a few more debug messages in useful places Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:35   ` David Brownell
2008-11-20 20:35     ` David Brownell
2008-11-18  7:52 ` [PATCH 09/16] Blackfin SPI Driver: do not check for SPI errors if DMA itself did not flag any Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-18  7:52 ` [PATCH 10/16] Blackfin SPI Driver: use the properl BIT_CTL_xxx defines Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:37   ` David Brownell
2008-11-20 20:37     ` David Brownell
2008-11-18  7:52 ` [PATCH 11/16] Blackfin SPI Driver: remove duplicated MAX_SPI_SSEL and remove unnecessary array size Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-18  7:52 ` Bryan Wu [this message]
2008-11-18  7:52   ` [PATCH 12/16] Blackfin SPI Driver: get dma working for SPI flashes Bryan Wu
2008-11-20 20:43   ` David Brownell
2008-11-20 20:43     ` David Brownell
2008-11-18  7:52 ` [PATCH 13/16] Blackfin SPI Driver: add timeout while waiting for SPIF in dma irq handler Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-18  7:52 ` [PATCH 14/16] Blackfin SPI Driver: tweak magic spi dma sequence to get it working on BF54x Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-18  7:52 ` [PATCH 15/16] Blackfin SPI Driver: fix bug - spi controller driver does not assert/deassert CS correctly Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:47   ` David Brownell
2008-11-20 20:47     ` David Brownell
2008-11-18  7:52 ` [PATCH 16/16] Blackfin SPI Driver: fix bug - correct usage of struct spi_transfer.cs_change Bryan Wu
2008-11-18  7:52   ` Bryan Wu
2008-11-20 20:51   ` David Brownell
2008-11-20 20:51     ` David Brownell

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=1226994760-4301-13-git-send-email-cooloney@kernel.org \
    --to=cooloney@kernel.org \
    --cc=dbrownell@users.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spi-devel-general@lists.sourceforge.net \
    --cc=vapier.adi@gmail.com \
    /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.