UINT32 PresentState;\r
UINT8 HostCtrl2;\r
UINTN Retry;\r
+ BOOLEAN ForceVoltage33;\r
+\r
+ ForceVoltage33 = FALSE;\r
\r
PciIo = Private->PciIo;\r
PassThru = &Private->PassThru;\r
+\r
+Voltage33Retry:\r
//\r
// 1. Send Cmd0 to the device\r
//\r
return EFI_UNSUPPORTED;\r
}\r
\r
+ //\r
+ // 1.8V had failed in the previous run, forcing a retry with 3.3V instead\r
+ //\r
+ if (ForceVoltage33 == TRUE) {\r
+ S18r = FALSE;\r
+ }\r
+\r
//\r
// 5. Repeatly send Acmd41 with supply voltage window to the device.\r
// Note here we only support the cards complied with SD physical\r
\r
SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);\r
if (((PresentState >> 20) & 0xF) != 0xF) {\r
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));\r
- Status = EFI_DEVICE_ERROR;\r
- goto Error;\r
+ //\r
+ // Delay 50 milliseconds in order for clock to stabilize, retry reading the SD_MMC_HC_PRESENT_STATE\r
+ //\r
+ gBS->Stall (50000);\r
+ SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);\r
+ if (((PresentState >> 20) & 0xF) != 0xF) {\r
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));\r
+ //\r
+ // Reset and reinitialize the slot before the 3.3V retry.\r
+ //\r
+ Status = SdMmcHcReset (Private, Slot);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
+\r
+ Status = SdMmcHcInitHost (Private, Slot);\r
+ if (EFI_ERROR (Status)) {\r
+ goto Error;\r
+ }\r
+\r
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: Switching to 1.8V failed, forcing a retry with 3.3V instead\n"));\r
+ ForceVoltage33 = TRUE;\r
+ goto Voltage33Retry;\r
+ }\r
}\r
}\r
\r