[U-Boot] [PATCH 5/6] mmc: Restructure polling loops to avoid extra delays

Pantelis Antoniou pantelis.antoniou at gmail.com
Tue May 5 11:09:57 CEST 2015


Hi Andrew,

> On Mar 19, 2015, at 14:44 , Andrew Gabbasov <andrew_gabbasov at mentor.com> wrote:
> 
> The polling loops in sd_send_op_cond and mmc_complete_op_cond functions
> check the ready flag state at the end of the loop, that is after executing
> a delay inside the loop, which, in case of exiting with no error,
> is not needed. Also, one of these loops, as well as the loop
> in mmc_send_status, have the delay just before exiting on timeout
> conditions.
> 
> Restructure all these loops to check the respective conditions before making
> a delay for the next loop pass, and to appropriately exit without the delay.
> 
> Signed-off-by: Andrew Gabbasov <andrew_gabbasov at mentor.com>
> ---
> drivers/mmc/mmc.c | 27 +++++++++++++++++----------
> 1 file changed, 17 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index 42af47c..b81533c 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -118,7 +118,7 @@ int mmc_send_status(struct mmc *mmc, int timeout)
> 	if (!mmc_host_is_spi(mmc))
> 		cmd.cmdarg = mmc->rca << 16;
> 
> -	do {
> +	while (1) {
> 		err = mmc_send_cmd(mmc, &cmd, NULL);
> 		if (!err) {
> 			if ((cmd.response[0] & MMC_STATUS_RDY_FOR_DATA) &&
> @@ -135,9 +135,11 @@ int mmc_send_status(struct mmc *mmc, int timeout)
> 		} else if (--retries < 0)
> 			return err;
> 
> -		udelay(1000);
> +		if (timeout-- <= 0)
> +			break;
> 
> -	} while (timeout--);
> +		udelay(1000);
> +	}
> 
> #ifdef CONFIG_MMC_TRACE
> 	status = (cmd.response[0] & MMC_STATUS_CURR_STATE) >> 9;
> @@ -291,7 +293,7 @@ static int sd_send_op_cond(struct mmc *mmc)
> 	int err;
> 	struct mmc_cmd cmd;
> 
> -	do {
> +	while (1) {
> 		cmd.cmdidx = MMC_CMD_APP_CMD;
> 		cmd.resp_type = MMC_RSP_R1;
> 		cmd.cmdarg = 0;
> @@ -322,11 +324,14 @@ static int sd_send_op_cond(struct mmc *mmc)
> 		if (err)
> 			return err;
> 
> -		udelay(1000);
> -	} while ((!(cmd.response[0] & OCR_BUSY)) && timeout--);
> +		if (cmd.response[0] & OCR_BUSY)
> +			break;
> 
> -	if (timeout <= 0)
> -		return UNUSABLE_ERR;
> +		if (timeout-- <= 0)
> +			return UNUSABLE_ERR;
> +
> +		udelay(1000);
> +	}
> 
> 	if (mmc->version != SD_VERSION_2)
> 		mmc->version = SD_VERSION_1_0;
> @@ -405,14 +410,16 @@ static int mmc_complete_op_cond(struct mmc *mmc)
> 	mmc->op_cond_pending = 0;
> 	if (!(mmc->ocr & OCR_BUSY)) {
> 		start = get_timer(0);
> -		do {
> +		while (1) {
> 			err = mmc_send_op_cond_iter(mmc, 1);
> 			if (err)
> 				return err;
> +			if (mmc->ocr & OCR_BUSY)
> +				break;
> 			if (get_timer(start) > timeout)
> 				return UNUSABLE_ERR;
> 			udelay(100);
> -		} while (!(mmc->ocr & OCR_BUSY));
> +		}
> 	}
> 
> 	if (mmc_host_is_spi(mmc)) { /* read OCR for spi */
> -- 
> 2.1.0

Thanks, Applied.

— Pantelis



More information about the U-Boot mailing list