Skip to content

Commit 36754ea

Browse files
tchebbgregkh
authored andcommitted
mmc: rtsx_pci: Fix long reads when clock is prescaled
[ Upstream commit 3ac5e45 ] For unexplained reasons, the prescaler register for this device needs to be cleared (set to 1) while performing a data read or else the command will hang. This does not appear to affect the real clock rate sent out on the bus, so I assume it's purely to work around a hardware bug. During normal operation, the prescaler is already set to 1, so nothing needs to be done. However, in "initial mode" (which is used for sub-MHz clock speeds, like the core sets while enumerating cards), it's set to 128 and so we need to reset it during data reads. We currently fail to do this for long reads. This has no functional affect on the driver's operation currently written, as the MMC core always sets a clock above 1MHz before attempting any long reads. However, the core could conceivably set any clock speed at any time and the driver should still work, so I think this fix is worthwhile. I personally encountered this issue while performing data recovery on an external chip. My connections had poor signal integrity, so I modified the core code to reduce the clock speed. Without this change, I saw the card enumerate but was unable to actually read any data. Writes don't seem to work in the situation described above even with this change (and even if the workaround is extended to encompass data write commands). I was not able to find a way to get them working. Signed-off-by: Thomas Hebb <tommyhebb@gmail.com> Link: https://lore.kernel.org/r/2fef280d8409ab0100c26c6ac7050227defd098d.1627818365.git.tommyhebb@gmail.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 2ca265e commit 36754ea

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

‎drivers/mmc/host/rtsx_pci_sdmmc.c‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -542,9 +542,22 @@ static int sd_write_long_data(struct realtek_pci_sdmmc *host,
542542
return 0;
543543
}
544544

545+
static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host)
546+
{
547+
rtsx_pci_write_register(host->pcr, SD_CFG1,
548+
SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128);
549+
}
550+
551+
static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host)
552+
{
553+
rtsx_pci_write_register(host->pcr, SD_CFG1,
554+
SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0);
555+
}
556+
545557
static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
546558
{
547559
struct mmc_data *data = mrq->data;
560+
int err;
548561

549562
if (host->sg_count < 0) {
550563
data->error = host->sg_count;
@@ -553,22 +566,19 @@ static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq)
553566
return data->error;
554567
}
555568

556-
if (data->flags & MMC_DATA_READ)
557-
return sd_read_long_data(host, mrq);
569+
if (data->flags & MMC_DATA_READ) {
570+
if (host->initial_mode)
571+
sd_disable_initial_mode(host);
558572

559-
return sd_write_long_data(host, mrq);
560-
}
573+
err = sd_read_long_data(host, mrq);
561574

562-
static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host)
563-
{
564-
rtsx_pci_write_register(host->pcr, SD_CFG1,
565-
SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128);
566-
}
575+
if (host->initial_mode)
576+
sd_enable_initial_mode(host);
567577

568-
static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host)
569-
{
570-
rtsx_pci_write_register(host->pcr, SD_CFG1,
571-
SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0);
578+
return err;
579+
}
580+
581+
return sd_write_long_data(host, mrq);
572582
}
573583

574584
static void sd_normal_rw(struct realtek_pci_sdmmc *host,

0 commit comments

Comments
 (0)