From b9d5fe03e660b6b3c423d9ceefd10864cbfcdc6c Mon Sep 17 00:00:00 2001 From: oliviermartin Date: Fri, 3 Jun 2011 09:09:18 +0000 Subject: EmbeddedPkg/MmcDxe: Wait for the MMC controller to be in Transfer Mode The MMC controller might be ready for data but not be in a 'ready' state to send or receive commands. This fix waits for the MMC controller to be in the correct state. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11726 6f19259b-4bc3-4df7-8a09-765794883524 --- EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c') diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c index f7cdb6d6d9..a77c8f088b 100644 --- a/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c +++ b/EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c @@ -476,13 +476,18 @@ EFI_STATUS MmcIoBlocks ( CmdArg = MmcHostInstance->CardInfo.RCA << 16; Response[0] = 0; Timeout = 20; - while((Response[0] & (1 << 8)) && Timeout-- ){ + while(!(Response[0] & MMC_R0_READY_FOR_DATA) && (MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout--) { Status = MmcHost->SendCommand(MMC_CMD13, CmdArg); if (!EFI_ERROR(Status)){ MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response); } } + if (0 == Timeout) { + DEBUG((EFI_D_ERROR, "The Card is busy\n")); + return EFI_NOT_READY; + } + // Set Block Length Status = MmcHost->SendCommand(MMC_CMD16, This->Media->BlockSize); if (EFI_ERROR(Status)) { @@ -554,14 +559,19 @@ EFI_STATUS MmcIoBlocks ( // Command 12 - Stop transmission (ends read) Status = MmcHost->SendCommand(MMC_CMD12, 0); - MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1b,Response); + if (!EFI_ERROR(Status)) { + MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1b,Response); + } // Command 13 - Read status and wait for programming to complete (return to tran) Timeout = MMCI0_TIMEOUT; CmdArg = MmcHostInstance->CardInfo.RCA << 16; - while ((MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout) { - MmcHost->SendCommand(MMC_CMD13, CmdArg); - MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response); + Response[0] = 0; + while(!(Response[0] & MMC_R0_READY_FOR_DATA) && (MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout--) { + Status = MmcHost->SendCommand(MMC_CMD13, CmdArg); + if (!EFI_ERROR(Status)) { + MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response); + } NanoSecondDelay(100); Timeout--; } -- cgit v1.2.3