From: Ulf Hansson <ulf.hansson@linaro.org>
To: linux-mmc@vger.kernel.org, Ulf Hansson <ulf.hansson@linaro.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com>,
linux-renesas-soc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 5/5] mmc: core: Add support for graceful host removal for SD
Date: Thu, 20 Mar 2025 15:00:36 +0100 [thread overview]
Message-ID: <20250320140040.162416-6-ulf.hansson@linaro.org> (raw)
In-Reply-To: <20250320140040.162416-1-ulf.hansson@linaro.org>
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.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/mmc/core/sd.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 8eba697d3d86..cb4254a43f85 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -1596,15 +1596,6 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr,
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.
*/
@@ -1630,7 +1621,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);
@@ -1730,6 +1722,19 @@ static int _mmc_sd_suspend(struct mmc_host *host)
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
*/
--
2.43.0
next prev parent reply other threads:[~2025-03-20 14:00 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-20 14:00 [PATCH 0/5] mmc: core: Add support for graceful host removal for eMMC/SD Ulf Hansson
2025-03-20 14:00 ` [PATCH 1/5] mmc: core: Convert mmc_can_poweroff_notify() into a bool Ulf Hansson
2025-03-28 13:39 ` Avri Altman
2025-03-31 8:14 ` Wolfram Sang
2025-03-20 14:00 ` [PATCH 2/5] mmc: core: Further avoid re-storing power to the eMMC before a shutdown Ulf Hansson
2025-03-28 13:55 ` Avri Altman
2025-03-31 8:21 ` Wolfram Sang
2025-03-31 9:13 ` Ulf Hansson
2025-03-31 10:46 ` Wolfram Sang
2025-03-31 12:06 ` Ulf Hansson
2025-04-01 6:51 ` Wolfram Sang
2025-04-01 11:50 ` Ulf Hansson
2025-03-20 14:00 ` [PATCH 3/5] mmc: core: Convert into an enum for the poweroff-type for eMMC Ulf Hansson
2025-03-31 8:22 ` Wolfram Sang
2025-03-20 14:00 ` [PATCH 4/5] mmc: core: Add support for graceful host removal " Ulf Hansson
2025-03-28 8:13 ` Avri Altman
2025-03-28 10:21 ` Ulf Hansson
2025-03-31 8:27 ` Wolfram Sang
2025-03-31 8:23 ` Wolfram Sang
2025-03-20 14:00 ` Ulf Hansson [this message]
2025-03-31 8:30 ` [PATCH 5/5] mmc: core: Add support for graceful host removal for SD Wolfram Sang
2025-04-01 8:50 ` Wolfram Sang
2025-04-01 8:51 ` Wolfram Sang
2025-04-01 11:51 ` Ulf Hansson
2025-03-20 15:50 ` [PATCH 0/5] mmc: core: Add support for graceful host removal for eMMC/SD Wolfram Sang
2025-03-31 8:32 ` Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250320140040.162416-6-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=adrian.hunter@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.com \
--cc=yoshihiro.shimoda.uh@renesas.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox