Skip to contentSkip to conversation

mmc: fix the condition for MMC version 4

PATCH New Yoshihiro Shimoda 1 participant 1 message Jul 5, 2011 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mmc: fix the condition for MMC version 4

Fix the problem that if we use the chip of MMC version 4 and the capacity is smaller than 2GB or equal, the mmc->capacity is invalid. According to the JEDEC Standard, the value of ext_csd's capacity is valid if the value is more than 2GB.

---
 drivers/mmc/mmc.c |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
drivers/mmc/mmc.c +11 -4
index 21aedba..79a162b 100644
@@ -771,7 +771,7 @@ int mmc_startup(struct mmc *mmc)
 {
 	int err;
 	uint mult, freq;
-	u64 cmult, csize;
+	u64 cmult, csize, capacity;
 	struct mmc_cmd cmd;
 	char ext_csd[512];
 	int timeout = 1000;
@@ -916,9 +916,16 @@ int mmc_startup(struct mmc *mmc)
 		/* check  ext_csd version and capacity */
 		err = mmc_send_ext_csd(mmc, ext_csd);
 		if (!err & (ext_csd[192] >= 2)) {
-			mmc->capacity = ext_csd[212] << 0 | ext_csd[213] << 8 |
-					ext_csd[214] << 16 | ext_csd[215] << 24;
-			mmc->capacity *= 512;
+			/*
+			 * According to the JEDEC Standard, the value of
+			 * ext_csd's capacity is valid if the value is more
+			 * than 2GB
+			 */
+			capacity = ext_csd[212] << 0 | ext_csd[213] << 8 |
+				   ext_csd[214] << 16 | ext_csd[215] << 24;
+			capacity *= 512;
+			if (capacity > 2 * 1024 * 1024 * 1024)
+				mmc->capacity = capacity;
 		}
 
 		/* store the partition info of emmc */
Signature · 1 line
1.7.1