EmbeddedPkg/MmcDxe: Wait for the MMC controller to be in Transfer Mode
authoroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 3 Jun 2011 09:09:18 +0000 (09:09 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 3 Jun 2011 09:09:18 +0000 (09:09 +0000)
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/Mmc.h
EmbeddedPkg/Universal/MmcDxe/MmcBlockIo.c

index 44ad585..542355f 100644 (file)
@@ -41,6 +41,8 @@
 #define MMC_CSD_GET_DEVICESIZE(csd)         (((Response[2] >> 30) & 0x3) | ((Response[1] & 0x3FF) << 2))\r
 #define MMC_CSD_GET_DEVICESIZEMULT(csd)     ((Response[2] >> 15) & 0x7)\r
 \r
+#define MMC_R0_READY_FOR_DATA               (1 << 8)\r
+\r
 #define MMC_R0_CURRENTSTATE(Response)       ((Response[0] >> 9) & 0xF)\r
 \r
 #define MMC_R0_STATE_IDLE       0\r
index f7cdb6d..a77c8f0 100644 (file)
@@ -476,13 +476,18 @@ EFI_STATUS MmcIoBlocks (
                CmdArg = MmcHostInstance->CardInfo.RCA << 16;\r
                Response[0] = 0;\r
                Timeout = 20;\r
-       while((Response[0] & (1 << 8)) && Timeout-- ){\r
+       while(!(Response[0] & MMC_R0_READY_FOR_DATA) && (MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout--) {\r
                Status = MmcHost->SendCommand(MMC_CMD13, CmdArg);\r
                if (!EFI_ERROR(Status)){\r
                        MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response);\r
                }\r
        }\r
 \r
+       if (0 == Timeout) {\r
+               DEBUG((EFI_D_ERROR, "The Card is busy\n"));\r
+               return EFI_NOT_READY;\r
+    }\r
+\r
         // Set Block Length\r
         Status = MmcHost->SendCommand(MMC_CMD16, This->Media->BlockSize);\r
         if (EFI_ERROR(Status)) {\r
@@ -554,14 +559,19 @@ EFI_STATUS MmcIoBlocks (
 \r
         // Command 12 - Stop transmission (ends read)\r
         Status = MmcHost->SendCommand(MMC_CMD12, 0);\r
-        MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1b,Response);\r
+       if (!EFI_ERROR(Status)) {\r
+               MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1b,Response);\r
+       }\r
 \r
         // Command 13 - Read status and wait for programming to complete (return to tran)\r
         Timeout = MMCI0_TIMEOUT;\r
         CmdArg = MmcHostInstance->CardInfo.RCA << 16;\r
-        while ((MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout) {\r
-            MmcHost->SendCommand(MMC_CMD13, CmdArg);\r
-            MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response);\r
+       Response[0] = 0;\r
+       while(!(Response[0] & MMC_R0_READY_FOR_DATA) && (MMC_R0_CURRENTSTATE(Response) != MMC_R0_STATE_TRAN) && Timeout--) {\r
+               Status = MmcHost->SendCommand(MMC_CMD13, CmdArg);\r
+               if (!EFI_ERROR(Status)) {\r
+               MmcHost->ReceiveResponse(MMC_RESPONSE_TYPE_R1,Response);\r
+               }\r
             NanoSecondDelay(100);\r
             Timeout--;\r
         }\r