Commit 1937e5aa3b0ec0767a36580db654ef8918c09b84

Authored by Oliver Metz
Committed by Pantelis Antoniou
1 parent 509dca7a11

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>

Showing 2 changed files with 15 additions and 4 deletions Side-by-side Diff

... ... @@ -960,15 +960,24 @@
960 960 }
961 961  
962 962 /*
963   - * Check whether GROUP_DEF is set, if yes, read out
964   - * group size from ext_csd directly, or calculate
965   - * the group size from the csd value.
  963 + * Host needs to enable ERASE_GRP_DEF bit if device is
  964 + * partitioned. This bit will be lost every time after a reset
  965 + * or power off. This will affect erase size.
966 966 */
967   - if (ext_csd[EXT_CSD_ERASE_GROUP_DEF]) {
  967 + if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) &&
  968 + (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & PART_ENH_ATTRIB)) {
  969 + err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
  970 + EXT_CSD_ERASE_GROUP_DEF, 1);
  971 +
  972 + if (err)
  973 + return err;
  974 +
  975 + /* Read out group size from ext_csd */
968 976 mmc->erase_grp_size =
969 977 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] *
970 978 MMC_MAX_BLOCK_LEN * 1024;
971 979 } else {
  980 + /* Calculate the group size from the csd value. */
972 981 int erase_gsz, erase_gmul;
973 982 erase_gsz = (mmc->csd[2] & 0x00007c00) >> 10;
974 983 erase_gmul = (mmc->csd[2] & 0x000003e0) >> 5;
... ... @@ -148,6 +148,7 @@
148 148 * EXT_CSD fields
149 149 */
150 150 #define EXT_CSD_GP_SIZE_MULT 143 /* R/W */
  151 +#define EXT_CSD_PARTITIONS_ATTRIBUTE 156 /* R/W */
151 152 #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */
152 153 #define EXT_CSD_RPMB_MULT 168 /* RO */
153 154 #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */
... ... @@ -210,6 +211,7 @@
210 211 #define MMCPART_NOAVAILABLE (0xff)
211 212 #define PART_ACCESS_MASK (0x7)
212 213 #define PART_SUPPORT (0x1)
  214 +#define PART_ENH_ATTRIB (0x1f)
213 215  
214 216 /* Maximum block size for MMC */
215 217 #define MMC_MAX_BLOCK_LEN 512