@@ -664,21 +664,46 @@ static int mmc_send_op_cond_iter(struct mmc *mmc, int use_arg)
static int mmc_send_op_cond(struct mmc *mmc)
{
+ struct mmc_cmd cmd;
int err, i;
+ int timeout = 1000;
+ ulong start;
/* Some cards seem to need this */
mmc_go_idle(mmc);
- /* Asking to the card its capabilities */
- for (i = 0; i < 2; i++) {
- err = mmc_send_op_cond_iter(mmc, i != 0);
+ cmd.cmdidx = MMC_CMD_SEND_OP_COND;
+ cmd.resp_type = MMC_RSP_R3;
+ cmd.cmdarg = 0;
+
+ start = get_timer(0);
+ /*
+ * According to eMMC specification v5.1 section 6.4.3, we
+ * should issue CMD1 repeatedly in the idle state until
+ * the eMMC is ready. Otherwise some eMMC devices seem to enter
+ * the inactive mode after mmc_complete_op_cond() issued CMD0 when
+ * the eMMC device is busy.
+ */
+ while (1) {
+ err = mmc_send_cmd(mmc, &cmd, NULL);
if (err)
return err;
-
- /* exit if not busy (flag seems to be inverted) */
- if (mmc->ocr & OCR_BUSY)
- break;
+ if (mmc_host_is_spi(mmc)) {
+ if (!(cmd.response[0] & (1 << 0)))
+ break;
+ } else {
+ mmc->ocr = cmd.response[0];
+ /* exit if not busy (flag seems to be inverted) */
+ if (mmc->ocr & OCR_BUSY)
+ break;
+ }
+ if (get_timer(start) > timeout)
+ return -EOPNOTSUPP;
+ udelay(100);
+ if (!mmc_host_is_spi(mmc))
+ cmd.cmdarg = cmd.response[0] | (1 << 30);
}
+
mmc->op_cond_pending = 1;
return 0;
}
@@ -691,7 +716,7 @@ static int mmc_complete_op_cond(struct mmc *mmc)
int err;
mmc->op_cond_pending = 0;
- if (!(mmc->ocr & OCR_BUSY)) {
+ if (mmc->ocr & OCR_BUSY) {
/* Some cards seem to need this */
mmc_go_idle(mmc);