From patchwork Tue Nov 25 15:01:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Lemberg X-Patchwork-Id: 5380131 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7F7E1C11AC for ; Tue, 25 Nov 2014 15:01:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7A02F20145 for ; Tue, 25 Nov 2014 15:01:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 418E120117 for ; Tue, 25 Nov 2014 15:01:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750877AbaKYPBu (ORCPT ); Tue, 25 Nov 2014 10:01:50 -0500 Received: from mail-bn1on0088.outbound.protection.outlook.com ([157.56.110.88]:27296 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1750875AbaKYPBt (ORCPT ); Tue, 25 Nov 2014 10:01:49 -0500 Received: from BY1PR0201CA0033.namprd02.prod.outlook.com (25.160.191.171) by BN1PR02MB120.namprd02.prod.outlook.com (10.255.204.26) with Microsoft SMTP Server (TLS) id 15.1.26.15; Tue, 25 Nov 2014 15:01:44 +0000 Received: from BY2FFO11FD011.protection.gbl (2a01:111:f400:7c0c::196) by BY1PR0201CA0033.outlook.office365.com (2a01:111:e400:4814::43) with Microsoft SMTP Server (TLS) id 15.1.26.15 via Frontend Transport; Tue, 25 Nov 2014 15:01:43 +0000 Received: from milsmgep11.sandisk.com (63.163.107.172) by BY2FFO11FD011.mail.protection.outlook.com (10.1.14.129) with Microsoft SMTP Server id 15.1.6.13 via Frontend Transport; Tue, 25 Nov 2014 15:01:43 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep11.sandisk.com (Symantec Messaging Gateway) with SMTP id 7D.DC.06562.6D994745; Tue, 25 Nov 2014 07:01:42 -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; Tue, 25 Nov 2014 07:01:42 -0800 X-AuditID: ac160a68-f79d16d0000019a2-a2-547499d60353 Received: from E6410-C110490.sdcorp.global.sandisk.com ( [10.177.8.100]) by milsmgip11.sandisk.com (Symantec Messaging Gateway) with SMTP id 10.05.10458.5D994745; Tue, 25 Nov 2014 07:01:42 -0800 (PST) From: Alex Lemberg To: CC: , , , Alex Lemberg Subject: [PATCH v2] mmc: Add Production State Awareness Support Date: Tue, 25 Nov 2014 17:01:38 +0200 Message-ID: <1416927698-5304-1-git-send-email-alex.lemberg@sandisk.com> X-Mailer: git-send-email 2.1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrLLMWRmVeSWpSXmKPExsWyRoxnke61mSUhBr8e2lhMuLyd0eLI/35G i+Nrwx2YPe5c28PmcePVQiaPz5vkApijuGxSUnMyy1KL9O0SuDL+LOAv6FCpeDD5BVsD4yrZ LkZODgkBE4kDJ54yQdhiEhfurWfrYuTiEBI4wSjRcmMSK4Szg1Fi34pGJpiOT0tuMkMkzjBK XH7wkxEkwSagK/Hiw1Mgm4NDREBGovGAMUiYWaBO4tjDn+wgtrCAvcTKw7PAylkEVCWW3rjD AmLzCrhLbFu0hh1ivpzEht3/GUHmSwi8ZpHoevuMDaJIUOLkzCcsEEMlJA6+eMEMsksIaNDZ t3UTGAVnIamahaRqASPTKkax3Myc4tz01AJDQ73ixLyUzOJsveT83E2M4EDlytjBuHWS+SFG AQ5GJR7ehmPFIUKsiWXFlbmHGCU4mJVEeIN6S0KEeFMSK6tSi/Lji0pzUosPMUpzsCiJ89rP y/IXEkhPLEnNTk0tSC2CyTJxcEo1MBr7nBF5P+Xbj8OaS3eLTf+jrXg2qu9SSKLT+r7ncqws P6V5Hy3mtuGIXM/lrMh1+YSwmuMLo8dR59K8un9eVD/zxetpnl/jqiRxqY7jTo6nVdfEPvv0 f85eJVaNhHdHLoTfvzyHsc5O5l/b5cecptkykQdLss+brGKWP3381ZYZii8U/pnI31BiKc5I NNRiLipOBACA7K6aUAIAAA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprEJMWRmVeSWpSXmKPExsXCtZEjRffazJIQgxun9SxuPvjBZrFz7zom iwmXtzNaHPnfz2hxfG24A6vHnWt72DxuvFrI5DFtzXkmj8+b5AJYorhsUlJzMstSi/TtErgy /izgL+hQqXgw+QVbA+Mq2S5GTg4JAROJT0tuMkPYYhIX7q1n62Lk4hASOMUosfJPD1iCTUBX 4sWHp4wgtoiAlETP02agOAcHs0CNxJWbmSBhYQF7iZWHZ4GVsAioSiy9cYcFxOYVcJe4uOY4 1Hw5iQ27/zNOYORawMiwilEsNzOnODc9s8DQUK84MS8lszhbLzk/dxMj2NeckTsYn040P8TI xMEp1cC4YOOb2QGOp5cpnvnfPn2FtuDPH99zpGawTdRVeMV2ze4Ed9mu7fIfFNovJEurarfM +Dk5OyjxykyLGH0Ztz0Tlx/bMeG2e8qHiSYex83PSTAaTJ6ak/twQiT7rsrlipeaUvuyJgYv eyS2vXzXZOb/zluvNxd7Bf7b2V/yMjPT8rVXyBUJ1T9KSizFGYmGWsxFxYkAzwIX8KUBAAA= MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:63.163.107.172; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(189002)(199003)(120916001)(99396003)(104166001)(102836001)(31966008)(50986999)(89996001)(77156002)(62966003)(64706001)(48376002)(47776003)(15202345003)(20776003)(21056001)(36756003)(92566001)(19580395003)(92726001)(69596002)(68736004)(86362001)(93916002)(50466002)(44976005)(19580405001)(229853001)(107046002)(2351001)(110136001)(33646002)(97736003)(46102003)(87286001)(4396001)(50226001)(87936001)(15975445006)(84676001)(88136002)(95666004)(106466001)(81156004); DIR:OUT; SFP:1101; SCL:1; SRVR:BN1PR02MB120; H:milsmgep11.sandisk.com; FPR:; SPF:Pass; MLV:sfv; PTR:ErrorRetry; MX:1; A:1; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BN1PR02MB120; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BN1PR02MB120; X-Forefront-PRVS: 040655413E Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.172 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.172; helo=milsmgep11.sandisk.com; Authentication-Results: spf=pass (sender IP is 63.163.107.172) smtp.mailfrom=Alex.Lemberg@sandisk.com; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:BN1PR02MB120; 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 --- Changes in v2: - Remove typo in patch code --- drivers/mmc/core/mmc.c | 28 ++++++++++++++++++++++++++++ include/linux/mmc/card.h | 2 ++ include/linux/mmc/mmc.h | 8 ++++++++ 3 files changed, 38 insertions(+) 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)); + } } 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 */