@@ -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)
@@ -303,6 +303,7 @@ struct mmc_cmd {
uint resp_type;
uint cmdarg;
uint response[4];
+ int timeout;
};
struct mmc_data {
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(+)