mmc: spi: Fix card detection during probe [Linux 5.0]

mmc: spi: Fix card detection during probe [Linux 5.0]

This Linux kernel change "mmc: spi: Fix card detection during probe" is included in the Linux 5.0 release. This change is authored by Jonathan Neuschäfer <j.neuschaefer [at]> on Sun Feb 10 18:31:07 2019 +0100. The commit for this change in Linux stable tree is c9bd505 (patch).

mmc: spi: Fix card detection during probe

When using the mmc_spi driver with a card-detect pin, I noticed that the
card was not detected immediately after probe, but only after it was
unplugged and plugged back in (and the CD IRQ fired).

The call tree looks something like this:

        mmc_schedule_delayed_work(&host->detect, 0)
                    mmc_gpio_get_cd -> -ENOSYS (ctx->cd_gpio not set)
    ctx->cd_gpio = desc

To fix this issue, call mmc_detect_change after the card-detect GPIO/IRQ
is registered.

Signed-off-by: Jonathan Neuschäfer <[email protected]>
Reviewed-by: Linus Walleij <[email protected]>
Cc: [email protected]
Signed-off-by: Ulf Hansson <[email protected]>

There is one line of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/mmc/host/mmc_spi.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c
index 10ba46b..8ade14f 100644
--- a/drivers/mmc/host/mmc_spi.c
+++ b/drivers/mmc/host/mmc_spi.c
@@ -1450,6 +1450,7 @@ static int mmc_spi_probe(struct spi_device *spi)
        mmc->caps &= ~MMC_CAP_NEEDS_POLL;
+   mmc_detect_change(mmc, 0);

    /* Index 1 is write protect/read only */
    status = mmc_gpiod_request_ro(mmc, NULL, 1, false, 0, NULL);

Leave a Reply

Your email address will not be published. Required fields are marked *