diff mbox

[U-Boot,V2,3/5] mmc: sd: add erase timeout support

Message ID 1470996817-13731-3-git-send-email-peng.fan@nxp.com
State Superseded
Delegated to: Jaehoon Chung
Headers show

Commit Message

Peng Fan Aug. 12, 2016, 10:13 a.m. UTC
Add timeout in mmc_cmd, we can use this in driver code.
Add mmc_sd_erase_timeout, this function is modified from linux kernel.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Simon Glass <sjg@chromium.org>
Cc: Bin Meng <bmeng.cn@gmail.com>
Cc: Stefan Wahren <stefan.wahren@i2se.com>
Cc: Clemens Gruber <clemens.gruber@pqgruber.com>
Cc: Kever Yang <kever.yang@rock-chips.com>
Cc: Eric Nelson <eric@nelint.com>
Cc: Stephen Warren <swarren@nvidia.com>
---
 drivers/mmc/mmc_write.c | 29 +++++++++++++++++++++++++++++
 include/mmc.h           |  1 +
 2 files changed, 30 insertions(+)
diff mbox

Patch

diff --git a/drivers/mmc/mmc_write.c b/drivers/mmc/mmc_write.c
index 4149f4a..3589f8e 100644
--- a/drivers/mmc/mmc_write.c
+++ b/drivers/mmc/mmc_write.c
@@ -15,6 +15,33 @@ 
 #include <linux/math64.h>
 #include "mmc_private.h"
 
+/*
+ * Modified from from Linux kernel mmc_sd_erase_timeout.
+ */
+static unsigned int mmc_sd_erase_timeout(struct mmc *mmc,
+					 unsigned int nr)
+{
+	unsigned int erase_timeout;
+
+	if (mmc->ssr.erase_timeout) {
+		/* Erase timeout specified in SD Status Register (SSR) */
+		erase_timeout = mmc->ssr.erase_timeout * nr +
+				mmc->ssr.erase_offset;
+	} else {
+		/*
+		 * Erase timeout not specified in SD Status Register (SSR) so
+		 * use 250ms per write block.
+		 */
+		erase_timeout = 250 * nr;
+	}
+
+	/* Must not be less than 1 second */
+	if (erase_timeout < 1000)
+		erase_timeout = 1000;
+
+	return erase_timeout;
+}
+
 static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt)
 {
 	struct mmc_cmd cmd = {0};
@@ -54,6 +81,8 @@  static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt)
 	cmd.cmdidx = MMC_CMD_ERASE;
 	cmd.cmdarg = MMC_ERASE_ARG;
 	cmd.resp_type = MMC_RSP_R1b;
+	if (IS_SD(mmc))
+		cmd.timeout = mmc_sd_erase_timeout(mmc, blkcnt);
 
 	err = mmc_send_cmd(mmc, &cmd, NULL);
 	if (err)
diff --git a/include/mmc.h b/include/mmc.h
index af2595c..432e6ee 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -303,6 +303,7 @@  struct mmc_cmd {
 	uint resp_type;
 	uint cmdarg;
 	uint response[4];
+	int timeout;
 };
 
 struct mmc_data {