public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pete Batard" <pete@akeo.ie>
To: devel@edk2.groups.io
Cc: ard.biesheuvel@linaro.org, leif.lindholm@linaro.org,
	philmd@redhat.com, samer.el-haj-mahmoud@arm.com,
	andrey.warkentin@gmail.com
Subject: [edk2-platforms][PATCH 3/5] Platform/RPi/MmcDxe: Factorize SCR call and clean up MMC init
Date: Wed, 27 Nov 2019 12:37:04 +0000	[thread overview]
Message-ID: <20191127123706.4604-4-pete@akeo.ie> (raw)
In-Reply-To: <20191127123706.4604-1-pete@akeo.ie>

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


  parent reply	other threads:[~2019-11-27 12:37 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-27 12:37 [edk2-platforms][PATCH 0/5] Further RPi4 support groundwork Pete Batard
2019-11-27 12:37 ` [edk2-platforms][PATCH 1/5] Silicon/Bcm283x: Clean up Bcm2836.h header Pete Batard
2019-11-27 12:48   ` Ard Biesheuvel
2019-11-27 12:56     ` Pete Batard
2019-11-27 13:00       ` Ard Biesheuvel
2019-11-27 13:09         ` Pete Batard
2019-11-27 13:17           ` Ard Biesheuvel
2019-11-27 13:21             ` Pete Batard
2019-11-27 14:47   ` Philippe Mathieu-Daudé
2019-11-27 14:59     ` [edk2-devel] " Pete Batard
2019-11-27 15:18       ` Philippe Mathieu-Daudé
2019-11-27 12:37 ` [edk2-platforms][PATCH 2/5] Silicon/Bcm283x: Add FIFO mode for RNG Pete Batard
2019-11-27 12:44   ` Ard Biesheuvel
2019-11-27 12:47     ` Pete Batard
2019-11-27 12:37 ` Pete Batard [this message]
2019-11-27 12:37 ` [edk2-platforms][PATCH 4/5] Platform/RPi/MmcDxe: Improve MMC driver stability Pete Batard
2019-11-27 12:37 ` [edk2-platforms][PATCH 5/5] Platform/RPi: Set SD routing according to model Pete Batard
2019-11-27 15:24   ` Philippe Mathieu-Daudé
2019-11-27 16:33     ` Pete Batard
2019-11-27 17:04       ` Leif Lindholm
2019-11-27 17:17         ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191127123706.4604-4-pete@akeo.ie \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox