| ← Previous: The PI Training Engine | Index | Next: Write Leveling → |
A training pass centres the data eye for one frequency point that is
already running (boot_pp). The boot runs several passes, one per frequency
point (and fp0 twice); the orchestration is in
boot-sequence.md.
After Device_Init the bus works but the eye is not centred:
At 2400/2666 MT/s the eye is closed without this. Device_Init does not do it.
| Input | Values | Role |
|---|---|---|
ddr |
MC base | 0xc0000000 |
cs_num |
1 or 2 | Ranks actually populated |
boot_pp |
0..3 | The frequency point / PHY slice already active |
| log | optional | Text output in SRAM; may be absent |
The pass must not depend on a caller buffer and must not read the
0xc0800000 block.
For the frequency point boot_pp:
byte + 0x24);byte + 0x70);CTL_TXVREF[21:16];PHY_STATUS (phy+0x18000).Each slice keeps the taps of its rate. Training only the final rate leaves
the other frequency points with reset delays (0xf).
CTL_FREQ or PI_CFG.Before entering SR and triggering the PI:
dclk stable at the rate of boot_pp (SW-FC for the first fp0 pass,
HW-DFC for the others).CTL_FREQ[31:30] = boot_pp and [29:28] = sel (equal in the normal boot).PI_CFG[3:2] = boot_pp (set by init/DFC, never by the pass).phy + (boot_pp << 14) is the active one.cs_num equals the number of real ranks.If any of these fails, triggering the PI is pointless. The PI does not choose
the frequency. cs_num = 1 on a two-rank package leaves CS1 with reset delays.
enter SR (both ranks)
PHY_INIT = 512
[CA training only if a product requires it — the LPDDR4X boot does not]
write_leveling per rank
read_gate per rank; a timeout fails the boot
read_training sweep PHY Rx Vref 0..15; max-min; re-apply winner
write_training sweep MR14 21..36; max-min; re-apply winner
st = PHY_STATUS
exit SR
return st
| Rule | Reason |
|---|---|
| SR first | Without SR a CPU access can collide with the PI. |
PHY_INIT = 512 next |
Arms the training FSM for this pass. |
| WL before the gate | The gate measures DQS relative to a DQS already aligned with CK. |
| Gate before read training | Without a gate, read training gets margin 0 or times out. |
| Read before write | Rx Vref (PHY) and Tx Vref (die) are independent, but the PI’s CFG/STATUS leftovers on this SoC expect this order. |
| Re-apply the winning Vref while still in SR | The last sweep step would otherwise leave the wrong taps in the PHY. |
| Exit SR at the end | The boot needs the DRAM for MR reads, the DFC and the next pass. |
ddr_init
between passes).PHY_STATUS (phy+0x18000):
| Bit | Meaning |
|---|---|
| 1 | Write leveling failed |
| 2 | Read leveling failed |
| 3 | Write DQ failed |
| 4 | Read gate failed |
PHY_STATUS != 0 at the end of the pass, or if the
gate times out. Continuing with a bad DRAM is worse than stopping.PI_STATUS = 0x80008067 at the end is not an error: those are sticky done
bits plus the idle bits 15/31.0x33 after the exit; STATUS 0x77 at the end
means the pass is still in SR (self-refresh.md).Things not to do:
PI_CMD (it reads 0);PI_STATUS to equal an absolute value;0xc0058xxx;Code, stack and scratch are in SRAM. The minimum scratch is 16 minimum values for the current sweep and 32 margins per rank for the current step: the whole sweep need not be stored if the minimum is updated on the fly and the re-kick uses the winning step. Zero the scratch at the start of the pass.
Rather than prescribing a specific code structure, the table below summarises
the exact hardware state transitions and MMIO operations required for one pass
at boot_pp (slice = phy + (boot_pp << 14)). Detailed rules for each stage
are in self-refresh.md, write-leveling.md,
read-gate.md, and eye-training.md.
| Step | Stage | MMIO writes & operations | Completion / result |
|---|---|---|---|
| 1 | Enter SR & arm FSM | Enter self-refresh on populated ranks (self-refresh.md); write phy + 0x10028 = 0x200 (PHY_INIT = 512). |
ddr+0x08 SR bits set (0x44 for 2 ranks, 0x04 for 1 rank); phy+0x10028 == 0x200. |
| 2 | Write leveling | Write ddr + 0x13e8 = 0x0a641e44 (PI_WL_CFG). For each rank cs = 1..cs_num, write ddr + 0x13d0 = 0x10400000 \| (cs << 24). |
Poll (ddr + 0x13fc & 0x1) == 0x1 per rank. Trained WL delays in byte_base + 0x24. |
| 3 | DQS read gate | For each rank cs = 1..cs_num, write ddr + 0x13d0 = 0x10100000 \| (cs << 24). |
Poll (ddr + 0x13fc & 0x2) == 0x2 and check gate timeout (read-gate.md). Gate code in byte_base + 0x70, applied delay in slice + 0x64[4:0]. |
| 4 | Read eye sweep (RX Vref) | Clear bit 4 of VREF0 (slice + 0x3004 &= ~0x10); write ddr + 0x13ec = 0x00005070 (PI_RD_CFG). Sweep step = 0..15: set [31:16] of VREF0 (slice + 0x3004) and VREF1 (slice + 0x3204) to (step << 28) \| (step << 24) \| (step << 20) \| (step << 16) (preserving [15:0]), trigger ddr + 0x13d0 = 0x10200000 \| (cs << 24) for each cs = 1..cs_num, wait for (PI_STATUS & 0x6) == 0x6, and immediately read the 32 DQ margins (8 words) from phy + 0x18200 to record the minimum margin across all DQs and ranks for step. |
Clear transient read-leveling error bit 2 (phy + 0x18000 &= ~0x4), select the step with the largest minimum margin, write that winning step to VREF0 and VREF1, re-run 0x10200000 \| (cs << 24) for all ranks so the PHY latches the winning RX DQ/DM taps (byte_base + 0x30..0x50), and restore VREF0 \|= 0x10. |
| 5 | Write eye sweep (TX MR14) | Write ddr + 0x13f8 = 0x00001810 (PI_WR_CFG). Sweep 16 candidate MR14 values vdq (e.g. 21..36 on LPDDR4X): update ddr + 0x30c[21:16] = vdq, issue MRW MR14 (ddr + 0x24 = 0x1302000e for 2 ranks or 0x1102000e for 1 rank), trigger ddr + 0x13d0 = 0x10080000 \| (cs << 24) for each cs = 1..cs_num, wait for (PI_STATUS & 0x60) == 0x60, and immediately read the 32 DQ margins (8 words) from phy + 0x18300 to record the minimum margin across all DQs and ranks for vdq. |
Select the vdq with the largest minimum margin, write it to ddr + 0x30c[21:16], issue MRW MR14 (ddr + 0x24), and re-run 0x10080000 \| (cs << 24) for all ranks so the PHY latches the winning TX DQ/DM taps (byte_base + 0x00..0x20). |
| 6 | Status check & exit SR | Read st = readl(phy + 0x18000) (PHY_STATUS), exit self-refresh (self-refresh.md), and return st. |
st == 0 indicates success; any nonzero value must abort the boot. |
After the pass, outside SR: optionally read MR14 on every (rank, channel) and
check it equals CTL_TXVREF[21:16] (after a dummy MRR if a DFC happened since
the last read).
| ← Previous: The PI Training Engine | Index | Next: Write Leveling → |