/* Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details. */
EFI_STATUS EmmcPeimHcInitPowerVoltage(IN UINTN Bar)
/* Refer to SD Host Controller Simplified spec 3.0 Section 3.3 for details. */
EFI_STATUS EmmcPeimHcInitPowerVoltage(IN UINTN Bar)
{
  EFI_STATUS        Status;
  EMMC_HC_SLOT_CAP  Capability;
  UINT8             MaxVoltage;
  UINT8             HostCtrl2;
  Status = EmmcPeimHcGetCapability (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     = EmmcPeimHcOrMmio (Bar + EMMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
    if (EFI_ERROR (Status)) {
      return Status;
    }
    MicroSecondDelay (5000);
  } else {
    ASSERT (FALSE);
    return EFI_DEVICE_ERROR;
  }
  Status = EmmcPeimHcPowerControl (Bar, MaxVoltage);
  return Status;
}