diff options
author | Aiman Rosli <muhammad.aiman.rosli@intel.com> | 2022-01-21 02:53:24 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2022-01-24 01:52:35 +0000 |
commit | 7e5c603cba0823fd97456984f4cfc21c4c831b52 (patch) | |
tree | 7b828b8fd9675b214558184f70a5f2ccecc008d5 /MdeModulePkg | |
parent | 21320ef66989f8af5a9e9b57df73d20a70bea85f (diff) | |
download | edk2-7e5c603cba0823fd97456984f4cfc21c4c831b52.tar.gz edk2-7e5c603cba0823fd97456984f4cfc21c4c831b52.tar.bz2 edk2-7e5c603cba0823fd97456984f4cfc21c4c831b52.zip |
MdeModulePkg/SdMmcPciHcDxe: Robust improvements for SD card 1.8V switch
This changes is by adding 50ms delay during voltage switching from 3.3V to
1.8V, plus adding a goto Voltage33Retry for 3.3V checking and retrying.
Change is for Enabling OS boot from SD card through UEFI payload.
Signed-off-by: Aiman Rosli <muhammad.aiman.rosli@intel.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
Diffstat (limited to 'MdeModulePkg')
-rw-r--r-- | MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c index 662f9f483c..f5a3607e47 100644 --- a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c +++ b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c @@ -1213,9 +1213,14 @@ SdCardIdentification ( UINT32 PresentState;
UINT8 HostCtrl2;
UINTN Retry;
+ BOOLEAN ForceVoltage33;
+
+ ForceVoltage33 = FALSE;
PciIo = Private->PciIo;
PassThru = &Private->PassThru;
+
+Voltage33Retry:
//
// 1. Send Cmd0 to the device
//
@@ -1295,6 +1300,13 @@ SdCardIdentification ( }
//
+ // 1.8V had failed in the previous run, forcing a retry with 3.3V instead
+ //
+ if (ForceVoltage33 == TRUE) {
+ S18r = FALSE;
+ }
+
+ //
// 5. Repeatly send Acmd41 with supply voltage window to the device.
// Note here we only support the cards complied with SD physical
// layer simplified spec version 2.0 and version 3.0 and above.
@@ -1366,9 +1378,30 @@ SdCardIdentification ( SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
if (((PresentState >> 20) & 0xF) != 0xF) {
- DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
- Status = EFI_DEVICE_ERROR;
- goto Error;
+ //
+ // Delay 50 milliseconds in order for clock to stabilize, retry reading the SD_MMC_HC_PRESENT_STATE
+ //
+ gBS->Stall (50000);
+ SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
+ if (((PresentState >> 20) & 0xF) != 0xF) {
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
+ //
+ // Reset and reinitialize the slot before the 3.3V retry.
+ //
+ Status = SdMmcHcReset (Private, Slot);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ Status = SdMmcHcInitHost (Private, Slot);
+ if (EFI_ERROR (Status)) {
+ goto Error;
+ }
+
+ DEBUG ((DEBUG_ERROR, "SdCardIdentification: Switching to 1.8V failed, forcing a retry with 3.3V instead\n"));
+ ForceVoltage33 = TRUE;
+ goto Voltage33Retry;
+ }
}
}
|