Commit 1677eef45976da1cdccc73cd4291877dbb05eea9

Authored by Andrew Gabbasov
Committed by Pantelis Antoniou
1 parent cc17c01f2d

mmc: Restructure polling loops to avoid extra delays

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@mentor.com>

Showing 1 changed file with 17 additions and 10 deletions Side-by-side Diff

... ... @@ -118,7 +118,7 @@
118 118 if (!mmc_host_is_spi(mmc))
119 119 cmd.cmdarg = mmc->rca << 16;
120 120  
121   - do {
  121 + while (1) {
122 122 err = mmc_send_cmd(mmc, &cmd, NULL);
123 123 if (!err) {
124 124 if ((cmd.response[0] & MMC_STATUS_RDY_FOR_DATA) &&
125 125  
126 126  
... ... @@ -135,10 +135,12 @@
135 135 } else if (--retries < 0)
136 136 return err;
137 137  
  138 + if (timeout-- <= 0)
  139 + break;
  140 +
138 141 udelay(1000);
  142 + }
139 143  
140   - } while (timeout--);
141   -
142 144 #ifdef CONFIG_MMC_TRACE
143 145 status = (cmd.response[0] & MMC_STATUS_CURR_STATE) >> 9;
144 146 printf("CURR STATE:%d\n", status);
... ... @@ -291,7 +293,7 @@
291 293 int err;
292 294 struct mmc_cmd cmd;
293 295  
294   - do {
  296 + while (1) {
295 297 cmd.cmdidx = MMC_CMD_APP_CMD;
296 298 cmd.resp_type = MMC_RSP_R1;
297 299 cmd.cmdarg = 0;
298 300  
299 301  
... ... @@ -322,12 +324,15 @@
322 324 if (err)
323 325 return err;
324 326  
325   - udelay(1000);
326   - } while ((!(cmd.response[0] & OCR_BUSY)) && timeout--);
  327 + if (cmd.response[0] & OCR_BUSY)
  328 + break;
327 329  
328   - if (timeout <= 0)
329   - return UNUSABLE_ERR;
  330 + if (timeout-- <= 0)
  331 + return UNUSABLE_ERR;
330 332  
  333 + udelay(1000);
  334 + }
  335 +
331 336 if (mmc->version != SD_VERSION_2)
332 337 mmc->version = SD_VERSION_1_0;
333 338  
334 339  
335 340  
... ... @@ -405,14 +410,16 @@
405 410 mmc->op_cond_pending = 0;
406 411 if (!(mmc->ocr & OCR_BUSY)) {
407 412 start = get_timer(0);
408   - do {
  413 + while (1) {
409 414 err = mmc_send_op_cond_iter(mmc, 1);
410 415 if (err)
411 416 return err;
  417 + if (mmc->ocr & OCR_BUSY)
  418 + break;
412 419 if (get_timer(start) > timeout)
413 420 return UNUSABLE_ERR;
414 421 udelay(100);
415   - } while (!(mmc->ocr & OCR_BUSY));
  422 + }
416 423 }
417 424  
418 425 if (mmc_host_is_spi(mmc)) { /* read OCR for spi */