]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
MdeModulePkg/SdMmc: Add EDKII SD/MMC stack
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SdMmcPciHcDxe / EmmcDevice.c
1 /** @file
2 This file provides some helper functions which are specific for EMMC device.
3
4 Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
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
9
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.
12
13 **/
14
15 #include "SdMmcPciHcDxe.h"
16
17 /**
18 Send command GO_IDLE_STATE (CMD0 with argument of 0x00000000) to the device to
19 make it go to Idle State.
20
21 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
22
23 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
24 @param[in] Slot The slot number of the SD card to send the command to.
25
26 @retval EFI_SUCCESS The EMMC device is reset correctly.
27 @retval Others The device reset fails.
28
29 **/
30 EFI_STATUS
31 EmmcReset (
32 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
33 IN UINT8 Slot
34 )
35 {
36 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
37 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
38 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
39 EFI_STATUS Status;
40
41 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
42 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
43 ZeroMem (&Packet, sizeof (Packet));
44
45 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
46 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
47 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
48
49 SdMmcCmdBlk.CommandIndex = EMMC_GO_IDLE_STATE;
50 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBc;
51 SdMmcCmdBlk.ResponseType = 0;
52 SdMmcCmdBlk.CommandArgument = 0;
53
54 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
55
56 return Status;
57 }
58
59 /**
60 Send command SEND_OP_COND to the EMMC device to get the data of the OCR register.
61
62 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
63
64 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
65 @param[in] Slot The slot number of the SD card to send the command to.
66 @param[in, out] Argument On input, the argument of SEND_OP_COND is to send to the device.
67 On output, the argument is the value of OCR register.
68
69 @retval EFI_SUCCESS The operation is done correctly.
70 @retval Others The operation fails.
71
72 **/
73 EFI_STATUS
74 EmmcGetOcr (
75 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
76 IN UINT8 Slot,
77 IN OUT UINT32 *Argument
78 )
79 {
80 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
81 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
82 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
83 EFI_STATUS Status;
84
85 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
86 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
87 ZeroMem (&Packet, sizeof (Packet));
88
89 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
90 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
91 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
92
93 SdMmcCmdBlk.CommandIndex = EMMC_SEND_OP_COND;
94 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
95 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR3;
96 SdMmcCmdBlk.CommandArgument = *Argument;
97
98 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
99 if (!EFI_ERROR (Status)) {
100 //
101 // For details, refer to SD Host Controller Simplified Spec 3.0 Table 2-12.
102 //
103 *Argument = SdMmcStatusBlk.Resp0;
104 }
105
106 return Status;
107 }
108
109 /**
110 Broadcast command ALL_SEND_CID to the bus to ask all the EMMC devices to send the
111 data of their CID registers.
112
113 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
114
115 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
116 @param[in] Slot The slot number of the SD card to send the command to.
117
118 @retval EFI_SUCCESS The operation is done correctly.
119 @retval Others The operation fails.
120
121 **/
122 EFI_STATUS
123 EmmcGetAllCid (
124 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
125 IN UINT8 Slot
126 )
127 {
128 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
129 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
130 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
131 EFI_STATUS Status;
132
133 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
134 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
135 ZeroMem (&Packet, sizeof (Packet));
136
137 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
138 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
139 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
140
141 SdMmcCmdBlk.CommandIndex = EMMC_ALL_SEND_CID;
142 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
143 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
144 SdMmcCmdBlk.CommandArgument = 0;
145
146 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
147
148 return Status;
149 }
150
151 /**
152 Send command SET_RELATIVE_ADDR to the EMMC device to assign a Relative device
153 Address (RCA).
154
155 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
156
157 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
158 @param[in] Slot The slot number of the SD card to send the command to.
159 @param[in] Rca The relative device address to be assigned.
160
161 @retval EFI_SUCCESS The operation is done correctly.
162 @retval Others The operation fails.
163
164 **/
165 EFI_STATUS
166 EmmcSetRca (
167 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
168 IN UINT8 Slot,
169 IN UINT16 Rca
170 )
171 {
172 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
173 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
174 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
175 EFI_STATUS Status;
176
177 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
178 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
179 ZeroMem (&Packet, sizeof (Packet));
180
181 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
182 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
183 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
184
185 SdMmcCmdBlk.CommandIndex = EMMC_SET_RELATIVE_ADDR;
186 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
187 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
188 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
189
190 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
191
192 return Status;
193 }
194
195 /**
196 Send command SEND_CSD to the EMMC device to get the data of the CSD register.
197
198 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
199
200 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
201 @param[in] Slot The slot number of the SD card to send the command to.
202 @param[in] Rca The relative device address of selected device.
203 @param[out] Csd The buffer to store the content of the CSD register.
204 Note the caller should ignore the lowest byte of this
205 buffer as the content of this byte is meaningless even
206 if the operation succeeds.
207
208 @retval EFI_SUCCESS The operation is done correctly.
209 @retval Others The operation fails.
210
211 **/
212 EFI_STATUS
213 EmmcGetCsd (
214 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
215 IN UINT8 Slot,
216 IN UINT16 Rca,
217 OUT EMMC_CSD *Csd
218 )
219 {
220 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
221 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
222 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
223 EFI_STATUS Status;
224
225 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
226 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
227 ZeroMem (&Packet, sizeof (Packet));
228
229 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
230 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
231 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
232
233 SdMmcCmdBlk.CommandIndex = EMMC_SEND_CSD;
234 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
235 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
236 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
237
238 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
239 if (!EFI_ERROR (Status)) {
240 //
241 // For details, refer to SD Host Controller Simplified Spec 3.0 Table 2-12.
242 //
243 CopyMem (((UINT8*)Csd) + 1, &SdMmcStatusBlk.Resp0, sizeof (EMMC_CSD) - 1);
244 }
245
246 return Status;
247 }
248
249 /**
250 Send command SELECT_DESELECT_CARD to the EMMC device to select/deselect it.
251
252 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
253
254 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
255 @param[in] Slot The slot number of the SD card to send the command to.
256 @param[in] Rca The relative device address of selected device.
257
258 @retval EFI_SUCCESS The operation is done correctly.
259 @retval Others The operation fails.
260
261 **/
262 EFI_STATUS
263 EmmcSelect (
264 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
265 IN UINT8 Slot,
266 IN UINT16 Rca
267 )
268 {
269 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
270 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
271 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
272 EFI_STATUS Status;
273
274 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
275 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
276 ZeroMem (&Packet, sizeof (Packet));
277
278 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
279 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
280 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
281
282 SdMmcCmdBlk.CommandIndex = EMMC_SELECT_DESELECT_CARD;
283 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
284 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
285 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
286
287 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
288
289 return Status;
290 }
291
292 /**
293 Send command SEND_EXT_CSD to the EMMC device to get the data of the EXT_CSD register.
294
295 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
296
297 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
298 @param[in] Slot The slot number of the SD card to send the command to.
299 @param[out] ExtCsd The buffer to store the content of the EXT_CSD register.
300
301 @retval EFI_SUCCESS The operation is done correctly.
302 @retval Others The operation fails.
303
304 **/
305 EFI_STATUS
306 EmmcGetExtCsd (
307 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
308 IN UINT8 Slot,
309 OUT EMMC_EXT_CSD *ExtCsd
310 )
311 {
312 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
313 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
314 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
315 EFI_STATUS Status;
316
317 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
318 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
319 ZeroMem (&Packet, sizeof (Packet));
320
321 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
322 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
323 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
324
325 SdMmcCmdBlk.CommandIndex = EMMC_SEND_EXT_CSD;
326 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
327 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
328 SdMmcCmdBlk.CommandArgument = 0x00000000;
329
330 Packet.InDataBuffer = ExtCsd;
331 Packet.InTransferLength = sizeof (EMMC_EXT_CSD);
332
333 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
334 return Status;
335 }
336
337 /**
338 Send command SWITCH to the EMMC device to switch the mode of operation of the
339 selected Device or modifies the EXT_CSD registers.
340
341 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
342
343 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
344 @param[in] Slot The slot number of the SD card to send the command to.
345 @param[in] Access The access mode of SWTICH command.
346 @param[in] Index The offset of the field to be access.
347 @param[in] Value The value to be set to the specified field of EXT_CSD register.
348 @param[in] CmdSet The value of CmdSet field of EXT_CSD register.
349
350 @retval EFI_SUCCESS The operation is done correctly.
351 @retval Others The operation fails.
352
353 **/
354 EFI_STATUS
355 EmmcSwitch (
356 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
357 IN UINT8 Slot,
358 IN UINT8 Access,
359 IN UINT8 Index,
360 IN UINT8 Value,
361 IN UINT8 CmdSet
362 )
363 {
364 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
365 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
366 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
367 EFI_STATUS Status;
368
369 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
370 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
371 ZeroMem (&Packet, sizeof (Packet));
372
373 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
374 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
375 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
376
377 SdMmcCmdBlk.CommandIndex = EMMC_SWITCH;
378 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
379 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
380 SdMmcCmdBlk.CommandArgument = (Access << 24) | (Index << 16) | (Value << 8) | CmdSet;
381
382 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
383
384 return Status;
385 }
386
387 /**
388 Send command SEND_STATUS to the addressed EMMC device to get its status register.
389
390 Refer to EMMC Electrical Standard Spec 5.1 Section 6.10.4 for details.
391
392 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
393 @param[in] Slot The slot number of the SD card to send the command to.
394 @param[in] Rca The relative device address of addressed device.
395 @param[out] DevStatus The returned device status.
396
397 @retval EFI_SUCCESS The operation is done correctly.
398 @retval Others The operation fails.
399
400 **/
401 EFI_STATUS
402 EmmcSendStatus (
403 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
404 IN UINT8 Slot,
405 IN UINT16 Rca,
406 OUT UINT32 *DevStatus
407 )
408 {
409 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
410 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
411 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
412 EFI_STATUS Status;
413
414 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
415 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
416 ZeroMem (&Packet, sizeof (Packet));
417
418 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
419 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
420 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
421
422 SdMmcCmdBlk.CommandIndex = EMMC_SEND_STATUS;
423 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
424 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
425 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
426
427 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
428 if (!EFI_ERROR (Status)) {
429 *DevStatus = SdMmcStatusBlk.Resp0;
430 }
431
432 return Status;
433 }
434
435 /**
436 Send command SEND_TUNING_BLOCK to the EMMC device for HS200 optimal sampling point
437 detection.
438
439 It may be sent up to 40 times until the host finishes the tuning procedure.
440
441 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 for details.
442
443 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
444 @param[in] Slot The slot number of the SD card to send the command to.
445 @param[in] BusWidth The bus width to work.
446
447 @retval EFI_SUCCESS The operation is done correctly.
448 @retval Others The operation fails.
449
450 **/
451 EFI_STATUS
452 EmmcSendTuningBlk (
453 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
454 IN UINT8 Slot,
455 IN UINT8 BusWidth
456 )
457 {
458 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
459 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
460 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
461 EFI_STATUS Status;
462 UINT8 TuningBlock[128];
463
464 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
465 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
466 ZeroMem (&Packet, sizeof (Packet));
467
468 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
469 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
470 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
471
472 SdMmcCmdBlk.CommandIndex = EMMC_SEND_TUNING_BLOCK;
473 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
474 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
475 SdMmcCmdBlk.CommandArgument = 0;
476
477 Packet.InDataBuffer = TuningBlock;
478 if (BusWidth == 8) {
479 Packet.InTransferLength = sizeof (TuningBlock);
480 } else {
481 Packet.InTransferLength = 64;
482 }
483
484 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
485
486 return Status;
487 }
488
489 /**
490 Tunning the clock to get HS200 optimal sampling point.
491
492 Command SEND_TUNING_BLOCK may be sent up to 40 times until the host finishes the
493 tuning procedure.
494
495 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
496 Simplified Spec 3.0 Figure 2-29 for details.
497
498 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
499 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
500 @param[in] Slot The slot number of the SD card to send the command to.
501 @param[in] BusWidth The bus width to work.
502
503 @retval EFI_SUCCESS The operation is done correctly.
504 @retval Others The operation fails.
505
506 **/
507 EFI_STATUS
508 EmmcTuningClkForHs200 (
509 IN EFI_PCI_IO_PROTOCOL *PciIo,
510 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
511 IN UINT8 Slot,
512 IN UINT8 BusWidth
513 )
514 {
515 EFI_STATUS Status;
516 UINT8 HostCtrl2;
517 UINT8 Retry;
518
519 //
520 // Notify the host that the sampling clock tuning procedure starts.
521 //
522 HostCtrl2 = BIT6;
523 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
524 if (EFI_ERROR (Status)) {
525 return Status;
526 }
527 //
528 // Ask the device to send a sequence of tuning blocks till the tuning procedure is done.
529 //
530 Retry = 0;
531 do {
532 Status = EmmcSendTuningBlk (PassThru, Slot, BusWidth);
533 if (EFI_ERROR (Status)) {
534 DEBUG ((EFI_D_ERROR, "EmmcTuningClkForHs200: Send tuning block fails with %r\n", Status));
535 return Status;
536 }
537
538 Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2);
539 if (EFI_ERROR (Status)) {
540 return Status;
541 }
542
543 if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {
544 break;
545 }
546 } while (++Retry < 40);
547
548 if (Retry == 40) {
549 Status = EFI_TIMEOUT;
550 DEBUG ((EFI_D_ERROR, "EmmcTuningClkForHs200: Send tuning block exceeds 40 times\n"));
551 }
552
553 return Status;
554 }
555
556 /**
557 Switch the bus width to specified width.
558
559 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.9 and SD Host Controller
560 Simplified Spec 3.0 Figure 3-7 for details.
561
562 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
563 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
564 @param[in] Slot The slot number of the SD card to send the command to.
565 @param[in] Rca The relative device address to be assigned.
566 @param[in] IsDdr If TRUE, use dual data rate data simpling method. Otherwise
567 use single data rate data simpling method.
568 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
569
570 @retval EFI_SUCCESS The operation is done correctly.
571 @retval Others The operation fails.
572
573 **/
574 EFI_STATUS
575 EmmcSwitchBusWidth (
576 IN EFI_PCI_IO_PROTOCOL *PciIo,
577 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
578 IN UINT8 Slot,
579 IN UINT16 Rca,
580 IN BOOLEAN IsDdr,
581 IN UINT8 BusWidth
582 )
583 {
584 EFI_STATUS Status;
585 UINT8 Access;
586 UINT8 Index;
587 UINT8 Value;
588 UINT8 CmdSet;
589 UINT32 DevStatus;
590
591 //
592 // Write Byte, the Value field is written into the byte pointed by Index.
593 //
594 Access = 0x03;
595 Index = OFFSET_OF (EMMC_EXT_CSD, BusWidth);
596 if (BusWidth == 4) {
597 Value = 1;
598 } else if (BusWidth == 8) {
599 Value = 2;
600 } else {
601 return EFI_INVALID_PARAMETER;
602 }
603
604 if (IsDdr) {
605 Value += 4;
606 }
607
608 CmdSet = 0;
609 Status = EmmcSwitch (PassThru, Slot, Access, Index, Value, CmdSet);
610 if (EFI_ERROR (Status)) {
611 DEBUG ((EFI_D_ERROR, "EmmcSwitchBusWidth: Switch to bus width %d fails with %r\n", BusWidth, Status));
612 return Status;
613 }
614
615 Status = EmmcSendStatus (PassThru, Slot, Rca, &DevStatus);
616 if (EFI_ERROR (Status)) {
617 DEBUG ((EFI_D_ERROR, "EmmcSwitchBusWidth: Send status fails with %r\n", Status));
618 return Status;
619 }
620 //
621 // Check the switch operation is really successful or not.
622 //
623 if ((DevStatus & BIT7) != 0) {
624 DEBUG ((EFI_D_ERROR, "EmmcSwitchBusWidth: The switch operation fails as DevStatus is 0x%08x\n", DevStatus));
625 return EFI_DEVICE_ERROR;
626 }
627
628 Status = SdMmcHcSetBusWidth (PciIo, Slot, BusWidth);
629
630 return Status;
631 }
632
633 /**
634 Switch the clock frequency to the specified value.
635
636 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6 and SD Host Controller
637 Simplified Spec 3.0 Figure 3-3 for details.
638
639 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
640 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
641 @param[in] Slot The slot number of the SD card to send the command to.
642 @param[in] Rca The relative device address to be assigned.
643 @param[in] HsTiming The value to be written to HS_TIMING field of EXT_CSD register.
644 @param[in] ClockFreq The max clock frequency to be set, the unit is MHz.
645
646 @retval EFI_SUCCESS The operation is done correctly.
647 @retval Others The operation fails.
648
649 **/
650 EFI_STATUS
651 EmmcSwitchClockFreq (
652 IN EFI_PCI_IO_PROTOCOL *PciIo,
653 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
654 IN UINT8 Slot,
655 IN UINT16 Rca,
656 IN UINT8 HsTiming,
657 IN UINT32 ClockFreq
658 )
659 {
660 EFI_STATUS Status;
661 UINT8 Access;
662 UINT8 Index;
663 UINT8 Value;
664 UINT8 CmdSet;
665 UINT32 DevStatus;
666 SD_MMC_HC_PRIVATE_DATA *Private;
667
668 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
669 //
670 // Write Byte, the Value field is written into the byte pointed by Index.
671 //
672 Access = 0x03;
673 Index = OFFSET_OF (EMMC_EXT_CSD, HsTiming);
674 Value = HsTiming;
675 CmdSet = 0;
676
677 Status = EmmcSwitch (PassThru, Slot, Access, Index, Value, CmdSet);
678 if (EFI_ERROR (Status)) {
679 DEBUG ((EFI_D_ERROR, "EmmcSwitchClockFreq: Switch to hstiming %d fails with %r\n", HsTiming, Status));
680 return Status;
681 }
682
683 Status = EmmcSendStatus (PassThru, Slot, Rca, &DevStatus);
684 if (EFI_ERROR (Status)) {
685 DEBUG ((EFI_D_ERROR, "EmmcSwitchClockFreq: Send status fails with %r\n", Status));
686 return Status;
687 }
688 //
689 // Check the switch operation is really successful or not.
690 //
691 if ((DevStatus & BIT7) != 0) {
692 DEBUG ((EFI_D_ERROR, "EmmcSwitchClockFreq: The switch operation fails as DevStatus is 0x%08x\n", DevStatus));
693 return EFI_DEVICE_ERROR;
694 }
695 //
696 // Convert the clock freq unit from MHz to KHz.
697 //
698 Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private->Capability[Slot]);
699
700 return Status;
701 }
702
703 /**
704 Switch to the High Speed timing according to request.
705
706 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
707 Simplified Spec 3.0 Figure 2-29 for details.
708
709 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
710 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
711 @param[in] Slot The slot number of the SD card to send the command to.
712 @param[in] Rca The relative device address to be assigned.
713 @param[in] ClockFreq The max clock frequency to be set.
714 @param[in] IsDdr If TRUE, use dual data rate data simpling method. Otherwise
715 use single data rate data simpling method.
716 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
717
718 @retval EFI_SUCCESS The operation is done correctly.
719 @retval Others The operation fails.
720
721 **/
722 EFI_STATUS
723 EmmcSwitchToHighSpeed (
724 IN EFI_PCI_IO_PROTOCOL *PciIo,
725 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
726 IN UINT8 Slot,
727 IN UINT16 Rca,
728 IN UINT32 ClockFreq,
729 IN BOOLEAN IsDdr,
730 IN UINT8 BusWidth
731 )
732 {
733 EFI_STATUS Status;
734 UINT8 HsTiming;
735 UINT8 HostCtrl1;
736 UINT8 HostCtrl2;
737
738 Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, IsDdr, BusWidth);
739 if (EFI_ERROR (Status)) {
740 return Status;
741 }
742 //
743 // Set to Hight Speed timing
744 //
745 HostCtrl1 = BIT2;
746 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1, sizeof (HostCtrl1), &HostCtrl1);
747 if (EFI_ERROR (Status)) {
748 return Status;
749 }
750
751 //
752 // Clean UHS Mode Select field of Host Control 2 reigster before update
753 //
754 HostCtrl2 = (UINT8)~0x7;
755 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
756 if (EFI_ERROR (Status)) {
757 return Status;
758 }
759 //
760 // Set UHS Mode Select field of Host Control 2 reigster to SDR12/25/50
761 //
762 if (IsDdr) {
763 HostCtrl2 = BIT2;
764 } else if (ClockFreq == 52) {
765 HostCtrl2 = BIT0;
766 } else {
767 HostCtrl2 = 0;
768 }
769 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
770 if (EFI_ERROR (Status)) {
771 return Status;
772 }
773
774 HsTiming = 1;
775 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, ClockFreq);
776 if (EFI_ERROR (Status)) {
777 return Status;
778 }
779
780 return Status;
781 }
782
783 /**
784 Switch to the HS200 timing according to request.
785
786 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
787 Simplified Spec 3.0 Figure 2-29 for details.
788
789 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
790 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
791 @param[in] Slot The slot number of the SD card to send the command to.
792 @param[in] Rca The relative device address to be assigned.
793 @param[in] ClockFreq The max clock frequency to be set.
794 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
795
796 @retval EFI_SUCCESS The operation is done correctly.
797 @retval Others The operation fails.
798
799 **/
800 EFI_STATUS
801 EmmcSwitchToHS200 (
802 IN EFI_PCI_IO_PROTOCOL *PciIo,
803 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
804 IN UINT8 Slot,
805 IN UINT16 Rca,
806 IN UINT32 ClockFreq,
807 IN UINT8 BusWidth
808 )
809 {
810 EFI_STATUS Status;
811 UINT8 HsTiming;
812 UINT8 HostCtrl2;
813 UINT16 ClockCtrl;
814
815 if ((BusWidth != 4) && (BusWidth != 8)) {
816 return EFI_INVALID_PARAMETER;
817 }
818
819 Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, FALSE, BusWidth);
820 if (EFI_ERROR (Status)) {
821 return Status;
822 }
823 //
824 // Set to HS200/SDR104 timing
825 //
826 //
827 // Stop bus clock at first
828 //
829 Status = SdMmcHcStopClock (PciIo, Slot);
830 if (EFI_ERROR (Status)) {
831 return Status;
832 }
833 //
834 // Clean UHS Mode Select field of Host Control 2 reigster before update
835 //
836 HostCtrl2 = (UINT8)~0x7;
837 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
838 if (EFI_ERROR (Status)) {
839 return Status;
840 }
841 //
842 // Set UHS Mode Select field of Host Control 2 reigster to SDR104
843 //
844 HostCtrl2 = BIT0 | BIT1;
845 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
846 if (EFI_ERROR (Status)) {
847 return Status;
848 }
849 //
850 // Wait Internal Clock Stable in the Clock Control register to be 1 before set SD Clock Enable bit
851 //
852 Status = SdMmcHcWaitMmioSet (
853 PciIo,
854 Slot,
855 SD_MMC_HC_CLOCK_CTRL,
856 sizeof (ClockCtrl),
857 BIT1,
858 BIT1,
859 SD_MMC_HC_GENERIC_TIMEOUT
860 );
861 if (EFI_ERROR (Status)) {
862 return Status;
863 }
864 //
865 // Set SD Clock Enable in the Clock Control register to 1
866 //
867 ClockCtrl = BIT2;
868 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_CLOCK_CTRL, sizeof (ClockCtrl), &ClockCtrl);
869
870 HsTiming = 2;
871 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, ClockFreq);
872 if (EFI_ERROR (Status)) {
873 return Status;
874 }
875
876 Status = EmmcTuningClkForHs200 (PciIo, PassThru, Slot, BusWidth);
877
878 return Status;
879 }
880
881 /**
882 Switch to the HS400 timing according to request.
883
884 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
885 Simplified Spec 3.0 Figure 2-29 for details.
886
887 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
888 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
889 @param[in] Slot The slot number of the SD card to send the command to.
890 @param[in] Rca The relative device address to be assigned.
891 @param[in] ClockFreq The max clock frequency to be set.
892
893 @retval EFI_SUCCESS The operation is done correctly.
894 @retval Others The operation fails.
895
896 **/
897 EFI_STATUS
898 EmmcSwitchToHS400 (
899 IN EFI_PCI_IO_PROTOCOL *PciIo,
900 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
901 IN UINT8 Slot,
902 IN UINT16 Rca,
903 IN UINT32 ClockFreq
904 )
905 {
906 EFI_STATUS Status;
907 UINT8 HsTiming;
908 UINT8 HostCtrl2;
909
910 Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, 8);
911 if (EFI_ERROR (Status)) {
912 return Status;
913 }
914 //
915 // Set to Hight Speed timing and set the clock frequency to a value less than 52MHz.
916 //
917 HsTiming = 1;
918 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, 52);
919 if (EFI_ERROR (Status)) {
920 return Status;
921 }
922 //
923 // HS400 mode must use 8 data lines.
924 //
925 Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, TRUE, 8);
926 if (EFI_ERROR (Status)) {
927 return Status;
928 }
929 //
930 // Clean UHS Mode Select field of Host Control 2 reigster before update
931 //
932 HostCtrl2 = (UINT8)~0x7;
933 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
934 if (EFI_ERROR (Status)) {
935 return Status;
936 }
937 //
938 // Set UHS Mode Select field of Host Control 2 reigster to HS400
939 //
940 HostCtrl2 = BIT0 | BIT2;
941 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
942 if (EFI_ERROR (Status)) {
943 return Status;
944 }
945
946 HsTiming = 3;
947 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, ClockFreq);
948
949 return Status;
950 }
951
952 /**
953 Switch the high speed timing according to request.
954
955 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
956 Simplified Spec 3.0 Figure 2-29 for details.
957
958 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
959 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
960 @param[in] Slot The slot number of the SD card to send the command to.
961 @param[in] Rca The relative device address to be assigned.
962
963 @retval EFI_SUCCESS The operation is done correctly.
964 @retval Others The operation fails.
965
966 **/
967 EFI_STATUS
968 EmmcSetBusMode (
969 IN EFI_PCI_IO_PROTOCOL *PciIo,
970 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
971 IN UINT8 Slot,
972 IN UINT16 Rca
973 )
974 {
975 EFI_STATUS Status;
976 EMMC_CSD Csd;
977 EMMC_EXT_CSD ExtCsd;
978 UINT8 HsTiming;
979 BOOLEAN IsDdr;
980 UINT32 ClockFreq;
981 UINT8 BusWidth;
982 SD_MMC_HC_PRIVATE_DATA *Private;
983
984 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
985
986 Status = EmmcGetCsd (PassThru, Slot, Rca, &Csd);
987 if (EFI_ERROR (Status)) {
988 DEBUG ((EFI_D_ERROR, "EmmcSetBusMode: GetCsd fails with %r\n", Status));
989 return Status;
990 }
991
992 Status = EmmcSelect (PassThru, Slot, Rca);
993 if (EFI_ERROR (Status)) {
994 DEBUG ((EFI_D_ERROR, "EmmcSetBusMode: Select fails with %r\n", Status));
995 return Status;
996 }
997
998 ASSERT (Private->Capability[Slot].BaseClkFreq != 0);
999 //
1000 // Check if the Host Controller support 8bits bus width.
1001 //
1002 if (Private->Capability[Slot].BusWidth8 != 0) {
1003 BusWidth = 8;
1004 } else {
1005 BusWidth = 4;
1006 }
1007 //
1008 // Get Deivce_Type from EXT_CSD register.
1009 //
1010 Status = EmmcGetExtCsd (PassThru, Slot, &ExtCsd);
1011 if (EFI_ERROR (Status)) {
1012 DEBUG ((EFI_D_ERROR, "EmmcSetBusMode: GetExtCsd fails with %r\n", Status));
1013 return Status;
1014 }
1015 //
1016 // Calculate supported bus speed/bus width/clock frequency.
1017 //
1018 HsTiming = 0;
1019 IsDdr = FALSE;
1020 ClockFreq = 0;
1021 if (((ExtCsd.DeviceType & (BIT4 | BIT5)) != 0) && (Private->Capability[Slot].Sdr104 != 0)) {
1022 HsTiming = 2;
1023 IsDdr = FALSE;
1024 ClockFreq = 200;
1025 } else if (((ExtCsd.DeviceType & (BIT2 | BIT3)) != 0) && (Private->Capability[Slot].Ddr50 != 0)) {
1026 HsTiming = 1;
1027 IsDdr = TRUE;
1028 ClockFreq = 52;
1029 } else if (((ExtCsd.DeviceType & BIT1) != 0) && (Private->Capability[Slot].HighSpeed != 0)) {
1030 HsTiming = 1;
1031 IsDdr = FALSE;
1032 ClockFreq = 52;
1033 } else if (((ExtCsd.DeviceType & BIT0) != 0) && (Private->Capability[Slot].HighSpeed != 0)) {
1034 HsTiming = 1;
1035 IsDdr = FALSE;
1036 ClockFreq = 26;
1037 }
1038 //
1039 // Check if both of the device and the host controller support HS400 DDR mode.
1040 //
1041 if (((ExtCsd.DeviceType & (BIT6 | BIT7)) != 0) && (Private->Capability[Slot].Hs400 != 0)) {
1042 //
1043 // The host controller supports 8bits bus.
1044 //
1045 ASSERT (BusWidth == 8);
1046 HsTiming = 3;
1047 IsDdr = TRUE;
1048 ClockFreq = 200;
1049 }
1050
1051 if ((ClockFreq == 0) || (HsTiming == 0)) {
1052 //
1053 // Continue using default setting.
1054 //
1055 return EFI_SUCCESS;
1056 }
1057
1058 DEBUG ((EFI_D_INFO, "EmmcSetBusMode: HsTiming %d ClockFreq %d BusWidth %d Ddr %a\n", HsTiming, ClockFreq, BusWidth, IsDdr ? "TRUE":"FALSE"));
1059
1060 if (HsTiming == 3) {
1061 //
1062 // Execute HS400 timing switch procedure
1063 //
1064 Status = EmmcSwitchToHS400 (PciIo, PassThru, Slot, Rca, ClockFreq);
1065 } else if (HsTiming == 2) {
1066 //
1067 // Execute HS200 timing switch procedure
1068 //
1069 Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, BusWidth);
1070 } else {
1071 //
1072 // Execute High Speed timing switch procedure
1073 //
1074 Status = EmmcSwitchToHighSpeed (PciIo, PassThru, Slot, Rca, ClockFreq, BusWidth, IsDdr);
1075 }
1076
1077 DEBUG ((EFI_D_INFO, "EmmcSetBusMode: Switch to %a %r\n", (HsTiming == 3) ? "HS400" : ((HsTiming == 2) ? "HS200" : "HighSpeed"), Status));
1078
1079 return Status;
1080 }
1081
1082 /**
1083 Execute EMMC device identification procedure.
1084
1085 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
1086
1087 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1088 @param[in] Slot The slot number of the SD card to send the command to.
1089
1090 @retval EFI_SUCCESS There is a EMMC card.
1091 @retval Others There is not a EMMC card.
1092
1093 **/
1094 EFI_STATUS
1095 EmmcIdentification (
1096 IN SD_MMC_HC_PRIVATE_DATA *Private,
1097 IN UINT8 Slot
1098 )
1099 {
1100 EFI_STATUS Status;
1101 EFI_PCI_IO_PROTOCOL *PciIo;
1102 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
1103 UINT32 Ocr;
1104 UINT16 Rca;
1105
1106 PciIo = Private->PciIo;
1107 PassThru = &Private->PassThru;
1108
1109 Status = EmmcReset (PassThru, Slot);
1110 if (EFI_ERROR (Status)) {
1111 DEBUG ((EFI_D_VERBOSE, "EmmcIdentification: Executing Cmd0 fails with %r\n", Status));
1112 return Status;
1113 }
1114
1115 Ocr = 0;
1116 do {
1117 Status = EmmcGetOcr (PassThru, Slot, &Ocr);
1118 if (EFI_ERROR (Status)) {
1119 DEBUG ((EFI_D_VERBOSE, "EmmcIdentification: Executing Cmd1 fails with %r\n", Status));
1120 return Status;
1121 }
1122 Ocr |= BIT30;
1123 } while ((Ocr & BIT31) == 0);
1124
1125 Status = EmmcGetAllCid (PassThru, Slot);
1126 if (EFI_ERROR (Status)) {
1127 DEBUG ((EFI_D_VERBOSE, "EmmcIdentification: Executing Cmd2 fails with %r\n", Status));
1128 return Status;
1129 }
1130 //
1131 // Slot starts from 0 and valid RCA starts from 1.
1132 // Here we takes a simple formula to calculate the RCA.
1133 // Don't support multiple devices on the slot, that is
1134 // shared bus slot feature.
1135 //
1136 Rca = Slot + 1;
1137 Status = EmmcSetRca (PassThru, Slot, Rca);
1138 if (EFI_ERROR (Status)) {
1139 DEBUG ((EFI_D_ERROR, "EmmcIdentification: Executing Cmd3 fails with %r\n", Status));
1140 return Status;
1141 }
1142 //
1143 // Enter Data Tranfer Mode.
1144 //
1145 DEBUG ((EFI_D_INFO, "EmmcIdentification: Found a EMMC device at slot [%d], RCA [%d]\n", Slot, Rca));
1146 Private->Slot[Slot].CardType = EmmcCardType;
1147
1148 Status = EmmcSetBusMode (PciIo, PassThru, Slot, Rca);
1149
1150 return Status;
1151 }
1152