dmb();
}
-static bool mctl_phy_write_leveling(const struct dram_config *config)
+static bool mctl_phy_write_leveling(const struct dram_para *para,
+ const struct dram_config *config)
{
bool result = true;
u32 val;
clrsetbits_le32(SUNXI_DRAM_PHY0_BASE + 8, 0xc0, 0x80);
- writel(4, SUNXI_DRAM_PHY0_BASE + 0xc);
- writel(0x40, SUNXI_DRAM_PHY0_BASE + 0x10);
+
+ if (para->type == SUNXI_DRAM_TYPE_LPDDR4) {
+ /* MR2 value */
+ writel(0x1b, SUNXI_DRAM_PHY0_BASE + 0xc);
+ writel(0, SUNXI_DRAM_PHY0_BASE + 0x10);
+ } else {
+ writel(4, SUNXI_DRAM_PHY0_BASE + 0xc);
+ writel(0x40, SUNXI_DRAM_PHY0_BASE + 0x10);
+ }
setbits_le32(SUNXI_DRAM_PHY0_BASE + 8, 4);
}
break;
case SUNXI_DRAM_TYPE_LPDDR4:
- if (para->tpr2 & 1) {
- writel(val, SUNXI_DRAM_PHY0_BASE + 0x788);
- } else {
+ writel(val, SUNXI_DRAM_PHY0_BASE + 0x788);
+ if (config->ranks == 2) {
+ val = (para->tpr10 >> 11) & 0x1e;
writel(val, SUNXI_DRAM_PHY0_BASE + 0x794);
};
break;
mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
writel(0xb04, &mctl_ctl->mrctrl1);
+ udelay(10);
writel(0x80000030, &mctl_ctl->mrctrl0);
+ udelay(10);
mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
writel(0xc72, &mctl_ctl->mrctrl1);
+ udelay(10);
writel(0x80000030, &mctl_ctl->mrctrl0);
+ udelay(10);
mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
writel(0xe09, &mctl_ctl->mrctrl1);
+ udelay(10);
writel(0x80000030, &mctl_ctl->mrctrl0);
+ udelay(10);
mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
writel(0x1624, &mctl_ctl->mrctrl1);
+ udelay(10);
writel(0x80000030, &mctl_ctl->mrctrl0);
+ udelay(10);
mctl_await_completion(&mctl_ctl->mrctrl0, BIT(31), 0);
break;
case SUNXI_DRAM_TYPE_DDR4:
if (para->tpr10 & TPR10_WRITE_LEVELING) {
for (i = 0; i < 5; i++)
- if (mctl_phy_write_leveling(config))
+ if (mctl_phy_write_leveling(para, config))
break;
if (i == 5) {
debug("write leveling failed!\n");
setbits_le32(&mctl_ctl->unk_0x3180, BIT(31) | BIT(30));
setbits_le32(&mctl_ctl->unk_0x4180, BIT(31) | BIT(30));
- if (para->type == SUNXI_DRAM_TYPE_LPDDR4)
- setbits_le32(&mctl_ctl->dbictl, 0x1);
-
setbits_le32(&mctl_ctl->rfshctl3, BIT(0));
clrbits_le32(&mctl_ctl->dfimisc, BIT(0));