mmc: Fix erase_grp_size for partitioned card

EXT_CSD_ERASE_GROUP_DEF is lost every time after a reset or
 power off. Set it if device has enhanced partitions.

Signed-off-by: Oliver Metz <oliver@freetz.org>
Acked-by: Pantelis Antoniou <panto@antoniou-consulting.com>
This commit is contained in:
Oliver Metz 2013-10-01 20:32:07 +02:00 committed by Pantelis Antoniou
parent 509dca7a11
commit 1937e5aa3b
2 changed files with 15 additions and 4 deletions

View file

@ -960,15 +960,24 @@ static int mmc_startup(struct mmc *mmc)
} }
/* /*
* Check whether GROUP_DEF is set, if yes, read out * Host needs to enable ERASE_GRP_DEF bit if device is
* group size from ext_csd directly, or calculate * partitioned. This bit will be lost every time after a reset
* the group size from the csd value. * or power off. This will affect erase size.
*/ */
if (ext_csd[EXT_CSD_ERASE_GROUP_DEF]) { if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) &&
(ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & PART_ENH_ATTRIB)) {
err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
EXT_CSD_ERASE_GROUP_DEF, 1);
if (err)
return err;
/* Read out group size from ext_csd */
mmc->erase_grp_size = mmc->erase_grp_size =
ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] * ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] *
MMC_MAX_BLOCK_LEN * 1024; MMC_MAX_BLOCK_LEN * 1024;
} else { } else {
/* Calculate the group size from the csd value. */
int erase_gsz, erase_gmul; int erase_gsz, erase_gmul;
erase_gsz = (mmc->csd[2] & 0x00007c00) >> 10; erase_gsz = (mmc->csd[2] & 0x00007c00) >> 10;
erase_gmul = (mmc->csd[2] & 0x000003e0) >> 5; erase_gmul = (mmc->csd[2] & 0x000003e0) >> 5;

View file

@ -148,6 +148,7 @@
* EXT_CSD fields * EXT_CSD fields
*/ */
#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ #define EXT_CSD_GP_SIZE_MULT 143 /* R/W */
#define EXT_CSD_PARTITIONS_ATTRIBUTE 156 /* R/W */
#define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */ #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */
#define EXT_CSD_RPMB_MULT 168 /* RO */ #define EXT_CSD_RPMB_MULT 168 /* RO */
#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
@ -210,6 +211,7 @@
#define MMCPART_NOAVAILABLE (0xff) #define MMCPART_NOAVAILABLE (0xff)
#define PART_ACCESS_MASK (0x7) #define PART_ACCESS_MASK (0x7)
#define PART_SUPPORT (0x1) #define PART_SUPPORT (0x1)
#define PART_ENH_ATTRIB (0x1f)
/* Maximum block size for MMC */ /* Maximum block size for MMC */
#define MMC_MAX_BLOCK_LEN 512 #define MMC_MAX_BLOCK_LEN 512