From: Andrei Warkentin <andrey.warkentin@gmail.com>
This is mostly a maintainability improvement for the
InitializeSdMmcDevice () call achieved by factorizing the
code related to SCR execution into a new SdExecuteScr () call.
Signed-off-by: Pete Batard <pete@akeo.ie>
---
Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c | 105 ++++++++++++--------
1 file changed, 62 insertions(+), 43 deletions(-)
diff --git a/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c b/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c
index 4ee5c5ca6fb2..34a97e954220 100644
--- a/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c
+++ b/Platform/RaspberryPi/Drivers/MmcDxe/MmcIdentification.c
@@ -1,5 +1,6 @@
/** @file
*
+ * Copyright (c) 2019, Andrei Warkentin <andrey.warkentin@gmail.com>
* Copyright (c) 2011-2015, ARM Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -567,6 +568,48 @@ SdSetSpeed (
return EFI_SUCCESS;
}
+STATIC
+EFI_STATUS
+SdExecuteScr (
+ IN MMC_HOST_INSTANCE *MmcHostInstance,
+ OUT SCR *Scr
+ )
+{
+ EFI_STATUS Status;
+ UINT32 Response[4];
+ EFI_MMC_HOST_PROTOCOL *MmcHost = MmcHostInstance->MmcHost;
+
+ Status = MmcHost->SendCommand (MmcHost, MMC_CMD55,
+ MmcHostInstance->CardInfo.RCA << 16);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
+ return Status;
+ }
+ Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
+ return Status;
+ }
+ if ((Response[0] & MMC_STATUS_APP_CMD) == 0) {
+ return EFI_SUCCESS;
+ }
+
+ /* SCR */
+ Status = MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): Error and Status = %r\n", __func__, Status));
+ return Status;
+ }
+
+ Status = MmcHost->ReadBlockData (MmcHost, 0, 8, (VOID *) Scr);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status = %r\n", __func__, Status));
+ return Status;
+ }
+
+ return EFI_SUCCESS;
+}
+
STATIC
EFI_STATUS
InitializeSdMmcDevice (
@@ -574,7 +617,6 @@ InitializeSdMmcDevice (
)
{
UINT32 Response[4];
- UINT32 Buffer[128];
UINTN BlockSize;
UINTN CardSize;
UINTN NumBlocks;
@@ -621,58 +663,35 @@ InitializeSdMmcDevice (
return Status;
}
- Status = MmcHost->SendCommand (MmcHost, MMC_CMD55,
- MmcHostInstance->CardInfo.RCA << 16);
+ Status = SdExecuteScr (MmcHostInstance, &Scr);
if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
- return Status;
- }
- Status = MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a (MMC_CMD55): Error and Status = %r\n", __FUNCTION__, Status));
- return Status;
- }
- if ((Response[0] & MMC_STATUS_APP_CMD) == 0) {
- return EFI_SUCCESS;
+ return Status;
}
- /* SCR */
- Status = MmcHost->SendCommand (MmcHost, MMC_ACMD51, 0);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): Error and Status = %r\n", __func__, Status));
- return Status;
- } else {
- Status = MmcHost->ReadBlockData (MmcHost, 0, 8, Buffer);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a(MMC_ACMD51): ReadBlockData Error and Status = %r\n", __func__, Status));
- return Status;
- }
- CopyMem (&Scr, Buffer, 8);
- if (Scr.SD_SPEC == 2) {
- if (Scr.SD_SPEC3 == 1) {
- if (Scr.SD_SPEC4 == 1) {
- DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 4.xx\n"));
- } else {
- DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 3.0x\n"));
- }
+ if (Scr.SD_SPEC == 2) {
+ if (Scr.SD_SPEC3 == 1) {
+ if (Scr.SD_SPEC4 == 1) {
+ DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 4.xx\n"));
} else {
- if (Scr.SD_SPEC4 == 0) {
- DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 2.0\n"));
- } else {
- DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n"));
- }
+ DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 3.0x\n"));
}
} else {
- if ((Scr.SD_SPEC3 == 0) && (Scr.SD_SPEC4 == 0)) {
- if (Scr.SD_SPEC == 1) {
- DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.10\n"));
- } else {
- DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.0\n"));
- }
+ if (Scr.SD_SPEC4 == 0) {
+ DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 2.0\n"));
} else {
DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n"));
}
}
+ } else {
+ if ((Scr.SD_SPEC3 == 0) && (Scr.SD_SPEC4 == 0)) {
+ if (Scr.SD_SPEC == 1) {
+ DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.10\n"));
+ } else {
+ DEBUG ((DEBUG_INFO, "Found SD Card for Spec Version 1.0\n"));
+ }
+ } else {
+ DEBUG ((DEBUG_ERROR, "Found invalid SD Card\n"));
+ }
}
Status = SdSetSpeed (MmcHostInstance, CccSwitch);
--
2.21.0.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#51337): https://edk2.groups.io/g/devel/message/51337
Mute This Topic: https://groups.io/mt/62504742/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-