From 55e99402dd72dc889ca5c5700d1f777fc864d020 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Thu, 13 Apr 2023 02:08:47 +0300 Subject: [PATCH] mmc: sdhci-tegra: enforce min window size for manual tuning Check against minimum allowed sampling window size on manual tuning. That allows DDR200 to fail if not enough and then re-init to SDR104. A safe window size for DDR200 is 8. --- drivers/mmc/host/sdhci-tegra.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c index 4296d89d29d2..a571ce5666b4 100644 --- a/drivers/mmc/host/sdhci-tegra.c +++ b/drivers/mmc/host/sdhci-tegra.c @@ -1663,6 +1663,7 @@ static void tegra_sdhci_execute_manual_tuning(struct sdhci_host *host, int num_i } #define INVALID_TAP 0x100 +#define SAMPLING_WINDOW_SIZE_MIN 8 /* DDR200 */ static int tegra_sdhci_execute_tuning_ddr200(struct sdhci_host *host) { struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); @@ -1730,6 +1731,15 @@ static int tegra_sdhci_execute_tuning_ddr200(struct sdhci_host *host) } } + if (best_size < SAMPLING_WINDOW_SIZE_MIN) { + dev_err(mmc_dev(host->mmc), + "manual tuning failed, " + "sampling window size (%d) too small...\n", + best_size); + err = -EIO; + goto out; + } + if (!best_tap) { dev_err(mmc_dev(host->mmc), "manual tuning failed, no best tap...\n");