]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg: SdMmcPciHcDxe: Fix issue that SD1.0 cards can't be recognized
authorChevron Li (WH) <chevron.li@bayhubtech.com>
Wed, 7 Dec 2022 11:08:39 +0000 (19:08 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 12 Dec 2022 02:43:33 +0000 (02:43 +0000)
SD1.0 cards don't support CMD8 and CMD6
CMD8 result can be used to distinguish the card is SD1.0 or not.
CMD8 result can be used to decide following CMD6 is sent or skip.

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Signed-off-by: Chevron Li <chevron.li@bayhubtech.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c

index f5a3607e47c0936e96db0ea68f323ec86869b134..8bf452e9d01efe30dd9a78de3a49719f6d57bc57 100644 (file)
@@ -1074,6 +1074,7 @@ SdGetTargetBusMode (
   @param[in] Slot           The slot number of the SD card to send the command to.\r
   @param[in] Rca            The relative device address to be assigned.\r
   @param[in] S18A           The boolean to show if it's a UHS-I SD card.\r
+  @param[in] SdVersion1     The boolean to show if it's a Version 1 SD card.\r
 \r
   @retval EFI_SUCCESS       The operation is done correctly.\r
   @retval Others            The operation fails.\r
@@ -1085,7 +1086,8 @@ SdCardSetBusMode (
   IN EFI_SD_MMC_PASS_THRU_PROTOCOL  *PassThru,\r
   IN UINT8                          Slot,\r
   IN UINT16                         Rca,\r
-  IN BOOLEAN                        S18A\r
+  IN BOOLEAN                        S18A,\r
+  IN BOOLEAN                        SdVersion1\r
   )\r
 {\r
   EFI_STATUS              Status;\r
@@ -1095,6 +1097,8 @@ SdCardSetBusMode (
   SD_MMC_HC_PRIVATE_DATA  *Private;\r
   SD_MMC_BUS_SETTINGS     BusMode;\r
 \r
+  ZeroMem (SwitchResp, 64 * sizeof (UINT8));\r
+\r
   Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);\r
 \r
   Capability = &Private->Capability[Slot];\r
@@ -1117,10 +1121,13 @@ SdCardSetBusMode (
 \r
   //\r
   // Get the supported bus speed from SWITCH cmd return data group #1.\r
+  // SdVersion1 don't support the SWITCH cmd\r
   //\r
-  Status = SdCardSwitch (PassThru, Slot, 0xFF, 0xF, SdDriverStrengthIgnore, 0xF, FALSE, SwitchResp);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  if (!SdVersion1) {\r
+    Status = SdCardSwitch (PassThru, Slot, 0xFF, 0xF, SdDriverStrengthIgnore, 0xF, FALSE, SwitchResp);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
   }\r
 \r
   SdGetTargetBusMode (Private, Slot, SwitchResp, S18A, &BusMode);\r
@@ -1141,9 +1148,14 @@ SdCardSetBusMode (
     }\r
   }\r
 \r
-  Status = SdCardSwitch (PassThru, Slot, BusMode.BusTiming, 0xF, BusMode.DriverStrength.Sd, 0xF, TRUE, SwitchResp);\r
-  if (EFI_ERROR (Status)) {\r
-    return Status;\r
+  //\r
+  // SdVersion1 don't support the SWITCH cmd\r
+  //\r
+  if (!SdVersion1) {\r
+    Status = SdCardSwitch (PassThru, Slot, BusMode.BusTiming, 0xF, BusMode.DriverStrength.Sd, 0xF, TRUE, SwitchResp);\r
+    if (EFI_ERROR (Status)) {\r
+      return Status;\r
+    }\r
   }\r
 \r
   Status = SdMmcSetDriverStrength (Private->PciIo, Slot, BusMode.DriverStrength.Sd);\r
@@ -1214,8 +1226,10 @@ SdCardIdentification (
   UINT8                          HostCtrl2;\r
   UINTN                          Retry;\r
   BOOLEAN                        ForceVoltage33;\r
+  BOOLEAN                        SdVersion1;\r
 \r
   ForceVoltage33 = FALSE;\r
+  SdVersion1     = FALSE;\r
 \r
   PciIo    = Private->PciIo;\r
   PassThru = &Private->PassThru;\r
@@ -1231,12 +1245,12 @@ Voltage33Retry:
   }\r
 \r
   //\r
-  // 2. Send Cmd8 to the device\r
+  // 2. Send Cmd8 to the device, the command will fail for SdVersion1\r
   //\r
   Status = SdCardVoltageCheck (PassThru, Slot, 0x1, 0xFF);\r
   if (EFI_ERROR (Status)) {\r
+    SdVersion1 = TRUE;\r
     DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd8 fails with %r\n", Status));\r
-    return Status;\r
   }\r
 \r
   //\r
@@ -1426,7 +1440,7 @@ Voltage33Retry:
   DEBUG ((DEBUG_INFO, "SdCardIdentification: Found a SD device at slot [%d]\n", Slot));\r
   Private->Slot[Slot].CardType = SdCardType;\r
 \r
-  Status = SdCardSetBusMode (PciIo, PassThru, Slot, Rca, ((Ocr & BIT24) != 0));\r
+  Status = SdCardSetBusMode (PciIo, PassThru, Slot, Rca, ((Ocr & BIT24) != 0), SdVersion1);\r
 \r
   return Status;\r
 \r