]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/SdMmcPciHcDxe/SdDevice.c
MdeModulePkg/NvmExpressPei: Consume S3StorageDeviceInitList LockBox
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / SdMmcPciHcDxe / SdDevice.c
1 /** @file
2 This file provides some helper functions which are specific for SD card device.
3
4 Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
5 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "SdMmcPciHcDxe.h"
17
18 /**
19 Send command GO_IDLE_STATE to the device to make it go to Idle State.
20
21 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 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 SD device is reset correctly.
27 @retval Others The device reset fails.
28
29 **/
30 EFI_STATUS
31 SdCardReset (
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 = SD_GO_IDLE_STATE;
50 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBc;
51
52 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
53
54 return Status;
55 }
56
57 /**
58 Send command SEND_IF_COND to the device to inquiry the SD Memory Card interface
59 condition.
60
61 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
62
63 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
64 @param[in] Slot The slot number of the SD card to send the command to.
65 @param[in] SupplyVoltage The supplied voltage by the host.
66 @param[in] CheckPattern The check pattern to be sent to the device.
67
68 @retval EFI_SUCCESS The operation is done correctly.
69 @retval Others The operation fails.
70
71 **/
72 EFI_STATUS
73 SdCardVoltageCheck (
74 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
75 IN UINT8 Slot,
76 IN UINT8 SupplyVoltage,
77 IN UINT8 CheckPattern
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 = SD_SEND_IF_COND;
94 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
95 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR7;
96 SdMmcCmdBlk.CommandArgument = (SupplyVoltage << 8) | CheckPattern;
97
98 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
99
100 if (!EFI_ERROR (Status)) {
101 if (SdMmcStatusBlk.Resp0 != SdMmcCmdBlk.CommandArgument) {
102 return EFI_DEVICE_ERROR;
103 }
104 }
105
106 return Status;
107 }
108
109 /**
110 Send command SDIO_SEND_OP_COND to the device to see whether it is SDIO device.
111
112 Refer to SDIO Simplified Spec 3 Section 3.2 for details.
113
114 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
115 @param[in] Slot The slot number of the SD card to send the command to.
116 @param[in] VoltageWindow The supply voltage window.
117 @param[in] S18R The boolean to show if it should switch to 1.8v.
118
119 @retval EFI_SUCCESS The operation is done correctly.
120 @retval Others The operation fails.
121
122 **/
123 EFI_STATUS
124 SdioSendOpCond (
125 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
126 IN UINT8 Slot,
127 IN UINT32 VoltageWindow,
128 IN BOOLEAN S18R
129 )
130 {
131 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
132 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
133 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
134 EFI_STATUS Status;
135 UINT32 Switch;
136
137 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
138 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
139 ZeroMem (&Packet, sizeof (Packet));
140
141 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
142 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
143 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
144
145 SdMmcCmdBlk.CommandIndex = SDIO_SEND_OP_COND;
146 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
147 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR4;
148
149 Switch = S18R ? BIT24 : 0;
150
151 SdMmcCmdBlk.CommandArgument = (VoltageWindow & 0xFFFFFF) | Switch;
152
153 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
154
155 return Status;
156 }
157
158 /**
159 Send command SD_SEND_OP_COND to the device to see whether it is SDIO device.
160
161 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
162
163 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
164 @param[in] Slot The slot number of the SD card to send the command to.
165 @param[in] Rca The relative device address of addressed device.
166 @param[in] VoltageWindow The supply voltage window.
167 @param[in] S18R The boolean to show if it should switch to 1.8v.
168 @param[in] Xpc The boolean to show if it should provide 0.36w power control.
169 @param[in] Hcs The boolean to show if it support host capacity info.
170 @param[out] Ocr The buffer to store returned OCR register value.
171
172 @retval EFI_SUCCESS The operation is done correctly.
173 @retval Others The operation fails.
174
175 **/
176 EFI_STATUS
177 SdCardSendOpCond (
178 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
179 IN UINT8 Slot,
180 IN UINT16 Rca,
181 IN UINT32 VoltageWindow,
182 IN BOOLEAN S18R,
183 IN BOOLEAN Xpc,
184 IN BOOLEAN Hcs,
185 OUT UINT32 *Ocr
186 )
187 {
188 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
189 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
190 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
191 EFI_STATUS Status;
192 UINT32 Switch;
193 UINT32 MaxPower;
194 UINT32 HostCapacity;
195
196 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
197 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
198 ZeroMem (&Packet, sizeof (Packet));
199
200 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
201 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
202 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
203
204 SdMmcCmdBlk.CommandIndex = SD_APP_CMD;
205 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
206 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
207 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
208
209 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
210 if (EFI_ERROR (Status)) {
211 return Status;
212 }
213
214 SdMmcCmdBlk.CommandIndex = SD_SEND_OP_COND;
215 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
216 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR3;
217
218 Switch = S18R ? BIT24 : 0;
219 MaxPower = Xpc ? BIT28 : 0;
220 HostCapacity = Hcs ? BIT30 : 0;
221
222 SdMmcCmdBlk.CommandArgument = (VoltageWindow & 0xFFFFFF) | Switch | MaxPower | HostCapacity;
223
224 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
225 if (!EFI_ERROR (Status)) {
226 //
227 // For details, refer to SD Host Controller Simplified Spec 3.0 Table 2-12.
228 //
229 *Ocr = SdMmcStatusBlk.Resp0;
230 }
231
232 return Status;
233 }
234
235 /**
236 Broadcast command ALL_SEND_CID to the bus to ask all the SD devices to send the
237 data of their CID registers.
238
239 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
240
241 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
242 @param[in] Slot The slot number of the SD card to send the command to.
243
244 @retval EFI_SUCCESS The operation is done correctly.
245 @retval Others The operation fails.
246
247 **/
248 EFI_STATUS
249 SdCardAllSendCid (
250 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
251 IN UINT8 Slot
252 )
253 {
254 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
255 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
256 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
257 EFI_STATUS Status;
258
259 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
260 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
261 ZeroMem (&Packet, sizeof (Packet));
262
263 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
264 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
265 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
266
267 SdMmcCmdBlk.CommandIndex = SD_ALL_SEND_CID;
268 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
269 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR2;
270
271 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
272
273 return Status;
274 }
275
276 /**
277 Send command SET_RELATIVE_ADDR to the SD device to assign a Relative device
278 Address (RCA).
279
280 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
281
282 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
283 @param[in] Slot The slot number of the SD card to send the command to.
284 @param[out] Rca The relative device address to assign.
285
286 @retval EFI_SUCCESS The operation is done correctly.
287 @retval Others The operation fails.
288
289 **/
290 EFI_STATUS
291 SdCardSetRca (
292 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
293 IN UINT8 Slot,
294 OUT UINT16 *Rca
295 )
296 {
297 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
298 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
299 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
300 EFI_STATUS Status;
301
302 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
303 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
304 ZeroMem (&Packet, sizeof (Packet));
305
306 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
307 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
308 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
309
310 SdMmcCmdBlk.CommandIndex = SD_SET_RELATIVE_ADDR;
311 SdMmcCmdBlk.CommandType = SdMmcCommandTypeBcr;
312 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR6;
313
314 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
315 if (!EFI_ERROR (Status)) {
316 *Rca = (UINT16)(SdMmcStatusBlk.Resp0 >> 16);
317 }
318
319 return Status;
320 }
321
322
323
324
325
326 /**
327 Send command SELECT_DESELECT_CARD to the SD device to select/deselect it.
328
329 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
330
331 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
332 @param[in] Slot The slot number of the SD card to send the command to.
333 @param[in] Rca The relative device address of selected device.
334
335 @retval EFI_SUCCESS The operation is done correctly.
336 @retval Others The operation fails.
337
338 **/
339 EFI_STATUS
340 SdCardSelect (
341 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
342 IN UINT8 Slot,
343 IN UINT16 Rca
344 )
345 {
346 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
347 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
348 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
349 EFI_STATUS Status;
350
351 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
352 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
353 ZeroMem (&Packet, sizeof (Packet));
354
355 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
356 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
357 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
358
359 SdMmcCmdBlk.CommandIndex = SD_SELECT_DESELECT_CARD;
360 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
361 if (Rca != 0) {
362 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
363 }
364 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
365
366 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
367
368 return Status;
369 }
370
371 /**
372 Send command VOLTAGE_SWITCH to the SD device to switch the voltage of the device.
373
374 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
375
376 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
377 @param[in] Slot The slot number of the SD card to send the command to.
378
379 @retval EFI_SUCCESS The operation is done correctly.
380 @retval Others The operation fails.
381
382 **/
383 EFI_STATUS
384 SdCardVoltageSwitch (
385 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
386 IN UINT8 Slot
387 )
388 {
389 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
390 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
391 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
392 EFI_STATUS Status;
393
394 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
395 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
396 ZeroMem (&Packet, sizeof (Packet));
397
398 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
399 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
400 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
401
402 SdMmcCmdBlk.CommandIndex = SD_VOLTAGE_SWITCH;
403 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
404 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
405 SdMmcCmdBlk.CommandArgument = 0;
406
407 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
408
409 return Status;
410 }
411
412 /**
413 Send command SET_BUS_WIDTH to the SD device to set the bus width.
414
415 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
416
417 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
418 @param[in] Slot The slot number of the SD card to send the command to.
419 @param[in] Rca The relative device address of addressed device.
420 @param[in] BusWidth The bus width to be set, it could be 1 or 4.
421
422 @retval EFI_SUCCESS The operation is done correctly.
423 @retval Others The operation fails.
424
425 **/
426 EFI_STATUS
427 SdCardSetBusWidth (
428 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
429 IN UINT8 Slot,
430 IN UINT16 Rca,
431 IN UINT8 BusWidth
432 )
433 {
434 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
435 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
436 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
437 EFI_STATUS Status;
438 UINT8 Value;
439
440 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
441 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
442 ZeroMem (&Packet, sizeof (Packet));
443
444 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
445 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
446 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
447
448 SdMmcCmdBlk.CommandIndex = SD_APP_CMD;
449 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
450 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
451 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
452
453 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
454 if (EFI_ERROR (Status)) {
455 return Status;
456 }
457
458 SdMmcCmdBlk.CommandIndex = SD_SET_BUS_WIDTH;
459 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
460 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
461
462 if (BusWidth == 1) {
463 Value = 0;
464 } else if (BusWidth == 4) {
465 Value = 2;
466 } else {
467 return EFI_INVALID_PARAMETER;
468 }
469
470 SdMmcCmdBlk.CommandArgument = Value & 0x3;
471
472 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
473 return Status;
474 }
475
476 /**
477 Send command SWITCH_FUNC to the SD device to check switchable function or switch card function.
478
479 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
480
481 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
482 @param[in] Slot The slot number of the SD card to send the command to.
483 @param[in] AccessMode The value for access mode group.
484 @param[in] CommandSystem The value for command set group.
485 @param[in] DriveStrength The value for drive length group.
486 @param[in] PowerLimit The value for power limit group.
487 @param[in] Mode Switch or check function.
488 @param[out] SwitchResp The return switch function status.
489
490 @retval EFI_SUCCESS The operation is done correctly.
491 @retval Others The operation fails.
492
493 **/
494 EFI_STATUS
495 SdCardSwitch (
496 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
497 IN UINT8 Slot,
498 IN UINT8 AccessMode,
499 IN UINT8 CommandSystem,
500 IN UINT8 DriveStrength,
501 IN UINT8 PowerLimit,
502 IN BOOLEAN Mode,
503 OUT UINT8 *SwitchResp
504 )
505 {
506 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
507 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
508 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
509 EFI_STATUS Status;
510 UINT32 ModeValue;
511
512 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
513 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
514 ZeroMem (&Packet, sizeof (Packet));
515
516 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
517 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
518 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
519
520 SdMmcCmdBlk.CommandIndex = SD_SWITCH_FUNC;
521 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
522 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
523
524 ModeValue = Mode ? BIT31 : 0;
525 SdMmcCmdBlk.CommandArgument = (AccessMode & 0xF) | ((PowerLimit & 0xF) << 4) | \
526 ((DriveStrength & 0xF) << 8) | ((DriveStrength & 0xF) << 12) | \
527 ModeValue;
528
529 Packet.InDataBuffer = SwitchResp;
530 Packet.InTransferLength = 64;
531
532 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
533
534 return Status;
535 }
536
537 /**
538 Send command SEND_STATUS to the addressed SD device to get its status register.
539
540 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
541
542 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
543 @param[in] Slot The slot number of the SD card to send the command to.
544 @param[in] Rca The relative device address of addressed device.
545 @param[out] DevStatus The returned device status.
546
547 @retval EFI_SUCCESS The operation is done correctly.
548 @retval Others The operation fails.
549
550 **/
551 EFI_STATUS
552 SdCardSendStatus (
553 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
554 IN UINT8 Slot,
555 IN UINT16 Rca,
556 OUT UINT32 *DevStatus
557 )
558 {
559 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
560 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
561 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
562 EFI_STATUS Status;
563
564 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
565 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
566 ZeroMem (&Packet, sizeof (Packet));
567
568 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
569 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
570 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
571
572 SdMmcCmdBlk.CommandIndex = SD_SEND_STATUS;
573 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAc;
574 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
575 SdMmcCmdBlk.CommandArgument = (UINT32)Rca << 16;
576
577 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
578 if (!EFI_ERROR (Status)) {
579 *DevStatus = SdMmcStatusBlk.Resp0;
580 }
581
582 return Status;
583 }
584
585 /**
586 Send command SEND_TUNING_BLOCK to the SD device for HS200 optimal sampling point
587 detection.
588
589 It may be sent up to 40 times until the host finishes the tuning procedure.
590
591 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 for details.
592
593 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
594 @param[in] Slot The slot number of the SD card to send the command to.
595
596 @retval EFI_SUCCESS The operation is done correctly.
597 @retval Others The operation fails.
598
599 **/
600 EFI_STATUS
601 SdCardSendTuningBlk (
602 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
603 IN UINT8 Slot
604 )
605 {
606 EFI_SD_MMC_COMMAND_BLOCK SdMmcCmdBlk;
607 EFI_SD_MMC_STATUS_BLOCK SdMmcStatusBlk;
608 EFI_SD_MMC_PASS_THRU_COMMAND_PACKET Packet;
609 EFI_STATUS Status;
610 UINT8 TuningBlock[64];
611
612 ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
613 ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
614 ZeroMem (&Packet, sizeof (Packet));
615
616 Packet.SdMmcCmdBlk = &SdMmcCmdBlk;
617 Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
618 Packet.Timeout = SD_MMC_HC_GENERIC_TIMEOUT;
619
620 SdMmcCmdBlk.CommandIndex = SD_SEND_TUNING_BLOCK;
621 SdMmcCmdBlk.CommandType = SdMmcCommandTypeAdtc;
622 SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1;
623 SdMmcCmdBlk.CommandArgument = 0;
624
625 Packet.InDataBuffer = TuningBlock;
626 Packet.InTransferLength = sizeof (TuningBlock);
627
628 Status = SdMmcPassThruPassThru (PassThru, Slot, &Packet, NULL);
629
630 return Status;
631 }
632
633 /**
634 Tunning the sampling point of SDR104 or SDR50 bus speed mode.
635
636 Command SD_SEND_TUNING_BLOCK may be sent up to 40 times until the host finishes the
637 tuning procedure.
638
639 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 and
640 SD Host Controller Simplified Spec 3.0 section Figure 3-7 for details.
641
642 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
643 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
644 @param[in] Slot The slot number of the SD card to send the command to.
645
646 @retval EFI_SUCCESS The operation is done correctly.
647 @retval Others The operation fails.
648
649 **/
650 EFI_STATUS
651 SdCardTuningClock (
652 IN EFI_PCI_IO_PROTOCOL *PciIo,
653 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
654 IN UINT8 Slot
655 )
656 {
657 EFI_STATUS Status;
658 UINT8 HostCtrl2;
659 UINT8 Retry;
660
661 //
662 // Notify the host that the sampling clock tuning procedure starts.
663 //
664 HostCtrl2 = BIT6;
665 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
666 if (EFI_ERROR (Status)) {
667 return Status;
668 }
669 //
670 // Ask the device to send a sequence of tuning blocks till the tuning procedure is done.
671 //
672 Retry = 0;
673 do {
674 Status = SdCardSendTuningBlk (PassThru, Slot);
675 if (EFI_ERROR (Status)) {
676 DEBUG ((DEBUG_ERROR, "SdCardSendTuningBlk: Send tuning block fails with %r\n", Status));
677 return Status;
678 }
679
680 Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2);
681 if (EFI_ERROR (Status)) {
682 return Status;
683 }
684
685 if ((HostCtrl2 & (BIT6 | BIT7)) == 0) {
686 break;
687 }
688 if ((HostCtrl2 & (BIT6 | BIT7)) == BIT7) {
689 return EFI_SUCCESS;
690 }
691 } while (++Retry < 40);
692
693 DEBUG ((DEBUG_ERROR, "SdCardTuningClock: Send tuning block fails at %d times with HostCtrl2 %02x\n", Retry, HostCtrl2));
694 //
695 // Abort the tuning procedure and reset the tuning circuit.
696 //
697 HostCtrl2 = (UINT8)~(BIT6 | BIT7);
698 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
699 if (EFI_ERROR (Status)) {
700 return Status;
701 }
702 return EFI_DEVICE_ERROR;
703 }
704
705 /**
706 Switch the bus width to specified width.
707
708 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 and
709 SD Host Controller Simplified Spec 3.0 section Figure 3-7 for details.
710
711 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
712 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
713 @param[in] Slot The slot number of the SD card to send the command to.
714 @param[in] Rca The relative device address to be assigned.
715 @param[in] BusWidth The bus width to be set, it could be 4 or 8.
716
717 @retval EFI_SUCCESS The operation is done correctly.
718 @retval Others The operation fails.
719
720 **/
721 EFI_STATUS
722 SdCardSwitchBusWidth (
723 IN EFI_PCI_IO_PROTOCOL *PciIo,
724 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
725 IN UINT8 Slot,
726 IN UINT16 Rca,
727 IN UINT8 BusWidth
728 )
729 {
730 EFI_STATUS Status;
731 UINT32 DevStatus;
732
733 Status = SdCardSetBusWidth (PassThru, Slot, Rca, BusWidth);
734 if (EFI_ERROR (Status)) {
735 DEBUG ((DEBUG_ERROR, "SdCardSwitchBusWidth: Switch to bus width %d fails with %r\n", BusWidth, Status));
736 return Status;
737 }
738
739 Status = SdCardSendStatus (PassThru, Slot, Rca, &DevStatus);
740 if (EFI_ERROR (Status)) {
741 DEBUG ((DEBUG_ERROR, "SdCardSwitchBusWidth: Send status fails with %r\n", Status));
742 return Status;
743 }
744 //
745 // Check the switch operation is really successful or not.
746 //
747 if ((DevStatus >> 16) != 0) {
748 DEBUG ((DEBUG_ERROR, "SdCardSwitchBusWidth: The switch operation fails as DevStatus is 0x%08x\n", DevStatus));
749 return EFI_DEVICE_ERROR;
750 }
751
752 Status = SdMmcHcSetBusWidth (PciIo, Slot, BusWidth);
753
754 return Status;
755 }
756
757 /**
758 Switch the high speed timing according to request.
759
760 Refer to SD Physical Layer Simplified Spec 4.1 Section 4.7 and
761 SD Host Controller Simplified Spec 3.0 section Figure 2-29 for details.
762
763 @param[in] PciIo A pointer to the EFI_PCI_IO_PROTOCOL instance.
764 @param[in] PassThru A pointer to the EFI_SD_MMC_PASS_THRU_PROTOCOL instance.
765 @param[in] Slot The slot number of the SD card to send the command to.
766 @param[in] Rca The relative device address to be assigned.
767 @param[in] S18A The boolean to show if it's a UHS-I SD card.
768
769 @retval EFI_SUCCESS The operation is done correctly.
770 @retval Others The operation fails.
771
772 **/
773 EFI_STATUS
774 SdCardSetBusMode (
775 IN EFI_PCI_IO_PROTOCOL *PciIo,
776 IN EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru,
777 IN UINT8 Slot,
778 IN UINT16 Rca,
779 IN BOOLEAN S18A
780 )
781 {
782 EFI_STATUS Status;
783 SD_MMC_HC_SLOT_CAP *Capability;
784 UINT32 ClockFreq;
785 UINT8 BusWidth;
786 UINT8 AccessMode;
787 UINT8 HostCtrl1;
788 UINT8 SwitchResp[64];
789 SD_MMC_BUS_MODE Timing;
790 SD_MMC_HC_PRIVATE_DATA *Private;
791
792 Private = SD_MMC_HC_PRIVATE_FROM_THIS (PassThru);
793
794 Capability = &Private->Capability[Slot];
795
796 Status = SdCardSelect (PassThru, Slot, Rca);
797 if (EFI_ERROR (Status)) {
798 return Status;
799 }
800
801 BusWidth = 4;
802
803 Status = SdCardSwitchBusWidth (PciIo, PassThru, Slot, Rca, BusWidth);
804 if (EFI_ERROR (Status)) {
805 return Status;
806 }
807 //
808 // Get the supported bus speed from SWITCH cmd return data group #1.
809 //
810 Status = SdCardSwitch (PassThru, Slot, 0xF, 0xF, 0xF, 0xF, FALSE, SwitchResp);
811 if (EFI_ERROR (Status)) {
812 return Status;
813 }
814 //
815 // Calculate supported bus speed/bus width/clock frequency by host and device capability.
816 //
817 ClockFreq = 0;
818 if (S18A && (Capability->Sdr104 != 0) && ((SwitchResp[13] & BIT3) != 0)) {
819 ClockFreq = 208;
820 AccessMode = 3;
821 Timing = SdMmcUhsSdr104;
822 } else if (S18A && (Capability->Sdr50 != 0) && ((SwitchResp[13] & BIT2) != 0)) {
823 ClockFreq = 100;
824 AccessMode = 2;
825 Timing = SdMmcUhsSdr50;
826 } else if (S18A && (Capability->Ddr50 != 0) && ((SwitchResp[13] & BIT4) != 0)) {
827 ClockFreq = 50;
828 AccessMode = 4;
829 Timing = SdMmcUhsDdr50;
830 } else if ((SwitchResp[13] & BIT1) != 0) {
831 ClockFreq = 50;
832 AccessMode = 1;
833 Timing = SdMmcUhsSdr25;
834 } else {
835 ClockFreq = 25;
836 AccessMode = 0;
837 Timing = SdMmcUhsSdr12;
838 }
839
840 Status = SdCardSwitch (PassThru, Slot, AccessMode, 0xF, 0xF, 0xF, TRUE, SwitchResp);
841 if (EFI_ERROR (Status)) {
842 return Status;
843 }
844
845 if ((SwitchResp[16] & 0xF) != AccessMode) {
846 DEBUG ((DEBUG_ERROR, "SdCardSetBusMode: Switch to AccessMode %d ClockFreq %d BusWidth %d fails! The Switch response is 0x%1x\n", AccessMode, ClockFreq, BusWidth, SwitchResp[16] & 0xF));
847 return EFI_DEVICE_ERROR;
848 }
849
850 DEBUG ((DEBUG_INFO, "SdCardSetBusMode: Switch to AccessMode %d ClockFreq %d BusWidth %d\n", AccessMode, ClockFreq, BusWidth));
851
852 //
853 // Set to Hight Speed timing
854 //
855 if (AccessMode == 1) {
856 HostCtrl1 = BIT2;
857 Status = SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL1, sizeof (HostCtrl1), &HostCtrl1);
858 if (EFI_ERROR (Status)) {
859 return Status;
860 }
861 }
862
863 Status = SdMmcHcUhsSignaling (Private->ControllerHandle, PciIo, Slot, Timing);
864 if (EFI_ERROR (Status)) {
865 return Status;
866 }
867
868 Status = SdMmcHcClockSupply (PciIo, Slot, ClockFreq * 1000, Private->BaseClkFreq[Slot], Private->ControllerVersion[Slot]);
869 if (EFI_ERROR (Status)) {
870 return Status;
871 }
872
873 if (mOverride != NULL && mOverride->NotifyPhase != NULL) {
874 Status = mOverride->NotifyPhase (
875 Private->ControllerHandle,
876 Slot,
877 EdkiiSdMmcSwitchClockFreqPost,
878 &Timing
879 );
880 if (EFI_ERROR (Status)) {
881 DEBUG ((
882 DEBUG_ERROR,
883 "%a: SD/MMC switch clock freq post notifier callback failed - %r\n",
884 __FUNCTION__,
885 Status
886 ));
887 return Status;
888 }
889 }
890
891 if ((AccessMode == 3) || ((AccessMode == 2) && (Capability->TuningSDR50 != 0))) {
892 Status = SdCardTuningClock (PciIo, PassThru, Slot);
893 if (EFI_ERROR (Status)) {
894 return Status;
895 }
896 }
897
898 return Status;
899 }
900
901 /**
902 Execute SD device identification procedure.
903
904 Refer to SD Physical Layer Simplified Spec 4.1 Section 3.6 for details.
905
906 @param[in] Private A pointer to the SD_MMC_HC_PRIVATE_DATA instance.
907 @param[in] Slot The slot number of the SD card to send the command to.
908
909 @retval EFI_SUCCESS There is a SD card.
910 @retval Others There is not a SD card.
911
912 **/
913 EFI_STATUS
914 SdCardIdentification (
915 IN SD_MMC_HC_PRIVATE_DATA *Private,
916 IN UINT8 Slot
917 )
918 {
919 EFI_STATUS Status;
920 EFI_PCI_IO_PROTOCOL *PciIo;
921 EFI_SD_MMC_PASS_THRU_PROTOCOL *PassThru;
922 UINT32 Ocr;
923 UINT16 Rca;
924 BOOLEAN Xpc;
925 BOOLEAN S18r;
926 UINT64 MaxCurrent;
927 UINT16 ControllerVer;
928 UINT8 PowerCtrl;
929 UINT32 PresentState;
930 UINT8 HostCtrl2;
931 UINTN Retry;
932
933 PciIo = Private->PciIo;
934 PassThru = &Private->PassThru;
935 //
936 // 1. Send Cmd0 to the device
937 //
938 Status = SdCardReset (PassThru, Slot);
939 if (EFI_ERROR (Status)) {
940 DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd0 fails with %r\n", Status));
941 return Status;
942 }
943 //
944 // 2. Send Cmd8 to the device
945 //
946 Status = SdCardVoltageCheck (PassThru, Slot, 0x1, 0xFF);
947 if (EFI_ERROR (Status)) {
948 DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing Cmd8 fails with %r\n", Status));
949 return Status;
950 }
951 //
952 // 3. Send SDIO Cmd5 to the device to the SDIO device OCR register.
953 //
954 Status = SdioSendOpCond (PassThru, Slot, 0, FALSE);
955 if (!EFI_ERROR (Status)) {
956 DEBUG ((DEBUG_INFO, "SdCardIdentification: Found SDIO device, ignore it as we don't support\n"));
957 return EFI_DEVICE_ERROR;
958 }
959 //
960 // 4. Send Acmd41 with voltage window 0 to the device
961 //
962 Status = SdCardSendOpCond (PassThru, Slot, 0, 0, FALSE, FALSE, FALSE, &Ocr);
963 if (EFI_ERROR (Status)) {
964 DEBUG ((DEBUG_INFO, "SdCardIdentification: Executing SdCardSendOpCond fails with %r\n", Status));
965 return EFI_DEVICE_ERROR;
966 }
967
968 if (Private->Capability[Slot].Voltage33 != 0) {
969 //
970 // Support 3.3V
971 //
972 MaxCurrent = ((UINT32)Private->MaxCurrent[Slot] & 0xFF) * 4;
973 } else if (Private->Capability[Slot].Voltage30 != 0) {
974 //
975 // Support 3.0V
976 //
977 MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 8) & 0xFF) * 4;
978 } else if (Private->Capability[Slot].Voltage18 != 0) {
979 //
980 // Support 1.8V
981 //
982 MaxCurrent = (((UINT32)Private->MaxCurrent[Slot] >> 16) & 0xFF) * 4;
983 } else {
984 ASSERT (FALSE);
985 return EFI_DEVICE_ERROR;
986 }
987
988 if (MaxCurrent >= 150) {
989 Xpc = TRUE;
990 } else {
991 Xpc = FALSE;
992 }
993
994 Status = SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_CTRL_VER, TRUE, sizeof (ControllerVer), &ControllerVer);
995 if (EFI_ERROR (Status)) {
996 return Status;
997 }
998
999 if (((ControllerVer & 0xFF) >= SD_MMC_HC_CTRL_VER_300) &&
1000 ((ControllerVer & 0xFF) <= SD_MMC_HC_CTRL_VER_420)) {
1001 S18r = TRUE;
1002 } else if (((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_100) || ((ControllerVer & 0xFF) == SD_MMC_HC_CTRL_VER_200)) {
1003 S18r = FALSE;
1004 } else {
1005 ASSERT (FALSE);
1006 return EFI_UNSUPPORTED;
1007 }
1008 //
1009 // 5. Repeatly send Acmd41 with supply voltage window to the device.
1010 // Note here we only support the cards complied with SD physical
1011 // layer simplified spec version 2.0 and version 3.0 and above.
1012 //
1013 Ocr = 0;
1014 Retry = 0;
1015 do {
1016 Status = SdCardSendOpCond (PassThru, Slot, 0, Ocr, S18r, Xpc, TRUE, &Ocr);
1017 if (EFI_ERROR (Status)) {
1018 DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails with %r Ocr %x, S18r %x, Xpc %x\n", Status, Ocr, S18r, Xpc));
1019 return EFI_DEVICE_ERROR;
1020 }
1021
1022 if (Retry++ == 100) {
1023 DEBUG ((DEBUG_ERROR, "SdCardIdentification: SdCardSendOpCond fails too many times\n"));
1024 return EFI_DEVICE_ERROR;
1025 }
1026 gBS->Stall(10 * 1000);
1027 } while ((Ocr & BIT31) == 0);
1028
1029 //
1030 // 6. If the S18A bit is set and the Host Controller supports 1.8V signaling
1031 // (One of support bits is set to 1: SDR50, SDR104 or DDR50 in the
1032 // Capabilities register), switch its voltage to 1.8V.
1033 //
1034 if ((Private->Capability[Slot].Sdr50 != 0 ||
1035 Private->Capability[Slot].Sdr104 != 0 ||
1036 Private->Capability[Slot].Ddr50 != 0) &&
1037 ((Ocr & BIT24) != 0)) {
1038 Status = SdCardVoltageSwitch (PassThru, Slot);
1039 if (EFI_ERROR (Status)) {
1040 DEBUG ((DEBUG_ERROR, "SdCardIdentification: Executing SdCardVoltageSwitch fails with %r\n", Status));
1041 Status = EFI_DEVICE_ERROR;
1042 goto Error;
1043 } else {
1044 Status = SdMmcHcStopClock (PciIo, Slot);
1045 if (EFI_ERROR (Status)) {
1046 Status = EFI_DEVICE_ERROR;
1047 goto Error;
1048 }
1049
1050 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
1051 if (((PresentState >> 20) & 0xF) != 0) {
1052 DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x\n", PresentState));
1053 Status = EFI_DEVICE_ERROR;
1054 goto Error;
1055 }
1056 HostCtrl2 = BIT3;
1057 SdMmcHcOrMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, sizeof (HostCtrl2), &HostCtrl2);
1058
1059 gBS->Stall (5000);
1060
1061 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_HOST_CTRL2, TRUE, sizeof (HostCtrl2), &HostCtrl2);
1062 if ((HostCtrl2 & BIT3) == 0) {
1063 DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with HostCtrl2 = 0x%x\n", HostCtrl2));
1064 Status = EFI_DEVICE_ERROR;
1065 goto Error;
1066 }
1067
1068 SdMmcHcInitClockFreq (PciIo, Slot, Private->BaseClkFreq[Slot], Private->ControllerVersion[Slot]);
1069
1070 gBS->Stall (1000);
1071
1072 SdMmcHcRwMmio (PciIo, Slot, SD_MMC_HC_PRESENT_STATE, TRUE, sizeof (PresentState), &PresentState);
1073 if (((PresentState >> 20) & 0xF) != 0xF) {
1074 DEBUG ((DEBUG_ERROR, "SdCardIdentification: SwitchVoltage fails with PresentState = 0x%x, It should be 0xF\n", PresentState));
1075 Status = EFI_DEVICE_ERROR;
1076 goto Error;
1077 }
1078 }
1079 DEBUG ((DEBUG_INFO, "SdCardIdentification: Switch to 1.8v signal voltage success\n"));
1080 }
1081
1082 Status = SdCardAllSendCid (PassThru, Slot);
1083 if (EFI_ERROR (Status)) {
1084 DEBUG ((DEBUG_ERROR, "SdCardIdentification: Executing SdCardAllSendCid fails with %r\n", Status));
1085 return Status;
1086 }
1087
1088 Status = SdCardSetRca (PassThru, Slot, &Rca);
1089 if (EFI_ERROR (Status)) {
1090 DEBUG ((DEBUG_ERROR, "SdCardIdentification: Executing SdCardSetRca fails with %r\n", Status));
1091 return Status;
1092 }
1093 //
1094 // Enter Data Tranfer Mode.
1095 //
1096 DEBUG ((DEBUG_INFO, "SdCardIdentification: Found a SD device at slot [%d]\n", Slot));
1097 Private->Slot[Slot].CardType = SdCardType;
1098
1099 Status = SdCardSetBusMode (PciIo, PassThru, Slot, Rca, ((Ocr & BIT24) != 0));
1100
1101 return Status;
1102
1103 Error:
1104 //
1105 // Set SD Bus Power = 0
1106 //
1107 PowerCtrl = (UINT8)~BIT0;
1108 Status = SdMmcHcAndMmio (PciIo, Slot, SD_MMC_HC_POWER_CTRL, sizeof (PowerCtrl), &PowerCtrl);
1109 return EFI_DEVICE_ERROR;
1110 }
1111