linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Frysinger <vapier@gentoo.org>
To: spi-devel-general@lists.sourceforge.net,
	David Brownell <dbrownell@users.sourceforge.net>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Yi Li <yi.li@analog.com>
Subject: [PATCH 2/2] mmc_spi: lock the SPI bus when accessing the card
Date: Thu, 17 Sep 2009 18:03:17 -0400	[thread overview]
Message-ID: <1253224997-7422-2-git-send-email-vapier@gentoo.org> (raw)
In-Reply-To: <1253224997-7422-1-git-send-email-vapier@gentoo.org>

From: Yi Li <yi.li@analog.com>

The MMC/SPI spec does not play well with typical SPI design -- it often
needs to send out a command in one message, read a response, then do some
other arbitrary step.  Since we can't let another SPI client use the bus
during this time, use the new SPI lock/unlock functions to provide the
required exclusivity.

Signed-off-by: Yi Li <yi.li@analog.com>
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 drivers/mmc/host/mmc_spi.c |   29 ++---------------------------
 1 files changed, 2 insertions(+), 27 deletions(-)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index a461017..a96e058 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1084,6 +1084,7 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
 #endif
 
 	/* issue command; then optionally data and stop */
+	spi_lock_bus(host->spi);
 	status = mmc_spi_command_send(host, mrq, mrq->cmd, mrq->data != NULL);
 	if (status == 0 && mrq->data) {
 		mmc_spi_data_do(host, mrq->cmd, mrq->data, mrq->data->blksz);
@@ -1092,7 +1093,7 @@ static void mmc_spi_request(struct mmc_host *mmc, struct mmc_request *mrq)
 		else
 			mmc_cs_off(host);
 	}
-
+	spi_unlock_bus(host->spi);
 	mmc_request_done(host->mmc, mrq);
 }
 
@@ -1337,32 +1338,6 @@ static int mmc_spi_probe(struct spi_device *spi)
 		return status;
 	}
 
-	/* We can use the bus safely iff nobody else will interfere with us.
-	 * Most commands consist of one SPI message to issue a command, then
-	 * several more to collect its response, then possibly more for data
-	 * transfer.  Clocking access to other devices during that period will
-	 * corrupt the command execution.
-	 *
-	 * Until we have software primitives which guarantee non-interference,
-	 * we'll aim for a hardware-level guarantee.
-	 *
-	 * REVISIT we can't guarantee another device won't be added later...
-	 */
-	if (spi->master->num_chipselect > 1) {
-		struct count_children cc;
-
-		cc.n = 0;
-		cc.bus = spi->dev.bus;
-		status = device_for_each_child(spi->dev.parent, &cc,
-				maybe_count_child);
-		if (status < 0) {
-			dev_err(&spi->dev, "can't share SPI bus\n");
-			return status;
-		}
-
-		dev_warn(&spi->dev, "ASSUMING SPI bus stays unshared!\n");
-	}
-
 	/* We need a supply of ones to transmit.  This is the only time
 	 * the CPU touches these, so cache coherency isn't a concern.
 	 *
-- 
1.6.5.rc1

  reply	other threads:[~2009-09-17 22:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-17 22:03 [PATCH 1/2] spi: new SPI bus lock/unlock functions Mike Frysinger
2009-09-17 22:03 ` Mike Frysinger [this message]
2009-09-18  0:29   ` [spi-devel-general] [PATCH 2/2] mmc_spi: lock the SPI bus whenaccessing the card H Hartley Sweeten
2009-09-18  0:52     ` [PATCH 2/2 v2] mmc_spi: lock the SPI bus when accessing " Mike Frysinger
2009-09-18 21:30       ` Andrew Morton
2009-09-17 22:45 ` [spi-devel-general] [PATCH 1/2] spi: new SPI bus lock/unlockfunctions H Hartley Sweeten
2009-09-17 22:53   ` Mike Frysinger
2009-09-18 23:00     ` H Hartley Sweeten
2009-09-19 19:11       ` Mike Frysinger
2009-09-21  8:08       ` Li Yi
2009-09-18 21:29 ` [PATCH 1/2] spi: new SPI bus lock/unlock functions Andrew Morton
2009-09-21  6:33   ` Li Yi
2009-09-21 13:36     ` Mike Frysinger
2009-09-22 14:15 ` Mike Frysinger
2009-12-16 22:49 ` [spi-devel-general] [PATCH 1/2] spi: new SPI bus lock/unlockfunctions H Hartley Sweeten
2009-12-16 23:00   ` Mike Frysinger

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=1253224997-7422-2-git-send-email-vapier@gentoo.org \
    --to=vapier@gentoo.org \
    --cc=akpm@linux-foundation.org \
    --cc=dbrownell@users.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spi-devel-general@lists.sourceforge.net \
    --cc=yi.li@analog.com \
    --subject='Re: [PATCH 2/2] mmc_spi: lock the SPI bus when accessing the card' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).