mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Matt Fleming" <mattjfleming@googlemail.com>
To: linux-kernel@vger.kernel.org, drzeus-mmc@drzeus.cx,
	dbrownell@users.sourceforge.net
Subject: [RFC][PATCH] MMC: Use write timeout value as read from CSR
Date: Mon, 1 Sep 2008 16:12:03 +0100	[thread overview]
Message-ID: <5ff4a1e50809010812i32168136qea538ba177b81446@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 3972 bytes --]

Currently, the MMC/SD over SPI code has a hard-coded timeout value of
250ms on writes. This is correct for SD cards and is specified in the
spec, but it is not correct for MMC cards. For MMC cards the values
that is read from the CSR should be used.

There is already code to ensure that the write timeout value for SD
cards does not exceed 250ms, this patch only affects the MMC case.

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 7503b81..2818837 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -34,6 +34,7 @@

 #include <linux/mmc/host.h>
 #include <linux/mmc/mmc.h>             /* for R1_SPI_* bit values */
+#include <linux/mmc/card.h>

 #include <linux/spi/spi.h>
 #include <linux/spi/mmc_spi.h>
@@ -96,7 +97,6 @@
  * shorter timeouts ... but why bother?
  */
 #define readblock_timeout      ktime_set(0, 100 * 1000 * 1000)
-#define writeblock_timeout     ktime_set(0, 250 * 1000 * 1000)
 #define r1b_timeout            ktime_set(3, 0)


@@ -225,6 +225,20 @@ static int mmc_spi_readtoken(struct mmc_spi_host *host)
        return mmc_spi_skip(host, readblock_timeout, 1, 0xff);
 }

+/*
+ * Return the write timeout value (in nanoseconds) for this card.
+ */
+static inline unsigned int
+mmc_get_write_timeout(struct mmc_spi_host *host, struct mmc_data *data)
+{
+       unsigned int timeout_ns;
+
+       timeout_ns = data->timeout_ns;
+       timeout_ns += data->timeout_clks * 1000  * 1000 /
+               (host->mmc->card->host->ios.clock);
+
+       return timeout_ns;
+}

 /*
  * Note that for SPI, cmd->resp[0] is not the same data as "native" protocol
@@ -605,11 +619,13 @@ mmc_spi_setup_data_message(
  * Return negative errno, else success.
  */
 static int
-mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
+mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t,
+       struct mmc_data *data)
 {
        struct spi_device       *spi = host->spi;
        int                     status, i;
        struct scratch          *scratch = host->data;
+       unsigned int            timeout_ns;

        if (host->mmc->use_spi_crc)
                scratch->crc_val = cpu_to_be16(
@@ -673,7 +689,11 @@ mmc_spi_writeblock(struct mmc_spi_host *host,
struct spi_transfer *t)
                if (scratch->status[i] != 0)
                        return 0;
        }
-       return mmc_spi_wait_unbusy(host, writeblock_timeout);
+
+       timeout_ns = mmc_get_write_timeout(host, data);
+
+       return mmc_spi_wait_unbusy(host,
+               ktime_add_ns(ktime_set(0, 0), timeout_ns));
 }

 /*
@@ -832,7 +852,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct
mmc_command *cmd,
                                t->len);

                        if (direction == DMA_TO_DEVICE)
-                               status = mmc_spi_writeblock(host, t);
+                               status = mmc_spi_writeblock(host, t, data);
                        else
                                status = mmc_spi_readblock(host, t);
                        if (status < 0)
@@ -872,6 +892,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct
mmc_command *cmd,
                struct scratch  *scratch = host->data;
                int             tmp;
                const unsigned  statlen = sizeof(scratch->status);
+               unsigned int    timeout_ns;

                dev_dbg(&spi->dev, "    mmc_spi: STOP_TRAN\n");

@@ -917,7 +938,9 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct
mmc_command *cmd,
                        if (scratch->status[tmp] != 0)
                                return;
                }
-               tmp = mmc_spi_wait_unbusy(host, writeblock_timeout);
+               timeout_ns = mmc_get_write_timeout(host, data);
+               tmp = mmc_spi_wait_unbusy(host,
+                       ktime_add_ns(ktime_set(0, 0), timeout_ns));
                if (tmp < 0 && !data->error)
                        data->error = tmp;
        }

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mmc-spi-use-timeout-from-card.patch --]
[-- Type: text/x-diff; name=mmc-spi-use-timeout-from-card.patch, Size: 2955 bytes --]

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 7503b81..2818837 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -34,6 +34,7 @@
 
 #include <linux/mmc/host.h>
 #include <linux/mmc/mmc.h>		/* for R1_SPI_* bit values */
+#include <linux/mmc/card.h>
 
 #include <linux/spi/spi.h>
 #include <linux/spi/mmc_spi.h>
@@ -96,7 +97,6 @@
  * shorter timeouts ... but why bother?
  */
 #define readblock_timeout	ktime_set(0, 100 * 1000 * 1000)
-#define writeblock_timeout	ktime_set(0, 250 * 1000 * 1000)
 #define r1b_timeout		ktime_set(3, 0)
 
 
@@ -225,6 +225,20 @@ static int mmc_spi_readtoken(struct mmc_spi_host *host)
 	return mmc_spi_skip(host, readblock_timeout, 1, 0xff);
 }
 
+/*
+ * Return the write timeout value (in nanoseconds) for this card.
+ */
+static inline unsigned int
+mmc_get_write_timeout(struct mmc_spi_host *host, struct mmc_data *data)
+{
+	unsigned int timeout_ns;
+
+	timeout_ns = data->timeout_ns;
+	timeout_ns += data->timeout_clks * 1000  * 1000 /
+		(host->mmc->card->host->ios.clock);
+
+	return timeout_ns;
+}
 
 /*
  * Note that for SPI, cmd->resp[0] is not the same data as "native" protocol
@@ -605,11 +619,13 @@ mmc_spi_setup_data_message(
  * Return negative errno, else success.
  */
 static int
-mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
+mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t,
+	struct mmc_data *data)
 {
 	struct spi_device	*spi = host->spi;
 	int			status, i;
 	struct scratch		*scratch = host->data;
+	unsigned int		timeout_ns;
 
 	if (host->mmc->use_spi_crc)
 		scratch->crc_val = cpu_to_be16(
@@ -673,7 +689,11 @@ mmc_spi_writeblock(struct mmc_spi_host *host, struct spi_transfer *t)
 		if (scratch->status[i] != 0)
 			return 0;
 	}
-	return mmc_spi_wait_unbusy(host, writeblock_timeout);
+
+	timeout_ns = mmc_get_write_timeout(host, data);
+
+	return mmc_spi_wait_unbusy(host,
+		ktime_add_ns(ktime_set(0, 0), timeout_ns));
 }
 
 /*
@@ -832,7 +852,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
 				t->len);
 
 			if (direction == DMA_TO_DEVICE)
-				status = mmc_spi_writeblock(host, t);
+				status = mmc_spi_writeblock(host, t, data);
 			else
 				status = mmc_spi_readblock(host, t);
 			if (status < 0)
@@ -872,6 +892,7 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
 		struct scratch	*scratch = host->data;
 		int		tmp;
 		const unsigned	statlen = sizeof(scratch->status);
+		unsigned int	timeout_ns;
 
 		dev_dbg(&spi->dev, "    mmc_spi: STOP_TRAN\n");
 
@@ -917,7 +938,9 @@ mmc_spi_data_do(struct mmc_spi_host *host, struct mmc_command *cmd,
 			if (scratch->status[tmp] != 0)
 				return;
 		}
-		tmp = mmc_spi_wait_unbusy(host, writeblock_timeout);
+		timeout_ns = mmc_get_write_timeout(host, data);
+		tmp = mmc_spi_wait_unbusy(host,
+			ktime_add_ns(ktime_set(0, 0), timeout_ns));
 		if (tmp < 0 && !data->error)
 			data->error = tmp;
 	}

             reply	other threads:[~2008-09-01 15:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-01 15:12 Matt Fleming [this message]
2008-09-07 10:38 ` Pierre Ossman
2008-09-08 13:28   ` Matt Fleming
2008-09-08 19:18     ` David Brownell
2008-09-09  7:22     ` Pierre Ossman
2008-09-09  7:34       ` Matt Fleming
2008-09-09  7:44         ` Pierre Ossman
2008-09-09  7:59           ` Matt Fleming
2008-09-09  8:55             ` Pierre Ossman
2008-09-09  9:07               ` Matt Fleming
2008-09-09  9:42                 ` Matt Fleming
2008-09-14 13:48                   ` Pierre Ossman
     [not found]                     ` <5ff4a1e50809150103v1e250e0x4192e2fe901750a6@mail.gmail.com>
     [not found]                       ` <20080915103821.2b618bba@mjolnir.drzeus.cx>
2008-09-15  9:24                         ` Matt Fleming
2008-09-20 11:06                           ` Pierre Ossman
2008-09-24 11:16                             ` Matt Fleming
2008-10-02  8:26                               ` Pierre Ossman

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=5ff4a1e50809010812i32168136qea538ba177b81446@mail.gmail.com \
    --to=mattjfleming@googlemail.com \
    --cc=dbrownell@users.sourceforge.net \
    --cc=drzeus-mmc@drzeus.cx \
    --cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®