Skip to contentSkip to conversation

board: bsh: imx6ulz_smm_m2: Match SPL DDR settings to DCD table

PATCH Superseded Dario Binacchi 2 participants 7 messages May 13, 2025 – May 20, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 board: bsh: imx6ulz_smm_m2: Match SPL DDR settings to DCD table

From: Michael Trimarchi <[email protected]>

When using SPL on i.mx6 we frequently notice some DDR initialization mismatches between the SPL code and the non-SPL code.

As the non-SPL code have been tested for long time and proves to be reliable, let's configure the DDR in the exact same way as the non-SPL case.

The idea is simple: just use the DCD table and write directly to the DDR registers.

---

 arch/arm/include/asm/arch-mx6/mx6-ddr.h |   2 +
 arch/arm/mach-imx/mx6/ddr.c             |   3 +
 board/bsh/imx6ulz_smm_m2/spl.c          | 235 +++++++++++++++++-------
 3 files changed, 178 insertions(+), 62 deletions(-)
arch/arm/include/asm/arch-mx6/mx6-ddr.h +2 -0
index ad9c1ac906a3..bd3ff65bcd96 100644
@@ -457,6 +457,8 @@ struct mx6_mmdc_calibration {
 	u32 p1_mpwrdlctl;
 	/* lpddr2 zq hw calibration */
 	u32 mpzqlp2ctl;
+	/* MDC Duty Cycle Control Register */
+	u32 mpdccr;
 };
 
 /* configure iomux (pinctl/padctl) */
arch/arm/mach-imx/mx6/ddr.c +3 -0
index 5a1258e002d2..749ceee0cdbf 100644
@@ -1444,6 +1444,9 @@ void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo,
 	mmdc0->mpdgctrl1 = calib->p0_mpdgctrl1;
 	mmdc0->mprddlctl = calib->p0_mprddlctl;
 	mmdc0->mpwrdlctl = calib->p0_mpwrdlctl;
+	if (calib->mpdccr)
+		mmdc0->mpdccr = calib->mpdccr;
+
 	if (sysinfo->dsize > 1) {
 		MMDC1(mpwldectrl0, calib->p1_mpwldectrl0);
 		MMDC1(mpwldectrl1, calib->p1_mpwldectrl1);
board/bsh/imx6ulz_smm_m2/spl.c +173 -62

263 lines not on this page · raw message

Signature · 4 lines
2.43.0

base-commit: cf37480bc8335494cf88b7180dc3f1eb8cf63a9d
branch: bsh-202505-RAM
#1 lore raw

PATCH 2/4 board: bsh: imx6ulz_smm_m2: Add support for 256 MiB DRAM

From: Simon Holesch <[email protected]>

Calibration values were calculated using the NXP tool I.MX6ULL_DDR3_Script_Aid_V0.01.xlsx

---

 board/bsh/imx6ulz_smm_m2/Makefile            |   2 +-
 board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c | 147 +++++++++++++++
 board/bsh/imx6ulz_smm_m2/ddr3l_timing_256m.c | 141 ++++++++++++++
 board/bsh/imx6ulz_smm_m2/spl.c               | 182 +++----------------
 board/bsh/imx6ulz_smm_m2/spl_mtypes.h        |  26 +++
 include/configs/imx6ulz_smm_m2.h             |   6 +-
 6 files changed, 339 insertions(+), 165 deletions(-)
 create mode 100644 board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c
 create mode 100644 board/bsh/imx6ulz_smm_m2/ddr3l_timing_256m.c
 create mode 100644 board/bsh/imx6ulz_smm_m2/spl_mtypes.h
board/bsh/imx6ulz_smm_m2/Makefile +1 -1
index 59870419bdde..d448f4fc5215 100644
@@ -2,5 +2,5 @@
 # (C) Copyright 2021 Amarula Solutions B.V.
 
 obj-y  := imx6ulz_smm_m2.o
-obj-$(CONFIG_XPL_BUILD) += spl.o
+obj-$(CONFIG_XPL_BUILD) += spl.o ddr3l_timing_256m.o ddr3l_timing_128m.o
 
board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c new file +147 -0

147 lines not on this page · raw message

board/bsh/imx6ulz_smm_m2/ddr3l_timing_256m.c new file +141 -0

141 lines not on this page · raw message

board/bsh/imx6ulz_smm_m2/spl.c +22 -160

205 lines not on this page · raw message

board/bsh/imx6ulz_smm_m2/spl_mtypes.h new file +26 -0
new file mode 100644
index 000000000000..f8dba6fb13f1
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2025 BSH Hausgeraete GmbH
+ *
+ * Written by: Simon Holesch <[email protected]>
+ */
+
+#ifndef __SPL_BOARD__
+#define __SPL_BOARD__
+
+#include <spl.h>
+
+struct dram_cfg_param {
+	unsigned int reg;
+	unsigned int val;
+};
+
+struct dram_timing_info {
+	const struct dram_cfg_param *ddrc_cfg;
+	unsigned int ddrc_cfg_num;
+};
+
+extern struct dram_timing_info bsh_dram_timing_256mb;
+extern struct dram_timing_info bsh_dram_timing_128mb;
+
+#endif
include/configs/imx6ulz_smm_m2.h +2 -4
index 44a3fc02e8ac..87aede218d16 100644
@@ -60,10 +60,8 @@
 	BOOTENV
 
 /* Physical Memory Map */
-#define PHYS_SDRAM			MMDC0_ARB_BASE_ADDR
-#define PHYS_SDRAM_SIZE			SZ_128M
-
-#define CFG_SYS_SDRAM_BASE		PHYS_SDRAM
+#define PHYS_SDRAM		MMDC0_ARB_BASE_ADDR
+#define CFG_SYS_SDRAM_BASE	PHYS_SDRAM
 #define CFG_SYS_INIT_RAM_ADDR	IRAM_BASE_ADDR
 #define CFG_SYS_INIT_RAM_SIZE	IRAM_SIZE
 
Signature · 4 lines
2.43.0

base-commit: cf37480bc8335494cf88b7180dc3f1eb8cf63a9d
branch: bsh-202505-RAM
reviewer
#2 lore raw

Re: [PATCH 2/4] board: bsh: imx6ulz_smm_m2: Add support for 256 MiB DRAM

board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c line 8

Quoted 4 lines · Dario Binacchi
board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c new file +4 -0
+static const struct dram_cfg_param ddr_ddrc_cfg_128mb[] = {
+       // IOMUX
+
+       //DDR IO TYPE:

Same comment as in the previous patch.

Quoted 1 line

+ //read data bit delay: 3 is the reccommended default value, although out of reset value is 0

recommended.

board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c line 105

Quoted 3 lines
board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c new file +3 -0
+       //Lower RALAT benefits:
+       //a. better operation at low frequency, for LPDDR2 freq < 100MHz, change RALAT to 3
+       //b. Small performence improvment

performance improvement

board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c line 105

Quoted 5 lines
board/bsh/imx6ulz_smm_m2/ddr3l_timing_128m.c new file +5 -0
+       //MDMISC: RALAT kept to the high level of 5.
+       //MDMISC: consider reducing RALAT if your 528MHz board design allow that.
+       //Lower RALAT benefits:
+       //a. better operation at low frequency, for LPDDR2 freq < 100MHz, change RALAT to 3
+       //b. Small performence improvment

performance improvement.

Quoted 3 lines

static void ddr_cfg_write(const struct dram_timing_info *dram_timing_info)

 {
        int i = 0;

You don't need to initialize i.

board/bsh/imx6ulz_smm_m2/spl_mtypes.h line 9

Quoted 11 lines

+++ b/board/bsh/imx6ulz_smm_m2/spl_mtypes.h

board/bsh/imx6ulz_smm_m2/spl_mtypes.h new file +9 -0
@@ -0,0 +1,26 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright 2025 BSH Hausgeraete GmbH
+ *
+ * Written by: Simon Holesch <[email protected]>
+ */
+
+#ifndef __SPL_BOARD__
+#define __SPL_BOARD__

This symbol does not match the file name.

#3 lore raw

PATCH 3/4 board: bsh: imx6ulz_smm_m2: Add support for 512 MiB DRAM

In reply to Dario Binacchi

From: Michael Bode <[email protected]>

Calibration values were calculated using the NXP tool I.MX6ULL_DDR3_Script_Aid_V0.01.xlsx

---

 board/bsh/imx6ulz_smm_m2/Makefile            |   3 +-
 board/bsh/imx6ulz_smm_m2/ddr3l_timing_512m.c | 139 +++++++++++++++++++
 board/bsh/imx6ulz_smm_m2/spl.c               |   9 +-
 board/bsh/imx6ulz_smm_m2/spl_mtypes.h        |   1 +
 4 files changed, 147 insertions(+), 5 deletions(-)
 create mode 100644 board/bsh/imx6ulz_smm_m2/ddr3l_timing_512m.c
board/bsh/imx6ulz_smm_m2/Makefile +1 -2
index d448f4fc5215..4f4d67f659d0 100644
@@ -2,5 +2,4 @@
 # (C) Copyright 2021 Amarula Solutions B.V.
 
 obj-y  := imx6ulz_smm_m2.o
-obj-$(CONFIG_XPL_BUILD) += spl.o ddr3l_timing_256m.o ddr3l_timing_128m.o
-
+obj-$(CONFIG_XPL_BUILD) += spl.o ddr3l_timing_512m.o ddr3l_timing_256m.o ddr3l_timing_128m.o
board/bsh/imx6ulz_smm_m2/ddr3l_timing_512m.c new file +139 -0

139 lines not on this page · raw message

board/bsh/imx6ulz_smm_m2/spl.c +6 -3
index 3b3b295d9ca7..dba5982d0865 100644
@@ -54,16 +54,19 @@ static void ddr_cfg_write(const struct dram_timing_info *dram_timing_info)
 static void spl_dram_init(void)
 {
 	/* Configure memory to maximum supported size for detection */
-	ddr_cfg_write(&bsh_dram_timing_256mb);
+	ddr_cfg_write(&bsh_dram_timing_512mb);
 
 	/* Detect memory physically present */
-	gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, SZ_256M);
+	gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE, SZ_512M);
 
 	/* Reconfigure memory for actual detected size */
 	switch (gd->ram_size) {
-	case SZ_256M:
+	case SZ_512M:
 		/* Already configured, nothing to do */
 		break;
+	case SZ_256M:
+		ddr_cfg_write(&bsh_dram_timing_256mb);
+		break;
 	case SZ_128M:
 	default:
 		ddr_cfg_write(&bsh_dram_timing_128mb);
board/bsh/imx6ulz_smm_m2/spl_mtypes.h +1 -0
index f8dba6fb13f1..0d79b9758f31 100644
@@ -20,6 +20,7 @@ struct dram_timing_info {
 	unsigned int ddrc_cfg_num;
 };
 
+extern struct dram_timing_info bsh_dram_timing_512mb;
 extern struct dram_timing_info bsh_dram_timing_256mb;
 extern struct dram_timing_info bsh_dram_timing_128mb;
 
Signature · 4 lines
2.43.0

base-commit: cf37480bc8335494cf88b7180dc3f1eb8cf63a9d
branch: bsh-202505-RAM
reviewer
#4 lore raw

Re: [PATCH 3/4] board: bsh: imx6ulz_smm_m2: Add support for 512 MiB DRAM

Quoted 3 lines · Dario Binacchi

+extern struct dram_timing_info bsh_dram_timing_512mb;
extern struct dram_timing_info bsh_dram_timing_256mb; extern struct dram_timing_info bsh_dram_timing_128mb;

Please keep these entries sorted.

#5 lore raw

PATCH 4/4 board: bsh: imx6ulz_smm_m2: Add delay between DRAM read access

In reply to Dario Binacchi

From: Michael Bode <[email protected]>

A small delay between DRAM read access with wrong parameters and reconfiguration is necessary.
Without a delay between DRAM read access and a following reconfiguration this reconfiguration fails for certain DRAM chips (Nanya).

---

 board/bsh/imx6ulz_smm_m2/spl.c | 3 +++
 1 file changed, 3 insertions(+)
board/bsh/imx6ulz_smm_m2/spl.c +3 -0
index dba5982d0865..d1d38163ec19 100644
@@ -13,6 +13,7 @@
 #include <asm/gpio.h>
 #include <asm/mach-imx/iomux-v3.h>
 #include <asm/mach-imx/boot_mode.h>
+#include <linux/delay.h>
 #include <linux/libfdt.h>
 #include <spl.h>
 #include <asm/arch/mx6-ddr.h>
@@ -65,10 +66,12 @@ static void spl_dram_init(void)
 		/* Already configured, nothing to do */
 		break;
 	case SZ_256M:
+		udelay(1);
 		ddr_cfg_write(&bsh_dram_timing_256mb);
 		break;
 	case SZ_128M:
 	default:
+		udelay(1);
 		ddr_cfg_write(&bsh_dram_timing_128mb);
 		break;
 	}
Signature · 4 lines
2.43.0

base-commit: cf37480bc8335494cf88b7180dc3f1eb8cf63a9d
branch: bsh-202505-RAM
reviewer
#6 lore raw
In reply to Dario Binacchi
Quoted 60 lines · Dario Binacchi

From: Michael Trimarchi <[email protected]>

When using SPL on i.mx6 we frequently notice some DDR initialization mismatches between the SPL code and the non-SPL code.

As the non-SPL code have been tested for long time and proves to be reliable, let's configure the DDR in the exact same way as the non-SPL case.

The idea is simple: just use the DCD table and write directly to the DDR registers.

---

 arch/arm/include/asm/arch-mx6/mx6-ddr.h |   2 +
 arch/arm/mach-imx/mx6/ddr.c             |   3 +
 board/bsh/imx6ulz_smm_m2/spl.c          | 235 +++++++++++++++++-------
 3 files changed, 178 insertions(+), 62 deletions(-)
arch/arm/include/asm/arch-mx6/mx6-ddr.h +2 -0
index ad9c1ac906a3..bd3ff65bcd96 100644
@@ -457,6 +457,8 @@ struct mx6_mmdc_calibration {
        u32 p1_mpwrdlctl;
        /* lpddr2 zq hw calibration */
        u32 mpzqlp2ctl;
+       /* MDC Duty Cycle Control Register */
+       u32 mpdccr;
 };
 
 /* configure iomux (pinctl/padctl) */
arch/arm/mach-imx/mx6/ddr.c +3 -0
index 5a1258e002d2..749ceee0cdbf 100644
@@ -1444,6 +1444,9 @@ void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo,
        mmdc0->mpdgctrl1 = calib->p0_mpdgctrl1;
        mmdc0->mprddlctl = calib->p0_mprddlctl;
        mmdc0->mpwrdlctl = calib->p0_mpwrdlctl;
+       if (calib->mpdccr)
+               mmdc0->mpdccr = calib->mpdccr;
+
        if (sysinfo->dsize > 1) {
                MMDC1(mpwldectrl0, calib->p1_mpwldectrl0);
                MMDC1(mpwldectrl1, calib->p1_mpwldectrl1);
board/bsh/imx6ulz_smm_m2/spl.c +0 -3
index 724841b57456..0fa510446813 100644
@@ -31,70 +31,184 @@ static void setup_iomux_uart(void)
        imx_iomux_v3_setup_multiple_pads(uart4_pads, ARRAY_SIZE(uart4_pads));
 }
 
-static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
-       .grp_addds              = 0x00000028,
-       .grp_ddrmode_ctl        = 0x00020000,

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void) · line 37

Quoted 10 lines
board/bsh/imx6ulz_smm_m2/spl.c +3 -6
-       .grp_b0ds               = 0x00000028,
-       .grp_ctlds              = 0x00000028,
-       .grp_b1ds               = 0x00000028,
-       .grp_ddrpke             = 0x00000000,
-       .grp_ddrmode            = 0x00020000,
-       .grp_ddr_type           = 0x000c0000,
+struct dram_cfg_param {
+       unsigned int reg;
+       unsigned int val;
 };

static struct.

Quoted 6 lines
board/bsh/imx6ulz_smm_m2/spl.c +0 -5
-static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
-       .dram_dqm0              = 0x00000028,
-       .dram_dqm1              = 0x00000028,
-       .dram_ras               = 0x00000028,
-       .dram_cas               = 0x00000028,

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void) · line 41

Quoted 10 lines
board/bsh/imx6ulz_smm_m2/spl.c +3 -7
-       .dram_odt0              = 0x00000028,
-       .dram_odt1              = 0x00000028,
-       .dram_sdba2             = 0x00000000,
-       .dram_sdclk_0           = 0x00000028,
-       .dram_sdqs0             = 0x00000028,
-       .dram_sdqs1             = 0x00000028,
-       .dram_reset             = 0x000c0028,
+struct dram_timing_info {
+       const struct dram_cfg_param *ddrc_cfg;
+       unsigned int ddrc_cfg_num;

static struct.

Please check globally in the series where the definitions can be made static.

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void) · line 47

Quoted 4 lines
board/bsh/imx6ulz_smm_m2/spl.c +4 -0
+static const struct dram_cfg_param ddr_ddrc_cfg_128mb[] = {
+       // IOMUX
+
+       //DDR IO TYPE:

Please use the standard C comment style:

/* For single line comment */

/*
* Or this style,
* For multi-line comments.
*/

Also, please put a space before DDR. The same applies everywhere in this series.

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void) · line 116

Quoted 4 lines
board/bsh/imx6ulz_smm_m2/spl.c +4 -0
+       //Write calibration
+       { 0x021b0850, 0x4040362E },     // MPWRDLCTL PHY0
+
+       //read data bit delay: 3 is the reccommended default value, although out of reset value is 0

Typo: recommended

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void)

Quoted 12 lines
board/bsh/imx6ulz_smm_m2/spl.c +12 -0
+       //MMDC init:
+       { 0x021b0004, 0x0002002D },     // MMDC0_MDPDC
+       { 0x021b0008, 0x1B333030 },     // MMDC0_MDOTC
+       { 0x021b000c, 0x2B2F52F3 },     // MMDC0_MDCFG0
+       { 0x021b0010, 0xB66D0B63 },     // MMDC0_MDCFG1
+       { 0x021b0014, 0x01FF00DB },     // MMDC0_MDCFG2
+
+       //MDMISC: RALAT kept to the high level of 5.
+       //MDMISC: consider reducing RALAT if your 528MHz board design allow that.
+       //Lower RALAT benefits:
+       //a. better operation at low frequency, for LPDDR2 freq < 100MHz, change RALAT to 3
+       //b. Small performence improvement

Typo: performance

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void) · line 166

Quoted 5 lines
board/bsh/imx6ulz_smm_m2/spl.c +5 -0
+       //    {0x021b001c,0x0200803A}, // MMDC0_MDSCR, MR2 write, CS1
+       //    {0x021b001c,0x0000803B}, // MMDC0_MDSCR, MR3 write, CS1
+       //    {0x021b001c,0x00048039}, // MMDC0_MDSCR, MR1 write, CS1
+       //    {0x021b001c,0x15208038}, // MMDC0_MDSCR, MR0write, CS1
+       //    {0x021b001c,0x04008048}, // MMDC0_MDSCR, ZQ calibration command sent to device on CS1

Please don't add the comment code. Please remove these commented code lines.

board/bsh/imx6ulz_smm_m2/spl.c static void setup_iomux_uart(void) · line 190

Quoted 3 lines
board/bsh/imx6ulz_smm_m2/spl.c +3 -0
+static void ddr_cfg_write(const struct dram_timing_info *dram_timing_info)
+{
+       int i = 0;

You don't need to initialize i.