/** @file\r
*\r
-* Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
+* Copyright (c) 2011-2015, ARM Limited. All rights reserved.\r
*\r
* This program and the accompanying materials\r
* are licensed and made available under the terms and conditions of the BSD License\r
*\r
**/\r
\r
-#include <Library/TimerLib.h>\r
-\r
#include "Mmc.h"\r
\r
typedef union {\r
EFI_BLOCK_IO_MEDIA *Media;\r
EFI_STATUS Status;\r
UINT32 RCA;\r
- UINT32 ECSD[128];\r
\r
Host = MmcHostInstance->MmcHost;\r
Media = MmcHostInstance->BlockIo.Media;\r
DEBUG ((EFI_D_ERROR, "EmmcIdentificationMode(): ECSD fetch error, Status=%r.\n", Status));\r
}\r
\r
- Status = Host->ReadBlockData (Host, 0, 512, ECSD);\r
+ Status = Host->ReadBlockData (Host, 0, 512, (UINT32 *)&(MmcHostInstance->CardInfo.ECSD));\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "EmmcIdentificationMode(): ECSD read error, Status=%r.\n", Status));\r
return Status;\r
Media->LogicalBlocksPerPhysicalBlock = 1;\r
Media->IoAlign = 4;\r
// Compute last block using bits [215:212] of the ECSD\r
- Media->LastBlock = ECSD[EMMC_ECSD_SIZE_OFFSET] - 1; // eMMC isn't supposed to report this for\r
+ Media->LastBlock = MmcHostInstance->CardInfo.ECSD[EMMC_ECSD_SIZE_OFFSET] - 1; // eMMC isn't supposed to report this for\r
// Cards <2GB in size, but the model does.\r
\r
// Setup card type\r
\r
// Send CMD1 to get OCR (MMC)\r
// This command only valid for MMC and eMMC\r
- Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, EMMC_CMD1_CAPACITY_GREATER_THAN_2GB);\r
- if (Status == EFI_SUCCESS) {\r
+ Timeout = MAX_RETRY_COUNT;\r
+ do {\r
+ Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, EMMC_CMD1_CAPACITY_GREATER_THAN_2GB);\r
+ if (EFI_ERROR (Status))\r
+ break;\r
Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, (UINT32 *)&OcrResponse);\r
if (EFI_ERROR (Status)) {\r
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));\r
return Status;\r
}\r
-\r
+ Timeout--;\r
+ } while (!OcrResponse.Ocr.PowerUp && (Timeout > 0));\r
+ if (Status == EFI_SUCCESS) {\r
if (!OcrResponse.Ocr.PowerUp) {\r
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD1): Card initialisation failure, Status=%r.\n", Status));\r
return EFI_DEVICE_ERROR;\r
\r
if (!EFI_ERROR (Status)) {\r
if (!MmcHostInstance->CardInfo.OCRData.PowerUp) {\r
- MicroSecondDelay (1);\r
+ gBS->Stall (1);\r
Timeout--;\r
} else {\r
if ((MmcHostInstance->CardInfo.CardType == SD_CARD_2) && (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1)) {\r
break; // The MMC/SD card is ready. Continue the Identification Mode\r
}\r
} else {\r
- MicroSecondDelay (1);\r
+ gBS->Stall (1);\r
Timeout--;\r
}\r
}\r