From: Frank Chang <frank.ch...@sifive.com>

In SPI-mode, CMD58 returns R3 response with the format:

39          32 31                                  0
+------------+ +-----------------------------------+
|     R1     | |                OCR                |
+------------+ +-----------------------------------+

Where R1 has bits[0] indicating whether SD card is "in idle state".
However, according to SD card state transition table, CMD58 can only be
transited from trans to data state, which the "in idle state" bit should
not be set in CMD58's R3 response.
(But CMD8 should still have "in idle state" bit to be set in its
R7 response because it can only be transited from idle to idle state.)

Signed-off-by: Frank Chang <frank.ch...@sifive.com>
---
 hw/sd/ssi-sd.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 167c03b780..7faa969e82 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -176,12 +176,17 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev, 
uint32_t val)
                 s->arglen = 1;
                 s->response[0] = 4;
                 DPRINTF("SD command failed\n");
-            } else if (s->cmd == 8 || s->cmd == 58) {
-                /* CMD8/CMD58 returns R3/R7 response */
-                DPRINTF("Returned R3/R7\n");
+            } else if (s->cmd == 8) {
+                /* CMD8 returns R7 response */
+                DPRINTF("Returned R7\n");
                 s->arglen = 5;
                 s->response[0] = 1;
                 memcpy(&s->response[1], longresp, 4);
+            } else if (s->cmd == 58) {
+                /* CMD58 returns R3 response */
+                DPRINTF("Returned R3\n");
+                s->arglen = 5;
+                memcpy(&s->response[1], longresp, 4);
             } else if (s->arglen != 4) {
                 BADF("Unexpected response to cmd %d\n", s->cmd);
                 /* Illegal command is about as near as we can get.  */
-- 
2.31.1


Reply via email to