mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Freimut Diener <f.diener@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	 Freimut Diener <f.diener@pengutronix.de>
Subject: [PATCH 4/5] ddr: imx9: allow DDR PHY training errors to propagate
Date: Fri, 27 Nov 2026 10:42:02 +0100	[thread overview]
Message-ID: <20261127-imx93-frdm-2cs-ddr-v1-4-64f5a99b3e4b@pengutronix.de> (raw)
In-Reply-To: <20261127-imx93-frdm-2cs-ddr-v1-0-64f5a99b3e4b@pengutronix.de>

The i.MX93 FRDM needs to try alternative DDR timings when PHY training
fails. The shared training code currently hangs on failure, preventing
the error from propagating to the caller.

Allow the i.MX9 DDR controller to return -EINVAL on training failure
while preserving the existing i.MX8M behavior.

Keep imx93_ddr_init() fatal on training failure, as existing callers
ignore its return value. This allows a subsequent patch to implement
DDR timing selection using the lower-level initialization function.

Signed-off-by: Freimut Diener <f.diener@pengutronix.de>
---
 drivers/ddr/imx/ddrphy_utils.c  | 2 ++
 drivers/ddr/imx/imx9_ddr_init.c | 1 +
 include/soc/imx/ddr.h           | 1 +
 include/soc/imx9/ddr.h          | 6 +++++-
 4 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/ddr/imx/ddrphy_utils.c b/drivers/ddr/imx/ddrphy_utils.c
index fa88ab83a5..4f07dbb50c 100644
--- a/drivers/ddr/imx/ddrphy_utils.c
+++ b/drivers/ddr/imx/ddrphy_utils.c
@@ -93,6 +93,8 @@ int wait_ddrphy_training_complete(struct dram_controller *dram)
 		case PMC_TRAIN_SUCCESS:
 			return 0;
 		case PMC_TRAIN_FAIL:
+			if (dram->return_training_error)
+				return -EINVAL;
 			hang();
 		}
 	}
diff --git a/drivers/ddr/imx/imx9_ddr_init.c b/drivers/ddr/imx/imx9_ddr_init.c
index 086827d9b3..9163b289ce 100644
--- a/drivers/ddr/imx/imx9_ddr_init.c
+++ b/drivers/ddr/imx/imx9_ddr_init.c
@@ -619,6 +619,7 @@ struct dram_controller imx9_dram_controller = {
 	.phy_remap = ddrphy_addr_remap,
 	.get_trained_CDD = get_trained_CDD,
 	.set_dfi_clk = ddrphy_init_set_dfi_clk,
+	.return_training_error = true,
 };
 
 int imx9_ddr_init(struct dram_timing_info *dram_timing, enum dram_type dram_type)
diff --git a/include/soc/imx/ddr.h b/include/soc/imx/ddr.h
index 4039b8d6e6..cc91e0ed32 100644
--- a/include/soc/imx/ddr.h
+++ b/include/soc/imx/ddr.h
@@ -113,6 +113,7 @@ struct dram_controller {
 	void (*get_trained_CDD)(struct dram_controller *dram, u32 fsp);
 	void (*set_dfi_clk)(struct dram_controller *dram, unsigned int drate_mhz);
 	bool imx8m_ddr_old_spreadsheet;
+	bool return_training_error;
 };
 
 void ddr_get_firmware_lpddr4(void);
diff --git a/include/soc/imx9/ddr.h b/include/soc/imx9/ddr.h
index 6435ce9d6d..bb3864f8c6 100644
--- a/include/soc/imx9/ddr.h
+++ b/include/soc/imx9/ddr.h
@@ -1,6 +1,7 @@
 #ifndef __SOC_IMX9_DDR_H
 #define __SOC_IMX9_DDR_H
 
+#include <barebox.h>
 #include <io.h>
 #include <asm/types.h>
 #include <soc/imx/ddr.h>
@@ -12,7 +13,10 @@ static inline int imx93_ddr_init(struct dram_timing_info *dram_timing,
 {
 	ddr_get_firmware(dram_type);
 
-	return imx9_ddr_init(dram_timing, dram_type);
+	if (imx9_ddr_init(dram_timing, dram_type))
+		hang();
+
+	return 0;
 }
 
 #endif /* __SOC_IMX9_DDR_H */

-- 
2.56.0




  parent reply	other threads:[~2026-11-27  9:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27  9:41 [PATCH 0/5] ARM: nxp-imx93-frdm: support both 2 GiB LPDDR4 Freimut Diener
2026-11-27  9:41 ` [PATCH 1/5] ARM: nxp-imx93-frdm: name the existing DDR timings for 1CS Freimut Diener
2026-11-27 10:37   ` Ahmad Fatoum
2026-11-27  9:42 ` [PATCH 2/5] ARM: nxp-imx93-frdm: import 2CS DDR timings from U-Boot Freimut Diener
2026-11-27  9:42 ` [PATCH 3/5] ARM: nxp-imx93-frdm: adapt the 2CS DDR timings for barebox Freimut Diener
2026-11-27  9:42 ` Freimut Diener [this message]
2026-11-27  9:42 ` [PATCH 5/5] ARM: nxp-imx93-frdm: select DDR timings at boot Freimut Diener

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=20261127-imx93-frdm-2cs-ddr-v1-4-64f5a99b3e4b@pengutronix.de \
    --to=f.diener@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=s.hauer@pengutronix.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox