]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/SdMmcPciHcDxe: Robust improvements for SD card 1.8V switch
authorAiman Rosli <muhammad.aiman.rosli@intel.com>
Thu, 20 Jan 2022 18:53:24 +0000 (02:53 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 24 Jan 2022 01:52:35 +0000 (01:52 +0000)
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>
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c

index 662f9f483c67e19849cb80e6822b1f3da980aa07..f5a3607e47c0936e96db0ea68f323ec86869b134 100644 (file)
@@ -1213,9 +1213,14 @@ SdCardIdentification (
   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
@@ -1294,6 +1299,13 @@ SdCardIdentification (
     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
@@ -1366,9 +1378,30 @@ SdCardIdentification (
 \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