From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0081.outbound.protection.outlook.com [104.47.40.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B75C021DF8080 for ; Tue, 5 Sep 2017 22:03:51 -0700 (PDT) Received: from MWHPR03CA0050.namprd03.prod.outlook.com (10.174.173.167) by DM5PR03MB3321.namprd03.prod.outlook.com (10.174.241.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Wed, 6 Sep 2017 05:06:40 +0000 Received: from BL2FFO11FD037.protection.gbl (2a01:111:f400:7c09::176) by MWHPR03CA0050.outlook.office365.com (2603:10b6:301:3b::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10 via Frontend Transport; Wed, 6 Sep 2017 05:06:40 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none;nxp.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD037.mail.protection.outlook.com (10.173.161.133) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1385.11 via Frontend Transport; Wed, 6 Sep 2017 05:06:39 +0000 Received: from uefi-OptiPlex-790.ap.freescale.net (uefi-OptiPlex-790.ap.freescale.net [10.232.132.78]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id v8656WD4009321; Tue, 5 Sep 2017 22:06:37 -0700 From: Meenakshi Aggarwal To: CC: , , , Meenakshi Aggarwal Date: Wed, 6 Sep 2017 16:25:10 +0530 Message-ID: <1504695310-25426-2-git-send-email-meenakshi.aggarwal@nxp.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504695310-25426-1-git-send-email-meenakshi.aggarwal@nxp.com> References: <1504695310-25426-1-git-send-email-meenakshi.aggarwal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131491479995248540; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39860400002)(39380400002)(2980300002)(1109001)(1110001)(339900001)(189002)(199003)(53936002)(189998001)(50226002)(81156014)(81166006)(5660300001)(85426001)(356003)(305945005)(626005)(2906002)(8936002)(48376002)(104016004)(86362001)(575784001)(97736004)(68736007)(8676002)(54906002)(110136004)(498600001)(8656003)(36756003)(5003940100001)(76176999)(4326008)(50986999)(33646002)(47776003)(105606002)(77096006)(2950100002)(6666003)(6916009)(106466001)(50466002)(2351001); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB3321; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD037; 1:J1zuo8PV3Rzav+VIX1QqKlYIlEKtQVhtAkczy0Lq+0QLu7TzyDZWGUsUJXc+IluT7WvKoj/ald+hWMcEGMNw1RtJzgAL+zZjX9nX5mP7W86ezlSgHpv+TmuHbYgtZzar MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fe3316a3-ba5d-4cb9-0e3b-08d4f4e50e90 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(2017052603199)(201703131430075)(201703131517081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:DM5PR03MB3321; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB3321; 3:ALOZ+u7+GCTHWHwaTsTrI5ledkngFc0pHroj9ceDateolEFEQc6zh5NtF3NFPMifqyXuuTyDDKCBkCx6YOqDUUgaB0o+PCUvfZ9F/8rxklMHi6VGbztqkPngkj1ZWTDpAE9byncWc5SqUKq+iox6LFPtLs3+vBipuX1RjswMvJ1/z3tFi3e8alv/yEzXchGfXHe+H03urakaCOYpDCO80f6I79j3KdFfnYMmlJobgsMSE0j4ylpp8bh8yPC3IRX0t66ImLf7FNbM1S83ft76cWyA8hZ8tk5/S2PN4vBHVpZT8yWm1al0WvYrmC6/KijsGKh+BNia/gGLo0as0q9Vi3SeTg7P6yvWXxYm3yQuE5U=; 25:t104LDrOX+4szArutox7YAiy8HtDR0ZC9Xr8cKU3X2p5UMKRYds3x4hdqFugZ08XufnuuRlS3QAu+WGrYD3BjPEeGuT5lbQSmXPGCAOhJgvWbVDo79Q/ZpYodA6G0nhpF3ZCmU5XYROy1X11/kzNAviEekcxG6SsF+HFQLp45+8RqnZcWhMUDGaIl1yIH/NXeLlanZahSBKoQesjBasNDSOaMLFMjweLrOvVvIjLhDP3l5wF6V+JhvdepxkF5mZlsy/E20m80QsLJ5R9PbOnQn32g//4rhdmTw85pUsG8FnAwzr9mnRGobd6SPwpbVKYsBaE552z0C8Dpo/KHLw00w== X-MS-TrafficTypeDiagnostic: DM5PR03MB3321: X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB3321; 31:3waxfep7tkvGScZEnmVu9aWPLkbWGSz3AS5SHtVGYrv/OS2Lq6mWNS38ithav3UxdpYAjUyiNe4YFAjk5Rbga30PZsu+qJqJn+2jCw7Ym+fwd/i5dcY9jN4tqk8iEFCbLQ6DbBQceoAO6Xfl3sMZJwq+qebPYr2TtHqhJV7J9KdnE30hXtMd4d6SZ1ksOP9CThCQ6PrhUNg0YgrVU0MfqOyXcboEyLM858RNmpHMrJU=; 4:SrANJHFBaOp4LetTs/ltB3oB3gE7Pcvy3bYweHd5HPTWJi9w4/Vd6bCRaf7WeO0Vq7XzhdK3mvHMiTQJkwVPw8M9bDB+HO9hWgjqTSSpgqxMBRIWyxnlz1a0xWq3dV9VbD51w39FkqfFKV2rtqsefsIRaXlJWuxFs7jqRw2svdsyz+AM8oKqAnYTJg8c8gXS3/V2ohuVCp9nzKCYMaA1af7hp8p1OYfcEB7EaYWj0smEHHajmPO71JVp2PSGHXRtSCUG9DuHckzJ4yGsVLW8I/8iICCOUHGA4wyACJ9Hofg= X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6095135)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6055026)(6096035)(20161123559100)(20161123565025)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123561025)(20161123556025)(20161123563025)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:DM5PR03MB3321; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(400006)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:DM5PR03MB3321; X-Forefront-PRVS: 0422860ED4 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB3321; 23:ZXLadmMfRGl9ihIEacEQWxC0odE5hkvBL3JD003Bz?= =?us-ascii?Q?aQM2RdHJm8Ym6e+gPIZQqv5C/cRC76c1y2vzUefpV+KREiPhQPl9NhdM7pGF?= =?us-ascii?Q?X1Kk1UWwxjJd562xBCZ2F4gDdot2qEoruBljrUDHP9F+tUTj4voRwScNCuqc?= =?us-ascii?Q?zACM8uHbW6qyBboA78dwEktGn7YzBRuxeWnOw53E6K50sfRmhY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ZbXi3QZpq2v8ocEdX77kb7LvERhRX6ly681aOajYxHE9PZJ2q?= =?us-ascii?Q?T1ohp+FIxg2c06kdyosGmnUY5s7ZPOavbXE1lspZaHIDhx250LsBQ=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB3321; 6:KBr4BD8ySYqo+8XwP88HBW89YTAdc9CXgewN1tV4HifBc8hLlDPzDvOjwldkYQ98jOWNVubNABjJFey6im9UZm5YU+qXWmxa34fs1WJTfo2qV7sXaSAXn02ieVIGrmkcHGjLxXBRLi/EovCeYEITnGSK2Qw7kUB43z7/g+Jw9V8Es3KAWJy6mPiLy6CZ44a8MGg8IdtyEscM6YH6LpE8QQMgyH+nVlF1tie5uOJNVYqCPCQnBqNCvXNIaorTJA4ZKSvRDECXZ0APBcAmMxIdMZ2ua4u9D/R9UgHOdOiyR739rbfPwrjCI4jUB7gQ95o7B1Vvw7th3xjagaWZz17PdA==; 5:HcBAV7nOgMzP4ZU0Lwhhd/hv+AfHFyf59/gxEeqtjT5tE77tLFPIVX7lICnMptwN+KRqOtef3AZUEWy3ENtF+YqDtEzACXRHPA0jnorWMBLPOaqzpzwEYH8hXC54q2qOaNkL1h5fVohYSQJ1yfhQVQ==; 24:W3nIz9pCjccD5Z9wt9lWB+pEUFTG1g+7fMc306TvyYu76HBZCp2E8qLOjM6enmX60r0hVvgR4DX2E5aEBaYu6lhupnlMekiotHoGcStOPIg=; 7:HzTEPtnNaCj2dFShBPXKhYjebK825sm6Ll4EyPES/7UohtTPqhemQjzrzQ6fiegAoHEqZnp9XKrlPt8AaahrUcp2IZ6uXoZ/PPUtTml7rsfJyBlJH4CKqzvnrkr9AuCaBzkS4No8RF6BfF5Va54oqrhRC/N+QkS6yb433ZjX3PC2h7zWGeubhQrFkVhTxByEVePAQ7LDkkchnwy/mSh5IlwwcVAi1vUwGwH+qoe/lfw= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2017 05:06:39.3376 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB3321 Subject: [PATCH v2 2/2] SD : Updated CMD 6 implememtation. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Sep 2017 05:03:52 -0000 Content-Type: text/plain For setting high speed in SD card, First CMD 6 (Switch) is send to check if card supports High Speed and Second command is send to switch card to high speed mode. In current inplementation, CMD 6 was sent only once to switch the card into HS mode without checking if card supports HS or not, which is not as per specification and also we are not setting the HS i.e. 50000000 but directly asking the card to switch to 26000000 which is incorrect as SD card supports either 25000000 or 50000000. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Meenakshi Aggarwal --- EmbeddedPkg/Universal/MmcDxe/Mmc.h | 8 ++++ EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c | 55 +++++++++++++++++++++--- 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.h b/EmbeddedPkg/Universal/MmcDxe/Mmc.h index f3e56ff..a77ba41 100644 --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.h +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.h @@ -64,6 +64,14 @@ #define EMMC_CMD6_ARG_VALUE(x) (((x) & 0xFF) << 8) #define EMMC_CMD6_ARG_CMD_SET(x) (((x) & 0x7) << 0) +#define SWITCH_CMD_DATA_LENGTH 64 +#define SD_HIGH_SPEED_SUPPORTED 0x20000 +#define SD_DEFAULT_SPEED 25000000 +#define SD_HIGH_SPEED 50000000 +#define SWITCH_CMD_SUCCESS_MASK 0x0f000000 + +#define BUSWIDTH_4 4 + typedef enum { UNKNOWN_CARD, MMC_CARD, //MMC card diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c index 8010dea..e60d8b0 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c @@ -318,6 +318,23 @@ InitializeEmmcDevice ( } STATIC +UINT32 +CreateSwitchCmdArgument ( + IN UINT32 Mode, + IN UINT8 Group, + IN UINT8 Value + ) +{ + UINT32 Argument; + + Argument = Mode << 31 | 0x00FFFFFF; + Argument &= ~(0xF << (Group * 4)); + Argument |= Value << (Group * 4); + + return Argument; +} + +STATIC EFI_STATUS InitializeSdMmcDevice ( IN MMC_HOST_INSTANCE *MmcHostInstance @@ -326,6 +343,7 @@ InitializeSdMmcDevice ( UINT32 CmdArg; UINT32 Response[4]; UINT32 Buffer[128]; + UINT32 Speed; UINTN BlockSize; UINTN CardSize; UINTN NumBlocks; @@ -334,6 +352,7 @@ InitializeSdMmcDevice ( EFI_STATUS Status; EFI_MMC_HOST_PROTOCOL *MmcHost; + Speed = SD_DEFAULT_SPEED; MmcHost = MmcHostInstance->MmcHost; // Send a command to get Card specific data @@ -439,21 +458,45 @@ InitializeSdMmcDevice ( } } if (CccSwitch) { - /* SD Switch, Mode:1, Group:0, Value:1 */ - CmdArg = 1 << 31 | 0x00FFFFFF; - CmdArg &= ~(0xF << (0 * 4)); - CmdArg |= 1 << (0 * 4); + /* SD Switch, Mode:0, Group:0, Value:0 */ + CmdArg = CreateSwitchCmdArgument(0, 0, 0); Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): Error and Status = %r\n", __FUNCTION__, Status)); return Status; } else { - Status = MmcHost->ReadBlockData (MmcHost, 0, 64, Buffer); + Status = MmcHost->ReadBlockData (MmcHost, 0, SWITCH_CMD_DATA_LENGTH, Buffer); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): ReadBlockData Error and Status = %r\n", __FUNCTION__, Status)); return Status; } } + + if (!(Buffer[3] & SD_HIGH_SPEED_SUPPORTED)) { + DEBUG ((EFI_D_ERROR, "%a : High Speed not supported by Card %r\n", __FUNCTION__, Status)); + return Status; + } + + Speed = SD_HIGH_SPEED; + + /* SD Switch, Mode:1, Group:0, Value:1 */ + CmdArg = CreateSwitchCmdArgument(1, 0, 1); + Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): Error and Status = %r\n", __FUNCTION__, Status)); + return Status; + } else { + Status = MmcHost->ReadBlockData (MmcHost, 0, SWITCH_CMD_DATA_LENGTH, Buffer); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): ReadBlockData Error and Status = %r\n",__FUNCTION__, Status)); + return Status; + } + + if ((Buffer[4] & SWITCH_CMD_SUCCESS_MASK) != 0x01000000) { + DEBUG((EFI_D_ERROR, "Problem switching SD card into high-speed mode\n")); + return Status; + } + } } if (Scr.SD_BUS_WIDTHS & SD_BUS_WIDTH_4BIT) { CmdArg = MmcHostInstance->CardInfo.RCA << 16; @@ -470,7 +513,7 @@ InitializeSdMmcDevice ( } } if (MMC_HOST_HAS_SETIOS(MmcHost)) { - Status = MmcHost->SetIos (MmcHost, 26 * 1000 * 1000, 4, EMMCBACKWARD); + Status = MmcHost->SetIos (MmcHost, Speed, BUSWIDTH_4, EMMCBACKWARD); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "%a (SetIos): Error and Status = %r\n", __FUNCTION__, Status)); return Status; -- 1.9.1