From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] mci: core: reset ERASE_GRP_DEF on startup
Date: Fri, 14 Feb 2025 10:48:50 +0100 [thread overview]
Message-ID: <20250214094850.2847143-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250214094850.2847143-1-a.fatoum@pengutronix.de>
EXT_CSD register EXT_CSD_ERASE_GROUP_DEF loses its value after power
cycles and needs to be reset. Quoting the eMMC 5.1 standard[1]:
After every power-up, when the host uses a device that partition(s)
are configured, it must set the ERASE_GROUP_DEF bit to high before
issuing read, write, erase and write protect commands, because this
bit is reset after power-up. Otherwise, these may not work correctly
and it may leave the stored data in an unknown state.
[1]: JESD84-B51
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/mci/mci-core.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 6d55eb8305b9..098c67f0102b 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1218,11 +1218,24 @@ static void mci_extract_block_lengths_from_csd(struct mci *mci)
}
/**
- * Extract erase group size
+ * Configure erase group size
* @param mci MCI instance
*/
-static void mci_extract_erase_group_size(struct mci *mci)
+static void mci_configure_erase_group_size(struct mci *mci)
{
+ /* Enable ERASE_GRP_DEF. This bit is lost after a reset or power off.
+ * This needs to happen even if we don't have erase support compiled-in.
+ */
+ if (!IS_SD(mci) && mci->version >= MMC_VERSION_4_3) {
+ int err;
+
+ err = mci_switch(mci, EXT_CSD_ERASE_GROUP_DEF, 1);
+ if (err)
+ dev_warn(&mci->dev, "failed erase group switch\n");
+ else
+ mci->ext_csd[EXT_CSD_ERASE_GROUP_DEF] = 1;
+ }
+
if (!IS_ENABLED(CONFIG_MCI_ERASE) ||
!(UNSTUFF_BITS(mci->csd, 84, 12) & CCC_ERASE))
return;
@@ -1954,7 +1967,7 @@ static int mci_startup(struct mci *mci)
dev_info(&mci->dev, "detected %s card version %s\n", IS_SD(mci) ? "SD" : "MMC",
mci_version_string(mci));
mci_extract_card_capacity_from_csd(mci);
- mci_extract_erase_group_size(mci);
+ mci_configure_erase_group_size(mci);
if (IS_SD(mci))
err = mci_startup_sd(mci);
--
2.39.5
next prev parent reply other threads:[~2025-02-14 9:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-14 9:48 [PATCH 1/2] mci: core: import Linux logic for higher preferred erase size Ahmad Fatoum
2025-02-14 9:48 ` Ahmad Fatoum [this message]
2025-02-17 10:53 ` Sascha Hauer
2025-02-17 11:36 ` Ahmad Fatoum
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=20250214094850.2847143-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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