linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mmc: dw_mmc: exynos: fix the finding clock sample value
       [not found] <CGME20211022035959epcas1p40ccc67175d6a4a22943e5836609fb834@epcas1p4.samsung.com>
@ 2021-10-22  4:00 ` Jaehoon Chung
  2021-10-22  6:53   ` Marek Szyprowski
  0 siblings, 1 reply; 2+ messages in thread
From: Jaehoon Chung @ 2021-10-22  4:00 UTC (permalink / raw)
  To: linux-mmc
  Cc: ulf.hansson, krzysztof.kozlowski, christianshewitt, mihailescu2m,
	m.szyprowski, Jaehoon Chung

Even though there are candiates value if can't find best value, it's
returned -EIO. It's not proper behavior.
If there is not best value, use a first candiate value to work eMMC.

Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
---
 drivers/mmc/host/dw_mmc-exynos.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
index 0c75810812a0..a475c249c430 100644
--- a/drivers/mmc/host/dw_mmc-exynos.c
+++ b/drivers/mmc/host/dw_mmc-exynos.c
@@ -431,6 +431,7 @@ static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
 		clksel = mci_readl(host, CLKSEL);
 
 	sample = (clksel + 1) & 0x7;
+
 	clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
 
 	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
@@ -464,6 +465,14 @@ static s8 dw_mci_exynos_get_best_clksmpl(u8 candiates)
 		}
 	}
 
+	/* Return a first candiates value, if there is some candiates */
+	for (i = 0; i < iter; i++) {
+		__c = ror8(candiates, i);
+		if ((__c & 0x1) == 0x1) {
+			loc = i;
+			goto out;
+		}
+	}
 out:
 	return loc;
 }
@@ -493,7 +502,18 @@ static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode)
 		dw_mci_exynos_set_clksmpl(host, found);
 		priv->tuned_sample = found;
 	} else {
-		ret = -EIO;
+		/*
+		 * If there is no cadiates value, then it needs to return -EIO.
+		 * If there are candiates values and don't find bset clk sample value,
+		 * then use a first candiates clock sample value.
+		 */
+		if (candiates == 0) {
+			ret = -EIO;
+			dev_warn(&mmc->class_dev,
+				"There is no candiates value about clksmpl!\n");
+		} else {
+			priv->tuned_sample = dw_mci_exynos_get_clksmpl(host);
+		}
 	}
 
 	return ret;
-- 
2.29.0


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

* Re: [PATCH] mmc: dw_mmc: exynos: fix the finding clock sample value
  2021-10-22  4:00 ` [PATCH] mmc: dw_mmc: exynos: fix the finding clock sample value Jaehoon Chung
@ 2021-10-22  6:53   ` Marek Szyprowski
  0 siblings, 0 replies; 2+ messages in thread
From: Marek Szyprowski @ 2021-10-22  6:53 UTC (permalink / raw)
  To: Jaehoon Chung, linux-mmc
  Cc: ulf.hansson, krzysztof.kozlowski, christianshewitt, mihailescu2m

On 22.10.2021 06:00, Jaehoon Chung wrote:
> Even though there are candiates value if can't find best value, it's
> returned -EIO. It's not proper behavior.
> If there is not best value, use a first candiate value to work eMMC.
>
> Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

Works fine with all eMMC modules I have on my test systems.

> ---
>   drivers/mmc/host/dw_mmc-exynos.c | 22 +++++++++++++++++++++-
>   1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/dw_mmc-exynos.c b/drivers/mmc/host/dw_mmc-exynos.c
> index 0c75810812a0..a475c249c430 100644
> --- a/drivers/mmc/host/dw_mmc-exynos.c
> +++ b/drivers/mmc/host/dw_mmc-exynos.c
> @@ -431,6 +431,7 @@ static inline u8 dw_mci_exynos_move_next_clksmpl(struct dw_mci *host)
>   		clksel = mci_readl(host, CLKSEL);
>   
>   	sample = (clksel + 1) & 0x7;
> +
>   	clksel = SDMMC_CLKSEL_UP_SAMPLE(clksel, sample);
>   
>   	if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS7 ||
> @@ -464,6 +465,14 @@ static s8 dw_mci_exynos_get_best_clksmpl(u8 candiates)
>   		}
>   	}
>   
> +	/* Return a first candiates value, if there is some candiates */
> +	for (i = 0; i < iter; i++) {
> +		__c = ror8(candiates, i);
> +		if ((__c & 0x1) == 0x1) {
> +			loc = i;
> +			goto out;
> +		}
> +	}
>   out:
>   	return loc;
>   }
> @@ -493,7 +502,18 @@ static int dw_mci_exynos_execute_tuning(struct dw_mci_slot *slot, u32 opcode)
>   		dw_mci_exynos_set_clksmpl(host, found);
>   		priv->tuned_sample = found;
>   	} else {
> -		ret = -EIO;
> +		/*
> +		 * If there is no cadiates value, then it needs to return -EIO.
> +		 * If there are candiates values and don't find bset clk sample value,
> +		 * then use a first candiates clock sample value.
> +		 */
> +		if (candiates == 0) {
> +			ret = -EIO;
> +			dev_warn(&mmc->class_dev,
> +				"There is no candiates value about clksmpl!\n");
> +		} else {
> +			priv->tuned_sample = dw_mci_exynos_get_clksmpl(host);
> +		}
>   	}
>   
>   	return ret;

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland


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

end of thread, other threads:[~2021-10-22  6:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20211022035959epcas1p40ccc67175d6a4a22943e5836609fb834@epcas1p4.samsung.com>
2021-10-22  4:00 ` [PATCH] mmc: dw_mmc: exynos: fix the finding clock sample value Jaehoon Chung
2021-10-22  6:53   ` Marek Szyprowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).