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....@nxp.com> Cc: Jaehoon Chung <jh80.ch...@samsung.com> Cc: Simon Glass <s...@chromium.org> Cc: Bin Meng <bmeng...@gmail.com> Cc: Stefan Wahren <stefan.wah...@i2se.com> Cc: Clemens Gruber <clemens.gru...@pqgruber.com> Cc: Kever Yang <kever.y...@rock-chips.com> Cc: Eric Nelson <e...@nelint.com> Cc: Stephen Warren <swar...@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 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot