2018-05-07 06:58:06 +09:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2008-08-27 05:01:29 +09:00
|
|
|
/*
|
2014-03-28 09:54:47 +09:00
|
|
|
* Copyright 2008-2014 Freescale Semiconductor, Inc.
|
2008-08-27 05:01:29 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generic driver for Freescale DDR/DDR2/DDR3 memory controller.
|
|
|
|
* Based on code from spd_sdram.c
|
|
|
|
* Author: James Yang [at freescale.com]
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2011-02-01 13:18:47 +09:00
|
|
|
#include <i2c.h>
|
2013-10-01 01:22:09 +09:00
|
|
|
#include <fsl_ddr_sdram.h>
|
|
|
|
#include <fsl_ddr.h>
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2014-02-11 06:59:43 +09:00
|
|
|
/*
|
|
|
|
* CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY is the physical address from the view
|
|
|
|
* of DDR controllers. It is the same as CONFIG_SYS_DDR_SDRAM_BASE for
|
|
|
|
* all Power SoCs. But it could be different for ARM SoCs. For example,
|
|
|
|
* fsl_lsch3 has a mapping mechanism to map DDR memory to ranges (in order) of
|
|
|
|
* 0x00_8000_0000 ~ 0x00_ffff_ffff
|
|
|
|
* 0x80_8000_0000 ~ 0xff_ffff_ffff
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY
|
2019-01-21 17:18:16 +09:00
|
|
|
#ifdef CONFIG_MPC83xx
|
|
|
|
#define CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY CONFIG_SYS_SDRAM_BASE
|
|
|
|
#else
|
2014-02-11 06:59:43 +09:00
|
|
|
#define CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY CONFIG_SYS_DDR_SDRAM_BASE
|
|
|
|
#endif
|
2019-01-21 17:18:16 +09:00
|
|
|
#endif
|
2014-02-11 06:59:43 +09:00
|
|
|
|
2013-10-01 06:20:51 +09:00
|
|
|
#ifdef CONFIG_PPC
|
|
|
|
#include <asm/fsl_law.h>
|
|
|
|
|
2012-08-17 17:22:39 +09:00
|
|
|
void fsl_ddr_set_lawbar(
|
2008-08-27 05:01:29 +09:00
|
|
|
const common_timing_params_t *memctl_common_params,
|
|
|
|
unsigned int memctl_interleaved,
|
|
|
|
unsigned int ctrl_num);
|
2013-10-01 06:20:51 +09:00
|
|
|
#endif
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2013-10-01 06:20:51 +09:00
|
|
|
void fsl_ddr_set_intl3r(const unsigned int granule_size);
|
2011-02-01 13:18:47 +09:00
|
|
|
#if defined(SPD_EEPROM_ADDRESS) || \
|
|
|
|
defined(SPD_EEPROM_ADDRESS1) || defined(SPD_EEPROM_ADDRESS2) || \
|
|
|
|
defined(SPD_EEPROM_ADDRESS3) || defined(SPD_EEPROM_ADDRESS4)
|
2016-12-29 01:43:45 +09:00
|
|
|
#if (CONFIG_SYS_NUM_DDR_CTLRS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
|
|
|
|
u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
|
2011-02-01 13:18:47 +09:00
|
|
|
[0][0] = SPD_EEPROM_ADDRESS,
|
|
|
|
};
|
2016-12-29 01:43:45 +09:00
|
|
|
#elif (CONFIG_SYS_NUM_DDR_CTLRS == 1) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
|
|
|
|
u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
|
2011-08-27 03:32:41 +09:00
|
|
|
[0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
|
|
|
|
[0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
|
|
|
|
};
|
2016-12-29 01:43:45 +09:00
|
|
|
#elif (CONFIG_SYS_NUM_DDR_CTLRS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
|
|
|
|
u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
|
2011-02-01 13:18:47 +09:00
|
|
|
[0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
|
|
|
|
[1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */
|
|
|
|
};
|
2016-12-29 01:43:45 +09:00
|
|
|
#elif (CONFIG_SYS_NUM_DDR_CTLRS == 2) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
|
|
|
|
u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
|
2011-02-01 13:18:47 +09:00
|
|
|
[0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
|
|
|
|
[0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
|
|
|
|
[1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */
|
|
|
|
[1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */
|
|
|
|
};
|
2016-12-29 01:43:45 +09:00
|
|
|
#elif (CONFIG_SYS_NUM_DDR_CTLRS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 1)
|
|
|
|
u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
|
2012-08-17 17:22:39 +09:00
|
|
|
[0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
|
|
|
|
[1][0] = SPD_EEPROM_ADDRESS2, /* controller 2 */
|
|
|
|
[2][0] = SPD_EEPROM_ADDRESS3, /* controller 3 */
|
|
|
|
};
|
2016-12-29 01:43:45 +09:00
|
|
|
#elif (CONFIG_SYS_NUM_DDR_CTLRS == 3) && (CONFIG_DIMM_SLOTS_PER_CTLR == 2)
|
|
|
|
u8 spd_i2c_addr[CONFIG_SYS_NUM_DDR_CTLRS][CONFIG_DIMM_SLOTS_PER_CTLR] = {
|
2012-08-17 17:22:39 +09:00
|
|
|
[0][0] = SPD_EEPROM_ADDRESS1, /* controller 1 */
|
|
|
|
[0][1] = SPD_EEPROM_ADDRESS2, /* controller 1 */
|
|
|
|
[1][0] = SPD_EEPROM_ADDRESS3, /* controller 2 */
|
|
|
|
[1][1] = SPD_EEPROM_ADDRESS4, /* controller 2 */
|
|
|
|
[2][0] = SPD_EEPROM_ADDRESS5, /* controller 3 */
|
|
|
|
[2][1] = SPD_EEPROM_ADDRESS6, /* controller 3 */
|
|
|
|
};
|
|
|
|
|
2011-02-01 13:18:47 +09:00
|
|
|
#endif
|
|
|
|
|
2014-03-28 09:54:47 +09:00
|
|
|
#define SPD_SPA0_ADDRESS 0x36
|
|
|
|
#define SPD_SPA1_ADDRESS 0x37
|
|
|
|
|
2011-02-01 13:18:47 +09:00
|
|
|
static void __get_spd(generic_spd_eeprom_t *spd, u8 i2c_address)
|
|
|
|
{
|
2013-10-18 18:47:19 +09:00
|
|
|
int ret;
|
2014-03-28 09:54:47 +09:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
uint8_t dummy = 0;
|
|
|
|
#endif
|
2013-10-18 18:47:19 +09:00
|
|
|
|
2019-07-10 22:00:20 +09:00
|
|
|
#ifndef CONFIG_DM_I2C
|
2013-10-18 18:47:19 +09:00
|
|
|
i2c_set_bus_num(CONFIG_SYS_SPD_BUS_NUM);
|
2019-07-10 22:00:20 +09:00
|
|
|
#endif
|
|
|
|
|
2013-10-18 18:47:19 +09:00
|
|
|
|
2014-03-28 09:54:47 +09:00
|
|
|
#ifdef CONFIG_SYS_FSL_DDR4
|
|
|
|
/*
|
|
|
|
* DDR4 SPD has 384 to 512 bytes
|
|
|
|
* To access the lower 256 bytes, we need to set EE page address to 0
|
|
|
|
* To access the upper 256 bytes, we need to set EE page address to 1
|
|
|
|
* See Jedec standar No. 21-C for detail
|
|
|
|
*/
|
2019-07-10 22:00:20 +09:00
|
|
|
#ifndef CONFIG_DM_I2C
|
2014-03-28 09:54:47 +09:00
|
|
|
i2c_write(SPD_SPA0_ADDRESS, 0, 1, &dummy, 1);
|
|
|
|
ret = i2c_read(i2c_address, 0, 1, (uchar *)spd, 256);
|
|
|
|
if (!ret) {
|
|
|
|
i2c_write(SPD_SPA1_ADDRESS, 0, 1, &dummy, 1);
|
|
|
|
ret = i2c_read(i2c_address, 0, 1,
|
|
|
|
(uchar *)((ulong)spd + 256),
|
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-07 03:03:31 +09:00
|
|
|
min(256,
|
|
|
|
(int)sizeof(generic_spd_eeprom_t) - 256));
|
2014-03-28 09:54:47 +09:00
|
|
|
}
|
|
|
|
#else
|
2019-07-10 22:00:20 +09:00
|
|
|
struct udevice *dev;
|
|
|
|
int read_len = min(256, (int)sizeof(generic_spd_eeprom_t) - 256);
|
|
|
|
|
|
|
|
ret = i2c_get_chip_for_busnum(0, SPD_SPA0_ADDRESS, 1, &dev);
|
|
|
|
if (!ret)
|
|
|
|
dm_i2c_write(dev, 0, &dummy, 1);
|
|
|
|
ret = i2c_get_chip_for_busnum(0, i2c_address, 1, &dev);
|
|
|
|
if (!ret) {
|
|
|
|
if (!dm_i2c_read(dev, 0, (uchar *)spd, 256)) {
|
|
|
|
if (!i2c_get_chip_for_busnum(0, SPD_SPA1_ADDRESS,
|
|
|
|
1, &dev))
|
|
|
|
dm_i2c_write(dev, 0, &dummy, 1);
|
|
|
|
if (!i2c_get_chip_for_busnum(0, i2c_address, 1, &dev))
|
|
|
|
ret = dm_i2c_read(dev, 0,
|
|
|
|
(uchar *)((ulong)spd + 256),
|
|
|
|
read_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#ifndef CONFIG_DM_I2C
|
2013-10-18 18:47:19 +09:00
|
|
|
ret = i2c_read(i2c_address, 0, 1, (uchar *)spd,
|
2019-07-10 22:00:20 +09:00
|
|
|
sizeof(generic_spd_eeprom_t));
|
|
|
|
#else
|
|
|
|
ret = i2c_get_chip_for_busnum(0, i2c_address, 1, &dev);
|
|
|
|
if (!ret)
|
|
|
|
ret = dm_i2c_read(dev, 0, (uchar *)spd,
|
|
|
|
sizeof(generic_spd_eeprom_t));
|
|
|
|
#endif
|
|
|
|
|
2014-03-28 09:54:47 +09:00
|
|
|
#endif
|
2011-02-01 13:18:47 +09:00
|
|
|
|
|
|
|
if (ret) {
|
2012-10-08 16:44:28 +09:00
|
|
|
if (i2c_address ==
|
|
|
|
#ifdef SPD_EEPROM_ADDRESS
|
|
|
|
SPD_EEPROM_ADDRESS
|
|
|
|
#elif defined(SPD_EEPROM_ADDRESS1)
|
|
|
|
SPD_EEPROM_ADDRESS1
|
|
|
|
#endif
|
|
|
|
) {
|
|
|
|
printf("DDR: failed to read SPD from address %u\n",
|
|
|
|
i2c_address);
|
|
|
|
} else {
|
|
|
|
debug("DDR: failed to read SPD from address %u\n",
|
|
|
|
i2c_address);
|
|
|
|
}
|
2011-02-01 13:18:47 +09:00
|
|
|
memset(spd, 0, sizeof(generic_spd_eeprom_t));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak, alias("__get_spd")))
|
|
|
|
void get_spd(generic_spd_eeprom_t *spd, u8 i2c_address);
|
|
|
|
|
2015-05-28 18:24:08 +09:00
|
|
|
/* This function allows boards to update SPD address */
|
|
|
|
__weak void update_spd_address(unsigned int ctrl_num,
|
|
|
|
unsigned int slot,
|
|
|
|
unsigned int *addr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-01 13:18:47 +09:00
|
|
|
void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
|
2014-08-02 07:51:00 +09:00
|
|
|
unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl)
|
2011-02-01 13:18:47 +09:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
unsigned int i2c_address = 0;
|
|
|
|
|
2016-12-29 01:43:45 +09:00
|
|
|
if (ctrl_num >= CONFIG_SYS_NUM_DDR_CTLRS) {
|
2011-02-01 13:18:47 +09:00
|
|
|
printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = 0; i < dimm_slots_per_ctrl; i++) {
|
2011-02-01 13:18:47 +09:00
|
|
|
i2c_address = spd_i2c_addr[ctrl_num][i];
|
2015-05-28 18:24:08 +09:00
|
|
|
update_spd_address(ctrl_num, i, &i2c_address);
|
2011-02-01 13:18:47 +09:00
|
|
|
get_spd(&(ctrl_dimms_spd[i]), i2c_address);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void fsl_ddr_get_spd(generic_spd_eeprom_t *ctrl_dimms_spd,
|
2014-08-02 07:51:00 +09:00
|
|
|
unsigned int ctrl_num, unsigned int dimm_slots_per_ctrl)
|
2011-02-01 13:18:47 +09:00
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif /* SPD_EEPROM_ADDRESSx */
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ASSUMPTIONS:
|
|
|
|
* - Same number of CONFIG_DIMM_SLOTS_PER_CTLR on each controller
|
|
|
|
* - Same memory data bus width on all controllers
|
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
*
|
|
|
|
* The memory controller and associated documentation use confusing
|
|
|
|
* terminology when referring to the orgranization of DRAM.
|
|
|
|
*
|
|
|
|
* Here is a terminology translation table:
|
|
|
|
*
|
|
|
|
* memory controller/documention |industry |this code |signals
|
|
|
|
* -------------------------------|-----------|-----------|-----------------
|
2008-09-13 09:23:05 +09:00
|
|
|
* physical bank/bank |rank |rank |chip select (CS)
|
|
|
|
* logical bank/sub-bank |bank |bank |bank address (BA)
|
|
|
|
* page/row |row |page |row address
|
|
|
|
* ??? |column |column |column address
|
2008-08-27 05:01:29 +09:00
|
|
|
*
|
|
|
|
* The naming confusion is further exacerbated by the descriptions of the
|
|
|
|
* memory controller interleaving feature, where accesses are interleaved
|
|
|
|
* _BETWEEN_ two seperate memory controllers. This is configured only in
|
|
|
|
* CS0_CONFIG[INTLV_CTL] of each memory controller.
|
|
|
|
*
|
|
|
|
* memory controller documentation | number of chip selects
|
2008-09-13 09:23:05 +09:00
|
|
|
* | per memory controller supported
|
2008-08-27 05:01:29 +09:00
|
|
|
* --------------------------------|-----------------------------------------
|
2008-09-13 09:23:05 +09:00
|
|
|
* cache line interleaving | 1 (CS0 only)
|
|
|
|
* page interleaving | 1 (CS0 only)
|
|
|
|
* bank interleaving | 1 (CS0 only)
|
|
|
|
* superbank interleraving | depends on bank (chip select)
|
|
|
|
* | interleraving [rank interleaving]
|
|
|
|
* | mode used on every memory controller
|
2008-08-27 05:01:29 +09:00
|
|
|
*
|
|
|
|
* Even further confusing is the existence of the interleaving feature
|
|
|
|
* _WITHIN_ each memory controller. The feature is referred to in
|
|
|
|
* documentation as chip select interleaving or bank interleaving,
|
|
|
|
* although it is configured in the DDR_SDRAM_CFG field.
|
|
|
|
*
|
2008-09-13 09:23:05 +09:00
|
|
|
* Name of field | documentation name | this code
|
2008-08-27 05:01:29 +09:00
|
|
|
* -----------------------------|-----------------------|------------------
|
2008-09-13 09:23:05 +09:00
|
|
|
* DDR_SDRAM_CFG[BA_INTLV_CTL] | Bank (chip select) | rank interleaving
|
|
|
|
* | interleaving
|
2008-08-27 05:01:29 +09:00
|
|
|
*/
|
|
|
|
|
|
|
|
const char *step_string_tbl[] = {
|
|
|
|
"STEP_GET_SPD",
|
|
|
|
"STEP_COMPUTE_DIMM_PARMS",
|
|
|
|
"STEP_COMPUTE_COMMON_PARMS",
|
|
|
|
"STEP_GATHER_OPTS",
|
|
|
|
"STEP_ASSIGN_ADDRESSES",
|
|
|
|
"STEP_COMPUTE_REGS",
|
|
|
|
"STEP_PROGRAM_REGS",
|
|
|
|
"STEP_ALL"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char * step_to_string(unsigned int step) {
|
|
|
|
|
|
|
|
unsigned int s = __ilog2(step);
|
|
|
|
|
|
|
|
if ((1 << s) != step)
|
|
|
|
return step_string_tbl[7];
|
|
|
|
|
2014-04-02 06:20:49 +09:00
|
|
|
if (s >= ARRAY_SIZE(step_string_tbl)) {
|
|
|
|
printf("Error for the step in %s\n", __func__);
|
|
|
|
s = 0;
|
|
|
|
}
|
|
|
|
|
2008-08-27 05:01:29 +09:00
|
|
|
return step_string_tbl[s];
|
|
|
|
}
|
|
|
|
|
2013-03-25 16:39:35 +09:00
|
|
|
static unsigned long long __step_assign_addresses(fsl_ddr_info_t *pinfo,
|
2012-08-17 17:22:39 +09:00
|
|
|
unsigned int dbw_cap_adj[])
|
2008-08-27 05:01:29 +09:00
|
|
|
{
|
2014-08-02 07:51:00 +09:00
|
|
|
unsigned int i, j;
|
2012-08-17 17:22:39 +09:00
|
|
|
unsigned long long total_mem, current_mem_base, total_ctlr_mem;
|
|
|
|
unsigned long long rank_density, ctlr_density = 0;
|
2014-08-02 07:51:00 +09:00
|
|
|
unsigned int first_ctrl = pinfo->first_ctrl;
|
|
|
|
unsigned int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If a reduced data width is requested, but the SPD
|
|
|
|
* specifies a physically wider device, adjust the
|
|
|
|
* computed dimm capacities accordingly before
|
|
|
|
* assigning addresses.
|
|
|
|
*/
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
unsigned int found = 0;
|
|
|
|
|
|
|
|
switch (pinfo->memctl_opts[i].data_bus_width) {
|
|
|
|
case 2:
|
|
|
|
/* 16-bit */
|
2011-05-27 08:25:51 +09:00
|
|
|
for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
|
|
|
|
unsigned int dw;
|
|
|
|
if (!pinfo->dimm_params[i][j].n_ranks)
|
|
|
|
continue;
|
|
|
|
dw = pinfo->dimm_params[i][j].primary_sdram_width;
|
|
|
|
if ((dw == 72 || dw == 64)) {
|
|
|
|
dbw_cap_adj[i] = 2;
|
|
|
|
break;
|
|
|
|
} else if ((dw == 40 || dw == 32)) {
|
|
|
|
dbw_cap_adj[i] = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-08-27 05:01:29 +09:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
/* 32-bit */
|
|
|
|
for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
|
|
|
|
unsigned int dw;
|
|
|
|
dw = pinfo->dimm_params[i][j].data_width;
|
|
|
|
if (pinfo->dimm_params[i][j].n_ranks
|
|
|
|
&& (dw == 72 || dw == 64)) {
|
|
|
|
/*
|
|
|
|
* FIXME: can't really do it
|
|
|
|
* like this because this just
|
|
|
|
* further reduces the memory
|
|
|
|
*/
|
|
|
|
found = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (found) {
|
|
|
|
dbw_cap_adj[i] = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 0:
|
|
|
|
/* 64-bit */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printf("unexpected data bus width "
|
|
|
|
"specified controller %u\n", i);
|
|
|
|
return 1;
|
|
|
|
}
|
2012-08-17 17:22:39 +09:00
|
|
|
debug("dbw_cap_adj[%d]=%d\n", i, dbw_cap_adj[i]);
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
current_mem_base = pinfo->mem_base;
|
2012-08-17 17:22:39 +09:00
|
|
|
total_mem = 0;
|
2014-08-02 07:51:00 +09:00
|
|
|
if (pinfo->memctl_opts[first_ctrl].memctl_interleaving) {
|
|
|
|
rank_density = pinfo->dimm_params[first_ctrl][0].rank_density >>
|
|
|
|
dbw_cap_adj[first_ctrl];
|
|
|
|
switch (pinfo->memctl_opts[first_ctrl].ba_intlv_ctl &
|
2012-08-17 17:22:39 +09:00
|
|
|
FSL_DDR_CS0_CS1_CS2_CS3) {
|
|
|
|
case FSL_DDR_CS0_CS1_CS2_CS3:
|
|
|
|
ctlr_density = 4 * rank_density;
|
|
|
|
break;
|
|
|
|
case FSL_DDR_CS0_CS1:
|
|
|
|
case FSL_DDR_CS0_CS1_AND_CS2_CS3:
|
|
|
|
ctlr_density = 2 * rank_density;
|
|
|
|
break;
|
|
|
|
case FSL_DDR_CS2_CS3:
|
|
|
|
default:
|
|
|
|
ctlr_density = rank_density;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
debug("rank density is 0x%llx, ctlr density is 0x%llx\n",
|
|
|
|
rank_density, ctlr_density);
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2012-08-17 17:22:39 +09:00
|
|
|
if (pinfo->memctl_opts[i].memctl_interleaving) {
|
|
|
|
switch (pinfo->memctl_opts[i].memctl_interleaving_mode) {
|
2014-02-11 06:59:44 +09:00
|
|
|
case FSL_DDR_256B_INTERLEAVING:
|
2012-08-17 17:22:39 +09:00
|
|
|
case FSL_DDR_CACHE_LINE_INTERLEAVING:
|
|
|
|
case FSL_DDR_PAGE_INTERLEAVING:
|
|
|
|
case FSL_DDR_BANK_INTERLEAVING:
|
|
|
|
case FSL_DDR_SUPERBANK_INTERLEAVING:
|
|
|
|
total_ctlr_mem = 2 * ctlr_density;
|
|
|
|
break;
|
|
|
|
case FSL_DDR_3WAY_1KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_3WAY_4KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_3WAY_8KB_INTERLEAVING:
|
|
|
|
total_ctlr_mem = 3 * ctlr_density;
|
|
|
|
break;
|
|
|
|
case FSL_DDR_4WAY_1KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_4WAY_4KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_4WAY_8KB_INTERLEAVING:
|
|
|
|
total_ctlr_mem = 4 * ctlr_density;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
panic("Unknown interleaving mode");
|
|
|
|
}
|
|
|
|
pinfo->common_timing_params[i].base_address =
|
|
|
|
current_mem_base;
|
|
|
|
pinfo->common_timing_params[i].total_mem =
|
|
|
|
total_ctlr_mem;
|
|
|
|
total_mem = current_mem_base + total_ctlr_mem;
|
|
|
|
debug("ctrl %d base 0x%llx\n", i, current_mem_base);
|
|
|
|
debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
|
|
|
|
} else {
|
|
|
|
/* when 3rd controller not interleaved */
|
|
|
|
current_mem_base = total_mem;
|
|
|
|
total_ctlr_mem = 0;
|
|
|
|
pinfo->common_timing_params[i].base_address =
|
|
|
|
current_mem_base;
|
|
|
|
for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
|
|
|
|
unsigned long long cap =
|
|
|
|
pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i];
|
|
|
|
pinfo->dimm_params[i][j].base_address =
|
|
|
|
current_mem_base;
|
|
|
|
debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base);
|
|
|
|
current_mem_base += cap;
|
|
|
|
total_ctlr_mem += cap;
|
|
|
|
}
|
|
|
|
debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
|
|
|
|
pinfo->common_timing_params[i].total_mem =
|
|
|
|
total_ctlr_mem;
|
|
|
|
total_mem += total_ctlr_mem;
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Simple linear assignment if memory
|
|
|
|
* controllers are not interleaved.
|
|
|
|
*/
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2012-08-17 17:22:39 +09:00
|
|
|
total_ctlr_mem = 0;
|
2008-08-27 05:01:29 +09:00
|
|
|
pinfo->common_timing_params[i].base_address =
|
2012-08-17 17:22:39 +09:00
|
|
|
current_mem_base;
|
2008-08-27 05:01:29 +09:00
|
|
|
for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
|
|
|
|
/* Compute DIMM base addresses. */
|
|
|
|
unsigned long long cap =
|
2012-08-17 17:22:39 +09:00
|
|
|
pinfo->dimm_params[i][j].capacity >> dbw_cap_adj[i];
|
2008-08-27 05:01:29 +09:00
|
|
|
pinfo->dimm_params[i][j].base_address =
|
2012-08-17 17:22:39 +09:00
|
|
|
current_mem_base;
|
|
|
|
debug("ctrl %d dimm %d base 0x%llx\n", i, j, current_mem_base);
|
|
|
|
current_mem_base += cap;
|
|
|
|
total_ctlr_mem += cap;
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
2012-08-17 17:22:39 +09:00
|
|
|
debug("ctrl %d total 0x%llx\n", i, total_ctlr_mem);
|
2008-08-27 05:01:29 +09:00
|
|
|
pinfo->common_timing_params[i].total_mem =
|
2012-08-17 17:22:39 +09:00
|
|
|
total_ctlr_mem;
|
|
|
|
total_mem += total_ctlr_mem;
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
}
|
2012-08-17 17:22:39 +09:00
|
|
|
debug("Total mem by %s is 0x%llx\n", __func__, total_mem);
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2012-08-17 17:22:39 +09:00
|
|
|
return total_mem;
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
2013-03-25 16:39:35 +09:00
|
|
|
/* Use weak function to allow board file to override the address assignment */
|
|
|
|
__attribute__((weak, alias("__step_assign_addresses")))
|
|
|
|
unsigned long long step_assign_addresses(fsl_ddr_info_t *pinfo,
|
|
|
|
unsigned int dbw_cap_adj[]);
|
|
|
|
|
2009-06-12 13:42:35 +09:00
|
|
|
unsigned long long
|
2010-12-02 00:35:31 +09:00
|
|
|
fsl_ddr_compute(fsl_ddr_info_t *pinfo, unsigned int start_step,
|
|
|
|
unsigned int size_only)
|
2008-08-27 05:01:29 +09:00
|
|
|
{
|
|
|
|
unsigned int i, j;
|
2009-06-12 13:42:35 +09:00
|
|
|
unsigned long long total_mem = 0;
|
2014-08-02 07:51:00 +09:00
|
|
|
int assert_reset = 0;
|
|
|
|
unsigned int first_ctrl = pinfo->first_ctrl;
|
|
|
|
unsigned int last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
|
|
|
|
__maybe_unused int retval;
|
|
|
|
__maybe_unused bool goodspd = false;
|
|
|
|
__maybe_unused int dimm_slots_per_ctrl = pinfo->dimm_slots_per_ctrl;
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
fsl_ddr_cfg_regs_t *ddr_reg = pinfo->fsl_ddr_config_reg;
|
|
|
|
common_timing_params_t *timing_params = pinfo->common_timing_params;
|
2014-08-02 07:51:00 +09:00
|
|
|
if (pinfo->board_need_mem_reset)
|
|
|
|
assert_reset = pinfo->board_need_mem_reset();
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
/* data bus width capacity adjust shift amount */
|
2016-12-29 01:43:45 +09:00
|
|
|
unsigned int dbw_capacity_adjust[CONFIG_SYS_NUM_DDR_CTLRS];
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++)
|
2008-08-27 05:01:29 +09:00
|
|
|
dbw_capacity_adjust[i] = 0;
|
|
|
|
|
|
|
|
debug("starting at step %u (%s)\n",
|
|
|
|
start_step, step_to_string(start_step));
|
|
|
|
|
|
|
|
switch (start_step) {
|
|
|
|
case STEP_GET_SPD:
|
2011-06-07 10:42:16 +09:00
|
|
|
#if defined(CONFIG_DDR_SPD) || defined(CONFIG_SPD_EEPROM)
|
2008-08-27 05:01:29 +09:00
|
|
|
/* STEP 1: Gather all DIMM SPD data */
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
|
|
|
fsl_ddr_get_spd(pinfo->spd_installed_dimms[i], i,
|
|
|
|
dimm_slots_per_ctrl);
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
case STEP_COMPUTE_DIMM_PARMS:
|
|
|
|
/* STEP 2: Compute DIMM parameters from SPD data */
|
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
|
|
|
|
generic_spd_eeprom_t *spd =
|
|
|
|
&(pinfo->spd_installed_dimms[i][j]);
|
|
|
|
dimm_params_t *pdimm =
|
2008-09-13 09:23:05 +09:00
|
|
|
&(pinfo->dimm_params[i][j]);
|
2015-01-07 06:18:50 +09:00
|
|
|
retval = compute_dimm_parameters(
|
|
|
|
i, spd, pdimm, j);
|
2011-06-07 10:42:17 +09:00
|
|
|
#ifdef CONFIG_SYS_DDR_RAW_TIMING
|
2015-03-20 01:30:26 +09:00
|
|
|
if (!j && retval) {
|
2012-08-17 17:22:39 +09:00
|
|
|
printf("SPD error on controller %d! "
|
|
|
|
"Trying fallback to raw timing "
|
|
|
|
"calculation\n", i);
|
2014-08-02 07:51:00 +09:00
|
|
|
retval = fsl_ddr_get_dimm_params(pdimm,
|
|
|
|
i, j);
|
2011-06-07 10:42:17 +09:00
|
|
|
}
|
|
|
|
#else
|
2008-08-27 05:01:29 +09:00
|
|
|
if (retval == 2) {
|
|
|
|
printf("Error: compute_dimm_parameters"
|
|
|
|
" non-zero returned FATAL value "
|
|
|
|
"for memctl=%u dimm=%u\n", i, j);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-06-07 10:42:17 +09:00
|
|
|
#endif
|
2008-08-27 05:01:29 +09:00
|
|
|
if (retval) {
|
|
|
|
debug("Warning: compute_dimm_parameters"
|
|
|
|
" non-zero return value for memctl=%u "
|
|
|
|
"dimm=%u\n", i, j);
|
2014-08-02 07:51:00 +09:00
|
|
|
} else {
|
|
|
|
goodspd = true;
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-08-02 07:51:00 +09:00
|
|
|
if (!goodspd) {
|
|
|
|
/*
|
|
|
|
* No valid SPD found
|
|
|
|
* Throw an error if this is for main memory, i.e.
|
|
|
|
* first_ctrl == 0. Otherwise, siliently return 0
|
|
|
|
* as the memory size.
|
|
|
|
*/
|
|
|
|
if (first_ctrl == 0)
|
|
|
|
printf("Error: No valid SPD detected.\n");
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
return 0;
|
|
|
|
}
|
2012-06-29 08:36:38 +09:00
|
|
|
#elif defined(CONFIG_SYS_DDR_RAW_TIMING)
|
2011-06-07 10:42:16 +09:00
|
|
|
case STEP_COMPUTE_DIMM_PARMS:
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2011-06-07 10:42:16 +09:00
|
|
|
for (j = 0; j < CONFIG_DIMM_SLOTS_PER_CTLR; j++) {
|
|
|
|
dimm_params_t *pdimm =
|
|
|
|
&(pinfo->dimm_params[i][j]);
|
|
|
|
fsl_ddr_get_dimm_params(pdimm, i, j);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
debug("Filling dimm parameters from board specific file\n");
|
|
|
|
#endif
|
2008-08-27 05:01:29 +09:00
|
|
|
case STEP_COMPUTE_COMMON_PARMS:
|
|
|
|
/*
|
|
|
|
* STEP 3: Compute a common set of timing parameters
|
|
|
|
* suitable for all of the DIMMs on each memory controller
|
|
|
|
*/
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
debug("Computing lowest common DIMM"
|
|
|
|
" parameters for memctl=%u\n", i);
|
2015-01-07 06:18:50 +09:00
|
|
|
compute_lowest_common_dimm_parameters
|
|
|
|
(i,
|
|
|
|
pinfo->dimm_params[i],
|
|
|
|
&timing_params[i],
|
|
|
|
CONFIG_DIMM_SLOTS_PER_CTLR);
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
case STEP_GATHER_OPTS:
|
|
|
|
/* STEP 4: Gather configuration requirements from user */
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
debug("Reloading memory controller "
|
|
|
|
"configuration options for memctl=%u\n", i);
|
|
|
|
/*
|
|
|
|
* This "reloads" the memory controller options
|
|
|
|
* to defaults. If the user "edits" an option,
|
|
|
|
* next_step points to the step after this,
|
|
|
|
* which is currently STEP_ASSIGN_ADDRESSES.
|
|
|
|
*/
|
|
|
|
populate_memctl_options(
|
2015-07-24 06:04:48 +09:00
|
|
|
&timing_params[i],
|
2008-10-04 01:36:55 +09:00
|
|
|
&pinfo->memctl_opts[i],
|
|
|
|
pinfo->dimm_params[i], i);
|
2013-06-26 03:37:48 +09:00
|
|
|
/*
|
|
|
|
* For RDIMMs, JEDEC spec requires clocks to be stable
|
|
|
|
* before reset signal is deasserted. For the boards
|
|
|
|
* using fixed parameters, this function should be
|
|
|
|
* be called from board init file.
|
|
|
|
*/
|
2013-09-25 14:11:19 +09:00
|
|
|
if (timing_params[i].all_dimms_registered)
|
2013-06-26 03:37:48 +09:00
|
|
|
assert_reset = 1;
|
|
|
|
}
|
2014-08-02 07:51:00 +09:00
|
|
|
if (assert_reset && !size_only) {
|
|
|
|
if (pinfo->board_mem_reset) {
|
|
|
|
debug("Asserting mem reset\n");
|
|
|
|
pinfo->board_mem_reset();
|
|
|
|
} else {
|
|
|
|
debug("Asserting mem reset missing\n");
|
|
|
|
}
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
2013-06-26 03:37:48 +09:00
|
|
|
|
2008-08-27 05:01:29 +09:00
|
|
|
case STEP_ASSIGN_ADDRESSES:
|
|
|
|
/* STEP 5: Assign addresses to chip selects */
|
2012-08-17 17:22:39 +09:00
|
|
|
check_interleaving_options(pinfo);
|
|
|
|
total_mem = step_assign_addresses(pinfo, dbw_capacity_adjust);
|
2014-04-02 06:20:49 +09:00
|
|
|
debug("Total mem %llu assigned\n", total_mem);
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
case STEP_COMPUTE_REGS:
|
|
|
|
/* STEP 6: compute controller register values */
|
2012-08-17 17:22:39 +09:00
|
|
|
debug("FSL Memory ctrl register computation\n");
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
if (timing_params[i].ndimms_present == 0) {
|
|
|
|
memset(&ddr_reg[i], 0,
|
|
|
|
sizeof(fsl_ddr_cfg_regs_t));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-07 06:18:50 +09:00
|
|
|
compute_fsl_memctl_config_regs
|
|
|
|
(i,
|
|
|
|
&pinfo->memctl_opts[i],
|
|
|
|
&ddr_reg[i], &timing_params[i],
|
|
|
|
pinfo->dimm_params[i],
|
|
|
|
dbw_capacity_adjust[i],
|
|
|
|
size_only);
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-08-17 17:22:39 +09:00
|
|
|
{
|
2008-08-27 05:01:29 +09:00
|
|
|
/*
|
|
|
|
* Compute the amount of memory available just by
|
|
|
|
* looking for the highest valid CSn_BNDS value.
|
|
|
|
* This allows us to also experiment with using
|
|
|
|
* only CS0 when using dual-rank DIMMs.
|
|
|
|
*/
|
|
|
|
unsigned int max_end = 0;
|
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
for (j = 0; j < CONFIG_CHIP_SELECTS_PER_CTRL; j++) {
|
|
|
|
fsl_ddr_cfg_regs_t *reg = &ddr_reg[i];
|
|
|
|
if (reg->cs[j].config & 0x80000000) {
|
|
|
|
unsigned int end;
|
2013-06-26 03:37:45 +09:00
|
|
|
/*
|
|
|
|
* 0xfffffff is a special value we put
|
|
|
|
* for unused bnds
|
|
|
|
*/
|
|
|
|
if (reg->cs[j].bnds == 0xffffffff)
|
|
|
|
continue;
|
|
|
|
end = reg->cs[j].bnds & 0xffff;
|
2008-08-27 05:01:29 +09:00
|
|
|
if (end > max_end) {
|
|
|
|
max_end = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-29 08:36:02 +09:00
|
|
|
total_mem = 1 + (((unsigned long long)max_end << 24ULL) |
|
2014-08-02 07:51:00 +09:00
|
|
|
0xFFFFFFULL) - pinfo->mem_base;
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
return total_mem;
|
|
|
|
}
|
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
phys_size_t __fsl_ddr_sdram(fsl_ddr_info_t *pinfo)
|
2008-08-27 05:01:29 +09:00
|
|
|
{
|
2014-08-02 07:51:00 +09:00
|
|
|
unsigned int i, first_ctrl, last_ctrl;
|
2013-10-01 06:20:51 +09:00
|
|
|
#ifdef CONFIG_PPC
|
2012-08-17 17:22:39 +09:00
|
|
|
unsigned int law_memctl = LAW_TRGT_IF_DDR_1;
|
2013-10-01 06:20:51 +09:00
|
|
|
#endif
|
2009-06-12 13:42:35 +09:00
|
|
|
unsigned long long total_memory;
|
2014-08-02 07:51:00 +09:00
|
|
|
int deassert_reset = 0;
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2014-08-02 07:51:00 +09:00
|
|
|
first_ctrl = pinfo->first_ctrl;
|
|
|
|
last_ctrl = first_ctrl + pinfo->num_ctrls - 1;
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
/* Compute it once normally. */
|
2011-09-17 05:21:35 +09:00
|
|
|
#ifdef CONFIG_FSL_DDR_INTERACTIVE
|
2013-01-07 23:01:03 +09:00
|
|
|
if (tstc() && (getc() == 'd')) { /* we got a key press of 'd' */
|
2014-08-02 07:51:00 +09:00
|
|
|
total_memory = fsl_ddr_interactive(pinfo, 0);
|
2013-01-07 23:01:03 +09:00
|
|
|
} else if (fsl_ddr_interactive_env_var_exists()) {
|
2014-08-02 07:51:00 +09:00
|
|
|
total_memory = fsl_ddr_interactive(pinfo, 1);
|
2013-01-04 17:13:59 +09:00
|
|
|
} else
|
2011-09-17 05:21:35 +09:00
|
|
|
#endif
|
2014-08-02 07:51:00 +09:00
|
|
|
total_memory = fsl_ddr_compute(pinfo, STEP_GET_SPD, 0);
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2012-10-08 16:44:24 +09:00
|
|
|
/* setup 3-way interleaving before enabling DDRC */
|
2014-08-02 07:51:00 +09:00
|
|
|
switch (pinfo->memctl_opts[first_ctrl].memctl_interleaving_mode) {
|
|
|
|
case FSL_DDR_3WAY_1KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_3WAY_4KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_3WAY_8KB_INTERLEAVING:
|
|
|
|
fsl_ddr_set_intl3r(
|
|
|
|
pinfo->memctl_opts[first_ctrl].
|
|
|
|
memctl_interleaving_mode);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2012-10-08 16:44:24 +09:00
|
|
|
}
|
|
|
|
|
2013-06-26 03:37:48 +09:00
|
|
|
/*
|
|
|
|
* Program configuration registers.
|
|
|
|
* JEDEC specs requires clocks to be stable before deasserting reset
|
|
|
|
* for RDIMMs. Clocks start after chip select is enabled and clock
|
|
|
|
* control register is set. During step 1, all controllers have their
|
|
|
|
* registers set but not enabled. Step 2 proceeds after deasserting
|
|
|
|
* reset through board FPGA or GPIO.
|
|
|
|
* For non-registered DIMMs, initialization can go through but it is
|
|
|
|
* also OK to follow the same flow.
|
|
|
|
*/
|
2014-08-02 07:51:00 +09:00
|
|
|
if (pinfo->board_need_mem_reset)
|
|
|
|
deassert_reset = pinfo->board_need_mem_reset();
|
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
|
|
|
if (pinfo->common_timing_params[i].all_dimms_registered)
|
2013-06-26 03:37:48 +09:00
|
|
|
deassert_reset = 1;
|
|
|
|
}
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2008-08-27 05:01:29 +09:00
|
|
|
debug("Programming controller %u\n", i);
|
2014-08-02 07:51:00 +09:00
|
|
|
if (pinfo->common_timing_params[i].ndimms_present == 0) {
|
2008-08-27 05:01:29 +09:00
|
|
|
debug("No dimms present on controller %u; "
|
|
|
|
"skipping programming\n", i);
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-26 03:37:48 +09:00
|
|
|
/*
|
|
|
|
* The following call with step = 1 returns before enabling
|
|
|
|
* the controller. It has to finish with step = 2 later.
|
|
|
|
*/
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_memctl_regs(&(pinfo->fsl_ddr_config_reg[i]), i,
|
2013-06-26 03:37:48 +09:00
|
|
|
deassert_reset ? 1 : 0);
|
|
|
|
}
|
|
|
|
if (deassert_reset) {
|
|
|
|
/* Use board FPGA or GPIO to deassert reset signal */
|
2014-08-02 07:51:00 +09:00
|
|
|
if (pinfo->board_mem_de_reset) {
|
|
|
|
debug("Deasserting mem reset\n");
|
|
|
|
pinfo->board_mem_de_reset();
|
|
|
|
} else {
|
|
|
|
debug("Deasserting mem reset missing\n");
|
|
|
|
}
|
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
2013-06-26 03:37:48 +09:00
|
|
|
/* Call with step = 2 to continue initialization */
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_memctl_regs(&(pinfo->fsl_ddr_config_reg[i]),
|
2013-06-26 03:37:48 +09:00
|
|
|
i, 2);
|
|
|
|
}
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
|
2015-01-07 06:18:55 +09:00
|
|
|
#ifdef CONFIG_FSL_DDR_SYNC_REFRESH
|
|
|
|
fsl_ddr_sync_memctl_refresh(first_ctrl, last_ctrl);
|
|
|
|
#endif
|
|
|
|
|
2013-10-01 06:20:51 +09:00
|
|
|
#ifdef CONFIG_PPC
|
2012-08-17 17:22:39 +09:00
|
|
|
/* program LAWs */
|
2014-08-02 07:51:00 +09:00
|
|
|
for (i = first_ctrl; i <= last_ctrl; i++) {
|
|
|
|
if (pinfo->memctl_opts[i].memctl_interleaving) {
|
|
|
|
switch (pinfo->memctl_opts[i].
|
|
|
|
memctl_interleaving_mode) {
|
2012-08-17 17:22:39 +09:00
|
|
|
case FSL_DDR_CACHE_LINE_INTERLEAVING:
|
|
|
|
case FSL_DDR_PAGE_INTERLEAVING:
|
|
|
|
case FSL_DDR_BANK_INTERLEAVING:
|
|
|
|
case FSL_DDR_SUPERBANK_INTERLEAVING:
|
2014-08-02 07:51:00 +09:00
|
|
|
if (i % 2)
|
|
|
|
break;
|
2012-08-17 17:22:39 +09:00
|
|
|
if (i == 0) {
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_INTRLV;
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_lawbar(
|
|
|
|
&pinfo->common_timing_params[i],
|
2012-08-17 17:22:39 +09:00
|
|
|
law_memctl, i);
|
2014-08-02 07:51:00 +09:00
|
|
|
}
|
2016-12-29 01:43:45 +09:00
|
|
|
#if CONFIG_SYS_NUM_DDR_CTLRS > 3
|
2014-08-02 07:51:00 +09:00
|
|
|
else if (i == 2) {
|
2012-08-17 17:22:39 +09:00
|
|
|
law_memctl = LAW_TRGT_IF_DDR_INTLV_34;
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_lawbar(
|
|
|
|
&pinfo->common_timing_params[i],
|
2012-08-17 17:22:39 +09:00
|
|
|
law_memctl, i);
|
|
|
|
}
|
2014-08-02 07:51:00 +09:00
|
|
|
#endif
|
2012-08-17 17:22:39 +09:00
|
|
|
break;
|
|
|
|
case FSL_DDR_3WAY_1KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_3WAY_4KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_3WAY_8KB_INTERLEAVING:
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_INTLV_123;
|
|
|
|
if (i == 0) {
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_lawbar(
|
|
|
|
&pinfo->common_timing_params[i],
|
2012-08-17 17:22:39 +09:00
|
|
|
law_memctl, i);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FSL_DDR_4WAY_1KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_4WAY_4KB_INTERLEAVING:
|
|
|
|
case FSL_DDR_4WAY_8KB_INTERLEAVING:
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_INTLV_1234;
|
|
|
|
if (i == 0)
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_lawbar(
|
|
|
|
&pinfo->common_timing_params[i],
|
2012-08-17 17:22:39 +09:00
|
|
|
law_memctl, i);
|
|
|
|
/* place holder for future 4-way interleaving */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch (i) {
|
|
|
|
case 0:
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_2;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_3;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
law_memctl = LAW_TRGT_IF_DDR_4;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2014-08-02 07:51:00 +09:00
|
|
|
fsl_ddr_set_lawbar(&pinfo->common_timing_params[i],
|
|
|
|
law_memctl, i);
|
2008-08-27 05:01:29 +09:00
|
|
|
}
|
|
|
|
}
|
2013-10-01 06:20:51 +09:00
|
|
|
#endif
|
2008-08-27 05:01:29 +09:00
|
|
|
|
2012-08-17 17:22:39 +09:00
|
|
|
debug("total_memory by %s = %llu\n", __func__, total_memory);
|
2009-06-12 13:42:35 +09:00
|
|
|
|
|
|
|
#if !defined(CONFIG_PHYS_64BIT)
|
|
|
|
/* Check for 4G or more. Bad. */
|
2014-08-02 07:51:00 +09:00
|
|
|
if ((first_ctrl == 0) && (total_memory >= (1ull << 32))) {
|
2013-08-16 01:25:37 +09:00
|
|
|
puts("Detected ");
|
|
|
|
print_size(total_memory, " of memory\n");
|
2010-12-18 08:17:59 +09:00
|
|
|
printf(" This U-Boot only supports < 4G of DDR\n");
|
|
|
|
printf(" You could rebuild it with CONFIG_PHYS_64BIT\n");
|
2017-04-07 03:47:05 +09:00
|
|
|
printf(" "); /* re-align to match init_dram print */
|
2009-06-12 13:42:35 +09:00
|
|
|
total_memory = CONFIG_MAX_MEM_MAPPED;
|
|
|
|
}
|
|
|
|
#endif
|
2008-08-27 05:01:29 +09:00
|
|
|
|
|
|
|
return total_memory;
|
|
|
|
}
|
2010-12-02 00:35:31 +09:00
|
|
|
|
|
|
|
/*
|
2014-08-02 07:51:00 +09:00
|
|
|
* fsl_ddr_sdram(void) -- this is the main function to be
|
2017-04-07 03:47:05 +09:00
|
|
|
* called by dram_init() in the board file.
|
2014-08-02 07:51:00 +09:00
|
|
|
*
|
|
|
|
* It returns amount of memory configured in bytes.
|
|
|
|
*/
|
|
|
|
phys_size_t fsl_ddr_sdram(void)
|
|
|
|
{
|
|
|
|
fsl_ddr_info_t info;
|
|
|
|
|
|
|
|
/* Reset info structure. */
|
|
|
|
memset(&info, 0, sizeof(fsl_ddr_info_t));
|
|
|
|
info.mem_base = CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY;
|
|
|
|
info.first_ctrl = 0;
|
|
|
|
info.num_ctrls = CONFIG_SYS_FSL_DDR_MAIN_NUM_CTRLS;
|
|
|
|
info.dimm_slots_per_ctrl = CONFIG_DIMM_SLOTS_PER_CTLR;
|
|
|
|
info.board_need_mem_reset = board_need_mem_reset;
|
|
|
|
info.board_mem_reset = board_assert_mem_reset;
|
|
|
|
info.board_mem_de_reset = board_deassert_mem_reset;
|
2015-11-05 02:53:10 +09:00
|
|
|
remove_unused_controllers(&info);
|
2014-08-02 07:51:00 +09:00
|
|
|
|
|
|
|
return __fsl_ddr_sdram(&info);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_SYS_FSL_OTHER_DDR_NUM_CTRLS
|
|
|
|
phys_size_t fsl_other_ddr_sdram(unsigned long long base,
|
|
|
|
unsigned int first_ctrl,
|
|
|
|
unsigned int num_ctrls,
|
|
|
|
unsigned int dimm_slots_per_ctrl,
|
|
|
|
int (*board_need_reset)(void),
|
|
|
|
void (*board_reset)(void),
|
|
|
|
void (*board_de_reset)(void))
|
|
|
|
{
|
|
|
|
fsl_ddr_info_t info;
|
|
|
|
|
|
|
|
/* Reset info structure. */
|
|
|
|
memset(&info, 0, sizeof(fsl_ddr_info_t));
|
|
|
|
info.mem_base = base;
|
|
|
|
info.first_ctrl = first_ctrl;
|
|
|
|
info.num_ctrls = num_ctrls;
|
|
|
|
info.dimm_slots_per_ctrl = dimm_slots_per_ctrl;
|
|
|
|
info.board_need_mem_reset = board_need_reset;
|
|
|
|
info.board_mem_reset = board_reset;
|
|
|
|
info.board_mem_de_reset = board_de_reset;
|
|
|
|
|
|
|
|
return __fsl_ddr_sdram(&info);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* fsl_ddr_sdram_size(first_ctrl, last_intlv) - This function only returns the
|
|
|
|
* size of the total memory without setting ddr control registers.
|
2010-12-02 00:35:31 +09:00
|
|
|
*/
|
|
|
|
phys_size_t
|
|
|
|
fsl_ddr_sdram_size(void)
|
|
|
|
{
|
|
|
|
fsl_ddr_info_t info;
|
|
|
|
unsigned long long total_memory = 0;
|
|
|
|
|
|
|
|
memset(&info, 0 , sizeof(fsl_ddr_info_t));
|
2014-08-02 07:51:00 +09:00
|
|
|
info.mem_base = CONFIG_SYS_FSL_DDR_SDRAM_BASE_PHY;
|
|
|
|
info.first_ctrl = 0;
|
|
|
|
info.num_ctrls = CONFIG_SYS_FSL_DDR_MAIN_NUM_CTRLS;
|
|
|
|
info.dimm_slots_per_ctrl = CONFIG_DIMM_SLOTS_PER_CTLR;
|
|
|
|
info.board_need_mem_reset = NULL;
|
2016-01-15 03:28:04 +09:00
|
|
|
remove_unused_controllers(&info);
|
2010-12-02 00:35:31 +09:00
|
|
|
|
|
|
|
/* Compute it once normally. */
|
|
|
|
total_memory = fsl_ddr_compute(&info, STEP_GET_SPD, 1);
|
|
|
|
|
|
|
|
return total_memory;
|
|
|
|
}
|