mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: John Watts <contact@jookia.org>
To: barebox@lists.infradead.org
Cc: John Watts <contact@jookia.org>
Subject: [PATCH 2/2] imx6-mmdc: Revert calibration configuration on failure
Date: Tue, 24 Jan 2023 07:18:20 +1100	[thread overview]
Message-ID: <20230123201817.1084728-2-contact@jookia.org> (raw)
In-Reply-To: <20230123201817.1084728-1-contact@jookia.org>

When calibration fails it will clobber the existing configuration,
even if the configuration was working but not ideal.

Reverting calibration from a known bad value to a possibly good value
gives a better chance of the memory working.

I've tested this on the Novena board and had good success with it.
U-Boot implements a similar solution in its write level calibration.

Signed-off-by: John Watts <contact@jookia.org>
---
 arch/arm/mach-imx/imx6-mmdc.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-imx/imx6-mmdc.c b/arch/arm/mach-imx/imx6-mmdc.c
index 908771626a..0d50b39566 100644
--- a/arch/arm/mach-imx/imx6-mmdc.c
+++ b/arch/arm/mach-imx/imx6-mmdc.c
@@ -25,11 +25,18 @@ static bool wlcalib_failed(void __iomem *ips)
 
 int mmdc_do_write_level_calibration(void)
 {
+	u32 ldectrl[4] = {0};
 	u32 esdmisc_val, zq_val;
 	int errorcount = 0;
 	u32 val;
 	u32 ddr_mr1 = 0x4;
 
+	/* Store current calibration data in case of failure */
+	ldectrl[0] = readl(P0_IPS + MPWLDECTRL0);
+	ldectrl[1] = readl(P0_IPS + MPWLDECTRL1);
+	ldectrl[2] = readl(P1_IPS + MPWLDECTRL0);
+	ldectrl[3] = readl(P1_IPS + MPWLDECTRL1);
+
 	/* disable DDR logic power down timer */
 	val = readl((P0_IPS + MDPDC));
 	val &= 0xffff00ff;
@@ -69,8 +76,14 @@ int mmdc_do_write_level_calibration(void)
 	while (readl(P0_IPS + MPWLGCR) & 0x00000001);
 
 	/* check for any errors on both PHYs */
-	if (wlcalib_failed(P0_IPS) || wlcalib_failed(P1_IPS))
+	if (wlcalib_failed(P0_IPS) || wlcalib_failed(P1_IPS)) {
+		pr_debug("Calibration failed, rolling back calibration data\n");
+		writel(ldectrl[0], P0_IPS + MPWLDECTRL0);
+		writel(ldectrl[1], P0_IPS + MPWLDECTRL1);
+		writel(ldectrl[2], P1_IPS + MPWLDECTRL0);
+		writel(ldectrl[3], P1_IPS + MPWLDECTRL1);
 		errorcount++;
+	}
 
 	pr_debug("Write leveling calibration completed\n");
 
-- 
2.39.0




  reply	other threads:[~2023-01-23 20:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-23 20:18 [PATCH 1/2] imx6-mmdc: Work around ERR050070 John Watts
2023-01-23 20:18 ` John Watts [this message]
2023-01-24  8:29   ` [PATCH 2/2] imx6-mmdc: Revert calibration configuration on failure Ahmad Fatoum
2023-01-24 12:01     ` John Watts
2023-01-24 12:07       ` Ahmad Fatoum
2023-01-24  8:27 ` [PATCH 1/2] imx6-mmdc: Work around ERR050070 Ahmad Fatoum
2023-01-24 11:48   ` John Watts
2023-01-24 11:58     ` Ahmad Fatoum
2023-01-24 17:41 ` [PATCH v2 " John Watts
2023-01-25 15:48   ` Sascha Hauer
2023-01-24 17:41 ` [PATCH v2 2/2] imx6-mmdc: Revert calibration configuration on failure John Watts

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=20230123201817.1084728-2-contact@jookia.org \
    --to=contact@jookia.org \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox