sdmmc: add sd vendor/rsvd info

This commit is contained in:
CTCaer
2026-06-16 22:57:49 +03:00
parent a7f0d6768c
commit 739805357f
2 changed files with 86 additions and 8 deletions

View File

@@ -968,6 +968,50 @@ void _sd_storage_debug_print_ssr(const u8 *raw_ssr)
}
#endif
void sd_storage_get_vendor_info(sdmmc_storage_t *storage, sd_vendor_info_t *info)
{
// CID Reserved.
info->cid_rsvd = storage->cid.rsvd;
// CSD Reserved.
info->csd_rsvd8_9 = unstuff_bits((u32 *)storage->raw_csd, 8, 2);
info->csd_rsvd16_20 = unstuff_bits((u32 *)storage->raw_csd, 16, 5);
info->csd_rsvd29_30 = unstuff_bits((u32 *)storage->raw_csd, 29, 2);
info->csd_rsvd120_125 = unstuff_bits((u32 *)storage->raw_csd, 120, 6);
// SCR Vendor and Reserved.
u32 scr[4];
memcpy(&scr[2], storage->raw_scr, 8);
info->scr_vendor = storage->scr.vendor;
info->scr_rsvd = unstuff_bits(scr, 36, 2);
// SSR Vendor and Reserved.
u32 raw_ssr0[4]; // 511:384.
u32 raw_ssr1[4]; // 383:256.
u32 raw_ssr2[4]; // 255:128.
u32 raw_ssr3[4]; // 127:0.
memcpy(raw_ssr0, &storage->raw_ssr[0], 16);
memcpy(raw_ssr1, &storage->raw_ssr[16], 16);
memcpy(raw_ssr2, &storage->raw_ssr[32], 16);
memcpy(raw_ssr3, &storage->raw_ssr[48], 16);
info->ssr_vendor0_31 = unstuff_bits(raw_ssr3, 0, 32);
info->ssr_vendor32_63 = unstuff_bits(raw_ssr3, 32, 32);
info->ssr_vendor64_95 = unstuff_bits(raw_ssr3, 64, 32);
info->ssr_vendor96_127 = unstuff_bits(raw_ssr3, 96, 32);
info->ssr_vendor128_159 = unstuff_bits(raw_ssr2, 128, 32);
info->ssr_vendor160_191 = unstuff_bits(raw_ssr2, 160, 32);
info->ssr_vendor192_223 = unstuff_bits(raw_ssr2, 192, 32);
info->ssr_vendor224_255 = unstuff_bits(raw_ssr2, 224, 32);
info->ssr_vendor256_287 = unstuff_bits(raw_ssr1, 256, 32);
info->ssr_vendor288_311 = unstuff_bits(raw_ssr1, 288, 24);
info->ssr_rsvd314_327 = unstuff_bits(raw_ssr1, 314, 14);
info->ssr_rsvd340_345 = unstuff_bits(raw_ssr1, 340, 6);
info->ssr_rsvd378_383 = unstuff_bits(raw_ssr1, 378, 6);
info->ssr_rsvd424_427 = unstuff_bits(raw_ssr0, 424, 4);
info->ssr_rsvd496_501 = unstuff_bits(raw_ssr0, 496, 6);
}
int sd_storage_get_ext_reg(sdmmc_storage_t *storage, u8 fno, u8 page, u16 address, u32 len, void *buf)
{
if (!(storage->scr.cmds & BIT(2)))

View File

@@ -190,6 +190,46 @@ typedef struct _sd_ext_reg_t
int valid;
} sd_ext_reg_t;
typedef struct _sd_func_modes_t
{
u16 access_mode;
u16 cmd_system;
u16 driver_strength;
u16 power_limit;
} sd_func_modes_t;
typedef struct _sd_vendor_info_t
{
// CID Reserved.
u8 cid_rsvd; // 4-bit.
// CSD Reserved.
u8 csd_rsvd8_9; // 2-bit.
u8 csd_rsvd16_20; // 5-bit.
u8 csd_rsvd29_30; // 2-bit.
u8 csd_rsvd120_125; // 6-bit.
u32 scr_vendor;
u8 scr_rsvd; // 2-bit.
u32 ssr_vendor0_31;
u32 ssr_vendor32_63;
u32 ssr_vendor64_95;
u32 ssr_vendor96_127;
u32 ssr_vendor128_159;
u32 ssr_vendor160_191;
u32 ssr_vendor192_223;
u32 ssr_vendor224_255;
u32 ssr_vendor256_287;
u32 ssr_vendor288_311; // 24-bit.
u16 ssr_rsvd314_327; // 14-bit.
u8 ssr_rsvd340_345; // 6-bit.
u8 ssr_rsvd378_383; // 6-bit.
u8 ssr_rsvd424_427; // 4-bit.
u8 ssr_rsvd496_501; // 6-bit.
} sd_vendor_info_t;
/*! SDMMC storage context. */
typedef struct _sdmmc_storage_t
{
@@ -216,14 +256,6 @@ typedef struct _sdmmc_storage_t
sd_ext_reg_t ser;
} sdmmc_storage_t;
typedef struct _sd_func_modes_t
{
u16 access_mode;
u16 cmd_system;
u16 driver_strength;
u16 power_limit;
} sd_func_modes_t;
int sdmmc_storage_end(sdmmc_storage_t *storage);
int sdmmc_storage_read(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf);
int sdmmc_storage_write(sdmmc_storage_t *storage, u32 sector, u32 num_sectors, void *buf);
@@ -249,4 +281,6 @@ void sd_storage_get_ext_regs(sdmmc_storage_t *storage, u8 *buf);
int sd_storage_parse_perf_enhance(sdmmc_storage_t *storage, u8 fno, u8 page, u16 offset, u8 *buf);
bool sd_storage_get_ddr200_support(sdmmc_storage_t *storage);
void sd_storage_get_vendor_info(sdmmc_storage_t *storage, sd_vendor_info_t *info);
#endif