From: Shawn Lin <shawn.lin@linux.dev>
To: Ulf Hansson <ulfh@kernel.org>
Cc: linux-mmc@vger.kernel.org,
Adrian Hunter <adrian.hunter@intel.com>,
linux-kernel@vger.kernel.org, Shawn Lin <shawn.lin@linux.dev>
Subject: [PATCH] mmc: core: Fix max_dtr passed to SD drive strength selection
Date: Tue, 6 Oct 2026 21:18:46 +0800 [thread overview]
Message-ID: <1791292726-31978-1-git-send-email-shawn.lin@linux.dev> (raw)
sd_select_driver_type() passes card->sw_caps.uhs_max_dtr to
mmc_select_drive_strength(), but that field is only assigned later by
sd_set_bus_speed_mode(). A card initialized for the first time thus
gets max_dtr=0, while a re-initialized card (system resume or
hw reset recovery reuse the card struct) gets the stale value from the
previous initialization.
No in-tree driver implementing ->select_drive_strength() (AMD and Intel
SDHCI) actually looks at max_dtr, so there is no functional impact
today. Still, compute the frequency from the bus speed mode that
sd_update_bus_speed_mode() has already selected, so the core doesn't
hand out a bogus value, and use the same helper in sd_set_bus_speed_mode()
to keep a single mapping.
Signed-off-by: Shawn Lin <shawn.lin@linux.dev>
---
drivers/mmc/core/sd.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index c763efb..5ba4e2d 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -417,6 +417,22 @@ int mmc_sd_switch_hs(struct mmc_card *card)
return err;
}
+static unsigned int sd_get_bus_speed_dtr(struct mmc_card *card)
+{
+ switch (card->sd_bus_speed) {
+ case UHS_SDR104_BUS_SPEED:
+ return UHS_SDR104_MAX_DTR;
+ case UHS_DDR50_BUS_SPEED:
+ return UHS_DDR50_MAX_DTR;
+ case UHS_SDR50_BUS_SPEED:
+ return UHS_SDR50_MAX_DTR;
+ case UHS_SDR25_BUS_SPEED:
+ return UHS_SDR25_MAX_DTR;
+ default:
+ return UHS_SDR12_MAX_DTR;
+ }
+}
+
static int sd_select_driver_type(struct mmc_card *card, u8 *status)
{
int card_drv_type, drive_strength, drv_type;
@@ -427,7 +443,7 @@ static int sd_select_driver_type(struct mmc_card *card, u8 *status)
card_drv_type = card->sw_caps.sd3_drv_type | SD_DRIVER_TYPE_B;
drive_strength = mmc_select_drive_strength(card,
- card->sw_caps.uhs_max_dtr,
+ sd_get_bus_speed_dtr(card),
card_drv_type, &drv_type);
if (drive_strength) {
@@ -490,28 +506,25 @@ static int sd_set_bus_speed_mode(struct mmc_card *card, u8 *status)
switch (card->sd_bus_speed) {
case UHS_SDR104_BUS_SPEED:
timing = MMC_TIMING_UHS_SDR104;
- card->sw_caps.uhs_max_dtr = UHS_SDR104_MAX_DTR;
break;
case UHS_DDR50_BUS_SPEED:
timing = MMC_TIMING_UHS_DDR50;
- card->sw_caps.uhs_max_dtr = UHS_DDR50_MAX_DTR;
break;
case UHS_SDR50_BUS_SPEED:
timing = MMC_TIMING_UHS_SDR50;
- card->sw_caps.uhs_max_dtr = UHS_SDR50_MAX_DTR;
break;
case UHS_SDR25_BUS_SPEED:
timing = MMC_TIMING_UHS_SDR25;
- card->sw_caps.uhs_max_dtr = UHS_SDR25_MAX_DTR;
break;
case UHS_SDR12_BUS_SPEED:
timing = MMC_TIMING_UHS_SDR12;
- card->sw_caps.uhs_max_dtr = UHS_SDR12_MAX_DTR;
break;
default:
return 0;
}
+ card->sw_caps.uhs_max_dtr = sd_get_bus_speed_dtr(card);
+
err = mmc_sd_switch(card, SD_SWITCH_SET, 0, card->sd_bus_speed, status);
if (err)
return err;
--
2.7.4
reply other threads:[~2026-10-06 13:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1791292726-31978-1-git-send-email-shawn.lin@linux.dev \
--to=shawn.lin@linux.dev \
--cc=adrian.hunter@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=ulfh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®