summaryrefslogtreecommitdiffstats
path: root/drivers/mci
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-11-29 16:48:19 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2012-12-03 19:48:25 +0100
commitfa5b8a2a32c23dcd2cd2f6c2191f33b9535df465 (patch)
treec08d36316cf70c59d6164be48057d1aeeae30e0c /drivers/mci
parentae01f384f2435ed694226ac924c307a023f20a9b (diff)
downloadbarebox-fa5b8a2a32c23dcd2cd2f6c2191f33b9535df465.tar.gz
barebox-fa5b8a2a32c23dcd2cd2f6c2191f33b9535df465.tar.xz
mci: Fix capacity calculation for high capacity MMC cards
For these cards we have to calculate the size using the ext csd sector count fields. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mci')
-rw-r--r--drivers/mci/mci-core.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index 0d601e3385..88892b646f 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -758,15 +758,22 @@ static void mci_extract_card_capacity_from_csd(struct mci *mci)
uint64_t csize, cmult;
if (mci->high_capacity) {
- csize = (mci->csd[1] & 0x3f) << 16 | (mci->csd[2] & 0xffff0000) >> 16;
- cmult = 8;
+ if (IS_SD(mci)) {
+ csize = UNSTUFF_BITS(mci->csd, 48, 22);
+ mci->capacity = (1 + csize) << 10;
+ } else {
+ mci->capacity = mci->ext_csd[EXT_CSD_SEC_CNT] << 0 |
+ mci->ext_csd[EXT_CSD_SEC_CNT + 1] << 8 |
+ mci->ext_csd[EXT_CSD_SEC_CNT + 2] << 16 |
+ mci->ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
+ }
} else {
- csize = (mci->csd[1] & 0x3ff) << 2 | (mci->csd[2] & 0xc0000000) >> 30;
- cmult = (mci->csd[2] & 0x00038000) >> 15;
+ cmult = UNSTUFF_BITS(mci->csd, 47, 3);
+ csize = UNSTUFF_BITS(mci->csd, 62, 12);
+ mci->capacity = (csize + 1) << (cmult + 2);
}
- mci->capacity = (csize + 1) << (cmult + 2);
- mci->capacity *= mci->read_bl_len;
+ mci->capacity *= 1 << UNSTUFF_BITS(mci->csd, 80, 4);;
dev_dbg(mci->mci_dev, "Capacity: %u MiB\n", (unsigned)(mci->capacity >> 20));
}
@@ -996,7 +1003,6 @@ static int mci_startup(struct mci *mci)
mci_detect_version_from_csd(mci);
mci_extract_max_tran_speed_from_csd(mci);
mci_extract_block_lengths_from_csd(mci);
- mci_extract_card_capacity_from_csd(mci);
/* sanitiy? */
if (mci->read_bl_len > SECTOR_SIZE) {
@@ -1032,6 +1038,8 @@ static int mci_startup(struct mci *mci)
if (err)
return err;
+ mci_extract_card_capacity_from_csd(mci);
+
/* Restrict card's capabilities by what the host can do */
mci->card_caps &= host->host_caps;