From patchwork Wed Nov 19 19:27:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Lemberg X-Patchwork-Id: 5340661 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D86629F1E1 for ; Wed, 19 Nov 2014 19:43:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D8EBF201F5 for ; Wed, 19 Nov 2014 19:43:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E5EB5201EF for ; Wed, 19 Nov 2014 19:43:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755737AbaKSTnf (ORCPT ); Wed, 19 Nov 2014 14:43:35 -0500 Received: from mail-by2on0062.outbound.protection.outlook.com ([207.46.100.62]:47488 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754598AbaKSTne (ORCPT ); Wed, 19 Nov 2014 14:43:34 -0500 Received: from BLUPR02CA024.namprd02.prod.outlook.com (25.160.23.142) by BLUPR02MB114.namprd02.prod.outlook.com (10.242.187.23) with Microsoft SMTP Server (TLS) id 15.1.16.15; Wed, 19 Nov 2014 19:28:04 +0000 Received: from BL2FFO11FD056.protection.gbl (2a01:111:f400:7c09::123) by BLUPR02CA024.outlook.office365.com (2a01:111:e400:8ad::14) with Microsoft SMTP Server (TLS) id 15.1.26.15 via Frontend Transport; Wed, 19 Nov 2014 19:28:03 +0000 Received: from milsmgep12.sandisk.com (63.163.107.173) by BL2FFO11FD056.mail.protection.outlook.com (10.173.161.184) with Microsoft SMTP Server id 15.1.6.13 via Frontend Transport; Wed, 19 Nov 2014 19:28:01 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id D4.B4.11368.04FEC645; Wed, 19 Nov 2014 11:28:00 -0800 (PST) Received: from milsmgip11.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.195.1; Wed, 19 Nov 2014 11:28:00 -0800 X-AuditID: ac160a69-f79066d000002c68-26-546cef402933 Received: from E6410-C110490.sdcorp.global.sandisk.com ( [10.177.8.100]) by milsmgip11.sandisk.com (Symantec Messaging Gateway) with SMTP id 5B.39.10458.F3FEC645; Wed, 19 Nov 2014 11:28:00 -0800 (PST) From: Alex Lemberg To: CC: , , , Alex Lemberg Subject: [PATCH] mmc: Add Production State Awareness Support Date: Wed, 19 Nov 2014 21:27:56 +0200 Message-ID: <1416425276-4672-1-git-send-email-alex.lemberg@sandisk.com> X-Mailer: git-send-email 2.1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLLMWRmVeSWpSXmKPExsWyRoxnka7D+5wQgyvXjS0mXN7OaHHkfz+j xfG14Q7MHneu7WHzuPFqIZPH501yAcxRXDYpqTmZZalF+nYJXBkP+1azFGxRqjg37zpTA2OT TBcjJ4eEgInE3DsbWCFsMYkL99azdTFycQgJnGCUePXlJpSzg1HibccXVpiOlnUdTBCJM4wS O1+0soMk2AR0JV58eMrYxcjBISIgI9F4wBgkzCxQJ3FrQxsbSFhYwEZiz3JlkDCLgKrEhh1v WEBsXgF3iW/nrzBBjJeT2LD7PyPIeAmB1ywS61rnQhUJSpyc+YQFYqaExMEXL5hBZgoBDTr7 tm4Co+AsJFWzkFQtYGRaxSiWm5lTnJueWmBopFecmJeSWZytl5yfu4kRHKhcmTsYV0wyP8Qo wMGoxMP74m12iBBrYllxZe4hRgkOZiUR3sNvckKEeFMSK6tSi/Lji0pzUosPMUpzsCiJ8wpO z/IXEkhPLEnNTk0tSC2CyTJxcEo1MPYckd3t8SJ9qeHR9gmv3Q7531L9w/32bL5vltXUkvxD r/ZeW+KTbL+oJMXh0SLjOOOEO+qTem9zGnD8ajvIMWl/2rE95qYz7lnwrgyqOLN8aYyrwczb j6weS4ftzFp+pEqWadf1lVsefjjNsoCtPGD2ntolzwqfKbDr3U7K5PF7N/Hgth8MS48rsRRn JBpqMRcVJwIA/aBbu1ACAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprIJMWRmVeSWpSXmKPExsXCtZEjRdfhfU6IwZEnihY3H/xgs9i5dx2T xYTL2xktjvzvZ7Q4vjbcgdXjzrU9bB43Xi1k8pi25jyTx+dNcgEsUVw2Kak5mWWpRfp2CVwZ D/tWsxRsUao4N+86UwNjk0wXIyeHhICJRMu6DiYIW0ziwr31bCC2kMApRol9Bz1BbDYBXYkX H54ygtgiAlISPU+bmbsYOTiYBWokmqZFgZjCAjYSe5Yrg1SwCKhKbNjxhgXE5hVwl9i2/S87 xHQ5iQ27/zNOYORawMiwilEsNzOnODc9s8DQUK84MS8lszhbLzk/dxMj2NOckTsYn040P8TI xMEp1cA47d59ZyGWJX5abjKl6xWbf4ZcfpFzfkMWz8PoR9+SCk7uMz/WvL7a64FV17yVfZX8 s2qj+x2F/75ezVLisvxO4m0fuV+Lgj25r5wwUGU6Fj5ZT/uZ+naeiwkLKzckXa/0CAkPqugw sft2wUhzq/IGtgaZHe7dSjMvS0r4Cs9UaPy75ZTFl5NKLMUZiYZazEXFiQA74Z1apAEAAA== MIME-Version: 1.0 X-EOPAttributedMessage: 0 Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=Alex.Lemberg@sandisk.com; X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(189002)(199003)(50226001)(110136001)(107046002)(2351001)(120916001)(81156004)(19580395003)(19580405001)(50466002)(69596002)(44976005)(21056001)(68736004)(33646002)(106466001)(15202345003)(95666004)(62966003)(4396001)(89996001)(77156002)(50986999)(102836001)(229853001)(99396003)(104166001)(15975445006)(20776003)(31966008)(97736003)(46102003)(86362001)(92566001)(64706001)(48376002)(88136002)(92726001)(87936001)(84676001)(47776003)(36756003)(87286001)(93916002); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR02MB114; H:milsmgep12.sandisk.com; FPR:; MLV:sfv; PTR:ErrorRetry; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB114; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB114; X-Forefront-PRVS: 04004D94E2 X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BLUPR02MB114; X-OriginatorOrg: sandisk.com Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In this patch driver should recognize if eMMC device (Rev >=5.0) was left in PRE_SOLDERING_POST_WRITES (0x02) state, and switch it to NORMAL (0x00). PRE_SOLDERING_POST_WRITES (0x02) state - represents a state where the device is in production process and the host (usually programmer) completed loading the content to the device. The host (usually programmer) sets the device to this state after loading the content and just before soldering. After soldering the device to the real host (not programmer), the device should be switched to NORMAL (0x00) mode. The NORMAL (0x00) mode of PSA register represents a state in which the device is running in the field and uses regular operations. Leaving device in PRE_SOLDERING_POST_WRITES (0x02) might cause unexpected behaviour of eMMC device. More details about PSA feature can be found in eMMC5.0 JEDEC spec (JESD84-B50.pdf): http://www.jedec.org/standards-documents/technology-focus-areas/flash-memory-ssds-ufs-emmc/e-mmc Signed-off-by: Alex Lemberg diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 02ad792..3923c90 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -571,6 +571,16 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) card->ext_csd.ffu_capable = (ext_csd[EXT_CSD_SUPPORTED_MODE] & 0x1) && !(ext_csd[EXT_CSD_FW_CONFIG] & 0x1); + card->ext_csd.psa = + ext_csd[EXT_CSD_PSA]; + if (ext_csd[EXT_CSD_PSA_TIMEOUT] > 0) { + card->ext_csd.psa_timeout = + 100 * + (1 << ext_csd[EXT_CSD_PSA_TIMEOUT]); + } else { + pr_warn("%s: EXT_CSD PSA Timeout is zero\n", + mmc_hostname(card->host)); + }format-patch } out: return err; @@ -1331,6 +1341,24 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr, mmc_set_dsr(host); /* + * eMMC v5.0 or later + * and Production State Awareness state is + * EXT_CSD_PSA_POST_SOLDERING_WRITES (0x02) + * The host should set the device to NORMAL mode + */ + if ((card->ext_csd.rev >= 7) && + (card->ext_csd.psa == EXT_CSD_PSA_POST_SOLDERING_WRITES)) { + unsigned int timeout; + + timeout = DIV_ROUND_UP(card->ext_csd.psa_timeout, 1000); + card->ext_csd.psa = EXT_CSD_PSA_NORMAL; + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, + EXT_CSD_PSA, card->ext_csd.psa, timeout); + if (err && err != -EBADMSG) + goto free_card; + } + + /* * Select card, as all following commands rely on that. */ if (!mmc_host_is_spi(host)) { diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 4d69c00..09ac3b0 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -60,9 +60,11 @@ struct mmc_ext_csd { u8 packed_event_en; unsigned int part_time; /* Units: ms */ unsigned int sa_timeout; /* Units: 100ns */ + unsigned int psa_timeout; /* Units: 100us */ unsigned int generic_cmd6_time; /* Units: 10ms */ unsigned int power_off_longtime; /* Units: ms */ u8 power_off_notification; /* state */ + u8 psa; /* production state awareness */ unsigned int hs_max_dtr; unsigned int hs200_max_dtr; #define MMC_HIGH_26_MAX_DTR 26000000 diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h index 49ad7a9..458814d 100644 --- a/include/linux/mmc/mmc.h +++ b/include/linux/mmc/mmc.h @@ -285,6 +285,7 @@ struct _mmc_csd { #define EXT_CSD_EXP_EVENTS_STATUS 54 /* RO, 2 bytes */ #define EXT_CSD_EXP_EVENTS_CTRL 56 /* R/W, 2 bytes */ #define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ +#define EXT_CSD_PSA 133 /* R/W/E */ #define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ #define EXT_CSD_PARTITION_SETTING_COMPLETED 155 /* R/W */ #define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ @@ -315,6 +316,7 @@ struct _mmc_csd { #define EXT_CSD_PWR_CL_26_360 203 /* RO */ #define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ #define EXT_CSD_S_A_TIMEOUT 217 /* RO */ +#define EXT_CSD_PSA_TIMEOUT 218 /* RO */ #define EXT_CSD_REL_WR_SEC_C 222 /* RO */ #define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */ #define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */ @@ -433,6 +435,12 @@ struct _mmc_csd { #define EXT_CSD_BKOPS_LEVEL_2 0x2 /* + * PRODUCTION STATE AWARENESS fields + */ +#define EXT_CSD_PSA_NORMAL 0x00 +#define EXT_CSD_PSA_POST_SOLDERING_WRITES 0x02 + +/* * MMC_SWITCH access modes */