* [PATCH 1/2] mci: Support the correct version for eMMC
@ 2014-01-10 9:05 Markus Niebel
2014-01-10 9:05 ` [PATCH 2/2] mci: production year for eMMC 4.41 and later Markus Niebel
2014-01-10 13:59 ` [PATCH 1/2] mci: Support the correct version for eMMC Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Markus Niebel @ 2014-01-10 9:05 UTC (permalink / raw)
To: barebox; +Cc: Markus Niebel
From: Markus Niebel <Markus.Niebel@tqs.de>
eMMC is available up to version 4.5 but the
correct version is not decoded. Change version
definitions to support more minor verions, add
missing versions and parse the minor versions from
ext_csd.
After this, card detection code and devinfo reports
correct versions.
Handling is inspired by u-boot code.
Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
---
drivers/mci/mci-core.c | 38 ++++++++++++++++++++++++++++++--------
include/mci.h | 21 +++++++++++++--------
2 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index a232679..9bdcdbe 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -695,7 +695,6 @@ static void mci_set_bus_width(struct mci *mci, unsigned width)
static void mci_detect_version_from_csd(struct mci *mci)
{
int version;
- char *vstr;
if (mci->version == MMC_VERSION_UNKNOWN) {
/* the version is coded in the bits 127:126 (left aligned) */
@@ -703,32 +702,52 @@ static void mci_detect_version_from_csd(struct mci *mci)
switch (version) {
case 0:
- vstr = "1.2";
mci->version = MMC_VERSION_1_2;
break;
case 1:
- vstr = "1.4";
mci->version = MMC_VERSION_1_4;
break;
case 2:
- vstr = "2.2";
mci->version = MMC_VERSION_2_2;
break;
case 3:
- vstr = "3.0";
mci->version = MMC_VERSION_3;
break;
case 4:
- vstr = "4.0";
mci->version = MMC_VERSION_4;
break;
default:
- vstr = "unknown, fallback to 1.2";
+ printf("unknown card version, fallback to 1.2\n");
mci->version = MMC_VERSION_1_2;
break;
}
+ }
+}
- dev_info(&mci->dev, "detected card version %s\n", vstr);
+/**
+ * correct the version from ext_csd data if it's not an SD-card, detected
+ * version is at least 4 and we have ext_csd data
+ */
+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 1:
+ mci->version = MMC_VERSION_4_1;
+ break;
+ case 2:
+ mci->version = MMC_VERSION_4_2;
+ break;
+ case 3:
+ mci->version = MMC_VERSION_4_3;
+ break;
+ case 5:
+ mci->version = MMC_VERSION_4_41;
+ break;
+ case 6:
+ mci->version = MMC_VERSION_4_5;
+ break;
+ }
}
}
@@ -1093,6 +1112,9 @@ static int mci_startup(struct mci *mci)
if (err)
return err;
+ mci_correct_version_from_ext_csd(mci);
+ printf("detected %s card version %d.%d\n", IS_SD(mci) ? "SD" : "MMC",
+ (mci->version >> 8) & 0xf, mci->version & 0xff);
mci_extract_card_capacity_from_csd(mci);
if (IS_SD(mci))
diff --git a/include/mci.h b/include/mci.h
index 0f10e8a..65f90ca 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -31,18 +31,23 @@
/* Firmware revisions for SD cards */
#define SD_VERSION_SD 0x20000
-#define SD_VERSION_2 (SD_VERSION_SD | 0x20)
-#define SD_VERSION_1_0 (SD_VERSION_SD | 0x10)
-#define SD_VERSION_1_10 (SD_VERSION_SD | 0x1a)
+#define SD_VERSION_2 (SD_VERSION_SD | 0x200)
+#define SD_VERSION_1_0 (SD_VERSION_SD | 0x100)
+#define SD_VERSION_1_10 (SD_VERSION_SD | 0x10a)
/* Firmware revisions for MMC cards */
#define MMC_VERSION_MMC 0x10000
#define MMC_VERSION_UNKNOWN (MMC_VERSION_MMC)
-#define MMC_VERSION_1_2 (MMC_VERSION_MMC | 0x12)
-#define MMC_VERSION_1_4 (MMC_VERSION_MMC | 0x14)
-#define MMC_VERSION_2_2 (MMC_VERSION_MMC | 0x22)
-#define MMC_VERSION_3 (MMC_VERSION_MMC | 0x30)
-#define MMC_VERSION_4 (MMC_VERSION_MMC | 0x40)
+#define MMC_VERSION_1_2 (MMC_VERSION_MMC | 0x102)
+#define MMC_VERSION_1_4 (MMC_VERSION_MMC | 0x104)
+#define MMC_VERSION_2_2 (MMC_VERSION_MMC | 0x202)
+#define MMC_VERSION_3 (MMC_VERSION_MMC | 0x300)
+#define MMC_VERSION_4 (MMC_VERSION_MMC | 0x400)
+#define MMC_VERSION_4_1 (MMC_VERSION_MMC | 0x401)
+#define MMC_VERSION_4_2 (MMC_VERSION_MMC | 0x402)
+#define MMC_VERSION_4_3 (MMC_VERSION_MMC | 0x403)
+#define MMC_VERSION_4_41 (MMC_VERSION_MMC | 0x429)
+#define MMC_VERSION_4_5 (MMC_VERSION_MMC | 0x405)
#define MMC_CAP_SPI (1 << 0)
#define MMC_CAP_4_BIT_DATA (1 << 1)
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] mci: production year for eMMC 4.41 and later
2014-01-10 9:05 [PATCH 1/2] mci: Support the correct version for eMMC Markus Niebel
@ 2014-01-10 9:05 ` Markus Niebel
2014-01-10 13:59 ` [PATCH 1/2] mci: Support the correct version for eMMC Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Markus Niebel @ 2014-01-10 9:05 UTC (permalink / raw)
To: barebox; +Cc: Markus Niebel
From: Markus Niebel <Markus.Niebel@tqs.de>
Year is coded in 4 bits of CID. eMMC 4.41
adds a new interpretation rule: production
year for 4.41 cards and newer is between 2010
and 2025 with 0 corresponding to 2013.
This fix was inspired by currect kernel code.
Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
---
drivers/mci/mci-core.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 9bdcdbe..7161af1 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -717,7 +717,7 @@ static void mci_detect_version_from_csd(struct mci *mci)
mci->version = MMC_VERSION_4;
break;
default:
- printf("unknown card version, fallback to 1.2\n");
+ printf("unknown card version, fallback to 1.02\n");
mci->version = MMC_VERSION_1_2;
break;
}
@@ -1398,10 +1398,17 @@ static unsigned extract_mtd_month(struct mci *mci)
*/
static unsigned extract_mtd_year(struct mci *mci)
{
+ unsigned year;
if (IS_SD(mci))
- return UNSTUFF_BITS(mci->cid, 12, 8) + 2000;
- else
+ year = UNSTUFF_BITS(mci->cid, 12, 8) + 2000;
+ else if (mci->version < MMC_VERSION_4_41)
return UNSTUFF_BITS(mci->cid, 8, 4) + 1997;
+ else {
+ year = UNSTUFF_BITS(mci->cid, 8, 4) + 1997;
+ if (year < 2010)
+ year += 16;
+ }
+ return year;
}
static void mci_print_caps(unsigned caps)
@@ -1448,7 +1455,7 @@ static void mci_info(struct device_d *dev)
(mci->version >> 4) & 0xf, mci->version & 0xf);
} else {
printf(" Attached is an SD Card (Version: %u.%u)\n",
- (mci->version >> 4) & 0xf, mci->version & 0xf);
+ (mci->version >> 8) & 0xf, mci->version & 0xff);
}
printf(" Capacity: %u MiB\n", (unsigned)(mci->capacity >> 20));
--
1.7.9.5
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] mci: Support the correct version for eMMC
2014-01-10 9:05 [PATCH 1/2] mci: Support the correct version for eMMC Markus Niebel
2014-01-10 9:05 ` [PATCH 2/2] mci: production year for eMMC 4.41 and later Markus Niebel
@ 2014-01-10 13:59 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2014-01-10 13:59 UTC (permalink / raw)
To: Markus Niebel; +Cc: barebox, Markus Niebel
On Fri, Jan 10, 2014 at 10:05:32AM +0100, Markus Niebel wrote:
> From: Markus Niebel <Markus.Niebel@tqs.de>
>
> eMMC is available up to version 4.5 but the
> correct version is not decoded. Change version
> definitions to support more minor verions, add
> missing versions and parse the minor versions from
> ext_csd.
>
> After this, card detection code and devinfo reports
> correct versions.
>
> Handling is inspired by u-boot code.
>
> Signed-off-by: Markus Niebel <Markus.Niebel@tqs.de>
Applied, thanks
I also stumbled upon the wrong production dates. Thanks for finxing.
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-10 14:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-10 9:05 [PATCH 1/2] mci: Support the correct version for eMMC Markus Niebel
2014-01-10 9:05 ` [PATCH 2/2] mci: production year for eMMC 4.41 and later Markus Niebel
2014-01-10 13:59 ` [PATCH 1/2] mci: Support the correct version for eMMC Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox