2 This file provides some helper functions which are specific for EMMC device.
4 Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
5 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "SdMmcPciHcDxe.h"
13 Send command GO_IDLE_STATE (CMD0 with argument of 0x00000000) to the device to
14 make it go to Idle State.
16 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
18 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
19 @param[in] Slot The slot number of the SD card to send the command to.
21 @retval EFI_SUCCESS The EMMC device is reset correctly.
22 @retval Others The device reset fails.
27 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
31 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
32 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
33 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
36 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
37 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
38 ZeroMem (&Packet
, sizeof (Packet
));
40 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
41 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
42 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
44 SdMmcCmdBlk
.CommandIndex
= EMMC_GO_IDLE_STATE
;
45 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeBc
;
46 SdMmcCmdBlk
.ResponseType
= 0;
47 SdMmcCmdBlk
.CommandArgument
= 0;
51 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
57 Send command SEND_OP_COND to the EMMC device to get the data of the OCR register.
59 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
61 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
62 @param[in] Slot The slot number of the SD card to send the command to.
63 @param[in, out] Argument On input, the argument of SEND_OP_COND is to send to the device.
64 On output, the argument is the value of OCR register.
66 @retval EFI_SUCCESS The operation is done correctly.
67 @retval Others The operation fails.
72 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
74 IN OUT UINT32
*Argument
77 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
78 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
79 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
82 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
83 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
84 ZeroMem (&Packet
, sizeof (Packet
));
86 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
87 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
88 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
90 SdMmcCmdBlk
.CommandIndex
= EMMC_SEND_OP_COND
;
91 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeBcr
;
92 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR3
;
93 SdMmcCmdBlk
.CommandArgument
= *Argument
;
95 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
96 if (!EFI_ERROR (Status
)) {
98 // For details, refer to SD Host Controller Simplified Spec 3.0 Table 2-12.
100 *Argument
= SdMmcStatusBlk
.Resp0
;
107 Broadcast command ALL_SEND_CID to the bus to ask all the EMMC devices to send the
108 data of their CID registers.
110 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
112 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
113 @param[in] Slot The slot number of the SD card to send the command to.
115 @retval EFI_SUCCESS The operation is done correctly.
116 @retval Others The operation fails.
121 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
125 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
126 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
127 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
130 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
131 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
132 ZeroMem (&Packet
, sizeof (Packet
));
134 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
135 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
136 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
138 SdMmcCmdBlk
.CommandIndex
= EMMC_ALL_SEND_CID
;
139 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeBcr
;
140 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR2
;
141 SdMmcCmdBlk
.CommandArgument
= 0;
143 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
149 Send command SET_RELATIVE_ADDR to the EMMC device to assign a Relative device
152 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
154 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
155 @param[in] Slot The slot number of the SD card to send the command to.
156 @param[in] Rca The relative device address to be assigned.
158 @retval EFI_SUCCESS The operation is done correctly.
159 @retval Others The operation fails.
164 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
169 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
170 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
171 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
174 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
175 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
176 ZeroMem (&Packet
, sizeof (Packet
));
178 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
179 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
180 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
182 SdMmcCmdBlk
.CommandIndex
= EMMC_SET_RELATIVE_ADDR
;
183 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAc
;
184 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR1
;
185 SdMmcCmdBlk
.CommandArgument
= (UINT32
)Rca
<< 16;
187 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
193 Send command SEND_CSD to the EMMC device to get the data of the CSD register.
195 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
197 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
198 @param[in] Slot The slot number of the SD card to send the command to.
199 @param[in] Rca The relative device address of selected device.
200 @param[out] Csd The buffer to store the content of the CSD register.
201 Note the caller should ignore the lowest byte of this
202 buffer as the content of this byte is meaningless even
203 if the operation succeeds.
205 @retval EFI_SUCCESS The operation is done correctly.
206 @retval Others The operation fails.
211 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
217 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
218 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
219 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
222 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
223 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
224 ZeroMem (&Packet
, sizeof (Packet
));
226 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
227 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
228 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
230 SdMmcCmdBlk
.CommandIndex
= EMMC_SEND_CSD
;
231 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAc
;
232 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR2
;
233 SdMmcCmdBlk
.CommandArgument
= (UINT32
)Rca
<< 16;
235 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
236 if (!EFI_ERROR (Status
)) {
238 // For details, refer to SD Host Controller Simplified Spec 3.0 Table 2-12.
240 CopyMem (((UINT8
*)Csd
) + 1, &SdMmcStatusBlk
.Resp0
, sizeof (EMMC_CSD
) - 1);
247 Send command SELECT_DESELECT_CARD to the EMMC device to select/deselect it.
249 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
251 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
252 @param[in] Slot The slot number of the SD card to send the command to.
253 @param[in] Rca The relative device address of selected device.
255 @retval EFI_SUCCESS The operation is done correctly.
256 @retval Others The operation fails.
261 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
266 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
267 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
268 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
271 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
272 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
273 ZeroMem (&Packet
, sizeof (Packet
));
275 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
276 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
277 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
279 SdMmcCmdBlk
.CommandIndex
= EMMC_SELECT_DESELECT_CARD
;
280 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAc
;
281 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR1
;
282 SdMmcCmdBlk
.CommandArgument
= (UINT32
)Rca
<< 16;
284 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
290 Send command SEND_EXT_CSD to the EMMC device to get the data of the EXT_CSD register.
292 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
294 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
295 @param[in] Slot The slot number of the SD card to send the command to.
296 @param[out] ExtCsd The buffer to store the content of the EXT_CSD register.
298 @retval EFI_SUCCESS The operation is done correctly.
299 @retval Others The operation fails.
304 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
306 OUT EMMC_EXT_CSD
*ExtCsd
309 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
310 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
311 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
314 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
315 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
316 ZeroMem (&Packet
, sizeof (Packet
));
318 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
319 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
320 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
322 SdMmcCmdBlk
.CommandIndex
= EMMC_SEND_EXT_CSD
;
323 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAdtc
;
324 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR1
;
325 SdMmcCmdBlk
.CommandArgument
= 0x00000000;
327 Packet
.InDataBuffer
= ExtCsd
;
328 Packet
.InTransferLength
= sizeof (EMMC_EXT_CSD
);
330 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
335 Send command SWITCH to the EMMC device to switch the mode of operation of the
336 selected Device or modifies the EXT_CSD registers.
338 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
340 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
341 @param[in] Slot The slot number of the SD card to send the command to.
342 @param[in] Access The access mode of SWTICH command.
343 @param[in] Index The offset of the field to be access.
344 @param[in] Value The value to be set to the specified field of EXT_CSD register.
345 @param[in] CmdSet The value of CmdSet field of EXT_CSD register.
347 @retval EFI_SUCCESS The operation is done correctly.
348 @retval Others The operation fails.
353 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
361 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
362 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
363 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
366 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
367 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
368 ZeroMem (&Packet
, sizeof (Packet
));
370 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
371 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
372 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
374 SdMmcCmdBlk
.CommandIndex
= EMMC_SWITCH
;
375 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAc
;
376 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR1b
;
377 SdMmcCmdBlk
.CommandArgument
= (Access
<< 24) | (Index
<< 16) | (Value
<< 8) | CmdSet
;
379 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
385 Send command SEND_STATUS to the addressed EMMC device to get its status register.
387 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
389 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
390 @param[in] Slot The slot number of the SD card to send the command to.
391 @param[in] Rca The relative device address of addressed device.
392 @param[out] DevStatus The returned device status.
394 @retval EFI_SUCCESS The operation is done correctly.
395 @retval Others The operation fails.
400 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
403 OUT UINT32
*DevStatus
406 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
407 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
408 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
411 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
412 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
413 ZeroMem (&Packet
, sizeof (Packet
));
415 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
416 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
417 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
419 SdMmcCmdBlk
.CommandIndex
= EMMC_SEND_STATUS
;
420 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAc
;
421 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR1
;
422 SdMmcCmdBlk
.CommandArgument
= (UINT32
)Rca
<< 16;
424 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
425 if (!EFI_ERROR (Status
)) {
426 *DevStatus
= SdMmcStatusBlk
.Resp0
;
433 Send command SEND_TUNING_BLOCK to the EMMC device for HS200 optimal sampling point
436 It may be sent up to 40 times until the host finishes the tuning procedure.
438 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 for details.
440 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
441 @param[in] Slot The slot number of the SD card to send the command to.
442 @param[in] BusWidth The bus width to work.
444 @retval EFI_SUCCESS The operation is done correctly.
445 @retval Others The operation fails.
450 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
455 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk
;
456 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk
;
457 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet
;
459 UINT8 TuningBlock
[128];
461 ZeroMem (&SdMmcCmdBlk
, sizeof (SdMmcCmdBlk
));
462 ZeroMem (&SdMmcStatusBlk
, sizeof (SdMmcStatusBlk
));
463 ZeroMem (&Packet
, sizeof (Packet
));
465 Packet
.SdMmcCmdBlk
= &SdMmcCmdBlk
;
466 Packet
.SdMmcStatusBlk
= &SdMmcStatusBlk
;
467 Packet
.Timeout
= SD_MMC_HC_GENERIC_TIMEOUT
;
469 SdMmcCmdBlk
.CommandIndex
= EMMC_SEND_TUNING_BLOCK
;
470 SdMmcCmdBlk
.CommandType
= SdMmcCommandTypeAdtc
;
471 SdMmcCmdBlk
.ResponseType
= SdMmcResponseTypeR1
;
472 SdMmcCmdBlk
.CommandArgument
= 0;
474 Packet
.InDataBuffer
= TuningBlock
;
476 Packet
.InTransferLength
= sizeof (TuningBlock
);
478 Packet
.InTransferLength
= 64;
481 Status
= SdMmcPassThruPassThru (PassThru
, Slot
, &Packet
, NULL
);
487 Tunning the clock to get HS200 optimal sampling point.
489 Command SEND_TUNING_BLOCK may be sent up to 40 times until the host finishes the
492 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
493 Simplified Spec 3.0 Figure 2-29 for details.
495 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
496 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
497 @param[in] Slot The slot number of the SD card to send the command to.
498 @param[in] BusWidth The bus width to work.
500 @retval EFI_SUCCESS The operation is done correctly.
501 @retval Others The operation fails.
505 EmmcTuningClkForHs200 (
506 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
507 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
517 // Notify the host that the sampling clock tuning procedure starts.
520 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
521 if (EFI_ERROR (Status
)) {
525 // Ask the device to send a sequence of tuning blocks till the tuning procedure is done.
529 Status
= EmmcSendTuningBlk (PassThru
, Slot
, BusWidth
);
530 if (EFI_ERROR (Status
)) {
531 DEBUG ((DEBUG_ERROR
, "EmmcTuningClkForHs200: Send tuning block fails with %r\n", Status
));
535 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, TRUE
, sizeof (HostCtrl2
), &HostCtrl2
);
536 if (EFI_ERROR (Status
)) {
540 if ((HostCtrl2
& (BIT6
| BIT7
)) == 0) {
544 if ((HostCtrl2
& (BIT6
| BIT7
)) == BIT7
) {
547 } while (++Retry
< 40);
549 DEBUG ((DEBUG_ERROR
, "EmmcTuningClkForHs200: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry
, HostCtrl2
));
551 // Abort the tuning procedure and reset the tuning circuit.
553 HostCtrl2
= (UINT8
)~(BIT6
| BIT7
);
554 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
555 if (EFI_ERROR (Status
)) {
558 return EFI_DEVICE_ERROR
;
562 Switch the bus width to specified width.
564 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.9 and SD Host Controller
565 Simplified Spec 3.0 Figure 3-7 for details.
567 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
568 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
569 @param[in] Slot The slot number of the SD card to send the command to.
570 @param[in] Rca The relative device address to be assigned.
571 @param[in] IsDdr If TRUE, use dual data rate data simpling method. Otherwise
572 use single data rate data simpling method.
573 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
575 @retval EFI_SUCCESS The operation is done correctly.
576 @retval Others The operation fails.
581 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
582 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
597 // Write Byte, the Value field is written into the byte pointed by Index.
600 Index
= OFFSET_OF (EMMC_EXT_CSD
, BusWidth
);
603 } else if (BusWidth
== 8) {
606 return EFI_INVALID_PARAMETER
;
614 Status
= EmmcSwitch (PassThru
, Slot
, Access
, Index
, Value
, CmdSet
);
615 if (EFI_ERROR (Status
)) {
616 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusWidth: Switch to bus width %d fails with %r\n", BusWidth
, Status
));
620 Status
= EmmcSendStatus (PassThru
, Slot
, Rca
, &DevStatus
);
621 if (EFI_ERROR (Status
)) {
622 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusWidth: Send status fails with %r\n", Status
));
626 // Check the switch operation is really successful or not.
628 if ((DevStatus
& BIT7
) != 0) {
629 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusWidth: The switch operation fails as DevStatus is 0x%08x\n", DevStatus
));
630 return EFI_DEVICE_ERROR
;
633 Status
= SdMmcHcSetBusWidth (PciIo
, Slot
, BusWidth
);
639 Switch the bus timing and clock frequency.
641 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6 and SD Host Controller
642 Simplified Spec 3.0 Figure 3-3 for details.
644 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
645 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
646 @param[in] Slot The slot number of the SD card to send the command to.
647 @param[in] Rca The relative device address to be assigned.
648 @param[in] DriverStrength Driver strength to set for speed modes that support it.
649 @param[in] BusTiming The bus mode timing indicator.
650 @param[in] ClockFreq The max clock frequency to be set, the unit is MHz.
652 @retval EFI_SUCCESS The operation is done correctly.
653 @retval Others The operation fails.
657 EmmcSwitchBusTiming (
658 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
659 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
662 IN EDKII_SD_MMC_DRIVER_STRENGTH DriverStrength
,
663 IN SD_MMC_BUS_MODE BusTiming
,
673 SD_MMC_HC_PRIVATE_DATA
*Private
;
675 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
677 // Write Byte, the Value field is written into the byte pointed by Index.
680 Index
= OFFSET_OF (EMMC_EXT_CSD
, HsTiming
);
684 Value
= (UINT8
)((DriverStrength
.Emmc
<< 4) | 3);
687 Value
= (UINT8
)((DriverStrength
.Emmc
<< 4) | 2);
697 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusTiming: Unsupported BusTiming(%d\n)", BusTiming
));
698 return EFI_INVALID_PARAMETER
;
701 Status
= EmmcSwitch (PassThru
, Slot
, Access
, Index
, Value
, CmdSet
);
702 if (EFI_ERROR (Status
)) {
703 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusTiming: Switch to bus timing %d fails with %r\n", BusTiming
, Status
));
708 // Convert the clock freq unit from MHz to KHz.
710 Status
= SdMmcHcClockSupply (PciIo
, Slot
, ClockFreq
* 1000, Private
->BaseClkFreq
[Slot
], Private
->ControllerVersion
[Slot
]);
711 if (EFI_ERROR (Status
)) {
715 Status
= EmmcSendStatus (PassThru
, Slot
, Rca
, &DevStatus
);
716 if (EFI_ERROR (Status
)) {
717 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusTiming: Send status fails with %r\n", Status
));
721 // Check the switch operation is really successful or not.
723 if ((DevStatus
& BIT7
) != 0) {
724 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusTiming: The switch operation fails as DevStatus is 0x%08x\n", DevStatus
));
725 return EFI_DEVICE_ERROR
;
728 if (mOverride
!= NULL
&& mOverride
->NotifyPhase
!= NULL
) {
729 Status
= mOverride
->NotifyPhase (
730 Private
->ControllerHandle
,
732 EdkiiSdMmcSwitchClockFreqPost
,
735 if (EFI_ERROR (Status
)) {
738 "%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
750 Switch to the High Speed timing according to request.
752 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
753 Simplified Spec 3.0 Figure 2-29 for details.
755 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
756 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
757 @param[in] Slot The slot number of the SD card to send the command to.
758 @param[in] Rca The relative device address to be assigned.
759 @param[in] BusMode Pointer to SD_MMC_BUS_SETTINGS structure containing bus settings.
761 @retval EFI_SUCCESS The operation is done correctly.
762 @retval Others The operation fails.
766 EmmcSwitchToHighSpeed (
767 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
768 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
771 IN SD_MMC_BUS_SETTINGS
*BusMode
776 SD_MMC_HC_PRIVATE_DATA
*Private
;
779 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
781 if ((BusMode
->BusTiming
!= SdMmcMmcHsSdr
&& BusMode
->BusTiming
!= SdMmcMmcHsDdr
) ||
782 BusMode
->ClockFreq
> 52) {
783 return EFI_INVALID_PARAMETER
;
786 if (BusMode
->BusTiming
== SdMmcMmcHsDdr
) {
792 Status
= EmmcSwitchBusWidth (PciIo
, PassThru
, Slot
, Rca
, IsDdr
, BusMode
->BusWidth
);
793 if (EFI_ERROR (Status
)) {
798 // Set to High Speed timing
801 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
802 if (EFI_ERROR (Status
)) {
806 Status
= SdMmcHcUhsSignaling (Private
->ControllerHandle
, PciIo
, Slot
, BusMode
->BusTiming
);
807 if (EFI_ERROR (Status
)) {
811 return EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, BusMode
->BusTiming
, BusMode
->ClockFreq
);
815 Switch to the HS200 timing. This function assumes that eMMC bus is still in legacy mode.
817 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
818 Simplified Spec 3.0 Figure 2-29 for details.
820 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
821 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
822 @param[in] Slot The slot number of the SD card to send the command to.
823 @param[in] Rca The relative device address to be assigned.
824 @param[in] BusMode Pointer to SD_MMC_BUS_SETTINGS structure containing bus settings.
826 @retval EFI_SUCCESS The operation is done correctly.
827 @retval Others The operation fails.
832 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
833 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
836 IN SD_MMC_BUS_SETTINGS
*BusMode
840 SD_MMC_HC_PRIVATE_DATA
*Private
;
842 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
844 if (BusMode
->BusTiming
!= SdMmcMmcHs200
||
845 (BusMode
->BusWidth
!= 4 && BusMode
->BusWidth
!= 8)) {
846 return EFI_INVALID_PARAMETER
;
849 Status
= EmmcSwitchBusWidth (PciIo
, PassThru
, Slot
, Rca
, FALSE
, BusMode
->BusWidth
);
850 if (EFI_ERROR (Status
)) {
854 Status
= SdMmcHcUhsSignaling (Private
->ControllerHandle
, PciIo
, Slot
, BusMode
->BusTiming
);
855 if (EFI_ERROR (Status
)) {
859 Status
= EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, BusMode
->BusTiming
, BusMode
->ClockFreq
);
860 if (EFI_ERROR (Status
)) {
864 Status
= EmmcTuningClkForHs200 (PciIo
, PassThru
, Slot
, BusMode
->BusWidth
);
870 Switch to the HS400 timing. This function assumes that eMMC bus is still in legacy mode.
872 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
873 Simplified Spec 3.0 Figure 2-29 for details.
875 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
876 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
877 @param[in] Slot The slot number of the SD card to send the command to.
878 @param[in] Rca The relative device address to be assigned.
879 @param[in] BusMode Pointer to SD_MMC_BUS_SETTINGS structure containing bus settings.
881 @retval EFI_SUCCESS The operation is done correctly.
882 @retval Others The operation fails.
887 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
888 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
891 IN SD_MMC_BUS_SETTINGS
*BusMode
895 SD_MMC_HC_PRIVATE_DATA
*Private
;
896 SD_MMC_BUS_SETTINGS Hs200BusMode
;
899 if (BusMode
->BusTiming
!= SdMmcMmcHs400
||
900 BusMode
->BusWidth
!= 8) {
901 return EFI_INVALID_PARAMETER
;
904 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
905 Hs200BusMode
.BusTiming
= SdMmcMmcHs200
;
906 Hs200BusMode
.BusWidth
= BusMode
->BusWidth
;
907 Hs200BusMode
.ClockFreq
= BusMode
->ClockFreq
;
908 Hs200BusMode
.DriverStrength
= BusMode
->DriverStrength
;
910 Status
= EmmcSwitchToHS200 (PciIo
, PassThru
, Slot
, Rca
, &Hs200BusMode
);
911 if (EFI_ERROR (Status
)) {
916 // Set to High Speed timing and set the clock frequency to a value less than or equal to 52MHz.
917 // This step is necessary to be able to switch Bus into 8 bit DDR mode which is unsupported in HS200.
919 Status
= SdMmcHcUhsSignaling (Private
->ControllerHandle
, PciIo
, Slot
, SdMmcMmcHsSdr
);
920 if (EFI_ERROR (Status
)) {
924 HsFreq
= BusMode
->ClockFreq
< 52 ? BusMode
->ClockFreq
: 52;
925 Status
= EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, SdMmcMmcHsSdr
, HsFreq
);
926 if (EFI_ERROR (Status
)) {
930 Status
= EmmcSwitchBusWidth (PciIo
, PassThru
, Slot
, Rca
, TRUE
, BusMode
->BusWidth
);
931 if (EFI_ERROR (Status
)) {
935 Status
= SdMmcHcUhsSignaling (Private
->ControllerHandle
, PciIo
, Slot
, BusMode
->BusTiming
);
936 if (EFI_ERROR (Status
)) {
940 return EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, BusMode
->BusTiming
, BusMode
->ClockFreq
);
944 Check if passed BusTiming is supported in both controller and card.
946 @param[in] Private Pointer to controller private data
947 @param[in] SlotIndex Index of the slot in the controller
948 @param[in] ExtCsd Pointer to the card's extended CSD
949 @param[in] BusTiming Bus timing to check
951 @retval TRUE Both card and controller support given BusTiming
952 @retval FALSE Card or controller doesn't support given BusTiming
955 EmmcIsBusTimingSupported (
956 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
958 IN EMMC_EXT_CSD
*ExtCsd
,
959 IN SD_MMC_BUS_MODE BusTiming
963 SD_MMC_HC_SLOT_CAP
*Capabilities
;
965 Capabilities
= &Private
->Capability
[SlotIndex
];
970 if ((((ExtCsd
->DeviceType
& (BIT6
| BIT7
)) != 0) && (Capabilities
->Hs400
!= 0)) && Capabilities
->BusWidth8
!= 0) {
975 if ((((ExtCsd
->DeviceType
& (BIT4
| BIT5
)) != 0) && (Capabilities
->Sdr104
!= 0))) {
980 if ((((ExtCsd
->DeviceType
& (BIT2
| BIT3
)) != 0) && (Capabilities
->Ddr50
!= 0))) {
985 if ((((ExtCsd
->DeviceType
& BIT1
) != 0) && (Capabilities
->HighSpeed
!= 0))) {
990 if ((ExtCsd
->DeviceType
& BIT0
) != 0) {
1002 Get the target bus timing to set on the link. This function
1003 will try to select highest bus timing supported by card, controller
1006 @param[in] Private Pointer to controller private data
1007 @param[in] SlotIndex Index of the slot in the controller
1008 @param[in] ExtCsd Pointer to the card's extended CSD
1010 @return Bus timing value that should be set on link
1013 EmmcGetTargetBusTiming (
1014 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1016 IN EMMC_EXT_CSD
*ExtCsd
1019 SD_MMC_BUS_MODE BusTiming
;
1022 // We start with highest bus timing that this driver currently supports and
1023 // return as soon as we find supported timing.
1025 BusTiming
= SdMmcMmcHs400
;
1026 while (BusTiming
> SdMmcMmcLegacy
) {
1027 if (EmmcIsBusTimingSupported (Private
, SlotIndex
, ExtCsd
, BusTiming
)) {
1037 Check if the passed bus width is supported by controller and card.
1039 @param[in] Private Pointer to controller private data
1040 @param[in] SlotIndex Index of the slot in the controller
1041 @param[in] BusTiming Bus timing set on the link
1042 @param[in] BusWidth Bus width to check
1044 @retval TRUE Passed bus width is supported in current bus configuration
1045 @retval FALSE Passed bus width is not supported in current bus configuration
1048 EmmcIsBusWidthSupported (
1049 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1051 IN SD_MMC_BUS_MODE BusTiming
,
1055 if (BusWidth
== 8 && Private
->Capability
[SlotIndex
].BusWidth8
!= 0) {
1057 } else if (BusWidth
== 4 && BusTiming
!= SdMmcMmcHs400
) {
1059 } else if (BusWidth
== 1 && (BusTiming
== SdMmcMmcHsSdr
|| BusTiming
== SdMmcMmcLegacy
)) {
1067 Get the target bus width to be set on the bus.
1069 @param[in] Private Pointer to controller private data
1070 @param[in] SlotIndex Index of the slot in the controller
1071 @param[in] ExtCsd Pointer to card's extended CSD
1072 @param[in] BusTiming Bus timing set on the bus
1074 @return Bus width to be set on the bus
1077 EmmcGetTargetBusWidth (
1078 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1080 IN EMMC_EXT_CSD
*ExtCsd
,
1081 IN SD_MMC_BUS_MODE BusTiming
1085 UINT8 PreferredBusWidth
;
1087 PreferredBusWidth
= Private
->Slot
[SlotIndex
].OperatingParameters
.BusWidth
;
1089 if (PreferredBusWidth
!= EDKII_SD_MMC_BUS_WIDTH_IGNORE
&&
1090 EmmcIsBusWidthSupported (Private
, SlotIndex
, BusTiming
, PreferredBusWidth
)) {
1091 BusWidth
= PreferredBusWidth
;
1092 } else if (EmmcIsBusWidthSupported (Private
, SlotIndex
, BusTiming
, 8)) {
1094 } else if (EmmcIsBusWidthSupported (Private
, SlotIndex
, BusTiming
, 4)) {
1104 Get the target clock frequency to be set on the bus.
1106 @param[in] Private Pointer to controller private data
1107 @param[in] SlotIndex Index of the slot in the controller
1108 @param[in] ExtCsd Pointer to card's extended CSD
1109 @param[in] BusTiming Bus timing to be set on the bus
1111 @return Value of the clock frequency to be set on bus in MHz
1114 EmmcGetTargetClockFreq (
1115 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1117 IN EMMC_EXT_CSD
*ExtCsd
,
1118 IN SD_MMC_BUS_MODE BusTiming
1121 UINT32 PreferredClockFreq
;
1122 UINT32 MaxClockFreq
;
1124 PreferredClockFreq
= Private
->Slot
[SlotIndex
].OperatingParameters
.ClockFreq
;
1126 switch (BusTiming
) {
1140 if (PreferredClockFreq
!= EDKII_SD_MMC_CLOCK_FREQ_IGNORE
&& PreferredClockFreq
< MaxClockFreq
) {
1141 return PreferredClockFreq
;
1143 return MaxClockFreq
;
1148 Get the driver strength to be set on bus.
1150 @param[in] Private Pointer to controller private data
1151 @param[in] SlotIndex Index of the slot in the controller
1152 @param[in] ExtCsd Pointer to card's extended CSD
1153 @param[in] BusTiming Bus timing set on the bus
1155 @return Value of the driver strength to be set on the bus
1157 EDKII_SD_MMC_DRIVER_STRENGTH
1158 EmmcGetTargetDriverStrength (
1159 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1161 IN EMMC_EXT_CSD
*ExtCsd
,
1162 IN SD_MMC_BUS_MODE BusTiming
1165 EDKII_SD_MMC_DRIVER_STRENGTH PreferredDriverStrength
;
1166 EDKII_SD_MMC_DRIVER_STRENGTH DriverStrength
;
1168 PreferredDriverStrength
= Private
->Slot
[SlotIndex
].OperatingParameters
.DriverStrength
;
1169 DriverStrength
.Emmc
= EmmcDriverStrengthType0
;
1171 if (PreferredDriverStrength
.Emmc
!= EDKII_SD_MMC_DRIVER_STRENGTH_IGNORE
&&
1172 (ExtCsd
->DriverStrength
& (BIT0
<< PreferredDriverStrength
.Emmc
))) {
1173 DriverStrength
.Emmc
= PreferredDriverStrength
.Emmc
;
1176 return DriverStrength
;
1180 Get the target settings for the bus mode.
1182 @param[in] Private Pointer to controller private data
1183 @param[in] SlotIndex Index of the slot in the controller
1184 @param[in] ExtCsd Pointer to card's extended CSD
1185 @param[out] BusMode Target configuration of the bus
1188 EmmcGetTargetBusMode (
1189 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1191 IN EMMC_EXT_CSD
*ExtCsd
,
1192 OUT SD_MMC_BUS_SETTINGS
*BusMode
1195 BusMode
->BusTiming
= EmmcGetTargetBusTiming (Private
, SlotIndex
, ExtCsd
);
1196 BusMode
->BusWidth
= EmmcGetTargetBusWidth (Private
, SlotIndex
, ExtCsd
, BusMode
->BusTiming
);
1197 BusMode
->ClockFreq
= EmmcGetTargetClockFreq (Private
, SlotIndex
, ExtCsd
, BusMode
->BusTiming
);
1198 BusMode
->DriverStrength
= EmmcGetTargetDriverStrength (Private
, SlotIndex
, ExtCsd
, BusMode
->BusTiming
);
1202 Switch the high speed timing according to request.
1204 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
1205 Simplified Spec 3.0 Figure 2-29 for details.
1207 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
1208 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
1209 @param[in] Slot The slot number of the SD card to send the command to.
1210 @param[in] Rca The relative device address to be assigned.
1212 @retval EFI_SUCCESS The operation is done correctly.
1213 @retval Others The operation fails.
1218 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1219 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
1226 EMMC_EXT_CSD ExtCsd
;
1227 SD_MMC_BUS_SETTINGS BusMode
;
1228 SD_MMC_HC_PRIVATE_DATA
*Private
;
1230 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
1232 Status
= EmmcGetCsd (PassThru
, Slot
, Rca
, &Csd
);
1233 if (EFI_ERROR (Status
)) {
1234 DEBUG ((DEBUG_ERROR
, "EmmcSetBusMode: GetCsd fails with %r\n", Status
));
1238 Status
= EmmcSelect (PassThru
, Slot
, Rca
);
1239 if (EFI_ERROR (Status
)) {
1240 DEBUG ((DEBUG_ERROR
, "EmmcSetBusMode: Select fails with %r\n", Status
));
1244 ASSERT (Private
->BaseClkFreq
[Slot
] != 0);
1247 // Get Device_Type from EXT_CSD register.
1249 Status
= EmmcGetExtCsd (PassThru
, Slot
, &ExtCsd
);
1250 if (EFI_ERROR (Status
)) {
1251 DEBUG ((DEBUG_ERROR
, "EmmcSetBusMode: GetExtCsd fails with %r\n", Status
));
1255 EmmcGetTargetBusMode (Private
, Slot
, &ExtCsd
, &BusMode
);
1257 DEBUG ((DEBUG_INFO
, "EmmcSetBusMode: Target bus mode: timing = %d, width = %d, clock freq = %d, driver strength = %d\n",
1258 BusMode
.BusTiming
, BusMode
.BusWidth
, BusMode
.ClockFreq
, BusMode
.DriverStrength
.Emmc
));
1260 if (BusMode
.BusTiming
== SdMmcMmcHs400
) {
1261 Status
= EmmcSwitchToHS400 (PciIo
, PassThru
, Slot
, Rca
, &BusMode
);
1262 } else if (BusMode
.BusTiming
== SdMmcMmcHs200
) {
1263 Status
= EmmcSwitchToHS200 (PciIo
, PassThru
, Slot
, Rca
, &BusMode
);
1265 Status
= EmmcSwitchToHighSpeed (PciIo
, PassThru
, Slot
, Rca
, &BusMode
);
1268 DEBUG ((DEBUG_INFO
, "EmmcSetBusMode: Switch to %a %r\n", (BusMode
.BusTiming
== SdMmcMmcHs400
) ? "HS400" : ((BusMode
.BusTiming
== SdMmcMmcHs200
) ? "HS200" : "HighSpeed"), Status
));
1274 Execute EMMC device identification procedure.
1276 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
1278 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1279 @param[in] Slot The slot number of the SD card to send the command to.
1281 @retval EFI_SUCCESS There is a EMMC card.
1282 @retval Others There is not a EMMC card.
1286 EmmcIdentification (
1287 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1292 EFI_PCI_IO_PROTOCOL
*PciIo
;
1293 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
1298 PciIo
= Private
->PciIo
;
1299 PassThru
= &Private
->PassThru
;
1301 Status
= EmmcReset (PassThru
, Slot
);
1302 if (EFI_ERROR (Status
)) {
1303 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd0 fails with %r\n", Status
));
1310 Status
= EmmcGetOcr (PassThru
, Slot
, &Ocr
);
1311 if (EFI_ERROR (Status
)) {
1312 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd1 fails with %r\n", Status
));
1317 if (Retry
++ == 100) {
1318 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd1 fails too many times\n"));
1319 return EFI_DEVICE_ERROR
;
1321 gBS
->Stall(10 * 1000);
1322 } while ((Ocr
& BIT31
) == 0);
1324 Status
= EmmcGetAllCid (PassThru
, Slot
);
1325 if (EFI_ERROR (Status
)) {
1326 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd2 fails with %r\n", Status
));
1330 // Slot starts from 0 and valid RCA starts from 1.
1331 // Here we takes a simple formula to calculate the RCA.
1332 // Don't support multiple devices on the slot, that is
1333 // shared bus slot feature.
1336 Status
= EmmcSetRca (PassThru
, Slot
, Rca
);
1337 if (EFI_ERROR (Status
)) {
1338 DEBUG ((DEBUG_ERROR
, "EmmcIdentification: Executing Cmd3 fails with %r\n", Status
));
1342 // Enter Data Tranfer Mode.
1344 DEBUG ((DEBUG_INFO
, "EmmcIdentification: Found a EMMC device at slot [%d], RCA [%d]\n", Slot
, Rca
));
1345 Private
->Slot
[Slot
].CardType
= EmmcCardType
;
1347 Status
= EmmcSetBusMode (PciIo
, PassThru
, Slot
, Rca
);