All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 8/9] mmc: tmio: sdhi: Skip bad taps
Date: Sun, 10 Nov 2019 16:40:11 +0100	[thread overview]
Message-ID: <20191110154012.24603-8-marek.vasut+renesas@gmail.com> (raw)
In-Reply-To: <20191110154012.24603-1-marek.vasut+renesas@gmail.com>

Some of the tuning taps produce suboptimal results. Add code
which skips those "bad" taps.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
---
 drivers/mmc/renesas-sdhi.c | 49 +++++++++++++++++++++++++++++++++++++-
 drivers/mmc/tmio-common.h  |  1 +
 2 files changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c
index dcc77dd86c..087d8b47a8 100644
--- a/drivers/mmc/renesas-sdhi.c
+++ b/drivers/mmc/renesas-sdhi.c
@@ -97,6 +97,7 @@ static bool renesas_sdhi_check_scc_error(struct udevice *dev)
 	struct tmio_sd_priv *priv = dev_get_priv(dev);
 	struct mmc *mmc = mmc_get_mmc_dev(dev);
 	unsigned long new_tap = priv->tap_set;
+	unsigned long error_tap = priv->tap_set;
 	u32 reg, smpcmp;
 
 	if ((priv->caps & TMIO_SD_CAP_RCAR_UHS) &&
@@ -140,15 +141,32 @@ static bool renesas_sdhi_check_scc_error(struct udevice *dev)
 		case RENESAS_SDHI_SCC_SMPCMP_CMD_REQUP:
 			new_tap = (priv->tap_set +
 				   priv->tap_num + 1) % priv->tap_num;
+			error_tap = (priv->tap_set +
+				     priv->tap_num - 1) % priv->tap_num;
 			break;
 		case RENESAS_SDHI_SCC_SMPCMP_CMD_REQDOWN:
 			new_tap = (priv->tap_set +
 				   priv->tap_num - 1) % priv->tap_num;
+			error_tap = (priv->tap_set +
+				     priv->tap_num + 1) % priv->tap_num;
 			break;
 		default:
 			return true;	/* Need re-tune */
 		}
 
+		if (priv->hs400_bad_tap & BIT(new_tap)) {
+			/*
+			 * New tap is bad tap (cannot change).
+			 * Compare with HS200 tuning result.
+			 * In HS200 tuning, when smpcmp[error_tap]
+			 * is OK, retune is executed.
+			 */
+			if (priv->smpcmp & BIT(error_tap))
+				return true;	/* Need retune */
+
+			return false;	/* cannot change */
+		}
+
 		priv->tap_set = new_tap;
 	} else {
 		if (reg & RENESAS_SDHI_SCC_RVSREQ_RVSERR)
@@ -303,6 +321,7 @@ static int renesas_sdhi_hs400(struct udevice *dev)
 	struct mmc *mmc = mmc_get_mmc_dev(dev);
 	bool hs400 = (mmc->selected_mode == MMC_HS_400);
 	int ret, taps = hs400 ? priv->nrtaps : 8;
+	unsigned long new_tap;
 	u32 reg;
 
 	if (taps == 4)	/* HS400 on 4tap SoC needs different clock */
@@ -335,6 +354,24 @@ static int renesas_sdhi_hs400(struct udevice *dev)
 			     RENESAS_SDHI_SCC_DTCNTL_TAPEN,
 			     RENESAS_SDHI_SCC_DTCNTL);
 
+	/* Avoid bad TAP */
+	if (priv->hs400_bad_tap & BIT(priv->tap_set)) {
+		new_tap = (priv->tap_set +
+			   priv->tap_num + 1) % priv->tap_num;
+
+		if (priv->hs400_bad_tap & BIT(new_tap))
+			new_tap = (priv->tap_set +
+				   priv->tap_num - 1) % priv->tap_num;
+
+		if (priv->hs400_bad_tap & BIT(new_tap)) {
+			new_tap = priv->tap_set;
+			debug("Three consecutive bad tap is prohibited\n");
+		}
+
+		priv->tap_set = new_tap;
+		tmio_sd_writel(priv, priv->tap_set, RENESAS_SDHI_SCC_TAPSET);
+	}
+
 	if (taps == 4) {
 		tmio_sd_writel(priv, priv->tap_set >> 1,
 			       RENESAS_SDHI_SCC_TAPSET);
@@ -682,13 +719,23 @@ static void renesas_sdhi_filter_caps(struct udevice *dev)
 	    (rmobile_get_cpu_rev_fraction() <= 2)))
 		plat->cfg.host_caps &= ~MMC_MODE_HS400;
 
-	/* M3W ES1.x for x>2 can use HS400 with manual adjustment */
+	/* H3 ES2.0, ES3.0 and M3W ES1.2 and M3N bad taps */
+	if (((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7795) &&
+	    (rmobile_get_cpu_rev_integer() >= 2)) ||
+	    ((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7796) &&
+	    (rmobile_get_cpu_rev_integer() == 1) &&
+	    (rmobile_get_cpu_rev_fraction() == 2)) ||
+	    (rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A77965))
+		priv->hs400_bad_tap = BIT(2) | BIT(3) | BIT(6) | BIT(7);
+
+	/* M3W ES1.x for x>2 can use HS400 with manual adjustment and taps */
 	if ((rmobile_get_cpu_type() == RMOBILE_CPU_TYPE_R8A7796) &&
 	    (rmobile_get_cpu_rev_integer() == 1) &&
 	    (rmobile_get_cpu_rev_fraction() > 2)) {
 		priv->adjust_hs400_enable = true;
 		priv->adjust_hs400_offset = 3;
 		priv->adjust_hs400_calibrate = 0x9;
+		priv->hs400_bad_tap = BIT(1) | BIT(3) | BIT(5) | BIT(7);
 	}
 
 	/* M3N can use HS400 with manual adjustment */
diff --git a/drivers/mmc/tmio-common.h b/drivers/mmc/tmio-common.h
index 79f51d21af..f39118e337 100644
--- a/drivers/mmc/tmio-common.h
+++ b/drivers/mmc/tmio-common.h
@@ -145,6 +145,7 @@ struct tmio_sd_priv {
 	bool				adjust_hs400_enable;
 	u8				adjust_hs400_offset;
 	u8				adjust_hs400_calibrate;
+	u8				hs400_bad_tap;
 #endif
 	ulong (*clk_get_rate)(struct tmio_sd_priv *);
 };
-- 
2.24.0.rc1

  parent reply	other threads:[~2019-11-10 15:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-10 15:40 [U-Boot] [PATCH 1/9] mmc: tmio: sdhi: Track current tap number in private data Marek Vasut
2019-11-10 15:40 ` [U-Boot] [PATCH 2/9] mmc: tmio: sdhi: Track SMPCMP valu " Marek Vasut
2019-11-10 15:40 ` [U-Boot] [PATCH 3/9] mmc: tmio: sdhi: Use 4 tuning taps on M3W up to ES1.2 Marek Vasut
2019-11-10 15:40 ` [U-Boot] [PATCH 4/9] mmc: tmio: sdhi: Adjust DT2FF settings for HS400 mode Marek Vasut
2019-11-10 15:40 ` [U-Boot] [PATCH 5/9] mmc: tmio: sdhi: Adjust HS400 calibration offsets Marek Vasut
2019-11-10 15:40 ` [U-Boot] [PATCH 6/9] mmc: tmio: sdhi: Disable auto-retuning in HS400 Marek Vasut
2019-11-10 15:40 ` [U-Boot] [PATCH 7/9] mmc: tmio: sdhi: Add SCC error checking Marek Vasut
2019-11-10 15:40 ` Marek Vasut [this message]
2019-11-10 15:40 ` [U-Boot] [PATCH 9/9] mmc: tmio: sdhi: Add calibration tables Marek Vasut
2019-11-22  6:22   ` Peng Fan
2019-11-23 12:38     ` Marek Vasut
2019-11-21  1:57 ` [U-Boot] [PATCH 1/9] mmc: tmio: sdhi: Track current tap number in private data Peng Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191110154012.24603-8-marek.vasut+renesas@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.