[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/19] hw/sd/sdcard: Add comments around registers and commands
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 19/19] hw/sd/sdcard: Add comments around registers and commands |
Date: |
Mon, 24 Jun 2024 15:14:40 +0200 |
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Tested-by: Cédric Le Goater <clg@redhat.com>
Message-Id: <20240621080554.18986-21-philmd@linaro.org>
---
hw/sd/sd.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index d4e3d079a8..a48010cfc1 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -315,6 +315,8 @@ static uint8_t sd_crc7(const void *message, size_t width)
return shift_reg;
}
+/* Operation Conditions register */
+
#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */
FIELD(OCR, VDD_VOLTAGE_WINDOW, 0, 24)
@@ -364,6 +366,8 @@ static void sd_set_ocr(SDState *sd)
}
}
+/* SD Configuration register */
+
static void sd_set_scr(SDState *sd)
{
sd->scr[0] = 0 << 4; /* SCR structure version 1.0 */
@@ -386,6 +390,8 @@ static void sd_set_scr(SDState *sd)
sd->scr[7] = 0x00;
}
+/* Card IDentification register */
+
#define MID 0xaa
#define OID "XY"
#define PNM "QEMU!"
@@ -411,6 +417,8 @@ static void sd_set_cid(SDState *sd)
sd->cid[15] = (sd_crc7(sd->cid, 15) << 1) | 1;
}
+/* Card-Specific Data register */
+
#define HWBLOCK_SHIFT 9 /* 512 bytes */
#define SECTOR_SHIFT 5 /* 16 kilobytes */
#define WPGROUP_SHIFT 7 /* 2 megs */
@@ -480,6 +488,8 @@ static void sd_set_csd(SDState *sd, uint64_t size)
sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1;
}
+/* Relative Card Address register */
+
static void sd_set_rca(SDState *sd)
{
sd->rca += 0x4567;
@@ -493,6 +503,8 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest req)
return 0;
}
+/* Card Status register */
+
FIELD(CSR, AKE_SEQ_ERROR, 3, 1)
FIELD(CSR, APP_CMD, 5, 1)
FIELD(CSR, FX_EVENT, 6, 1)
@@ -623,6 +635,8 @@ static void sd_reset(DeviceState *dev)
sect = sd_addr_to_wpnum(size) + 1;
sd->state = sd_idle_state;
+
+ /* card registers */
sd->rca = 0x0000;
sd->size = size;
sd_set_ocr(sd);
@@ -1055,6 +1069,7 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd,
SDRequest req)
return sd_illegal;
}
+/* CMD0 */
static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req)
{
if (sd->state != sd_inactive_state) {
@@ -1065,6 +1080,7 @@ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd,
SDRequest req)
return sd_is_spi(sd) ? sd_r1 : sd_r0;
}
+/* CMD1 */
static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd, SDRequest req)
{
sd->state = sd_transfer_state;
@@ -1072,6 +1088,7 @@ static sd_rsp_type_t spi_cmd_SEND_OP_COND(SDState *sd,
SDRequest req)
return sd_r1;
}
+/* CMD2 */
static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req)
{
switch (sd->state) {
@@ -1083,6 +1100,7 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd,
SDRequest req)
}
}
+/* CMD3 */
static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req)
{
switch (sd->state) {
@@ -1097,6 +1115,7 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState
*sd, SDRequest req)
}
}
+/* CMD19 */
static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req)
{
if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
@@ -1113,6 +1132,7 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState
*sd, SDRequest req)
return sd_r1;
}
+/* CMD23 */
static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req)
{
if (sd->spec_version < SD_PHY_SPECv3_01_VERS) {
--
2.41.0
- [PULL 09/19] hw/sd/sdcard: Remove ACMD6 handler for SPI mode, (continued)
- [PULL 09/19] hw/sd/sdcard: Remove ACMD6 handler for SPI mode, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 10/19] hw/sd/sdcard: Remove explicit entries for illegal commands, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 11/19] hw/sd/sdcard: Trace update of block count (CMD23), Philippe Mathieu-Daudé, 2024/06/24
- [PULL 12/19] hw/sd/sdcard: Have cmd_valid_while_locked() return a boolean value, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 13/19] hw/sd/sdcard: Factor sd_req_get_rca() method out, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 14/19] hw/sd/sdcard: Only call sd_req_get_rca() where RCA is used, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 15/19] hw/sd/sdcard: Factor sd_req_get_address() method out, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 16/19] hw/sd/sdcard: Only call sd_req_get_address() where address is used, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 17/19] hw/sd/sdcard: Add sd_invalid_mode_for_cmd to report invalid mode switch, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 18/19] hw/sd/sdcard: Inline BLK_READ_BLOCK / BLK_WRITE_BLOCK macros, Philippe Mathieu-Daudé, 2024/06/24
- [PULL 19/19] hw/sd/sdcard: Add comments around registers and commands,
Philippe Mathieu-Daudé <=
- Re: [PULL 00/19] SD/MMC patches for 2024-06-24, Richard Henderson, 2024/06/25