hw/sd: Correct the CURRENT_STATE bits in SPI-mode response
PATCH 1/1 hw/sd: Correct the CURRENT_STATE bits in SPI-mode response
From: Frank Chang <[email protected]>
In SPI-mode, type B ("cleared on valid command") clear condition is not supported, and as the "In idle state" bit in SPI-mode has type A ("according to current state") clear condition, the CURRENT_STATE bits in an SPI-mode response should be the SD card's state after the command is executed, instead of the state when it received the preceding command.
Also, we don't need to clear the type B ("clear on valid command") status bits after the response is updated in SPI-mode.
--- hw/sd/sd.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)
hw/sd/sd.c +18 -8
@@ -1757,12 +1757,20 @@ int sd_do_command(SDState *sd, SDRequest *req,if (rtype == sd_illegal) { sd->card_status |=ILLEGAL_COMMAND ; }else { -/* Valid command, we can update the 'state before command' bits. -* (Do this now so they appear in r1 responses.) -*/ sd->current_cmd = req->cmd; sd->card_status &= ~CURRENT_STATE ; - sd->card_status |= (last_state <<9 ); + +if (!sd->spi) { +/* Valid command, we can update the 'state before command' bits. +* (Do this now so they appear in r1 responses.) +*/ + sd->card_status |= (last_state <<9 ); + }else { +/* Type B ("clear on valid command") is not supported +* in SPI-mode. +*/ + sd->card_status |= (sd->state <<9 ); + } } send_response:
@@ -1808,10 +1816,12 @@ send_response:trace_sdcard_response (sd_response_name (rtype), rsplen);if (rtype != sd_illegal) { -/* Clear the "clear on valid command" status bits now we've -* sent any response -*/ - sd->card_status &= ~CARD_STATUS_B ; +if (!sd->spi) { +/* Clear the "clear on valid command" status bits now we've +* sent any response +*/ + sd->card_status &= ~CARD_STATUS_B ; + } }#ifdef DEBUG_SD
Signature · 1 line
2.31.1
Quoted 65 lines · On Tue, Jan 18, 2022 at 10:35 AM <[email protected]> wrote:
From: Frank Chang <[email protected]>
In SPI-mode, type B ("cleared on valid command") clear condition is not supported, and as the "In idle state" bit in SPI-mode has type A ("according to current state") clear condition, the
CURRENT_STATEbits in an SPI-mode response should be the SD card's state after the command is executed, instead of the state when it received the preceding command.Also, we don't need to clear the type B ("clear on valid command") status bits after the response is updated in SPI-mode.
Signed-off-by Frank Chang <[email protected]>--- hw/sd/sd.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-)hw/sd/sd.c +3
-4@@ -1757,12 +1757,20 @@ int sd_do_command(SDState *sd, SDRequest *req,if (rtype == sd_illegal) { sd->card_status |=ILLEGAL_COMMAND ; }else { -/* Valid command, we can update the 'state before command' bits. -* (Do this now so they appear in r1 responses.) -*/ sd->current_cmd = req->cmd; sd->card_status &= ~CURRENT_STATE ; - sd->card_status |= (last_state <<9 ); + +if (!sd->spi) { +/* Valid command, we can update the 'state before command' bits.
hw/sd/sd.c +15
-5+* (Do this now so they appear in r1 responses.) +*/ + sd->card_status |= (last_state <<9 ); + }else { +/* Type B ("clear on valid command") is not supported +* in SPI-mode. +*/ + sd->card_status |= (sd->state <<9 ); + } } send_response:@@ -1808,10 +1816,12 @@ send_response:trace_sdcard_response (sd_response_name (rtype), rsplen);if (rtype != sd_illegal) { -/* Clear the "clear on valid command" status bits now we've -* sent any response -*/ - sd->card_status &= ~CARD_STATUS_B ; +if (!sd->spi) { +/* Clear the "clear on valid command" status bits now we've +* sent any response +*/ + sd->card_status &= ~CARD_STATUS_B ; + } }#ifdef DEBUG_SD --
Quoted 3 lines
2.31.1
This patch is replaced with more proper SPI clear conditions fix patch:
https://patchew.org/QEMU/[email protected]/
Please ignore this one, sorry for the confusion.
Regards,
Frank Chang