All of lore.kernel.org
 help / color / mirror / Atom feed
From: Aswath Govindraju <a-govindraju@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v3 08/20] mmc: am654_sdhci: Add support for software tuning
Date: Thu, 21 Jan 2021 18:10:40 +0530	[thread overview]
Message-ID: <20210121124052.3454-9-a-govindraju@ti.com> (raw)
In-Reply-To: <20210121124052.3454-1-a-govindraju@ti.com>

From: Faiz Abbas <faiz_abbas@ti.com>

With the new SW tuning App note[1], a custom tuning algorithm is
required for eMMC HS200, HS400 and SD card UHS modes. The algorithm
involves running through the 32 possible input tap delay values and
sending the appropriate tuning command (CMD19/21) for each of them
to get a fail or pass result for each of the values. Typically, the
range will have a small contiguous failing window. Considering the
tuning range as a circular buffer, the algorithm then sets a final
tuned value directly opposite to the failing window.

[1] https://www.ti.com/lit/pdf/spract9

Signed-off-by: Faiz Abbas <faiz_abbas@ti.com>
Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
---
 drivers/mmc/am654_sdhci.c | 45 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

diff --git a/drivers/mmc/am654_sdhci.c b/drivers/mmc/am654_sdhci.c
index e86ef1a8b218..9549420c6582 100644
--- a/drivers/mmc/am654_sdhci.c
+++ b/drivers/mmc/am654_sdhci.c
@@ -9,6 +9,7 @@
 #include <common.h>
 #include <dm.h>
 #include <malloc.h>
+#include <mmc.h>
 #include <power-domain.h>
 #include <regmap.h>
 #include <sdhci.h>
@@ -368,7 +369,48 @@ static int am654_sdhci_deferred_probe(struct sdhci_host *host)
 	return sdhci_probe(dev);
 }
 
+#ifdef MMC_SUPPORTS_TUNING
+#define ITAP_MAX	32
+static int am654_sdhci_execute_tuning(struct mmc *mmc, u8 opcode)
+{
+	struct udevice *dev = mmc->dev;
+	struct am654_sdhci_plat *plat = dev_get_plat(dev);
+	int cur_val, prev_val = 1, fail_len = 0, pass_window = 0, pass_len;
+	u32 itap;
+
+	/* Enable ITAPDLY */
+	regmap_update_bits(plat->base, PHY_CTRL4, ITAPDLYENA_MASK,
+			   1 << ITAPDLYENA_SHIFT);
+
+	for (itap = 0; itap < ITAP_MAX; itap++) {
+		am654_sdhci_write_itapdly(plat, itap);
+
+		cur_val = !mmc_send_tuning(mmc, opcode, NULL);
+		if (cur_val && !prev_val)
+			pass_window = itap;
+
+		if (!cur_val)
+			fail_len++;
+
+		prev_val = cur_val;
+	}
+	/*
+	 * Having determined the length of the failing window and start of
+	 * the passing window calculate the length of the passing window and
+	 * set the final value halfway through it considering the range as a
+	 * circular buffer
+	 */
+	pass_len = ITAP_MAX - fail_len;
+	itap = (pass_window + (pass_len >> 1)) % ITAP_MAX;
+	am654_sdhci_write_itapdly(plat, itap);
+
+	return 0;
+}
+#endif
 const struct sdhci_ops am654_sdhci_ops = {
+#ifdef MMC_SUPPORTS_TUNING
+	.platform_execute_tuning = am654_sdhci_execute_tuning,
+#endif
 	.deferred_probe		= am654_sdhci_deferred_probe,
 	.set_ios_post		= &am654_sdhci_set_ios_post,
 	.set_control_reg	= &am654_sdhci_set_control_reg,
@@ -408,6 +450,9 @@ static int j721e_4bit_sdhci_set_ios_post(struct sdhci_host *host)
 }
 
 const struct sdhci_ops j721e_4bit_sdhci_ops = {
+#ifdef MMC_SUPPORTS_TUNING
+	.platform_execute_tuning = am654_sdhci_execute_tuning,
+#endif
 	.deferred_probe		= am654_sdhci_deferred_probe,
 	.set_ios_post		= &j721e_4bit_sdhci_set_ios_post,
 };
-- 
2.17.1

  parent reply	other threads:[~2021-01-21 12:40 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21 12:40 [PATCH v3 00/20] Add support for MMC higher speed modes for TI's am65x, j721e and j7200 platforms Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 01/20] mmc: sdhci: Add helper functions for UHS modes Aswath Govindraju
2021-01-24  2:03   ` Simon Glass
2021-01-25 10:23     ` Aswath Govindraju
2021-01-25 22:18   ` Jaehoon Chung
2021-01-28  9:20     ` Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 02/20] mmc: am654_sdhci: Unconditionally switch off DLL in the beginning of ios_post() Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 03/20] mmc: am654_sdhci: Convert flag fields to BIT macro Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 04/20] mmc: am654_sdhci: Add flag for PHY calibration Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 05/20] mmc: am654_sdhci: Add support for AM65x SR2.0 Aswath Govindraju
2021-01-25 22:19   ` Jaehoon Chung
2021-01-28  9:15     ` Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 06/20] mmc: am654_sdhci: Add support for input tap delay Aswath Govindraju
2021-01-25 22:21   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 07/20] mmc: am654_sdhci: Add support for writing to clkbuf_sel Aswath Govindraju
2021-01-25 22:22   ` Jaehoon Chung
2021-01-21 12:40 ` Aswath Govindraju [this message]
2021-01-25 22:41   ` [PATCH v3 08/20] mmc: am654_sdhci: Add support for software tuning Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 09/20] mmc: am654_sdhci: Fix HISPD bit configuration in some lower speed modes Aswath Govindraju
2021-01-25 22:43   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 10/20] mmc: am654_sdhci: Use sdhci_set_control_reg() Aswath Govindraju
2021-01-25 22:43   ` Jaehoon Chung
2021-01-21 12:40 ` [PATCH v3 11/20] arm: dts: k3-am65: Fix mmc nodes Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 12/20] arm: dts: k3-j721e-main: Update otap-delay values Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 13/20] arm: dts: k3-j721e-common-proc-board: Add support for UHS modes for SD card Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 14/20] arm: dts: k3-j7200-main: Add support for gpio0 Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 15/20] arm: dts: k3-j7200-common-proc-board: Enable support for UHS modes Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 16/20] configs: j721e_evm: Add " Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 17/20] configs: j7200_evm: " Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 18/20] arm: dts: k3-am65-main: Add itapdly and clkbuf-sel values Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 19/20] arm: dts: k3-am654-base-board: Limit Sd card to High speed modes Aswath Govindraju
2021-01-21 12:40 ` [PATCH v3 20/20] configs: am65x_evm: Add configs for UHS modes Aswath Govindraju

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=20210121124052.3454-9-a-govindraju@ti.com \
    --to=a-govindraju@ti.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.