ARM Sunxi Platform Development
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: "Jernej Škrabec" <jernej.skrabec@gmail.com>
Cc: u-boot@lists.denx.de, Tom Rini <trini@konsulko.com>,
	Cody Eksal <masterr3c0rd@epochal.quest>,
	Chris Morgan <macromorgan@hotmail.com>,
	linux-sunxi@lists.linux.dev
Subject: Re: [PATCH 3/3] sunxi: H616: dram: fix LPDDR3 mode register settings
Date: Mon, 11 Aug 2025 17:08:16 +0100	[thread overview]
Message-ID: <20250811170816.60e57b14@donnerap.manchester.arm.com> (raw)
In-Reply-To: <7836068.EvYhyI6sBW@jernej-laptop>

On Mon, 11 Aug 2025 17:49:06 +0200
Jernej Škrabec <jernej.skrabec@gmail.com> wrote:

Hi Jernej,

many thanks for having a look!

> Dne sobota, 2. avgust 2025 ob 01:49:18 Srednjeevropski poletni čas je Andre Przywara napisal(a):
> > The JEDEC LPDDR3 spec defines mode register 0 (MR0) as being read-only,
> > so there is no point in trying to set its value.
> > Also the H616 memory controller encodes the mode register index to be
> > written starting from bit 8 in MRCTRL1 (for LPDDR3 and LPDDR4 chips), so
> > we need to OR in that number to tell the controller which MR to program.
> > 
> > On top of that, the mode registers between DDR3 and LPDDR3 are
> > completely different, so writing values crafted for DDR3 into a LPDDR3
> > chip is just wrong. Due to the above mentioned bugs the writes for
> > MR0-MR2 did not have any effect (as they were all trying to set the
> > read-only MR0), so the mode registers just stayed unchanged.  
> 
> Nice catch! Looking at BSP DRAM code, it only sets MR1, MR2 and MR3.
> 
> > 
> > Looking at the LPDDR3 spec and the BSP code, let's write the proper MR
> > values into LPDDR3 chips, using the proper addressing mode.  
> 
> Please explain how you find those values. Are they always set in this way
> for all boards using LPDDR3?

Yeah, that's a good question! At first, I tried using what JEDEC describes
as the default settings, but that didn't work. Then I looked into some
parameters found in some BSP image dumps, but that didn't work either.
JEDEC describes those MRs as write-only, and I haven't tried whether
reading them would work nevertheless, not sure about the exact algorithm
for reading MRs anyway.
What eventually worked was to use the BSP values written by exactly the
boot0 on the eMMC that boots an LPDDR3 system - which is actually only one
in mainline: the Tanix TX1.

So yeah, those values work for me (TM), and there is only one LPDDR3 board
supported, so fingers crossed. But actually I wonder if those MR values
really belong into the timing routine (mctl_set_timing_params(), since
parts depend on the speed bin. I see some other SoC/DRAM type combinations
doing that already (H6 DDR3/LPDDR3 and A523 LPDDR4), maybe we should
follow suit here?

Cheers,
Andre


> 
> Best regards,
> Jernej
> 
> > Use the opportunity to document the LPDDR3 mode register bits written.
> > 
> > Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> > ---
> >  arch/arm/mach-sunxi/dram_sun50i_h616.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/arch/arm/mach-sunxi/dram_sun50i_h616.c b/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > index 877181016f3..3345c9b8e82 100644
> > --- a/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > +++ b/arch/arm/mach-sunxi/dram_sun50i_h616.c
> > @@ -1078,18 +1078,18 @@ static bool mctl_phy_init(const struct dram_para *para,
> >  		mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
> >  		break;
> >  	case SUNXI_DRAM_TYPE_LPDDR3:
> > -		writel(mr0, &mctl_ctl->mrctrl1);
> > -		writel(0x800000f0, &mctl_ctl->mrctrl0);
> > -		mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
> > -
> > -		writel(4, &mctl_ctl->mrctrl1);
> > +		/* MR0 is read-only */
> > +		/* MR1: nWR=14, BL8 */
> > +		writel(0x183, &mctl_ctl->mrctrl1);
> >  		writel(0x800000f0, &mctl_ctl->mrctrl0);
> >  		mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
> >  
> > -		writel(mr2, &mctl_ctl->mrctrl1);
> > +		/* MR2: no WR leveling, WL set A, use nWR>9, nRL=14/nWL=8 */
> > +		writel(0x21c, &mctl_ctl->mrctrl1);
> >  		writel(0x800000f0, &mctl_ctl->mrctrl0);
> >  		mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
> >  
> > +		/* MR3: 34.3 Ohm pull-up/pull-down resistor */
> >  		writel(0x301, &mctl_ctl->mrctrl1);
> >  		writel(0x800000f0, &mctl_ctl->mrctrl0);
> >  		mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
> >   
> 
> 
> 
> 


  reply	other threads:[~2025-08-11 16:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-01 23:49 [PATCH 0/3] sunxi: assorted fixes to DRAM and clock init Andre Przywara
2025-08-01 23:49 ` [PATCH 1/3] sunxi: a133: dram: fix data type for address variable Andre Przywara
2025-08-11 15:36   ` Jernej Škrabec
2025-08-01 23:49 ` [PATCH 2/3] sunxi: spl: initialise timer before clocks Andre Przywara
2025-08-11 15:34   ` Jernej Škrabec
2025-08-11 15:52     ` Andre Przywara
2025-08-11 16:31       ` Jernej Škrabec
2025-08-11 23:01       ` Andre Przywara
2025-08-12  4:14   ` Jernej Škrabec
2025-08-01 23:49 ` [PATCH 3/3] sunxi: H616: dram: fix LPDDR3 mode register settings Andre Przywara
2025-08-11 15:49   ` Jernej Škrabec
2025-08-11 16:08     ` Andre Przywara [this message]
2025-08-11 16:28       ` Jernej Škrabec

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=20250811170816.60e57b14@donnerap.manchester.arm.com \
    --to=andre.przywara@arm.com \
    --cc=jernej.skrabec@gmail.com \
    --cc=linux-sunxi@lists.linux.dev \
    --cc=macromorgan@hotmail.com \
    --cc=masterr3c0rd@epochal.quest \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.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