[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 20/32] hw/sd: Add CMD21 tuning sequence
From: |
Cédric Le Goater |
Subject: |
[PATCH 20/32] hw/sd: Add CMD21 tuning sequence |
Date: |
Mon, 3 Jul 2023 15:24:57 +0200 |
From: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
MMC cards support different 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>
[ clg: - ported on QEMU 7.0 ]
Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
hw/sd/sd.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 4b4a4cda2e68..7332f7a18435 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -2017,6 +2017,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_tuning_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 */
@@ -2103,6 +2127,22 @@ uint8_t sd_read_byte(SDState *sd)
ret = sd_tuning_block_pattern[sd->data_offset++];
break;
+ case 21: /* CMD21: SEND_TUNING_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_tuning_block_pattern[sd->data_offset++];
+ } else {
+ /*
+ * Return LSB Nibbles of two byte from the 8bit tuning
+ * block for 4bit mode
+ */
+ ret = mmc_tuning_block_pattern[sd->data_offset++] & 0x0F;
+ ret |= (mmc_tuning_block_pattern[sd->data_offset++] & 0x0F) << 4;
+ }
+ break;
+
case 22: /* ACMD22: SEND_NUM_WR_BLOCKS */
ret = sd->data[sd->data_offset ++];
--
2.41.0
- [PATCH 11/32] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler, (continued)
- [PATCH 11/32] hw/sd: Add sd_cmd_SEND_TUNING_BLOCK() handler, Cédric Le Goater, 2023/07/03
- [PATCH 13/32] hw/sd: Introduce a "sd-card" SPI variant model, Cédric Le Goater, 2023/07/03
- [PATCH 14/32] hw/sd: Basis for eMMC support, Cédric Le Goater, 2023/07/03
- [PATCH 15/32] hw/sd: Add emmc_cmd_SEND_OP_CMD() handler, Cédric Le Goater, 2023/07/03
- [PATCH 16/32] hw/sd: Add emmc_cmd_ALL_SEND_CID() handler, Cédric Le Goater, 2023/07/03
- [PATCH 17/32] hw/sd: Add emmc_cmd_SEND_RELATIVE_ADDR() handler, Cédric Le Goater, 2023/07/03
- [PATCH 18/32] hw/sd: Add emmc_cmd_APP_CMD() handler, Cédric Le Goater, 2023/07/03
- [PATCH 21/32] hw/sd: Add mmc switch function support, Cédric Le Goater, 2023/07/03
- [PATCH 22/32] hw/sd: Add emmc_cmd_SEND_EXT_CSD() handler, Cédric Le Goater, 2023/07/03
- [PATCH 19/32] hw/sd: add emmc_cmd_SEND_TUNING_BLOCK() handler, Cédric Le Goater, 2023/07/03
- [PATCH 20/32] hw/sd: Add CMD21 tuning sequence,
Cédric Le Goater <=
- [PATCH 23/32] hw/sd: Support boot area in emmc image, Cédric Le Goater, 2023/07/03
- [PATCH 24/32] hw/sd: Subtract bootarea size from blk, Cédric Le Goater, 2023/07/03
- [PATCH 25/32] hw/sd: Add boot config support, Cédric Le Goater, 2023/07/03
- [PATCH 26/32] hw/sd: Fix SET_BLOCK_COUNT command argument, Cédric Le Goater, 2023/07/03
- [PATCH 28/32] hw/arm/aspeed: Add eMMC device, Cédric Le Goater, 2023/07/03
- [PATCH 30/32] hw/arm/aspeed: Set boot device to emmc, Cédric Le Goater, 2023/07/03
- [PATCH 31/32] aspeed: Set bootconfig, Cédric Le Goater, 2023/07/03
- [PATCH 27/32] hw/sd: Update CMD1 definition for MMC, Cédric Le Goater, 2023/07/03
- [PATCH 32/32] aspeed: Introduce a 'boot-emmc' property for AST2600 based machines, Cédric Le Goater, 2023/07/03
- [PATCH 29/32] hw/arm/aspeed: Load eMMC first boot area as a boot rom, Cédric Le Goater, 2023/07/03