diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2011-12-18 21:37:55 +0100 |
---|---|---|
committer | Andrzej Zaborowski <andrew.zaborowski@intel.com> | 2011-12-21 05:01:31 +0100 |
commit | 53bb8cc4855827f2981bf0566076233573a05bd7 (patch) | |
tree | ed473e8d7151bd594b5aa2b6a7d93219708e4d7f /hw/sd.c | |
parent | e30d59388bab90418b414c1f29d5779361d31ffe (diff) |
hw/sd.c: Handle illegal commands in sd_do_command
Add an extra sd_illegal value to the sd_rsp_type_t enum so that
sd_app_command() and sd_normal_command() can tell sd_do_command()
that the command was illegal. This is needed so we can do things
like reset certain status bits only on receipt of a valid command.
For the moment, just use it to pull out the setting of the
ILLEGAL_COMMAND status bit into sd_do_command().
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andrzej Zaborowski <andrew.zaborowski@intel.com>
Diffstat (limited to 'hw/sd.c')
-rw-r--r-- | hw/sd.c | 25 |
1 files changed, 11 insertions, 14 deletions
@@ -51,6 +51,7 @@ typedef enum { sd_r6 = 6, /* Published RCA response */ sd_r7, /* Operating voltage */ sd_r1b = -1, + sd_illegal = -2, } sd_rsp_type_t; struct SDState { @@ -679,8 +680,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, break; case 5: /* CMD5: reserved for SDIO cards */ - sd->card_status |= ILLEGAL_COMMAND; - return sd_r0; + return sd_illegal; case 6: /* CMD6: SWITCH_FUNCTION */ if (sd->spi) @@ -1115,8 +1115,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, * on stderr, as some OSes may use these in their * probing for presence of an SDIO card. */ - sd->card_status |= ILLEGAL_COMMAND; - return sd_r0; + return sd_illegal; /* Application specific commands (Class 8) */ case 55: /* CMD55: APP_CMD */ @@ -1145,21 +1144,17 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, default: bad_cmd: - sd->card_status |= ILLEGAL_COMMAND; - fprintf(stderr, "SD: Unknown CMD%i\n", req.cmd); - return sd_r0; + return sd_illegal; unimplemented_cmd: /* Commands that are recognised but not yet implemented in SPI mode. */ - sd->card_status |= ILLEGAL_COMMAND; fprintf(stderr, "SD: CMD%i not implemented in SPI mode\n", req.cmd); - return sd_r0; + return sd_illegal; } - sd->card_status |= ILLEGAL_COMMAND; fprintf(stderr, "SD: CMD%i in a wrong state\n", req.cmd); - return sd_r0; + return sd_illegal; } static sd_rsp_type_t sd_app_command(SDState *sd, @@ -1321,6 +1316,10 @@ int sd_do_command(SDState *sd, SDRequest *req, } else rtype = sd_normal_command(sd, *req); + if (rtype == sd_illegal) { + sd->card_status |= ILLEGAL_COMMAND; + } + sd->current_cmd = req->cmd; switch (rtype) { @@ -1356,14 +1355,12 @@ int sd_do_command(SDState *sd, SDRequest *req, break; case sd_r0: + case sd_illegal: default: rsplen = 0; break; } - if (sd->card_status & ILLEGAL_COMMAND) - rsplen = 0; - #ifdef DEBUG_SD if (rsplen) { int i; |