[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 07/11] hw/sd/sdcard: Implement eMMC sleep state (CMD5)
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 07/11] hw/sd/sdcard: Implement eMMC sleep state (CMD5) |
Date: |
Tue, 16 Jul 2024 20:41:40 +0200 |
From: Luc Michel <luc.michel@amd.com>
The JEDEC standards specifies a sleep state where the eMMC won't
answer any command appart from RESET and WAKEUP and go to low power
state. Implement this state and the corresponding command number 5.
Signed-off-by: Luc Michel <luc.michel@amd.com>
Signed-off-by: Francisco Iglesias <francisco.iglesias@amd.com>
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: <20240712162719.88165-8-philmd@linaro.org>
---
hw/sd/sd.c | 47 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 45 insertions(+), 2 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index a90612af58..d98952a12f 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1236,8 +1236,19 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd,
SDRequest req,
/* CMD0 */
static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req)
{
- sd->state = sd_idle_state;
- sd_reset(DEVICE(sd));
+ if (sd->state == sd_sleep_state) {
+ switch (req.arg) {
+ case 0x00000000:
+ case 0xf0f0f0f0:
+ break;
+ default:
+ return sd_r0;
+ }
+ }
+ if (sd->state != sd_inactive_state) {
+ sd->state = sd_idle_state;
+ sd_reset(DEVICE(sd));
+ }
return sd_is_spi(sd) ? sd_r1 : sd_r0;
}
@@ -1294,6 +1305,30 @@ static sd_rsp_type_t emmc_cmd_SET_RELATIVE_ADDR(SDState
*sd, SDRequest req)
}
}
+/* CMD5 */
+static sd_rsp_type_t emmc_cmd_sleep_awake(SDState *sd, SDRequest req)
+{
+ bool do_sleep = extract32(req.arg, 15, 1);
+
+ switch (sd->state) {
+ case sd_sleep_state:
+ if (!do_sleep) {
+ /* Awake */
+ sd->state = sd_standby_state;
+ }
+ return sd_r1b;
+
+ case sd_standby_state:
+ if (do_sleep) {
+ sd->state = sd_sleep_state;
+ }
+ return sd_r1b;
+
+ default:
+ return sd_invalid_state_for_cmd(sd, req);
+ }
+}
+
/* CMD6 */
static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req)
{
@@ -1696,6 +1731,7 @@ static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd,
SDRequest req)
case sd_ready_state:
case sd_identification_state:
case sd_inactive_state:
+ case sd_sleep_state:
return sd_invalid_state_for_cmd(sd, req);
case sd_idle_state:
if (!sd_is_spi(sd) && sd_req_get_rca(sd, req) != 0x0000) {
@@ -2018,6 +2054,12 @@ int sd_do_command(SDState *sd, SDRequest *req,
req->cmd &= 0x3f;
}
+ if (sd->state == sd_sleep_state && req->cmd) {
+ qemu_log_mask(LOG_GUEST_ERROR, "SD: Card is sleeping\n");
+ rtype = sd_r0;
+ goto send_response;
+ }
+
if (sd->card_status & CARD_IS_LOCKED) {
if (!cmd_valid_while_locked(sd, req->cmd)) {
sd->card_status |= ILLEGAL_COMMAND;
@@ -2467,6 +2509,7 @@ static const SDProto sd_proto_emmc = {
[2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID},
[3] = {0, sd_ac, "SET_RELATIVE_ADDR", emmc_cmd_SET_RELATIVE_ADDR},
[4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented},
+ [5] = {0, sd_ac, "SLEEP/AWAKE", emmc_cmd_sleep_awake},
[7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD},
[9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD},
[10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID},
--
2.41.0
- [PULL 00/11] SD/MMC patches for 2024-07-16, Philippe Mathieu-Daudé, 2024/07/16
- [PULL 01/11] hw/sd/sdcard: Basis for eMMC support, Philippe Mathieu-Daudé, 2024/07/16
- [PULL 02/11] hw/sd/sdcard: Register generic command handlers, Philippe Mathieu-Daudé, 2024/07/16
- [PULL 03/11] hw/sd/sdcard: Register unimplemented command handlers, Philippe Mathieu-Daudé, 2024/07/16
- [PULL 04/11] hw/sd/sdcard: Add emmc_cmd_SET_RELATIVE_ADDR handler (CMD3), Philippe Mathieu-Daudé, 2024/07/16
- [PULL 06/11] hw/sd/sdcard: Add emmc_cmd_PROGRAM_CID handler (CMD26), Philippe Mathieu-Daudé, 2024/07/16
- [PULL 05/11] hw/sd/sdcard: Fix SET_BLOCK_COUNT command argument on eMMC (CMD23), Philippe Mathieu-Daudé, 2024/07/16
- [PULL 07/11] hw/sd/sdcard: Implement eMMC sleep state (CMD5),
Philippe Mathieu-Daudé <=
- [PULL 08/11] hw/sd/sdcard: Add emmc_cmd_SEND_EXT_CSD handler (CMD8), Philippe Mathieu-Daudé, 2024/07/16
- [PULL 10/11] hw/sd/sdcard: Add mmc SWITCH function support (CMD6), Philippe Mathieu-Daudé, 2024/07/16
- [PULL 11/11] hw/sd/sdcard: Support boot area in emmc image, Philippe Mathieu-Daudé, 2024/07/16
- [PULL 09/11] hw/sd/sdcard: Add eMMC 'boot-partition-size' property, Philippe Mathieu-Daudé, 2024/07/16
- Re: [PULL 00/11] SD/MMC patches for 2024-07-16, Richard Henderson, 2024/07/17