3 * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
22 #define MAX_RETRY_COUNT 1000
23 #define CMD_RETRY_COUNT 20
24 #define RCA_SHIFT_OFFSET 16
25 #define EMMC_CARD_SIZE 512
26 #define EMMC_ECSD_SIZE_OFFSET 53
28 #define EXTCSD_BUS_WIDTH 183
29 #define EXTCSD_HS_TIMING 185
31 #define EMMC_TIMING_BACKWARD 0
32 #define EMMC_TIMING_HS 1
33 #define EMMC_TIMING_HS200 2
34 #define EMMC_TIMING_HS400 3
36 #define EMMC_BUS_WIDTH_1BIT 0
37 #define EMMC_BUS_WIDTH_4BIT 1
38 #define EMMC_BUS_WIDTH_8BIT 2
39 #define EMMC_BUS_WIDTH_DDR_4BIT 5
40 #define EMMC_BUS_WIDTH_DDR_8BIT 6
42 #define EMMC_SWITCH_ERROR (1 << 7)
44 #define DEVICE_STATE(x) (((x) >> 9) & 0xf)
45 typedef enum _EMMC_DEVICE_STATE
{
59 UINT32 mEmmcRcaCount
= 0;
65 IN MMC_HOST_INSTANCE
*MmcHostInstance
,
66 OUT EMMC_DEVICE_STATE
*State
69 EFI_MMC_HOST_PROTOCOL
*Host
;
74 return EFI_INVALID_PARAMETER
;
77 Host
= MmcHostInstance
->MmcHost
;
78 RCA
= MmcHostInstance
->CardInfo
.RCA
<< RCA_SHIFT_OFFSET
;
79 Status
= Host
->SendCommand (Host
, MMC_CMD13
, RCA
);
80 if (EFI_ERROR (Status
)) {
81 DEBUG ((EFI_D_ERROR
, "EmmcGetDeviceState(): Failed to get card status, Status=%r.\n", Status
));
84 Status
= Host
->ReceiveResponse (Host
, MMC_RESPONSE_TYPE_R1
, &Data
);
85 if (EFI_ERROR (Status
)) {
86 DEBUG ((EFI_D_ERROR
, "EmmcGetDeviceState(): Failed to get response of CMD13, Status=%r.\n", Status
));
89 if (Data
& EMMC_SWITCH_ERROR
) {
90 DEBUG ((EFI_D_ERROR
, "EmmcGetDeviceState(): Failed to switch expected mode, Status=%r.\n", Status
));
91 return EFI_DEVICE_ERROR
;
93 *State
= DEVICE_STATE(Data
);
101 IN MMC_HOST_INSTANCE
*MmcHostInstance
,
106 EFI_MMC_HOST_PROTOCOL
*Host
;
107 EMMC_DEVICE_STATE State
;
111 Host
= MmcHostInstance
->MmcHost
;
112 Argument
= EMMC_CMD6_ARG_ACCESS(3) | EMMC_CMD6_ARG_INDEX(ExtCmdIndex
) |
113 EMMC_CMD6_ARG_VALUE(Value
) | EMMC_CMD6_ARG_CMD_SET(1);
114 Status
= Host
->SendCommand (Host
, MMC_CMD6
, Argument
);
115 if (EFI_ERROR (Status
)) {
116 DEBUG ((EFI_D_ERROR
, "EmmcSetEXTCSD(): Failed to send CMD6, Status=%r.\n", Status
));
119 // Make sure device exiting prog mode
121 Status
= EmmcGetDeviceState (MmcHostInstance
, &State
);
122 if (EFI_ERROR (Status
)) {
123 DEBUG ((EFI_D_ERROR
, "EmmcSetEXTCSD(): Failed to get device state, Status=%r.\n", Status
));
126 } while (State
== EMMC_PRG_STATE
);
133 EmmcIdentificationMode (
134 IN MMC_HOST_INSTANCE
*MmcHostInstance
,
135 IN OCR_RESPONSE Response
138 EFI_MMC_HOST_PROTOCOL
*Host
;
139 EFI_BLOCK_IO_MEDIA
*Media
;
141 EMMC_DEVICE_STATE State
;
144 Host
= MmcHostInstance
->MmcHost
;
145 Media
= MmcHostInstance
->BlockIo
.Media
;
147 // Fetch card identity register
148 Status
= Host
->SendCommand (Host
, MMC_CMD2
, 0);
149 if (EFI_ERROR (Status
)) {
150 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): Failed to send CMD2, Status=%r.\n", Status
));
154 Status
= Host
->ReceiveResponse (Host
, MMC_RESPONSE_TYPE_R2
, (UINT32
*)&(MmcHostInstance
->CardInfo
.CIDData
));
155 if (EFI_ERROR (Status
)) {
156 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): CID retrieval error, Status=%r.\n", Status
));
160 // Assign a relative address value to the card
161 MmcHostInstance
->CardInfo
.RCA
= ++mEmmcRcaCount
; // TODO: might need a more sophisticated way of doing this
162 RCA
= MmcHostInstance
->CardInfo
.RCA
<< RCA_SHIFT_OFFSET
;
163 Status
= Host
->SendCommand (Host
, MMC_CMD3
, RCA
);
164 if (EFI_ERROR (Status
)) {
165 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): RCA set error, Status=%r.\n", Status
));
169 // Fetch card specific data
170 Status
= Host
->SendCommand (Host
, MMC_CMD9
, RCA
);
171 if (EFI_ERROR (Status
)) {
172 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): Failed to send CMD9, Status=%r.\n", Status
));
176 Status
= Host
->ReceiveResponse (Host
, MMC_RESPONSE_TYPE_R2
, (UINT32
*)&(MmcHostInstance
->CardInfo
.CSDData
));
177 if (EFI_ERROR (Status
)) {
178 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): CSD retrieval error, Status=%r.\n", Status
));
183 Status
= Host
->SendCommand (Host
, MMC_CMD7
, RCA
);
184 if (EFI_ERROR (Status
)) {
185 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): Card selection error, Status=%r.\n", Status
));
188 if (MMC_HOST_HAS_SETIOS(Host
)) {
189 // Set 1-bit bus width
190 Status
= Host
->SetIos (Host
, 0, 1, EMMCBACKWARD
);
191 if (EFI_ERROR (Status
)) {
192 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): Set 1-bit bus width error, Status=%r.\n", Status
));
196 // Set 1-bit bus width for EXTCSD
197 Status
= EmmcSetEXTCSD (MmcHostInstance
, EXTCSD_BUS_WIDTH
, EMMC_BUS_WIDTH_1BIT
);
198 if (EFI_ERROR (Status
)) {
199 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): Set extcsd bus width error, Status=%r.\n", Status
));
205 Status
= Host
->SendCommand (Host
, MMC_CMD8
, RCA
);
206 if (EFI_ERROR (Status
)) {
207 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): ECSD fetch error, Status=%r.\n", Status
));
210 Status
= Host
->ReadBlockData (Host
, 0, 512, (UINT32
*)&(MmcHostInstance
->CardInfo
.ECSDData
));
211 if (EFI_ERROR (Status
)) {
212 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): ECSD read error, Status=%r.\n", Status
));
216 // Make sure device exiting data mode
218 Status
= EmmcGetDeviceState (MmcHostInstance
, &State
);
219 if (EFI_ERROR (Status
)) {
220 DEBUG ((EFI_D_ERROR
, "EmmcIdentificationMode(): Failed to get device state, Status=%r.\n", Status
));
223 } while (State
== EMMC_DATA_STATE
);
226 Media
->BlockSize
= EMMC_CARD_SIZE
; // 512-byte support is mandatory for eMMC cards
227 Media
->MediaId
= MmcHostInstance
->CardInfo
.CIDData
.PSN
;
228 Media
->ReadOnly
= MmcHostInstance
->CardInfo
.CSDData
.PERM_WRITE_PROTECT
;
229 Media
->LogicalBlocksPerPhysicalBlock
= 1;
231 // Compute last block using bits [215:212] of the ECSD
232 Media
->LastBlock
= MmcHostInstance
->CardInfo
.ECSDData
.SECTOR_COUNT
- 1; // eMMC isn't supposed to report this for
233 // Cards <2GB in size, but the model does.
236 MmcHostInstance
->CardInfo
.CardType
= EMMC_CARD
;
242 InitializeEmmcDevice (
243 IN MMC_HOST_INSTANCE
*MmcHostInstance
246 EFI_MMC_HOST_PROTOCOL
*Host
;
247 EFI_STATUS Status
= EFI_SUCCESS
;
249 UINT32 BusClockFreq
, Idx
;
250 UINT32 TimingMode
[4] = {EMMCHS52DDR1V2
, EMMCHS52DDR1V8
, EMMCHS52
, EMMCHS26
};
252 Host
= MmcHostInstance
->MmcHost
;
253 ECSDData
= &MmcHostInstance
->CardInfo
.ECSDData
;
254 if (ECSDData
->DEVICE_TYPE
== EMMCBACKWARD
)
257 if (!MMC_HOST_HAS_SETIOS(Host
)) {
260 Status
= EmmcSetEXTCSD (MmcHostInstance
, EXTCSD_HS_TIMING
, EMMC_TIMING_HS
);
261 if (EFI_ERROR (Status
)) {
262 DEBUG ((DEBUG_ERROR
, "InitializeEmmcDevice(): Failed to switch high speed mode, Status:%r.\n", Status
));
266 for (Idx
= 0; Idx
< 4; Idx
++) {
267 switch (TimingMode
[Idx
]) {
271 BusClockFreq
= 52000000;
274 BusClockFreq
= 26000000;
277 return EFI_UNSUPPORTED
;
279 Status
= Host
->SetIos (Host
, BusClockFreq
, 8, TimingMode
[Idx
]);
280 if (!EFI_ERROR (Status
)) {
281 Status
= EmmcSetEXTCSD (MmcHostInstance
, EXTCSD_BUS_WIDTH
, EMMC_BUS_WIDTH_DDR_8BIT
);
282 if (EFI_ERROR (Status
)) {
283 DEBUG ((DEBUG_ERROR
, "InitializeEmmcDevice(): Failed to set EXTCSD bus width, Status:%r\n", Status
));
293 InitializeSdMmcDevice (
294 IN MMC_HOST_INSTANCE
*MmcHostInstance
303 EFI_MMC_HOST_PROTOCOL
*MmcHost
;
305 MmcHost
= MmcHostInstance
->MmcHost
;
307 // Send a command to get Card specific data
308 CmdArg
= MmcHostInstance
->CardInfo
.RCA
<< 16;
309 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD9
, CmdArg
);
310 if (EFI_ERROR (Status
)) {
311 DEBUG((EFI_D_ERROR
, "InitializeSdMmcDevice(MMC_CMD9): Error, Status=%r\n", Status
));
316 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_CSD
, Response
);
317 if (EFI_ERROR (Status
)) {
318 DEBUG((EFI_D_ERROR
, "InitializeSdMmcDevice(): Failed to receive CSD, Status=%r\n", Status
));
323 if (MmcHostInstance
->CardInfo
.CardType
== SD_CARD_2_HIGH
) {
324 CardSize
= HC_MMC_CSD_GET_DEVICESIZE (Response
);
325 NumBlocks
= ((CardSize
+ 1) * 1024);
326 BlockSize
= 1 << MMC_CSD_GET_READBLLEN (Response
);
328 CardSize
= MMC_CSD_GET_DEVICESIZE (Response
);
329 NumBlocks
= (CardSize
+ 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response
) + 2));
330 BlockSize
= 1 << MMC_CSD_GET_READBLLEN (Response
);
333 // For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.
334 if (BlockSize
> 512) {
335 NumBlocks
= MultU64x32 (NumBlocks
, BlockSize
/ 512);
339 MmcHostInstance
->BlockIo
.Media
->LastBlock
= (NumBlocks
- 1);
340 MmcHostInstance
->BlockIo
.Media
->BlockSize
= BlockSize
;
341 MmcHostInstance
->BlockIo
.Media
->ReadOnly
= MmcHost
->IsReadOnly (MmcHost
);
342 MmcHostInstance
->BlockIo
.Media
->MediaPresent
= TRUE
;
343 MmcHostInstance
->BlockIo
.Media
->MediaId
++;
345 CmdArg
= MmcHostInstance
->CardInfo
.RCA
<< 16;
346 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD7
, CmdArg
);
347 if (EFI_ERROR (Status
)) {
348 DEBUG((EFI_D_ERROR
, "InitializeSdMmcDevice(MMC_CMD7): Error and Status = %r\n", Status
));
358 MmcIdentificationMode (
359 IN MMC_HOST_INSTANCE
*MmcHostInstance
367 EFI_MMC_HOST_PROTOCOL
*MmcHost
;
368 OCR_RESPONSE OcrResponse
;
370 MmcHost
= MmcHostInstance
->MmcHost
;
374 if (MmcHost
== NULL
) {
375 return EFI_INVALID_PARAMETER
;
378 // We can get into this function if we restart the identification mode
379 if (MmcHostInstance
->State
== MmcHwInitializationState
) {
380 // Initialize the MMC Host HW
381 Status
= MmcNotifyState (MmcHostInstance
, MmcHwInitializationState
);
382 if (EFI_ERROR (Status
)) {
383 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Error MmcHwInitializationState, Status=%r.\n", Status
));
388 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD0
, 0);
389 if (EFI_ERROR (Status
)) {
390 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode(MMC_CMD0): Error, Status=%r.\n", Status
));
393 Status
= MmcNotifyState (MmcHostInstance
, MmcIdleState
);
394 if (EFI_ERROR (Status
)) {
395 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Error MmcIdleState, Status=%r.\n", Status
));
399 // Send CMD1 to get OCR (MMC)
400 // This command only valid for MMC and eMMC
401 Timeout
= MAX_RETRY_COUNT
;
403 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD1
, EMMC_CMD1_CAPACITY_GREATER_THAN_2GB
);
404 if (EFI_ERROR (Status
))
406 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_OCR
, (UINT32
*)&OcrResponse
);
407 if (EFI_ERROR (Status
)) {
408 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status
));
412 } while (!OcrResponse
.Ocr
.PowerUp
&& (Timeout
> 0));
413 if (Status
== EFI_SUCCESS
) {
414 if (!OcrResponse
.Ocr
.PowerUp
) {
415 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode(MMC_CMD1): Card initialisation failure, Status=%r.\n", Status
));
416 return EFI_DEVICE_ERROR
;
418 OcrResponse
.Ocr
.PowerUp
= 0;
419 if (OcrResponse
.Raw
== EMMC_CMD1_CAPACITY_GREATER_THAN_2GB
) {
420 MmcHostInstance
->CardInfo
.OCRData
.AccessMode
= BIT1
;
423 MmcHostInstance
->CardInfo
.OCRData
.AccessMode
= 0x0;
425 // Check whether MMC or eMMC
426 if (OcrResponse
.Raw
== EMMC_CMD1_CAPACITY_GREATER_THAN_2GB
||
427 OcrResponse
.Raw
== EMMC_CMD1_CAPACITY_LESS_THAN_2GB
) {
428 return EmmcIdentificationMode (MmcHostInstance
, OcrResponse
);
432 // Are we using SDIO ?
433 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD5
, 0);
434 if (Status
== EFI_SUCCESS
) {
435 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode(MMC_CMD5): Error - SDIO not supported, Status=%r.\n", Status
));
436 return EFI_UNSUPPORTED
;
439 // Check which kind of card we are using. Ver2.00 or later SD Memory Card (PL180 is SD v1.1)
440 CmdArg
= (0x0UL
<< 12 | BIT8
| 0xCEUL
<< 0);
441 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD8
, CmdArg
);
442 if (Status
== EFI_SUCCESS
) {
443 DEBUG ((EFI_D_ERROR
, "Card is SD2.0 => Supports high capacity\n"));
445 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_R7
, Response
);
446 if (EFI_ERROR (Status
)) {
447 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Failed to receive response to CMD8, Status=%r.\n", Status
));
450 PrintResponseR1 (Response
[0]);
451 // Check if it is valid response
452 if (Response
[0] != CmdArg
) {
453 DEBUG ((EFI_D_ERROR
, "The Card is not usable\n"));
454 return EFI_UNSUPPORTED
;
457 DEBUG ((EFI_D_ERROR
, "Not a SD2.0 Card\n"));
460 // We need to wait for the MMC or SD card is ready => (gCardInfo.OCRData.PowerUp == 1)
461 Timeout
= MAX_RETRY_COUNT
;
462 while (Timeout
> 0) {
463 // SD Card or MMC Card ? CMD55 indicates to the card that the next command is an application specific command
464 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD55
, 0);
465 if (Status
== EFI_SUCCESS
) {
466 DEBUG ((EFI_D_INFO
, "Card should be SD\n"));
468 MmcHostInstance
->CardInfo
.CardType
= SD_CARD_2
;
470 MmcHostInstance
->CardInfo
.CardType
= SD_CARD
;
473 // Note: The first time CmdArg will be zero
474 CmdArg
= ((UINTN
*) &(MmcHostInstance
->CardInfo
.OCRData
))[0];
478 Status
= MmcHost
->SendCommand (MmcHost
, MMC_ACMD41
, CmdArg
);
479 if (!EFI_ERROR (Status
)) {
480 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_OCR
, Response
);
481 if (EFI_ERROR (Status
)) {
482 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status
));
485 ((UINT32
*) &(MmcHostInstance
->CardInfo
.OCRData
))[0] = Response
[0];
488 DEBUG ((EFI_D_INFO
, "Card should be MMC\n"));
489 MmcHostInstance
->CardInfo
.CardType
= MMC_CARD
;
491 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD1
, 0x800000);
492 if (!EFI_ERROR (Status
)) {
493 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_OCR
, Response
);
494 if (EFI_ERROR (Status
)) {
495 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Failed to receive OCR, Status=%r.\n", Status
));
498 ((UINT32
*) &(MmcHostInstance
->CardInfo
.OCRData
))[0] = Response
[0];
502 if (!EFI_ERROR (Status
)) {
503 if (!MmcHostInstance
->CardInfo
.OCRData
.PowerUp
) {
507 if ((MmcHostInstance
->CardInfo
.CardType
== SD_CARD_2
) && (MmcHostInstance
->CardInfo
.OCRData
.AccessMode
& BIT1
)) {
508 MmcHostInstance
->CardInfo
.CardType
= SD_CARD_2_HIGH
;
509 DEBUG ((EFI_D_ERROR
, "High capacity card.\n"));
511 break; // The MMC/SD card is ready. Continue the Identification Mode
520 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode(): No Card\n"));
523 PrintOCR (Response
[0]);
526 Status
= MmcNotifyState (MmcHostInstance
, MmcReadyState
);
527 if (EFI_ERROR (Status
)) {
528 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Error MmcReadyState\n"));
532 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD2
, 0);
533 if (EFI_ERROR (Status
)) {
534 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode(MMC_CMD2): Error\n"));
537 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_CID
, Response
);
538 if (EFI_ERROR (Status
)) {
539 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Failed to receive CID, Status=%r.\n", Status
));
545 Status
= MmcHost
->NotifyState (MmcHost
, MmcIdentificationState
);
546 if (EFI_ERROR (Status
)) {
547 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Error MmcIdentificationState\n"));
552 // Note, SD specifications say that "if the command execution causes a state change, it
553 // will be visible to the host in the response to the next command"
554 // The status returned for this CMD3 will be 2 - identification
557 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD3
, CmdArg
);
558 if (EFI_ERROR (Status
)) {
559 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode(MMC_CMD3): Error\n"));
563 Status
= MmcHost
->ReceiveResponse (MmcHost
, MMC_RESPONSE_TYPE_RCA
, Response
);
564 if (EFI_ERROR (Status
)) {
565 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Failed to receive RCA, Status=%r.\n", Status
));
568 PrintRCA (Response
[0]);
570 // For MMC card, RCA is assigned by CMD3 while CMD3 dumps the RCA for SD card
571 if (MmcHostInstance
->CardInfo
.CardType
!= MMC_CARD
) {
572 MmcHostInstance
->CardInfo
.RCA
= Response
[0] >> 16;
574 MmcHostInstance
->CardInfo
.RCA
= CmdArg
;
576 Status
= MmcNotifyState (MmcHostInstance
, MmcStandByState
);
577 if (EFI_ERROR (Status
)) {
578 DEBUG ((EFI_D_ERROR
, "MmcIdentificationMode() : Error MmcStandByState\n"));
586 InitializeMmcDevice (
587 IN MMC_HOST_INSTANCE
*MmcHostInstance
591 EFI_MMC_HOST_PROTOCOL
*MmcHost
;
595 MmcHost
= MmcHostInstance
->MmcHost
;
597 Status
= MmcIdentificationMode (MmcHostInstance
);
598 if (EFI_ERROR (Status
)) {
599 DEBUG((EFI_D_ERROR
, "InitializeMmcDevice(): Error in Identification Mode, Status=%r\n", Status
));
603 Status
= MmcNotifyState (MmcHostInstance
, MmcTransferState
);
604 if (EFI_ERROR (Status
)) {
605 DEBUG((EFI_D_ERROR
, "InitializeMmcDevice(): Error MmcTransferState, Status=%r\n", Status
));
609 if (MmcHostInstance
->CardInfo
.CardType
!= EMMC_CARD
) {
610 Status
= InitializeSdMmcDevice (MmcHostInstance
);
612 Status
= InitializeEmmcDevice (MmcHostInstance
);
614 if (EFI_ERROR (Status
)) {
619 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD16
, MmcHostInstance
->BlockIo
.Media
->BlockSize
);
620 if (EFI_ERROR (Status
)) {
621 DEBUG((EFI_D_ERROR
, "InitializeMmcDevice(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n",
622 MmcHostInstance
->BlockIo
.Media
->BlockSize
, Status
));
626 // Block Count (not used). Could return an error for SD card
627 if (MmcHostInstance
->CardInfo
.CardType
== MMC_CARD
) {
628 Status
= MmcHost
->SendCommand (MmcHost
, MMC_CMD23
, BlockCount
);
629 if (EFI_ERROR (Status
)) {
630 DEBUG((EFI_D_ERROR
, "InitializeMmcDevice(MMC_CMD23): Error, Status=%r\n", Status
));