20#define MAX_RETRY_COUNT 1000
21#define CMD_RETRY_COUNT 20
22#define RCA_SHIFT_OFFSET 16
23#define EMMC_CARD_SIZE 512
24#define EMMC_ECSD_SIZE_OFFSET 53
26#define EXTCSD_BUS_WIDTH 183
27#define EXTCSD_HS_TIMING 185
29#define EMMC_TIMING_BACKWARD 0
30#define EMMC_TIMING_HS 1
31#define EMMC_TIMING_HS200 2
32#define EMMC_TIMING_HS400 3
34#define EMMC_BUS_WIDTH_1BIT 0
35#define EMMC_BUS_WIDTH_4BIT 1
36#define EMMC_BUS_WIDTH_8BIT 2
37#define EMMC_BUS_WIDTH_DDR_4BIT 5
38#define EMMC_BUS_WIDTH_DDR_8BIT 6
40#define EMMC_SWITCH_ERROR (1 << 7)
42#define SD_BUS_WIDTH_1BIT (1 << 0)
43#define SD_BUS_WIDTH_4BIT (1 << 2)
45#define SD_CCC_SWITCH (1 << 10)
47#define DEVICE_STATE(x) (((x) >> 9) & 0xf)
48typedef enum _EMMC_DEVICE_STATE {
62UINT32 mEmmcRcaCount = 0;
69 OUT EMMC_DEVICE_STATE *State
77 return EFI_INVALID_PARAMETER;
80 Host = MmcHostInstance->MmcHost;
81 RCA = MmcHostInstance->CardInfo.RCA << RCA_SHIFT_OFFSET;
82 Status = Host->SendCommand (Host, MMC_CMD13, RCA);
83 if (EFI_ERROR (Status)) {
84 DEBUG ((DEBUG_ERROR,
"EmmcGetDeviceState(): Failed to get card status, Status=%r.\n", Status));
88 Status = Host->ReceiveResponse (Host, MMC_RESPONSE_TYPE_R1, &Data);
89 if (EFI_ERROR (Status)) {
90 DEBUG ((DEBUG_ERROR,
"EmmcGetDeviceState(): Failed to get response of CMD13, Status=%r.\n", Status));
94 if (Data & EMMC_SWITCH_ERROR) {
95 DEBUG ((DEBUG_ERROR,
"EmmcGetDeviceState(): Failed to switch expected mode, Status=%r.\n", Status));
96 return EFI_DEVICE_ERROR;
99 *State = DEVICE_STATE (Data);
113 EMMC_DEVICE_STATE State;
117 Host = MmcHostInstance->MmcHost;
118 Argument = EMMC_CMD6_ARG_ACCESS (3) | EMMC_CMD6_ARG_INDEX (ExtCmdIndex) |
119 EMMC_CMD6_ARG_VALUE (Value) | EMMC_CMD6_ARG_CMD_SET (1);
120 Status = Host->SendCommand (Host, MMC_CMD6, Argument);
121 if (EFI_ERROR (Status)) {
122 DEBUG ((DEBUG_ERROR,
"EmmcSetEXTCSD(): Failed to send CMD6, Status=%r.\n", Status));
128 Status = EmmcGetDeviceState (MmcHostInstance, &State);
129 if (EFI_ERROR (Status)) {
130 DEBUG ((DEBUG_ERROR,
"EmmcSetEXTCSD(): Failed to get device state, Status=%r.\n", Status));
133 }
while (State == EMMC_PRG_STATE);
141EmmcIdentificationMode (
149 EMMC_DEVICE_STATE State;
152 Host = MmcHostInstance->MmcHost;
153 Media = MmcHostInstance->BlockIo.Media;
156 Status = Host->SendCommand (Host, MMC_CMD2, 0);
157 if (EFI_ERROR (Status)) {
158 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): Failed to send CMD2, Status=%r.\n", Status));
162 Status = Host->ReceiveResponse (Host, MMC_RESPONSE_TYPE_R2, (UINT32 *)&(MmcHostInstance->CardInfo.CIDData));
163 if (EFI_ERROR (Status)) {
164 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): CID retrieval error, Status=%r.\n", Status));
169 MmcHostInstance->CardInfo.RCA = ++mEmmcRcaCount;
170 RCA = MmcHostInstance->CardInfo.RCA << RCA_SHIFT_OFFSET;
171 Status = Host->SendCommand (Host, MMC_CMD3, RCA);
172 if (EFI_ERROR (Status)) {
173 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): RCA set error, Status=%r.\n", Status));
178 Status = Host->SendCommand (Host, MMC_CMD9, RCA);
179 if (EFI_ERROR (Status)) {
180 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): Failed to send CMD9, Status=%r.\n", Status));
184 Status = Host->ReceiveResponse (Host, MMC_RESPONSE_TYPE_R2, (UINT32 *)&(MmcHostInstance->CardInfo.CSDData));
185 if (EFI_ERROR (Status)) {
186 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): CSD retrieval error, Status=%r.\n", Status));
191 Status = Host->SendCommand (Host, MMC_CMD7, RCA);
192 if (EFI_ERROR (Status)) {
193 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): Card selection error, Status=%r.\n", Status));
196 if (MMC_HOST_HAS_SETIOS (Host)) {
198 Status = Host->SetIos (Host, 0, 1, EMMCBACKWARD);
199 if (EFI_ERROR (Status)) {
200 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): Set 1-bit bus width error, Status=%r.\n", Status));
205 Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_BUS_WIDTH, EMMC_BUS_WIDTH_1BIT);
206 if (EFI_ERROR (Status)) {
207 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): Set extcsd bus width error, Status=%r.\n", Status));
214 if (MmcHostInstance->CardInfo.ECSDData ==
NULL) {
215 return EFI_OUT_OF_RESOURCES;
218 Status = Host->SendCommand (Host, MMC_CMD8, 0);
219 if (EFI_ERROR (Status)) {
220 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): ECSD fetch error, Status=%r.\n", Status));
223 Status = Host->ReadBlockData (Host, 0, 512, (UINT32 *)MmcHostInstance->CardInfo.ECSDData);
224 if (EFI_ERROR (Status)) {
225 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): ECSD read error, Status=%r.\n", Status));
231 Status = EmmcGetDeviceState (MmcHostInstance, &State);
232 if (EFI_ERROR (Status)) {
233 DEBUG ((DEBUG_ERROR,
"EmmcIdentificationMode(): Failed to get device state, Status=%r.\n", Status));
236 }
while (State == EMMC_DATA_STATE);
240 Media->
MediaId = MmcHostInstance->CardInfo.CIDData.PSN;
241 Media->
ReadOnly = MmcHostInstance->CardInfo.CSDData.PERM_WRITE_PROTECT;
245 Media->
LastBlock = MmcHostInstance->CardInfo.ECSDData->SECTOR_COUNT - 1;
249 MmcHostInstance->CardInfo.CardType = EMMC_CARD;
259InitializeEmmcDevice (
266 UINT32 BusClockFreq, Idx, BusMode;
267 UINT32 TimingMode[4] = { EMMCHS52DDR1V2, EMMCHS52DDR1V8, EMMCHS52, EMMCHS26 };
269 Host = MmcHostInstance->MmcHost;
270 ECSDData = MmcHostInstance->CardInfo.ECSDData;
271 if (ECSDData->DEVICE_TYPE == EMMCBACKWARD) {
275 if (!MMC_HOST_HAS_SETIOS (Host)) {
279 Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_HS_TIMING, EMMC_TIMING_HS);
280 if (EFI_ERROR (Status)) {
281 DEBUG ((DEBUG_ERROR,
"InitializeEmmcDevice(): Failed to switch high speed mode, Status:%r.\n", Status));
285 for (Idx = 0; Idx < 4; Idx++) {
286 switch (TimingMode[Idx]) {
290 BusClockFreq = 52000000;
293 BusClockFreq = 26000000;
296 return EFI_UNSUPPORTED;
299 Status = Host->SetIos (Host, BusClockFreq, 8, TimingMode[Idx]);
300 if (!EFI_ERROR (Status)) {
301 switch (TimingMode[Idx]) {
304 BusMode = EMMC_BUS_WIDTH_DDR_8BIT;
308 BusMode = EMMC_BUS_WIDTH_8BIT;
311 return EFI_UNSUPPORTED;
314 Status = EmmcSetEXTCSD (MmcHostInstance, EXTCSD_BUS_WIDTH, BusMode);
315 if (EFI_ERROR (Status)) {
316 DEBUG ((DEBUG_ERROR,
"InitializeEmmcDevice(): Failed to set EXTCSD bus width, Status:%r\n", Status));
328CreateSwitchCmdArgument (
336 Argument = Mode << 31 | 0x00FFFFFF;
337 Argument &= ~(0xF << (Group * 4));
338 Argument |= Value << (Group * 4);
345InitializeSdMmcDevice (
361 Speed = SD_DEFAULT_SPEED;
362 MmcHost = MmcHostInstance->MmcHost;
365 CmdArg = MmcHostInstance->CardInfo.RCA << 16;
366 Status = MmcHost->SendCommand (MmcHost, MMC_CMD9, CmdArg);
367 if (EFI_ERROR (Status)) {
368 DEBUG ((DEBUG_ERROR,
"InitializeSdMmcDevice(MMC_CMD9): Error, Status=%r\n", Status));
373 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CSD, Response);
374 if (EFI_ERROR (Status)) {
375 DEBUG ((DEBUG_ERROR,
"InitializeSdMmcDevice(): Failed to receive CSD, Status=%r\n", Status));
380 if (MMC_CSD_GET_CCC (Response) & SD_CCC_SWITCH) {
386 if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) {
387 CardSize = HC_MMC_CSD_GET_DEVICESIZE (Response);
388 NumBlocks = ((CardSize + 1) * 1024);
389 BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response);
391 CardSize = MMC_CSD_GET_DEVICESIZE (Response);
392 NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2));
393 BlockSize = 1 << MMC_CSD_GET_READBLLEN (Response);
397 if (BlockSize > 512) {
398 NumBlocks =
MultU64x32 (NumBlocks, BlockSize / 512);
402 MmcHostInstance->BlockIo.Media->LastBlock = (NumBlocks - 1);
403 MmcHostInstance->BlockIo.Media->BlockSize = BlockSize;
404 MmcHostInstance->BlockIo.Media->ReadOnly = MmcHost->IsReadOnly (MmcHost);
405 MmcHostInstance->BlockIo.Media->MediaPresent =
TRUE;
406 MmcHostInstance->BlockIo.Media->MediaId++;
408 CmdArg = MmcHostInstance->CardInfo.RCA << 16;
409 Status = MmcHost->SendCommand (MmcHost, MMC_CMD7, CmdArg);
410 if (EFI_ERROR (Status)) {
411 DEBUG ((DEBUG_ERROR,
"InitializeSdMmcDevice(MMC_CMD7): Error and Status = %r\n", Status));
415 Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, CmdArg);
416 if (EFI_ERROR (Status)) {
417 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD55): Error and Status = %r\n", __func__, Status));
421 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
422 if (EFI_ERROR (Status)) {
423 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD55): Error and Status = %r\n", __func__, Status));
427 if ((Response[0] & MMC_STATUS_APP_CMD) == 0) {
432 Status = MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0);
433 if (EFI_ERROR (Status)) {
434 DEBUG ((DEBUG_ERROR,
"%a(MMC_ACMD51): Error and Status = %r\n", __func__, Status));
437 Status = MmcHost->ReadBlockData (MmcHost, 0, 8, Buffer);
438 if (EFI_ERROR (Status)) {
439 DEBUG ((DEBUG_ERROR,
"%a(MMC_ACMD51): ReadBlockData Error and Status = %r\n", __func__, Status));
444 if (Scr.SD_SPEC == 2) {
445 if (Scr.SD_SPEC3 == 1) {
446 if (Scr.SD_SPEC4 == 1) {
447 DEBUG ((DEBUG_INFO,
"Found SD Card for Spec Version 4.xx\n"));
449 DEBUG ((DEBUG_INFO,
"Found SD Card for Spec Version 3.0x\n"));
452 if (Scr.SD_SPEC4 == 0) {
453 DEBUG ((DEBUG_INFO,
"Found SD Card for Spec Version 2.0\n"));
455 DEBUG ((DEBUG_ERROR,
"Found invalid SD Card\n"));
459 if ((Scr.SD_SPEC3 == 0) && (Scr.SD_SPEC4 == 0)) {
460 if (Scr.SD_SPEC == 1) {
461 DEBUG ((DEBUG_INFO,
"Found SD Card for Spec Version 1.10\n"));
463 DEBUG ((DEBUG_INFO,
"Found SD Card for Spec Version 1.0\n"));
466 DEBUG ((DEBUG_ERROR,
"Found invalid SD Card\n"));
473 CmdArg = CreateSwitchCmdArgument (0, 0, 0);
474 Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg);
475 if (EFI_ERROR (Status)) {
476 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD6): Error and Status = %r\n", __func__, Status));
479 Status = MmcHost->ReadBlockData (MmcHost, 0, SWITCH_CMD_DATA_LENGTH, Buffer);
480 if (EFI_ERROR (Status)) {
481 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD6): ReadBlockData Error and Status = %r\n", __func__, Status));
486 if (!(Buffer[3] & SD_HIGH_SPEED_SUPPORTED)) {
487 DEBUG ((DEBUG_INFO,
"%a : High Speed not supported by Card\n", __func__));
489 Speed = SD_HIGH_SPEED;
492 CmdArg = CreateSwitchCmdArgument (1, 0, 1);
493 Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg);
494 if (EFI_ERROR (Status)) {
495 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD6): Error and Status = %r\n", __func__, Status));
498 Status = MmcHost->ReadBlockData (MmcHost, 0, SWITCH_CMD_DATA_LENGTH, Buffer);
499 if (EFI_ERROR (Status)) {
500 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD6): ReadBlockData Error and Status = %r\n", __func__, Status));
504 if ((Buffer[4] & SWITCH_CMD_SUCCESS_MASK) != 0x01000000) {
505 DEBUG ((DEBUG_ERROR,
"Problem switching SD card into high-speed mode\n"));
512 if (Scr.SD_BUS_WIDTHS & SD_BUS_WIDTH_4BIT) {
513 CmdArg = MmcHostInstance->CardInfo.RCA << 16;
514 Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, CmdArg);
515 if (EFI_ERROR (Status)) {
516 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD55): Error and Status = %r\n", __func__, Status));
521 Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, 2);
522 if (EFI_ERROR (Status)) {
523 DEBUG ((DEBUG_ERROR,
"%a (MMC_CMD6): Error and Status = %r\n", __func__, Status));
528 if (MMC_HOST_HAS_SETIOS (MmcHost)) {
529 Status = MmcHost->SetIos (MmcHost, Speed, BUSWIDTH_4, EMMCBACKWARD);
530 if (EFI_ERROR (Status)) {
531 DEBUG ((DEBUG_ERROR,
"%a (SetIos): Error and Status = %r\n", __func__, Status));
542MmcIdentificationMode (
554 MmcHost = MmcHostInstance->MmcHost;
558 if (MmcHost ==
NULL) {
559 return EFI_INVALID_PARAMETER;
563 if (MmcHostInstance->State == MmcHwInitializationState) {
565 Status = MmcNotifyState (MmcHostInstance, MmcHwInitializationState);
566 if (EFI_ERROR (Status)) {
567 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Error MmcHwInitializationState, Status=%r.\n", Status));
572 Status = MmcHost->SendCommand (MmcHost, MMC_CMD0, 0);
573 if (EFI_ERROR (Status)) {
574 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode(MMC_CMD0): Error, Status=%r.\n", Status));
578 Status = MmcNotifyState (MmcHostInstance, MmcIdleState);
579 if (EFI_ERROR (Status)) {
580 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Error MmcIdleState, Status=%r.\n", Status));
586 Timeout = MAX_RETRY_COUNT;
588 Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, EMMC_CMD1_CAPACITY_GREATER_THAN_2GB);
589 if (EFI_ERROR (Status)) {
593 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, (UINT32 *)&OcrResponse);
594 if (EFI_ERROR (Status)) {
595 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));
600 }
while (!OcrResponse.Ocr.PowerUp && (Timeout > 0));
603 if (!OcrResponse.Ocr.PowerUp) {
604 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode(MMC_CMD1): Card initialisation failure, Status=%r.\n", Status));
605 return EFI_DEVICE_ERROR;
608 OcrResponse.Ocr.PowerUp = 0;
609 if (OcrResponse.Raw == EMMC_CMD1_CAPACITY_GREATER_THAN_2GB) {
610 MmcHostInstance->CardInfo.OCRData.AccessMode = BIT1;
612 MmcHostInstance->CardInfo.OCRData.AccessMode = 0x0;
616 if ((OcrResponse.Raw == EMMC_CMD1_CAPACITY_GREATER_THAN_2GB) ||
617 (OcrResponse.Raw == EMMC_CMD1_CAPACITY_LESS_THAN_2GB))
619 return EmmcIdentificationMode (MmcHostInstance, OcrResponse);
624 Status = MmcHost->SendCommand (MmcHost, MMC_CMD5, 0);
626 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode(MMC_CMD5): Error - SDIO not supported, Status=%r.\n", Status));
627 return EFI_UNSUPPORTED;
631 CmdArg = (0x0UL << 12 | BIT8 | 0xCEUL << 0);
632 Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, CmdArg);
634 DEBUG ((DEBUG_ERROR,
"Card is SD2.0 => Supports high capacity\n"));
636 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R7, Response);
637 if (EFI_ERROR (Status)) {
638 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Failed to receive response to CMD8, Status=%r.\n", Status));
642 PrintResponseR1 (Response[0]);
644 if (Response[0] != CmdArg) {
645 DEBUG ((DEBUG_ERROR,
"The Card is not usable\n"));
646 return EFI_UNSUPPORTED;
649 DEBUG ((DEBUG_ERROR,
"Not a SD2.0 Card\n"));
653 Timeout = MAX_RETRY_COUNT;
654 while (Timeout > 0) {
656 Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, 0);
658 DEBUG ((DEBUG_INFO,
"Card should be SD\n"));
660 MmcHostInstance->CardInfo.CardType = SD_CARD_2;
662 MmcHostInstance->CardInfo.CardType = SD_CARD;
666 CmdArg = ((
UINTN *)&(MmcHostInstance->CardInfo.OCRData))[0];
671 Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg);
672 if (!EFI_ERROR (Status)) {
673 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response);
674 if (EFI_ERROR (Status)) {
675 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));
679 ((UINT32 *)&(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
682 DEBUG ((DEBUG_INFO,
"Card should be MMC\n"));
683 MmcHostInstance->CardInfo.CardType = MMC_CARD;
685 Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, 0x800000);
686 if (!EFI_ERROR (Status)) {
687 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response);
688 if (EFI_ERROR (Status)) {
689 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status));
693 ((UINT32 *)&(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
697 if (!EFI_ERROR (Status)) {
698 if (!MmcHostInstance->CardInfo.OCRData.PowerUp) {
702 if ((MmcHostInstance->CardInfo.CardType == SD_CARD_2) && (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1)) {
703 MmcHostInstance->CardInfo.CardType = SD_CARD_2_HIGH;
704 DEBUG ((DEBUG_ERROR,
"High capacity card.\n"));
716 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode(): No Card\n"));
719 PrintOCR (Response[0]);
722 Status = MmcNotifyState (MmcHostInstance, MmcReadyState);
723 if (EFI_ERROR (Status)) {
724 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Error MmcReadyState\n"));
728 Status = MmcHost->SendCommand (MmcHost, MMC_CMD2, 0);
729 if (EFI_ERROR (Status)) {
730 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode(MMC_CMD2): Error\n"));
734 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID, Response);
735 if (EFI_ERROR (Status)) {
736 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Failed to receive CID, Status=%r.\n", Status));
742 Status = MmcHost->NotifyState (MmcHost, MmcIdentificationState);
743 if (EFI_ERROR (Status)) {
744 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Error MmcIdentificationState\n"));
754 Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, CmdArg);
755 if (EFI_ERROR (Status)) {
756 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode(MMC_CMD3): Error\n"));
760 Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_RCA, Response);
761 if (EFI_ERROR (Status)) {
762 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Failed to receive RCA, Status=%r.\n", Status));
766 PrintRCA (Response[0]);
769 if (MmcHostInstance->CardInfo.CardType != MMC_CARD) {
770 MmcHostInstance->CardInfo.RCA = Response[0] >> 16;
772 MmcHostInstance->CardInfo.RCA = CmdArg;
775 Status = MmcNotifyState (MmcHostInstance, MmcStandByState);
776 if (EFI_ERROR (Status)) {
777 DEBUG ((DEBUG_ERROR,
"MmcIdentificationMode() : Error MmcStandByState\n"));
794 MmcHost = MmcHostInstance->MmcHost;
796 Status = MmcIdentificationMode (MmcHostInstance);
797 if (EFI_ERROR (Status)) {
798 DEBUG ((DEBUG_ERROR,
"InitializeMmcDevice(): Error in Identification Mode, Status=%r\n", Status));
802 Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
803 if (EFI_ERROR (Status)) {
804 DEBUG ((DEBUG_ERROR,
"InitializeMmcDevice(): Error MmcTransferState, Status=%r\n", Status));
808 if (MmcHostInstance->CardInfo.CardType != EMMC_CARD) {
809 Status = InitializeSdMmcDevice (MmcHostInstance);
811 Status = InitializeEmmcDevice (MmcHostInstance);
814 if (EFI_ERROR (Status)) {
819 Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize);
820 if (EFI_ERROR (Status)) {
823 "InitializeMmcDevice(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n",
824 MmcHostInstance->BlockIo.Media->BlockSize,
831 if (MmcHostInstance->CardInfo.CardType == MMC_CARD) {
832 Status = MmcHost->SendCommand (MmcHost, MMC_CMD23, BlockCount);
833 if (EFI_ERROR (Status)) {
834 DEBUG ((DEBUG_ERROR,
"InitializeMmcDevice(MMC_CMD23): Error, Status=%r\n", Status));
UINT64 EFIAPI MultU64x32(IN UINT64 Multiplicand, IN UINT32 Multiplier)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define EFI_SIZE_TO_PAGES(Size)
UINT32 LogicalBlocksPerPhysicalBlock