Skip to content

Commit 3ae4f26

Browse files
committed
mmc: core: Convert to use __mmc_poll_for_busy() SD_APP_OP_COND too
Similar to what has already been changed for eMMC and the MMC_SEND_OP_COND (CMD1), let's convert the SD_APP_OP_COND (ACMD41) for SD cards to use the common __mmc_poll_for_busy() too. This change means the initial delay period, that starts as 10ms will now increase for every loop when being busy. The total accepted timeout for being busy is 1s, which is according to the SD spec. Signed-off-by: Ulf Hansson <[email protected]> Acked-by: Felix Qin <[email protected]> Reviewed-by: Dragan Simic <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e38063b commit 3ae4f26

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

drivers/mmc/core/sd_ops.c

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@
1919
#include "sd_ops.h"
2020
#include "mmc_ops.h"
2121

22+
#define SD_APP_OP_COND_PERIOD_US (10 * 1000) /* 10ms */
23+
#define SD_APP_OP_COND_TIMEOUT_MS 1000 /* 1s */
24+
25+
struct sd_app_op_cond_busy_data {
26+
struct mmc_host *host;
27+
u32 ocr;
28+
struct mmc_command *cmd;
29+
};
30+
2231
int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card)
2332
{
2433
int err;
@@ -115,10 +124,45 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width)
115124
return mmc_wait_for_app_cmd(card->host, card, &cmd);
116125
}
117126

127+
static int sd_app_op_cond_cb(void *cb_data, bool *busy)
128+
{
129+
struct sd_app_op_cond_busy_data *data = cb_data;
130+
struct mmc_host *host = data->host;
131+
struct mmc_command *cmd = data->cmd;
132+
u32 ocr = data->ocr;
133+
int err;
134+
135+
*busy = false;
136+
137+
err = mmc_wait_for_app_cmd(host, NULL, cmd);
138+
if (err)
139+
return err;
140+
141+
/* If we're just probing, do a single pass. */
142+
if (ocr == 0)
143+
return 0;
144+
145+
/* Wait until reset completes. */
146+
if (mmc_host_is_spi(host)) {
147+
if (!(cmd->resp[0] & R1_SPI_IDLE))
148+
return 0;
149+
} else if (cmd->resp[0] & MMC_CARD_BUSY) {
150+
return 0;
151+
}
152+
153+
*busy = true;
154+
return 0;
155+
}
156+
118157
int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
119158
{
120159
struct mmc_command cmd = {};
121-
int i, err = 0;
160+
struct sd_app_op_cond_busy_data cb_data = {
161+
.host = host,
162+
.ocr = ocr,
163+
.cmd = &cmd
164+
};
165+
int err;
122166

123167
cmd.opcode = SD_APP_OP_COND;
124168
if (mmc_host_is_spi(host))
@@ -127,36 +171,16 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr)
127171
cmd.arg = ocr;
128172
cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR;
129173

130-
for (i = 100; i; i--) {
131-
err = mmc_wait_for_app_cmd(host, NULL, &cmd);
132-
if (err)
133-
break;
134-
135-
/* if we're just probing, do a single pass */
136-
if (ocr == 0)
137-
break;
138-
139-
/* otherwise wait until reset completes */
140-
if (mmc_host_is_spi(host)) {
141-
if (!(cmd.resp[0] & R1_SPI_IDLE))
142-
break;
143-
} else {
144-
if (cmd.resp[0] & MMC_CARD_BUSY)
145-
break;
146-
}
147-
148-
err = -ETIMEDOUT;
149-
150-
mmc_delay(10);
151-
}
152-
153-
if (!i)
154-
pr_err("%s: card never left busy state\n", mmc_hostname(host));
174+
err = __mmc_poll_for_busy(host, SD_APP_OP_COND_PERIOD_US,
175+
SD_APP_OP_COND_TIMEOUT_MS, &sd_app_op_cond_cb,
176+
&cb_data);
177+
if (err)
178+
return err;
155179

156180
if (rocr && !mmc_host_is_spi(host))
157181
*rocr = cmd.resp[0];
158182

159-
return err;
183+
return 0;
160184
}
161185

162186
static int __mmc_send_if_cond(struct mmc_host *host, u32 ocr, u8 pcie_bits,

0 commit comments

Comments
 (0)