ram: rk3399: Fix LPDDR4 tRFCab for high-density devices
Subsystems (2)
cover ram: rk3399: Fix LPDDR4 tRFCab for high-density devices
From: Shigeaki Asai <[email protected]>
Resending, as the original posting was rejected by the mailing list (the sender's mail server was blocked by Spamhaus). No changes.
Some ROCK 4C+ boards fail to boot with mainline U-Boot. TPL completes, but SPL never starts:
U-Boot TPL 2027.01-rc1-00126-g3401e006432a
...
Channel 0: LPDDR4, 400MHz
BW=32 Col=10 Bk=8 CS0 Row=16 CS=1 Die BW=16 Size=2048MB Channel 1: LPDDR4, 400MHz
BW=32 Col=10 Bk=8 CS0 Row=16 CS=1 Die BW=16 Size=2048MB 256B stride
lpddr4_set_rate: change freq to 800MHz 1, 0 Trying to boot from BOOTROM
Returning to boot ROM...
[SPL does not start]
The cause is tRFCab in rk3399-sdram-lpddr4-100.dtsi, which is 180ns. JEDEC requires 280ns for 8Gb per channel devices, which this board uses.
This dtsi is shared by other RK3399 boards. Boards that boot today may still be out of spec: the ROCK 4SE boots with 180ns, but it reports MR8=0x10 (8Gb per channel), so it also needs 280ns.
Patch 1 sets the default tRFCab to 380ns, which is valid for all densities. This alone fixes the ROCK 4C+.
Patch 2 reads MR8 after DRAM init and selects the JEDEC value for the density, so smaller devices do not pay for the longer tRFCab.
Tested on main (2027.01-rc1):
- ROCK 4C+ (MT53E512M32D2NP): fails without the series, boots with patch 1 alone and with both patches.
- ROCK 4SE (MT53E512M32D4NQ): boots with and without the series.
I could not test devices of 4Gb per channel or less, where patch 2 selects 180ns. Testing on such boards would be appreciated.
Shigeaki Asai (2):
ram: rk3399: Use the maximum LPDDR4 tRFCab as the default
ram: rk3399: Select LPDDR4 tRFCab from MR8 density
arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi | 20 +++---- drivers/ram/rockchip/sdram_rk3399.c | 64 +++++++++++++++++++++++ 2 files changed, 74 insertions(+), 10 deletions(-)
Signature · 1 line
2.43.0
PATCH RESEND 1/2 ram: rk3399: Use the maximum LPDDR4 tRFCab as the default
From: Shigeaki Asai <[email protected]>
Some ROCK 4C+ boards fail to boot with mainline U-Boot (SPL does not start), depending on the DRAM fitted.
rk3399-sdram-lpddr4-100.dtsi sets tRFCab to 180ns regardless of the DRAM density. JEDEC defines the minimum tRFCab per density: 180ns is sufficient only for 4Gb per channel or less. 8Gb per channel requires 280ns, and 16Gb per channel requires 380ns.
Set the default to 380ns, the largest JEDEC value, so that all densities are within spec. This is longer than necessary for smaller devices; a follow-up patch selects the value from MR8.
Tested on ROCK 4C+ (MT53E512M32D2NP, 8Gb per channel), which boots with this patch alone.
This patch was written with the help of Claude (claude-opus-5-5).
--- arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
arch/arm/dts/rk3399-sdram-lpddr4-100.dtsi +10 -10
@@ -94,9 +94,9 @@ 0x00041109 0x00000000 0x03010000 - 0x06100048 - 0x0c280090 - 0x00bb0009 + 0x06100098 + 0x0c280130 + 0x00bb0013 0x00000000 0x00060005 0x000a0005
@@ -105,10 +105,10 @@ 0x030a0000 0x0c000002 0x00000103 - 0x0005030a - 0x00060037 - 0x0005006e - 0x05050007 + 0x009b030a + 0x0136009b + 0x00140136 + 0x05050014 0x03030605 0x06050301 0x06030c05
@@ -424,9 +424,9 @@ 0x080c0004 0x00061c00 0x00000214 - 0x00bb0009 - 0x0c280090 - 0x06100048 + 0x00bb0013 + 0x0c280130 + 0x06100098 0x00000500 0x00000000 0x00000000
Signature · 1 line
2.43.0
PATCH RESEND 2/2 ram: rk3399: Select LPDDR4 tRFCab from MR8 density
In reply to Shigeaki AsaiFrom: Shigeaki Asai <[email protected]>
The default LPDDR4 tRFCab is 380ns, which is valid for all densities but longer than necessary for smaller devices, and increases the time the DRAM is unavailable during refresh.
Once the DRAM is initialized, read the density from MR8 for each channel and reprogram tRFCab with the JEDEC value for that density, together with tXSR and tXSNR (tRFCab + 7.5ns). This is done for all three frequency sets in both the CTL and the PI, before switching to the final frequency.
Tested on ROCK 4C+ (MT53E512M32D2NP) and ROCK 4SE (MT53E512M32D4NQ). Both report MR8=0x10 and use 280ns.
This patch was written with the help of Claude (claude-opus-5-5).
--- drivers/ram/rockchip/sdram_rk3399.c | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+)
drivers/ram/rockchip/sdram_rk3399.c +64 -0
@@ -2565,6 +2565,37 @@ static int lpddr4_set_rate(struct dram_info *dram, return 0; } + +/* +* tRFCab (JEDEC LPDDR4) by density per channel, indexed by MR8 OP[5:2]: +* 2Gb, 3Gb, 4Gb, 6Gb, 8Gb, 12Gb, 16Gb per channel. +*/ +static const u16 lpddr4_trfc_ns[] = {130 ,180 ,180 ,280 ,280 ,380 ,380 }; + +/* +* Program tRFCab and tXSR/tXSNR (tRFCab + 7.5ns) for the three frequency +* sets. mhz[] holds the rate of CTL F0, F1 and F2; the PI uses the +* reverse order for F0 and F2. +*/ +static void lpddr4_set_trfc (u32 *denali_ctl,u32 *denali_pi,u32 trfc_ns, +const u32 mhz[3 ]) +{ +u32 f, trfc, txsr; + +for (f =0 ; f <3 ; f++) { + trfc =DIV_ROUND_UP (trfc_ns * mhz[f],1000 ); + txsr =DIV_ROUND_UP ((trfc_ns *2 +15 ) * mhz[f],2000 ); + +/* CTL TRFC_Fx [9:0] */ +clrsetbits_le32 (&denali_ctl[48 + f],0x3ff , trfc); +/* CTL TXSR_Fx [31:16] */ +clrsetbits_le32 (&denali_ctl[59 + f],0xffff <<16 , txsr <<16 ); +/* CTL TXSNR_Fx [15:0] */ +clrsetbits_le32 (&denali_ctl[60 + f],0xffff , txsr); +/* PI_TRFC_Fx [9:0] */ +clrsetbits_le32 (&denali_pi[46 +2 - f],0x3ff , trfc); + } +}#endif /* CONFIG_RAM_ROCKCHIP_LPDDR4 */ /* CS0,n=1
@@ -2964,6 +2995,39 @@ static int sdram_init(struct dram_info *dram, }#if defined(CONFIG_RAM_ROCKCHIP_LPDDR4 ) +/* +* The parameters start with the longest tRFCab (380ns). Now that the +* devices are initialised, read the density from MR8 and use the +* tRFCab it requires. +*/ +if (dramtype ==LPDDR4 ) { +const u32 mhz[3 ] = { + dfs_cfgs_lpddr4[0 ].base.ddr_freq / MHz, + dfs_cfgs_lpddr4[1 ].base.ddr_freq / MHz, + ddr_freq, + }; + +for (channel =0 ; channel <2 ; channel++) { +const struct chan_info *chan = &dram->chan[channel]; +u32 mr8 =0 , density; + +if (!params->ch[channel].cap_info.rank) +continue ; + +read_mr (chan->pctl,1 ,8 , &mr8); + density = (mr8 >>2 ) &0xf ; +if (density >=ARRAY_SIZE (lpddr4_trfc_ns)) +continue ; + +lpddr4_set_trfc (chan->pctl->denali_ctl, + chan->pi->denali_pi, + lpddr4_trfc_ns[density], mhz); +if (IS_ENABLED (CONFIG_RAM_ROCKCHIP_DEBUG )) +printf ("%s: ch%d MR8=0x%02x tRFCab %uns\n" , __func__, + channel, mr8, lpddr4_trfc_ns[density]); + } + } +/* LPDDR4 needs to be trained at 400MHz */ lpddr4_set_rate (dram, params,0 ); params->base.ddr_freq = dfs_cfgs_lpddr4[0 ].base.ddr_freq / MHz;
Signature · 1 line
2.43.0