/* Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details. */
EFI_STATUS SdPeimHcInitPowerVoltage(IN UINTN Bar)
/* Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details. */
EFI_STATUS SdPeimHcInitPowerVoltage(IN UINTN Bar)
{
  EFI_STATUS      Status;
  SD_HC_SLOT_CAP  Capability;
  UINT8           MaxVoltage;
  UINT8           HostCtrl2;
  Status = SdPeimHcGetCapability (Bar, &Capability);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  if (Capability.Voltage33 != 0) {
    MaxVoltage = 0x0E;
  } else if (Capability.Voltage30 != 0) {
    MaxVoltage = 0x0C;
  } else if (Capability.Voltage18 != 0) {
    MaxVoltage = 0x0A;
    HostCtrl2  = BIT3;
    Status     = SdPeimHcOrMmio (Bar + SD_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    MicroSecondDelay (5000);
  } else {
    ASSERT (FALSE);
    return EFI_DEVICE_ERROR;
  }
  Status = SdPeimHcPowerControl (Bar, MaxVoltage);
  return Status;
}