]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mmc: core: Add support for graceful host removal for SD
authorUlf Hansson <ulf.hansson@linaro.org>
Mon, 7 Apr 2025 15:27:55 +0000 (17:27 +0200)
committerUlf Hansson <ulf.hansson@linaro.org>
Wed, 14 May 2025 14:59:16 +0000 (16:59 +0200)
An mmc host driver may allow to unbind from its corresponding host device.
If an SD card is attached to the host, the mmc core will just try to cut
the power for it, without obeying to the SD spec that potentially may
damage the card.

Let's fix this problem by implementing a graceful power-down of the card at
host removal.

Reviewed-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Tested-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://lore.kernel.org/r/20250407152759.25160-6-ulf.hansson@linaro.org
drivers/mmc/core/sd.c

index 6847b3fe8887aaa2a6f4f4bf85041708301e7ee5..08ab076fe2f9ea593ef3f5ebdc01a9473d150093 100644 (file)
@@ -1612,15 +1612,6 @@ free_card:
        return err;
 }
 
-/*
- * Host is being removed. Free up the current card.
- */
-static void mmc_sd_remove(struct mmc_host *host)
-{
-       mmc_remove_card(host->card);
-       host->card = NULL;
-}
-
 /*
  * Card detection - card is alive.
  */
@@ -1646,7 +1637,8 @@ static void mmc_sd_detect(struct mmc_host *host)
        mmc_put_card(host->card, NULL);
 
        if (err) {
-               mmc_sd_remove(host);
+               mmc_remove_card(host->card);
+               host->card = NULL;
 
                mmc_claim_host(host);
                mmc_detach_bus(host);
@@ -1746,6 +1738,19 @@ out:
        return err;
 }
 
+/*
+ * Host is being removed. Free up the current card and do a graceful power-off.
+ */
+static void mmc_sd_remove(struct mmc_host *host)
+{
+       get_device(&host->card->dev);
+       mmc_remove_card(host->card);
+
+       _mmc_sd_suspend(host);
+
+       put_device(&host->card->dev);
+       host->card = NULL;
+}
 /*
  * Callback for suspend
  */