From patchwork Tue Dec 23 09:50:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Santa Cruz X-Patchwork-Id: 423614 X-Patchwork-Delegate: panto@antoniou-consulting.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 01AF2140082 for ; Tue, 23 Dec 2014 20:51:44 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8E7634B6AF; Tue, 23 Dec 2014 10:51:39 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ShZB-KIhJ4FI; Tue, 23 Dec 2014 10:51:39 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B60014B661; Tue, 23 Dec 2014 10:51:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DF44B4B609 for ; Tue, 23 Dec 2014 10:51:12 +0100 (CET) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JyGEyAPzZC7d for ; Tue, 23 Dec 2014 10:51:12 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0097.outbound.protection.outlook.com [157.55.234.97]) by theia.denx.de (Postfix) with ESMTPS id 6E4284B608 for ; Tue, 23 Dec 2014 10:51:08 +0100 (CET) Received: from DB4PR01MB125.eurprd01.prod.exchangelabs.com (10.242.156.12) by DB4PR01MB335.eurprd01.prod.exchangelabs.com (10.242.194.13) with Microsoft SMTP Server (TLS) id 15.1.49.12; Tue, 23 Dec 2014 09:51:07 +0000 Received: from prefix.spinetix.local (212.147.27.179) by DB4PR01MB125.eurprd01.prod.exchangelabs.com (10.242.156.12) with Microsoft SMTP Server (TLS) id 15.1.49.12; Tue, 23 Dec 2014 09:51:06 +0000 From: Diego Santa Cruz To: Date: Tue, 23 Dec 2014 10:50:20 +0100 Message-ID: <1419328233-6977-6-git-send-email-Diego.SantaCruz@spinetix.com> X-Mailer: git-send-email 2.2.1 In-Reply-To: <1419328233-6977-1-git-send-email-Diego.SantaCruz@spinetix.com> References: <1419328233-6977-1-git-send-email-Diego.SantaCruz@spinetix.com> MIME-Version: 1.0 X-Originating-IP: [212.147.27.179] X-ClientProxiedBy: DB4PR04CA0041.eurprd04.prod.outlook.com (25.160.41.51) To DB4PR01MB125.eurprd01.prod.exchangelabs.com (10.242.156.12) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Diego.SantaCruz@spinetix.com; X-Microsoft-Antispam: UriScan:;UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DB4PR01MB125; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004); SRVR:DB4PR01MB125; X-Forefront-PRVS: 04347F8039 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(199003)(189002)(76176999)(77156002)(110136001)(101416001)(68736005)(62966003)(31966008)(40100003)(21056001)(50986999)(122386002)(92566001)(99396003)(48376002)(2950100001)(86362001)(77096005)(87976001)(66066001)(2351001)(20776003)(107046002)(89996001)(97736003)(229853001)(4396001)(46102003)(120916001)(36756003)(64706001)(50466002)(106356001)(105586002)(19580395003)(19580405001)(50226001)(42186005)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:DB4PR01MB125; H:prefix.spinetix.local; FPR:; SPF:None; MLV:sfv; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: spinetix.com does not designate permitted sender hosts) X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:DB4PR01MB125; X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Dec 2014 09:51:06.9367 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR01MB125 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DB4PR01MB335; X-OriginatorOrg: spinetix.com Cc: panto@antoniou-consulting.com Subject: [U-Boot] [PATCH v4 05/18] mmc: incomplete test to switch to high-capacity group size definitions X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- drivers/mmc/mmc.c | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 9ce15d0..5e9926c 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -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);