2011-02-02 23:35:30 +01:00
|
|
|
/** @file
|
|
|
|
*
|
2013-03-12 01:45:29 +01:00
|
|
|
* Copyright (c) 2011-2013, ARM Limited. All rights reserved.
|
2011-02-02 23:35:30 +01:00
|
|
|
*
|
|
|
|
* This program and the accompanying materials
|
|
|
|
* are licensed and made available under the terms and conditions of the BSD License
|
|
|
|
* which accompanies this distribution. The full text of the license may be found at
|
|
|
|
* http://opensource.org/licenses/bsd-license.php
|
|
|
|
*
|
|
|
|
* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
|
|
|
*
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <Protocol/MmcHost.h>
|
|
|
|
#include <Library/DebugLib.h>
|
|
|
|
#include <Library/BaseMemoryLib.h>
|
|
|
|
#include <Library/TimerLib.h>
|
|
|
|
|
|
|
|
#include "Mmc.h"
|
|
|
|
|
|
|
|
// Untested ...
|
|
|
|
//#define USE_STREAM
|
|
|
|
|
2011-03-31 13:16:02 +02:00
|
|
|
#define MAX_RETRY_COUNT 1000
|
|
|
|
#define CMD_RETRY_COUNT 20
|
2011-02-02 23:35:30 +01:00
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
MmcNotifyState (
|
2011-06-03 11:10:26 +02:00
|
|
|
IN MMC_HOST_INSTANCE *MmcHostInstance,
|
|
|
|
IN MMC_STATE State
|
|
|
|
)
|
|
|
|
{
|
|
|
|
MmcHostInstance->State = State;
|
2011-09-01 19:08:41 +02:00
|
|
|
return MmcHostInstance->MmcHost->NotifyState (MmcHostInstance->MmcHost, State);
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
VOID
|
|
|
|
PrintOCR (
|
|
|
|
IN UINT32 Ocr
|
|
|
|
)
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
UINTN MinV;
|
|
|
|
UINTN MaxV;
|
|
|
|
UINTN Volts;
|
|
|
|
UINTN Loop;
|
2011-06-03 11:10:26 +02:00
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
MinV = 36; // 3.6
|
|
|
|
MaxV = 20; // 2.0
|
|
|
|
Volts = 20; // 2.0
|
2011-06-03 11:10:26 +02:00
|
|
|
|
|
|
|
// The MMC register bits [23:8] indicate the working range of the card
|
2013-03-12 01:45:29 +01:00
|
|
|
for (Loop = 8; Loop < 24; Loop++) {
|
|
|
|
if (Ocr & (1 << Loop)) {
|
|
|
|
if (MinV > Volts) MinV = Volts;
|
|
|
|
if (MaxV < Volts) MaxV = Volts + 1;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
2013-03-12 01:45:29 +01:00
|
|
|
Volts = Volts + 1;
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "- PrintOCR Ocr (0x%X)\n",Ocr));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Card operating voltage: %d.%d to %d.%d\n", MinV/10, MinV % 10, MaxV/10, MaxV % 10));
|
2011-06-03 11:10:26 +02:00
|
|
|
if (((Ocr >> 29) & 3) == 0) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\t- AccessMode: Byte Mode\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\t- AccessMode: Block Mode (0x%X)\n", ((Ocr >> 29) & 3)));
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Ocr & MMC_OCR_POWERUP) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\t- PowerUp\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Voltage Not Supported\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
VOID PrintCID (
|
|
|
|
IN UINT32* Cid
|
|
|
|
)
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "- PrintCID\n"));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Manufacturing date: %d/%d\n", (Cid[0] >> 8) & 0xF, (Cid[0] >> 12) & 0xFF));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Product serial number: 0x%X%X\n", Cid[1] & 0xFFFFFF, (Cid[0] >> 24) & 0xFF));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Product revision: %d\n", Cid[1] >> 24));
|
|
|
|
//DEBUG ((EFI_D_ERROR, "\t- Product name: %s\n", (char*)(Cid + 2)));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- OEM ID: %c%c\n", (Cid[3] >> 8) & 0xFF, (Cid[3] >> 16) & 0xFF));
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2012-03-26 14:28:05 +02:00
|
|
|
#if !defined(MDEPKG_NDEBUG)
|
2013-03-12 01:45:29 +01:00
|
|
|
CONST CHAR8* mStrUnit[] = { "100kbit/s", "1Mbit/s", "10Mbit/s", "100MBit/s",
|
|
|
|
"Unknown", "Unknown", "Unknown", "Unknown" };
|
|
|
|
CONST CHAR8* mStrValue[] = { "1.0", "1.2", "1.3", "1.5", "2.0", "2.5", "3.0", "3.5", "4.0", "4.5", "5.0",
|
|
|
|
"Unknown", "Unknown", "Unknown", "Unknown" };
|
2012-03-26 14:28:05 +02:00
|
|
|
#endif
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
VOID
|
|
|
|
PrintCSD (
|
|
|
|
IN UINT32* Csd
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINTN Value;
|
|
|
|
|
|
|
|
if (((Csd[2] >> 30) & 0x3) == 0) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "- PrintCSD Version 1.01-1.10/Version 2.00/Standard Capacity\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
} else if (((Csd[2] >> 30) & 0x3) == 1) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "- PrintCSD Version 2.00/High Capacity\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "- PrintCSD Version Higher than v3.3\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Supported card command class: 0x%X\n", MMC_CSD_GET_CCC(Csd)));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Speed: %a %a\n",mStrValue[(MMC_CSD_GET_TRANSPEED(Csd) >> 3) & 0xF],mStrUnit[MMC_CSD_GET_TRANSPEED(Csd) & 7]));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Maximum Read Data Block: %d\n",2 << (MMC_CSD_GET_READBLLEN(Csd)-1)));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Maximum Write Data Block: %d\n",2 << (MMC_CSD_GET_WRITEBLLEN(Csd)-1)));
|
2011-06-03 11:10:26 +02:00
|
|
|
|
|
|
|
if (!MMC_CSD_GET_FILEFORMATGRP(Csd)) {
|
2013-03-12 01:45:29 +01:00
|
|
|
Value = MMC_CSD_GET_FILEFORMAT (Csd);
|
|
|
|
if (Value == 0) DEBUG ((EFI_D_ERROR, "\t- Format (0): Hard disk-like file system with partition table\n"));
|
|
|
|
else if (Value == 1) DEBUG ((EFI_D_ERROR, "\t- Format (1): DOS FAT (floppy-like) with boot sector only (no partition table)\n"));
|
|
|
|
else if (Value == 2) DEBUG ((EFI_D_ERROR, "\t- Format (2): Universal File Format\n"));
|
|
|
|
else DEBUG ((EFI_D_ERROR, "\t- Format (3): Others/Unknown\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Format: Reserved\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
VOID
|
|
|
|
PrintRCA (
|
|
|
|
IN UINT32 Rca
|
|
|
|
)
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "- PrintRCA: 0x%X\n", Rca));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- Status: 0x%X\n", Rca & 0xFFFF));
|
|
|
|
DEBUG ((EFI_D_ERROR, "\t- RCA: 0x%X\n", (Rca >> 16) & 0xFFFF));
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
VOID
|
|
|
|
PrintResponseR1 (
|
|
|
|
IN UINT32 Response
|
|
|
|
)
|
|
|
|
{
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_INFO, "Response: 0x%X\n", Response));
|
|
|
|
if (Response & MMC_R0_READY_FOR_DATA) {
|
|
|
|
DEBUG ((EFI_D_INFO, "\t- READY_FOR_DATA\n"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((Response >> 9) & 0xF) == 0) DEBUG ((EFI_D_INFO, "\t- State: Idle\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 1) DEBUG ((EFI_D_INFO, "\t- State: Ready\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 2) DEBUG ((EFI_D_INFO, "\t- State: Ident\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 3) DEBUG ((EFI_D_INFO, "\t- State: StandBy\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 4) DEBUG ((EFI_D_INFO, "\t- State: Tran\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 5) DEBUG ((EFI_D_INFO, "\t- State: Data\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 6) DEBUG ((EFI_D_INFO, "\t- State: Rcv\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 7) DEBUG ((EFI_D_INFO, "\t- State: Prg\n"));
|
|
|
|
else if (((Response >> 9) & 0xF) == 8) DEBUG ((EFI_D_INFO, "\t- State: Dis\n"));
|
|
|
|
else DEBUG ((EFI_D_INFO, "\t- State: Reserved\n"));
|
2011-03-31 13:16:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MmcGetCardStatus(
|
2011-06-03 11:10:26 +02:00
|
|
|
IN MMC_HOST_INSTANCE *MmcHostInstance
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 Response[4];
|
|
|
|
UINTN CmdArg;
|
|
|
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
|
|
|
|
|
|
|
Status = EFI_SUCCESS;
|
|
|
|
MmcHost = MmcHostInstance->MmcHost;
|
|
|
|
CmdArg = 0;
|
|
|
|
|
|
|
|
if (MmcHost == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
if(MmcHostInstance->State != MmcHwInitializationState){
|
|
|
|
//Get the Status of the card.
|
|
|
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcGetCardStatus(MMC_CMD13): Error and Status = %r\n", Status));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
2011-03-31 13:16:02 +02:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
//Read Response
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
|
|
|
|
PrintResponseR1 (Response[0]);
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MmcIdentificationMode (
|
2011-06-03 11:10:26 +02:00
|
|
|
IN MMC_HOST_INSTANCE *MmcHostInstance
|
|
|
|
)
|
|
|
|
{
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINT32 Response[4];
|
|
|
|
UINTN Timeout;
|
|
|
|
UINTN CmdArg;
|
|
|
|
BOOLEAN IsHCS;
|
|
|
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
|
|
|
|
|
|
|
MmcHost = MmcHostInstance->MmcHost;
|
|
|
|
CmdArg = 0;
|
|
|
|
IsHCS = FALSE;
|
|
|
|
|
|
|
|
if (MmcHost == NULL) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We can get into this function if we restart the identification mode
|
|
|
|
if (MmcHostInstance->State == MmcHwInitializationState) {
|
|
|
|
// Initialize the MMC Host HW
|
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcHwInitializationState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcHwInitializationState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
2012-10-19 11:47:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD0, 0);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD0): Error\n"));
|
2012-10-19 11:47:49 +02:00
|
|
|
return Status;
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcIdleState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcIdleState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Are we using SDIO ?
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD5, 0);
|
2011-06-03 11:10:26 +02:00
|
|
|
if (Status == EFI_SUCCESS) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD5): Error - SDIO not supported.\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return EFI_UNSUPPORTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check which kind of card we are using. Ver2.00 or later SD Memory Card (PL180 is SD v1.1)
|
|
|
|
CmdArg = (0x0UL << 12 | BIT8 | 0xCEUL << 0);
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD8, CmdArg);
|
2011-06-03 11:10:26 +02:00
|
|
|
if (Status == EFI_SUCCESS) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "Card is SD2.0 => Supports high capacity\n"));
|
|
|
|
IsHCS = TRUE;
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R7, Response);
|
|
|
|
PrintResponseR1 (Response[0]);
|
2011-06-03 11:10:26 +02:00
|
|
|
//check if it is valid response
|
|
|
|
if(Response[0] != CmdArg){
|
|
|
|
DEBUG ((EFI_D_ERROR, "The Card is not usable\n"));
|
|
|
|
return EFI_UNSUPPORTED;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
2011-06-03 11:10:26 +02:00
|
|
|
} else {
|
|
|
|
DEBUG ((EFI_D_ERROR, "Not a SD2.0 Card\n"));
|
|
|
|
}
|
|
|
|
|
2012-08-02 12:11:29 +02:00
|
|
|
// We need to wait for the MMC or SD card is ready => (gCardInfo.OCRData.PowerUp == 1)
|
2011-06-03 11:10:26 +02:00
|
|
|
Timeout = MAX_RETRY_COUNT;
|
|
|
|
while (Timeout > 0) {
|
|
|
|
// SD Card or MMC Card ? CMD55 indicates to the card that the next command is an application specific command
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD55, 0);
|
2011-02-02 23:35:30 +01:00
|
|
|
if (Status == EFI_SUCCESS) {
|
2011-06-03 11:10:26 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "Card should be SD\n"));
|
|
|
|
if (IsHCS) {
|
|
|
|
MmcHostInstance->CardInfo.CardType = SD_CARD_2;
|
2011-02-02 23:35:30 +01:00
|
|
|
} else {
|
2011-06-03 11:10:26 +02:00
|
|
|
MmcHostInstance->CardInfo.CardType = SD_CARD;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
// Note: The first time CmdArg will be zero
|
|
|
|
CmdArg = ((UINTN *) &(MmcHostInstance->CardInfo.OCRData))[0];
|
|
|
|
if (IsHCS) {
|
|
|
|
CmdArg |= BIT30;
|
|
|
|
}
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_ACMD41, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response);
|
2011-06-03 11:10:26 +02:00
|
|
|
((UINT32 *) &(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
} else {
|
2011-06-03 11:10:26 +02:00
|
|
|
DEBUG ((EFI_D_INFO, "Card should be MMC\n"));
|
|
|
|
MmcHostInstance->CardInfo.CardType = MMC_CARD;
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD1, 0x800000);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_OCR, Response);
|
2011-06-03 11:10:26 +02:00
|
|
|
((UINT32 *) &(MmcHostInstance->CardInfo.OCRData))[0] = Response[0];
|
2011-03-31 13:16:02 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
if (!EFI_ERROR (Status)) {
|
2012-08-02 12:11:29 +02:00
|
|
|
if (!MmcHostInstance->CardInfo.OCRData.PowerUp) {
|
2013-03-12 01:45:29 +01:00
|
|
|
MicroSecondDelay (1);
|
2011-06-03 11:10:26 +02:00
|
|
|
Timeout--;
|
|
|
|
} else {
|
|
|
|
if ((MmcHostInstance->CardInfo.CardType == SD_CARD_2) && (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1)) {
|
|
|
|
MmcHostInstance->CardInfo.CardType = SD_CARD_2_HIGH;
|
|
|
|
DEBUG ((EFI_D_ERROR, "High capacity card.\n"));
|
|
|
|
}
|
|
|
|
break; // The MMC/SD card is ready. Continue the Identification Mode
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
MicroSecondDelay (1);
|
2011-06-03 11:10:26 +02:00
|
|
|
Timeout--;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Timeout == 0) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(): No Card\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return EFI_NO_MEDIA;
|
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
PrintOCR (Response[0]);
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcReadyState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcReadyState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD2, 0);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD2): Error\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CID, Response);
|
2011-06-03 11:10:26 +02:00
|
|
|
PrintCID(Response);
|
|
|
|
|
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcIdentificationState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcIdentificationState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:12:13 +02:00
|
|
|
//
|
|
|
|
// Note, SD specifications say that "if the command execution causes a state change, it
|
|
|
|
// will be visible to the host in the response to the next command"
|
|
|
|
// The status returned for this CMD3 will be 2 - identification
|
|
|
|
//
|
|
|
|
CmdArg = 1;
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD3, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD3): Error\n"));
|
2011-08-15 18:12:13 +02:00
|
|
|
return Status;
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_RCA, Response);
|
|
|
|
PrintRCA (Response[0]);
|
2011-08-15 18:12:13 +02:00
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
// For MMC card, RCA is assigned by CMD3 while CMD3 dumps the RCA for SD card
|
|
|
|
if (MmcHostInstance->CardInfo.CardType != MMC_CARD) {
|
|
|
|
MmcHostInstance->CardInfo.RCA = Response[0] >> 16;
|
|
|
|
} else {
|
|
|
|
MmcHostInstance->CardInfo.RCA = CmdArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcStandByState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcStandByState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:08:41 +02:00
|
|
|
EFI_STATUS InitializeMmcDevice (
|
2011-08-30 20:02:38 +02:00
|
|
|
IN MMC_HOST_INSTANCE *MmcHostInstance
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Response[4];
|
|
|
|
EFI_STATUS Status;
|
|
|
|
UINTN CardSize, NumBlocks, BlockSize, CmdArg;
|
|
|
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
|
|
|
UINTN BlockCount = 1;
|
|
|
|
|
|
|
|
MmcHost = MmcHostInstance->MmcHost;
|
|
|
|
|
|
|
|
MmcIdentificationMode (MmcHostInstance);
|
|
|
|
|
|
|
|
//Send a command to get Card specific data
|
|
|
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD9, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD9): Error, Status=%r\n", Status));
|
2011-08-30 20:02:38 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
//Read Response
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_CSD, Response);
|
2011-08-30 20:02:38 +02:00
|
|
|
PrintCSD(Response);
|
|
|
|
|
|
|
|
if (MmcHostInstance->CardInfo.CardType == SD_CARD_2_HIGH) {
|
2013-03-12 01:45:29 +01:00
|
|
|
CardSize = HC_MMC_CSD_GET_DEVICESIZE (Response);
|
2011-08-30 20:02:38 +02:00
|
|
|
NumBlocks = ((CardSize + 1) * 1024);
|
|
|
|
BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);
|
|
|
|
} else {
|
2013-03-12 01:45:29 +01:00
|
|
|
CardSize = MMC_CSD_GET_DEVICESIZE (Response);
|
|
|
|
NumBlocks = (CardSize + 1) * (1 << (MMC_CSD_GET_DEVICESIZEMULT (Response) + 2));
|
2011-08-30 20:02:38 +02:00
|
|
|
BlockSize = 1 << MMC_CSD_GET_READBLLEN(Response);
|
|
|
|
}
|
|
|
|
|
|
|
|
//For >=2G card, BlockSize may be 1K, but the transfer size is 512 bytes.
|
|
|
|
if (BlockSize > 512) {
|
2013-03-12 01:45:29 +01:00
|
|
|
NumBlocks = MultU64x32 (NumBlocks, BlockSize/512);
|
2011-08-30 20:02:38 +02:00
|
|
|
BlockSize = 512;
|
|
|
|
}
|
|
|
|
|
|
|
|
MmcHostInstance->BlockIo.Media->LastBlock = (NumBlocks - 1);
|
|
|
|
MmcHostInstance->BlockIo.Media->BlockSize = BlockSize;
|
2011-09-01 19:08:41 +02:00
|
|
|
MmcHostInstance->BlockIo.Media->ReadOnly = MmcHost->IsReadOnly (MmcHost);
|
2011-08-30 20:02:38 +02:00
|
|
|
MmcHostInstance->BlockIo.Media->MediaPresent = TRUE;
|
|
|
|
MmcHostInstance->BlockIo.Media->MediaId++;
|
|
|
|
|
|
|
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD7, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD7): Error and Status = %r\n", Status));
|
2011-08-30 20:02:38 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode() : Error MmcTransferState\n"));
|
2011-08-30 20:02:38 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set Block Length
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD16, MmcHostInstance->BlockIo.Media->BlockSize);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIdentificationMode(MMC_CMD16): Error MmcHostInstance->BlockIo.Media->BlockSize: %d and Error = %r\n", MmcHostInstance->BlockIo.Media->BlockSize, Status));
|
2011-08-30 20:02:38 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Block Count (not used). Could return an error for SD card
|
|
|
|
if (MmcHostInstance->CardInfo.CardType == MMC_CARD) {
|
2011-09-01 19:08:41 +02:00
|
|
|
MmcHost->SendCommand (MmcHost, MMC_CMD23, BlockCount);
|
2011-08-30 20:02:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-02-02 23:35:30 +01:00
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MmcReset (
|
|
|
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
|
|
IN BOOLEAN ExtendedVerification
|
2011-06-03 11:10:26 +02:00
|
|
|
)
|
|
|
|
{
|
2011-08-15 18:04:14 +02:00
|
|
|
MMC_HOST_INSTANCE *MmcHostInstance;
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
2011-08-15 18:04:14 +02:00
|
|
|
|
|
|
|
if (MmcHostInstance->MmcHost == NULL) {
|
|
|
|
// Nothing to do
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If a card is not present then clear all media settings
|
2011-09-01 19:08:41 +02:00
|
|
|
if (!MmcHostInstance->MmcHost->IsCardPresent (MmcHostInstance->MmcHost)) {
|
2011-08-15 18:04:14 +02:00
|
|
|
MmcHostInstance->BlockIo.Media->MediaPresent = FALSE;
|
|
|
|
MmcHostInstance->BlockIo.Media->LastBlock = 0;
|
|
|
|
MmcHostInstance->BlockIo.Media->BlockSize = 512; // Should be zero but there is a bug in DiskIo
|
|
|
|
MmcHostInstance->BlockIo.Media->ReadOnly = FALSE;
|
|
|
|
|
|
|
|
// Indicate that the driver requires initialization
|
|
|
|
MmcHostInstance->State = MmcHwInitializationState;
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
// Implement me. Either send a CMD0 (could not work for some MMC host) or just turn off/turn
|
|
|
|
// on power and restart Identification mode
|
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
MmcDetectCard (
|
|
|
|
EFI_MMC_HOST_PROTOCOL *MmcHost
|
|
|
|
)
|
|
|
|
{
|
2011-09-01 19:08:41 +02:00
|
|
|
if (!MmcHost->IsCardPresent (MmcHost)) {
|
2011-06-03 11:10:26 +02:00
|
|
|
return EFI_NO_MEDIA;
|
|
|
|
} else {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#define MMCI0_BLOCKLEN 512
|
|
|
|
#define MMCI0_TIMEOUT 10000
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
EFI_STATUS
|
|
|
|
MmcIoBlocks (
|
2011-02-02 23:35:30 +01:00
|
|
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
|
|
IN UINTN Transfer,
|
|
|
|
IN UINT32 MediaId,
|
|
|
|
IN EFI_LBA Lba,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
OUT VOID *Buffer
|
2011-06-03 11:10:26 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 Response[4];
|
|
|
|
EFI_STATUS Status;
|
2011-08-30 20:02:38 +02:00
|
|
|
UINTN CmdArg;
|
2011-08-15 18:06:53 +02:00
|
|
|
INTN Timeout;
|
2011-06-03 11:10:26 +02:00
|
|
|
UINTN Cmd;
|
|
|
|
MMC_HOST_INSTANCE *MmcHostInstance;
|
|
|
|
EFI_MMC_HOST_PROTOCOL *MmcHost;
|
|
|
|
UINTN BytesRemainingToBeTransfered;
|
|
|
|
UINTN BlockCount = 1;
|
|
|
|
|
2013-03-12 01:45:29 +01:00
|
|
|
MmcHostInstance = MMC_HOST_INSTANCE_FROM_BLOCK_IO_THIS (This);
|
|
|
|
ASSERT (MmcHostInstance != 0);
|
2011-06-03 11:10:26 +02:00
|
|
|
MmcHost = MmcHostInstance->MmcHost;
|
2013-03-12 01:45:29 +01:00
|
|
|
ASSERT (MmcHost);
|
2011-06-03 11:10:26 +02:00
|
|
|
|
2013-04-14 11:26:28 +02:00
|
|
|
if (This->Media->MediaId != MediaId) {
|
|
|
|
return EFI_MEDIA_CHANGED;
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:06:53 +02:00
|
|
|
if ((MmcHost == 0)|| (Buffer == NULL)) {
|
2011-06-03 11:10:26 +02:00
|
|
|
return EFI_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if a Card is Present
|
2011-08-15 18:04:14 +02:00
|
|
|
if (!MmcHostInstance->BlockIo.Media->MediaPresent) {
|
2011-06-03 11:10:26 +02:00
|
|
|
return EFI_NO_MEDIA;
|
|
|
|
}
|
|
|
|
|
2011-08-15 18:06:53 +02:00
|
|
|
// All blocks must be within the device
|
|
|
|
if ((Lba + (BufferSize / This->Media->BlockSize)) > (This->Media->LastBlock + 1)){
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
2013-04-14 11:26:28 +02:00
|
|
|
if((Transfer == MMC_IOBLOCKS_WRITE) && (This->Media->ReadOnly == TRUE)) {
|
|
|
|
return EFI_WRITE_PROTECTED;
|
2011-08-15 18:06:53 +02:00
|
|
|
}
|
|
|
|
|
2013-04-14 11:26:28 +02:00
|
|
|
// Reading 0 Byte is valid
|
|
|
|
if (BufferSize == 0) {
|
|
|
|
return EFI_SUCCESS;
|
2011-08-15 18:06:53 +02:00
|
|
|
}
|
|
|
|
|
2013-04-14 11:26:28 +02:00
|
|
|
// The buffer size must be an exact multiple of the block size
|
|
|
|
if ((BufferSize % This->Media->BlockSize) != 0) {
|
|
|
|
return EFI_BAD_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the alignment
|
|
|
|
if ((This->Media->IoAlign > 2) && (((UINTN)Buffer & (This->Media->IoAlign - 1)) != 0)) {
|
|
|
|
return EFI_INVALID_PARAMETER;
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
BytesRemainingToBeTransfered = BufferSize;
|
|
|
|
while (BytesRemainingToBeTransfered > 0) {
|
|
|
|
|
|
|
|
// Check if the Card is in Ready status
|
|
|
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
|
|
|
Response[0] = 0;
|
|
|
|
Timeout = 20;
|
2012-08-02 12:23:41 +02:00
|
|
|
while( (!(Response[0] & MMC_R0_READY_FOR_DATA))
|
2013-03-12 01:45:29 +01:00
|
|
|
&& (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
|
2012-08-02 12:23:41 +02:00
|
|
|
&& Timeout--) {
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
if (0 == Timeout) {
|
2013-03-12 01:45:29 +01:00
|
|
|
DEBUG ((EFI_D_ERROR, "The Card is busy\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return EFI_NOT_READY;
|
2011-06-03 11:09:18 +02:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
//Set command argument based on the card access mode (Byte mode or Block mode)
|
|
|
|
if (MmcHostInstance->CardInfo.OCRData.AccessMode & BIT1) {
|
|
|
|
CmdArg = Lba;
|
|
|
|
} else {
|
|
|
|
CmdArg = Lba * This->Media->BlockSize;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
if (Transfer == MMC_IOBLOCKS_READ) {
|
2011-02-02 23:35:30 +01:00
|
|
|
#ifndef USE_STREAM
|
2011-06-03 11:10:26 +02:00
|
|
|
// Read a single block
|
|
|
|
Cmd = MMC_CMD17;
|
2011-02-02 23:35:30 +01:00
|
|
|
#else
|
2011-06-03 11:10:26 +02:00
|
|
|
//TODO: Should we support read stream (MMC_CMD11)
|
2011-02-02 23:35:30 +01:00
|
|
|
#endif
|
2011-06-03 11:10:26 +02:00
|
|
|
} else {
|
2011-02-02 23:35:30 +01:00
|
|
|
#ifndef USE_STREAM
|
2011-06-03 11:10:26 +02:00
|
|
|
// Write a single block
|
|
|
|
Cmd = MMC_CMD24;
|
2011-02-02 23:35:30 +01:00
|
|
|
#else
|
2011-06-03 11:10:26 +02:00
|
|
|
//TODO: Should we support write stream (MMC_CMD20)
|
2011-02-02 23:35:30 +01:00
|
|
|
#endif
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, Cmd, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIoBlocks(MMC_CMD%d): Error %r\n", Cmd, Status));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
if (Transfer == MMC_IOBLOCKS_READ) {
|
2011-02-02 23:35:30 +01:00
|
|
|
#ifndef USE_STREAM
|
2011-06-03 11:10:26 +02:00
|
|
|
// Read one block of Data
|
2013-03-12 01:45:29 +01:00
|
|
|
Status = MmcHost->ReadBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Read Block Data and Status = %r\n", Status));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
#else
|
2012-08-02 12:23:41 +02:00
|
|
|
//TODO: Read a stream
|
2013-03-12 01:45:29 +01:00
|
|
|
ASSERT (0);
|
2011-02-02 23:35:30 +01:00
|
|
|
#endif
|
2011-06-03 11:10:26 +02:00
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcProgrammingState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcProgrammingState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
|
|
|
} else {
|
2011-02-02 23:35:30 +01:00
|
|
|
#ifndef USE_STREAM
|
2011-06-03 11:10:26 +02:00
|
|
|
// Write one block of Data
|
2013-03-12 01:45:29 +01:00
|
|
|
Status = MmcHost->WriteBlockData (MmcHost, Lba, This->Media->BlockSize, Buffer);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_BLKIO, "MmcIoBlocks(): Error Write Block Data and Status = %r\n", Status));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
#else
|
2012-08-02 12:23:41 +02:00
|
|
|
//TODO: Write a stream
|
2013-03-12 01:45:29 +01:00
|
|
|
ASSERT (0);
|
2011-02-02 23:35:30 +01:00
|
|
|
#endif
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
// Command 12 - Stop transmission (ends read)
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD12, 0);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1b, Response);
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
// Command 13 - Read status and wait for programming to complete (return to tran)
|
|
|
|
Timeout = MMCI0_TIMEOUT;
|
|
|
|
CmdArg = MmcHostInstance->CardInfo.RCA << 16;
|
|
|
|
Response[0] = 0;
|
2012-08-02 12:23:41 +02:00
|
|
|
while( (!(Response[0] & MMC_R0_READY_FOR_DATA))
|
2013-03-12 01:45:29 +01:00
|
|
|
&& (MMC_R0_CURRENTSTATE (Response) != MMC_R0_STATE_TRAN)
|
2012-08-02 12:23:41 +02:00
|
|
|
&& Timeout--) {
|
2011-09-01 19:08:41 +02:00
|
|
|
Status = MmcHost->SendCommand (MmcHost, MMC_CMD13, CmdArg);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (!EFI_ERROR (Status)) {
|
2012-08-02 12:14:52 +02:00
|
|
|
MmcHost->ReceiveResponse (MmcHost, MMC_RESPONSE_TYPE_R1, Response);
|
|
|
|
if ((Response[0] & MMC_R0_READY_FOR_DATA)) {
|
|
|
|
break; // Prevents delay once finished
|
|
|
|
}
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2013-03-12 01:45:29 +01:00
|
|
|
NanoSecondDelay (100);
|
2011-06-03 11:10:26 +02:00
|
|
|
}
|
2011-02-02 23:35:30 +01:00
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
Status = MmcNotifyState (MmcHostInstance, MmcTransferState);
|
2013-03-12 01:45:29 +01:00
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
DEBUG ((EFI_D_ERROR, "MmcIoBlocks() : Error MmcTransferState\n"));
|
2011-06-03 11:10:26 +02:00
|
|
|
return Status;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
2011-06-03 11:10:26 +02:00
|
|
|
BytesRemainingToBeTransfered -= This->Media->BlockSize;
|
|
|
|
Lba += BlockCount;
|
|
|
|
Buffer = (UINT8 *)Buffer + This->Media->BlockSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MmcReadBlocks (
|
|
|
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
|
|
IN UINT32 MediaId,
|
|
|
|
IN EFI_LBA Lba,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
OUT VOID *Buffer
|
2011-06-03 11:10:26 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return MmcIoBlocks (This, MMC_IOBLOCKS_READ, MediaId, Lba, BufferSize, Buffer);
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MmcWriteBlocks (
|
|
|
|
IN EFI_BLOCK_IO_PROTOCOL *This,
|
|
|
|
IN UINT32 MediaId,
|
|
|
|
IN EFI_LBA Lba,
|
|
|
|
IN UINTN BufferSize,
|
|
|
|
IN VOID *Buffer
|
2011-06-03 11:10:26 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return MmcIoBlocks (This, MMC_IOBLOCKS_WRITE, MediaId, Lba, BufferSize, Buffer);
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
EFIAPI
|
|
|
|
MmcFlushBlocks (
|
|
|
|
IN EFI_BLOCK_IO_PROTOCOL *This
|
2011-06-03 11:10:26 +02:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return EFI_SUCCESS;
|
2011-02-02 23:35:30 +01:00
|
|
|
}
|