]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/EmmcDevice.c
MdeModulePkg/SdMmcPciHcDxe: Error handling enhance on tuning procedure
[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 - 2016, 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)) == 0) {
544 break;
545 }
546
547 if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {
548 return EFI_SUCCESS;
549 }
550 } while (++Retry < 40);
551
552 DEBUG ((EFI_D_ERROR, "EmmcTuningClkForHs200: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry, HostCtrl2));
553 //
554 // Abort the tuning procedure and reset the tuning circuit.
555 //
556 HostCtrl2 = (UINT8)~(BIT6 | BIT7);
557 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
558 if (EFI_ERROR (Status)) {
559 return Status;
560 }
561 return EFI_DEVICE_ERROR;
562 }
563
564 /**
565 Switch the bus width to specified width.
566
567 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.9 and SD Host Controller
568 Simplified Spec 3.0 Figure 3-7 for details.
569
570 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
571 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
572 @param[in] Slot The slot number of the SD card to send the command to.
573 @param[in] Rca The relative device address to be assigned.
574 @param[in] IsDdr If TRUE, use dual data rate data simpling method. Otherwise
575 use single data rate data simpling method.
576 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
577
578 @retval EFI_SUCCESS The operation is done correctly.
579 @retval Others The operation fails.
580
581 **/
582 EFI_STATUS
583 EmmcSwitchBusWidth (
584 IN EFI_PCI_IO_PROTOCOL *PciIo,
585 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
586 IN UINT8 Slot,
587 IN UINT16 Rca,
588 IN BOOLEAN IsDdr,
589 IN UINT8 BusWidth
590 )
591 {
592 EFI_STATUS Status;
593 UINT8 Access;
594 UINT8 Index;
595 UINT8 Value;
596 UINT8 CmdSet;
597 UINT32 DevStatus;
598
599 //
600 // Write Byte, the Value field is written into the byte pointed by Index.
601 //
602 Access = 0x03;
603 Index = OFFSET_OF (EMMC_EXT_CSD, BusWidth);
604 if (BusWidth == 4) {
605 Value = 1;
606 } else if (BusWidth == 8) {
607 Value = 2;
608 } else {
609 return EFI_INVALID_PARAMETER;
610 }
611
612 if (IsDdr) {
613 Value += 4;
614 }
615
616 CmdSet = 0;
617 Status = EmmcSwitch (PassThru, Slot, Access, Index, Value, CmdSet);
618 if (EFI_ERROR (Status)) {
619 DEBUG ((EFI_D_ERROR, "EmmcSwitchBusWidth: Switch to bus width %d fails with %r\n", BusWidth, Status));
620 return Status;
621 }
622
623 Status = EmmcSendStatus (PassThru, Slot, Rca, &DevStatus);
624 if (EFI_ERROR (Status)) {
625 DEBUG ((EFI_D_ERROR, "EmmcSwitchBusWidth: Send status fails with %r\n", Status));
626 return Status;
627 }
628 //
629 // Check the switch operation is really successful or not.
630 //
631 if ((DevStatus & BIT7) != 0) {
632 DEBUG ((EFI_D_ERROR, "EmmcSwitchBusWidth: The switch operation fails as DevStatus is 0x%08x\n", DevStatus));
633 return EFI_DEVICE_ERROR;
634 }
635
636 Status = SdMmcHcSetBusWidth (PciIo, Slot, BusWidth);
637
638 return Status;
639 }
640
641 /**
642 Switch the clock frequency to the specified value.
643
644 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6 and SD Host Controller
645 Simplified Spec 3.0 Figure 3-3 for details.
646
647 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
648 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
649 @param[in] Slot The slot number of the SD card to send the command to.
650 @param[in] Rca The relative device address to be assigned.
651 @param[in] HsTiming The value to be written to HS_TIMING field of EXT_CSD register.
652 @param[in] ClockFreq The max clock frequency to be set, the unit is MHz.
653
654 @retval EFI_SUCCESS The operation is done correctly.
655 @retval Others The operation fails.
656
657 **/
658 EFI_STATUS
659 EmmcSwitchClockFreq (
660 IN EFI_PCI_IO_PROTOCOL *PciIo,
661 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
662 IN UINT8 Slot,
663 IN UINT16 Rca,
664 IN UINT8 HsTiming,
665 IN UINT32 ClockFreq
666 )
667 {
668 EFI_STATUS Status;
669 UINT8 Access;
670 UINT8 Index;
671 UINT8 Value;
672 UINT8 CmdSet;
673 UINT32 DevStatus;
674 SD_MMC_HC_PRIVATE_DATA *Private;
675
676 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
677 //
678 // Write Byte, the Value field is written into the byte pointed by Index.
679 //
680 Access = 0x03;
681 Index = OFFSET_OF (EMMC_EXT_CSD, HsTiming);
682 Value = HsTiming;
683 CmdSet = 0;
684
685 Status = EmmcSwitch (PassThru, Slot, Access, Index, Value, CmdSet);
686 if (EFI_ERROR (Status)) {
687 DEBUG ((EFI_D_ERROR, "EmmcSwitchClockFreq: Switch to hstiming %d fails with %r\n", HsTiming, Status));
688 return Status;
689 }
690
691 Status = EmmcSendStatus (PassThru, Slot, Rca, &DevStatus);
692 if (EFI_ERROR (Status)) {
693 DEBUG ((EFI_D_ERROR, "EmmcSwitchClockFreq: Send status fails with %r\n", Status));
694 return Status;
695 }
696 //
697 // Check the switch operation is really successful or not.
698 //
699 if ((DevStatus & BIT7) != 0) {
700 DEBUG ((EFI_D_ERROR, "EmmcSwitchClockFreq: The switch operation fails as DevStatus is 0x%08x\n", DevStatus));
701 return EFI_DEVICE_ERROR;
702 }
703 //
704 // Convert the clock freq unit from MHz to KHz.
705 //
706 Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private->Capability[Slot]);
707
708 return Status;
709 }
710
711 /**
712 Switch to the High Speed timing according to request.
713
714 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
715 Simplified Spec 3.0 Figure 2-29 for details.
716
717 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
718 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
719 @param[in] Slot The slot number of the SD card to send the command to.
720 @param[in] Rca The relative device address to be assigned.
721 @param[in] ClockFreq The max clock frequency to be set.
722 @param[in] IsDdr If TRUE, use dual data rate data simpling method. Otherwise
723 use single data rate data simpling method.
724 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
725
726 @retval EFI_SUCCESS The operation is done correctly.
727 @retval Others The operation fails.
728
729 **/
730 EFI_STATUS
731 EmmcSwitchToHighSpeed (
732 IN EFI_PCI_IO_PROTOCOL *PciIo,
733 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
734 IN UINT8 Slot,
735 IN UINT16 Rca,
736 IN UINT32 ClockFreq,
737 IN BOOLEAN IsDdr,
738 IN UINT8 BusWidth
739 )
740 {
741 EFI_STATUS Status;
742 UINT8 HsTiming;
743 UINT8 HostCtrl1;
744 UINT8 HostCtrl2;
745
746 Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, IsDdr, BusWidth);
747 if (EFI_ERROR (Status)) {
748 return Status;
749 }
750 //
751 // Set to Hight Speed timing
752 //
753 HostCtrl1 = BIT2;
754 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1, sizeof (HostCtrl1), &HostCtrl1);
755 if (EFI_ERROR (Status)) {
756 return Status;
757 }
758
759 //
760 // Clean UHS Mode Select field of Host Control 2 reigster before update
761 //
762 HostCtrl2 = (UINT8)~0x7;
763 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
764 if (EFI_ERROR (Status)) {
765 return Status;
766 }
767 //
768 // Set UHS Mode Select field of Host Control 2 reigster to SDR12/25/50
769 //
770 if (IsDdr) {
771 HostCtrl2 = BIT2;
772 } else if (ClockFreq == 52) {
773 HostCtrl2 = BIT0;
774 } else {
775 HostCtrl2 = 0;
776 }
777 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
778 if (EFI_ERROR (Status)) {
779 return Status;
780 }
781
782 HsTiming = 1;
783 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, ClockFreq);
784 if (EFI_ERROR (Status)) {
785 return Status;
786 }
787
788 return Status;
789 }
790
791 /**
792 Switch to the HS200 timing according to request.
793
794 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
795 Simplified Spec 3.0 Figure 2-29 for details.
796
797 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
798 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
799 @param[in] Slot The slot number of the SD card to send the command to.
800 @param[in] Rca The relative device address to be assigned.
801 @param[in] ClockFreq The max clock frequency to be set.
802 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
803
804 @retval EFI_SUCCESS The operation is done correctly.
805 @retval Others The operation fails.
806
807 **/
808 EFI_STATUS
809 EmmcSwitchToHS200 (
810 IN EFI_PCI_IO_PROTOCOL *PciIo,
811 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
812 IN UINT8 Slot,
813 IN UINT16 Rca,
814 IN UINT32 ClockFreq,
815 IN UINT8 BusWidth
816 )
817 {
818 EFI_STATUS Status;
819 UINT8 HsTiming;
820 UINT8 HostCtrl2;
821 UINT16 ClockCtrl;
822
823 if ((BusWidth != 4) && (BusWidth != 8)) {
824 return EFI_INVALID_PARAMETER;
825 }
826
827 Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, FALSE, BusWidth);
828 if (EFI_ERROR (Status)) {
829 return Status;
830 }
831 //
832 // Set to HS200/SDR104 timing
833 //
834 //
835 // Stop bus clock at first
836 //
837 Status = SdMmcHcStopClock (PciIo, Slot);
838 if (EFI_ERROR (Status)) {
839 return Status;
840 }
841 //
842 // Clean UHS Mode Select field of Host Control 2 reigster before update
843 //
844 HostCtrl2 = (UINT8)~0x7;
845 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
846 if (EFI_ERROR (Status)) {
847 return Status;
848 }
849 //
850 // Set UHS Mode Select field of Host Control 2 reigster to SDR104
851 //
852 HostCtrl2 = BIT0 | BIT1;
853 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
854 if (EFI_ERROR (Status)) {
855 return Status;
856 }
857 //
858 // Wait Internal Clock Stable in the Clock Control register to be 1 before set SD Clock Enable bit
859 //
860 Status = SdMmcHcWaitMmioSet (
861 PciIo,
862 Slot,
863 SD_MMC_HC_CLOCK_CTRL,
864 sizeof (ClockCtrl),
865 BIT1,
866 BIT1,
867 SD_MMC_HC_GENERIC_TIMEOUT
868 );
869 if (EFI_ERROR (Status)) {
870 return Status;
871 }
872 //
873 // Set SD Clock Enable in the Clock Control register to 1
874 //
875 ClockCtrl = BIT2;
876 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_CLOCK_CTRL, sizeof (ClockCtrl), &ClockCtrl);
877
878 HsTiming = 2;
879 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, ClockFreq);
880 if (EFI_ERROR (Status)) {
881 return Status;
882 }
883
884 Status = EmmcTuningClkForHs200 (PciIo, PassThru, Slot, BusWidth);
885
886 return Status;
887 }
888
889 /**
890 Switch to the HS400 timing according to request.
891
892 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
893 Simplified Spec 3.0 Figure 2-29 for details.
894
895 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
896 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
897 @param[in] Slot The slot number of the SD card to send the command to.
898 @param[in] Rca The relative device address to be assigned.
899 @param[in] ClockFreq The max clock frequency to be set.
900
901 @retval EFI_SUCCESS The operation is done correctly.
902 @retval Others The operation fails.
903
904 **/
905 EFI_STATUS
906 EmmcSwitchToHS400 (
907 IN EFI_PCI_IO_PROTOCOL *PciIo,
908 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
909 IN UINT8 Slot,
910 IN UINT16 Rca,
911 IN UINT32 ClockFreq
912 )
913 {
914 EFI_STATUS Status;
915 UINT8 HsTiming;
916 UINT8 HostCtrl2;
917
918 Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, 8);
919 if (EFI_ERROR (Status)) {
920 return Status;
921 }
922 //
923 // Set to Hight Speed timing and set the clock frequency to a value less than 52MHz.
924 //
925 HsTiming = 1;
926 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, 52);
927 if (EFI_ERROR (Status)) {
928 return Status;
929 }
930 //
931 // HS400 mode must use 8 data lines.
932 //
933 Status = EmmcSwitchBusWidth (PciIo, PassThru, Slot, Rca, TRUE, 8);
934 if (EFI_ERROR (Status)) {
935 return Status;
936 }
937 //
938 // Clean UHS Mode Select field of Host Control 2 reigster before update
939 //
940 HostCtrl2 = (UINT8)~0x7;
941 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
942 if (EFI_ERROR (Status)) {
943 return Status;
944 }
945 //
946 // Set UHS Mode Select field of Host Control 2 reigster to HS400
947 //
948 HostCtrl2 = BIT0 | BIT2;
949 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
950 if (EFI_ERROR (Status)) {
951 return Status;
952 }
953
954 HsTiming = 3;
955 Status = EmmcSwitchClockFreq (PciIo, PassThru, Slot, Rca, HsTiming, ClockFreq);
956
957 return Status;
958 }
959
960 /**
961 Switch the high speed timing according to request.
962
963 Refer to EMMC Electrical Standard Spec 5.1 Section 6.6.8 and SD Host Controller
964 Simplified Spec 3.0 Figure 2-29 for details.
965
966 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
967 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
968 @param[in] Slot The slot number of the SD card to send the command to.
969 @param[in] Rca The relative device address to be assigned.
970
971 @retval EFI_SUCCESS The operation is done correctly.
972 @retval Others The operation fails.
973
974 **/
975 EFI_STATUS
976 EmmcSetBusMode (
977 IN EFI_PCI_IO_PROTOCOL *PciIo,
978 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
979 IN UINT8 Slot,
980 IN UINT16 Rca
981 )
982 {
983 EFI_STATUS Status;
984 EMMC_CSD Csd;
985 EMMC_EXT_CSD ExtCsd;
986 UINT8 HsTiming;
987 BOOLEAN IsDdr;
988 UINT32 ClockFreq;
989 UINT8 BusWidth;
990 SD_MMC_HC_PRIVATE_DATA *Private;
991
992 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
993
994 Status = EmmcGetCsd (PassThru, Slot, Rca, &Csd);
995 if (EFI_ERROR (Status)) {
996 DEBUG ((EFI_D_ERROR, "EmmcSetBusMode: GetCsd fails with %r\n", Status));
997 return Status;
998 }
999
1000 Status = EmmcSelect (PassThru, Slot, Rca);
1001 if (EFI_ERROR (Status)) {
1002 DEBUG ((EFI_D_ERROR, "EmmcSetBusMode: Select fails with %r\n", Status));
1003 return Status;
1004 }
1005
1006 ASSERT (Private->Capability[Slot].BaseClkFreq != 0);
1007 //
1008 // Check if the Host Controller support 8bits bus width.
1009 //
1010 if (Private->Capability[Slot].BusWidth8 != 0) {
1011 BusWidth = 8;
1012 } else {
1013 BusWidth = 4;
1014 }
1015 //
1016 // Get Deivce_Type from EXT_CSD register.
1017 //
1018 Status = EmmcGetExtCsd (PassThru, Slot, &ExtCsd);
1019 if (EFI_ERROR (Status)) {
1020 DEBUG ((EFI_D_ERROR, "EmmcSetBusMode: GetExtCsd fails with %r\n", Status));
1021 return Status;
1022 }
1023 //
1024 // Calculate supported bus speed/bus width/clock frequency.
1025 //
1026 HsTiming = 0;
1027 IsDdr = FALSE;
1028 ClockFreq = 0;
1029 if (((ExtCsd.DeviceType & (BIT4 | BIT5)) != 0) && (Private->Capability[Slot].Sdr104 != 0)) {
1030 HsTiming = 2;
1031 IsDdr = FALSE;
1032 ClockFreq = 200;
1033 } else if (((ExtCsd.DeviceType & (BIT2 | BIT3)) != 0) && (Private->Capability[Slot].Ddr50 != 0)) {
1034 HsTiming = 1;
1035 IsDdr = TRUE;
1036 ClockFreq = 52;
1037 } else if (((ExtCsd.DeviceType & BIT1) != 0) && (Private->Capability[Slot].HighSpeed != 0)) {
1038 HsTiming = 1;
1039 IsDdr = FALSE;
1040 ClockFreq = 52;
1041 } else if (((ExtCsd.DeviceType & BIT0) != 0) && (Private->Capability[Slot].HighSpeed != 0)) {
1042 HsTiming = 1;
1043 IsDdr = FALSE;
1044 ClockFreq = 26;
1045 }
1046 //
1047 // Check if both of the device and the host controller support HS400 DDR mode.
1048 //
1049 if (((ExtCsd.DeviceType & (BIT6 | BIT7)) != 0) && (Private->Capability[Slot].Hs400 != 0)) {
1050 //
1051 // The host controller supports 8bits bus.
1052 //
1053 ASSERT (BusWidth == 8);
1054 HsTiming = 3;
1055 IsDdr = TRUE;
1056 ClockFreq = 200;
1057 }
1058
1059 if ((ClockFreq == 0) || (HsTiming == 0)) {
1060 //
1061 // Continue using default setting.
1062 //
1063 return EFI_SUCCESS;
1064 }
1065
1066 DEBUG ((EFI_D_INFO, "EmmcSetBusMode: HsTiming %d ClockFreq %d BusWidth %d Ddr %a\n", HsTiming, ClockFreq, BusWidth, IsDdr ? "TRUE":"FALSE"));
1067
1068 if (HsTiming == 3) {
1069 //
1070 // Execute HS400 timing switch procedure
1071 //
1072 Status = EmmcSwitchToHS400 (PciIo, PassThru, Slot, Rca, ClockFreq);
1073 } else if (HsTiming == 2) {
1074 //
1075 // Execute HS200 timing switch procedure
1076 //
1077 Status = EmmcSwitchToHS200 (PciIo, PassThru, Slot, Rca, ClockFreq, BusWidth);
1078 } else {
1079 //
1080 // Execute High Speed timing switch procedure
1081 //
1082 Status = EmmcSwitchToHighSpeed (PciIo, PassThru, Slot, Rca, ClockFreq, BusWidth, IsDdr);
1083 }
1084
1085 DEBUG ((EFI_D_INFO, "EmmcSetBusMode: Switch to %a %r\n", (HsTiming == 3) ? "HS400" : ((HsTiming == 2) ? "HS200" : "HighSpeed"), Status));
1086
1087 return Status;
1088 }
1089
1090 /**
1091 Execute EMMC device identification procedure.
1092
1093 Refer to EMMC Electrical Standard Spec 5.1 Section 6.4 for details.
1094
1095 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
1096 @param[in] Slot The slot number of the SD card to send the command to.
1097
1098 @retval EFI_SUCCESS There is a EMMC card.
1099 @retval Others There is not a EMMC card.
1100
1101 **/
1102 EFI_STATUS
1103 EmmcIdentification (
1104 IN SD_MMC_HC_PRIVATE_DATA *Private,
1105 IN UINT8 Slot
1106 )
1107 {
1108 EFI_STATUS Status;
1109 EFI_PCI_IO_PROTOCOL *PciIo;
1110 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
1111 UINT32 Ocr;
1112 UINT16 Rca;
1113
1114 PciIo = Private->PciIo;
1115 PassThru = &Private->PassThru;
1116
1117 Status = EmmcReset (PassThru, Slot);
1118 if (EFI_ERROR (Status)) {
1119 DEBUG ((EFI_D_VERBOSE, "EmmcIdentification: Executing Cmd0 fails with %r\n", Status));
1120 return Status;
1121 }
1122
1123 Ocr = 0;
1124 do {
1125 Status = EmmcGetOcr (PassThru, Slot, &Ocr);
1126 if (EFI_ERROR (Status)) {
1127 DEBUG ((EFI_D_VERBOSE, "EmmcIdentification: Executing Cmd1 fails with %r\n", Status));
1128 return Status;
1129 }
1130 Ocr |= BIT30;
1131 } while ((Ocr & BIT31) == 0);
1132
1133 Status = EmmcGetAllCid (PassThru, Slot);
1134 if (EFI_ERROR (Status)) {
1135 DEBUG ((EFI_D_VERBOSE, "EmmcIdentification: Executing Cmd2 fails with %r\n", Status));
1136 return Status;
1137 }
1138 //
1139 // Slot starts from 0 and valid RCA starts from 1.
1140 // Here we takes a simple formula to calculate the RCA.
1141 // Don't support multiple devices on the slot, that is
1142 // shared bus slot feature.
1143 //
1144 Rca = Slot + 1;
1145 Status = EmmcSetRca (PassThru, Slot, Rca);
1146 if (EFI_ERROR (Status)) {
1147 DEBUG ((EFI_D_ERROR, "EmmcIdentification: Executing Cmd3 fails with %r\n", Status));
1148 return Status;
1149 }
1150 //
1151 // Enter Data Tranfer Mode.
1152 //
1153 DEBUG ((EFI_D_INFO, "EmmcIdentification: Found a EMMC device at slot [%d], RCA [%d]\n", Slot, Rca));
1154 Private->Slot[Slot].CardType = EmmcCardType;
1155
1156 Status = EmmcSetBusMode (PciIo, PassThru, Slot, Rca);
1157
1158 return Status;
1159 }
1160