[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 20/23] hw/sd/sdcard: Add comments around registers and commands
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 20/23] hw/sd/sdcard: Add comments around registers and commands |
Date: |
Fri, 21 Jun 2024 10:05:51 +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>
---
hw/sd/sd.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index ca2c903c5b..95e23abd30 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -317,6 +317,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)
@@ -366,6 +368,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 */
@@ -388,6 +392,8 @@ static void sd_set_scr(SDState *sd)
sd->scr[7] = 0x00;
}
+/* Card IDentification register */
+
#define MID 0xaa
#define OID "XY"
#define PNM "QEMU!"
@@ -413,6 +419,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 */
@@ -482,6 +490,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 uint16_t sd_req_get_rca(SDState *s, SDRequest req)
{
if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc) {
@@ -490,6 +500,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)
@@ -620,6 +632,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);
@@ -1052,6 +1066,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) {
@@ -1062,6 +1077,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;
@@ -1069,6 +1085,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) {
@@ -1080,6 +1097,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) {
@@ -1094,6 +1112,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) {
@@ -1110,6 +1129,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
- [PATCH 15/23] hw/sd/sdcard: Only call sd_req_get_rca() where RCA is used, (continued)
- [PATCH 15/23] hw/sd/sdcard: Only call sd_req_get_rca() where RCA is used, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 16/23] hw/sd/sdcard: Factor sd_req_get_address() method out, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 17/23] hw/sd/sdcard: Only call sd_req_get_address() where address is used, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 18/23] hw/sd/sdcard: Add sd_invalid_mode_for_cmd to report invalid mode switch, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 19/23] hw/sd/sdcard: Inline BLK_READ_BLOCK / BLK_WRITE_BLOCK macros, Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 20/23] hw/sd/sdcard: Add comments around registers and commands,
Philippe Mathieu-Daudé <=
- [PATCH 21/23] hw/sd/sdcard: Do not store vendor data on block drive (CMD56), Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 22/23] hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30), Philippe Mathieu-Daudé, 2024/06/21
- [PATCH 23/23] hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22), Philippe Mathieu-Daudé, 2024/06/21
- Re: [PATCH 00/23] hw/sd/sdcard: Accumulation of cleanups and fixes, Cédric Le Goater, 2024/06/24
- Re: [PATCH 00/23] hw/sd/sdcard: Accumulation of cleanups and fixes, Philippe Mathieu-Daudé, 2024/06/24