[U-Boot] generic mmc bug in reading sd card capacity

Submitted by victor on Nov. 2, 2012, 7:12 a.m.

Details

Message ID 02e101cdb8c9$7a25fe60$6e71fb20$@keyasic.com
State Rejected
Delegated to: Andy Fleming
Headers show

Commit Message

victor Nov. 2, 2012, 7:12 a.m.
Hi All,

Accord to SD spec 2.0, the formula to find out sd card capacity is:

memory capacity = (C_SIZE+1) * 512K byte 
 	and
C_SIZE  is from CSD [69:48]

Thus, the code in generic mmc is wrong for the high capacity sd card. My
patch is below.

Thanks,
victor

================================================================================================

Patch hide | download patch | download mbox

--- mmc.c	2012-10-09 02:20:28.000000000 +0800
+++ mmc.c.victor	2012-11-02 15:07:16.949207266 +0800
@@ -1068,17 +1104,26 @@ 
 		mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf);
 
 	if (mmc->high_capacity) {
-		csize = (mmc->csd[1] & 0x3f) << 16
-			| (mmc->csd[2] & 0xffff0000) >> 16;
-		cmult = 8;
+		//csize = (mmc->csd[1] & 0x3f) << 16
+		//	| (mmc->csd[2] & 0xffff0000) >> 16;
+		//cmult = 8;
+                csize = (mmc->csd[2] & 0x3f) << 16
+                      | (mmc->csd[1] & 0xffff0000) >> 16;
 	} else {
 		csize = (mmc->csd[1] & 0x3ff) << 2
 			| (mmc->csd[2] & 0xc0000000) >> 30;
 		cmult = (mmc->csd[2] & 0x00038000) >> 15;
 	}
 
-	mmc->capacity = (csize + 1) << (cmult + 2);
-	mmc->capacity *= mmc->read_bl_len;
+	if (mmc->high_capacity) {
+		mmc->capacity = (csize + 1) * 512 * 1024;
+	} else {
+		mmc->capacity = (csize + 1) << (cmult + 2);
+		mmc->capacity *= mmc->read_bl_len;
+	}


================================================================================================
CONFIDENTIALITY NOTE:
This e-mail and any attachments may contain confidential information and may be protected by legal privilege. If you are not the intended addressee (or authorized to receive for the addressee). be aware that any disclosure, copying, distribution or use of this e-mail or any attachment is prohibited. If you have received this e-mail in error, please notify us immediately by returning it to the sender and delete this copy from your system. Thank you for your cooperation.
KeyASIC Inc.