]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Sd/EmmcBlockIoPei/EmmcHci.c
MdeModulePkg/SdMmcPciHcDxe: Error handling enhance on tuning procedure
[mirror_edk2.git] / MdeModulePkg / Bus / Sd / EmmcBlockIoPei / EmmcHci.c
index 3ffc4779d948f0a111798f4121e670381b2dfeb0..e23d03c2be2d6b54790273eb962607c9c7fd35bf 100644 (file)
@@ -2305,15 +2305,25 @@ EmmcPeimTuningClkForHs200 (
       return Status;\r
     }\r
 \r
-    if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {\r
+    if ((HostCtrl2 & (BIT6 | BIT7)) == 0) {\r
       break;\r
     }\r
+\r
+    if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {\r
+      return EFI_SUCCESS;\r
+    }\r
   } while (++Retry < 40);\r
 \r
-  if (Retry == 40) {\r
-    Status = EFI_TIMEOUT;\r
+  DEBUG ((EFI_D_ERROR, "EmmcPeimTuningClkForHs200: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry, HostCtrl2));\r
+  //\r
+  // Abort the tuning procedure and reset the tuning circuit.\r
+  //\r
+  HostCtrl2 = (UINT8)~(BIT6 | BIT7);\r
+  Status = EmmcPeimHcAndMmio (Slot->EmmcHcBase + EMMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
   }\r
-  return Status;\r
+  return EFI_DEVICE_ERROR;\r
 }\r
 \r
 /**\r