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
)) {
526 // Ask the device to send a sequence of tuning blocks till the tuning procedure is done.
530 Status
= EmmcSendTuningBlk (PassThru
, Slot
, BusWidth
);
531 if (EFI_ERROR (Status
)) {
532 DEBUG ((DEBUG_ERROR
, "EmmcTuningClkForHs200: Send tuning block fails with %r\n", Status
));
536 Status
= SdMmcHcRwMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, TRUE
, sizeof (HostCtrl2
), &HostCtrl2
);
537 if (EFI_ERROR (Status
)) {
541 if ((HostCtrl2
& (BIT6
| BIT7
)) == 0) {
545 if ((HostCtrl2
& (BIT6
| BIT7
)) == BIT7
) {
548 } while (++Retry
< 40);
550 DEBUG ((DEBUG_ERROR
, "EmmcTuningClkForHs200: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry
, HostCtrl2
));
552 // Abort the tuning procedure and reset the tuning circuit.
554 HostCtrl2
= (UINT8
) ~(BIT6
| BIT7
);
555 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL2
, sizeof (HostCtrl2
), &HostCtrl2
);
556 if (EFI_ERROR (Status
)) {
560 return EFI_DEVICE_ERROR
;
564 Check the SWITCH operation status.
566 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
567 @param[in] Slot The slot number on which command should be sent.
568 @param[in] Rca The relative device address.
570 @retval EFI_SUCCESS The SWITCH finished siccessfully.
571 @retval others The SWITCH failed.
574 EmmcCheckSwitchStatus (
575 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
583 Status
= EmmcSendStatus (PassThru
, Slot
, Rca
, &DevStatus
);
584 if (EFI_ERROR (Status
)) {
585 DEBUG ((DEBUG_ERROR
, "EmmcCheckSwitchStatus: Send status fails with %r\n", Status
));
590 // Check the switch operation is really successful or not.
592 if ((DevStatus
& BIT7
) != 0) {
593 DEBUG ((DEBUG_ERROR
, "EmmcCheckSwitchStatus: The switch operation fails as DevStatus is 0x%08x\n", DevStatus
));
594 return EFI_DEVICE_ERROR
;
601 Switch the bus width to specified width.
603 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.9 and SD Host Controller
604 Simplified Spec 3.0 Figure 3-7 for details.
606 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
607 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
608 @param[in] Slot The slot number of the SD card to send the command to.
609 @param[in] Rca The relative device address to be assigned.
610 @param[in] IsDdr If TRUE, use dual data rate data simpling method. Otherwise
611 use single data rate data simpling method.
612 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
614 @retval EFI_SUCCESS The operation is done correctly.
615 @retval Others The operation fails.
620 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
621 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
635 // Write Byte, the Value field is written into the byte pointed by Index.
638 Index
= OFFSET_OF (EMMC_EXT_CSD
, BusWidth
);
641 } else if (BusWidth
== 8) {
644 return EFI_INVALID_PARAMETER
;
652 Status
= EmmcSwitch (PassThru
, Slot
, Access
, Index
, Value
, CmdSet
);
653 if (EFI_ERROR (Status
)) {
654 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusWidth: Switch to bus width %d fails with %r\n", BusWidth
, Status
));
658 Status
= EmmcCheckSwitchStatus (PassThru
, Slot
, Rca
);
659 if (EFI_ERROR (Status
)) {
663 Status
= SdMmcHcSetBusWidth (PciIo
, Slot
, BusWidth
);
669 Switch the bus timing and clock frequency.
671 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6 and SD Host Controller
672 Simplified Spec 3.0 Figure 3-3 for details.
674 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
675 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
676 @param[in] Slot The slot number of the SD card to send the command to.
677 @param[in] Rca The relative device address to be assigned.
678 @param[in] DriverStrength Driver strength to set for speed modes that support it.
679 @param[in] BusTiming The bus mode timing indicator.
680 @param[in] ClockFreq The max clock frequency to be set, the unit is MHz.
682 @retval EFI_SUCCESS The operation is done correctly.
683 @retval Others The operation fails.
687 EmmcSwitchBusTiming (
688 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
689 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
692 IN EDKII_SD_MMC_DRIVER_STRENGTH DriverStrength
,
693 IN SD_MMC_BUS_MODE BusTiming
,
702 SD_MMC_HC_PRIVATE_DATA
*Private
;
704 BOOLEAN DelaySendStatus
;
706 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
708 // Write Byte, the Value field is written into the byte pointed by Index.
711 Index
= OFFSET_OF (EMMC_EXT_CSD
, HsTiming
);
715 Value
= (UINT8
)((DriverStrength
.Emmc
<< 4) | 3);
718 Value
= (UINT8
)((DriverStrength
.Emmc
<< 4) | 2);
728 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusTiming: Unsupported BusTiming(%d)\n", BusTiming
));
729 return EFI_INVALID_PARAMETER
;
732 Status
= EmmcSwitch (PassThru
, Slot
, Access
, Index
, Value
, CmdSet
);
733 if (EFI_ERROR (Status
)) {
734 DEBUG ((DEBUG_ERROR
, "EmmcSwitchBusTiming: Switch to bus timing %d fails with %r\n", BusTiming
, Status
));
738 if ((BusTiming
== SdMmcMmcHsSdr
) || (BusTiming
== SdMmcMmcHsDdr
)) {
740 Status
= SdMmcHcOrMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
741 if (EFI_ERROR (Status
)) {
745 HostCtrl1
= (UINT8
) ~BIT2
;
746 Status
= SdMmcHcAndMmio (PciIo
, Slot
, SD_MMC_HC_HOST_CTRL1
, sizeof (HostCtrl1
), &HostCtrl1
);
747 if (EFI_ERROR (Status
)) {
752 Status
= SdMmcHcUhsSignaling (Private
->ControllerHandle
, PciIo
, Slot
, BusTiming
);
753 if (EFI_ERROR (Status
)) {
758 // For cases when we switch bus timing to higher mode from current we want to
759 // send SEND_STATUS at current, lower, frequency then the target frequency to avoid
760 // stability issues. It has been observed that some designs are unable to process the
761 // SEND_STATUS at higher frequency during switch to HS200 @200MHz irrespective of the number of retries
762 // and only running the clock tuning is able to make them work at target frequency.
764 // For cases when we are downgrading the frequency and current high frequency is invalid
765 // we have to first change the frequency to target frequency and then send the SEND_STATUS.
767 if (Private
->Slot
[Slot
].CurrentFreq
< (ClockFreq
* 1000)) {
768 Status
= EmmcCheckSwitchStatus (PassThru
, Slot
, Rca
);
769 if (EFI_ERROR (Status
)) {
773 DelaySendStatus
= FALSE
;
775 DelaySendStatus
= TRUE
;
779 // Convert the clock freq unit from MHz to KHz.
781 Status
= SdMmcHcClockSupply (Private
, Slot
, BusTiming
, FALSE
, ClockFreq
* 1000);
782 if (EFI_ERROR (Status
)) {
786 if (DelaySendStatus
) {
787 Status
= EmmcCheckSwitchStatus (PassThru
, Slot
, Rca
);
788 if (EFI_ERROR (Status
)) {
797 Switch to the High Speed timing according to request.
799 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
800 Simplified Spec 3.0 Figure 2-29 for details.
802 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
803 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
804 @param[in] Slot The slot number of the SD card to send the command to.
805 @param[in] Rca The relative device address to be assigned.
806 @param[in] BusMode Pointer to SD_MMC_BUS_SETTINGS structure containing bus settings.
808 @retval EFI_SUCCESS The operation is done correctly.
809 @retval Others The operation fails.
813 EmmcSwitchToHighSpeed (
814 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
815 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
818 IN SD_MMC_BUS_SETTINGS
*BusMode
824 if (((BusMode
->BusTiming
!= SdMmcMmcHsSdr
) && (BusMode
->BusTiming
!= SdMmcMmcHsDdr
) && (BusMode
->BusTiming
!= SdMmcMmcLegacy
)) ||
825 (BusMode
->ClockFreq
> 52))
827 return EFI_INVALID_PARAMETER
;
830 if (BusMode
->BusTiming
== SdMmcMmcHsDdr
) {
836 Status
= EmmcSwitchBusWidth (PciIo
, PassThru
, Slot
, Rca
, IsDdr
, BusMode
->BusWidth
);
837 if (EFI_ERROR (Status
)) {
841 return EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, BusMode
->BusTiming
, BusMode
->ClockFreq
);
845 Switch to the HS200 timing. This function assumes that eMMC bus is still in legacy mode.
847 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
848 Simplified Spec 3.0 Figure 2-29 for details.
850 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
851 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
852 @param[in] Slot The slot number of the SD card to send the command to.
853 @param[in] Rca The relative device address to be assigned.
854 @param[in] BusMode Pointer to SD_MMC_BUS_SETTINGS structure containing bus settings.
856 @retval EFI_SUCCESS The operation is done correctly.
857 @retval Others The operation fails.
862 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
863 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
866 IN SD_MMC_BUS_SETTINGS
*BusMode
871 if ((BusMode
->BusTiming
!= SdMmcMmcHs200
) ||
872 ((BusMode
->BusWidth
!= 4) && (BusMode
->BusWidth
!= 8)))
874 return EFI_INVALID_PARAMETER
;
877 Status
= EmmcSwitchBusWidth (PciIo
, PassThru
, Slot
, Rca
, FALSE
, BusMode
->BusWidth
);
878 if (EFI_ERROR (Status
)) {
882 Status
= EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, BusMode
->BusTiming
, BusMode
->ClockFreq
);
883 if (EFI_ERROR (Status
)) {
887 Status
= EmmcTuningClkForHs200 (PciIo
, PassThru
, Slot
, BusMode
->BusWidth
);
893 Switch to the HS400 timing. This function assumes that eMMC bus is still in legacy mode.
895 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
896 Simplified Spec 3.0 Figure 2-29 for details.
898 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
899 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
900 @param[in] Slot The slot number of the SD card to send the command to.
901 @param[in] Rca The relative device address to be assigned.
902 @param[in] BusMode Pointer to SD_MMC_BUS_SETTINGS structure containing bus settings.
904 @retval EFI_SUCCESS The operation is done correctly.
905 @retval Others The operation fails.
910 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
911 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
914 IN SD_MMC_BUS_SETTINGS
*BusMode
918 SD_MMC_BUS_SETTINGS Hs200BusMode
;
921 if ((BusMode
->BusTiming
!= SdMmcMmcHs400
) ||
922 (BusMode
->BusWidth
!= 8))
924 return EFI_INVALID_PARAMETER
;
927 Hs200BusMode
.BusTiming
= SdMmcMmcHs200
;
928 Hs200BusMode
.BusWidth
= BusMode
->BusWidth
;
929 Hs200BusMode
.ClockFreq
= BusMode
->ClockFreq
;
930 Hs200BusMode
.DriverStrength
= BusMode
->DriverStrength
;
932 Status
= EmmcSwitchToHS200 (PciIo
, PassThru
, Slot
, Rca
, &Hs200BusMode
);
933 if (EFI_ERROR (Status
)) {
938 // Set to High Speed timing and set the clock frequency to a value less than or equal to 52MHz.
939 // This step is necessary to be able to switch Bus into 8 bit DDR mode which is unsupported in HS200.
941 HsFreq
= BusMode
->ClockFreq
< 52 ? BusMode
->ClockFreq
: 52;
942 Status
= EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, SdMmcMmcHsSdr
, HsFreq
);
943 if (EFI_ERROR (Status
)) {
947 Status
= EmmcSwitchBusWidth (PciIo
, PassThru
, Slot
, Rca
, TRUE
, BusMode
->BusWidth
);
948 if (EFI_ERROR (Status
)) {
952 return EmmcSwitchBusTiming (PciIo
, PassThru
, Slot
, Rca
, BusMode
->DriverStrength
, BusMode
->BusTiming
, BusMode
->ClockFreq
);
956 Check if passed BusTiming is supported in both controller and card.
958 @param[in] Private Pointer to controller private data
959 @param[in] SlotIndex Index of the slot in the controller
960 @param[in] ExtCsd Pointer to the card's extended CSD
961 @param[in] BusTiming Bus timing to check
963 @retval TRUE Both card and controller support given BusTiming
964 @retval FALSE Card or controller doesn't support given BusTiming
967 EmmcIsBusTimingSupported (
968 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
970 IN EMMC_EXT_CSD
*ExtCsd
,
971 IN SD_MMC_BUS_MODE BusTiming
975 SD_MMC_HC_SLOT_CAP
*Capabilities
;
977 Capabilities
= &Private
->Capability
[SlotIndex
];
982 if ((((ExtCsd
->DeviceType
& (BIT6
| BIT7
)) != 0) && (Capabilities
->Hs400
!= 0)) && (Capabilities
->BusWidth8
!= 0)) {
988 if ((((ExtCsd
->DeviceType
& (BIT4
| BIT5
)) != 0) && (Capabilities
->Sdr104
!= 0))) {
994 if ((((ExtCsd
->DeviceType
& (BIT2
| BIT3
)) != 0) && (Capabilities
->Ddr50
!= 0))) {
1000 if ((((ExtCsd
->DeviceType
& BIT1
) != 0) && (Capabilities
->HighSpeed
!= 0))) {
1005 case SdMmcMmcLegacy
:
1006 if ((ExtCsd
->DeviceType
& BIT0
) != 0) {
1019 Get the target bus timing to set on the link. This function
1020 will try to select highest bus timing supported by card, controller
1023 @param[in] Private Pointer to controller private data
1024 @param[in] SlotIndex Index of the slot in the controller
1025 @param[in] ExtCsd Pointer to the card's extended CSD
1027 @return Bus timing value that should be set on link
1030 EmmcGetTargetBusTiming (
1031 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1033 IN EMMC_EXT_CSD
*ExtCsd
1036 SD_MMC_BUS_MODE BusTiming
;
1039 // We start with highest bus timing that this driver currently supports and
1040 // return as soon as we find supported timing.
1042 BusTiming
= SdMmcMmcHs400
;
1043 while (BusTiming
> SdMmcMmcLegacy
) {
1044 if (EmmcIsBusTimingSupported (Private
, SlotIndex
, ExtCsd
, BusTiming
)) {
1055 Check if the passed bus width is supported by controller and card.
1057 @param[in] Private Pointer to controller private data
1058 @param[in] SlotIndex Index of the slot in the controller
1059 @param[in] BusTiming Bus timing set on the link
1060 @param[in] BusWidth Bus width to check
1062 @retval TRUE Passed bus width is supported in current bus configuration
1063 @retval FALSE Passed bus width is not supported in current bus configuration
1066 EmmcIsBusWidthSupported (
1067 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1069 IN SD_MMC_BUS_MODE BusTiming
,
1073 if ((BusWidth
== 8) && (Private
->Capability
[SlotIndex
].BusWidth8
!= 0)) {
1075 } else if ((BusWidth
== 4) && (BusTiming
!= SdMmcMmcHs400
)) {
1077 } else if ((BusWidth
== 1) && ((BusTiming
== SdMmcMmcHsSdr
) || (BusTiming
== SdMmcMmcLegacy
))) {
1085 Get the target bus width to be set on the bus.
1087 @param[in] Private Pointer to controller private data
1088 @param[in] SlotIndex Index of the slot in the controller
1089 @param[in] ExtCsd Pointer to card's extended CSD
1090 @param[in] BusTiming Bus timing set on the bus
1092 @return Bus width to be set on the bus
1095 EmmcGetTargetBusWidth (
1096 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1098 IN EMMC_EXT_CSD
*ExtCsd
,
1099 IN SD_MMC_BUS_MODE BusTiming
1103 UINT8 PreferredBusWidth
;
1105 PreferredBusWidth
= Private
->Slot
[SlotIndex
].OperatingParameters
.BusWidth
;
1107 if ((PreferredBusWidth
!= EDKII_SD_MMC_BUS_WIDTH_IGNORE
) &&
1108 EmmcIsBusWidthSupported (Private
, SlotIndex
, BusTiming
, PreferredBusWidth
))
1110 BusWidth
= PreferredBusWidth
;
1111 } else if (EmmcIsBusWidthSupported (Private
, SlotIndex
, BusTiming
, 8)) {
1113 } else if (EmmcIsBusWidthSupported (Private
, SlotIndex
, BusTiming
, 4)) {
1123 Get the target clock frequency to be set on the bus.
1125 @param[in] Private Pointer to controller private data
1126 @param[in] SlotIndex Index of the slot in the controller
1127 @param[in] ExtCsd Pointer to card's extended CSD
1128 @param[in] BusTiming Bus timing to be set on the bus
1130 @return Value of the clock frequency to be set on bus in MHz
1133 EmmcGetTargetClockFreq (
1134 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1136 IN EMMC_EXT_CSD
*ExtCsd
,
1137 IN SD_MMC_BUS_MODE BusTiming
1140 UINT32 PreferredClockFreq
;
1141 UINT32 MaxClockFreq
;
1143 PreferredClockFreq
= Private
->Slot
[SlotIndex
].OperatingParameters
.ClockFreq
;
1145 switch (BusTiming
) {
1159 if ((PreferredClockFreq
!= EDKII_SD_MMC_CLOCK_FREQ_IGNORE
) && (PreferredClockFreq
< MaxClockFreq
)) {
1160 return PreferredClockFreq
;
1162 return MaxClockFreq
;
1167 Get the driver strength to be set on bus.
1169 @param[in] Private Pointer to controller private data
1170 @param[in] SlotIndex Index of the slot in the controller
1171 @param[in] ExtCsd Pointer to card's extended CSD
1172 @param[in] BusTiming Bus timing set on the bus
1174 @return Value of the driver strength to be set on the bus
1176 EDKII_SD_MMC_DRIVER_STRENGTH
1177 EmmcGetTargetDriverStrength (
1178 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1180 IN EMMC_EXT_CSD
*ExtCsd
,
1181 IN SD_MMC_BUS_MODE BusTiming
1184 EDKII_SD_MMC_DRIVER_STRENGTH PreferredDriverStrength
;
1185 EDKII_SD_MMC_DRIVER_STRENGTH DriverStrength
;
1187 PreferredDriverStrength
= Private
->Slot
[SlotIndex
].OperatingParameters
.DriverStrength
;
1188 DriverStrength
.Emmc
= EmmcDriverStrengthType0
;
1190 if ((PreferredDriverStrength
.Emmc
!= EDKII_SD_MMC_DRIVER_STRENGTH_IGNORE
) &&
1191 (ExtCsd
->DriverStrength
& (BIT0
<< PreferredDriverStrength
.Emmc
)))
1193 DriverStrength
.Emmc
= PreferredDriverStrength
.Emmc
;
1196 return DriverStrength
;
1200 Get the target settings for the bus mode.
1202 @param[in] Private Pointer to controller private data
1203 @param[in] SlotIndex Index of the slot in the controller
1204 @param[in] ExtCsd Pointer to card's extended CSD
1205 @param[out] BusMode Target configuration of the bus
1208 EmmcGetTargetBusMode (
1209 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1211 IN EMMC_EXT_CSD
*ExtCsd
,
1212 OUT SD_MMC_BUS_SETTINGS
*BusMode
1215 BusMode
->BusTiming
= EmmcGetTargetBusTiming (Private
, SlotIndex
, ExtCsd
);
1216 BusMode
->BusWidth
= EmmcGetTargetBusWidth (Private
, SlotIndex
, ExtCsd
, BusMode
->BusTiming
);
1217 BusMode
->ClockFreq
= EmmcGetTargetClockFreq (Private
, SlotIndex
, ExtCsd
, BusMode
->BusTiming
);
1218 BusMode
->DriverStrength
= EmmcGetTargetDriverStrength (Private
, SlotIndex
, ExtCsd
, BusMode
->BusTiming
);
1222 Switch the high speed timing according to request.
1224 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
1225 Simplified Spec 3.0 Figure 2-29 for details.
1227 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
1228 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
1229 @param[in] Slot The slot number of the SD card to send the command to.
1230 @param[in] Rca The relative device address to be assigned.
1232 @retval EFI_SUCCESS The operation is done correctly.
1233 @retval Others The operation fails.
1238 IN EFI_PCI_IO_PROTOCOL
*PciIo
,
1239 IN EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
,
1246 EMMC_EXT_CSD ExtCsd
;
1247 SD_MMC_BUS_SETTINGS BusMode
;
1248 SD_MMC_HC_PRIVATE_DATA
*Private
;
1250 Private
= SD_MMC_HC_PRIVATE_FROM_THIS (PassThru
);
1252 Status
= EmmcGetCsd (PassThru
, Slot
, Rca
, &Csd
);
1253 if (EFI_ERROR (Status
)) {
1254 DEBUG ((DEBUG_ERROR
, "EmmcSetBusMode: GetCsd fails with %r\n", Status
));
1258 Status
= EmmcSelect (PassThru
, Slot
, Rca
);
1259 if (EFI_ERROR (Status
)) {
1260 DEBUG ((DEBUG_ERROR
, "EmmcSetBusMode: Select fails with %r\n", Status
));
1264 ASSERT (Private
->BaseClkFreq
[Slot
] != 0);
1267 // Get Device_Type from EXT_CSD register.
1269 Status
= EmmcGetExtCsd (PassThru
, Slot
, &ExtCsd
);
1270 if (EFI_ERROR (Status
)) {
1271 DEBUG ((DEBUG_ERROR
, "EmmcSetBusMode: GetExtCsd fails with %r\n", Status
));
1275 EmmcGetTargetBusMode (Private
, Slot
, &ExtCsd
, &BusMode
);
1279 "EmmcSetBusMode: Target bus mode: timing = %d, width = %d, clock freq = %d, driver strength = %d\n",
1283 BusMode
.DriverStrength
.Emmc
1286 if (BusMode
.BusTiming
== SdMmcMmcHs400
) {
1287 Status
= EmmcSwitchToHS400 (PciIo
, PassThru
, Slot
, Rca
, &BusMode
);
1288 } else if (BusMode
.BusTiming
== SdMmcMmcHs200
) {
1289 Status
= EmmcSwitchToHS200 (PciIo
, PassThru
, Slot
, Rca
, &BusMode
);
1292 // Note that EmmcSwitchToHighSpeed is also called for SdMmcMmcLegacy
1293 // bus timing. This is because even though we might not want to
1294 // change the timing itself we still want to allow customization of
1295 // bus parameters such as clock frequency and bus width.
1297 Status
= EmmcSwitchToHighSpeed (PciIo
, PassThru
, Slot
, Rca
, &BusMode
);
1300 DEBUG ((DEBUG_INFO
, "EmmcSetBusMode: Switch to %a %r\n", (BusMode
.BusTiming
== SdMmcMmcHs400
) ? "HS400" : ((BusMode
.BusTiming
== SdMmcMmcHs200
) ? "HS200" : "HighSpeed"), Status
));
1306 Execute EMMC device identification procedure.
1308 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
1310 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1311 @param[in] Slot The slot number of the SD card to send the command to.
1313 @retval EFI_SUCCESS There is a EMMC card.
1314 @retval Others There is not a EMMC card.
1318 EmmcIdentification (
1319 IN SD_MMC_HC_PRIVATE_DATA
*Private
,
1324 EFI_PCI_IO_PROTOCOL
*PciIo
;
1325 EFI_SD_MMC_PASS_THRU_PROTOCOL
*PassThru
;
1330 PciIo
= Private
->PciIo
;
1331 PassThru
= &Private
->PassThru
;
1333 Status
= EmmcReset (PassThru
, Slot
);
1334 if (EFI_ERROR (Status
)) {
1335 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd0 fails with %r\n", Status
));
1342 Status
= EmmcGetOcr (PassThru
, Slot
, &Ocr
);
1343 if (EFI_ERROR (Status
)) {
1344 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd1 fails with %r\n", Status
));
1350 if (Retry
++ == 100) {
1351 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd1 fails too many times\n"));
1352 return EFI_DEVICE_ERROR
;
1355 gBS
->Stall (10 * 1000);
1356 } while ((Ocr
& BIT31
) == 0);
1358 Status
= EmmcGetAllCid (PassThru
, Slot
);
1359 if (EFI_ERROR (Status
)) {
1360 DEBUG ((DEBUG_VERBOSE
, "EmmcIdentification: Executing Cmd2 fails with %r\n", Status
));
1365 // Slot starts from 0 and valid RCA starts from 1.
1366 // Here we takes a simple formula to calculate the RCA.
1367 // Don't support multiple devices on the slot, that is
1368 // shared bus slot feature.
1371 Status
= EmmcSetRca (PassThru
, Slot
, Rca
);
1372 if (EFI_ERROR (Status
)) {
1373 DEBUG ((DEBUG_ERROR
, "EmmcIdentification: Executing Cmd3 fails with %r\n", Status
));
1378 // Enter Data Tranfer Mode.
1380 DEBUG ((DEBUG_INFO
, "EmmcIdentification: Found a EMMC device at slot [%d], RCA [%d]\n", Slot
, Rca
));
1381 Private
->Slot
[Slot
].CardType
= EmmcCardType
;
1383 Status
= EmmcSetBusMode (PciIo
, PassThru
, Slot
, Rca
);