From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30089.outbound.protection.outlook.com [40.107.3.89]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id AF20A21EB5277 for ; Wed, 30 Aug 2017 23:03:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=DDwn87/x/+WJqKA6UenpFAX+EmW9Kel19EyqMi+keVo=; b=mQekI3XcO7I+BG4b+/54EstMKCg2Za9G/FV18avsYZbN10L798gO1sD1MRmGHOjxp4oTMTA66KM6esOeE/h9tO9zbbdGEzupaLsG3mDBntL1d+/9L8rXI6Gto6gBfKTb2pImXu0qVFietZ7mB7T+YDUgJmB7j7yePfQ0+8k2DHQ= Received: from VI1PR04MB1005.eurprd04.prod.outlook.com (10.161.108.153) by VI1PR04MB2096.eurprd04.prod.outlook.com (10.166.43.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Thu, 31 Aug 2017 06:06:02 +0000 Received: from VI1PR04MB1005.eurprd04.prod.outlook.com ([fe80::10eb:b564:5131:ba2]) by VI1PR04MB1005.eurprd04.prod.outlook.com ([fe80::10eb:b564:5131:ba2%17]) with mapi id 15.20.0013.011; Thu, 31 Aug 2017 06:06:01 +0000 From: Meenakshi Aggarwal To: "edk2-devel@lists.01.org" CC: Meenakshi Aggarwal , Ard Biesheuvel , "leif.lindholm@linaro.org" Thread-Topic: [PATCH 2/2] SD : Updated CMD 6 implememtation. Thread-Index: AQHTIWqJ4QMoYdWOyU+fDBYrDUXGvKKd+vWg Date: Thu, 31 Aug 2017 06:06:01 +0000 Message-ID: References: <1504102859-13477-1-git-send-email-meenakshi.aggarwal@nxp.com> <1504102859-13477-2-git-send-email-meenakshi.aggarwal@nxp.com> In-Reply-To: <1504102859-13477-2-git-send-email-meenakshi.aggarwal@nxp.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=meenakshi.aggarwal@nxp.com; x-originating-ip: [192.88.169.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VI1PR04MB2096; 6:spWeE7c4Zl9ZTHhfhIn0eUSkOtjmmpREh56eqUzMM9dlIxl1cZ+x5A4U+PrL/15CX3UL/SXLVQd98U2mAS/OdnyUVn4M144V5PF8wtLkJh8gqmumxBh2Is5ObdwMG3BjunJ2cUKSGBIx5xZ2YMlJW5Os3Bqaj1avwpBtb4rO9rDXcz4Fv9gUwd71cQX8e9AGn510dCpDO6upQKvmONF7F6d6bss1Xm7x7dLTf8zGv7QOYoKKZQ7y00kHK0C1S32EA7qxDmiDROLbyElAFtugwjdW09lkuHR2XEKk5rIG0k1bIku1yg2dKW2A8Xf1ZN2v0euPzAAUAQ3wtU78l0YBBw==; 5:D+1c6qfJgsE8I9qSIB0c1bWx5LwvGq/j5fdcv7d3HgfvesutOAVjUCkwKypnaj8/SuNH4YRta47E3s2OIb1y5FJDKPipszTl14K0zsQ7jcbj75Mjbs1LE9YScE8ANY3TCgc0Hc9qz1ZU2i4ctzSbdQ==; 24:JJ+XujySB80xoNz2Vh5dYK5He0+8kORA73lvQVIsid3cLZ37K2QzVpHIi6fZteTcUCxBKjZq3+FMMCdWdHhiheeqmvod+XStjR5qjtB19Vc=; 7:gitEtxgD+pnJ3+/LutkW6QfLOwB0TKbrF873lMB2ShPiEab4OOlZ4xO8cytmh9K0TszPRYX9aafR1HfVrcP13bSyJlBT4HId6qGC227ZgTfuTZpAPMHaWRKI8Dnz7KCmRletsaQknQTdkcltvrGQ9a8NElTOWHTdIkMrt+Qq/B5BEY4IC+WKx8HUJ/E7dfoIT9WG+lSH56VSNJBG0PuBW92VJ2faQjd37pY34kQ+IBk= x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI; SCL:-1; SFV:NSPM; SFS:(10009020)(979002)(6009001)(39860400002)(189002)(377454003)(13464003)(199003)(2950100002)(3846002)(6916009)(110136004)(6116002)(102836003)(53936002)(55016002)(7736002)(305945005)(14454004)(5640700003)(66066001)(4326008)(229853002)(6436002)(6506006)(99286003)(9686003)(53546010)(6246003)(478600001)(54906002)(25786009)(189998001)(2900100001)(33656002)(15650500001)(3280700002)(3660700001)(74316002)(81166006)(7696004)(8676002)(5660300001)(8936002)(2906002)(81156014)(105586002)(106356001)(2351001)(97736004)(575784001)(68736007)(5250100002)(86362001)(101416001)(50986999)(54356999)(76176999)(2501003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:VI1PR04MB2096; H:VI1PR04MB1005.eurprd04.prod.outlook.com; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; x-ms-office365-filtering-correlation-id: 705853ad-e55c-4ff3-d331-08d4f0365b77 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254152)(48565401081)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:VI1PR04MB2096; x-ms-traffictypediagnostic: VI1PR04MB2096: x-exchange-antispam-report-test: UriScan:(185117386973197)(162533806227266); x-microsoft-antispam-prvs: x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6055026)(6041248)(20161123558100)(20161123564025)(20161123555025)(20161123562025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR04MB2096; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR04MB2096; x-forefront-prvs: 04163EF38A received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Aug 2017 06:06:01.8312 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB2096 Subject: Re: [PATCH 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: Thu, 31 Aug 2017 06:03:23 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi, Please review this patch. Thanks & Regards, Meenakshi -----Original Message----- From: Meenakshi Aggarwal [mailto:meenakshi.aggarwal@nxp.com]=20 Sent: Wednesday, August 30, 2017 7:51 PM To: edk2-devel@lists.01.org Cc: Meenakshi Aggarwal Subject: [PATCH 2/2] SD : Updated CMD 6 implememtation. For setting high speed in SD card, First CMD 6 (Switch) is send to check if card supports High Speed and Secon= d 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 s= pecification 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 support= s either 25000000 or 50000000. Signed-off-by: Meenakshi Aggarwal --- EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c | 64 ++++++++++++++++++++= ---- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c b/EmbeddedPkg= /Universal/MmcDxe/MmcIdentification.c index 7f74c54..3071b3b 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c @@ -317,6 +317,24 @@ InitializeEmmcDevice ( return Status; } =20 + +STATIC +UINT32 +CreateSwitchCmdArgument ( + IN UINT8 Mode, + IN UINT8 Group, + IN UINT8 Value + ) +{ + UINT32 Argument; + + Argument =3D Mode << 31 | 0x00FFFFFF; + Argument &=3D ~(0xF << (Group * 4)); + Argument |=3D Value << (Group * 4); + + return Argument; +} + STATIC EFI_STATUS InitializeSdMmcDevice ( @@ -326,6 +344,7 @@ InitializeSdMmcDevice ( UINT32 CmdArg; UINT32 Response[4]; UINT32 Buffer[128]; + UINT32 Speed; UINTN BlockSize; UINTN CardSize; UINTN NumBlocks; @@ -334,6 +353,7 @@ InitializeSdMmcDevice ( EFI_STATUS Status; EFI_MMC_HOST_PROTOCOL *MmcHost; =20 + Speed =3D 25000000; MmcHost =3D MmcHostInstance->MmcHost; =20 // Send a command to get Card specific data @@ -439,43 +459,69 @@ Initia= lizeSdMmcDevice ( } } if (CccSwitch) { + /* SD Switch, Mode:0, Group:0, Value:0 */ + CmdArg =3D CreateSwitchCmdArgument(0, 0, 0); + Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): Failed with Status =3D %r\n", __= func__, Status)); + return Status; + } else { + Status =3D MmcHost->ReadBlockData (MmcHost, 0, 64, Buffer); + if (EFI_ERROR (Status)) { + DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): ReadBlockData Failed with Stat= us =3D %r\n", __func__, Status)); + return Status; + } + } + + if (!(Buffer[3] & 0x20000)) { + DEBUG ((EFI_D_ERROR, "%aHigh Speed not supported by Card %r\n", __fu= nc__, Status)); + return Status; + } + + Speed =3D 50000000; //High Speed for SD card is 50 MHZ + /* SD Switch, Mode:1, Group:0, Value:1 */ - CmdArg =3D 1 << 31 | 0x00FFFFFF; - CmdArg &=3D ~(0xF << (0 * 4)); - CmdArg |=3D 1 << (0 * 4); + CmdArg =3D CreateSwitchCmdArgument(1, 0, 1); Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): Error and Status =3D %r\n", Stat= us)); + DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): Error and Status =3D %r\n",=20 + __func__, Status)); return Status; } else { Status =3D MmcHost->ReadBlockData (MmcHost, 0, 64, Buffer); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): ReadBlockData Error and Status= =3D %r\n", Status)); + DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): ReadBlockData Error and Status= =3D %r\n",__func__, Status)); + return Status; + } + + if ((Buffer[4] & 0x0f000000) !=3D 0x01000000) { + DEBUG((EFI_D_ERROR, "Problem switching SD card into high-speed=20 + mode\n")); return Status; } } } + if (Scr.SD_BUS_WIDTHS & SD_BUS_WIDTH_4BIT) { CmdArg =3D MmcHostInstance->CardInfo.RCA << 16; Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD55, CmdArg); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a(MMC_CMD55): Error and Status =3D %r\n", Sta= tus)); + DEBUG ((EFI_D_ERROR, "%a(MMC_CMD55): Error and Status =3D %r\n",=20 + __func__, Status)); return Status; } /* Width: 4 */ Status =3D MmcHost->SendCommand (MmcHost, MMC_CMD6, 2); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): Error and Status =3D %r\n", Stat= us)); + DEBUG ((EFI_D_ERROR, "%a(MMC_CMD6): Error and Status =3D %r\n",=20 + __func__, Status)); return Status; } } if (MMC_HOST_HAS_SETIOS(MmcHost)) { - Status =3D MmcHost->SetIos (MmcHost, 26 * 1000 * 1000, 4, EMMCBACKWARD= ); + Status =3D MmcHost->SetIos (MmcHost, Speed, 4, EMMCBACKWARD); if (EFI_ERROR (Status)) { - DEBUG ((EFI_D_ERROR, "%a(SetIos): Error and Status =3D %r\n", Status= )); + DEBUG ((EFI_D_ERROR, "%a(SetIos): Error and Status =3D %r\n",=20 + __func__, Status)); return Status; } } + return EFI_SUCCESS; } =20 -- 1.9.1