public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Aiman Rosli" <muhammad.aiman.rosli@intel.com>
To: devel@edk2.groups.io
Cc: Aiman Rosli <muhammad.aiman.rosli@intel.com>
Subject: [PATCH v2] MdeModulePkg: Enabling OS boot from SD card through UEFI payload
Date: Mon, 17 Jan 2022 20:55:35 +0800	[thread overview]
Message-ID: <7fbe9337faa69eaacc20f225a5e97d163d97a4c9.1642423955.git.muhammad.aiman.rosli@intel.com> (raw)

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.

Signed-off-by: Aiman Rosli <muhammad.aiman.rosli@intel.com>
---
 MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c | 23 ++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c b/MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
index 662f9f483c..527fe7dc20 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
   //
@@ -1294,6 +1299,14 @@ SdCardIdentification (
     return EFI_UNSUPPORTED;
   }
 
+  //
+  // 1.8V had failed in the previous run, forcing a retry with 3.3V instead
+  //
+  if (ForceVoltage33 == TRUE) {
+    S18r           = FALSE;
+    ForceVoltage33 = FALSE;
+  }
+
   //
   // 5. Repeatly send Acmd41 with supply voltage window to the device.
   //    Note here we only support the cards complied with SD physical
@@ -1362,13 +1375,17 @@ SdCardIdentification (
         goto Error;
       }
 
-      gBS->Stall (1000);
+      // Workaround to add a delay of 50 ms in order for clock to stabilize before turning on the SD card again.
+      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));
-        Status = EFI_DEVICE_ERROR;
-        goto Error;
+        Status         = SdMmcHcReset (Private, Slot);
+        Status         = SdMmcHcInitHost (Private, Slot);
+        ForceVoltage33 = TRUE;
+        DEBUG ((DEBUG_ERROR, "SdCardIdentification: Switching to 1.8V had failed in the previous run, forcing a retry with 3.3V instead\n"));
+        goto Voltage33Retry;
       }
     }
 
-- 
2.34.1.windows.1


             reply	other threads:[~2022-01-17 12:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 12:55 Aiman Rosli [this message]
2022-01-18  1:05 ` [edk2-devel] [PATCH v2] MdeModulePkg: Enabling OS boot from SD card through UEFI payload Wu, Hao A

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7fbe9337faa69eaacc20f225a5e97d163d97a4c9.1642423955.git.muhammad.aiman.rosli@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox