]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdMmcPciHci.c
MdeModulePkg/SdMmcPciHcDxe: allow HC capabilities to be overridden
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SdMmcPciHcDxe / SdMmcPciHci.c
index aa75aa8d243480f6142015b8a7c17e342f982ed8..9672b5b9bf18184055f6fc7f53bf3a8c68619d6d 100644 (file)
@@ -419,7 +419,7 @@ SdMmcHcWaitMmioSet (
 /**\r
   Software reset the specified SD/MMC host controller and enable all interrupts.\r
 \r
-  @param[in] PciIo          The PCI IO protocol instance.\r
+  @param[in] Private        A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
   @param[in] Slot           The slot number of the SD card to send the command to.\r
 \r
   @retval EFI_SUCCESS       The software reset executes successfully.\r
@@ -428,13 +428,32 @@ SdMmcHcWaitMmioSet (
 **/\r
 EFI_STATUS\r
 SdMmcHcReset (\r
-  IN EFI_PCI_IO_PROTOCOL    *PciIo,\r
+  IN SD_MMC_HC_PRIVATE_DATA *Private,\r
   IN UINT8                  Slot\r
   )\r
 {\r
   EFI_STATUS                Status;\r
   UINT8                     SwReset;\r
+  EFI_PCI_IO_PROTOCOL       *PciIo;\r
+\r
+  //\r
+  // Notify the SD/MMC override protocol that we are about to reset\r
+  // the SD/MMC host controller.\r
+  //\r
+  if (mOverride != NULL && mOverride->NotifyPhase != NULL) {\r
+    Status = mOverride->NotifyPhase (\r
+                          Private->ControllerHandle,\r
+                          Slot,\r
+                          EdkiiSdMmcResetPre);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_WARN,\r
+        "%a: SD/MMC pre reset notifier callback failed - %r\n",\r
+        __FUNCTION__, Status));\r
+      return Status;\r
+    }\r
+  }\r
 \r
+  PciIo   = Private->PciIo;\r
   SwReset = 0xFF;\r
   Status  = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_SW_RST, FALSE, sizeof (SwReset), &SwReset);\r
 \r
@@ -456,10 +475,32 @@ SdMmcHcReset (
     DEBUG ((DEBUG_INFO, "SdMmcHcReset: reset done with %r\n", Status));\r
     return Status;\r
   }\r
+\r
   //\r
   // Enable all interrupt after reset all.\r
   //\r
   Status = SdMmcHcEnableInterrupt (PciIo, Slot);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_INFO, "SdMmcHcReset: SdMmcHcEnableInterrupt done with %r\n",\r
+      Status));\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Notify the SD/MMC override protocol that we have just reset\r
+  // the SD/MMC host controller.\r
+  //\r
+  if (mOverride != NULL && mOverride->NotifyPhase != NULL) {\r
+    Status = mOverride->NotifyPhase (\r
+                          Private->ControllerHandle,\r
+                          Slot,\r
+                          EdkiiSdMmcResetPost);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_WARN,\r
+        "%a: SD/MMC post reset notifier callback failed - %r\n",\r
+        __FUNCTION__, Status));\r
+    }\r
+  }\r
 \r
   return Status;\r
 }\r
@@ -1021,9 +1062,8 @@ SdMmcHcInitTimeoutCtrl (
   Initial SD/MMC host controller with lowest clock frequency, max power and max timeout value\r
   at initialization.\r
 \r
-  @param[in] PciIo          The PCI IO protocol instance.\r
+  @param[in] Private        A pointer to the SD_MMC_HC_PRIVATE_DATA instance.\r
   @param[in] Slot           The slot number of the SD card to send the command to.\r
-  @param[in] Capability     The capability of the slot.\r
 \r
   @retval EFI_SUCCESS       The host controller is initialized successfully.\r
   @retval Others            The host controller isn't initialized successfully.\r
@@ -1031,12 +1071,33 @@ SdMmcHcInitTimeoutCtrl (
 **/\r
 EFI_STATUS\r
 SdMmcHcInitHost (\r
-  IN EFI_PCI_IO_PROTOCOL    *PciIo,\r
-  IN UINT8                  Slot,\r
-  IN SD_MMC_HC_SLOT_CAP     Capability\r
+  IN SD_MMC_HC_PRIVATE_DATA *Private,\r
+  IN UINT8                  Slot\r
   )\r
 {\r
-  EFI_STATUS       Status;\r
+  EFI_STATUS                Status;\r
+  EFI_PCI_IO_PROTOCOL       *PciIo;\r
+  SD_MMC_HC_SLOT_CAP        Capability;\r
+\r
+  //\r
+  // Notify the SD/MMC override protocol that we are about to initialize\r
+  // the SD/MMC host controller.\r
+  //\r
+  if (mOverride != NULL && mOverride->NotifyPhase != NULL) {\r
+    Status = mOverride->NotifyPhase (\r
+                          Private->ControllerHandle,\r
+                          Slot,\r
+                          EdkiiSdMmcInitHostPre);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_WARN,\r
+        "%a: SD/MMC pre init notifier callback failed - %r\n",\r
+        __FUNCTION__, Status));\r
+      return Status;\r
+    }\r
+  }\r
+\r
+  PciIo = Private->PciIo;\r
+  Capability = Private->Capability[Slot];\r
 \r
   Status = SdMmcHcInitClockFreq (PciIo, Slot, Capability);\r
   if (EFI_ERROR (Status)) {\r
@@ -1049,6 +1110,25 @@ SdMmcHcInitHost (
   }\r
 \r
   Status = SdMmcHcInitTimeoutCtrl (PciIo, Slot);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  //\r
+  // Notify the SD/MMC override protocol that we are have just initialized\r
+  // the SD/MMC host controller.\r
+  //\r
+  if (mOverride != NULL && mOverride->NotifyPhase != NULL) {\r
+    Status = mOverride->NotifyPhase (\r
+                          Private->ControllerHandle,\r
+                          Slot,\r
+                          EdkiiSdMmcInitHostPost);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_WARN,\r
+        "%a: SD/MMC post init notifier callback failed - %r\n",\r
+        __FUNCTION__, Status));\r
+    }\r
+  }\r
   return Status;\r
 }\r
 \r