/* Refer to EMMC Electrical Standard Spec 5.1 Section 6.6 and SD Host Controller Simplified Spec 3.0 section Figure 3-3 for details. */
EFI_STATUS EmmcPeimSwitchClockFreq(IN EMMC_PEIM_HC_SLOT *Slot, IN UINT32 Rca, IN UINT8 HsTiming, IN UINT32 ClockFreq)
/* Refer to EMMC Electrical Standard Spec 5.1 Section 6.6 and SD Host Controller Simplified Spec 3.0 section Figure 3-3 for details. */
EFI_STATUS EmmcPeimSwitchClockFreq(IN EMMC_PEIM_HC_SLOT *Slot, IN UINT32 Rca, IN UINT8 HsTiming, IN UINT32 ClockFreq)
{
  EFI_STATUS  Status;
  UINT8       Access;
  UINT8       Index;
  UINT8       Value;
  UINT8       CmdSet;
  UINT32      DevStatus;
  Access = 0x03;
  Index  = OFFSET_OF (EMMC_EXT_CSD, HsTiming);
  Value  = HsTiming;
  CmdSet = 0;
  Status = EmmcPeimSwitch (Slot, Access, Index, Value, CmdSet);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  Status = EmmcPeimSendStatus (Slot, Rca, &DevStatus);
  if (EFI_ERROR (Status)) {
    return Status;
  }
  if ((DevStatus & BIT7) != 0) {
    return EFI_DEVICE_ERROR;
  }
  Status = EmmcPeimHcClockSupply (Slot->EmmcHcBase, ClockFreq * 1000);
  return Status;
}