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

Peng Fan van.freenix at gmail.com
Fri Aug 12 12:13:35 CEST 2016


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

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 {
-- 
2.6.2



More information about the U-Boot mailing list