[PATCH 4/5] ddr: imx9: allow DDR PHY training errors to propagate

Freimut Diener f.diener at pengutronix.de
Fri Nov 27 01:42:02 PST 2026


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 at 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




More information about the barebox mailing list