SD/MMC patches queue
- Add SDHC support for SD card SPI-mode (Frank Chang) -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE+qvnXhKRciHc/Wuy4+MsLN6twN4FAmHaCHIACgkQ4+MsLN6t wN4sdhAAtGumw7ji0DOsVA7xP0jXi471NUaE5Y21OSsWWozbEqGpsF2cAkxSbY17 CY0cMpQUl/NqbMz0h+GwE1E3EXAChTnQSsEkTmHrWrZOZceIK20ODgiIKFpj6tls jIN0mG4YXdo7/ODLO8F7G18zkvcwTTb0+sRA4EUQfAzNcyjWIKBR/0U0xY+cVfy6 Y+UTk6+Vf01seS4BRVqE2mec4YMjRb/fKwnXdBgMVNf3OlRqfO0wBu6l/03rf0Mo GYwxSiDnmVZufLtSTRNL9wW4eQoDBhWrnzh7wTH6kSjNE/ylWLeZPg8uKkNC715h H4/k1srMHRpo8PcKOaGJ1VLR3iqAVY80MdBtFKtaFaDJQFkLT2aBUI1xREA9s4uo r6xUyfeMCb/d3l0n+gFX9+hv3LlzsfubvLT2FeIFp0K2YioG7upH0PV8eiG7okKf AiEvidr8gU1RFk/JUWQDUsqbInpo92INk88jDsrpsgXS74RoYe5T4tR6pIjDXe8s dKF3RdQzC0TcgW1uqobduMtrumwEhiY4WKeQvhaKQF1v1JcTQRLqrds3qHhPCayN NiyFfue43mtZllUZw0NnezbNsiY+Fgepg4DSqvPHzszdsMHmmY7bs0mx79JoJglN mH1xurwjo3Mvv9oeBwP1OcRM7IS4Oz/ALhi0ZNbP+MYwDGwujXU= =PEEr -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/philmd/tags/sdmmc-20220108' into staging SD/MMC patches queue - Add SDHC support for SD card SPI-mode (Frank Chang) # gpg: Signature made Sat 08 Jan 2022 21:56:02 GMT # gpg: using RSA key FAABE75E12917221DCFD6BB2E3E32C2CDEADC0DE # gpg: Good signature from "Philippe Mathieu-Daudé (F4BUG) <f4bug@amsat.org>" [unknown] # gpg: WARNING: This key is not certified with a trusted signature! # gpg: There is no indication that the signature belongs to the owner. # Primary key fingerprint: FAAB E75E 1291 7221 DCFD 6BB2 E3E3 2C2C DEAD C0DE * remotes/philmd/tags/sdmmc-20220108: hw/sd: Add SDHC support for SD card SPI-mode hw/sd/sdcard: Rename Write Protect Group variables Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
64c01c7da4
52
hw/sd/sd.c
52
hw/sd/sd.c
@ -116,8 +116,8 @@ struct SDState {
|
||||
int32_t state; /* current card state, one of SDCardStates */
|
||||
uint32_t vhs;
|
||||
bool wp_switch;
|
||||
unsigned long *wp_groups;
|
||||
int32_t wpgrps_size;
|
||||
unsigned long *wp_group_bmap;
|
||||
int32_t wp_group_bits;
|
||||
uint64_t size;
|
||||
uint32_t blk_len;
|
||||
uint32_t multi_blk_cnt;
|
||||
@ -290,12 +290,6 @@ FIELD(OCR, CARD_POWER_UP, 31, 1)
|
||||
| R_OCR_CARD_CAPACITY_MASK \
|
||||
| R_OCR_CARD_POWER_UP_MASK)
|
||||
|
||||
static void sd_set_ocr(SDState *sd)
|
||||
{
|
||||
/* All voltages OK */
|
||||
sd->ocr = R_OCR_VDD_VOLTAGE_WIN_HI_MASK;
|
||||
}
|
||||
|
||||
static void sd_ocr_powerup(void *opaque)
|
||||
{
|
||||
SDState *sd = opaque;
|
||||
@ -311,6 +305,22 @@ static void sd_ocr_powerup(void *opaque)
|
||||
}
|
||||
}
|
||||
|
||||
static void sd_set_ocr(SDState *sd)
|
||||
{
|
||||
/* All voltages OK */
|
||||
sd->ocr = R_OCR_VDD_VOLTAGE_WIN_HI_MASK;
|
||||
|
||||
if (sd->spi) {
|
||||
/*
|
||||
* We don't need to emulate power up sequence in SPI-mode.
|
||||
* Thus, the card's power up status bit should be set to 1 when reset.
|
||||
* The card's capacity status bit should also be set if SD card size
|
||||
* is larger than 2GB for SDHC support.
|
||||
*/
|
||||
sd_ocr_powerup(sd);
|
||||
}
|
||||
}
|
||||
|
||||
static void sd_set_scr(SDState *sd)
|
||||
{
|
||||
sd->scr[0] = 0 << 4; /* SCR structure version 1.0 */
|
||||
@ -560,6 +570,7 @@ static void sd_reset(DeviceState *dev)
|
||||
|
||||
sd->state = sd_idle_state;
|
||||
sd->rca = 0x0000;
|
||||
sd->size = size;
|
||||
sd_set_ocr(sd);
|
||||
sd_set_scr(sd);
|
||||
sd_set_cid(sd);
|
||||
@ -567,14 +578,13 @@ static void sd_reset(DeviceState *dev)
|
||||
sd_set_cardstatus(sd);
|
||||
sd_set_sdstatus(sd);
|
||||
|
||||
g_free(sd->wp_groups);
|
||||
g_free(sd->wp_group_bmap);
|
||||
sd->wp_switch = sd->blk ? !blk_is_writable(sd->blk) : false;
|
||||
sd->wpgrps_size = sect;
|
||||
sd->wp_groups = bitmap_new(sd->wpgrps_size);
|
||||
sd->wp_group_bits = sect;
|
||||
sd->wp_group_bmap = bitmap_new(sd->wp_group_bits);
|
||||
memset(sd->function_group, 0, sizeof(sd->function_group));
|
||||
sd->erase_start = INVALID_ADDRESS;
|
||||
sd->erase_end = INVALID_ADDRESS;
|
||||
sd->size = size;
|
||||
sd->blk_len = 0x200;
|
||||
sd->pwd_len = 0;
|
||||
sd->expecting_acmd = false;
|
||||
@ -673,7 +683,7 @@ static const VMStateDescription sd_vmstate = {
|
||||
VMSTATE_UINT32(card_status, SDState),
|
||||
VMSTATE_PARTIAL_BUFFER(sd_status, SDState, 1),
|
||||
VMSTATE_UINT32(vhs, SDState),
|
||||
VMSTATE_BITMAP(wp_groups, SDState, 0, wpgrps_size),
|
||||
VMSTATE_BITMAP(wp_group_bmap, SDState, 0, wp_group_bits),
|
||||
VMSTATE_UINT32(blk_len, SDState),
|
||||
VMSTATE_UINT32(multi_blk_cnt, SDState),
|
||||
VMSTATE_UINT32(erase_start, SDState),
|
||||
@ -803,8 +813,8 @@ static void sd_erase(SDState *sd)
|
||||
if (sdsc) {
|
||||
/* Only SDSC cards support write protect groups */
|
||||
wpnum = sd_addr_to_wpnum(erase_addr);
|
||||
assert(wpnum < sd->wpgrps_size);
|
||||
if (test_bit(wpnum, sd->wp_groups)) {
|
||||
assert(wpnum < sd->wp_group_bits);
|
||||
if (test_bit(wpnum, sd->wp_group_bmap)) {
|
||||
sd->card_status |= WP_ERASE_SKIP;
|
||||
continue;
|
||||
}
|
||||
@ -828,8 +838,8 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr)
|
||||
*/
|
||||
continue;
|
||||
}
|
||||
assert(wpnum < sd->wpgrps_size);
|
||||
if (test_bit(wpnum, sd->wp_groups)) {
|
||||
assert(wpnum < sd->wp_group_bits);
|
||||
if (test_bit(wpnum, sd->wp_group_bmap)) {
|
||||
ret |= (1 << i);
|
||||
}
|
||||
}
|
||||
@ -869,7 +879,7 @@ static void sd_function_switch(SDState *sd, uint32_t arg)
|
||||
|
||||
static inline bool sd_wp_addr(SDState *sd, uint64_t addr)
|
||||
{
|
||||
return test_bit(sd_addr_to_wpnum(addr), sd->wp_groups);
|
||||
return test_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap);
|
||||
}
|
||||
|
||||
static void sd_lock_command(SDState *sd)
|
||||
@ -897,7 +907,7 @@ static void sd_lock_command(SDState *sd)
|
||||
sd->card_status |= LOCK_UNLOCK_FAILED;
|
||||
return;
|
||||
}
|
||||
bitmap_zero(sd->wp_groups, sd->wpgrps_size);
|
||||
bitmap_zero(sd->wp_group_bmap, sd->wp_group_bits);
|
||||
sd->csd[14] &= ~0x10;
|
||||
sd->card_status &= ~CARD_IS_LOCKED;
|
||||
sd->pwd_len = 0;
|
||||
@ -1348,7 +1358,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
|
||||
}
|
||||
|
||||
sd->state = sd_programming_state;
|
||||
set_bit(sd_addr_to_wpnum(addr), sd->wp_groups);
|
||||
set_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap);
|
||||
/* Bzzzzzzztt .... Operation complete. */
|
||||
sd->state = sd_transfer_state;
|
||||
return sd_r1b;
|
||||
@ -1370,7 +1380,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
|
||||
}
|
||||
|
||||
sd->state = sd_programming_state;
|
||||
clear_bit(sd_addr_to_wpnum(addr), sd->wp_groups);
|
||||
clear_bit(sd_addr_to_wpnum(addr), sd->wp_group_bmap);
|
||||
/* Bzzzzzzztt .... Operation complete. */
|
||||
sd->state = sd_transfer_state;
|
||||
return sd_r1b;
|
||||
|
Loading…
Reference in New Issue
Block a user