qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
To: "Markus Armbruster" <armbru@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Eric Blake" <eblake@redhat.com>, "Joel Stanley" <joel@jms.id.au>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Vincent Palatin" <vpalatin@chromium.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Edgar E. Iglesias" <edgar.iglesias@xilinx.com>,
	"Luc Michel" <luc.michel@greensocs.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Cc: saipava@xilinx.com, qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: [RFC PATCH 07/15] sd: emmc: add CMD21 tuning sequence
Date: Thu, 11 Feb 2021 13:47:18 +0530	[thread overview]
Message-ID: <1613031446-22154-8-git-send-email-sai.pavan.boddu@xilinx.com> (raw)
In-Reply-To: <1613031446-22154-1-git-send-email-sai.pavan.boddu@xilinx.com>

eMMC cards support tuning sequence for entering HS200 mode.

Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 hw/sd/sd.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 7925174..90359f6 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1378,6 +1378,14 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
         }
         break;
 
+    case 21:    /* CMD21: mmc SEND TUNING_BLOCK */
+        if (sd->emmc && (sd->state == sd_transfer_state)) {
+            sd->state = sd_sendingdata_state;
+            sd->data_offset = 0;
+            return sd_r1;
+        }
+        break;
+
     case 23:    /* CMD23: SET_BLOCK_COUNT */
         if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
             break;
@@ -2112,6 +2120,30 @@ static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE] = {
     0xbb, 0xff, 0xf7, 0xff,         0xf7, 0x7f, 0x7b, 0xde,
 };
 
+#define EXCSD_BUS_WIDTH_OFFSET 183
+#define BUS_WIDTH_8_MASK    0x4
+#define BUS_WIDTH_4_MASK    0x2
+#define MMC_TUNING_BLOCK_SIZE   128
+
+static const uint8_t mmc_tunning_block_pattern[128] = {
+       0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
+       0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc, 0xcc,
+       0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff, 0xff,
+       0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee, 0xff,
+       0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd, 0xdd,
+       0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb,
+       0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff, 0xff,
+       0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, 0xff,
+       0xff, 0xff, 0xff, 0x00, 0xff, 0xff, 0xff, 0x00,
+       0x00, 0xff, 0xff, 0xcc, 0xcc, 0xcc, 0x33, 0xcc,
+       0xcc, 0xcc, 0x33, 0x33, 0xcc, 0xcc, 0xcc, 0xff,
+       0xff, 0xff, 0xee, 0xff, 0xff, 0xff, 0xee, 0xee,
+       0xff, 0xff, 0xff, 0xdd, 0xff, 0xff, 0xff, 0xdd,
+       0xdd, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff, 0xff,
+       0xbb, 0xbb, 0xff, 0xff, 0xff, 0x77, 0xff, 0xff,
+       0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee,
+};
+
 uint8_t sd_read_byte(SDState *sd)
 {
     /* TODO: Append CRCs */
@@ -2204,6 +2236,21 @@ uint8_t sd_read_byte(SDState *sd)
         ret = sd_tuning_block_pattern[sd->data_offset++];
         break;
 
+    case 21:    /* CMD21: SEND_TUNNING_BLOCK (MMC) */
+        if (sd->data_offset >= MMC_TUNING_BLOCK_SIZE - 1) {
+            sd->state = sd_transfer_state;
+        }
+        if (sd->ext_csd[EXCSD_BUS_WIDTH_OFFSET] & BUS_WIDTH_8_MASK) {
+            ret = mmc_tunning_block_pattern[sd->data_offset++];
+        } else {
+            /* Return LSB Nibbles of two byte from the 8bit tuning block
+             * for 4bit mode
+             */
+            ret = mmc_tunning_block_pattern[sd->data_offset++] & 0x0F;
+            ret |= (mmc_tunning_block_pattern[sd->data_offset++] & 0x0F) << 4;
+        }
+        break;
+
     case 22:	/* ACMD22: SEND_NUM_WR_BLOCKS */
         ret = sd->data[sd->data_offset ++];
 
-- 
2.7.4



  parent reply	other threads:[~2021-02-11  8:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-11  8:17 [RFC PATCH 00/15] eMMC support Sai Pavan Boddu
2021-02-11  8:17 ` [RFC PATCH 01/15] block: add eMMC block device type Sai Pavan Boddu
2021-02-12 21:29   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 02/15] sd: add eMMC support Sai Pavan Boddu
2021-02-13 13:18   ` Luc Michel
2021-02-11  8:17 ` [RFC PATCH 03/15] sd: emmc: Dont not update CARD_CAPACITY for eMMC cards Sai Pavan Boddu
2021-02-12 21:34   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 04/15] sd: emmc: Update CMD1 definition for eMMC Sai Pavan Boddu
2021-02-12 22:06   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 05/15] sd: emmc: support idle state in CMD2 Sai Pavan Boddu
2021-02-12 22:07   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 06/15] sd: emmc: Add mmc switch function support Sai Pavan Boddu
2021-02-11  8:17 ` Sai Pavan Boddu [this message]
2021-02-11  8:17 ` [RFC PATCH 08/15] sd: emmc: Make ACMD41 illegal for mmc Sai Pavan Boddu
2021-02-11  8:17 ` [RFC PATCH 09/15] sd: emmc: Add support for emmc erase Sai Pavan Boddu
2021-02-12 22:08   ` Alistair Francis
2021-02-16 10:03     ` Sai Pavan Boddu
2021-02-11  8:17 ` [RFC PATCH 10/15] sd: emmc: Update CID structure for eMMC Sai Pavan Boddu
2021-02-12 22:10   ` Alistair Francis
2021-02-16 10:51     ` Sai Pavan Boddu
2021-02-11  8:17 ` [RFC PATCH 11/15] sd: emmc: Add Extended CSD register definitions Sai Pavan Boddu
2021-02-13 12:56   ` Luc Michel
2021-02-16 11:11     ` Sai Pavan Boddu
2021-02-22  9:38       ` Cédric Le Goater
2021-02-11  8:17 ` [RFC PATCH 12/15] sd: emmc: Support boot area in emmc image Sai Pavan Boddu
2021-02-12 22:16   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 13/15] sd: emmc: Subtract bootarea size from blk Sai Pavan Boddu
2021-02-12 22:11   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 14/15] sd: sdhci: Support eMMC devices Sai Pavan Boddu
2021-02-12 22:12   ` Alistair Francis
2021-02-11  8:17 ` [RFC PATCH 15/15] arm: xlnx-versal: Add emmc to versal Sai Pavan Boddu
2021-02-12 21:37   ` Alistair Francis
2021-02-13  7:25     ` Edgar E. Iglesias

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-all 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=1613031446-22154-8-git-send-email-sai.pavan.boddu@xilinx.com \
    --to=sai.pavan.boddu@xilinx.com \
    --cc=alistair.francis@wdc.com \
    --cc=armbru@redhat.com \
    --cc=clg@kaod.org \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=joel@jms.id.au \
    --cc=kwolf@redhat.com \
    --cc=luc.michel@greensocs.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=saipava@xilinx.com \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=vpalatin@chromium.org \
    --cc=vsementsov@virtuozzo.com \
    /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;
as well as URLs for NNTP newsgroup(s).