From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-x230.google.com (mail-wr0-x230.google.com [IPv6:2a00:1450:400c:c0c::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6733821E7493E for ; Wed, 6 Sep 2017 09:36:13 -0700 (PDT) Received: by mail-wr0-x230.google.com with SMTP id o42so4422681wrb.3 for ; Wed, 06 Sep 2017 09:39:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TT/iycV4zLJ3vu1/D4Wh59Gfy4BpjXd+x7GD5rsbvnE=; b=Cvft7FqfoXWnWj44t2taNPwAyPJ7xDiU2XwmhgYSISmbX22pkP3/lR0YMqduULgCyL ivBhz+lDTrfoSLucTuxs3R9FWdnyEjV+UFINidMzTE2IFRea5WSEB7HKDjIxyxXjCRQX Rb5KnkeRGJ8vHkXNNcWE6clmkiwNm0b+OLUcQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TT/iycV4zLJ3vu1/D4Wh59Gfy4BpjXd+x7GD5rsbvnE=; b=pVEqRifygy4mwdXfs5WSfNicJiohtnzHnCODCy4SUe+JV3VTpxx0Fvb4OkydOf1Zyq PEYa3Jil2Zg65Fpb/7SOloyoKiLmovalBQIbIAAsycLvkeFcIy82LZU/+VD9LPGV91eq ys2skSRR1Nf+UL42lMFe5eWkepLd+XiLM9T2nkwgz3hq/StmEKPNq3Ma2k/PwsK/3qBP UfiS4WgiorxBRni63rfIYfv06OrAhnB+ve36kl80nMpjZdFtqb98qGtIoRMX0FXpbbb4 drWJR/ke1wJzl022JXBSlfp+PfBFueW4pmB554OWgYYT8BVDKbX8nYKAY1gHCtgO0tns jqFg== X-Gm-Message-State: AHPjjUhS3tTOOdOpyRnvIIn642/B+PvDPk+8GwW/fquGOsYCldZ+AFWn 5UVPBqk4xYZFK60k X-Google-Smtp-Source: ADKCNb7NOElBwQrb3o03/JqQSaQ8cW0jKVghwtZu+moj/N41lQ1BfNcyarqgGo1rrq2rrX/OtHjVGA== X-Received: by 10.223.134.23 with SMTP id 23mr1955316wrv.93.1504715942212; Wed, 06 Sep 2017 09:39:02 -0700 (PDT) Received: from bivouac.eciton.net (bivouac.eciton.net. [2a00:1098:0:86:1000:23:0:2]) by smtp.gmail.com with ESMTPSA id r72sm1910256wmb.9.2017.09.06.09.39.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 06 Sep 2017 09:39:01 -0700 (PDT) Date: Wed, 6 Sep 2017 17:39:00 +0100 From: Leif Lindholm To: Meenakshi Aggarwal Cc: edk2-devel@lists.01.org, jun.nie@linaro.org, haojian.zhuang@linaro.org Message-ID: <20170906163900.gbshgj27m4xj7qcb@bivouac.eciton.net> References: <1504695310-25426-1-git-send-email-meenakshi.aggarwal@nxp.com> <1504695310-25426-2-git-send-email-meenakshi.aggarwal@nxp.com> MIME-Version: 1.0 In-Reply-To: <1504695310-25426-2-git-send-email-meenakshi.aggarwal@nxp.com> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [PATCH v2 2/2] SD : Updated CMD 6 implememtation. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Sep 2017 16:36:13 -0000 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 06, 2017 at 04:25:10PM +0530, Meenakshi Aggarwal wrote: > For setting high speed in SD card, > First CMD 6 (Switch) is send to check if card supports High Speed and > Second command is send to switch card to high speed mode. > > In current inplementation, CMD 6 was sent only once to switch the > card into HS mode without checking if card supports HS or not, which is > not as per specification and also we are not setting the HS i.e. 50000000 > but directly asking the card to switch to 26000000 which is incorrect as > SD card supports either 25000000 or 50000000. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Meenakshi Aggarwal Same comment as for 1/2: please address PatchCheck.py feedback: * EFI_D_ERROR was used, but DEBUG_ERROR is now recommended Other than that, looks good to me. Jun, anything further? / Leif > --- > EmbeddedPkg/Universal/MmcDxe/Mmc.h | 8 ++++ > EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c | 55 +++++++++++++++++++++--- > 2 files changed, 57 insertions(+), 6 deletions(-) > > diff --git a/EmbeddedPkg/Universal/MmcDxe/Mmc.h b/EmbeddedPkg/Universal/MmcDxe/Mmc.h > index f3e56ff..a77ba41 100644 > --- a/EmbeddedPkg/Universal/MmcDxe/Mmc.h > +++ b/EmbeddedPkg/Universal/MmcDxe/Mmc.h > @@ -64,6 +64,14 @@ > #define EMMC_CMD6_ARG_VALUE(x) (((x) & 0xFF) << 8) > #define EMMC_CMD6_ARG_CMD_SET(x) (((x) & 0x7) << 0) > > +#define SWITCH_CMD_DATA_LENGTH 64 > +#define SD_HIGH_SPEED_SUPPORTED 0x20000 > +#define SD_DEFAULT_SPEED 25000000 > +#define SD_HIGH_SPEED 50000000 > +#define SWITCH_CMD_SUCCESS_MASK 0x0f000000 > + > +#define BUSWIDTH_4 4 > + > typedef enum { > UNKNOWN_CARD, > MMC_CARD, //MMC card > diff --git a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c > index 8010dea..e60d8b0 100644 > --- a/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c > +++ b/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c > @@ -318,6 +318,23 @@ InitializeEmmcDevice ( > } > > STATIC > +UINT32 > +CreateSwitchCmdArgument ( > + IN UINT32 Mode, > + IN UINT8 Group, > + IN UINT8 Value > + ) > +{ > + UINT32 Argument; > + > + Argument = Mode << 31 | 0x00FFFFFF; > + Argument &= ~(0xF << (Group * 4)); > + Argument |= Value << (Group * 4); > + > + return Argument; > +} > + > +STATIC > EFI_STATUS > InitializeSdMmcDevice ( > IN MMC_HOST_INSTANCE *MmcHostInstance > @@ -326,6 +343,7 @@ InitializeSdMmcDevice ( > UINT32 CmdArg; > UINT32 Response[4]; > UINT32 Buffer[128]; > + UINT32 Speed; > UINTN BlockSize; > UINTN CardSize; > UINTN NumBlocks; > @@ -334,6 +352,7 @@ InitializeSdMmcDevice ( > EFI_STATUS Status; > EFI_MMC_HOST_PROTOCOL *MmcHost; > > + Speed = SD_DEFAULT_SPEED; > MmcHost = MmcHostInstance->MmcHost; > > // Send a command to get Card specific data > @@ -439,21 +458,45 @@ InitializeSdMmcDevice ( > } > } > if (CccSwitch) { > - /* SD Switch, Mode:1, Group:0, Value:1 */ > - CmdArg = 1 << 31 | 0x00FFFFFF; > - CmdArg &= ~(0xF << (0 * 4)); > - CmdArg |= 1 << (0 * 4); > + /* SD Switch, Mode:0, Group:0, Value:0 */ > + CmdArg = CreateSwitchCmdArgument(0, 0, 0); > Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): Error and Status = %r\n", __FUNCTION__, Status)); > return Status; > } else { > - Status = MmcHost->ReadBlockData (MmcHost, 0, 64, Buffer); > + Status = MmcHost->ReadBlockData (MmcHost, 0, SWITCH_CMD_DATA_LENGTH, Buffer); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): ReadBlockData Error and Status = %r\n", __FUNCTION__, Status)); > return Status; > } > } > + > + if (!(Buffer[3] & SD_HIGH_SPEED_SUPPORTED)) { > + DEBUG ((EFI_D_ERROR, "%a : High Speed not supported by Card %r\n", __FUNCTION__, Status)); > + return Status; > + } > + > + Speed = SD_HIGH_SPEED; > + > + /* SD Switch, Mode:1, Group:0, Value:1 */ > + CmdArg = CreateSwitchCmdArgument(1, 0, 1); > + Status = MmcHost->SendCommand (MmcHost, MMC_CMD6, CmdArg); > + if (EFI_ERROR (Status)) { > + DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): Error and Status = %r\n", __FUNCTION__, Status)); > + return Status; > + } else { > + Status = MmcHost->ReadBlockData (MmcHost, 0, SWITCH_CMD_DATA_LENGTH, Buffer); > + if (EFI_ERROR (Status)) { > + DEBUG ((EFI_D_ERROR, "%a (MMC_CMD6): ReadBlockData Error and Status = %r\n",__FUNCTION__, Status)); > + return Status; > + } > + > + if ((Buffer[4] & SWITCH_CMD_SUCCESS_MASK) != 0x01000000) { > + DEBUG((EFI_D_ERROR, "Problem switching SD card into high-speed mode\n")); > + return Status; > + } > + } > } > if (Scr.SD_BUS_WIDTHS & SD_BUS_WIDTH_4BIT) { > CmdArg = MmcHostInstance->CardInfo.RCA << 16; > @@ -470,7 +513,7 @@ InitializeSdMmcDevice ( > } > } > if (MMC_HOST_HAS_SETIOS(MmcHost)) { > - Status = MmcHost->SetIos (MmcHost, 26 * 1000 * 1000, 4, EMMCBACKWARD); > + Status = MmcHost->SetIos (MmcHost, Speed, BUSWIDTH_4, EMMCBACKWARD); > if (EFI_ERROR (Status)) { > DEBUG ((EFI_D_ERROR, "%a (SetIos): Error and Status = %r\n", __FUNCTION__, Status)); > return Status; > -- > 1.9.1 >