Skip to contentSkip to conversation

mx6: ddr: Allow changing REFSEL and REFR fields

PATCH Superseded Fabio Estevam 2 participants 9 messages Aug 29, 2016 Arm (32-bit)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 mx6: ddr: Allow changing REFSEL and REFR fields

From: Fabio Estevam <[email protected]>

Currently MX6 SPL DDR initialization hardcodes the REF_SEL and REFR fields of the MDREF register as 1 and 7, respectively.

Looking at the MDREF initialization done via DCD we see that boards do need to initialize these fields differently:

$ git grep 0x021b0020 board/
board/bachmann/ot1200/mx6q_4x_mt41j128.cfg:DATA 4 0x021b0020 0x00005800
board/ccv/xpress/imximage.cfg:DATA 4 0x021b0020 0x00000800 /* MMDC0_MDREF */
board/freescale/mx6qarm2/imximage.cfg:DATA 4 0x021b0020 0x7800
board/freescale/mx6qarm2/imximage.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qarm2/imximage_mx6dl.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qarm2/imximage_mx6dl.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qsabreauto/imximage.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qsabreauto/mx6dl.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qsabreauto/mx6qp.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6sabresd/mx6dlsabresd.cfg:DATA 4      0x021b0020 0x00005800
board/freescale/mx6sabresd/mx6q_4x_mt41j128.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6slevk/imximage.cfg:DATA 4 0x021b0020 0x00001800
board/freescale/mx6sxsabreauto/imximage.cfg:DATA 4 0x021b0020 0x00000800
board/freescale/mx6sxsabresd/imximage.cfg:DATA 4 0x021b0020 0x00000800
board/warp/imximage.cfg:DATA 4 0x021b0020 0x00001800

So introduce a mechanism for users to configure REFSEL and REFR fields as needed.

---
Changes since v2:
- Do not make this mx6ul specific (Eric)

 arch/arm/cpu/armv7/mx6/ddr.c            | 15 ++++++++++++---
 arch/arm/include/asm/arch-mx6/mx6-ddr.h |  2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)
arch/arm/cpu/armv7/mx6/ddr.c +12 -3
index f151eec..ebc7903 100644
@@ -1183,7 +1183,7 @@ void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo,
 	volatile struct mmdc_p_regs *mmdc0;
 	volatile struct mmdc_p_regs *mmdc1;
 	u32 val;
-	u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd;
+	u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd, refsel, refr;
 	u8 todtlon, taxpd, tanpd, tcwl, txp, tfaw, tcl;
 	u8 todt_idle_off = 0x4; /* from DDR3 Script Aid spreadsheet */
 	u16 trcd, trc, tras, twr, tmrd, trtp, trp, twtr, trfc, txs, txpr;
@@ -1472,8 +1472,17 @@ void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo,
 		MMDC1(mpzqhwctrl, val);
 
 	/* Step 12: Configure and activate periodic refresh */
-	mmdc0->mdref = (1 << 14) | /* REF_SEL: Periodic refresh cycle: 32kHz */
-		       (7 << 11);  /* REFR: Refresh Rate - 8 refreshes */
+	if (!sysinfo->refsel)
+		refsel = 1; /* REF_SEL: Periodic refresh cycle: 32kHz */
+	else
+		refsel = sysinfo->refsel;
+
+	if (!sysinfo->refr)
+		refr = 7; /* REFR: Refresh Rate - 8 refreshes */
+	else
+		refr = sysinfo->refr;
+
+	mmdc0->mdref = (refsel << 14) | (refr << 11);
 
 	/* Step 13: Deassert config request - init complete */
 	mmdc0->mdscr = 0x00000000;
arch/arm/include/asm/arch-mx6/mx6-ddr.h +2 -0
index 12c30d2..9922409 100644
@@ -408,6 +408,8 @@ struct mx6_ddr_sysinfo {
 	u8 sde_to_rst;	/* Time from SDE enable until DDR reset# is high */
 	u8 pd_fast_exit;/* enable precharge powerdown fast-exit */
 	u8 ddr_type;	/* DDR type: DDR3(0) or LPDDR2(1) */
+	u8 refsel;	/* REF_SEL field of register MDREF */
+	u8 refr;	/* REFR field of register MDREF */
 };
 
 /*
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 2/4 mx6ul_14x14_evk: Pass refsel and refr fields to avoid hang

From: Fabio Estevam <[email protected]>

When running a NXP 4.1 kernel with U-Boot mainline on a mx6ul-evk, we observe a hang when going into the lowest operational point of cpufreq.

This hang issue does not happen on the NXP U-Boot version.

After comparing the SPL DDR initialization against the DCD table from NXP U-Boot, the key difference that causes the hang is the MDREF register setting:

DATA 4 0x021B0020 0x00000800

,which means:

REF_SEL = 0 --> Periodic refresh cycle: 64kHz
REFR = 1 ---> Refresh Rate - 2 refreshes

So adjust the MDREF initialization for mx6ul_evk accordingly to fix the kernel hang issue at low bus frequency.

---
Changes since v2:
- Newly intriduced in this series.

 board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c | 2 ++
 1 file changed, 2 insertions(+)
board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c +2 -0
index c213861..c3a5cd5 100644
@@ -804,6 +804,8 @@ struct mx6_ddr_sysinfo ddr_sysinfo = {
 	.sde_to_rst = 0x10,	/* 14 cycles, 200us (JEDEC default) */
 	.rst_to_cke = 0x23,	/* 33 cycles, 500us (JEDEC default) */
 	.ddr_type = DDR_TYPE_DDR3,
+	.refsel = 0,		/* Refresh cycles at 64KHz */
+	.refr = 1,		/* 2 refresh commands per refresh cycle */
 };
 
 static struct mx6_ddr3_cfg mem_ddr = {
Signature · 1 line
1.9.1
#2 lore raw

PATCH v3 3/4 mx6ul_14x14_evk: Adjust SPL DDR3 settings

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

Adjust DDR3 initialization done in SPL by comparing them against the NXP DCD table.

---
Changes since v2:
- None

 board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c +7 -7
index c3a5cd5..82d6a3a 100644
@@ -777,17 +777,17 @@ static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
 	.dram_odt0 = 0x00000030,
 	.dram_odt1 = 0x00000030,
 	.dram_sdba2 = 0x00000000,
-	.dram_sdclk_0 = 0x00000008,
-	.dram_sdqs0 = 0x00000038,
+	.dram_sdclk_0 = 0x00000030,
+	.dram_sdqs0 = 0x00000030,
 	.dram_sdqs1 = 0x00000030,
 	.dram_reset = 0x00000030,
 };
 
 static struct mx6_mmdc_calibration mx6_mmcd_calib = {
-	.p0_mpwldectrl0 = 0x00070007,
-	.p0_mpdgctrl0 = 0x41490145,
-	.p0_mprddlctl = 0x40404546,
-	.p0_mpwrdlctl = 0x4040524D,
+	.p0_mpwldectrl0 = 0x00000000,
+	.p0_mpdgctrl0 = 0x41570155,
+	.p0_mprddlctl = 0x4040474A,
+	.p0_mpwrdlctl = 0x40405550,
 };
 
 struct mx6_ddr_sysinfo ddr_sysinfo = {
@@ -797,7 +797,7 @@ struct mx6_ddr_sysinfo ddr_sysinfo = {
 	.cs1_mirror = 0,
 	.rtt_wr = 2,
 	.rtt_nom = 1,		/* RTT_Nom = RZQ/2 */
-	.walat = 1,		/* Write additional latency */
+	.walat = 0,		/* Write additional latency */
 	.ralat = 5,		/* Read additional latency */
 	.mif3_mode = 3,		/* Command prediction working mode */
 	.bi_on = 1,		/* Bank interleaving enabled */
Signature · 1 line
1.9.1
#3 lore raw

PATCH v3 4/4 mx6ul_14x14_ev: Enable the CCGR clocks earlier

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

To be in the safe side we need to enable the CCGR clocks prior to calling arch_cpu_init().

Inspired by Tim Harvey's commit d783c2744f9 ("imx: ventana: fix boot to SD").

---
Changes since v2:
- None

 board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/freescale/mx6ul_14x14_evk/mx6ul_14x14_evk.c +2 -2
index 82d6a3a..95303c7 100644
@@ -844,11 +844,11 @@ static void spl_dram_init(void)
 
 void board_init_f(ulong dummy)
 {
+	ccgr_init();
+
 	/* setup AIPS and disable watchdog */
 	arch_cpu_init();
 
-	ccgr_init();
-
 	/* iomux and setup of i2c */
 	board_early_init_f();
 
Signature · 1 line
1.9.1
#4 lore raw

PATCH v3 1/4 mx6: ddr: Allow changing REFSEL and REFR fields

In reply to Fabio Estevam

Hi Fabio,

Quoted 51 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Currently MX6 SPL DDR initialization hardcodes the REF_SEL and REFR fields of the MDREF register as 1 and 7, respectively.

Looking at the MDREF initialization done via DCD we see that boards do need to initialize these fields differently:

$ git grep 0x021b0020 board/
board/bachmann/ot1200/mx6q_4x_mt41j128.cfg:DATA 4 0x021b0020 0x00005800
board/ccv/xpress/imximage.cfg:DATA 4 0x021b0020 0x00000800 /* MMDC0_MDREF */
board/freescale/mx6qarm2/imximage.cfg:DATA 4 0x021b0020 0x7800
board/freescale/mx6qarm2/imximage.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qarm2/imximage_mx6dl.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qarm2/imximage_mx6dl.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qsabreauto/imximage.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qsabreauto/mx6dl.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6qsabreauto/mx6qp.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6sabresd/mx6dlsabresd.cfg:DATA 4      0x021b0020 0x00005800
board/freescale/mx6sabresd/mx6q_4x_mt41j128.cfg:DATA 4 0x021b0020 0x00005800
board/freescale/mx6slevk/imximage.cfg:DATA 4 0x021b0020 0x00001800
board/freescale/mx6sxsabreauto/imximage.cfg:DATA 4 0x021b0020 0x00000800
board/freescale/mx6sxsabresd/imximage.cfg:DATA 4 0x021b0020 0x00000800
board/warp/imximage.cfg:DATA 4 0x021b0020 0x00001800

So introduce a mechanism for users to configure REFSEL and REFR fields as needed.

---
Changes since v2:
- Do not make this mx6ul specific (Eric)

 arch/arm/cpu/armv7/mx6/ddr.c            | 15 ++++++++++++---
 arch/arm/include/asm/arch-mx6/mx6-ddr.h |  2 ++
 2 files changed, 14 insertions(+), 3 deletions(-)
arch/arm/cpu/armv7/mx6/ddr.c +1 -1
index f151eec..ebc7903 100644
@@ -1183,7 +1183,7 @@ void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo,
 	volatile struct mmdc_p_regs *mmdc0;
 	volatile struct mmdc_p_regs *mmdc1;
 	u32 val;
-	u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd;
+	u8 tcke, tcksrx, tcksre, txpdll, taofpd, taonpd, trrd, refsel, refr;
 	u8 todtlon, taxpd, tanpd, tcwl, txp, tfaw, tcl;
 	u8 todt_idle_off = 0x4; /* from DDR3 Script Aid spreadsheet */
 	u16 trcd, trc, tras, twr, tmrd, trtp, trp, twtr, trfc, txs, txpr;

arch/arm/cpu/armv7/mx6/ddr.c void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo, · line 1476

Quoted 5 lines
arch/arm/cpu/armv7/mx6/ddr.c +0 -2
@@ -1472,8 +1472,17 @@ void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo,
 		MMDC1(mpzqhwctrl, val);
 
 	/* Step 12: Configure and activate periodic refresh */
-	mmdc0->mdref = (1 << 14) | /* REF_SEL: Periodic refresh cycle: 32kHz */
-		       (7 << 11);  /* REFR: Refresh Rate - 8 refreshes */

Oops.

Your original patch (and what we want for the 6UL EVK) has a refsel of zero, right?

	http://lists.denx.de/pipermail/u-boot/2016-August/265128.html
Quoted 12 lines
arch/arm/cpu/armv7/mx6/ddr.c +11 -0
+	if (!sysinfo->refsel)
+		refsel = 1; /* REF_SEL: Periodic refresh cycle: 32kHz */
+	else
+		refsel = sysinfo->refsel;
+
+	if (!sysinfo->refr)
+		refr = 7; /* REFR: Refresh Rate - 8 refreshes */
+	else
+		refr = sysinfo->refr;
+
+	mmdc0->mdref = (refsel << 14) | (refr << 11);
 
#5 lore raw

PATCH v3 1/4 mx6: ddr: Allow changing REFSEL and REFR fields

Hi Eric,

Quoted 9 lines · Eric Nelson

arch/arm/cpu/armv7/mx6/ddr.c void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo, · line 1476

Quoted 3 lines
      /* Step 12: Configure and activate periodic refresh */
arch/arm/cpu/armv7/mx6/ddr.c +0 -2
-     mmdc0->mdref = (1 << 14) | /* REF_SEL: Periodic refresh cycle: 32kHz */
-                    (7 << 11);  /* REFR: Refresh Rate - 8 refreshes */

Oops.

Your original patch (and what we want for the 6UL EVK) has a refsel of zero, right?

        http://lists.denx.de/pipermail/u-boot/2016-August/265128.html

Yes, in this v3 series I change refsel to 0 in patch 2/4.

#6 lore raw

PATCH v3 1/4 mx6: ddr: Allow changing REFSEL and REFR fields

Quoted 8 lines · Fabio Estevam

Hi Eric,

Quoted 4 lines · Eric Nelson
Quoted 3 lines
      /* Step 12: Configure and activate periodic refresh */
arch/arm/cpu/armv7/mx6/ddr.c +0 -2
-     mmdc0->mdref = (1 << 14) | /* REF_SEL: Periodic refresh cycle: 32kHz */
-                    (7 << 11);  /* REFR: Refresh Rate - 8 refreshes */
Quoted 8 lines
Quoted 5 lines

Oops.

Your original patch (and what we want for the 6UL EVK) has a refsel of zero, right?

        http://lists.denx.de/pipermail/u-boot/2016-August/265128.html

Yes, in this v3 series I change refsel to 0 in patch 2/4.

Right, but this patch will change it back to a 1:

+ if (!sysinfo->refsel)
+ refsel = 1; /* REF_SEL: Periodic refresh cycle: 32kHz */
+ else
+ refsel = sysinfo->refsel;

#7 lore raw

PATCH v3 1/4 mx6: ddr: Allow changing REFSEL and REFR fields

arch/arm/cpu/armv7/mx6/ddr.c void mx6_ddr3_cfg(const struct mx6_ddr_sysinfo *sysinfo, · line 1478

Quoted 6 lines · Eric Nelson

Right, but this patch will change it back to a 1:

arch/arm/cpu/armv7/mx6/ddr.c +4 -0
+       if (!sysinfo->refsel)
+               refsel = 1; /* REF_SEL: Periodic refresh cycle: 32kHz */
+       else
+               refsel = sysinfo->refsel;

It only goes to 1 if refsel is not defined in the board file.

refsel = 1 is the current behavior and I need to keep it.

After patch 2/4, refsel will be 0 in imx6ul_evk.

#8 lore raw

PATCH v3 1/4 mx6: ddr: Allow changing REFSEL and REFR fields

In reply to Eric Nelson
Quoted 1 line · Eric Nelson

Right, but this patch will change it back to a 1:

Sorry, Eric. My mistake. Will send a v4.

Thanks