]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
mmc: incomplete test to switch to high-capacity group size definitions
authorDiego Santa Cruz <Diego.SantaCruz@spinetix.com>
Tue, 23 Dec 2014 09:50:20 +0000 (10:50 +0100)
committerPantelis Antoniou <pantelis.antoniou@konsulko.com>
Mon, 19 Jan 2015 15:02:29 +0000 (17:02 +0200)
The eMMC spec mandates that the high-capacity group size definitions
should be enabled when the device is partitioned (by setting
ERASE_GROUP_DEF in EXT_CSD). The current test to determine when this is
required misses a few cases. In particular a device may have been
partitioned without setting the enhanced attribute on any partition
or partitioning may be completed without creating any extra partitions.

This change moves the code to set ERASE_GROUP_DEF to after reading
all partition information. It is also enabled when
PARTITIONING_SETTING_COMPLETED is set as it is necessary to enable
ERASE_GROUP_DEF before setting that bit, so it means that the user
previously switched to the high capacity definitions.

Signed-off-by: Diego Santa Cruz <Diego.SantaCruz@spinetix.com>
drivers/mmc/mmc.c

index 9ce15d03e2c5ee60ecb07da297975cf2338e9bb4..5e9926cddf64987abe4ec1e5490b3c3f9190b134 100644 (file)
@@ -818,6 +818,7 @@ static int mmc_startup(struct mmc *mmc)
        ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
        ALLOC_CACHE_ALIGN_BUFFER(u8, test_csd, MMC_MAX_BLOCK_LEN);
        int timeout = 1000;
+       bool has_parts = false;
 
 #ifdef CONFIG_MMC_SPI_CRC_ON
        if (mmc_host_is_spi(mmc)) { /* enable CRC check for spi */
@@ -1006,13 +1007,41 @@ static int mmc_startup(struct mmc *mmc)
                        break;
                }
 
+               /* store the partition info of emmc */
+               mmc->part_support = ext_csd[EXT_CSD_PARTITIONING_SUPPORT];
+               if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||
+                   ext_csd[EXT_CSD_BOOT_MULT])
+                       mmc->part_config = ext_csd[EXT_CSD_PART_CONF];
+               if (ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & ENHNCD_SUPPORT)
+                       mmc->part_attr = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE];
+
+               mmc->capacity_boot = ext_csd[EXT_CSD_BOOT_MULT] << 17;
+
+               mmc->capacity_rpmb = ext_csd[EXT_CSD_RPMB_MULT] << 17;
+
+               for (i = 0; i < 4; i++) {
+                       int idx = EXT_CSD_GP_SIZE_MULT + i * 3;
+                       mmc->capacity_gp[i] = (ext_csd[idx + 2] << 16) +
+                               (ext_csd[idx + 1] << 8) + ext_csd[idx];
+                       mmc->capacity_gp[i] *=
+                               ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
+                       mmc->capacity_gp[i] *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
+                       if (mmc->capacity_gp[i])
+                               has_parts = true;
+               }
+
                /*
                 * Host needs to enable ERASE_GRP_DEF bit if device is
                 * partitioned. This bit will be lost every time after a reset
                 * or power off. This will affect erase size.
                 */
+               if (ext_csd[EXT_CSD_PARTITION_SETTING] &
+                   EXT_CSD_PARTITION_SETTING_COMPLETED)
+                       has_parts = true;
                if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) &&
-                   (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & PART_ENH_ATTRIB)) {
+                   (ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE] & PART_ENH_ATTRIB))
+                       has_parts = true;
+               if (has_parts) {
                        err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
                                EXT_CSD_ERASE_GROUP_DEF, 1);
 
@@ -1048,27 +1077,6 @@ static int mmc_startup(struct mmc *mmc)
                        mmc->erase_grp_size = (erase_gsz + 1)
                                * (erase_gmul + 1);
                }
-
-               /* store the partition info of emmc */
-               mmc->part_support = ext_csd[EXT_CSD_PARTITIONING_SUPPORT];
-               if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||
-                   ext_csd[EXT_CSD_BOOT_MULT])
-                       mmc->part_config = ext_csd[EXT_CSD_PART_CONF];
-               if (ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & ENHNCD_SUPPORT)
-                       mmc->part_attr = ext_csd[EXT_CSD_PARTITIONS_ATTRIBUTE];
-
-               mmc->capacity_boot = ext_csd[EXT_CSD_BOOT_MULT] << 17;
-
-               mmc->capacity_rpmb = ext_csd[EXT_CSD_RPMB_MULT] << 17;
-
-               for (i = 0; i < 4; i++) {
-                       int idx = EXT_CSD_GP_SIZE_MULT + i * 3;
-                       mmc->capacity_gp[i] = (ext_csd[idx + 2] << 16) +
-                               (ext_csd[idx + 1] << 8) + ext_csd[idx];
-                       mmc->capacity_gp[i] *=
-                               ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
-                       mmc->capacity_gp[i] *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
-               }
        }
 
        err = mmc_set_capacity(mmc, mmc->part_num);