Skip to content

Commit 1dc5a61

Browse files
author
Ulf Hansson
committed
mmc: sdio: Align the initialization commands in retry path for UHS-I
According to the comment in mmc_sdio_reinit_card(), some SDIO cards may require a "[CMD5,5,3,7] init sequence", which isn't always obeyed in mmc_sdio_init_card(). Especially, when we end up retrying the UHS-I specific initialization, there is a missing CMD5. Let's update the code to make the behaviour consistent and let's also take the opportunity to clean up the code a bit, to avoid open coding. Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://lore.kernel.org/r/20200430091640.455-5-ulf.hansson@linaro.org
1 parent fa1e319 commit 1dc5a61

1 file changed

Lines changed: 26 additions & 27 deletions

File tree

‎drivers/mmc/core/sdio.c‎

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -543,13 +543,33 @@ static int mmc_sdio_init_uhs_card(struct mmc_card *card)
543543
return err;
544544
}
545545

546-
static void mmc_sdio_resend_if_cond(struct mmc_host *host, u32 ocr,
547-
struct mmc_card *card)
546+
static int mmc_sdio_pre_init(struct mmc_host *host, u32 ocr,
547+
struct mmc_card *card)
548548
{
549+
if (card)
550+
mmc_remove_card(card);
551+
552+
/*
553+
* Reset the card by performing the same steps that are taken by
554+
* mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe.
555+
*
556+
* sdio_reset() is technically not needed. Having just powered up the
557+
* hardware, it should already be in reset state. However, some
558+
* platforms (such as SD8686 on OLPC) do not instantly cut power,
559+
* meaning that a reset is required when restoring power soon after
560+
* powering off. It is harmless in other cases.
561+
*
562+
* The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec,
563+
* is not necessary for non-removable cards. However, it is required
564+
* for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
565+
* harmless in other situations.
566+
*
567+
*/
568+
549569
sdio_reset(host);
550570
mmc_go_idle(host);
551571
mmc_send_if_cond(host, ocr);
552-
mmc_remove_card(card);
572+
return mmc_send_io_op_cond(host, 0, NULL);
553573
}
554574

555575
/*
@@ -640,7 +660,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
640660
if (rocr & ocr & R4_18V_PRESENT) {
641661
err = mmc_set_uhs_voltage(host, ocr_card);
642662
if (err == -EAGAIN) {
643-
mmc_sdio_resend_if_cond(host, ocr_card, card);
663+
mmc_sdio_pre_init(host, ocr_card, card);
644664
retries--;
645665
goto try_again;
646666
} else if (err) {
@@ -712,7 +732,7 @@ static int mmc_sdio_init_card(struct mmc_host *host, u32 ocr,
712732
*/
713733
err = sdio_read_cccr(card, ocr);
714734
if (err) {
715-
mmc_sdio_resend_if_cond(host, ocr_card, card);
735+
mmc_sdio_pre_init(host, ocr_card, card);
716736
if (ocr & R4_18V_PRESENT) {
717737
/* Retry init sequence, but without R4_18V_PRESENT. */
718738
retries = 0;
@@ -813,28 +833,7 @@ static int mmc_sdio_reinit_card(struct mmc_host *host)
813833
{
814834
int ret;
815835

816-
/*
817-
* Reset the card by performing the same steps that are taken by
818-
* mmc_rescan_try_freq() and mmc_attach_sdio() during a "normal" probe.
819-
*
820-
* sdio_reset() is technically not needed. Having just powered up the
821-
* hardware, it should already be in reset state. However, some
822-
* platforms (such as SD8686 on OLPC) do not instantly cut power,
823-
* meaning that a reset is required when restoring power soon after
824-
* powering off. It is harmless in other cases.
825-
*
826-
* The CMD5 reset (mmc_send_io_op_cond()), according to the SDIO spec,
827-
* is not necessary for non-removable cards. However, it is required
828-
* for OLPC SD8686 (which expects a [CMD5,5,3,7] init sequence), and
829-
* harmless in other situations.
830-
*
831-
*/
832-
833-
sdio_reset(host);
834-
mmc_go_idle(host);
835-
mmc_send_if_cond(host, host->card->ocr);
836-
837-
ret = mmc_send_io_op_cond(host, 0, NULL);
836+
ret = mmc_sdio_pre_init(host, host->card->ocr, NULL);
838837
if (ret)
839838
return ret;
840839

0 commit comments

Comments
 (0)