sunxi: a133: dram: fix DDR4 MR0 to match the controller timings

Message ID 20261112021945.71942-1-me@edm.sh (mailing list archive)
State New
Headers
Series sunxi: a133: dram: fix DDR4 MR0 to match the controller timings |

Commit Message

Eduardo Moreno Adanez Nov. 12, 2026, 2:19 a.m. UTC
MR0 is set to 0x840 (CL 18, WR 18), but the DRAMTMG values in
a133_ddr4.c are for CL 13, CWL 10, WR 14:

  DRAMTMG0.wr2pre        = 14 = (10 + 4 + 14) / 2
  DRAMTMG2.read_latency  =  7 = 13 / 2, rounded up
  DRAMTMG2.write_latency =  5 = 10 / 2

Use 0x520 (CL 13, WR 14, DLL reset), as boot0 does with the same
timings.

Write-then-read tests pass with the wrong value, but copies corrupt
about 300 64-bit words per MiB, so U-Boot hangs in memcpy() and TF-A
takes undefined instruction exceptions.

Tested on an Aqara Panel Hub S1 Plus (A133, 2 GiB DDR4 at 792 MHz):
without this patch U-Boot hangs before fastboot; with it, 16 MiB
copied 12 times with cp.q all match.

Fixes: 7a337270c076 ("sunxi: A133: add DRAM init code")
Signed-off-by: Eduardo Moreno Adanez <me@edm.sh>
---
boot0 also differs in MSTR geardown, INIT7 (MR6), DRAMTMG6, ADDRMAP1/8
and SCHED. Changing those without this patch still hangs, and with it
they make no difference here, so they are left out.

 arch/arm/mach-sunxi/dram_sun50i_a133.c       | 2 +-
 arch/arm/mach-sunxi/dram_timings/a133_ddr4.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)


base-commit: 8c1ea2aa66386fa3c8ea829531f581847814a569
  

Patch

diff --git a/arch/arm/mach-sunxi/dram_sun50i_a133.c b/arch/arm/mach-sunxi/dram_sun50i_a133.c
index ca3e2513c69..b5ff6707571 100644
--- a/arch/arm/mach-sunxi/dram_sun50i_a133.c
+++ b/arch/arm/mach-sunxi/dram_sun50i_a133.c
@@ -754,7 +754,7 @@  static void mctl_dfi_init(const struct dram_para *para)
 		mctl_mr_write(MRCTRL0_MR_ADDR(3), 0);		/* MR3 */
 		break;
 	case SUNXI_DRAM_TYPE_DDR4:
-		mctl_mr_write(MRCTRL0_MR_ADDR(0), 0x840);
+		mctl_mr_write(MRCTRL0_MR_ADDR(0), 0x520);	/* CL 13, WR 14 */
 		mctl_mr_write(MRCTRL0_MR_ADDR(1), 0x601);
 		mctl_mr_write(MRCTRL0_MR_ADDR(2), 0x8);
 		mctl_mr_write(MRCTRL0_MR_ADDR(3), 0);
diff --git a/arch/arm/mach-sunxi/dram_timings/a133_ddr4.c b/arch/arm/mach-sunxi/dram_timings/a133_ddr4.c
index dec208e22df..359b11aa42d 100644
--- a/arch/arm/mach-sunxi/dram_timings/a133_ddr4.c
+++ b/arch/arm/mach-sunxi/dram_timings/a133_ddr4.c
@@ -67,7 +67,7 @@  void mctl_set_timing_params(const struct dram_para *para)
 	clrsetbits_le32(&mctl_ctl->init[2], 0xff0f, 0xd05);
 	writel(0, &mctl_ctl->dfimisc);
 
-	writel(0x840 << 16 | 0x601, &mctl_ctl->init[3]);	/* MR0 / MR1 */
+	writel(0x520 << 16 | 0x601, &mctl_ctl->init[3]);	/* MR0 / MR1 */
 	writel(0x8 << 16 | 0x0, &mctl_ctl->init[4]);		/* MR2 / MR3 */
 	writel(0x0 << 16 | 0x400, &mctl_ctl->init[6]);		/* MR4 / MR5 */
 	writel(0x826, &mctl_ctl->init[7]);			/* MR6 */