Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH] mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing
@ 2023-08-31  3:26 haibo.chen
  2023-09-12 10:02 ` Adrian Hunter
  2023-09-14 13:02 ` Ulf Hansson
  0 siblings, 2 replies; 3+ messages in thread
From: haibo.chen @ 2023-08-31  3:26 UTC (permalink / raw)
  To: adrian.hunter, ulf.hansson, linux-mmc
  Cc: linux-imx, haibo.chen, shawnguo, s.hauer, kernel, festevam

From: Haibo Chen <haibo.chen@nxp.com>

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: Haibo Chen <haibo.chen@nxp.com>
---
 drivers/mmc/host/sdhci-esdhc-imx.c | 52 +++++++++++++++++++++---------
 1 file changed, 36 insertions(+), 16 deletions(-)

diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
index 6170b7121f36..4cbbc0a786a0 100644
--- a/drivers/mmc/host/sdhci-esdhc-imx.c
+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
@@ -1154,32 +1154,52 @@ 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;
-	while (min < ESDHC_TUNE_CTRL_MAX) {
-		esdhc_prepare_tuning(host, min);
-		if (!mmc_send_tuning(host->mmc, opcode, NULL))
-			break;
-		min += ESDHC_TUNE_CTRL_STEP;
-	}
-
-	/* find the maxinum delay which can not pass tuning */
-	max = min + ESDHC_TUNE_CTRL_STEP;
+	max = ESDHC_TUNE_CTRL_MIN;
+	target_win_length = 0;
 	while (max < ESDHC_TUNE_CTRL_MAX) {
-		esdhc_prepare_tuning(host, max);
-		if (mmc_send_tuning(host->mmc, opcode, NULL)) {
-			max -= ESDHC_TUNE_CTRL_STEP;
-			break;
+		/* 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))
+				break;
+			min += ESDHC_TUNE_CTRL_STEP;
 		}
-		max += ESDHC_TUNE_CTRL_STEP;
+
+		/* find the maxinum delay which can not pass tuning */
+		max = min + ESDHC_TUNE_CTRL_STEP;
+		while (max < ESDHC_TUNE_CTRL_MAX) {
+			esdhc_prepare_tuning(host, max);
+			if (mmc_send_tuning(host->mmc, opcode, NULL)) {
+				max -= ESDHC_TUNE_CTRL_STEP;
+				break;
+			}
+			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);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing
  2023-08-31  3:26 [PATCH] mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing haibo.chen
@ 2023-09-12 10:02 ` Adrian Hunter
  2023-09-14 13:02 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Adrian Hunter @ 2023-09-12 10:02 UTC (permalink / raw)
  To: haibo.chen, ulf.hansson, linux-mmc
  Cc: linux-imx, shawnguo, s.hauer, kernel, festevam

On 31/08/23 06:26, haibo.chen@nxp.com wrote:
> From: Haibo Chen <haibo.chen@nxp.com>
> 
> 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: Haibo Chen <haibo.chen@nxp.com>

Acked-by: Adrian Hunter <adrian.hunter@intel.com>

> ---
>  drivers/mmc/host/sdhci-esdhc-imx.c | 52 +++++++++++++++++++++---------
>  1 file changed, 36 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
> index 6170b7121f36..4cbbc0a786a0 100644
> --- a/drivers/mmc/host/sdhci-esdhc-imx.c
> +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
> @@ -1154,32 +1154,52 @@ 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;
> -	while (min < ESDHC_TUNE_CTRL_MAX) {
> -		esdhc_prepare_tuning(host, min);
> -		if (!mmc_send_tuning(host->mmc, opcode, NULL))
> -			break;
> -		min += ESDHC_TUNE_CTRL_STEP;
> -	}
> -
> -	/* find the maxinum delay which can not pass tuning */
> -	max = min + ESDHC_TUNE_CTRL_STEP;
> +	max = ESDHC_TUNE_CTRL_MIN;
> +	target_win_length = 0;
>  	while (max < ESDHC_TUNE_CTRL_MAX) {
> -		esdhc_prepare_tuning(host, max);
> -		if (mmc_send_tuning(host->mmc, opcode, NULL)) {
> -			max -= ESDHC_TUNE_CTRL_STEP;
> -			break;
> +		/* 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))
> +				break;
> +			min += ESDHC_TUNE_CTRL_STEP;
>  		}
> -		max += ESDHC_TUNE_CTRL_STEP;
> +
> +		/* find the maxinum delay which can not pass tuning */
> +		max = min + ESDHC_TUNE_CTRL_STEP;
> +		while (max < ESDHC_TUNE_CTRL_MAX) {
> +			esdhc_prepare_tuning(host, max);
> +			if (mmc_send_tuning(host->mmc, opcode, NULL)) {
> +				max -= ESDHC_TUNE_CTRL_STEP;
> +				break;
> +			}
> +			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);


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing
  2023-08-31  3:26 [PATCH] mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing haibo.chen
  2023-09-12 10:02 ` Adrian Hunter
@ 2023-09-14 13:02 ` Ulf Hansson
  1 sibling, 0 replies; 3+ messages in thread
From: Ulf Hansson @ 2023-09-14 13:02 UTC (permalink / raw)
  To: haibo.chen
  Cc: adrian.hunter, linux-mmc, linux-imx, shawnguo, s.hauer, kernel,
	festevam

On Thu, 31 Aug 2023 at 05:22, <haibo.chen@nxp.com> wrote:
>
> From: Haibo Chen <haibo.chen@nxp.com>
>
> 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: Haibo Chen <haibo.chen@nxp.com>

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/mmc/host/sdhci-esdhc-imx.c | 52 +++++++++++++++++++++---------
>  1 file changed, 36 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
> index 6170b7121f36..4cbbc0a786a0 100644
> --- a/drivers/mmc/host/sdhci-esdhc-imx.c
> +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
> @@ -1154,32 +1154,52 @@ 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;
> -       while (min < ESDHC_TUNE_CTRL_MAX) {
> -               esdhc_prepare_tuning(host, min);
> -               if (!mmc_send_tuning(host->mmc, opcode, NULL))
> -                       break;
> -               min += ESDHC_TUNE_CTRL_STEP;
> -       }
> -
> -       /* find the maxinum delay which can not pass tuning */
> -       max = min + ESDHC_TUNE_CTRL_STEP;
> +       max = ESDHC_TUNE_CTRL_MIN;
> +       target_win_length = 0;
>         while (max < ESDHC_TUNE_CTRL_MAX) {
> -               esdhc_prepare_tuning(host, max);
> -               if (mmc_send_tuning(host->mmc, opcode, NULL)) {
> -                       max -= ESDHC_TUNE_CTRL_STEP;
> -                       break;
> +               /* 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))
> +                               break;
> +                       min += ESDHC_TUNE_CTRL_STEP;
>                 }
> -               max += ESDHC_TUNE_CTRL_STEP;
> +
> +               /* find the maxinum delay which can not pass tuning */
> +               max = min + ESDHC_TUNE_CTRL_STEP;
> +               while (max < ESDHC_TUNE_CTRL_MAX) {
> +                       esdhc_prepare_tuning(host, max);
> +                       if (mmc_send_tuning(host->mmc, opcode, NULL)) {
> +                               max -= ESDHC_TUNE_CTRL_STEP;
> +                               break;
> +                       }
> +                       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);
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-09-14 13:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-31  3:26 [PATCH] mmc: sdhci-esdhc-imx: optimize the manual tuing logic to get the best timing haibo.chen
2023-09-12 10:02 ` Adrian Hunter
2023-09-14 13:02 ` Ulf Hansson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox