mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] mci: add support for eMMC v5.1b
@ 2026-03-02 16:37 Ahmad Fatoum
  2026-03-02 16:37 ` [PATCH 2/3] mci: treat unknown MMC version as greater than known versions Ahmad Fatoum
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-03-02 16:37 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Newer eMMC versions than what barebox knows about appear to be
interpreted as v4.0, which would affect at least erase group
size determination and manufacturer date calculation.

Fix this by adding proper v5.1b support.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/mci-core.c | 11 ++++++++++-
 include/mci.h          |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 37d864b3d02f..54006b149c0a 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1176,6 +1176,9 @@ static void mci_correct_version_from_ext_csd(struct mci *mci)
 		case 8:
 			mci->version = MMC_VERSION_5_1;
 			break;
+		case 9:
+			mci->version = MMC_VERSION_5_1B;
+			break;
 		}
 	}
 }
@@ -1436,7 +1439,7 @@ static char *mci_version_string(struct mci *mci)
 	n = sprintf(version, "%u.%u", major, minor);
 	/* Omit zero micro versions */
 	if (micro)
-		sprintf(version + n, "%u", micro);
+		sprintf(version + n, "%X", micro);
 
 	return version;
 }
@@ -2541,6 +2544,12 @@ static int mci_mmc_decode_cid(struct mci *card)
 			card->cid.year += 16;
 	}
 
+	if (card->version >= MMC_VERSION_5_1B) {
+		/* eMMC 5.1b: y field rolls over again after 2025 */
+		if (card->cid.year < 2023)
+			card->cid.year += 16;
+	}
+
 	return 0;
 }
 
diff --git a/include/mci.h b/include/mci.h
index 50214aaae7bb..b05571730ec2 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -46,6 +46,7 @@
 #define MMC_VERSION_4_5		(MMC_VERSION_MMC | 0x450)
 #define MMC_VERSION_5_0		(MMC_VERSION_MMC | 0x500)
 #define MMC_VERSION_5_1		(MMC_VERSION_MMC | 0x510)
+#define MMC_VERSION_5_1B	(MMC_VERSION_MMC | 0x51B)
 
 #define MMC_CAP_SPI			(1 << 0)
 #define MMC_CAP_4_BIT_DATA		(1 << 1)
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 2/3] mci: treat unknown MMC version as greater than known versions
  2026-03-02 16:37 [PATCH 1/3] mci: add support for eMMC v5.1b Ahmad Fatoum
@ 2026-03-02 16:37 ` Ahmad Fatoum
  2026-03-02 16:37 ` [PATCH 3/3] mci: detect SD card v3 Ahmad Fatoum
  2026-03-04  7:48 ` [PATCH 1/3] mci: add support for eMMC v5.1b Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-03-02 16:37 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

Currently, unknown MMC revisions are assumed to be v4.0-compatible.

Instead let's assume newer eMMC revisions to be compatible with the
newest that's explicitly supported by assigning 0xFFF as versions, so
comparison for being greater than some version always evaluate true.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/mci-core.c | 5 +++++
 include/mci.h          | 1 +
 2 files changed, 6 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 54006b149c0a..517e4de1c6b0 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1155,6 +1155,8 @@ static void mci_correct_version_from_ext_csd(struct mci *mci)
 {
 	if (!IS_SD(mci) && (mci->version >= MMC_VERSION_4) && mci->ext_csd) {
 		switch (mci->ext_csd[EXT_CSD_REV]) {
+		case 0:
+			mci->version = MMC_VERSION_4;
 		case 1:
 			mci->version = MMC_VERSION_4_1;
 			break;
@@ -1179,6 +1181,9 @@ static void mci_correct_version_from_ext_csd(struct mci *mci)
 		case 9:
 			mci->version = MMC_VERSION_5_1B;
 			break;
+		default:
+			mci->version = MMC_VERSION_MAX;
+			break;
 		}
 	}
 }
diff --git a/include/mci.h b/include/mci.h
index b05571730ec2..fc418ec0a2ea 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -47,6 +47,7 @@
 #define MMC_VERSION_5_0		(MMC_VERSION_MMC | 0x500)
 #define MMC_VERSION_5_1		(MMC_VERSION_MMC | 0x510)
 #define MMC_VERSION_5_1B	(MMC_VERSION_MMC | 0x51B)
+#define MMC_VERSION_MAX		(MMC_VERSION_MMC | 0xFFF)
 
 #define MMC_CAP_SPI			(1 << 0)
 #define MMC_CAP_4_BIT_DATA		(1 << 1)
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 3/3] mci: detect SD card v3
  2026-03-02 16:37 [PATCH 1/3] mci: add support for eMMC v5.1b Ahmad Fatoum
  2026-03-02 16:37 ` [PATCH 2/3] mci: treat unknown MMC version as greater than known versions Ahmad Fatoum
@ 2026-03-02 16:37 ` Ahmad Fatoum
  2026-03-04  7:48 ` [PATCH 1/3] mci: add support for eMMC v5.1b Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2026-03-02 16:37 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

We define the constant and the erase group determination code queries
the version, but we didn't actually set it anywhere.

The code determining the SD version was taken from U-Boot, so sync it to
add v3.0 support[1].

[1]: https://github.com/u-boot/u-boot/blob/v2026.04-rc3/drivers/mmc/mmc.c#L1430

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/mci/mci-core.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 517e4de1c6b0..ef5c4c5d6a5d 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -977,6 +977,8 @@ static int sd_change_freq(struct mci *mci)
 		break;
 	case 2:
 		mci->version = SD_VERSION_2;
+		if ((mci->scr[0] >> 15) & 0x1)
+			mci->version = SD_VERSION_3;
 		break;
 	default:
 		mci->version = SD_VERSION_1_0;
-- 
2.47.3




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/3] mci: add support for eMMC v5.1b
  2026-03-02 16:37 [PATCH 1/3] mci: add support for eMMC v5.1b Ahmad Fatoum
  2026-03-02 16:37 ` [PATCH 2/3] mci: treat unknown MMC version as greater than known versions Ahmad Fatoum
  2026-03-02 16:37 ` [PATCH 3/3] mci: detect SD card v3 Ahmad Fatoum
@ 2026-03-04  7:48 ` Sascha Hauer
  2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2026-03-04  7:48 UTC (permalink / raw)
  To: barebox, Ahmad Fatoum


On Mon, 02 Mar 2026 17:37:40 +0100, Ahmad Fatoum wrote:
> Newer eMMC versions than what barebox knows about appear to be
> interpreted as v4.0, which would affect at least erase group
> size determination and manufacturer date calculation.
> 
> Fix this by adding proper v5.1b support.
> 
> 
> [...]

Applied, thanks!

[1/3] mci: add support for eMMC v5.1b
      https://git.pengutronix.de/cgit/barebox/commit/?id=24b9e50b6fbb (link may not be stable)
[2/3] mci: treat unknown MMC version as greater than known versions
      https://git.pengutronix.de/cgit/barebox/commit/?id=e6c4c27a599e (link may not be stable)
[3/3] mci: detect SD card v3
      https://git.pengutronix.de/cgit/barebox/commit/?id=bf5ef9e15b7a (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-03-04  7:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-02 16:37 [PATCH 1/3] mci: add support for eMMC v5.1b Ahmad Fatoum
2026-03-02 16:37 ` [PATCH 2/3] mci: treat unknown MMC version as greater than known versions Ahmad Fatoum
2026-03-02 16:37 ` [PATCH 3/3] mci: detect SD card v3 Ahmad Fatoum
2026-03-04  7:48 ` [PATCH 1/3] mci: add support for eMMC v5.1b Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox