From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by mx.groups.io with SMTP id smtpd.web12.4237.1575307001845958514 for ; Mon, 02 Dec 2019 09:16:42 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=pWgKwv+i; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.128.48, mailfrom: pete@akeo.ie) Received: by mail-wm1-f48.google.com with SMTP id p9so75359wmc.2 for ; Mon, 02 Dec 2019 09:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=inZ6trD9ukgmtkiNFtqc90OHmeTHJZFrpQ+VaiS97w4=; b=pWgKwv+ijnRZfj9E1rDPwUty72rsIPmX4NaTC6RThqTYj69OAXd3aNpzoI80IWAZUt GlIVuLq9ROgowdSVBaNm+GMti9rbxxeQKQAd0Ik+ogRWFkcFgeck4nsRM6sP7f3jeoWT AUxbNU3g1PKqlQp+eDJ4sS004UeZk1+BPobC4a1FCo+uSUfefp0rmyYnX0gMbeJu3+Xz 9dzlsZgv0843MnkAEQUlLBr0PfmDAkeSVH+LIw3T9CvF7ZzdonMG1bKG2PWvu5NoaiJ2 odS6RiNk/Muf712bUua8zoU7vvE3cnwRFs6wVOCa06Ny3c2jN5JIytYqCrQf6LAcyBAd KlpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=inZ6trD9ukgmtkiNFtqc90OHmeTHJZFrpQ+VaiS97w4=; b=A+IJ0uQ2Q++HRrU7A5T/++Mv2kCHt+F20tg29rCXr2h7umWikvlrKE4KJZWVTSGvgk yg7PdMfQ+zbV1uiO5NeqK624CoNI8lUPn6CY4JEIoNExtCmq4dOjD+0ETyf2ZOnuuGkh JfQy666Jf5JyceUIW57qSjIzac1V9DOoll+cbMVLD3OJb/g730aWWjnw3zz7wjod8LqN tRT1bRzd62dGk/5SuXOdvayJ+fsDlpRMN7cyvOWqF357F0h9EnjMGK3Z94eqkcMeidiN UkMTyTlxuOkd5iAPJGY1E1SPJEcsUN2UBhCq/mGkpd2BFLsXjCB8rgIvtTYPlqdW4IE3 Y04w== X-Gm-Message-State: APjAAAVmAJhyqJGrDfDexW7+G74HxptAN4hyvyHrxPIliukFsCkyiSR/ hMDYr33qYcVb0UN3ybrONmHRyApIb9E= X-Google-Smtp-Source: APXvYqxlaqbULvpimlwXKJE5mFQhqTUC/hgZqWOXOh98XU+8FQy716u13IkMyw7wHTZUp3oksRKpuQ== X-Received: by 2002:a7b:c055:: with SMTP id u21mr30758404wmc.55.1575306998419; Mon, 02 Dec 2019 09:16:38 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.45.230]) by smtp.gmail.com with ESMTPSA id 205sm496035wmb.3.2019.12.02.09.16.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Dec 2019 09:16:37 -0800 (PST) From: "Pete Batard" 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 v2 1/3] Platform/RPi/MmcDxe: Factorize SCR call and clean up MMC init Date: Mon, 2 Dec 2019 17:16:20 +0000 Message-Id: <20191202171622.10980-2-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20191202171622.10980-1-pete@akeo.ie> References: <20191202171622.10980-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrei Warkentin 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 --- 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 * 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