aboutsummaryrefslogtreecommitdiff
path: root/hw/sd/sd.c
diff options
context:
space:
mode:
authorPhilippe Mathieu-Daudé <philmd@linaro.org>2024-06-25 05:50:16 +0200
committerPhilippe Mathieu-Daudé <philmd@linaro.org>2024-07-02 10:08:32 +0200
commit257e36c9e602b5d10927292d38a9c85c5738683a (patch)
treefe7693b276444007c0cf099f773d6afc51b3ca4b /hw/sd/sd.c
parent26be1ceee5c5d0b01ebadc271807e6fb870670e7 (diff)
hw/sd/sdcard: Simplify sd_inactive_state handling
Card entering sd_inactive_state powers off, and won't respond anymore. Handle that once when entering sd_do_command(). Remove condition always true in sd_cmd_GO_IDLE_STATE(). Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> Tested-by: Cédric Le Goater <clg@redhat.com> Reviewed-by: Cédric Le Goater <clg@redhat.com> Message-Id: <20240628070216.92609-12-philmd@linaro.org>
Diffstat (limited to 'hw/sd/sd.c')
-rw-r--r--hw/sd/sd.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 824cb47856..30c1d299d4 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1078,10 +1078,8 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)
/* CMD0 */
static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req)
{
- if (sd->state != sd_inactive_state) {
- sd->state = sd_idle_state;
- sd_reset(DEVICE(sd));
- }
+ sd->state = sd_idle_state;
+ sd_reset(DEVICE(sd));
return sd_is_spi(sd) ? sd_r1 : sd_r0;
}
@@ -1580,7 +1578,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
switch (sd->state) {
case sd_ready_state:
case sd_identification_state:
- case sd_inactive_state:
return sd_illegal;
case sd_idle_state:
if (rca) {
@@ -1801,6 +1798,11 @@ int sd_do_command(SDState *sd, SDRequest *req,
return 0;
}
+ if (sd->state == sd_inactive_state) {
+ rtype = sd_illegal;
+ goto send_response;
+ }
+
if (sd_req_crc_validate(req)) {
sd->card_status |= COM_CRC_ERROR;
rtype = sd_illegal;