2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2010-06-07 19:20:34 +00:00
|
|
|
/*
|
|
|
|
* Functions related to OMAP3 SDRC.
|
|
|
|
*
|
|
|
|
* This file has been created after exctracting and consolidating
|
|
|
|
* the SDRC related content from mem.c and board.c, also created
|
|
|
|
* generic init function (mem_init).
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004-2010
|
|
|
|
* Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
*
|
2011-09-14 19:15:37 +00:00
|
|
|
* Copyright (C) 2011
|
|
|
|
* Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
|
|
|
|
*
|
2010-06-07 19:20:34 +00:00
|
|
|
* Author :
|
|
|
|
* Vaibhav Hiremath <hvaibhav@ti.com>
|
|
|
|
*
|
|
|
|
* Original implementation by (mem.c, board.c) :
|
|
|
|
* Sunil Kumar <sunilsaini05@gmail.com>
|
|
|
|
* Shashi Ranjan <shashiranjanmca05@gmail.com>
|
|
|
|
* Manikandan Pillai <mani.pillai@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2010-06-07 19:20:34 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/mem.h>
|
|
|
|
#include <asm/arch/sys_proto.h>
|
|
|
|
|
2010-12-11 16:41:42 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2010-06-07 19:20:34 +00:00
|
|
|
extern omap3_sysinfo sysinfo;
|
|
|
|
|
|
|
|
static struct sdrc *sdrc_base = (struct sdrc *)OMAP34XX_SDRC_BASE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* is_mem_sdr -
|
|
|
|
* - Return 1 if mem type in use is SDR
|
|
|
|
*/
|
|
|
|
u32 is_mem_sdr(void)
|
|
|
|
{
|
|
|
|
if (readl(&sdrc_base->cs[CS0].mr) == SDRC_MR_0_SDR)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* make_cs1_contiguous -
|
2011-11-18 12:47:59 +00:00
|
|
|
* - When we have CS1 populated we want to have it mapped after cs0 to allow
|
|
|
|
* command line mem=xyz use all memory with out discontinuous support
|
|
|
|
* compiled in. We could do it in the ATAG, but there really is two banks...
|
2010-06-07 19:20:34 +00:00
|
|
|
*/
|
|
|
|
void make_cs1_contiguous(void)
|
|
|
|
{
|
|
|
|
u32 size, a_add_low, a_add_high;
|
|
|
|
|
|
|
|
size = get_sdr_cs_size(CS0);
|
|
|
|
size >>= 25; /* divide by 32 MiB to find size to offset CS1 */
|
|
|
|
a_add_high = (size & 3) << 8; /* set up low field */
|
|
|
|
a_add_low = (size & 0x3C) >> 2; /* set up high field */
|
|
|
|
writel((a_add_high | a_add_low), &sdrc_base->cs_cfg);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_sdr_cs_size -
|
|
|
|
* - Get size of chip select 0/1
|
|
|
|
*/
|
|
|
|
u32 get_sdr_cs_size(u32 cs)
|
|
|
|
{
|
|
|
|
u32 size;
|
|
|
|
|
|
|
|
/* get ram size field */
|
|
|
|
size = readl(&sdrc_base->cs[cs].mcfg) >> 8;
|
|
|
|
size &= 0x3FF; /* remove unwanted bits */
|
|
|
|
size <<= 21; /* multiply by 2 MiB to find size in MB */
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get_sdr_cs_offset -
|
|
|
|
* - Get offset of cs from cs0 start
|
|
|
|
*/
|
|
|
|
u32 get_sdr_cs_offset(u32 cs)
|
|
|
|
{
|
|
|
|
u32 offset;
|
|
|
|
|
|
|
|
if (!cs)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
offset = readl(&sdrc_base->cs_cfg);
|
2012-01-18 08:28:50 +00:00
|
|
|
offset = (offset & 15) << 27 | (offset & 0x300) << 17;
|
2010-06-07 19:20:34 +00:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2011-11-18 12:48:00 +00:00
|
|
|
/*
|
|
|
|
* write_sdrc_timings -
|
|
|
|
* - Takes CS and associated timings and initalize SDRAM
|
|
|
|
* - Test CS to make sure it's OK for use
|
|
|
|
*/
|
|
|
|
static void write_sdrc_timings(u32 cs, struct sdrc_actim *sdrc_actim_base,
|
2012-11-13 07:40:28 +00:00
|
|
|
struct board_sdrc_timings *timings)
|
2011-11-18 12:48:00 +00:00
|
|
|
{
|
|
|
|
/* Setup timings we got from the board. */
|
2012-11-13 07:40:28 +00:00
|
|
|
writel(timings->mcfg, &sdrc_base->cs[cs].mcfg);
|
|
|
|
writel(timings->ctrla, &sdrc_actim_base->ctrla);
|
|
|
|
writel(timings->ctrlb, &sdrc_actim_base->ctrlb);
|
|
|
|
writel(timings->rfr_ctrl, &sdrc_base->cs[cs].rfr_ctrl);
|
2011-11-18 12:48:00 +00:00
|
|
|
writel(CMD_NOP, &sdrc_base->cs[cs].manual);
|
|
|
|
writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
|
|
|
|
writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
|
|
|
|
writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
|
2012-11-13 07:40:28 +00:00
|
|
|
writel(timings->mr, &sdrc_base->cs[cs].mr);
|
2011-11-18 12:48:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test ram in this bank
|
|
|
|
* Disable if bad or not present
|
|
|
|
*/
|
|
|
|
if (!mem_ok(cs))
|
|
|
|
writel(0, &sdrc_base->cs[cs].mcfg);
|
|
|
|
}
|
|
|
|
|
2010-06-07 19:20:34 +00:00
|
|
|
/*
|
|
|
|
* do_sdrc_init -
|
2011-11-18 12:48:00 +00:00
|
|
|
* - Code called once in C-Stack only context for CS0 and with early being
|
|
|
|
* true and a possible 2nd time depending on memory configuration from
|
|
|
|
* stack+global context.
|
2010-06-07 19:20:34 +00:00
|
|
|
*/
|
|
|
|
void do_sdrc_init(u32 cs, u32 early)
|
|
|
|
{
|
2010-08-20 03:09:57 +00:00
|
|
|
struct sdrc_actim *sdrc_actim_base0, *sdrc_actim_base1;
|
2012-11-13 07:40:28 +00:00
|
|
|
struct board_sdrc_timings timings;
|
2011-11-18 12:48:00 +00:00
|
|
|
|
|
|
|
sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
|
|
|
|
sdrc_actim_base1 = (struct sdrc_actim *)SDRC_ACTIM_CTRL1_BASE;
|
2010-06-07 19:20:34 +00:00
|
|
|
|
2015-01-16 08:09:48 +00:00
|
|
|
/* set some default timings */
|
|
|
|
timings.sharing = SDRC_SHARING;
|
|
|
|
|
2011-11-18 12:48:06 +00:00
|
|
|
/*
|
|
|
|
* When called in the early context this may be SPL and we will
|
|
|
|
* need to set all of the timings. This ends up being board
|
|
|
|
* specific so we call a helper function to take care of this
|
|
|
|
* for us. Otherwise, to be safe, we need to copy the settings
|
|
|
|
* from the first bank to the second. We will setup CS0,
|
|
|
|
* then set cs_cfg to the appropriate value then try and
|
|
|
|
* setup CS1.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_SPL_BUILD
|
2015-01-16 08:09:48 +00:00
|
|
|
/* set/modify board-specific timings */
|
2012-11-13 07:40:28 +00:00
|
|
|
get_board_mem_timings(&timings);
|
2011-11-18 12:48:06 +00:00
|
|
|
#endif
|
2010-06-07 19:20:34 +00:00
|
|
|
if (early) {
|
|
|
|
/* reset sdrc controller */
|
|
|
|
writel(SOFTRESET, &sdrc_base->sysconfig);
|
|
|
|
wait_on_value(RESETDONE, RESETDONE, &sdrc_base->status,
|
|
|
|
12000000);
|
|
|
|
writel(0, &sdrc_base->sysconfig);
|
|
|
|
|
|
|
|
/* setup sdrc to ball mux */
|
2015-01-16 08:09:48 +00:00
|
|
|
writel(timings.sharing, &sdrc_base->sharing);
|
2010-06-07 19:20:34 +00:00
|
|
|
|
2011-11-18 12:48:00 +00:00
|
|
|
/* Disable Power Down of CKE because of 1 CKE on combo part */
|
2010-06-07 19:20:34 +00:00
|
|
|
writel(WAKEUPPROC | SRFRONRESET | PAGEPOLICY_HIGH,
|
|
|
|
&sdrc_base->power);
|
|
|
|
|
|
|
|
writel(ENADLL | DLLPHASE_90, &sdrc_base->dlla_ctrl);
|
|
|
|
sdelay(0x20000);
|
2011-09-14 19:15:37 +00:00
|
|
|
#ifdef CONFIG_SPL_BUILD
|
2012-11-13 07:40:28 +00:00
|
|
|
write_sdrc_timings(CS0, sdrc_actim_base0, &timings);
|
2011-11-18 12:48:06 +00:00
|
|
|
make_cs1_contiguous();
|
2012-11-13 07:40:28 +00:00
|
|
|
write_sdrc_timings(CS1, sdrc_actim_base1, &timings);
|
2011-11-18 12:48:00 +00:00
|
|
|
#endif
|
2011-09-14 19:15:37 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-07 19:20:34 +00:00
|
|
|
/*
|
2011-11-18 12:48:00 +00:00
|
|
|
* If we aren't using SPL we have been loaded by some
|
|
|
|
* other means which may not have correctly initialized
|
|
|
|
* both CS0 and CS1 (such as some older versions of x-loader)
|
|
|
|
* so we may be asked now to setup CS1.
|
2010-06-07 19:20:34 +00:00
|
|
|
*/
|
2011-09-14 19:15:37 +00:00
|
|
|
if (cs == CS1) {
|
2012-11-13 07:40:28 +00:00
|
|
|
timings.mcfg = readl(&sdrc_base->cs[CS0].mcfg),
|
|
|
|
timings.rfr_ctrl = readl(&sdrc_base->cs[CS0].rfr_ctrl);
|
|
|
|
timings.ctrla = readl(&sdrc_actim_base0->ctrla);
|
|
|
|
timings.ctrlb = readl(&sdrc_actim_base0->ctrlb);
|
|
|
|
timings.mr = readl(&sdrc_base->cs[CS0].mr);
|
|
|
|
write_sdrc_timings(cs, sdrc_actim_base1, &timings);
|
2011-11-18 12:48:00 +00:00
|
|
|
}
|
2010-06-07 19:20:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* dram_init -
|
|
|
|
* - Sets uboots idea of sdram size
|
|
|
|
*/
|
2010-09-17 11:10:41 +00:00
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
unsigned int size0 = 0, size1 = 0;
|
|
|
|
|
|
|
|
size0 = get_sdr_cs_size(CS0);
|
|
|
|
/*
|
2011-11-18 12:47:59 +00:00
|
|
|
* We always need to have cs_cfg point at where the second
|
|
|
|
* bank would be, if present. Failure to do so can lead to
|
|
|
|
* strange situations where memory isn't detected and
|
|
|
|
* configured correctly. CS0 will already have been setup
|
|
|
|
* at this point.
|
2010-09-17 11:10:41 +00:00
|
|
|
*/
|
2011-11-18 12:47:59 +00:00
|
|
|
make_cs1_contiguous();
|
|
|
|
do_sdrc_init(CS1, NOT_EARLY);
|
|
|
|
size1 = get_sdr_cs_size(CS1);
|
2010-09-17 11:10:41 +00:00
|
|
|
|
|
|
|
gd->ram_size = size0 + size1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-03-31 14:40:32 +00:00
|
|
|
int dram_init_banksize(void)
|
2010-09-17 11:10:41 +00:00
|
|
|
{
|
|
|
|
unsigned int size0 = 0, size1 = 0;
|
|
|
|
|
|
|
|
size0 = get_sdr_cs_size(CS0);
|
|
|
|
size1 = get_sdr_cs_size(CS1);
|
|
|
|
|
|
|
|
gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
|
|
|
|
gd->bd->bi_dram[0].size = size0;
|
|
|
|
gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
|
|
|
|
gd->bd->bi_dram[1].size = size1;
|
2017-03-31 14:40:32 +00:00
|
|
|
|
|
|
|
return 0;
|
2010-09-17 11:10:41 +00:00
|
|
|
}
|
2010-06-07 19:20:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* mem_init -
|
|
|
|
* - Init the sdrc chip,
|
|
|
|
* - Selects CS0 and CS1,
|
|
|
|
*/
|
|
|
|
void mem_init(void)
|
|
|
|
{
|
|
|
|
/* only init up first bank here */
|
|
|
|
do_sdrc_init(CS0, EARLY_INIT);
|
|
|
|
}
|