Commit 541a95e6 authored by Haibo Chen's avatar Haibo Chen Committed by Ulf Hansson
Browse files

mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing



Current manual tuning logic only get the first pass window, but
this pass window maybe not the best pass window.

Now find all the pass window, and chose the largest pass window,
and use the average value of this largest pass window to get the
best timing.

Signed-off-by: default avatarHaibo Chen <haibo.chen@nxp.com>
Acked-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Link: https://lore.kernel.org/r/20230831032647.3128702-1-haibo.chen@nxp.com


Signed-off-by: default avatarUlf Hansson <ulf.hansson@linaro.org>
parent a5b5006e
Loading
Loading
Loading
Loading
+36 −16
Original line number Diff line number Diff line
@@ -1154,12 +1154,20 @@ static void esdhc_post_tuning(struct sdhci_host *host)
	writel(reg, host->ioaddr + ESDHC_MIX_CTRL);
}

/*
 * find the largest pass window, and use the average delay of this
 * largest window to get the best timing.
 */
static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
{
	int min, max, avg, ret;
	int win_length, target_min, target_max, target_win_length;

	/* find the mininum delay first which can pass tuning */
	min = ESDHC_TUNE_CTRL_MIN;
	max = ESDHC_TUNE_CTRL_MIN;
	target_win_length = 0;
	while (max < ESDHC_TUNE_CTRL_MAX) {
		/* find the mininum delay first which can pass tuning */
		while (min < ESDHC_TUNE_CTRL_MAX) {
			esdhc_prepare_tuning(host, min);
			if (!mmc_send_tuning(host->mmc, opcode, NULL))
@@ -1178,8 +1186,20 @@ static int esdhc_executing_tuning(struct sdhci_host *host, u32 opcode)
			max += ESDHC_TUNE_CTRL_STEP;
		}

		win_length = max - min + 1;
		/* get the largest pass window */
		if (win_length > target_win_length) {
			target_win_length = win_length;
			target_min = min;
			target_max = max;
		}

		/* continue to find the next pass window */
		min = max + ESDHC_TUNE_CTRL_STEP;
	}

	/* use average delay to get the best timing */
	avg = (min + max) / 2;
	avg = (target_min + target_max) / 2;
	esdhc_prepare_tuning(host, avg);
	ret = mmc_send_tuning(host->mmc, opcode, NULL);
	esdhc_post_tuning(host);