From 0eb287bc184e61a834d859556570b5adc976a9f7 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Tue, 9 Jun 2026 07:00:26 +0300 Subject: [PATCH] sdmmc: add get sda spec version function Returned number is major version. --- bdk/storage/sdmmc.c | 44 +++++++++++++++++++++++++++++++++++++++++--- bdk/storage/sdmmc.h | 3 ++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/bdk/storage/sdmmc.c b/bdk/storage/sdmmc.c index b3522320..c51e734e 100644 --- a/bdk/storage/sdmmc.c +++ b/bdk/storage/sdmmc.c @@ -1113,10 +1113,45 @@ static int _sd_storage_get_rca(sdmmc_storage_t *storage) return 1; } +u8 sd_storage_get_scr_sda_ver(sdmmc_storage_t *storage) +{ + u8 version = 0; + + u8 sda_spec = storage->scr.sda_vsn; + u8 sda_spec3 = storage->scr.sda_spec & 1; + u8 sda_spec4 = (storage->scr.sda_spec >> 1) & 1; + u8 sda_specx = storage->scr.sda_spec >> 4; + + switch (sda_spec) + { + case 0: + version = 1; + break; + + case 1: + version = 1; + break; + + case 2: + if (!sda_spec3) + version = 2; + else if (!sda_spec4 && !sda_specx) + version = 3; + else + version = sda_specx + 4; + break; + } + + return version; +} + static void _sd_storage_parse_scr(sdmmc_storage_t *storage) { // unstuff_bits can parse only 4 u32 u32 scr[4]; + u8 sda_spec3 = 0; + u8 sda_spec4 = 0; + u8 sda_specx = 0; memcpy(&scr[2], storage->raw_scr, 8); @@ -1129,15 +1164,18 @@ static void _sd_storage_parse_scr(sdmmc_storage_t *storage) // If v2.0 is supported, check if Physical Layer Spec v3.0 is supported. if (storage->scr.sda_vsn == SCR_SPEC_VER_2) - storage->scr.sda_spec3 = unstuff_bits(scr, 47, 1); - if (storage->scr.sda_spec3) + sda_spec3 = unstuff_bits(scr, 47, 1); + if (sda_spec3) { - u8 sda_spec4 = unstuff_bits(scr, 42, 1); + sda_spec4 = unstuff_bits(scr, 42, 1); + sda_specx = unstuff_bits(scr, 38, 4); if (sda_spec4) storage->scr.cmds = unstuff_bits(scr, 32, 4); else storage->scr.cmds = unstuff_bits(scr, 32, 2); } + + storage->scr.sda_spec = sda_spec3 | (sda_spec4 << 1) | (sda_specx << 4); } int sd_storage_get_scr(sdmmc_storage_t *storage) diff --git a/bdk/storage/sdmmc.h b/bdk/storage/sdmmc.h index cb8c6d76..b9dab182 100644 --- a/bdk/storage/sdmmc.h +++ b/bdk/storage/sdmmc.h @@ -161,7 +161,7 @@ typedef struct _mmc_ext_csd typedef struct _sd_scr { u8 sda_vsn; - u8 sda_spec3; + u8 sda_spec; u8 bus_widths; u8 cmds; } sd_scr_t; @@ -238,6 +238,7 @@ int mmc_storage_get_ext_csd(sdmmc_storage_t *storage); int sd_storage_get_ext_reg(sdmmc_storage_t *storage, u8 fno, u8 page, u16 offset, u32 len, void *buf); int sd_storage_get_fmodes(sdmmc_storage_t *storage, u8 *buf, sd_func_modes_t *functions); int sd_storage_get_scr(sdmmc_storage_t *storage); +u8 sd_storage_get_scr_sda_ver(sdmmc_storage_t *storage); int sd_storage_get_ssr(sdmmc_storage_t *storage); u32 sd_storage_get_ssr_au(sdmmc_storage_t *storage);