2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-08-26 20:01:29 +00:00
|
|
|
/*
|
2018-01-29 17:44:35 +00:00
|
|
|
* Copyright 2008-2016 Freescale Semiconductor, Inc.
|
2020-06-02 07:14:02 +00:00
|
|
|
* Copyright 2017-2020 NXP Semiconductor
|
2008-08-26 20:01:29 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-11-21 03:36:48 +00:00
|
|
|
* Generic driver for Freescale DDR/DDR2/DDR3/DDR4 memory controller.
|
2008-08-26 20:01:29 +00:00
|
|
|
* Based on code from spd_sdram.c
|
|
|
|
* Author: James Yang [at freescale.com]
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2013-09-30 16:22:09 +00:00
|
|
|
#include <fsl_ddr_sdram.h>
|
2016-11-21 03:36:48 +00:00
|
|
|
#include <fsl_errata.h>
|
2013-09-30 16:22:09 +00:00
|
|
|
#include <fsl_ddr.h>
|
2013-11-18 18:29:32 +00:00
|
|
|
#include <fsl_immap.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <asm/bitops.h>
|
2013-09-30 16:22:09 +00:00
|
|
|
#include <asm/io.h>
|
2017-05-17 14:23:10 +00:00
|
|
|
#if defined(CONFIG_FSL_LSCH2) || defined(CONFIG_FSL_LSCH3) || \
|
|
|
|
defined(CONFIG_ARM)
|
2017-05-17 14:23:06 +00:00
|
|
|
#include <asm/arch/clock.h>
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Determine Rtt value.
|
|
|
|
*
|
|
|
|
* This should likely be either board or controller specific.
|
|
|
|
*
|
2009-03-14 04:48:30 +00:00
|
|
|
* Rtt(nominal) - DDR2:
|
2008-08-26 20:01:29 +00:00
|
|
|
* 0 = Rtt disabled
|
|
|
|
* 1 = 75 ohm
|
|
|
|
* 2 = 150 ohm
|
|
|
|
* 3 = 50 ohm
|
2009-03-14 04:48:30 +00:00
|
|
|
* Rtt(nominal) - DDR3:
|
|
|
|
* 0 = Rtt disabled
|
|
|
|
* 1 = 60 ohm
|
|
|
|
* 2 = 120 ohm
|
|
|
|
* 3 = 40 ohm
|
|
|
|
* 4 = 20 ohm
|
|
|
|
* 5 = 30 ohm
|
2008-08-26 20:01:29 +00:00
|
|
|
*
|
|
|
|
* FIXME: Apparently 8641 needs a value of 2
|
|
|
|
* FIXME: Old code seys if 667 MHz or higher, use 3 on 8572
|
|
|
|
*
|
|
|
|
* FIXME: There was some effort down this line earlier:
|
|
|
|
*
|
|
|
|
* unsigned int i;
|
|
|
|
* for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL/2; i++) {
|
|
|
|
* if (popts->dimmslot[i].num_valid_cs
|
|
|
|
* && (popts->cs_local_opts[2*i].odt_rd_cfg
|
|
|
|
* || popts->cs_local_opts[2*i].odt_wr_cfg)) {
|
|
|
|
* rtt = 2;
|
|
|
|
* break;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
static inline int fsl_ddr_get_rtt(void)
|
|
|
|
{
|
|
|
|
int rtt;
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR1)
|
2008-08-26 20:01:29 +00:00
|
|
|
rtt = 0;
|
2013-09-30 16:22:09 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR2)
|
2008-08-26 20:01:29 +00:00
|
|
|
rtt = 3;
|
|
|
|
#else
|
2009-03-14 04:48:30 +00:00
|
|
|
rtt = 0;
|
2008-08-26 20:01:29 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return rtt;
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
/*
|
|
|
|
* compute CAS write latency according to DDR4 spec
|
|
|
|
* CWL = 9 for <= 1600MT/s
|
|
|
|
* 10 for <= 1866MT/s
|
|
|
|
* 11 for <= 2133MT/s
|
|
|
|
* 12 for <= 2400MT/s
|
|
|
|
* 14 for <= 2667MT/s
|
|
|
|
* 16 for <= 2933MT/s
|
|
|
|
* 18 for higher
|
|
|
|
*/
|
2015-01-06 21:18:50 +00:00
|
|
|
static inline unsigned int compute_cas_write_latency(
|
|
|
|
const unsigned int ctrl_num)
|
2014-03-28 00:54:47 +00:00
|
|
|
{
|
|
|
|
unsigned int cwl;
|
2015-01-06 21:18:50 +00:00
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
|
2014-03-28 00:54:47 +00:00
|
|
|
if (mclk_ps >= 1250)
|
|
|
|
cwl = 9;
|
|
|
|
else if (mclk_ps >= 1070)
|
|
|
|
cwl = 10;
|
|
|
|
else if (mclk_ps >= 935)
|
|
|
|
cwl = 11;
|
|
|
|
else if (mclk_ps >= 833)
|
|
|
|
cwl = 12;
|
|
|
|
else if (mclk_ps >= 750)
|
|
|
|
cwl = 14;
|
|
|
|
else if (mclk_ps >= 681)
|
|
|
|
cwl = 16;
|
|
|
|
else
|
|
|
|
cwl = 18;
|
|
|
|
|
|
|
|
return cwl;
|
|
|
|
}
|
|
|
|
#else
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* compute the CAS write latency according to DDR3 spec
|
|
|
|
* CWL = 5 if tCK >= 2.5ns
|
|
|
|
* 6 if 2.5ns > tCK >= 1.875ns
|
|
|
|
* 7 if 1.875ns > tCK >= 1.5ns
|
|
|
|
* 8 if 1.5ns > tCK >= 1.25ns
|
2011-08-24 16:40:25 +00:00
|
|
|
* 9 if 1.25ns > tCK >= 1.07ns
|
|
|
|
* 10 if 1.07ns > tCK >= 0.935ns
|
|
|
|
* 11 if 0.935ns > tCK >= 0.833ns
|
|
|
|
* 12 if 0.833ns > tCK >= 0.75ns
|
2009-03-14 04:48:30 +00:00
|
|
|
*/
|
2015-01-06 21:18:50 +00:00
|
|
|
static inline unsigned int compute_cas_write_latency(
|
|
|
|
const unsigned int ctrl_num)
|
2009-03-14 04:48:30 +00:00
|
|
|
{
|
|
|
|
unsigned int cwl;
|
2015-01-06 21:18:50 +00:00
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
|
2009-03-14 04:48:30 +00:00
|
|
|
|
|
|
|
if (mclk_ps >= 2500)
|
|
|
|
cwl = 5;
|
|
|
|
else if (mclk_ps >= 1875)
|
|
|
|
cwl = 6;
|
|
|
|
else if (mclk_ps >= 1500)
|
|
|
|
cwl = 7;
|
|
|
|
else if (mclk_ps >= 1250)
|
|
|
|
cwl = 8;
|
2011-08-24 16:40:25 +00:00
|
|
|
else if (mclk_ps >= 1070)
|
|
|
|
cwl = 9;
|
|
|
|
else if (mclk_ps >= 935)
|
|
|
|
cwl = 10;
|
|
|
|
else if (mclk_ps >= 833)
|
|
|
|
cwl = 11;
|
|
|
|
else if (mclk_ps >= 750)
|
|
|
|
cwl = 12;
|
|
|
|
else {
|
|
|
|
cwl = 12;
|
|
|
|
printf("Warning: CWL is out of range\n");
|
|
|
|
}
|
2009-03-14 04:48:30 +00:00
|
|
|
return cwl;
|
|
|
|
}
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2009-03-14 04:48:30 +00:00
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/* Chip Select Configuration (CSn_CONFIG) */
|
2010-07-02 22:25:53 +00:00
|
|
|
static void set_csn_config(int dimm_number, int i, fsl_ddr_cfg_regs_t *ddr,
|
2008-08-26 20:01:29 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const dimm_params_t *dimm_params)
|
|
|
|
{
|
|
|
|
unsigned int cs_n_en = 0; /* Chip Select enable */
|
|
|
|
unsigned int intlv_en = 0; /* Memory controller interleave enable */
|
|
|
|
unsigned int intlv_ctl = 0; /* Interleaving control */
|
|
|
|
unsigned int ap_n_en = 0; /* Chip select n auto-precharge enable */
|
|
|
|
unsigned int odt_rd_cfg = 0; /* ODT for reads configuration */
|
|
|
|
unsigned int odt_wr_cfg = 0; /* ODT for writes configuration */
|
|
|
|
unsigned int ba_bits_cs_n = 0; /* Num of bank bits for SDRAM on CSn */
|
|
|
|
unsigned int row_bits_cs_n = 0; /* Num of row bits for SDRAM on CSn */
|
|
|
|
unsigned int col_bits_cs_n = 0; /* Num of ocl bits for SDRAM on CSn */
|
2010-07-02 22:25:53 +00:00
|
|
|
int go_config = 0;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
unsigned int bg_bits_cs_n = 0; /* Num of bank group bits */
|
|
|
|
#else
|
|
|
|
unsigned int n_banks_per_sdram_device;
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/* Compute CS_CONFIG only for existing ranks of each DIMM. */
|
2010-07-02 22:25:53 +00:00
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
if (dimm_params[dimm_number].n_ranks > 0) {
|
|
|
|
go_config = 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
/* These fields only available in CS0_CONFIG */
|
2012-08-17 08:22:39 +00:00
|
|
|
if (!popts->memctl_interleaving)
|
|
|
|
break;
|
|
|
|
switch (popts->memctl_interleaving_mode) {
|
2014-02-10 21:59:44 +00:00
|
|
|
case FSL_DDR_256B_INTERLEAVING:
|
2012-08-17 08:22:39 +00:00
|
|
|
case FSL_DDR_CACHE_LINE_INTERLEAVING:
|
|
|
|
case FSL_DDR_PAGE_INTERLEAVING:
|
|
|
|
case FSL_DDR_BANK_INTERLEAVING:
|
|
|
|
case FSL_DDR_SUPERBANK_INTERLEAVING:
|
|
|
|
intlv_en = popts->memctl_interleaving;
|
|
|
|
intlv_ctl = popts->memctl_interleaving_mode;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
2010-07-02 22:25:53 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if ((dimm_number == 0 && dimm_params[0].n_ranks > 1) || \
|
|
|
|
(dimm_number == 1 && dimm_params[1].n_ranks > 0))
|
|
|
|
go_config = 1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if ((dimm_number == 0 && dimm_params[0].n_ranks > 2) || \
|
2011-08-26 18:32:40 +00:00
|
|
|
(dimm_number >= 1 && dimm_params[dimm_number].n_ranks > 0))
|
2010-07-02 22:25:53 +00:00
|
|
|
go_config = 1;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
if ((dimm_number == 0 && dimm_params[0].n_ranks > 3) || \
|
|
|
|
(dimm_number == 1 && dimm_params[1].n_ranks > 1) || \
|
|
|
|
(dimm_number == 3 && dimm_params[3].n_ranks > 0))
|
|
|
|
go_config = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (go_config) {
|
|
|
|
cs_n_en = 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
ap_n_en = popts->cs_local_opts[i].auto_precharge;
|
|
|
|
odt_rd_cfg = popts->cs_local_opts[i].odt_rd_cfg;
|
|
|
|
odt_wr_cfg = popts->cs_local_opts[i].odt_wr_cfg;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
ba_bits_cs_n = dimm_params[dimm_number].bank_addr_bits;
|
|
|
|
bg_bits_cs_n = dimm_params[dimm_number].bank_group_bits;
|
|
|
|
#else
|
2008-08-26 20:01:29 +00:00
|
|
|
n_banks_per_sdram_device
|
2010-07-02 22:25:53 +00:00
|
|
|
= dimm_params[dimm_number].n_banks_per_sdram_device;
|
2008-08-26 20:01:29 +00:00
|
|
|
ba_bits_cs_n = __ilog2(n_banks_per_sdram_device) - 2;
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2010-07-02 22:25:53 +00:00
|
|
|
row_bits_cs_n = dimm_params[dimm_number].n_row_addr - 12;
|
|
|
|
col_bits_cs_n = dimm_params[dimm_number].n_col_addr - 8;
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
ddr->cs[i].config = (0
|
|
|
|
| ((cs_n_en & 0x1) << 31)
|
|
|
|
| ((intlv_en & 0x3) << 29)
|
2008-10-03 16:36:39 +00:00
|
|
|
| ((intlv_ctl & 0xf) << 24)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((ap_n_en & 0x1) << 23)
|
|
|
|
|
|
|
|
/* XXX: some implementation only have 1 bit starting at left */
|
|
|
|
| ((odt_rd_cfg & 0x7) << 20)
|
|
|
|
|
|
|
|
/* XXX: Some implementation only have 1 bit starting at left */
|
|
|
|
| ((odt_wr_cfg & 0x7) << 16)
|
|
|
|
|
|
|
|
| ((ba_bits_cs_n & 0x3) << 14)
|
|
|
|
| ((row_bits_cs_n & 0x7) << 8)
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
| ((bg_bits_cs_n & 0x3) << 4)
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((col_bits_cs_n & 0x7) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: cs[%d]_config = 0x%08x\n", i,ddr->cs[i].config);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Chip Select Configuration 2 (CSn_CONFIG_2) */
|
|
|
|
/* FIXME: 8572 */
|
|
|
|
static void set_csn_config_2(int i, fsl_ddr_cfg_regs_t *ddr)
|
|
|
|
{
|
|
|
|
unsigned int pasr_cfg = 0; /* Partial array self refresh config */
|
|
|
|
|
|
|
|
ddr->cs[i].config_2 = ((pasr_cfg & 7) << 24);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: cs[%d]_config_2 = 0x%08x\n", i, ddr->cs[i].config_2);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -3E = 667 CL5, -25 = CL6 800, -25E = CL5 800 */
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#if !defined(CONFIG_SYS_FSL_DDR1)
|
2014-11-07 20:14:36 +00:00
|
|
|
/*
|
|
|
|
* Check DIMM configuration, return 2 if quad-rank or two dual-rank
|
|
|
|
* Return 1 if other two slots configuration. Return 0 if single slot.
|
|
|
|
*/
|
2012-10-08 07:44:23 +00:00
|
|
|
static inline int avoid_odt_overlap(const dimm_params_t *dimm_params)
|
|
|
|
{
|
|
|
|
#if CONFIG_DIMM_SLOTS_PER_CTLR == 1
|
|
|
|
if (dimm_params[0].n_ranks == 4)
|
2014-11-07 20:14:36 +00:00
|
|
|
return 2;
|
2012-10-08 07:44:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CONFIG_DIMM_SLOTS_PER_CTLR == 2
|
|
|
|
if ((dimm_params[0].n_ranks == 2) &&
|
|
|
|
(dimm_params[1].n_ranks == 2))
|
2014-11-07 20:14:36 +00:00
|
|
|
return 2;
|
2012-10-08 07:44:23 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_FSL_DDR_FIRST_SLOT_QUAD_CAPABLE
|
|
|
|
if (dimm_params[0].n_ranks == 4)
|
2014-11-07 20:14:36 +00:00
|
|
|
return 2;
|
2012-10-08 07:44:23 +00:00
|
|
|
#endif
|
2014-11-07 20:14:36 +00:00
|
|
|
|
|
|
|
if ((dimm_params[0].n_ranks != 0) &&
|
|
|
|
(dimm_params[2].n_ranks != 0))
|
|
|
|
return 1;
|
2012-10-08 07:44:23 +00:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/*
|
|
|
|
* DDR SDRAM Timing Configuration 0 (TIMING_CFG_0)
|
|
|
|
*
|
|
|
|
* Avoid writing for DDR I. The new PQ38 DDR controller
|
|
|
|
* dreams up non-zero default values to be backwards compatible.
|
|
|
|
*/
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_timing_cfg_0(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2012-10-08 07:44:23 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const dimm_params_t *dimm_params)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned char trwt_mclk = 0; /* Read-to-write turnaround */
|
|
|
|
unsigned char twrt_mclk = 0; /* Write-to-read turnaround */
|
|
|
|
/* 7.5 ns on -3E; 0 means WL - CL + BL/2 + 1 */
|
|
|
|
unsigned char trrt_mclk = 0; /* Read-to-read turnaround */
|
|
|
|
unsigned char twwt_mclk = 0; /* Write-to-write turnaround */
|
|
|
|
|
|
|
|
/* Active powerdown exit timing (tXARD and tXARDS). */
|
|
|
|
unsigned char act_pd_exit_mclk;
|
|
|
|
/* Precharge powerdown exit timing (tXP). */
|
|
|
|
unsigned char pre_pd_exit_mclk;
|
2010-07-02 22:25:56 +00:00
|
|
|
/* ODT powerdown exit timing (tAXPD). */
|
2014-03-28 00:54:47 +00:00
|
|
|
unsigned char taxpd_mclk = 0;
|
2008-08-26 20:01:29 +00:00
|
|
|
/* Mode register set cycle time (tMRD). */
|
|
|
|
unsigned char tmrd_mclk;
|
2014-08-21 23:13:22 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR4) || defined(CONFIG_SYS_FSL_DDR3)
|
2015-01-06 21:18:50 +00:00
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
|
2014-08-21 23:13:22 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
/* tXP=max(4nCK, 6ns) */
|
linux/kernel.h: sync min, max, min3, max3 macros with Linux
U-Boot has never cared about the type when we get max/min of two
values, but Linux Kernel does. This commit gets min, max, min3, max3
macros synced with the kernel introducing type checks.
Many of references of those macros must be fixed to suppress warnings.
We have two options:
- Use min, max, min3, max3 only when the arguments have the same type
(or add casts to the arguments)
- Use min_t/max_t instead with the appropriate type for the first
argument
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Pavel Machek <pavel@denx.de>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
[trini: Fixup arch/blackfin/lib/string.c]
Signed-off-by: Tom Rini <trini@ti.com>
2014-11-06 18:03:31 +00:00
|
|
|
int txp = max((int)mclk_ps * 4, 6000); /* unit=ps */
|
2015-03-19 16:30:26 +00:00
|
|
|
unsigned int data_rate = get_ddr_freq(ctrl_num);
|
|
|
|
|
|
|
|
/* for faster clock, need more time for data setup */
|
|
|
|
trwt_mclk = (data_rate/1000000 > 1900) ? 3 : 2;
|
2015-11-04 18:03:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* for single quad-rank DIMM and two-slot DIMMs
|
|
|
|
* to avoid ODT overlap
|
|
|
|
*/
|
|
|
|
switch (avoid_odt_overlap(dimm_params)) {
|
|
|
|
case 2:
|
|
|
|
twrt_mclk = 2;
|
|
|
|
twwt_mclk = 2;
|
|
|
|
trrt_mclk = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
twrt_mclk = 1;
|
|
|
|
twwt_mclk = 1;
|
|
|
|
trrt_mclk = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
act_pd_exit_mclk = picos_to_mclk(ctrl_num, txp);
|
2014-03-28 00:54:47 +00:00
|
|
|
pre_pd_exit_mclk = act_pd_exit_mclk;
|
|
|
|
/*
|
|
|
|
* MRS_CYC = max(tMRD, tMOD)
|
|
|
|
* tMRD = 8nCK, tMOD = max(24nCK, 15ns)
|
|
|
|
*/
|
2015-01-06 21:18:50 +00:00
|
|
|
tmrd_mclk = max(24U, picos_to_mclk(ctrl_num, 15000));
|
2014-03-28 00:54:47 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3)
|
2015-01-06 21:18:50 +00:00
|
|
|
unsigned int data_rate = get_ddr_freq(ctrl_num);
|
2014-08-21 23:13:22 +00:00
|
|
|
int txp;
|
2014-12-02 19:18:09 +00:00
|
|
|
unsigned int ip_rev;
|
2014-11-07 20:14:36 +00:00
|
|
|
int odt_overlap;
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* (tXARD and tXARDS). Empirical?
|
|
|
|
* The DDR3 spec has not tXARD,
|
|
|
|
* we use the tXP instead of it.
|
2014-08-21 23:13:22 +00:00
|
|
|
* tXP=max(3nCK, 7.5ns) for DDR3-800, 1066
|
|
|
|
* max(3nCK, 6ns) for DDR3-1333, 1600, 1866, 2133
|
2009-03-14 04:48:30 +00:00
|
|
|
* spec has not the tAXPD, we use
|
2010-07-02 22:25:56 +00:00
|
|
|
* tAXPD=1, need design to confirm.
|
2009-03-14 04:48:30 +00:00
|
|
|
*/
|
linux/kernel.h: sync min, max, min3, max3 macros with Linux
U-Boot has never cared about the type when we get max/min of two
values, but Linux Kernel does. This commit gets min, max, min3, max3
macros synced with the kernel introducing type checks.
Many of references of those macros must be fixed to suppress warnings.
We have two options:
- Use min, max, min3, max3 only when the arguments have the same type
(or add casts to the arguments)
- Use min_t/max_t instead with the appropriate type for the first
argument
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Pavel Machek <pavel@denx.de>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
[trini: Fixup arch/blackfin/lib/string.c]
Signed-off-by: Tom Rini <trini@ti.com>
2014-11-06 18:03:31 +00:00
|
|
|
txp = max((int)mclk_ps * 3, (mclk_ps > 1540 ? 7500 : 6000));
|
2014-08-21 23:13:22 +00:00
|
|
|
|
2015-03-19 16:30:26 +00:00
|
|
|
ip_rev = fsl_ddr_get_version(ctrl_num);
|
2014-12-02 19:18:09 +00:00
|
|
|
if (ip_rev >= 0x40700) {
|
|
|
|
/*
|
|
|
|
* MRS_CYC = max(tMRD, tMOD)
|
|
|
|
* tMRD = 4nCK (8nCK for RDIMM)
|
|
|
|
* tMOD = max(12nCK, 15ns)
|
|
|
|
*/
|
2015-01-06 21:18:50 +00:00
|
|
|
tmrd_mclk = max((unsigned int)12,
|
|
|
|
picos_to_mclk(ctrl_num, 15000));
|
2014-12-02 19:18:09 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* MRS_CYC = tMRD
|
|
|
|
* tMRD = 4nCK (8nCK for RDIMM)
|
|
|
|
*/
|
|
|
|
if (popts->registered_dimm_en)
|
|
|
|
tmrd_mclk = 8;
|
|
|
|
else
|
|
|
|
tmrd_mclk = 4;
|
|
|
|
}
|
|
|
|
|
2009-12-08 03:56:48 +00:00
|
|
|
/* set the turnaround time */
|
2012-10-08 07:44:23 +00:00
|
|
|
|
|
|
|
/*
|
2014-11-07 20:14:36 +00:00
|
|
|
* for single quad-rank DIMM and two-slot DIMMs
|
2012-10-08 07:44:23 +00:00
|
|
|
* to avoid ODT overlap
|
|
|
|
*/
|
2014-11-07 20:14:36 +00:00
|
|
|
odt_overlap = avoid_odt_overlap(dimm_params);
|
|
|
|
switch (odt_overlap) {
|
|
|
|
case 2:
|
2012-10-08 07:44:23 +00:00
|
|
|
twwt_mclk = 2;
|
|
|
|
trrt_mclk = 1;
|
2014-11-07 20:14:36 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
twwt_mclk = 1;
|
|
|
|
trrt_mclk = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-10-08 07:44:23 +00:00
|
|
|
}
|
2014-11-07 20:14:36 +00:00
|
|
|
|
2012-10-08 07:44:23 +00:00
|
|
|
/* for faster clock, need more time for data setup */
|
|
|
|
trwt_mclk = (data_rate/1000000 > 1800) ? 2 : 1;
|
|
|
|
|
2011-02-10 18:13:10 +00:00
|
|
|
if ((data_rate/1000000 > 1150) || (popts->memctl_interleaving))
|
|
|
|
twrt_mclk = 1;
|
2011-01-10 12:03:00 +00:00
|
|
|
|
|
|
|
if (popts->dynamic_power == 0) { /* powerdown is not used */
|
|
|
|
act_pd_exit_mclk = 1;
|
|
|
|
pre_pd_exit_mclk = 1;
|
|
|
|
taxpd_mclk = 1;
|
|
|
|
} else {
|
|
|
|
/* act_pd_exit_mclk = tXARD, see above */
|
2015-01-06 21:18:50 +00:00
|
|
|
act_pd_exit_mclk = picos_to_mclk(ctrl_num, txp);
|
2011-01-10 12:03:00 +00:00
|
|
|
/* Mode register MR0[A12] is '1' - fast exit */
|
|
|
|
pre_pd_exit_mclk = act_pd_exit_mclk;
|
|
|
|
taxpd_mclk = 1;
|
|
|
|
}
|
2013-09-30 16:22:09 +00:00
|
|
|
#else /* CONFIG_SYS_FSL_DDR2 */
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* (tXARD and tXARDS). Empirical?
|
|
|
|
* tXARD = 2 for DDR2
|
|
|
|
* tXP=2
|
|
|
|
* tAXPD=8
|
|
|
|
*/
|
|
|
|
act_pd_exit_mclk = 2;
|
|
|
|
pre_pd_exit_mclk = 2;
|
|
|
|
taxpd_mclk = 8;
|
2008-08-26 20:01:29 +00:00
|
|
|
tmrd_mclk = 2;
|
2009-03-14 04:48:30 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2011-05-27 05:44:28 +00:00
|
|
|
if (popts->trwt_override)
|
|
|
|
trwt_mclk = popts->trwt;
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->timing_cfg_0 = (0
|
|
|
|
| ((trwt_mclk & 0x3) << 30) /* RWT */
|
|
|
|
| ((twrt_mclk & 0x3) << 28) /* WRT */
|
|
|
|
| ((trrt_mclk & 0x3) << 26) /* RRT */
|
|
|
|
| ((twwt_mclk & 0x3) << 24) /* WWT */
|
2013-06-03 19:39:06 +00:00
|
|
|
| ((act_pd_exit_mclk & 0xf) << 20) /* ACT_PD_EXIT */
|
2008-11-21 08:31:29 +00:00
|
|
|
| ((pre_pd_exit_mclk & 0xF) << 16) /* PRE_PD_EXIT */
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((taxpd_mclk & 0xf) << 8) /* ODT_PD_EXIT */
|
2013-06-03 19:39:06 +00:00
|
|
|
| ((tmrd_mclk & 0x1f) << 0) /* MRS_CYC */
|
2008-08-26 20:01:29 +00:00
|
|
|
);
|
|
|
|
debug("FSLDDR: timing_cfg_0 = 0x%08x\n", ddr->timing_cfg_0);
|
|
|
|
}
|
2014-11-07 20:14:36 +00:00
|
|
|
#endif /* !defined(CONFIG_SYS_FSL_DDR1) */
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/* DDR SDRAM Timing Configuration 3 (TIMING_CFG_3) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_timing_cfg_3(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency,
|
|
|
|
unsigned int additive_latency)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
2012-08-17 08:22:40 +00:00
|
|
|
/* Extended precharge to activate interval (tRP) */
|
|
|
|
unsigned int ext_pretoact = 0;
|
2008-08-26 20:01:29 +00:00
|
|
|
/* Extended Activate to precharge interval (tRAS) */
|
|
|
|
unsigned int ext_acttopre = 0;
|
2012-08-17 08:22:40 +00:00
|
|
|
/* Extended activate to read/write interval (tRCD) */
|
|
|
|
unsigned int ext_acttorw = 0;
|
|
|
|
/* Extended refresh recovery time (tRFC) */
|
|
|
|
unsigned int ext_refrec;
|
|
|
|
/* Extended MCAS latency from READ cmd */
|
|
|
|
unsigned int ext_caslat = 0;
|
2013-06-03 19:39:06 +00:00
|
|
|
/* Extended additive latency */
|
|
|
|
unsigned int ext_add_lat = 0;
|
2012-08-17 08:22:40 +00:00
|
|
|
/* Extended last data to precharge interval (tWR) */
|
|
|
|
unsigned int ext_wrrec = 0;
|
|
|
|
/* Control Adjust */
|
|
|
|
unsigned int cntl_adj = 0;
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
ext_pretoact = picos_to_mclk(ctrl_num, common_dimm->trp_ps) >> 4;
|
|
|
|
ext_acttopre = picos_to_mclk(ctrl_num, common_dimm->tras_ps) >> 4;
|
|
|
|
ext_acttorw = picos_to_mclk(ctrl_num, common_dimm->trcd_ps) >> 4;
|
2012-08-17 08:22:40 +00:00
|
|
|
ext_caslat = (2 * cas_latency - 1) >> 4;
|
2013-06-03 19:39:06 +00:00
|
|
|
ext_add_lat = additive_latency >> 4;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
2015-01-06 21:18:50 +00:00
|
|
|
ext_refrec = (picos_to_mclk(ctrl_num, common_dimm->trfc1_ps) - 8) >> 4;
|
2014-03-28 00:54:47 +00:00
|
|
|
#else
|
2015-01-06 21:18:50 +00:00
|
|
|
ext_refrec = (picos_to_mclk(ctrl_num, common_dimm->trfc_ps) - 8) >> 4;
|
2012-08-17 08:22:40 +00:00
|
|
|
/* ext_wrrec only deals with 16 clock and above, or 14 with OTF */
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2015-01-06 21:18:50 +00:00
|
|
|
ext_wrrec = (picos_to_mclk(ctrl_num, common_dimm->twr_ps) +
|
2013-09-25 05:11:19 +00:00
|
|
|
(popts->otf_burst_chop_en ? 2 : 0)) >> 4;
|
2009-03-14 04:48:30 +00:00
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->timing_cfg_3 = (0
|
2012-08-17 08:22:40 +00:00
|
|
|
| ((ext_pretoact & 0x1) << 28)
|
2013-07-22 16:35:26 +00:00
|
|
|
| ((ext_acttopre & 0x3) << 24)
|
2012-08-17 08:22:40 +00:00
|
|
|
| ((ext_acttorw & 0x1) << 22)
|
2018-01-29 17:44:35 +00:00
|
|
|
| ((ext_refrec & 0x3F) << 16)
|
2012-08-17 08:22:40 +00:00
|
|
|
| ((ext_caslat & 0x3) << 12)
|
2013-06-03 19:39:06 +00:00
|
|
|
| ((ext_add_lat & 0x1) << 10)
|
2012-08-17 08:22:40 +00:00
|
|
|
| ((ext_wrrec & 0x1) << 8)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((cntl_adj & 0x7) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: timing_cfg_3 = 0x%08x\n", ddr->timing_cfg_3);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR SDRAM Timing Configuration 1 (TIMING_CFG_1) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_timing_cfg_1(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
/* Precharge-to-activate interval (tRP) */
|
|
|
|
unsigned char pretoact_mclk;
|
|
|
|
/* Activate to precharge interval (tRAS) */
|
|
|
|
unsigned char acttopre_mclk;
|
|
|
|
/* Activate to read/write interval (tRCD) */
|
|
|
|
unsigned char acttorw_mclk;
|
|
|
|
/* CASLAT */
|
|
|
|
unsigned char caslat_ctrl;
|
|
|
|
/* Refresh recovery time (tRFC) ; trfc_low */
|
|
|
|
unsigned char refrec_ctrl;
|
|
|
|
/* Last data to precharge minimum interval (tWR) */
|
|
|
|
unsigned char wrrec_mclk;
|
|
|
|
/* Activate-to-activate interval (tRRD) */
|
|
|
|
unsigned char acttoact_mclk;
|
|
|
|
/* Last write data pair to read command issue interval (tWTR) */
|
|
|
|
unsigned char wrtord_mclk;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
/* DDR4 supports 10, 12, 14, 16, 18, 20, 24 */
|
|
|
|
static const u8 wrrec_table[] = {
|
|
|
|
10, 10, 10, 10, 10,
|
|
|
|
10, 10, 10, 10, 10,
|
|
|
|
12, 12, 14, 14, 16,
|
|
|
|
16, 18, 18, 20, 20,
|
|
|
|
24, 24, 24, 24};
|
|
|
|
#else
|
2011-03-02 22:24:11 +00:00
|
|
|
/* DDR_SDRAM_MODE doesn't support 9,11,13,15 */
|
|
|
|
static const u8 wrrec_table[] = {
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8, 10, 10, 12, 12, 14, 14, 0, 0};
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
pretoact_mclk = picos_to_mclk(ctrl_num, common_dimm->trp_ps);
|
|
|
|
acttopre_mclk = picos_to_mclk(ctrl_num, common_dimm->tras_ps);
|
|
|
|
acttorw_mclk = picos_to_mclk(ctrl_num, common_dimm->trcd_ps);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Translate CAS Latency to a DDR controller field value:
|
|
|
|
*
|
|
|
|
* CAS Lat DDR I DDR II Ctrl
|
|
|
|
* Clocks SPD Bit SPD Bit Value
|
|
|
|
* ------- ------- ------- -----
|
|
|
|
* 1.0 0 0001
|
|
|
|
* 1.5 1 0010
|
|
|
|
* 2.0 2 2 0011
|
|
|
|
* 2.5 3 0100
|
|
|
|
* 3.0 4 3 0101
|
|
|
|
* 3.5 5 0110
|
|
|
|
* 4.0 4 0111
|
|
|
|
* 4.5 1000
|
|
|
|
* 5.0 5 1001
|
|
|
|
*/
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR1)
|
2008-08-26 20:01:29 +00:00
|
|
|
caslat_ctrl = (cas_latency + 1) & 0x07;
|
2013-09-30 16:22:09 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR2)
|
2008-08-26 20:01:29 +00:00
|
|
|
caslat_ctrl = 2 * cas_latency - 1;
|
|
|
|
#else
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* if the CAS latency more than 8 cycle,
|
|
|
|
* we need set extend bit for it at
|
|
|
|
* TIMING_CFG_3[EXT_CASLAT]
|
|
|
|
*/
|
2015-03-19 16:30:26 +00:00
|
|
|
if (fsl_ddr_get_version(ctrl_num) <= 0x40400)
|
2014-03-28 00:54:47 +00:00
|
|
|
caslat_ctrl = 2 * cas_latency - 1;
|
|
|
|
else
|
|
|
|
caslat_ctrl = (cas_latency - 1) << 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
2015-01-06 21:18:50 +00:00
|
|
|
refrec_ctrl = picos_to_mclk(ctrl_num, common_dimm->trfc1_ps) - 8;
|
|
|
|
wrrec_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
|
|
|
|
acttoact_mclk = max(picos_to_mclk(ctrl_num, common_dimm->trrds_ps), 4U);
|
|
|
|
wrtord_mclk = max(2U, picos_to_mclk(ctrl_num, 2500));
|
2014-04-01 21:20:49 +00:00
|
|
|
if ((wrrec_mclk < 1) || (wrrec_mclk > 24))
|
|
|
|
printf("Error: WRREC doesn't support %d clocks\n", wrrec_mclk);
|
2014-03-28 00:54:47 +00:00
|
|
|
else
|
|
|
|
wrrec_mclk = wrrec_table[wrrec_mclk - 1];
|
|
|
|
#else
|
2015-01-06 21:18:50 +00:00
|
|
|
refrec_ctrl = picos_to_mclk(ctrl_num, common_dimm->trfc_ps) - 8;
|
|
|
|
wrrec_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
|
|
|
|
acttoact_mclk = picos_to_mclk(ctrl_num, common_dimm->trrd_ps);
|
|
|
|
wrtord_mclk = picos_to_mclk(ctrl_num, common_dimm->twtr_ps);
|
2014-04-01 21:20:49 +00:00
|
|
|
if ((wrrec_mclk < 1) || (wrrec_mclk > 16))
|
|
|
|
printf("Error: WRREC doesn't support %d clocks\n", wrrec_mclk);
|
2012-08-17 08:22:40 +00:00
|
|
|
else
|
|
|
|
wrrec_mclk = wrrec_table[wrrec_mclk - 1];
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2013-09-25 05:11:19 +00:00
|
|
|
if (popts->otf_burst_chop_en)
|
2009-03-14 04:48:30 +00:00
|
|
|
wrrec_mclk += 2;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* JEDEC has min requirement for tRRD
|
|
|
|
*/
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR3)
|
2009-03-14 04:48:30 +00:00
|
|
|
if (acttoact_mclk < 4)
|
|
|
|
acttoact_mclk = 4;
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* JEDEC has some min requirements for tWTR
|
|
|
|
*/
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR2)
|
2009-03-14 04:48:30 +00:00
|
|
|
if (wrtord_mclk < 2)
|
|
|
|
wrtord_mclk = 2;
|
2013-09-30 16:22:09 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3)
|
2009-03-14 04:48:30 +00:00
|
|
|
if (wrtord_mclk < 4)
|
|
|
|
wrtord_mclk = 4;
|
|
|
|
#endif
|
2013-09-25 05:11:19 +00:00
|
|
|
if (popts->otf_burst_chop_en)
|
2009-03-14 04:48:30 +00:00
|
|
|
wrtord_mclk += 2;
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
ddr->timing_cfg_1 = (0
|
2008-11-21 08:31:22 +00:00
|
|
|
| ((pretoact_mclk & 0x0F) << 28)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((acttopre_mclk & 0x0F) << 24)
|
2008-11-21 08:31:22 +00:00
|
|
|
| ((acttorw_mclk & 0xF) << 20)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((caslat_ctrl & 0xF) << 16)
|
|
|
|
| ((refrec_ctrl & 0xF) << 12)
|
2008-11-21 08:31:22 +00:00
|
|
|
| ((wrrec_mclk & 0x0F) << 8)
|
2012-10-08 07:44:22 +00:00
|
|
|
| ((acttoact_mclk & 0x0F) << 4)
|
|
|
|
| ((wrtord_mclk & 0x0F) << 0)
|
2008-08-26 20:01:29 +00:00
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: timing_cfg_1 = 0x%08x\n", ddr->timing_cfg_1);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR SDRAM Timing Configuration 2 (TIMING_CFG_2) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_timing_cfg_2(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency,
|
|
|
|
unsigned int additive_latency)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
/* Additive latency */
|
|
|
|
unsigned char add_lat_mclk;
|
|
|
|
/* CAS-to-preamble override */
|
|
|
|
unsigned short cpo;
|
|
|
|
/* Write latency */
|
|
|
|
unsigned char wr_lat;
|
|
|
|
/* Read to precharge (tRTP) */
|
|
|
|
unsigned char rd_to_pre;
|
|
|
|
/* Write command to write data strobe timing adjustment */
|
|
|
|
unsigned char wr_data_delay;
|
|
|
|
/* Minimum CKE pulse width (tCKE) */
|
|
|
|
unsigned char cke_pls;
|
|
|
|
/* Window for four activates (tFAW) */
|
|
|
|
unsigned short four_act;
|
2014-08-21 23:13:22 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR3
|
2015-01-06 21:18:50 +00:00
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
|
2014-08-21 23:13:22 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/* FIXME add check that this must be less than acttorw_mclk */
|
|
|
|
add_lat_mclk = additive_latency;
|
|
|
|
cpo = popts->cpo_override;
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR1)
|
2008-08-26 20:01:29 +00:00
|
|
|
/*
|
|
|
|
* This is a lie. It should really be 1, but if it is
|
|
|
|
* set to 1, bits overlap into the old controller's
|
|
|
|
* otherwise unused ACSM field. If we leave it 0, then
|
|
|
|
* the HW will magically treat it as 1 for DDR 1. Oh Yea.
|
|
|
|
*/
|
|
|
|
wr_lat = 0;
|
2013-09-30 16:22:09 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR2)
|
2009-03-14 04:48:19 +00:00
|
|
|
wr_lat = cas_latency - 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
#else
|
2015-01-06 21:18:50 +00:00
|
|
|
wr_lat = compute_cas_write_latency(ctrl_num);
|
2008-08-26 20:01:29 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
2015-01-06 21:18:50 +00:00
|
|
|
rd_to_pre = picos_to_mclk(ctrl_num, 7500);
|
2014-03-28 00:54:47 +00:00
|
|
|
#else
|
2015-01-06 21:18:50 +00:00
|
|
|
rd_to_pre = picos_to_mclk(ctrl_num, common_dimm->trtp_ps);
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* JEDEC has some min requirements for tRTP
|
|
|
|
*/
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR2)
|
2009-03-14 04:48:30 +00:00
|
|
|
if (rd_to_pre < 2)
|
|
|
|
rd_to_pre = 2;
|
2014-03-28 00:54:47 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
|
2009-03-14 04:48:30 +00:00
|
|
|
if (rd_to_pre < 4)
|
|
|
|
rd_to_pre = 4;
|
2009-03-14 04:48:19 +00:00
|
|
|
#endif
|
2013-09-25 05:11:19 +00:00
|
|
|
if (popts->otf_burst_chop_en)
|
2009-03-14 04:48:30 +00:00
|
|
|
rd_to_pre += 2; /* according to UM */
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
wr_data_delay = popts->write_data_delay;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
cpo = 0;
|
2015-01-06 21:18:50 +00:00
|
|
|
cke_pls = max(3U, picos_to_mclk(ctrl_num, 5000));
|
2014-08-21 23:13:22 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3)
|
|
|
|
/*
|
|
|
|
* cke pulse = max(3nCK, 7.5ns) for DDR3-800
|
|
|
|
* max(3nCK, 5.625ns) for DDR3-1066, 1333
|
|
|
|
* max(3nCK, 5ns) for DDR3-1600, 1866, 2133
|
|
|
|
*/
|
2015-01-06 21:18:50 +00:00
|
|
|
cke_pls = max(3U, picos_to_mclk(ctrl_num, mclk_ps > 1870 ? 7500 :
|
|
|
|
(mclk_ps > 1245 ? 5625 : 5000)));
|
2014-03-28 00:54:47 +00:00
|
|
|
#else
|
2014-08-21 23:13:22 +00:00
|
|
|
cke_pls = FSL_DDR_MIN_TCKE_PULSE_WIDTH_DDR;
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2015-01-06 21:18:50 +00:00
|
|
|
four_act = picos_to_mclk(ctrl_num,
|
|
|
|
popts->tfaw_window_four_activates_ps);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
ddr->timing_cfg_2 = (0
|
2008-11-21 08:31:29 +00:00
|
|
|
| ((add_lat_mclk & 0xf) << 28)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((cpo & 0x1f) << 23)
|
2008-11-21 08:31:29 +00:00
|
|
|
| ((wr_lat & 0xf) << 19)
|
2016-07-29 16:02:29 +00:00
|
|
|
| (((wr_lat & 0x10) >> 4) << 18)
|
2009-03-14 04:48:30 +00:00
|
|
|
| ((rd_to_pre & RD_TO_PRE_MASK) << RD_TO_PRE_SHIFT)
|
|
|
|
| ((wr_data_delay & WR_DATA_DELAY_MASK) << WR_DATA_DELAY_SHIFT)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((cke_pls & 0x7) << 6)
|
2008-11-21 08:31:29 +00:00
|
|
|
| ((four_act & 0x3f) << 0)
|
2008-08-26 20:01:29 +00:00
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: timing_cfg_2 = 0x%08x\n", ddr->timing_cfg_2);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2010-07-02 22:25:55 +00:00
|
|
|
/* DDR SDRAM Register Control Word */
|
2018-01-29 18:24:08 +00:00
|
|
|
static void set_ddr_sdram_rcw(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm)
|
2010-07-02 22:25:55 +00:00
|
|
|
{
|
2018-01-29 18:24:08 +00:00
|
|
|
unsigned int ddr_freq = get_ddr_freq(ctrl_num) / 1000000;
|
|
|
|
unsigned int rc0a, rc0f;
|
|
|
|
|
2013-09-25 05:11:19 +00:00
|
|
|
if (common_dimm->all_dimms_registered &&
|
|
|
|
!common_dimm->all_dimms_unbuffered) {
|
2011-01-10 12:03:00 +00:00
|
|
|
if (popts->rcw_override) {
|
|
|
|
ddr->ddr_sdram_rcw_1 = popts->rcw_1;
|
|
|
|
ddr->ddr_sdram_rcw_2 = popts->rcw_2;
|
2018-01-29 17:44:33 +00:00
|
|
|
ddr->ddr_sdram_rcw_3 = popts->rcw_3;
|
2011-01-10 12:03:00 +00:00
|
|
|
} else {
|
2018-01-29 18:24:08 +00:00
|
|
|
rc0a = ddr_freq > 3200 ? 0x7 :
|
|
|
|
(ddr_freq > 2933 ? 0x6 :
|
|
|
|
(ddr_freq > 2666 ? 0x5 :
|
|
|
|
(ddr_freq > 2400 ? 0x4 :
|
|
|
|
(ddr_freq > 2133 ? 0x3 :
|
|
|
|
(ddr_freq > 1866 ? 0x2 :
|
|
|
|
(ddr_freq > 1600 ? 1 : 0))))));
|
|
|
|
rc0f = ddr_freq > 3200 ? 0x3 :
|
|
|
|
(ddr_freq > 2400 ? 0x2 :
|
|
|
|
(ddr_freq > 2133 ? 0x1 : 0));
|
2011-01-10 12:03:00 +00:00
|
|
|
ddr->ddr_sdram_rcw_1 =
|
|
|
|
common_dimm->rcw[0] << 28 | \
|
|
|
|
common_dimm->rcw[1] << 24 | \
|
|
|
|
common_dimm->rcw[2] << 20 | \
|
|
|
|
common_dimm->rcw[3] << 16 | \
|
|
|
|
common_dimm->rcw[4] << 12 | \
|
|
|
|
common_dimm->rcw[5] << 8 | \
|
|
|
|
common_dimm->rcw[6] << 4 | \
|
|
|
|
common_dimm->rcw[7];
|
|
|
|
ddr->ddr_sdram_rcw_2 =
|
|
|
|
common_dimm->rcw[8] << 28 | \
|
|
|
|
common_dimm->rcw[9] << 24 | \
|
2018-01-29 18:24:08 +00:00
|
|
|
rc0a << 20 | \
|
2011-01-10 12:03:00 +00:00
|
|
|
common_dimm->rcw[11] << 16 | \
|
|
|
|
common_dimm->rcw[12] << 12 | \
|
|
|
|
common_dimm->rcw[13] << 8 | \
|
|
|
|
common_dimm->rcw[14] << 4 | \
|
2018-01-29 18:24:08 +00:00
|
|
|
rc0f;
|
|
|
|
ddr->ddr_sdram_rcw_3 =
|
|
|
|
((ddr_freq - 1260 + 19) / 20) << 8;
|
2011-01-10 12:03:00 +00:00
|
|
|
}
|
2018-01-29 17:44:33 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_rcw_1 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_rcw_1);
|
|
|
|
debug("FSLDDR: ddr_sdram_rcw_2 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_rcw_2);
|
|
|
|
debug("FSLDDR: ddr_sdram_rcw_3 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_rcw_3);
|
2010-07-02 22:25:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/* DDR SDRAM control configuration (DDR_SDRAM_CFG) */
|
|
|
|
static void set_ddr_sdram_cfg(fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm)
|
|
|
|
{
|
|
|
|
unsigned int mem_en; /* DDR SDRAM interface logic enable */
|
|
|
|
unsigned int sren; /* Self refresh enable (during sleep) */
|
|
|
|
unsigned int ecc_en; /* ECC enable. */
|
|
|
|
unsigned int rd_en; /* Registered DIMM enable */
|
|
|
|
unsigned int sdram_type; /* Type of SDRAM */
|
|
|
|
unsigned int dyn_pwr; /* Dynamic power management mode */
|
|
|
|
unsigned int dbw; /* DRAM dta bus width */
|
2008-11-21 08:31:29 +00:00
|
|
|
unsigned int eight_be = 0; /* 8-beat burst enable, DDR2 is zero */
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int ncap = 0; /* Non-concurrent auto-precharge */
|
2013-09-25 05:11:19 +00:00
|
|
|
unsigned int threet_en; /* Enable 3T timing */
|
|
|
|
unsigned int twot_en; /* Enable 2T timing */
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int ba_intlv_ctl; /* Bank (CS) interleaving control */
|
|
|
|
unsigned int x32_en = 0; /* x32 enable */
|
|
|
|
unsigned int pchb8 = 0; /* precharge bit 8 enable */
|
|
|
|
unsigned int hse; /* Global half strength override */
|
2014-09-05 05:52:41 +00:00
|
|
|
unsigned int acc_ecc_en = 0; /* Accumulated ECC enable */
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int mem_halt = 0; /* memory controller halt */
|
|
|
|
unsigned int bi = 0; /* Bypass initialization */
|
|
|
|
|
|
|
|
mem_en = 1;
|
|
|
|
sren = popts->self_refresh_in_sleep;
|
2013-09-25 05:11:19 +00:00
|
|
|
if (common_dimm->all_dimms_ecc_capable) {
|
2008-08-26 20:01:29 +00:00
|
|
|
/* Allow setting of ECC only if all DIMMs are ECC. */
|
2013-09-25 05:11:19 +00:00
|
|
|
ecc_en = popts->ecc_mode;
|
2008-08-26 20:01:29 +00:00
|
|
|
} else {
|
|
|
|
ecc_en = 0;
|
|
|
|
}
|
|
|
|
|
2013-09-25 05:11:19 +00:00
|
|
|
if (common_dimm->all_dimms_registered &&
|
|
|
|
!common_dimm->all_dimms_unbuffered) {
|
2011-01-10 12:03:00 +00:00
|
|
|
rd_en = 1;
|
2013-09-25 05:11:19 +00:00
|
|
|
twot_en = 0;
|
2011-01-10 12:03:00 +00:00
|
|
|
} else {
|
|
|
|
rd_en = 0;
|
2013-09-25 05:11:19 +00:00
|
|
|
twot_en = popts->twot_en;
|
2011-01-10 12:03:00 +00:00
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
sdram_type = CONFIG_FSL_SDRAM_TYPE;
|
|
|
|
|
|
|
|
dyn_pwr = popts->dynamic_power;
|
|
|
|
dbw = popts->data_bus_width;
|
2009-03-14 04:48:30 +00:00
|
|
|
/* 8-beat burst enable DDR-III case
|
|
|
|
* we must clear it when use the on-the-fly mode,
|
|
|
|
* must set it when use the 32-bits bus mode.
|
|
|
|
*/
|
2014-03-28 00:54:47 +00:00
|
|
|
if ((sdram_type == SDRAM_TYPE_DDR3) ||
|
|
|
|
(sdram_type == SDRAM_TYPE_DDR4)) {
|
2009-03-14 04:48:30 +00:00
|
|
|
if (popts->burst_length == DDR_BL8)
|
|
|
|
eight_be = 1;
|
|
|
|
if (popts->burst_length == DDR_OTF)
|
|
|
|
eight_be = 0;
|
|
|
|
if (dbw == 0x1)
|
|
|
|
eight_be = 1;
|
|
|
|
}
|
|
|
|
|
2013-09-25 05:11:19 +00:00
|
|
|
threet_en = popts->threet_en;
|
2008-08-26 20:01:29 +00:00
|
|
|
ba_intlv_ctl = popts->ba_intlv_ctl;
|
|
|
|
hse = popts->half_strength_driver_enable;
|
|
|
|
|
2014-09-05 05:52:41 +00:00
|
|
|
/* set when ddr bus width < 64 */
|
|
|
|
acc_ecc_en = (dbw != 0 && ecc_en == 1) ? 1 : 0;
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_sdram_cfg = (0
|
|
|
|
| ((mem_en & 0x1) << 31)
|
|
|
|
| ((sren & 0x1) << 30)
|
|
|
|
| ((ecc_en & 0x1) << 29)
|
|
|
|
| ((rd_en & 0x1) << 28)
|
|
|
|
| ((sdram_type & 0x7) << 24)
|
|
|
|
| ((dyn_pwr & 0x1) << 21)
|
|
|
|
| ((dbw & 0x3) << 19)
|
|
|
|
| ((eight_be & 0x1) << 18)
|
|
|
|
| ((ncap & 0x1) << 17)
|
2013-09-25 05:11:19 +00:00
|
|
|
| ((threet_en & 0x1) << 16)
|
|
|
|
| ((twot_en & 0x1) << 15)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((ba_intlv_ctl & 0x7F) << 8)
|
|
|
|
| ((x32_en & 0x1) << 5)
|
|
|
|
| ((pchb8 & 0x1) << 4)
|
|
|
|
| ((hse & 0x1) << 3)
|
2014-09-05 05:52:41 +00:00
|
|
|
| ((acc_ecc_en & 0x1) << 2)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((mem_halt & 0x1) << 1)
|
|
|
|
| ((bi & 0x1) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_cfg = 0x%08x\n", ddr->ddr_sdram_cfg);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR SDRAM control configuration 2 (DDR_SDRAM_CFG_2) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_cfg_2(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2011-01-10 12:03:00 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const unsigned int unq_mrs_en)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned int frc_sr = 0; /* Force self refresh */
|
|
|
|
unsigned int sr_ie = 0; /* Self-refresh interrupt enable */
|
2011-08-26 18:32:40 +00:00
|
|
|
unsigned int odt_cfg = 0; /* ODT configuration */
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int num_pr; /* Number of posted refreshes */
|
2012-10-08 07:44:22 +00:00
|
|
|
unsigned int slow = 0; /* DDR will be run less than 1250 */
|
2013-06-25 18:37:47 +00:00
|
|
|
unsigned int x4_en = 0; /* x4 DRAM enable */
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int obc_cfg; /* On-The-Fly Burst Chop Cfg */
|
|
|
|
unsigned int ap_en; /* Address Parity Enable */
|
|
|
|
unsigned int d_init; /* DRAM data initialization */
|
|
|
|
unsigned int rcw_en = 0; /* Register Control Word Enable */
|
|
|
|
unsigned int md_en = 0; /* Mirrored DIMM Enable */
|
2010-07-02 22:25:53 +00:00
|
|
|
unsigned int qd_en = 0; /* quad-rank DIMM Enable */
|
2011-08-26 18:32:40 +00:00
|
|
|
int i;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifndef CONFIG_SYS_FSL_DDR4
|
|
|
|
unsigned int dll_rst_dis = 1; /* DLL reset disable */
|
|
|
|
unsigned int dqs_cfg; /* DQS configuration */
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2013-09-25 05:11:19 +00:00
|
|
|
dqs_cfg = popts->dqs_config;
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2011-08-26 18:32:40 +00:00
|
|
|
for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
|
|
|
if (popts->cs_local_opts[i].odt_rd_cfg
|
|
|
|
|| popts->cs_local_opts[i].odt_wr_cfg) {
|
|
|
|
odt_cfg = SDRAM_CFG2_ODT_ONLY_READ;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
2015-10-14 14:32:00 +00:00
|
|
|
sr_ie = popts->self_refresh_interrupt_en;
|
2018-01-29 17:44:35 +00:00
|
|
|
num_pr = popts->package_3ds + 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 8572 manual says
|
|
|
|
* {TIMING_CFG_1[PRETOACT]
|
|
|
|
* + [DDR_SDRAM_CFG_2[NUM_PR]
|
|
|
|
* * ({EXT_REFREC || REFREC} + 8 + 2)]}
|
|
|
|
* << DDR_SDRAM_INTERVAL[REFINT]
|
|
|
|
*/
|
2014-03-28 00:54:47 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
|
2013-09-25 05:11:19 +00:00
|
|
|
obc_cfg = popts->otf_burst_chop_en;
|
2009-03-14 04:48:30 +00:00
|
|
|
#else
|
|
|
|
obc_cfg = 0;
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2012-10-08 07:44:22 +00:00
|
|
|
#if (CONFIG_SYS_FSL_DDR_VER >= FSL_DDR_VER_4_7)
|
2015-01-06 21:18:50 +00:00
|
|
|
slow = get_ddr_freq(ctrl_num) < 1249000000;
|
2012-10-08 07:44:22 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-10 09:36:56 +00:00
|
|
|
if (popts->registered_dimm_en)
|
2011-01-10 12:03:00 +00:00
|
|
|
rcw_en = 1;
|
2016-03-10 09:36:56 +00:00
|
|
|
|
|
|
|
/* DDR4 can have address parity for UDIMM and discrete */
|
|
|
|
if ((CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4) &&
|
|
|
|
(!popts->registered_dimm_en)) {
|
2011-01-10 12:03:00 +00:00
|
|
|
ap_en = 0;
|
2016-03-10 09:36:56 +00:00
|
|
|
} else {
|
|
|
|
ap_en = popts->ap_en;
|
2011-01-10 12:03:00 +00:00
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2013-06-25 18:37:47 +00:00
|
|
|
x4_en = popts->x4_en ? 1 : 0;
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
#if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
|
|
|
|
/* Use the DDR controller to auto initialize memory. */
|
2013-09-25 05:11:19 +00:00
|
|
|
d_init = popts->ecc_init_using_memctl;
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_data_init = CONFIG_MEM_INIT_VALUE;
|
|
|
|
debug("DDR: ddr_data_init = 0x%08x\n", ddr->ddr_data_init);
|
|
|
|
#else
|
|
|
|
/* Memory will be initialized via DMA, or not at all. */
|
|
|
|
d_init = 0;
|
|
|
|
#endif
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
|
2009-03-14 04:48:30 +00:00
|
|
|
md_en = popts->mirrored_dimm;
|
|
|
|
#endif
|
2010-07-02 22:25:53 +00:00
|
|
|
qd_en = popts->quad_rank_present ? 1 : 0;
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_sdram_cfg_2 = (0
|
|
|
|
| ((frc_sr & 0x1) << 31)
|
|
|
|
| ((sr_ie & 0x1) << 30)
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifndef CONFIG_SYS_FSL_DDR4
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((dll_rst_dis & 0x1) << 29)
|
|
|
|
| ((dqs_cfg & 0x3) << 26)
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((odt_cfg & 0x3) << 21)
|
|
|
|
| ((num_pr & 0xf) << 12)
|
2012-10-08 07:44:22 +00:00
|
|
|
| ((slow & 1) << 11)
|
2013-06-25 18:37:47 +00:00
|
|
|
| (x4_en << 10)
|
2010-07-02 22:25:53 +00:00
|
|
|
| (qd_en << 9)
|
2011-01-10 12:03:00 +00:00
|
|
|
| (unq_mrs_en << 8)
|
2008-08-26 20:01:29 +00:00
|
|
|
| ((obc_cfg & 0x1) << 6)
|
|
|
|
| ((ap_en & 0x1) << 5)
|
|
|
|
| ((d_init & 0x1) << 4)
|
|
|
|
| ((rcw_en & 0x1) << 2)
|
|
|
|
| ((md_en & 0x1) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_cfg_2 = 0x%08x\n", ddr->ddr_sdram_cfg_2);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
2008-08-26 20:01:29 +00:00
|
|
|
/* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode_2(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2011-01-10 12:03:00 +00:00
|
|
|
const memctl_options_t *popts,
|
2013-10-18 09:47:20 +00:00
|
|
|
const common_timing_params_t *common_dimm,
|
2011-01-10 12:03:00 +00:00
|
|
|
const unsigned int unq_mrs_en)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned short esdmode2 = 0; /* Extended SDRAM mode 2 */
|
|
|
|
unsigned short esdmode3 = 0; /* Extended SDRAM mode 3 */
|
2014-03-28 00:54:47 +00:00
|
|
|
int i;
|
|
|
|
unsigned int wr_crc = 0; /* Disable */
|
|
|
|
unsigned int rtt_wr = 0; /* Rtt_WR - dynamic ODT off */
|
|
|
|
unsigned int srt = 0; /* self-refresh temerature, normal range */
|
2015-01-06 21:18:50 +00:00
|
|
|
unsigned int cwl = compute_cas_write_latency(ctrl_num) - 9;
|
2014-03-28 00:54:47 +00:00
|
|
|
unsigned int mpr = 0; /* serial */
|
|
|
|
unsigned int wc_lat;
|
2015-01-06 21:18:50 +00:00
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt_wr = popts->rtt_wr_override_value;
|
|
|
|
else
|
|
|
|
rtt_wr = popts->cs_local_opts[0].odt_rtt_wr;
|
|
|
|
|
|
|
|
if (common_dimm->extended_op_srt)
|
|
|
|
srt = common_dimm->extended_op_srt;
|
|
|
|
|
|
|
|
esdmode2 = (0
|
|
|
|
| ((wr_crc & 0x1) << 12)
|
|
|
|
| ((rtt_wr & 0x3) << 9)
|
|
|
|
| ((srt & 0x3) << 6)
|
|
|
|
| ((cwl & 0x7) << 3));
|
|
|
|
|
|
|
|
if (mclk_ps >= 1250)
|
|
|
|
wc_lat = 0;
|
|
|
|
else if (mclk_ps >= 833)
|
|
|
|
wc_lat = 1;
|
|
|
|
else
|
|
|
|
wc_lat = 2;
|
|
|
|
|
|
|
|
esdmode3 = (0
|
|
|
|
| ((mpr & 0x3) << 11)
|
|
|
|
| ((wc_lat & 0x3) << 9));
|
|
|
|
|
|
|
|
ddr->ddr_sdram_mode_2 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_2 = 0x%08x\n", ddr->ddr_sdram_mode_2);
|
|
|
|
|
|
|
|
if (unq_mrs_en) { /* unique mode registers are supported */
|
|
|
|
for (i = 1; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt_wr = popts->rtt_wr_override_value;
|
|
|
|
else
|
|
|
|
rtt_wr = popts->cs_local_opts[i].odt_rtt_wr;
|
|
|
|
|
|
|
|
esdmode2 &= 0xF9FF; /* clear bit 10, 9 */
|
|
|
|
esdmode2 |= (rtt_wr & 0x3) << 9;
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
ddr->ddr_sdram_mode_4 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddr->ddr_sdram_mode_6 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ddr->ddr_sdram_mode_8 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_4 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_4);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_6 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_6);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_8 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_8);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3)
|
|
|
|
/* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode_2(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2014-03-28 00:54:47 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
const unsigned int unq_mrs_en)
|
|
|
|
{
|
|
|
|
unsigned short esdmode2 = 0; /* Extended SDRAM mode 2 */
|
|
|
|
unsigned short esdmode3 = 0; /* Extended SDRAM mode 3 */
|
2011-01-20 07:53:15 +00:00
|
|
|
int i;
|
2009-12-16 16:24:38 +00:00
|
|
|
unsigned int rtt_wr = 0; /* Rtt_WR - dynamic ODT off */
|
2009-03-14 04:48:30 +00:00
|
|
|
unsigned int srt = 0; /* self-refresh temerature, normal range */
|
|
|
|
unsigned int asr = 0; /* auto self-refresh disable */
|
2015-01-06 21:18:50 +00:00
|
|
|
unsigned int cwl = compute_cas_write_latency(ctrl_num) - 5;
|
2009-03-14 04:48:30 +00:00
|
|
|
unsigned int pasr = 0; /* partial array self refresh disable */
|
|
|
|
|
2009-12-16 16:24:38 +00:00
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt_wr = popts->rtt_wr_override_value;
|
2011-01-10 12:03:00 +00:00
|
|
|
else
|
|
|
|
rtt_wr = popts->cs_local_opts[0].odt_rtt_wr;
|
2013-10-18 09:47:20 +00:00
|
|
|
|
|
|
|
if (common_dimm->extended_op_srt)
|
|
|
|
srt = common_dimm->extended_op_srt;
|
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
esdmode2 = (0
|
|
|
|
| ((rtt_wr & 0x3) << 9)
|
|
|
|
| ((srt & 0x1) << 7)
|
|
|
|
| ((asr & 0x1) << 6)
|
|
|
|
| ((cwl & 0x7) << 3)
|
|
|
|
| ((pasr & 0x7) << 0));
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_sdram_mode_2 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_mode_2 = 0x%08x\n", ddr->ddr_sdram_mode_2);
|
2011-01-10 12:03:00 +00:00
|
|
|
|
|
|
|
if (unq_mrs_en) { /* unique mode registers are supported */
|
2011-11-09 16:05:10 +00:00
|
|
|
for (i = 1; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
2011-01-10 12:03:00 +00:00
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt_wr = popts->rtt_wr_override_value;
|
|
|
|
else
|
|
|
|
rtt_wr = popts->cs_local_opts[i].odt_rtt_wr;
|
|
|
|
|
|
|
|
esdmode2 &= 0xF9FF; /* clear bit 10, 9 */
|
|
|
|
esdmode2 |= (rtt_wr & 0x3) << 9;
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
ddr->ddr_sdram_mode_4 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddr->ddr_sdram_mode_6 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ddr->ddr_sdram_mode_8 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_4 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_4);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_6 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_6);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_8 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_8);
|
|
|
|
}
|
2014-03-28 00:54:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else /* for DDR2 and DDR1 */
|
|
|
|
/* DDR SDRAM Mode configuration 2 (DDR_SDRAM_MODE_2) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode_2(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2014-03-28 00:54:47 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
const unsigned int unq_mrs_en)
|
|
|
|
{
|
|
|
|
unsigned short esdmode2 = 0; /* Extended SDRAM mode 2 */
|
|
|
|
unsigned short esdmode3 = 0; /* Extended SDRAM mode 3 */
|
|
|
|
|
|
|
|
ddr->ddr_sdram_mode_2 = (0
|
|
|
|
| ((esdmode2 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode3 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_2 = 0x%08x\n", ddr->ddr_sdram_mode_2);
|
|
|
|
}
|
2011-01-10 12:03:00 +00:00
|
|
|
#endif
|
2014-03-28 00:54:47 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
/* DDR SDRAM Mode configuration 9 (DDR_SDRAM_MODE_9) */
|
|
|
|
static void set_ddr_sdram_mode_9(fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
const unsigned int unq_mrs_en)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned short esdmode4 = 0; /* Extended SDRAM mode 4 */
|
|
|
|
unsigned short esdmode5; /* Extended SDRAM mode 5 */
|
2015-03-19 16:30:27 +00:00
|
|
|
int rtt_park = 0;
|
2015-11-04 18:03:19 +00:00
|
|
|
bool four_cs = false;
|
2016-03-10 09:36:56 +00:00
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(0);
|
2015-11-04 18:03:19 +00:00
|
|
|
|
|
|
|
#if CONFIG_CHIP_SELECTS_PER_CTRL == 4
|
|
|
|
if ((ddr->cs[0].config & SDRAM_CS_CONFIG_EN) &&
|
|
|
|
(ddr->cs[1].config & SDRAM_CS_CONFIG_EN) &&
|
|
|
|
(ddr->cs[2].config & SDRAM_CS_CONFIG_EN) &&
|
|
|
|
(ddr->cs[3].config & SDRAM_CS_CONFIG_EN))
|
|
|
|
four_cs = true;
|
|
|
|
#endif
|
2015-03-19 16:30:27 +00:00
|
|
|
if (ddr->cs[0].config & SDRAM_CS_CONFIG_EN) {
|
|
|
|
esdmode5 = 0x00000500; /* Data mask enable, RTT_PARK CS0 */
|
2015-11-04 18:03:19 +00:00
|
|
|
rtt_park = four_cs ? 0 : 1;
|
2015-03-19 16:30:27 +00:00
|
|
|
} else {
|
|
|
|
esdmode5 = 0x00000400; /* Data mask enabled */
|
|
|
|
}
|
2014-03-28 00:54:47 +00:00
|
|
|
|
2018-01-29 17:44:33 +00:00
|
|
|
/*
|
|
|
|
* For DDR3, set C/A latency if address parity is enabled.
|
|
|
|
* For DDR4, set C/A latency for UDIMM only. For RDIMM the delay is
|
|
|
|
* handled by register chip and RCW settings.
|
|
|
|
*/
|
|
|
|
if ((ddr->ddr_sdram_cfg_2 & SDRAM_CFG2_AP_EN) &&
|
|
|
|
((CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4) ||
|
|
|
|
!popts->registered_dimm_en)) {
|
2016-03-10 09:36:56 +00:00
|
|
|
if (mclk_ps >= 935) {
|
|
|
|
/* for DDR4-1600/1866/2133 */
|
|
|
|
esdmode5 |= DDR_MR5_CA_PARITY_LAT_4_CLK;
|
|
|
|
} else if (mclk_ps >= 833) {
|
|
|
|
/* for DDR4-2400 */
|
|
|
|
esdmode5 |= DDR_MR5_CA_PARITY_LAT_5_CLK;
|
|
|
|
} else {
|
|
|
|
printf("parity: mclk_ps = %d not supported\n", mclk_ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
ddr->ddr_sdram_mode_9 = (0
|
|
|
|
| ((esdmode4 & 0xffff) << 16)
|
|
|
|
| ((esdmode5 & 0xffff) << 0)
|
|
|
|
);
|
2015-03-19 16:30:26 +00:00
|
|
|
|
2015-11-04 18:03:19 +00:00
|
|
|
/* Normally only the first enabled CS use 0x500, others use 0x400
|
|
|
|
* But when four chip-selects are all enabled, all mode registers
|
|
|
|
* need 0x500 to park.
|
|
|
|
*/
|
2015-03-19 16:30:26 +00:00
|
|
|
|
2018-01-29 17:44:35 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_mode_9 = 0x%08x\n", ddr->ddr_sdram_mode_9);
|
2014-03-28 00:54:47 +00:00
|
|
|
if (unq_mrs_en) { /* unique mode registers are supported */
|
|
|
|
for (i = 1; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
2015-03-19 16:30:27 +00:00
|
|
|
if (!rtt_park &&
|
|
|
|
(ddr->cs[i].config & SDRAM_CS_CONFIG_EN)) {
|
|
|
|
esdmode5 |= 0x00000500; /* RTT_PARK */
|
2015-11-04 18:03:19 +00:00
|
|
|
rtt_park = four_cs ? 0 : 1;
|
2015-03-19 16:30:27 +00:00
|
|
|
} else {
|
|
|
|
esdmode5 = 0x00000400;
|
|
|
|
}
|
2016-03-10 09:36:56 +00:00
|
|
|
|
2018-01-29 17:44:33 +00:00
|
|
|
if ((ddr->ddr_sdram_cfg_2 & SDRAM_CFG2_AP_EN) &&
|
|
|
|
((CONFIG_FSL_SDRAM_TYPE != SDRAM_TYPE_DDR4) ||
|
|
|
|
!popts->registered_dimm_en)) {
|
2016-03-10 09:36:56 +00:00
|
|
|
if (mclk_ps >= 935) {
|
|
|
|
/* for DDR4-1600/1866/2133 */
|
|
|
|
esdmode5 |= DDR_MR5_CA_PARITY_LAT_4_CLK;
|
|
|
|
} else if (mclk_ps >= 833) {
|
|
|
|
/* for DDR4-2400 */
|
|
|
|
esdmode5 |= DDR_MR5_CA_PARITY_LAT_5_CLK;
|
|
|
|
} else {
|
|
|
|
printf("parity: mclk_ps = %d not supported\n",
|
|
|
|
mclk_ps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
ddr->ddr_sdram_mode_11 = (0
|
|
|
|
| ((esdmode4 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode5 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddr->ddr_sdram_mode_13 = (0
|
|
|
|
| ((esdmode4 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode5 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ddr->ddr_sdram_mode_15 = (0
|
|
|
|
| ((esdmode4 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode5 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_11 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_11);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_13 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_13);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_15 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_15);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR SDRAM Mode configuration 10 (DDR_SDRAM_MODE_10) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode_10(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2014-03-28 00:54:47 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
const unsigned int unq_mrs_en)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned short esdmode6 = 0; /* Extended SDRAM mode 6 */
|
|
|
|
unsigned short esdmode7 = 0; /* Extended SDRAM mode 7 */
|
2015-01-06 21:18:50 +00:00
|
|
|
unsigned int tccdl_min = picos_to_mclk(ctrl_num, common_dimm->tccdl_ps);
|
2014-03-28 00:54:47 +00:00
|
|
|
|
|
|
|
esdmode6 = ((tccdl_min - 4) & 0x7) << 10;
|
|
|
|
|
2015-11-04 18:03:18 +00:00
|
|
|
if (popts->ddr_cdr2 & DDR_CDR2_VREF_RANGE_2)
|
|
|
|
esdmode6 |= 1 << 6; /* Range 2 */
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
ddr->ddr_sdram_mode_10 = (0
|
|
|
|
| ((esdmode6 & 0xffff) << 16)
|
|
|
|
| ((esdmode7 & 0xffff) << 0)
|
|
|
|
);
|
2018-01-29 17:44:35 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_mode_10 = 0x%08x\n", ddr->ddr_sdram_mode_10);
|
2014-03-28 00:54:47 +00:00
|
|
|
if (unq_mrs_en) { /* unique mode registers are supported */
|
|
|
|
for (i = 1; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
ddr->ddr_sdram_mode_12 = (0
|
|
|
|
| ((esdmode6 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode7 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddr->ddr_sdram_mode_14 = (0
|
|
|
|
| ((esdmode6 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode7 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ddr->ddr_sdram_mode_16 = (0
|
|
|
|
| ((esdmode6 & 0xFFFF) << 16)
|
|
|
|
| ((esdmode7 & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_12 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_12);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_14 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_14);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_16 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_16);
|
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/* DDR SDRAM Interval Configuration (DDR_SDRAM_INTERVAL) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_interval(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned int refint; /* Refresh interval */
|
|
|
|
unsigned int bstopre; /* Precharge interval */
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
refint = picos_to_mclk(ctrl_num, common_dimm->refresh_rate_ps);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
bstopre = popts->bstopre;
|
|
|
|
|
|
|
|
/* refint field used 0x3FFF in earlier controllers */
|
|
|
|
ddr->ddr_sdram_interval = (0
|
|
|
|
| ((refint & 0xFFFF) << 16)
|
|
|
|
| ((bstopre & 0x3FFF) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_interval = 0x%08x\n", ddr->ddr_sdram_interval);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
2009-03-14 04:48:30 +00:00
|
|
|
/* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2009-03-14 04:48:30 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency,
|
2011-01-10 12:03:00 +00:00
|
|
|
unsigned int additive_latency,
|
|
|
|
const unsigned int unq_mrs_en)
|
2009-03-14 04:48:30 +00:00
|
|
|
{
|
2014-03-28 00:54:47 +00:00
|
|
|
int i;
|
|
|
|
unsigned short esdmode; /* Extended SDRAM mode */
|
|
|
|
unsigned short sdmode; /* SDRAM mode */
|
|
|
|
|
|
|
|
/* Mode Register - MR1 */
|
|
|
|
unsigned int qoff = 0; /* Output buffer enable 0=yes, 1=no */
|
|
|
|
unsigned int tdqs_en = 0; /* TDQS Enable: 0=no, 1=yes */
|
|
|
|
unsigned int rtt;
|
|
|
|
unsigned int wrlvl_en = 0; /* Write level enable: 0=no, 1=yes */
|
|
|
|
unsigned int al = 0; /* Posted CAS# additive latency (AL) */
|
|
|
|
unsigned int dic = 0; /* Output driver impedance, 40ohm */
|
|
|
|
unsigned int dll_en = 1; /* DLL Enable 1=Enable (Normal),
|
|
|
|
0=Disable (Test/Debug) */
|
|
|
|
|
|
|
|
/* Mode Register - MR0 */
|
|
|
|
unsigned int wr = 0; /* Write Recovery */
|
|
|
|
unsigned int dll_rst; /* DLL Reset */
|
|
|
|
unsigned int mode; /* Normal=0 or Test=1 */
|
|
|
|
unsigned int caslat = 4;/* CAS# latency, default set as 6 cycles */
|
|
|
|
/* BT: Burst Type (0=Nibble Sequential, 1=Interleaved) */
|
|
|
|
unsigned int bt;
|
|
|
|
unsigned int bl; /* BL: Burst Length */
|
|
|
|
|
|
|
|
unsigned int wr_mclk;
|
|
|
|
/* DDR4 support WR 10, 12, 14, 16, 18, 20, 24 */
|
|
|
|
static const u8 wr_table[] = {
|
|
|
|
0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 6, 6};
|
|
|
|
/* DDR4 support CAS 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24 */
|
|
|
|
static const u8 cas_latency_table[] = {
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 8,
|
|
|
|
9, 9, 10, 10, 11, 11};
|
|
|
|
|
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt = popts->rtt_override_value;
|
|
|
|
else
|
|
|
|
rtt = popts->cs_local_opts[0].odt_rtt_norm;
|
|
|
|
|
|
|
|
if (additive_latency == (cas_latency - 1))
|
|
|
|
al = 1;
|
|
|
|
if (additive_latency == (cas_latency - 2))
|
|
|
|
al = 2;
|
|
|
|
|
|
|
|
if (popts->quad_rank_present)
|
|
|
|
dic = 1; /* output driver impedance 240/7 ohm */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The esdmode value will also be used for writing
|
|
|
|
* MR1 during write leveling for DDR3, although the
|
|
|
|
* bits specifically related to the write leveling
|
|
|
|
* scheme will be handled automatically by the DDR
|
|
|
|
* controller. so we set the wrlvl_en = 0 here.
|
|
|
|
*/
|
|
|
|
esdmode = (0
|
|
|
|
| ((qoff & 0x1) << 12)
|
|
|
|
| ((tdqs_en & 0x1) << 11)
|
|
|
|
| ((rtt & 0x7) << 8)
|
|
|
|
| ((wrlvl_en & 0x1) << 7)
|
|
|
|
| ((al & 0x3) << 3)
|
|
|
|
| ((dic & 0x3) << 1) /* DIC field is split */
|
|
|
|
| ((dll_en & 0x1) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DLL control for precharge PD
|
|
|
|
* 0=slow exit DLL off (tXPDLL)
|
|
|
|
* 1=fast exit DLL on (tXP)
|
|
|
|
*/
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
wr_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
|
2014-03-28 00:54:47 +00:00
|
|
|
if (wr_mclk <= 24) {
|
|
|
|
wr = wr_table[wr_mclk - 10];
|
|
|
|
} else {
|
|
|
|
printf("Error: unsupported write recovery for mode register wr_mclk = %d\n",
|
|
|
|
wr_mclk);
|
|
|
|
}
|
|
|
|
|
|
|
|
dll_rst = 0; /* dll no reset */
|
|
|
|
mode = 0; /* normal mode */
|
|
|
|
|
|
|
|
/* look up table to get the cas latency bits */
|
|
|
|
if (cas_latency >= 9 && cas_latency <= 24)
|
|
|
|
caslat = cas_latency_table[cas_latency - 9];
|
|
|
|
else
|
|
|
|
printf("Error: unsupported cas latency for mode register\n");
|
|
|
|
|
|
|
|
bt = 0; /* Nibble sequential */
|
|
|
|
|
|
|
|
switch (popts->burst_length) {
|
|
|
|
case DDR_BL8:
|
|
|
|
bl = 0;
|
|
|
|
break;
|
|
|
|
case DDR_OTF:
|
|
|
|
bl = 1;
|
|
|
|
break;
|
|
|
|
case DDR_BC4:
|
|
|
|
bl = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Error: invalid burst length of %u specified. ",
|
|
|
|
popts->burst_length);
|
|
|
|
puts("Defaulting to on-the-fly BC4 or BL8 beats.\n");
|
|
|
|
bl = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdmode = (0
|
|
|
|
| ((wr & 0x7) << 9)
|
|
|
|
| ((dll_rst & 0x1) << 8)
|
|
|
|
| ((mode & 0x1) << 7)
|
|
|
|
| (((caslat >> 1) & 0x7) << 4)
|
|
|
|
| ((bt & 0x1) << 3)
|
|
|
|
| ((caslat & 1) << 2)
|
|
|
|
| ((bl & 0x3) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
ddr->ddr_sdram_mode = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
debug("FSLDDR: ddr_sdram_mode = 0x%08x\n", ddr->ddr_sdram_mode);
|
|
|
|
|
|
|
|
if (unq_mrs_en) { /* unique mode registers are supported */
|
|
|
|
for (i = 1; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt = popts->rtt_override_value;
|
|
|
|
else
|
|
|
|
rtt = popts->cs_local_opts[i].odt_rtt_norm;
|
|
|
|
|
|
|
|
esdmode &= 0xF8FF; /* clear bit 10,9,8 for rtt */
|
|
|
|
esdmode |= (rtt & 0x7) << 8;
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
ddr->ddr_sdram_mode_3 = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddr->ddr_sdram_mode_5 = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ddr->ddr_sdram_mode_7 = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_3 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_3);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_5 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_5);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_5 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3)
|
|
|
|
/* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2014-03-28 00:54:47 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency,
|
|
|
|
unsigned int additive_latency,
|
|
|
|
const unsigned int unq_mrs_en)
|
|
|
|
{
|
|
|
|
int i;
|
2009-03-14 04:48:30 +00:00
|
|
|
unsigned short esdmode; /* Extended SDRAM mode */
|
|
|
|
unsigned short sdmode; /* SDRAM mode */
|
|
|
|
|
|
|
|
/* Mode Register - MR1 */
|
|
|
|
unsigned int qoff = 0; /* Output buffer enable 0=yes, 1=no */
|
|
|
|
unsigned int tdqs_en = 0; /* TDQS Enable: 0=no, 1=yes */
|
|
|
|
unsigned int rtt;
|
|
|
|
unsigned int wrlvl_en = 0; /* Write level enable: 0=no, 1=yes */
|
|
|
|
unsigned int al = 0; /* Posted CAS# additive latency (AL) */
|
2011-01-10 12:03:00 +00:00
|
|
|
unsigned int dic = 0; /* Output driver impedance, 40ohm */
|
2009-03-14 04:48:30 +00:00
|
|
|
unsigned int dll_en = 0; /* DLL Enable 0=Enable (Normal),
|
|
|
|
1=Disable (Test/Debug) */
|
|
|
|
|
|
|
|
/* Mode Register - MR0 */
|
|
|
|
unsigned int dll_on; /* DLL control for precharge PD, 0=off, 1=on */
|
2012-08-17 08:22:38 +00:00
|
|
|
unsigned int wr = 0; /* Write Recovery */
|
2009-03-14 04:48:30 +00:00
|
|
|
unsigned int dll_rst; /* DLL Reset */
|
|
|
|
unsigned int mode; /* Normal=0 or Test=1 */
|
|
|
|
unsigned int caslat = 4;/* CAS# latency, default set as 6 cycles */
|
|
|
|
/* BT: Burst Type (0=Nibble Sequential, 1=Interleaved) */
|
|
|
|
unsigned int bt;
|
|
|
|
unsigned int bl; /* BL: Burst Length */
|
|
|
|
|
|
|
|
unsigned int wr_mclk;
|
2011-03-02 22:24:11 +00:00
|
|
|
/*
|
|
|
|
* DDR_SDRAM_MODE doesn't support 9,11,13,15
|
|
|
|
* Please refer JEDEC Standard No. 79-3E for Mode Register MR0
|
|
|
|
* for this table
|
|
|
|
*/
|
|
|
|
static const u8 wr_table[] = {1, 2, 3, 4, 5, 5, 6, 6, 7, 7, 0, 0};
|
2009-03-14 04:48:30 +00:00
|
|
|
|
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt = popts->rtt_override_value;
|
2011-01-10 12:03:00 +00:00
|
|
|
else
|
|
|
|
rtt = popts->cs_local_opts[0].odt_rtt_norm;
|
2009-03-14 04:48:30 +00:00
|
|
|
|
|
|
|
if (additive_latency == (cas_latency - 1))
|
|
|
|
al = 1;
|
|
|
|
if (additive_latency == (cas_latency - 2))
|
|
|
|
al = 2;
|
|
|
|
|
2011-01-10 12:03:00 +00:00
|
|
|
if (popts->quad_rank_present)
|
|
|
|
dic = 1; /* output driver impedance 240/7 ohm */
|
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* The esdmode value will also be used for writing
|
|
|
|
* MR1 during write leveling for DDR3, although the
|
|
|
|
* bits specifically related to the write leveling
|
|
|
|
* scheme will be handled automatically by the DDR
|
|
|
|
* controller. so we set the wrlvl_en = 0 here.
|
|
|
|
*/
|
|
|
|
esdmode = (0
|
|
|
|
| ((qoff & 0x1) << 12)
|
|
|
|
| ((tdqs_en & 0x1) << 11)
|
2009-09-10 19:54:55 +00:00
|
|
|
| ((rtt & 0x4) << 7) /* rtt field is split */
|
2009-03-14 04:48:30 +00:00
|
|
|
| ((wrlvl_en & 0x1) << 7)
|
2009-09-10 19:54:55 +00:00
|
|
|
| ((rtt & 0x2) << 5) /* rtt field is split */
|
|
|
|
| ((dic & 0x2) << 4) /* DIC field is split */
|
2009-03-14 04:48:30 +00:00
|
|
|
| ((al & 0x3) << 3)
|
2009-09-10 19:54:55 +00:00
|
|
|
| ((rtt & 0x1) << 2) /* rtt field is split */
|
2009-03-14 04:48:30 +00:00
|
|
|
| ((dic & 0x1) << 1) /* DIC field is split */
|
|
|
|
| ((dll_en & 0x1) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DLL control for precharge PD
|
|
|
|
* 0=slow exit DLL off (tXPDLL)
|
|
|
|
* 1=fast exit DLL on (tXP)
|
|
|
|
*/
|
|
|
|
dll_on = 1;
|
2011-03-02 22:24:11 +00:00
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
wr_mclk = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
|
2012-08-17 08:22:38 +00:00
|
|
|
if (wr_mclk <= 16) {
|
|
|
|
wr = wr_table[wr_mclk - 5];
|
|
|
|
} else {
|
|
|
|
printf("Error: unsupported write recovery for mode register "
|
|
|
|
"wr_mclk = %d\n", wr_mclk);
|
|
|
|
}
|
2011-03-02 22:24:11 +00:00
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
dll_rst = 0; /* dll no reset */
|
|
|
|
mode = 0; /* normal mode */
|
|
|
|
|
|
|
|
/* look up table to get the cas latency bits */
|
2012-08-17 08:22:38 +00:00
|
|
|
if (cas_latency >= 5 && cas_latency <= 16) {
|
|
|
|
unsigned char cas_latency_table[] = {
|
2009-03-14 04:48:30 +00:00
|
|
|
0x2, /* 5 clocks */
|
|
|
|
0x4, /* 6 clocks */
|
|
|
|
0x6, /* 7 clocks */
|
|
|
|
0x8, /* 8 clocks */
|
|
|
|
0xa, /* 9 clocks */
|
|
|
|
0xc, /* 10 clocks */
|
2012-08-17 08:22:38 +00:00
|
|
|
0xe, /* 11 clocks */
|
|
|
|
0x1, /* 12 clocks */
|
|
|
|
0x3, /* 13 clocks */
|
|
|
|
0x5, /* 14 clocks */
|
|
|
|
0x7, /* 15 clocks */
|
|
|
|
0x9, /* 16 clocks */
|
2009-03-14 04:48:30 +00:00
|
|
|
};
|
|
|
|
caslat = cas_latency_table[cas_latency - 5];
|
2012-08-17 08:22:38 +00:00
|
|
|
} else {
|
|
|
|
printf("Error: unsupported cas latency for mode register\n");
|
2009-03-14 04:48:30 +00:00
|
|
|
}
|
2012-08-17 08:22:38 +00:00
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
bt = 0; /* Nibble sequential */
|
|
|
|
|
|
|
|
switch (popts->burst_length) {
|
|
|
|
case DDR_BL8:
|
|
|
|
bl = 0;
|
|
|
|
break;
|
|
|
|
case DDR_OTF:
|
|
|
|
bl = 1;
|
|
|
|
break;
|
|
|
|
case DDR_BC4:
|
|
|
|
bl = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Error: invalid burst length of %u specified. "
|
|
|
|
" Defaulting to on-the-fly BC4 or BL8 beats.\n",
|
|
|
|
popts->burst_length);
|
|
|
|
bl = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdmode = (0
|
|
|
|
| ((dll_on & 0x1) << 12)
|
|
|
|
| ((wr & 0x7) << 9)
|
|
|
|
| ((dll_rst & 0x1) << 8)
|
|
|
|
| ((mode & 0x1) << 7)
|
|
|
|
| (((caslat >> 1) & 0x7) << 4)
|
|
|
|
| ((bt & 0x1) << 3)
|
2012-08-17 08:22:38 +00:00
|
|
|
| ((caslat & 1) << 2)
|
2009-03-14 04:48:30 +00:00
|
|
|
| ((bl & 0x3) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
ddr->ddr_sdram_mode = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
debug("FSLDDR: ddr_sdram_mode = 0x%08x\n", ddr->ddr_sdram_mode);
|
2011-01-10 12:03:00 +00:00
|
|
|
|
|
|
|
if (unq_mrs_en) { /* unique mode registers are supported */
|
2011-11-09 16:05:10 +00:00
|
|
|
for (i = 1; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
2011-01-10 12:03:00 +00:00
|
|
|
if (popts->rtt_override)
|
|
|
|
rtt = popts->rtt_override_value;
|
|
|
|
else
|
|
|
|
rtt = popts->cs_local_opts[i].odt_rtt_norm;
|
|
|
|
|
|
|
|
esdmode &= 0xFDBB; /* clear bit 9,6,2 */
|
|
|
|
esdmode |= (0
|
|
|
|
| ((rtt & 0x4) << 7) /* rtt field is split */
|
|
|
|
| ((rtt & 0x2) << 5) /* rtt field is split */
|
|
|
|
| ((rtt & 0x1) << 2) /* rtt field is split */
|
|
|
|
);
|
|
|
|
switch (i) {
|
|
|
|
case 1:
|
|
|
|
ddr->ddr_sdram_mode_3 = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ddr->ddr_sdram_mode_5 = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
ddr->ddr_sdram_mode_7 = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_3 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_3);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_5 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_5);
|
|
|
|
debug("FSLDDR: ddr_sdram_mode_5 = 0x%08x\n",
|
|
|
|
ddr->ddr_sdram_mode_5);
|
|
|
|
}
|
2009-03-14 04:48:30 +00:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#else /* !CONFIG_SYS_FSL_DDR3 */
|
2009-03-14 04:48:30 +00:00
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/* DDR SDRAM Mode configuration set (DDR_SDRAM_MODE) */
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_ddr_sdram_mode(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2008-08-26 20:01:29 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency,
|
2011-01-10 12:03:00 +00:00
|
|
|
unsigned int additive_latency,
|
|
|
|
const unsigned int unq_mrs_en)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned short esdmode; /* Extended SDRAM mode */
|
|
|
|
unsigned short sdmode; /* SDRAM mode */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: This ought to be pre-calculated in a
|
|
|
|
* technology-specific routine,
|
|
|
|
* e.g. compute_DDR2_mode_register(), and then the
|
|
|
|
* sdmode and esdmode passed in as part of common_dimm.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Extended Mode Register */
|
|
|
|
unsigned int mrs = 0; /* Mode Register Set */
|
|
|
|
unsigned int outputs = 0; /* 0=Enabled, 1=Disabled */
|
|
|
|
unsigned int rdqs_en = 0; /* RDQS Enable: 0=no, 1=yes */
|
|
|
|
unsigned int dqs_en = 0; /* DQS# Enable: 0=enable, 1=disable */
|
|
|
|
unsigned int ocd = 0; /* 0x0=OCD not supported,
|
|
|
|
0x7=OCD default state */
|
|
|
|
unsigned int rtt;
|
|
|
|
unsigned int al; /* Posted CAS# additive latency (AL) */
|
|
|
|
unsigned int ods = 0; /* Output Drive Strength:
|
|
|
|
0 = Full strength (18ohm)
|
|
|
|
1 = Reduced strength (4ohm) */
|
|
|
|
unsigned int dll_en = 0; /* DLL Enable 0=Enable (Normal),
|
|
|
|
1=Disable (Test/Debug) */
|
|
|
|
|
|
|
|
/* Mode Register (MR) */
|
|
|
|
unsigned int mr; /* Mode Register Definition */
|
|
|
|
unsigned int pd; /* Power-Down Mode */
|
|
|
|
unsigned int wr; /* Write Recovery */
|
|
|
|
unsigned int dll_res; /* DLL Reset */
|
|
|
|
unsigned int mode; /* Normal=0 or Test=1 */
|
2008-09-05 19:40:29 +00:00
|
|
|
unsigned int caslat = 0;/* CAS# latency */
|
2008-08-26 20:01:29 +00:00
|
|
|
/* BT: Burst Type (0=Sequential, 1=Interleaved) */
|
|
|
|
unsigned int bt;
|
|
|
|
unsigned int bl; /* BL: Burst Length */
|
|
|
|
|
2013-09-25 05:11:19 +00:00
|
|
|
dqs_en = !popts->dqs_config;
|
2008-08-26 20:01:29 +00:00
|
|
|
rtt = fsl_ddr_get_rtt();
|
|
|
|
|
|
|
|
al = additive_latency;
|
|
|
|
|
|
|
|
esdmode = (0
|
|
|
|
| ((mrs & 0x3) << 14)
|
|
|
|
| ((outputs & 0x1) << 12)
|
|
|
|
| ((rdqs_en & 0x1) << 11)
|
|
|
|
| ((dqs_en & 0x1) << 10)
|
|
|
|
| ((ocd & 0x7) << 7)
|
|
|
|
| ((rtt & 0x2) << 5) /* rtt field is split */
|
|
|
|
| ((al & 0x7) << 3)
|
|
|
|
| ((rtt & 0x1) << 2) /* rtt field is split */
|
|
|
|
| ((ods & 0x1) << 1)
|
|
|
|
| ((dll_en & 0x1) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
mr = 0; /* FIXME: CHECKME */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 0 = Fast Exit (Normal)
|
|
|
|
* 1 = Slow Exit (Low Power)
|
|
|
|
*/
|
|
|
|
pd = 0;
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR1)
|
2008-08-26 20:01:29 +00:00
|
|
|
wr = 0; /* Historical */
|
2013-09-30 16:22:09 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR2)
|
2015-01-06 21:18:50 +00:00
|
|
|
wr = picos_to_mclk(ctrl_num, common_dimm->twr_ps);
|
2008-08-26 20:01:29 +00:00
|
|
|
#endif
|
|
|
|
dll_res = 0;
|
|
|
|
mode = 0;
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR1)
|
2008-08-26 20:01:29 +00:00
|
|
|
if (1 <= cas_latency && cas_latency <= 4) {
|
|
|
|
unsigned char mode_caslat_table[4] = {
|
|
|
|
0x5, /* 1.5 clocks */
|
|
|
|
0x2, /* 2.0 clocks */
|
|
|
|
0x6, /* 2.5 clocks */
|
|
|
|
0x3 /* 3.0 clocks */
|
|
|
|
};
|
2008-09-05 19:40:29 +00:00
|
|
|
caslat = mode_caslat_table[cas_latency - 1];
|
|
|
|
} else {
|
|
|
|
printf("Warning: unknown cas_latency %d\n", cas_latency);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
2013-09-30 16:22:09 +00:00
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR2)
|
2008-08-26 20:01:29 +00:00
|
|
|
caslat = cas_latency;
|
|
|
|
#endif
|
|
|
|
bt = 0;
|
|
|
|
|
|
|
|
switch (popts->burst_length) {
|
2009-03-14 04:48:30 +00:00
|
|
|
case DDR_BL4:
|
2008-08-26 20:01:29 +00:00
|
|
|
bl = 2;
|
|
|
|
break;
|
2009-03-14 04:48:30 +00:00
|
|
|
case DDR_BL8:
|
2008-08-26 20:01:29 +00:00
|
|
|
bl = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("Error: invalid burst length of %u specified. "
|
|
|
|
" Defaulting to 4 beats.\n",
|
|
|
|
popts->burst_length);
|
|
|
|
bl = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdmode = (0
|
|
|
|
| ((mr & 0x3) << 14)
|
|
|
|
| ((pd & 0x1) << 12)
|
|
|
|
| ((wr & 0x7) << 9)
|
|
|
|
| ((dll_res & 0x1) << 8)
|
|
|
|
| ((mode & 0x1) << 7)
|
|
|
|
| ((caslat & 0x7) << 4)
|
|
|
|
| ((bt & 0x1) << 3)
|
|
|
|
| ((bl & 0x7) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
ddr->ddr_sdram_mode = (0
|
|
|
|
| ((esdmode & 0xFFFF) << 16)
|
|
|
|
| ((sdmode & 0xFFFF) << 0)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_mode = 0x%08x\n", ddr->ddr_sdram_mode);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
2009-03-14 04:48:30 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
/* DDR SDRAM Data Initialization (DDR_DATA_INIT) */
|
|
|
|
static void set_ddr_data_init(fsl_ddr_cfg_regs_t *ddr)
|
|
|
|
{
|
|
|
|
unsigned int init_value; /* Initialization value */
|
|
|
|
|
2013-01-21 23:50:27 +00:00
|
|
|
#ifdef CONFIG_MEM_INIT_VALUE
|
|
|
|
init_value = CONFIG_MEM_INIT_VALUE;
|
|
|
|
#else
|
2008-08-26 20:01:29 +00:00
|
|
|
init_value = 0xDEADBEEF;
|
2013-01-21 23:50:27 +00:00
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_data_init = init_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DDR SDRAM Clock Control (DDR_SDRAM_CLK_CNTL)
|
|
|
|
* The old controller on the 8540/60 doesn't have this register.
|
|
|
|
* Hope it's OK to set it (to 0) anyway.
|
|
|
|
*/
|
|
|
|
static void set_ddr_sdram_clk_cntl(fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts)
|
|
|
|
{
|
|
|
|
unsigned int clk_adjust; /* Clock adjust */
|
2015-02-13 18:57:11 +00:00
|
|
|
unsigned int ss_en = 0; /* Source synchronous enable */
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2016-11-16 19:23:23 +00:00
|
|
|
#if defined(CONFIG_ARCH_MPC8541) || defined(CONFIG_ARCH_MPC8555)
|
2015-02-13 18:57:11 +00:00
|
|
|
/* Per FSL Application Note: AN2805 */
|
|
|
|
ss_en = 1;
|
|
|
|
#endif
|
2016-05-04 02:20:21 +00:00
|
|
|
if (fsl_ddr_get_version(0) >= 0x40701) {
|
|
|
|
/* clk_adjust in 5-bits on T-series and LS-series */
|
|
|
|
clk_adjust = (popts->clk_adjust & 0x1F) << 22;
|
|
|
|
} else {
|
|
|
|
/* clk_adjust in 4-bits on earlier MPC85xx and P-series */
|
|
|
|
clk_adjust = (popts->clk_adjust & 0xF) << 23;
|
|
|
|
}
|
|
|
|
|
2015-02-13 18:57:11 +00:00
|
|
|
ddr->ddr_sdram_clk_cntl = (0
|
|
|
|
| ((ss_en & 0x1) << 31)
|
2016-05-04 02:20:21 +00:00
|
|
|
| clk_adjust
|
2015-02-13 18:57:11 +00:00
|
|
|
);
|
2010-07-02 22:25:55 +00:00
|
|
|
debug("FSLDDR: clk_cntl = 0x%08x\n", ddr->ddr_sdram_clk_cntl);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR Initialization Address (DDR_INIT_ADDR) */
|
|
|
|
static void set_ddr_init_addr(fsl_ddr_cfg_regs_t *ddr)
|
|
|
|
{
|
|
|
|
unsigned int init_addr = 0; /* Initialization address */
|
|
|
|
|
|
|
|
ddr->ddr_init_addr = init_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR Initialization Address (DDR_INIT_EXT_ADDR) */
|
|
|
|
static void set_ddr_init_ext_addr(fsl_ddr_cfg_regs_t *ddr)
|
|
|
|
{
|
|
|
|
unsigned int uia = 0; /* Use initialization address */
|
|
|
|
unsigned int init_ext_addr = 0; /* Initialization address */
|
|
|
|
|
|
|
|
ddr->ddr_init_ext_addr = (0
|
|
|
|
| ((uia & 0x1) << 31)
|
|
|
|
| (init_ext_addr & 0xF)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR SDRAM Timing Configuration 4 (TIMING_CFG_4) */
|
2010-03-05 04:22:00 +00:00
|
|
|
static void set_timing_cfg_4(fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned int rwt = 0; /* Read-to-write turnaround for same CS */
|
|
|
|
unsigned int wrt = 0; /* Write-to-read turnaround for same CS */
|
|
|
|
unsigned int rrt = 0; /* Read-to-read turnaround for same CS */
|
|
|
|
unsigned int wwt = 0; /* Write-to-write turnaround for same CS */
|
2015-11-04 18:03:21 +00:00
|
|
|
unsigned int trwt_mclk = 0; /* ext_rwt */
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int dll_lock = 0; /* DDR SDRAM DLL Lock Time */
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
|
2010-03-05 04:22:00 +00:00
|
|
|
if (popts->burst_length == DDR_BL8) {
|
|
|
|
/* We set BL/2 for fixed BL8 */
|
|
|
|
rrt = 0; /* BL/2 clocks */
|
|
|
|
wwt = 0; /* BL/2 clocks */
|
|
|
|
} else {
|
|
|
|
/* We need to set BL/2 + 2 to BC4 and OTF */
|
|
|
|
rrt = 2; /* BL/2 + 2 clocks */
|
|
|
|
wwt = 2; /* BL/2 + 2 clocks */
|
|
|
|
}
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
dll_lock = 2; /* tDLLK = 1024 clocks */
|
|
|
|
#elif defined(CONFIG_SYS_FSL_DDR3)
|
2009-03-14 04:48:30 +00:00
|
|
|
dll_lock = 1; /* tDLLK = 512 clocks from spec */
|
|
|
|
#endif
|
2015-11-04 18:03:21 +00:00
|
|
|
|
|
|
|
if (popts->trwt_override)
|
|
|
|
trwt_mclk = popts->trwt;
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->timing_cfg_4 = (0
|
|
|
|
| ((rwt & 0xf) << 28)
|
|
|
|
| ((wrt & 0xf) << 24)
|
|
|
|
| ((rrt & 0xf) << 20)
|
|
|
|
| ((wwt & 0xf) << 16)
|
2015-11-04 18:03:21 +00:00
|
|
|
| ((trwt_mclk & 0xc) << 12)
|
2008-08-26 20:01:29 +00:00
|
|
|
| (dll_lock & 0x3)
|
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: timing_cfg_4 = 0x%08x\n", ddr->timing_cfg_4);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR SDRAM Timing Configuration 5 (TIMING_CFG_5) */
|
2011-01-10 12:03:00 +00:00
|
|
|
static void set_timing_cfg_5(fsl_ddr_cfg_regs_t *ddr, unsigned int cas_latency)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned int rodt_on = 0; /* Read to ODT on */
|
|
|
|
unsigned int rodt_off = 0; /* Read to ODT off */
|
|
|
|
unsigned int wodt_on = 0; /* Write to ODT on */
|
|
|
|
unsigned int wodt_off = 0; /* Write to ODT off */
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#if defined(CONFIG_SYS_FSL_DDR3) || defined(CONFIG_SYS_FSL_DDR4)
|
|
|
|
unsigned int wr_lat = ((ddr->timing_cfg_2 & 0x00780000) >> 19) +
|
|
|
|
((ddr->timing_cfg_2 & 0x00040000) >> 14);
|
2011-01-10 12:03:00 +00:00
|
|
|
/* rodt_on = timing_cfg_1[caslat] - timing_cfg_2[wrlat] + 1 */
|
2014-03-28 00:54:47 +00:00
|
|
|
if (cas_latency >= wr_lat)
|
|
|
|
rodt_on = cas_latency - wr_lat + 1;
|
2009-03-14 04:48:30 +00:00
|
|
|
rodt_off = 4; /* 4 clocks */
|
2010-07-02 22:25:56 +00:00
|
|
|
wodt_on = 1; /* 1 clocks */
|
2009-03-14 04:48:30 +00:00
|
|
|
wodt_off = 4; /* 4 clocks */
|
|
|
|
#endif
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->timing_cfg_5 = (0
|
2008-11-21 08:31:29 +00:00
|
|
|
| ((rodt_on & 0x1f) << 24)
|
|
|
|
| ((rodt_off & 0x7) << 20)
|
|
|
|
| ((wodt_on & 0x1f) << 12)
|
|
|
|
| ((wodt_off & 0x7) << 8)
|
2008-08-26 20:01:29 +00:00
|
|
|
);
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: timing_cfg_5 = 0x%08x\n", ddr->timing_cfg_5);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
static void set_timing_cfg_6(fsl_ddr_cfg_regs_t *ddr)
|
|
|
|
{
|
|
|
|
unsigned int hs_caslat = 0;
|
|
|
|
unsigned int hs_wrlat = 0;
|
|
|
|
unsigned int hs_wrrec = 0;
|
|
|
|
unsigned int hs_clkadj = 0;
|
|
|
|
unsigned int hs_wrlvl_start = 0;
|
|
|
|
|
|
|
|
ddr->timing_cfg_6 = (0
|
|
|
|
| ((hs_caslat & 0x1f) << 24)
|
|
|
|
| ((hs_wrlat & 0x1f) << 19)
|
|
|
|
| ((hs_wrrec & 0x1f) << 12)
|
|
|
|
| ((hs_clkadj & 0x1f) << 6)
|
|
|
|
| ((hs_wrlvl_start & 0x1f) << 0)
|
|
|
|
);
|
|
|
|
debug("FSLDDR: timing_cfg_6 = 0x%08x\n", ddr->timing_cfg_6);
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_timing_cfg_7(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2018-01-29 17:44:33 +00:00
|
|
|
const memctl_options_t *popts,
|
2015-01-06 21:18:50 +00:00
|
|
|
const common_timing_params_t *common_dimm)
|
2014-03-28 00:54:47 +00:00
|
|
|
{
|
|
|
|
unsigned int txpr, tcksre, tcksrx;
|
2016-03-10 09:36:56 +00:00
|
|
|
unsigned int cke_rst, cksre, cksrx, par_lat = 0, cs_to_cmd;
|
|
|
|
const unsigned int mclk_ps = get_memory_clk_period_ps(ctrl_num);
|
2014-03-28 00:54:47 +00:00
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
txpr = max(5U, picos_to_mclk(ctrl_num, common_dimm->trfc1_ps + 10000));
|
|
|
|
tcksre = max(5U, picos_to_mclk(ctrl_num, 10000));
|
|
|
|
tcksrx = max(5U, picos_to_mclk(ctrl_num, 10000));
|
2016-03-10 09:36:56 +00:00
|
|
|
|
2018-01-29 17:44:33 +00:00
|
|
|
if (ddr->ddr_sdram_cfg_2 & SDRAM_CFG2_AP_EN &&
|
|
|
|
CONFIG_FSL_SDRAM_TYPE == SDRAM_TYPE_DDR4) {
|
|
|
|
/* for DDR4 only */
|
2018-01-29 17:44:35 +00:00
|
|
|
par_lat = (ddr->ddr_sdram_rcw_2 & 0xf) + 1;
|
2018-01-29 17:44:33 +00:00
|
|
|
debug("PAR_LAT = %u for mclk_ps = %d\n", par_lat, mclk_ps);
|
2016-03-10 09:36:56 +00:00
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
cs_to_cmd = 0;
|
|
|
|
|
|
|
|
if (txpr <= 200)
|
|
|
|
cke_rst = 0;
|
|
|
|
else if (txpr <= 256)
|
|
|
|
cke_rst = 1;
|
|
|
|
else if (txpr <= 512)
|
|
|
|
cke_rst = 2;
|
|
|
|
else
|
|
|
|
cke_rst = 3;
|
|
|
|
|
|
|
|
if (tcksre <= 19)
|
|
|
|
cksre = tcksre - 5;
|
|
|
|
else
|
|
|
|
cksre = 15;
|
|
|
|
|
|
|
|
if (tcksrx <= 19)
|
|
|
|
cksrx = tcksrx - 5;
|
|
|
|
else
|
|
|
|
cksrx = 15;
|
|
|
|
|
|
|
|
ddr->timing_cfg_7 = (0
|
|
|
|
| ((cke_rst & 0x3) << 28)
|
|
|
|
| ((cksre & 0xf) << 24)
|
|
|
|
| ((cksrx & 0xf) << 20)
|
|
|
|
| ((par_lat & 0xf) << 16)
|
|
|
|
| ((cs_to_cmd & 0xf) << 4)
|
|
|
|
);
|
|
|
|
debug("FSLDDR: timing_cfg_7 = 0x%08x\n", ddr->timing_cfg_7);
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
static void set_timing_cfg_8(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
2014-03-28 00:54:47 +00:00
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
unsigned int cas_latency)
|
|
|
|
{
|
2018-01-29 17:44:33 +00:00
|
|
|
int rwt_bg, wrt_bg, rrt_bg, wwt_bg;
|
2014-03-28 00:54:47 +00:00
|
|
|
unsigned int acttoact_bg, wrtord_bg, pre_all_rec;
|
2018-01-29 17:44:33 +00:00
|
|
|
int tccdl = picos_to_mclk(ctrl_num, common_dimm->tccdl_ps);
|
|
|
|
int wr_lat = ((ddr->timing_cfg_2 & 0x00780000) >> 19) +
|
|
|
|
((ddr->timing_cfg_2 & 0x00040000) >> 14);
|
2014-03-28 00:54:47 +00:00
|
|
|
|
|
|
|
rwt_bg = cas_latency + 2 + 4 - wr_lat;
|
|
|
|
if (rwt_bg < tccdl)
|
|
|
|
rwt_bg = tccdl - rwt_bg;
|
|
|
|
else
|
|
|
|
rwt_bg = 0;
|
|
|
|
|
|
|
|
wrt_bg = wr_lat + 4 + 1 - cas_latency;
|
|
|
|
if (wrt_bg < tccdl)
|
|
|
|
wrt_bg = tccdl - wrt_bg;
|
|
|
|
else
|
|
|
|
wrt_bg = 0;
|
|
|
|
|
|
|
|
if (popts->burst_length == DDR_BL8) {
|
|
|
|
rrt_bg = tccdl - 4;
|
|
|
|
wwt_bg = tccdl - 4;
|
|
|
|
} else {
|
|
|
|
rrt_bg = tccdl - 2;
|
2015-01-06 21:18:52 +00:00
|
|
|
wwt_bg = tccdl - 2;
|
2014-03-28 00:54:47 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
acttoact_bg = picos_to_mclk(ctrl_num, common_dimm->trrdl_ps);
|
|
|
|
wrtord_bg = max(4U, picos_to_mclk(ctrl_num, 7500));
|
2014-06-26 18:14:44 +00:00
|
|
|
if (popts->otf_burst_chop_en)
|
|
|
|
wrtord_bg += 2;
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
pre_all_rec = 0;
|
|
|
|
|
|
|
|
ddr->timing_cfg_8 = (0
|
|
|
|
| ((rwt_bg & 0xf) << 28)
|
|
|
|
| ((wrt_bg & 0xf) << 24)
|
|
|
|
| ((rrt_bg & 0xf) << 20)
|
|
|
|
| ((wwt_bg & 0xf) << 16)
|
|
|
|
| ((acttoact_bg & 0xf) << 12)
|
|
|
|
| ((wrtord_bg & 0xf) << 8)
|
|
|
|
| ((pre_all_rec & 0x1f) << 0)
|
|
|
|
);
|
|
|
|
|
|
|
|
debug("FSLDDR: timing_cfg_8 = 0x%08x\n", ddr->timing_cfg_8);
|
|
|
|
}
|
|
|
|
|
2018-01-29 17:44:35 +00:00
|
|
|
static void set_timing_cfg_9(const unsigned int ctrl_num,
|
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts,
|
|
|
|
const common_timing_params_t *common_dimm)
|
2014-03-28 00:54:47 +00:00
|
|
|
{
|
2018-01-29 17:44:35 +00:00
|
|
|
unsigned int refrec_cid_mclk = 0;
|
|
|
|
unsigned int acttoact_cid_mclk = 0;
|
|
|
|
|
|
|
|
if (popts->package_3ds) {
|
|
|
|
refrec_cid_mclk =
|
|
|
|
picos_to_mclk(ctrl_num, common_dimm->trfc_slr_ps);
|
|
|
|
acttoact_cid_mclk = 4U; /* tRRDS_slr */
|
|
|
|
}
|
|
|
|
|
|
|
|
ddr->timing_cfg_9 = (refrec_cid_mclk & 0x3ff) << 16 |
|
|
|
|
(acttoact_cid_mclk & 0xf) << 8;
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
debug("FSLDDR: timing_cfg_9 = 0x%08x\n", ddr->timing_cfg_9);
|
|
|
|
}
|
|
|
|
|
2014-09-11 20:32:06 +00:00
|
|
|
/* This function needs to be called after set_ddr_sdram_cfg() is called */
|
2014-03-28 00:54:47 +00:00
|
|
|
static void set_ddr_dq_mapping(fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const dimm_params_t *dimm_params)
|
|
|
|
{
|
2014-09-11 20:32:06 +00:00
|
|
|
unsigned int acc_ecc_en = (ddr->ddr_sdram_cfg >> 2) & 0x1;
|
2015-03-19 16:30:27 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < CONFIG_DIMM_SLOTS_PER_CTLR; i++) {
|
|
|
|
if (dimm_params[i].n_ranks)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= CONFIG_DIMM_SLOTS_PER_CTLR) {
|
|
|
|
puts("DDR error: no DIMM found!\n");
|
|
|
|
return;
|
|
|
|
}
|
2014-09-11 20:32:06 +00:00
|
|
|
|
2015-03-19 16:30:27 +00:00
|
|
|
ddr->dq_map_0 = ((dimm_params[i].dq_mapping[0] & 0x3F) << 26) |
|
|
|
|
((dimm_params[i].dq_mapping[1] & 0x3F) << 20) |
|
|
|
|
((dimm_params[i].dq_mapping[2] & 0x3F) << 14) |
|
|
|
|
((dimm_params[i].dq_mapping[3] & 0x3F) << 8) |
|
|
|
|
((dimm_params[i].dq_mapping[4] & 0x3F) << 2);
|
2014-03-28 00:54:47 +00:00
|
|
|
|
2015-03-19 16:30:27 +00:00
|
|
|
ddr->dq_map_1 = ((dimm_params[i].dq_mapping[5] & 0x3F) << 26) |
|
|
|
|
((dimm_params[i].dq_mapping[6] & 0x3F) << 20) |
|
|
|
|
((dimm_params[i].dq_mapping[7] & 0x3F) << 14) |
|
|
|
|
((dimm_params[i].dq_mapping[10] & 0x3F) << 8) |
|
|
|
|
((dimm_params[i].dq_mapping[11] & 0x3F) << 2);
|
2014-03-28 00:54:47 +00:00
|
|
|
|
2015-03-19 16:30:27 +00:00
|
|
|
ddr->dq_map_2 = ((dimm_params[i].dq_mapping[12] & 0x3F) << 26) |
|
|
|
|
((dimm_params[i].dq_mapping[13] & 0x3F) << 20) |
|
|
|
|
((dimm_params[i].dq_mapping[14] & 0x3F) << 14) |
|
|
|
|
((dimm_params[i].dq_mapping[15] & 0x3F) << 8) |
|
|
|
|
((dimm_params[i].dq_mapping[16] & 0x3F) << 2);
|
2014-03-28 00:54:47 +00:00
|
|
|
|
2014-09-11 20:32:06 +00:00
|
|
|
/* dq_map for ECC[4:7] is set to 0 if accumulated ECC is enabled */
|
2015-03-19 16:30:27 +00:00
|
|
|
ddr->dq_map_3 = ((dimm_params[i].dq_mapping[17] & 0x3F) << 26) |
|
|
|
|
((dimm_params[i].dq_mapping[8] & 0x3F) << 20) |
|
2014-09-11 20:32:06 +00:00
|
|
|
(acc_ecc_en ? 0 :
|
2015-03-19 16:30:27 +00:00
|
|
|
(dimm_params[i].dq_mapping[9] & 0x3F) << 14) |
|
|
|
|
dimm_params[i].dq_mapping_ors;
|
2014-03-28 00:54:47 +00:00
|
|
|
|
|
|
|
debug("FSLDDR: dq_map_0 = 0x%08x\n", ddr->dq_map_0);
|
|
|
|
debug("FSLDDR: dq_map_1 = 0x%08x\n", ddr->dq_map_1);
|
|
|
|
debug("FSLDDR: dq_map_2 = 0x%08x\n", ddr->dq_map_2);
|
|
|
|
debug("FSLDDR: dq_map_3 = 0x%08x\n", ddr->dq_map_3);
|
|
|
|
}
|
|
|
|
static void set_ddr_sdram_cfg_3(fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const memctl_options_t *popts)
|
|
|
|
{
|
|
|
|
int rd_pre;
|
|
|
|
|
|
|
|
rd_pre = popts->quad_rank_present ? 1 : 0;
|
|
|
|
|
|
|
|
ddr->ddr_sdram_cfg_3 = (rd_pre & 0x1) << 16;
|
2018-01-29 17:44:33 +00:00
|
|
|
/* Disable MRS on parity error for RDIMMs */
|
|
|
|
ddr->ddr_sdram_cfg_3 |= popts->registered_dimm_en ? 1 : 0;
|
2014-03-28 00:54:47 +00:00
|
|
|
|
2018-01-29 17:44:35 +00:00
|
|
|
if (popts->package_3ds) { /* only 2,4,8 are supported */
|
|
|
|
if ((popts->package_3ds + 1) & 0x1) {
|
|
|
|
printf("Error: Unsupported 3DS DIMM with %d die\n",
|
|
|
|
popts->package_3ds + 1);
|
|
|
|
} else {
|
|
|
|
ddr->ddr_sdram_cfg_3 |= ((popts->package_3ds + 1) >> 1)
|
|
|
|
<< 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-28 00:54:47 +00:00
|
|
|
debug("FSLDDR: ddr_sdram_cfg_3 = 0x%08x\n", ddr->ddr_sdram_cfg_3);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_SYS_FSL_DDR4 */
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/* DDR ZQ Calibration Control (DDR_ZQ_CNTL) */
|
2009-03-14 04:48:30 +00:00
|
|
|
static void set_ddr_zq_cntl(fsl_ddr_cfg_regs_t *ddr, unsigned int zq_en)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned int zqinit = 0;/* POR ZQ Calibration Time (tZQinit) */
|
|
|
|
/* Normal Operation Full Calibration Time (tZQoper) */
|
|
|
|
unsigned int zqoper = 0;
|
|
|
|
/* Normal Operation Short Calibration Time (tZQCS) */
|
|
|
|
unsigned int zqcs = 0;
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
unsigned int zqcs_init;
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
if (zq_en) {
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
zqinit = 10; /* 1024 clocks */
|
|
|
|
zqoper = 9; /* 512 clocks */
|
|
|
|
zqcs = 7; /* 128 clocks */
|
|
|
|
zqcs_init = 5; /* 1024 refresh sequences */
|
|
|
|
#else
|
2009-03-14 04:48:30 +00:00
|
|
|
zqinit = 9; /* 512 clocks */
|
|
|
|
zqoper = 8; /* 256 clocks */
|
|
|
|
zqcs = 6; /* 64 clocks */
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2009-03-14 04:48:30 +00:00
|
|
|
}
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_zq_cntl = (0
|
|
|
|
| ((zq_en & 0x1) << 31)
|
|
|
|
| ((zqinit & 0xF) << 24)
|
|
|
|
| ((zqoper & 0xF) << 16)
|
|
|
|
| ((zqcs & 0xF) << 8)
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
| ((zqcs_init & 0xF) << 0)
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
);
|
2011-01-10 12:03:00 +00:00
|
|
|
debug("FSLDDR: zq_cntl = 0x%08x\n", ddr->ddr_zq_cntl);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR Write Leveling Control (DDR_WRLVL_CNTL) */
|
2009-12-16 16:24:37 +00:00
|
|
|
static void set_ddr_wrlvl_cntl(fsl_ddr_cfg_regs_t *ddr, unsigned int wrlvl_en,
|
|
|
|
const memctl_options_t *popts)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* First DQS pulse rising edge after margining mode
|
|
|
|
* is programmed (tWL_MRD)
|
|
|
|
*/
|
|
|
|
unsigned int wrlvl_mrd = 0;
|
|
|
|
/* ODT delay after margining mode is programmed (tWL_ODTEN) */
|
|
|
|
unsigned int wrlvl_odten = 0;
|
|
|
|
/* DQS/DQS_ delay after margining mode is programmed (tWL_DQSEN) */
|
|
|
|
unsigned int wrlvl_dqsen = 0;
|
|
|
|
/* WRLVL_SMPL: Write leveling sample time */
|
|
|
|
unsigned int wrlvl_smpl = 0;
|
|
|
|
/* WRLVL_WLR: Write leveling repeition time */
|
|
|
|
unsigned int wrlvl_wlr = 0;
|
|
|
|
/* WRLVL_START: Write leveling start time */
|
|
|
|
unsigned int wrlvl_start = 0;
|
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
/* suggest enable write leveling for DDR3 due to fly-by topology */
|
|
|
|
if (wrlvl_en) {
|
|
|
|
/* tWL_MRD min = 40 nCK, we set it 64 */
|
|
|
|
wrlvl_mrd = 0x6;
|
|
|
|
/* tWL_ODTEN 128 */
|
|
|
|
wrlvl_odten = 0x7;
|
|
|
|
/* tWL_DQSEN min = 25 nCK, we set it 32 */
|
|
|
|
wrlvl_dqsen = 0x5;
|
|
|
|
/*
|
2009-12-16 16:24:37 +00:00
|
|
|
* Write leveling sample time at least need 6 clocks
|
|
|
|
* higher than tWLO to allow enough time for progagation
|
|
|
|
* delay and sampling the prime data bits.
|
2009-03-14 04:48:30 +00:00
|
|
|
*/
|
|
|
|
wrlvl_smpl = 0xf;
|
|
|
|
/*
|
|
|
|
* Write leveling repetition time
|
|
|
|
* at least tWLO + 6 clocks clocks
|
2010-07-02 22:25:56 +00:00
|
|
|
* we set it 64
|
2009-03-14 04:48:30 +00:00
|
|
|
*/
|
2010-07-02 22:25:56 +00:00
|
|
|
wrlvl_wlr = 0x6;
|
2009-03-14 04:48:30 +00:00
|
|
|
/*
|
|
|
|
* Write leveling start time
|
|
|
|
* The value use for the DQS_ADJUST for the first sample
|
2011-01-10 12:03:00 +00:00
|
|
|
* when write leveling is enabled. It probably needs to be
|
2016-07-15 17:44:45 +00:00
|
|
|
* overridden per platform.
|
2009-03-14 04:48:30 +00:00
|
|
|
*/
|
|
|
|
wrlvl_start = 0x8;
|
2009-12-16 16:24:37 +00:00
|
|
|
/*
|
|
|
|
* Override the write leveling sample and start time
|
|
|
|
* according to specific board
|
|
|
|
*/
|
|
|
|
if (popts->wrlvl_override) {
|
|
|
|
wrlvl_smpl = popts->wrlvl_sample;
|
|
|
|
wrlvl_start = popts->wrlvl_start;
|
|
|
|
}
|
2009-03-14 04:48:30 +00:00
|
|
|
}
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_wrlvl_cntl = (0
|
|
|
|
| ((wrlvl_en & 0x1) << 31)
|
|
|
|
| ((wrlvl_mrd & 0x7) << 24)
|
|
|
|
| ((wrlvl_odten & 0x7) << 20)
|
|
|
|
| ((wrlvl_dqsen & 0x7) << 16)
|
|
|
|
| ((wrlvl_smpl & 0xf) << 12)
|
|
|
|
| ((wrlvl_wlr & 0x7) << 8)
|
2008-11-21 08:31:29 +00:00
|
|
|
| ((wrlvl_start & 0x1F) << 0)
|
2008-08-26 20:01:29 +00:00
|
|
|
);
|
2011-01-10 12:03:00 +00:00
|
|
|
debug("FSLDDR: wrlvl_cntl = 0x%08x\n", ddr->ddr_wrlvl_cntl);
|
2012-10-08 07:44:22 +00:00
|
|
|
ddr->ddr_wrlvl_cntl_2 = popts->wrlvl_ctl_2;
|
|
|
|
debug("FSLDDR: wrlvl_cntl_2 = 0x%08x\n", ddr->ddr_wrlvl_cntl_2);
|
|
|
|
ddr->ddr_wrlvl_cntl_3 = popts->wrlvl_ctl_3;
|
|
|
|
debug("FSLDDR: wrlvl_cntl_3 = 0x%08x\n", ddr->ddr_wrlvl_cntl_3);
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* DDR Self Refresh Counter (DDR_SR_CNTR) */
|
2008-11-21 08:31:35 +00:00
|
|
|
static void set_ddr_sr_cntr(fsl_ddr_cfg_regs_t *ddr, unsigned int sr_it)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
2008-11-21 08:31:35 +00:00
|
|
|
/* Self Refresh Idle Threshold */
|
2008-08-26 20:01:29 +00:00
|
|
|
ddr->ddr_sr_cntr = (sr_it & 0xF) << 16;
|
|
|
|
}
|
|
|
|
|
2010-07-02 22:25:54 +00:00
|
|
|
static void set_ddr_eor(fsl_ddr_cfg_regs_t *ddr, const memctl_options_t *popts)
|
|
|
|
{
|
|
|
|
if (popts->addr_hash) {
|
|
|
|
ddr->ddr_eor = 0x40000000; /* address hash enable */
|
2011-03-18 16:53:06 +00:00
|
|
|
puts("Address hashing enabled.\n");
|
2010-07-02 22:25:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-10 12:03:00 +00:00
|
|
|
static void set_ddr_cdr1(fsl_ddr_cfg_regs_t *ddr, const memctl_options_t *popts)
|
|
|
|
{
|
|
|
|
ddr->ddr_cdr1 = popts->ddr_cdr1;
|
|
|
|
debug("FSLDDR: ddr_cdr1 = 0x%08x\n", ddr->ddr_cdr1);
|
|
|
|
}
|
|
|
|
|
2012-10-08 07:44:22 +00:00
|
|
|
static void set_ddr_cdr2(fsl_ddr_cfg_regs_t *ddr, const memctl_options_t *popts)
|
|
|
|
{
|
|
|
|
ddr->ddr_cdr2 = popts->ddr_cdr2;
|
|
|
|
debug("FSLDDR: ddr_cdr2 = 0x%08x\n", ddr->ddr_cdr2);
|
|
|
|
}
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
unsigned int
|
|
|
|
check_fsl_memctl_config_regs(const fsl_ddr_cfg_regs_t *ddr)
|
|
|
|
{
|
|
|
|
unsigned int res = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check that DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN] are
|
|
|
|
* not set at the same time.
|
|
|
|
*/
|
|
|
|
if (ddr->ddr_sdram_cfg & 0x10000000
|
|
|
|
&& ddr->ddr_sdram_cfg & 0x00008000) {
|
|
|
|
printf("Error: DDR_SDRAM_CFG[RD_EN] and DDR_SDRAM_CFG[2T_EN] "
|
|
|
|
" should not be set at the same time.\n");
|
|
|
|
res++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2015-01-06 21:18:50 +00:00
|
|
|
compute_fsl_memctl_config_regs(const unsigned int ctrl_num,
|
|
|
|
const memctl_options_t *popts,
|
2008-08-26 20:01:29 +00:00
|
|
|
fsl_ddr_cfg_regs_t *ddr,
|
|
|
|
const common_timing_params_t *common_dimm,
|
|
|
|
const dimm_params_t *dimm_params,
|
2010-12-01 15:35:31 +00:00
|
|
|
unsigned int dbw_cap_adj,
|
|
|
|
unsigned int size_only)
|
2008-08-26 20:01:29 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int cas_latency;
|
|
|
|
unsigned int additive_latency;
|
2008-11-21 08:31:35 +00:00
|
|
|
unsigned int sr_it;
|
2009-03-14 04:48:30 +00:00
|
|
|
unsigned int zq_en;
|
|
|
|
unsigned int wrlvl_en;
|
2011-01-10 12:03:00 +00:00
|
|
|
unsigned int ip_rev = 0;
|
|
|
|
unsigned int unq_mrs_en = 0;
|
2010-10-18 20:46:50 +00:00
|
|
|
int cs_en = 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
memset(ddr, 0, sizeof(fsl_ddr_cfg_regs_t));
|
|
|
|
|
|
|
|
if (common_dimm == NULL) {
|
|
|
|
printf("Error: subset DIMM params struct null pointer\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process overrides first.
|
|
|
|
*
|
|
|
|
* FIXME: somehow add dereated caslat to this
|
|
|
|
*/
|
|
|
|
cas_latency = (popts->cas_latency_override)
|
|
|
|
? popts->cas_latency_override_value
|
2014-03-28 00:54:47 +00:00
|
|
|
: common_dimm->lowest_common_spd_caslat;
|
2008-08-26 20:01:29 +00:00
|
|
|
|
|
|
|
additive_latency = (popts->additive_latency_override)
|
|
|
|
? popts->additive_latency_override_value
|
|
|
|
: common_dimm->additive_latency;
|
|
|
|
|
2008-11-21 08:31:35 +00:00
|
|
|
sr_it = (popts->auto_self_refresh_en)
|
|
|
|
? popts->sr_it
|
|
|
|
: 0;
|
2009-03-14 04:48:30 +00:00
|
|
|
/* ZQ calibration */
|
|
|
|
zq_en = (popts->zq_en) ? 1 : 0;
|
|
|
|
/* write leveling */
|
|
|
|
wrlvl_en = (popts->wrlvl_en) ? 1 : 0;
|
2008-11-21 08:31:35 +00:00
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
/* Chip Select Memory Bounds (CSn_BNDS) */
|
|
|
|
for (i = 0; i < CONFIG_CHIP_SELECTS_PER_CTRL; i++) {
|
2012-08-17 08:22:39 +00:00
|
|
|
unsigned long long ea, sa;
|
2010-07-02 22:25:52 +00:00
|
|
|
unsigned int cs_per_dimm
|
|
|
|
= CONFIG_CHIP_SELECTS_PER_CTRL / CONFIG_DIMM_SLOTS_PER_CTLR;
|
|
|
|
unsigned int dimm_number
|
|
|
|
= i / cs_per_dimm;
|
|
|
|
unsigned long long rank_density
|
2012-08-17 08:22:39 +00:00
|
|
|
= dimm_params[dimm_number].rank_density >> dbw_cap_adj;
|
2010-07-02 22:25:52 +00:00
|
|
|
|
|
|
|
if (dimm_params[dimm_number].n_ranks == 0) {
|
2008-08-26 20:01:29 +00:00
|
|
|
debug("Skipping setup of CS%u "
|
2010-07-02 22:25:53 +00:00
|
|
|
"because n_ranks on DIMM %u is 0\n", i, dimm_number);
|
2008-08-26 20:01:29 +00:00
|
|
|
continue;
|
|
|
|
}
|
2012-08-17 08:22:39 +00:00
|
|
|
if (popts->memctl_interleaving) {
|
2010-07-02 22:25:52 +00:00
|
|
|
switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
|
2012-08-17 08:22:39 +00:00
|
|
|
case FSL_DDR_CS0_CS1_CS2_CS3:
|
|
|
|
break;
|
2010-07-02 22:25:52 +00:00
|
|
|
case FSL_DDR_CS0_CS1:
|
|
|
|
case FSL_DDR_CS0_CS1_AND_CS2_CS3:
|
2010-10-18 20:46:50 +00:00
|
|
|
if (i > 1)
|
|
|
|
cs_en = 0;
|
2010-07-02 22:25:52 +00:00
|
|
|
break;
|
|
|
|
case FSL_DDR_CS2_CS3:
|
2012-08-17 08:22:39 +00:00
|
|
|
default:
|
2010-10-18 20:46:50 +00:00
|
|
|
if (i > 0)
|
|
|
|
cs_en = 0;
|
2010-07-02 22:25:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2012-08-17 08:22:39 +00:00
|
|
|
sa = common_dimm->base_address;
|
2012-10-08 07:44:23 +00:00
|
|
|
ea = sa + common_dimm->total_mem - 1;
|
2012-08-17 08:22:39 +00:00
|
|
|
} else if (!popts->memctl_interleaving) {
|
2008-08-26 20:01:29 +00:00
|
|
|
/*
|
|
|
|
* If memory interleaving between controllers is NOT
|
|
|
|
* enabled, the starting address for each memory
|
|
|
|
* controller is distinct. However, because rank
|
|
|
|
* interleaving is enabled, the starting and ending
|
|
|
|
* addresses of the total memory on that memory
|
|
|
|
* controller needs to be programmed into its
|
|
|
|
* respective CS0_BNDS.
|
|
|
|
*/
|
2008-10-03 16:36:39 +00:00
|
|
|
switch (popts->ba_intlv_ctl & FSL_DDR_CS0_CS1_CS2_CS3) {
|
|
|
|
case FSL_DDR_CS0_CS1_CS2_CS3:
|
|
|
|
sa = common_dimm->base_address;
|
2012-10-08 07:44:23 +00:00
|
|
|
ea = sa + common_dimm->total_mem - 1;
|
2008-10-03 16:36:39 +00:00
|
|
|
break;
|
|
|
|
case FSL_DDR_CS0_CS1_AND_CS2_CS3:
|
2012-08-17 08:22:39 +00:00
|
|
|
if ((i >= 2) && (dimm_number == 0)) {
|
2010-07-02 22:25:52 +00:00
|
|
|
sa = dimm_params[dimm_number].base_address +
|
2012-08-17 08:22:39 +00:00
|
|
|
2 * rank_density;
|
|
|
|
ea = sa + 2 * rank_density - 1;
|
2010-07-02 22:25:52 +00:00
|
|
|
} else {
|
|
|
|
sa = dimm_params[dimm_number].base_address;
|
2012-08-17 08:22:39 +00:00
|
|
|
ea = sa + 2 * rank_density - 1;
|
2008-10-03 16:36:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FSL_DDR_CS0_CS1:
|
2010-07-02 22:25:52 +00:00
|
|
|
if (dimm_params[dimm_number].n_ranks > (i % cs_per_dimm)) {
|
|
|
|
sa = dimm_params[dimm_number].base_address;
|
2012-08-17 08:22:39 +00:00
|
|
|
ea = sa + rank_density - 1;
|
|
|
|
if (i != 1)
|
|
|
|
sa += (i % cs_per_dimm) * rank_density;
|
|
|
|
ea += (i % cs_per_dimm) * rank_density;
|
2010-07-02 22:25:52 +00:00
|
|
|
} else {
|
|
|
|
sa = 0;
|
|
|
|
ea = 0;
|
|
|
|
}
|
|
|
|
if (i == 0)
|
2012-08-17 08:22:39 +00:00
|
|
|
ea += rank_density;
|
2008-10-03 16:36:39 +00:00
|
|
|
break;
|
|
|
|
case FSL_DDR_CS2_CS3:
|
2010-07-02 22:25:52 +00:00
|
|
|
if (dimm_params[dimm_number].n_ranks > (i % cs_per_dimm)) {
|
|
|
|
sa = dimm_params[dimm_number].base_address;
|
2012-08-17 08:22:39 +00:00
|
|
|
ea = sa + rank_density - 1;
|
|
|
|
if (i != 3)
|
|
|
|
sa += (i % cs_per_dimm) * rank_density;
|
|
|
|
ea += (i % cs_per_dimm) * rank_density;
|
2010-07-02 22:25:52 +00:00
|
|
|
} else {
|
|
|
|
sa = 0;
|
|
|
|
ea = 0;
|
2008-10-03 16:36:39 +00:00
|
|
|
}
|
2010-07-02 22:25:52 +00:00
|
|
|
if (i == 2)
|
|
|
|
ea += (rank_density >> dbw_cap_adj);
|
2008-10-03 16:36:39 +00:00
|
|
|
break;
|
|
|
|
default: /* No bank(chip-select) interleaving */
|
2012-08-17 08:22:39 +00:00
|
|
|
sa = dimm_params[dimm_number].base_address;
|
|
|
|
ea = sa + rank_density - 1;
|
|
|
|
if (dimm_params[dimm_number].n_ranks > (i % cs_per_dimm)) {
|
|
|
|
sa += (i % cs_per_dimm) * rank_density;
|
|
|
|
ea += (i % cs_per_dimm) * rank_density;
|
|
|
|
} else {
|
|
|
|
sa = 0;
|
|
|
|
ea = 0;
|
|
|
|
}
|
2008-10-03 16:36:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sa >>= 24;
|
|
|
|
ea >>= 24;
|
|
|
|
|
2012-10-08 07:44:23 +00:00
|
|
|
if (cs_en) {
|
|
|
|
ddr->cs[i].bnds = (0
|
2013-06-03 19:39:06 +00:00
|
|
|
| ((sa & 0xffff) << 16) /* starting address */
|
|
|
|
| ((ea & 0xffff) << 0) /* ending address */
|
2012-10-08 07:44:23 +00:00
|
|
|
);
|
|
|
|
} else {
|
2013-06-25 18:37:45 +00:00
|
|
|
/* setting bnds to 0xffffffff for inactive CS */
|
|
|
|
ddr->cs[i].bnds = 0xffffffff;
|
2012-10-08 07:44:23 +00:00
|
|
|
}
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2008-10-03 16:37:26 +00:00
|
|
|
debug("FSLDDR: cs[%d]_bnds = 0x%08x\n", i, ddr->cs[i].bnds);
|
2012-10-08 07:44:23 +00:00
|
|
|
set_csn_config(dimm_number, i, ddr, popts, dimm_params);
|
|
|
|
set_csn_config_2(i, ddr);
|
2008-08-26 20:01:29 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 15:35:31 +00:00
|
|
|
/*
|
|
|
|
* In the case we only need to compute the ddr sdram size, we only need
|
|
|
|
* to set csn registers, so return from here.
|
|
|
|
*/
|
|
|
|
if (size_only)
|
|
|
|
return 0;
|
|
|
|
|
2010-07-02 22:25:54 +00:00
|
|
|
set_ddr_eor(ddr, popts);
|
|
|
|
|
2013-09-30 16:22:09 +00:00
|
|
|
#if !defined(CONFIG_SYS_FSL_DDR1)
|
2015-01-06 21:18:50 +00:00
|
|
|
set_timing_cfg_0(ctrl_num, ddr, popts, dimm_params);
|
2008-08-26 20:01:29 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
set_timing_cfg_3(ctrl_num, ddr, popts, common_dimm, cas_latency,
|
2013-06-03 19:39:06 +00:00
|
|
|
additive_latency);
|
2015-01-06 21:18:50 +00:00
|
|
|
set_timing_cfg_1(ctrl_num, ddr, popts, common_dimm, cas_latency);
|
|
|
|
set_timing_cfg_2(ctrl_num, ddr, popts, common_dimm,
|
|
|
|
cas_latency, additive_latency);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2011-01-10 12:03:00 +00:00
|
|
|
set_ddr_cdr1(ddr, popts);
|
2012-10-08 07:44:22 +00:00
|
|
|
set_ddr_cdr2(ddr, popts);
|
2008-08-26 20:01:29 +00:00
|
|
|
set_ddr_sdram_cfg(ddr, popts, common_dimm);
|
2015-03-19 16:30:26 +00:00
|
|
|
ip_rev = fsl_ddr_get_version(ctrl_num);
|
2011-01-10 12:03:00 +00:00
|
|
|
if (ip_rev > 0x40400)
|
|
|
|
unq_mrs_en = 1;
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2014-09-11 20:32:06 +00:00
|
|
|
if ((ip_rev > 0x40700) && (popts->cswl_override != 0))
|
2014-09-05 05:52:43 +00:00
|
|
|
ddr->debug[18] = popts->cswl_override;
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
set_ddr_sdram_cfg_2(ctrl_num, ddr, popts, unq_mrs_en);
|
|
|
|
set_ddr_sdram_mode(ctrl_num, ddr, popts, common_dimm,
|
|
|
|
cas_latency, additive_latency, unq_mrs_en);
|
|
|
|
set_ddr_sdram_mode_2(ctrl_num, ddr, popts, common_dimm, unq_mrs_en);
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
set_ddr_sdram_mode_9(ddr, popts, common_dimm, unq_mrs_en);
|
2015-01-06 21:18:50 +00:00
|
|
|
set_ddr_sdram_mode_10(ctrl_num, ddr, popts, common_dimm, unq_mrs_en);
|
2014-03-28 00:54:47 +00:00
|
|
|
#endif
|
2018-01-29 18:24:08 +00:00
|
|
|
set_ddr_sdram_rcw(ctrl_num, ddr, popts, common_dimm);
|
|
|
|
|
2015-01-06 21:18:50 +00:00
|
|
|
set_ddr_sdram_interval(ctrl_num, ddr, popts, common_dimm);
|
2008-08-26 20:01:29 +00:00
|
|
|
set_ddr_data_init(ddr);
|
|
|
|
set_ddr_sdram_clk_cntl(ddr, popts);
|
|
|
|
set_ddr_init_addr(ddr);
|
|
|
|
set_ddr_init_ext_addr(ddr);
|
2010-03-05 04:22:00 +00:00
|
|
|
set_timing_cfg_4(ddr, popts);
|
2011-01-10 12:03:00 +00:00
|
|
|
set_timing_cfg_5(ddr, cas_latency);
|
2014-03-28 00:54:47 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
set_ddr_sdram_cfg_3(ddr, popts);
|
|
|
|
set_timing_cfg_6(ddr);
|
2018-01-29 17:44:33 +00:00
|
|
|
set_timing_cfg_7(ctrl_num, ddr, popts, common_dimm);
|
2015-01-06 21:18:50 +00:00
|
|
|
set_timing_cfg_8(ctrl_num, ddr, popts, common_dimm, cas_latency);
|
2018-01-29 17:44:35 +00:00
|
|
|
set_timing_cfg_9(ctrl_num, ddr, popts, common_dimm);
|
2014-03-28 00:54:47 +00:00
|
|
|
set_ddr_dq_mapping(ddr, dimm_params);
|
|
|
|
#endif
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2009-03-14 04:48:30 +00:00
|
|
|
set_ddr_zq_cntl(ddr, zq_en);
|
2009-12-16 16:24:37 +00:00
|
|
|
set_ddr_wrlvl_cntl(ddr, wrlvl_en, popts);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2008-11-21 08:31:35 +00:00
|
|
|
set_ddr_sr_cntr(ddr, sr_it);
|
2008-08-26 20:01:29 +00:00
|
|
|
|
2013-06-25 18:37:41 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR_EMU
|
|
|
|
/* disble DDR training for emulator */
|
|
|
|
ddr->debug[2] = 0x00000400;
|
2015-01-06 21:18:45 +00:00
|
|
|
ddr->debug[4] = 0xff800800;
|
|
|
|
ddr->debug[5] = 0x08000800;
|
|
|
|
ddr->debug[6] = 0x08000800;
|
|
|
|
ddr->debug[7] = 0x08000800;
|
|
|
|
ddr->debug[8] = 0x08000800;
|
2013-06-25 18:37:41 +00:00
|
|
|
#endif
|
powerpc/mpc85xx: Add workaround for DDR erratum A004508
When the DDR controller is initialized below a junction temperature of
0°C and then operated above a junction temperature of 65°C, the DDR
controller may cause receive data errors, resulting ECC errors and/or
corrupted data. This erratum applies to the following SoCs and their
variants: MPC8536, MPC8569, MPC8572, P1010, P1020, P1021, P1022, P1023,
P2020.
Signed-off-by: York Sun <yorksun@freescale.com>
2014-05-23 20:15:00 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_ERRATUM_A004508
|
|
|
|
if ((ip_rev >= 0x40000) && (ip_rev < 0x40400))
|
|
|
|
ddr->debug[2] |= 0x00000200; /* set bit 22 */
|
|
|
|
#endif
|
|
|
|
|
2016-11-21 03:36:48 +00:00
|
|
|
#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
|
|
|
|
if (popts->cpo_sample)
|
|
|
|
ddr->debug[28] = (ddr->debug[28] & 0xffffff00) |
|
|
|
|
popts->cpo_sample;
|
|
|
|
#endif
|
|
|
|
|
2008-08-26 20:01:29 +00:00
|
|
|
return check_fsl_memctl_config_regs(ddr);
|
|
|
|
}
|
2016-11-21 03:36:48 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_FSL_ERRATUM_A009942
|
|
|
|
/*
|
|
|
|
* This additional workaround of A009942 checks the condition to determine if
|
|
|
|
* the CPO value set by the existing A009942 workaround needs to be updated.
|
|
|
|
* If need, print a warning to prompt user reconfigure DDR debug_29[24:31] with
|
|
|
|
* expected optimal value, the optimal value is highly board dependent.
|
|
|
|
*/
|
|
|
|
void erratum_a009942_check_cpo(void)
|
|
|
|
{
|
|
|
|
struct ccsr_ddr __iomem *ddr =
|
|
|
|
(struct ccsr_ddr __iomem *)(CONFIG_SYS_FSL_DDR_ADDR);
|
|
|
|
u32 cpo, cpo_e, cpo_o, cpo_target, cpo_optimal;
|
|
|
|
u32 cpo_min = ddr_in32(&ddr->debug[9]) >> 24;
|
|
|
|
u32 cpo_max = cpo_min;
|
|
|
|
u32 sdram_cfg, i, tmp, lanes, ddr_type;
|
|
|
|
bool update_cpo = false, has_ecc = false;
|
|
|
|
|
|
|
|
sdram_cfg = ddr_in32(&ddr->sdram_cfg);
|
|
|
|
if (sdram_cfg & SDRAM_CFG_32_BE)
|
|
|
|
lanes = 4;
|
|
|
|
else if (sdram_cfg & SDRAM_CFG_16_BE)
|
|
|
|
lanes = 2;
|
|
|
|
else
|
|
|
|
lanes = 8;
|
|
|
|
|
|
|
|
if (sdram_cfg & SDRAM_CFG_ECC_EN)
|
|
|
|
has_ecc = true;
|
|
|
|
|
|
|
|
/* determine the maximum and minimum CPO values */
|
|
|
|
for (i = 9; i < 9 + lanes / 2; i++) {
|
|
|
|
cpo = ddr_in32(&ddr->debug[i]);
|
|
|
|
cpo_e = cpo >> 24;
|
|
|
|
cpo_o = (cpo >> 8) & 0xff;
|
|
|
|
tmp = min(cpo_e, cpo_o);
|
|
|
|
if (tmp < cpo_min)
|
|
|
|
cpo_min = tmp;
|
|
|
|
tmp = max(cpo_e, cpo_o);
|
|
|
|
if (tmp > cpo_max)
|
|
|
|
cpo_max = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_ecc) {
|
|
|
|
cpo = ddr_in32(&ddr->debug[13]);
|
|
|
|
cpo = cpo >> 24;
|
|
|
|
if (cpo < cpo_min)
|
|
|
|
cpo_min = cpo;
|
|
|
|
if (cpo > cpo_max)
|
|
|
|
cpo_max = cpo;
|
|
|
|
}
|
|
|
|
|
|
|
|
cpo_target = ddr_in32(&ddr->debug[28]) & 0xff;
|
|
|
|
cpo_optimal = ((cpo_max + cpo_min) >> 1) + 0x27;
|
|
|
|
debug("cpo_optimal = 0x%x, cpo_target = 0x%x\n", cpo_optimal,
|
|
|
|
cpo_target);
|
|
|
|
debug("cpo_max = 0x%x, cpo_min = 0x%x\n", cpo_max, cpo_min);
|
|
|
|
|
|
|
|
ddr_type = (sdram_cfg & SDRAM_CFG_SDRAM_TYPE_MASK) >>
|
|
|
|
SDRAM_CFG_SDRAM_TYPE_SHIFT;
|
|
|
|
if (ddr_type == SDRAM_TYPE_DDR4)
|
|
|
|
update_cpo = (cpo_min + 0x3b) < cpo_target ? true : false;
|
|
|
|
else if (ddr_type == SDRAM_TYPE_DDR3)
|
|
|
|
update_cpo = (cpo_min + 0x3f) < cpo_target ? true : false;
|
|
|
|
|
|
|
|
if (update_cpo) {
|
|
|
|
printf("WARN: pls set popts->cpo_sample = 0x%x ", cpo_optimal);
|
|
|
|
printf("in <board>/ddr.c to optimize cpo\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|