[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/18] hw/sd: ssi-sd: Support multiple block write
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 06/18] hw/sd: ssi-sd: Support multiple block write |
Date: |
Sat, 20 Feb 2021 01:12:57 +0100 |
From: Bin Meng <bin.meng@windriver.com>
For a multiple block write operation, each block begins with a multi
write start token. Unlike the SD mode that the multiple block write
ends when receiving a STOP_TRAN command (CMD12), a special stop tran
token is used to signal the card.
Emulating this by manually sending a CMD12 to the SD card core, to
bring it out of the receiving data state.
Signed-off-by: Bin Meng <bin.meng@windriver.com>
Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Acked-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20210128063035.15674-7-bmeng.cn@gmail.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
hw/sd/ssi-sd.c | 33 +++++++++++++++++++++++++++++++--
1 file changed, 31 insertions(+), 2 deletions(-)
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 1205ad8b52c..200e885225a 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -4,6 +4,11 @@
* Copyright (c) 2007-2009 CodeSourcery.
* Written by Paul Brook
*
+ * Copyright (c) 2021 Wind River Systems, Inc.
+ * Improved by Bin Meng <bin.meng@windriver.com>
+ *
+ * Validated with U-Boot v2021.01 and Linux v5.10 mmc_spi driver
+ *
* This code is licensed under the GNU GPL v2.
*
* Contributions after 2012-01-13 are licensed under the terms of the
@@ -82,6 +87,10 @@ OBJECT_DECLARE_SIMPLE_TYPE(ssi_sd_state, SSI_SD)
#define SSI_SDR_ADDRESS_ERROR 0x2000
#define SSI_SDR_PARAMETER_ERROR 0x4000
+/* multiple block write */
+#define SSI_TOKEN_MULTI_WRITE 0xfc
+/* terminate multiple block write */
+#define SSI_TOKEN_STOP_TRAN 0xfd
/* single block read/write, multiple block read */
#define SSI_TOKEN_SINGLE 0xfe
@@ -94,6 +103,8 @@ OBJECT_DECLARE_SIMPLE_TYPE(ssi_sd_state, SSI_SD)
static uint32_t ssi_sd_transfer(SSIPeripheral *dev, uint32_t val)
{
ssi_sd_state *s = SSI_SD(dev);
+ SDRequest request;
+ uint8_t longresp[16];
/*
* Special case: allow CMD12 (STOP TRANSMISSION) while reading data.
@@ -125,8 +136,28 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev,
uint32_t val)
return SSI_DUMMY;
break;
case SSI_TOKEN_SINGLE:
+ case SSI_TOKEN_MULTI_WRITE:
DPRINTF("Start write block\n");
s->mode = SSI_SD_DATA_WRITE;
+ return SSI_DUMMY;
+ case SSI_TOKEN_STOP_TRAN:
+ DPRINTF("Stop multiple write\n");
+
+ /* manually issue cmd12 to stop the transfer */
+ request.cmd = 12;
+ request.arg = 0;
+ s->arglen = sdbus_do_command(&s->sdbus, &request, longresp);
+ if (s->arglen <= 0) {
+ s->arglen = 1;
+ /* a zero value indicates the card is busy */
+ s->response[0] = 0;
+ DPRINTF("SD card busy\n");
+ } else {
+ s->arglen = 1;
+ /* a non-zero value indicates the card is ready */
+ s->response[0] = SSI_DUMMY;
+ }
+
return SSI_DUMMY;
}
@@ -136,8 +167,6 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev,
uint32_t val)
return SSI_DUMMY;
case SSI_SD_CMDARG:
if (s->arglen == 4) {
- SDRequest request;
- uint8_t longresp[16];
/* FIXME: Check CRC. */
request.cmd = s->cmd;
request.arg = ldl_be_p(s->cmdarg);
--
2.26.2
- [PULL 00/18] SD/MMC patches for 2021-02-20, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 01/18] hw/sd: ssi-sd: Support multiple block read, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 02/18] hw/sd: sd: Remove duplicated codes in single/multiple block read/write, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 03/18] hw/sd: sd: Allow single/multiple block write for SPI mode, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 04/18] hw/sd: Introduce receive_ready() callback, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 05/18] hw/sd: ssi-sd: Support single block write, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 06/18] hw/sd: ssi-sd: Support multiple block write,
Philippe Mathieu-Daudé <=
- [PULL 07/18] hw/sd: ssi-sd: Fix SEND_IF_COND (CMD8) response, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 08/18] hw/sd: ssi-sd: Fix STOP_TRANSMISSION (CMD12) response, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 09/18] hw/sd: ssi-sd: Handle the rest commands with R1b response type, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 10/18] hw/sd: sd: Fix address check in sd_erase(), Philippe Mathieu-Daudé, 2021/02/19
- [PULL 11/18] hw/sd: sd: Only SDSC cards support CMD28/29/30, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 12/18] hw/sd: sd: Fix CMD30 response type, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 13/18] hw/sd: sd: Move the sd_block_{read, write} and macros ahead, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 14/18] hw/sd: sd: Skip write protect groups check in sd_erase() for high capacity cards, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 15/18] hw/sd: sd: Skip write protect groups check in CMD24/25 for high capacity cards, Philippe Mathieu-Daudé, 2021/02/19
- [PULL 16/18] hw/sd: sd: Bypass the RCA check for CMD13 in SPI mode, Philippe Mathieu-Daudé, 2021/02/19