Skip to content

Commit 76bfc7c

Browse files
Huijin Parkstorulf
authored andcommitted
mmc: core: adjust polling interval for CMD1
In mmc_send_op_cond(), loops are continuously performed at the same interval of 10 ms. However the behaviour is not good for some eMMC which can be out from a busy state earlier than 10 ms if normal. Rather than fixing about the interval time in mmc_send_op_cond(), let's instead convert into using the common __mmc_poll_for_busy(). The reason for adjusting the interval time is that it is important to reduce the eMMC initialization time, especially in devices that use eMMC as rootfs. Test log(eMMC:KLM8G1GETF-B041): before: 12 ms (0.311016 - 0.298729) [ 0.295823] mmc0: starting CMD0 arg 00000000 flags 000000c0 [ 0.298729] mmc0: starting CMD1 arg 40000080 flags 000000e1<-start [ 0.311016] mmc0: starting CMD1 arg 40000080 flags 000000e1<-finish [ 0.311336] mmc0: starting CMD2 arg 00000000 flags 00000007 after: 2 ms (0.301270 - 0.298762) [ 0.295862] mmc0: starting CMD0 arg 00000000 flags 000000c0 [ 0.298762] mmc0: starting CMD1 arg 40000080 flags 000000e1<-start [ 0.299067] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.299441] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.299879] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.300446] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.301270] mmc0: starting CMD1 arg 40000080 flags 000000e1<-finish [ 0.301572] mmc0: starting CMD2 arg 00000000 flags 00000007 Signed-off-by: Huijin Park <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ulf Hansson <[email protected]>
1 parent 2ebbdac commit 76bfc7c

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

drivers/mmc/core/mmc_ops.c

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ struct mmc_busy_data {
5858
enum mmc_busy_cmd busy_cmd;
5959
};
6060

61+
struct mmc_op_cond_busy_data {
62+
struct mmc_host *host;
63+
u32 ocr;
64+
struct mmc_command *cmd;
65+
};
66+
6167
int __mmc_send_status(struct mmc_card *card, u32 *status, unsigned int retries)
6268
{
6369
int err;
@@ -173,43 +179,62 @@ int mmc_go_idle(struct mmc_host *host)
173179
return err;
174180
}
175181

182+
static int __mmc_send_op_cond_cb(void *cb_data, bool *busy)
183+
{
184+
struct mmc_op_cond_busy_data *data = cb_data;
185+
struct mmc_host *host = data->host;
186+
struct mmc_command *cmd = data->cmd;
187+
u32 ocr = data->ocr;
188+
int err = 0;
189+
190+
err = mmc_wait_for_cmd(host, cmd, 0);
191+
if (err)
192+
return err;
193+
194+
if (mmc_host_is_spi(host)) {
195+
if (!(cmd->resp[0] & R1_SPI_IDLE)) {
196+
*busy = false;
197+
return 0;
198+
}
199+
} else {
200+
if (cmd->resp[0] & MMC_CARD_BUSY) {
201+
*busy = false;
202+
return 0;
203+
}
204+
}
205+
206+
*busy = true;
207+
208+
/*
209+
* According to eMMC specification v5.1 section 6.4.3, we
210+
* should issue CMD1 repeatedly in the idle state until
211+
* the eMMC is ready. Otherwise some eMMC devices seem to enter
212+
* the inactive mode after mmc_init_card() issued CMD0 when
213+
* the eMMC device is busy.
214+
*/
215+
if (!ocr && !mmc_host_is_spi(host))
216+
cmd->arg = cmd->resp[0] | BIT(30);
217+
218+
return 0;
219+
}
220+
176221
int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
177222
{
178223
struct mmc_command cmd = {};
179-
int i, err = 0;
224+
int err = 0;
225+
struct mmc_op_cond_busy_data cb_data = {
226+
.host = host,
227+
.ocr = ocr,
228+
.cmd = &cmd
229+
};
180230

181231
cmd.opcode = MMC_SEND_OP_COND;
182232
cmd.arg = mmc_host_is_spi(host) ? 0 : ocr;
183233
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
184234

185-
for (i = 100; i; i--) {
186-
err = mmc_wait_for_cmd(host, &cmd, 0);
187-
if (err)
188-
break;
189-
190-
/* wait until reset completes */
191-
if (mmc_host_is_spi(host)) {
192-
if (!(cmd.resp[0] & R1_SPI_IDLE))
193-
break;
194-
} else {
195-
if (cmd.resp[0] & MMC_CARD_BUSY)
196-
break;
197-
}
198-
199-
err = -ETIMEDOUT;
200-
201-
mmc_delay(10);
202-
203-
/*
204-
* According to eMMC specification v5.1 section 6.4.3, we
205-
* should issue CMD1 repeatedly in the idle state until
206-
* the eMMC is ready. Otherwise some eMMC devices seem to enter
207-
* the inactive mode after mmc_init_card() issued CMD0 when
208-
* the eMMC device is busy.
209-
*/
210-
if (!ocr && !mmc_host_is_spi(host))
211-
cmd.arg = cmd.resp[0] | BIT(30);
212-
}
235+
err = __mmc_poll_for_busy(host, 1000, &__mmc_send_op_cond_cb, &cb_data);
236+
if (err)
237+
return err;
213238

214239
if (rocr && !mmc_host_is_spi(host))
215240
*rocr = cmd.resp[0];

0 commit comments

Comments
 (0)