Skip to content

Commit 27bdc37

Browse files
Yann-lmsUlf Hansson
authored andcommitted
mmc: mmci: stm32: manage block gap hardware flow control
In stm32 sdmmc variant revision v3.0, a block gap hardware flow control should be used with bus speed modes SDR104 and HS200. It is enabled by writing a non-null value to the new added register MMCI_STM32_FIFOTHRR. The threshold will be 2^(N-1) bytes, so we can use the ffs() function to compute the value N to be written to the register. The threshold used should be the data block size, but must not be bigger than the FIFO size. Signed-off-by: Yann Gautier <yann.gautier@foss.st.com> Link: https://lore.kernel.org/r/20230619115120.64474-5-yann.gautier@foss.st.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
1 parent ea9ca04 commit 27bdc37

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

drivers/mmc/host/mmci.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@
218218
#define MCI_STM32_BUSYD0ENDMASK BIT(21)
219219

220220
#define MMCIMASK1 0x040
221+
222+
/* STM32 sdmmc data FIFO threshold register */
223+
#define MMCI_STM32_FIFOTHRR 0x044
224+
#define MMCI_STM32_THR_MASK GENMASK(3, 0)
225+
221226
#define MMCIFIFOCNT 0x048
222227
#define MMCIFIFO 0x080 /* to 0x0bc */
223228

drivers/mmc/host/mmci_stm32_sdmmc.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,19 @@ static u32 sdmmc_get_dctrl_cfg(struct mmci_host *host)
361361

362362
datactrl = mmci_dctrl_blksz(host);
363363

364+
if (host->hw_revision >= 3) {
365+
u32 thr = 0;
366+
367+
if (host->mmc->ios.timing == MMC_TIMING_UHS_SDR104 ||
368+
host->mmc->ios.timing == MMC_TIMING_MMC_HS200) {
369+
thr = ffs(min_t(unsigned int, host->data->blksz,
370+
host->variant->fifosize));
371+
thr = min_t(u32, thr, MMCI_STM32_THR_MASK);
372+
}
373+
374+
writel_relaxed(thr, host->base + MMCI_STM32_FIFOTHRR);
375+
}
376+
364377
if (host->mmc->card && mmc_card_sdio(host->mmc->card) &&
365378
host->data->blocks == 1)
366379
datactrl |= MCI_DPSM_STM32_MODE_SDIO;

0 commit comments

Comments
 (0)