2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2016-08-26 10:30:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic driver for Freescale MMDC(Multi Mode DDR Controller).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <fsl_mmdc.h>
|
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2016-08-26 10:30:39 +00:00
|
|
|
|
|
|
|
static void set_wait_for_bits_clear(void *ptr, u32 value, u32 bits)
|
|
|
|
{
|
|
|
|
int timeout = 1000;
|
|
|
|
|
|
|
|
out_be32(ptr, value);
|
|
|
|
|
|
|
|
while (in_be32(ptr) & bits) {
|
|
|
|
udelay(100);
|
|
|
|
timeout--;
|
|
|
|
}
|
|
|
|
if (timeout <= 0)
|
|
|
|
printf("Error: %p wait for clear timeout.\n", ptr);
|
|
|
|
}
|
|
|
|
|
2016-09-26 15:09:25 +00:00
|
|
|
void mmdc_init(const struct fsl_mmdc_info *priv)
|
2016-08-26 10:30:39 +00:00
|
|
|
{
|
|
|
|
struct mmdc_regs *mmdc = (struct mmdc_regs *)CONFIG_SYS_FSL_DDR_ADDR;
|
|
|
|
unsigned int tmp;
|
|
|
|
|
|
|
|
/* 1. set configuration request */
|
|
|
|
out_be32(&mmdc->mdscr, MDSCR_ENABLE_CON_REQ);
|
|
|
|
|
|
|
|
/* 2. configure the desired timing parameters */
|
2016-09-26 15:09:25 +00:00
|
|
|
out_be32(&mmdc->mdotc, priv->mdotc);
|
|
|
|
out_be32(&mmdc->mdcfg0, priv->mdcfg0);
|
|
|
|
out_be32(&mmdc->mdcfg1, priv->mdcfg1);
|
|
|
|
out_be32(&mmdc->mdcfg2, priv->mdcfg2);
|
2016-08-26 10:30:39 +00:00
|
|
|
|
|
|
|
/* 3. configure DDR type and other miscellaneous parameters */
|
2016-09-26 15:09:25 +00:00
|
|
|
out_be32(&mmdc->mdmisc, priv->mdmisc);
|
2016-08-26 10:30:39 +00:00
|
|
|
out_be32(&mmdc->mpmur0, MMDC_MPMUR0_FRC_MSR);
|
2016-09-26 15:09:25 +00:00
|
|
|
out_be32(&mmdc->mdrwd, priv->mdrwd);
|
|
|
|
out_be32(&mmdc->mpodtctrl, priv->mpodtctrl);
|
2016-08-26 10:30:39 +00:00
|
|
|
|
|
|
|
/* 4. configure the required delay while leaving reset */
|
2016-09-26 15:09:25 +00:00
|
|
|
out_be32(&mmdc->mdor, priv->mdor);
|
2016-08-26 10:30:39 +00:00
|
|
|
|
|
|
|
/* 5. configure DDR physical parameters */
|
|
|
|
/* set row/column address width, burst length, data bus width */
|
2016-09-26 15:09:25 +00:00
|
|
|
tmp = priv->mdctl & ~(MDCTL_SDE0 | MDCTL_SDE1);
|
2016-08-26 10:30:39 +00:00
|
|
|
out_be32(&mmdc->mdctl, tmp);
|
|
|
|
/* configure address space partition */
|
2016-09-26 15:09:25 +00:00
|
|
|
out_be32(&mmdc->mdasp, priv->mdasp);
|
2016-08-26 10:30:39 +00:00
|
|
|
|
|
|
|
/* 6. perform a ZQ calibration - not needed here, doing in #8b */
|
|
|
|
|
|
|
|
/* 7. enable MMDC with the desired chip select */
|
|
|
|
#if (CONFIG_CHIP_SELECTS_PER_CTRL == 1)
|
|
|
|
out_be32(&mmdc->mdctl, tmp | MDCTL_SDE0);
|
|
|
|
#elif (CONFIG_CHIP_SELECTS_PER_CTRL == 2)
|
|
|
|
out_be32(&mmdc->mdctl, tmp | MDCTL_SDE0 | MDCTL_SDE1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 8a. dram init sequence: update MRs for ZQ, ODT, PRE, etc */
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(8) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_2);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(0) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_3);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_1);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_MSB_MR_OP(0x19) |
|
|
|
|
CMD_ADDR_LSB_MR_ADDR(0x30) |
|
|
|
|
MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_0);
|
|
|
|
|
|
|
|
/* 8b. ZQ calibration */
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_MSB_MR_OP(0x4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_ZQ_CALIBRATION | CMD_BANK_ADDR_0);
|
|
|
|
|
2016-09-26 15:09:25 +00:00
|
|
|
set_wait_for_bits_clear(&mmdc->mpzqhwctrl, priv->mpzqhwctrl,
|
2016-08-26 10:30:39 +00:00
|
|
|
MPZQHWCTRL_ZQ_HW_FORCE);
|
|
|
|
|
|
|
|
/* 9a. calibrations now, wr lvl */
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(0x84) |
|
|
|
|
MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_1);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, MDSCR_ENABLE_CON_REQ | MDSCR_WL_EN |
|
|
|
|
CMD_NORMAL);
|
|
|
|
|
|
|
|
set_wait_for_bits_clear(&mmdc->mpwlgcr, MPWLGCR_HW_WL_EN,
|
|
|
|
MPWLGCR_HW_WL_EN);
|
|
|
|
|
|
|
|
mdelay(1);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_1);
|
|
|
|
out_be32(&mmdc->mdscr, MDSCR_ENABLE_CON_REQ);
|
|
|
|
|
|
|
|
mdelay(1);
|
|
|
|
|
|
|
|
/* 9b. read DQS gating calibration */
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_MSB_MR_OP(4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_PRECHARGE_BANK_OPEN | CMD_BANK_ADDR_0);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_3);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mppdcmpr2, MPPDCMPR2_MPR_COMPARE_EN);
|
|
|
|
|
|
|
|
/* set absolute read delay offset */
|
2016-09-26 15:09:25 +00:00
|
|
|
if (priv->mprddlctl)
|
|
|
|
out_be32(&mmdc->mprddlctl, priv->mprddlctl);
|
|
|
|
else
|
|
|
|
out_be32(&mmdc->mprddlctl, MMDC_MPRDDLCTL_DEFAULT_DELAY);
|
|
|
|
|
2016-08-26 10:30:39 +00:00
|
|
|
set_wait_for_bits_clear(&mmdc->mpdgctrl0,
|
|
|
|
AUTO_RD_DQS_GATING_CALIBRATION_EN,
|
|
|
|
AUTO_RD_DQS_GATING_CALIBRATION_EN);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, MDSCR_ENABLE_CON_REQ | CMD_LOAD_MODE_REG |
|
|
|
|
CMD_BANK_ADDR_3);
|
|
|
|
|
|
|
|
/* 9c. read calibration */
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_MSB_MR_OP(4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_PRECHARGE_BANK_OPEN | CMD_BANK_ADDR_0);
|
|
|
|
out_be32(&mmdc->mdscr, CMD_ADDR_LSB_MR_ADDR(4) | MDSCR_ENABLE_CON_REQ |
|
|
|
|
CMD_LOAD_MODE_REG | CMD_BANK_ADDR_3);
|
|
|
|
out_be32(&mmdc->mppdcmpr2, MPPDCMPR2_MPR_COMPARE_EN);
|
|
|
|
set_wait_for_bits_clear(&mmdc->mprddlhwctl,
|
|
|
|
MPRDDLHWCTL_AUTO_RD_CALIBRATION_EN,
|
|
|
|
MPRDDLHWCTL_AUTO_RD_CALIBRATION_EN);
|
|
|
|
|
|
|
|
out_be32(&mmdc->mdscr, MDSCR_ENABLE_CON_REQ | CMD_LOAD_MODE_REG |
|
|
|
|
CMD_BANK_ADDR_3);
|
|
|
|
|
|
|
|
/* 10. configure power-down, self-refresh entry, exit parameters */
|
2016-09-26 15:09:25 +00:00
|
|
|
out_be32(&mmdc->mdpdc, priv->mdpdc);
|
2016-08-26 10:30:39 +00:00
|
|
|
out_be32(&mmdc->mapsr, MMDC_MAPSR_PWR_SAV_CTRL_STAT);
|
|
|
|
|
|
|
|
/* 11. ZQ config again? do nothing here */
|
|
|
|
|
|
|
|
/* 12. refresh scheme */
|
2016-09-26 15:09:25 +00:00
|
|
|
set_wait_for_bits_clear(&mmdc->mdref, priv->mdref,
|
2016-08-26 10:30:39 +00:00
|
|
|
MDREF_START_REFRESH);
|
|
|
|
|
|
|
|
/* 13. disable CON_REQ */
|
|
|
|
out_be32(&mmdc->mdscr, MDSCR_DISABLE_CFG_REQ);
|
|
|
|
}
|