2011-10-14 02:58:24 +00:00
|
|
|
/*
|
|
|
|
* emif4.c
|
|
|
|
*
|
|
|
|
* AM33XX emif4 configuration file
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-10-14 02:58:24 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
|
|
|
#include <asm/arch/ddr_defs.h>
|
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/arch/clock.h>
|
2012-07-03 16:20:06 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2011-10-14 02:58:24 +00:00
|
|
|
#include <asm/io.h>
|
2012-07-03 15:51:34 +00:00
|
|
|
#include <asm/emif.h>
|
2011-10-14 02:58:24 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
arm:am33xx: Make dram_init call sdram_init() in some contexts
We have two contexts for booting these platforms. One is SPL which is
roughly: reset, cpu_init_crit, lowlevel_init, s_init, sdram_init, _main,
board_init_f from SPL, ... then U-Boot loads. The other is a
memory-mapped XIP case (NOR or QSPI) where we do not run an SPL. In
this case we go, roughly: reset, cpu_init_crit, lowlevel_init, s_init,
_main, regular board_init_f.
In the first case s_init will set a valid gd and then be able to call
sdram_init which in many cases will need i2c (which needs a valid gd for
gd->cur_i2c_bus). In this second case we must (and are able to and
should) defer sdram_init() into dram_init() called by board_init_f as gd
will have been set in _main and cleared in board_init_f.
Signed-off-by: Tom Rini <trini@ti.com>
2014-05-21 16:57:21 +00:00
|
|
|
#ifndef CONFIG_SKIP_LOWLEVEL_INIT
|
|
|
|
sdram_init();
|
|
|
|
#endif
|
|
|
|
|
2011-10-14 02:58:24 +00:00
|
|
|
/* dram_init must store complete ramsize in gd->ram_size */
|
|
|
|
gd->ram_size = get_ram_size(
|
|
|
|
(void *)CONFIG_SYS_SDRAM_BASE,
|
|
|
|
CONFIG_MAX_RAM_BANK_SIZE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dram_init_banksize(void)
|
|
|
|
{
|
|
|
|
gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
|
|
|
|
gd->bd->bi_dram[0].size = gd->ram_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 12:25:57 +00:00
|
|
|
#ifndef CONFIG_SKIP_LOWLEVEL_INIT
|
2013-07-18 19:13:04 +00:00
|
|
|
#ifdef CONFIG_TI81XX
|
2013-03-15 10:07:07 +00:00
|
|
|
static struct dmm_lisa_map_regs *hw_lisa_map_regs =
|
|
|
|
(struct dmm_lisa_map_regs *)DMM_BASE;
|
2013-07-18 19:13:04 +00:00
|
|
|
#endif
|
2013-07-02 10:05:59 +00:00
|
|
|
#ifndef CONFIG_TI816X
|
2013-03-15 10:07:03 +00:00
|
|
|
static struct vtp_reg *vtpreg[2] = {
|
|
|
|
(struct vtp_reg *)VTP0_CTRL_ADDR,
|
|
|
|
(struct vtp_reg *)VTP1_CTRL_ADDR};
|
2013-07-02 10:05:59 +00:00
|
|
|
#endif
|
2013-03-15 10:07:03 +00:00
|
|
|
#ifdef CONFIG_AM33XX
|
2012-07-30 21:13:16 +00:00
|
|
|
static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
|
2013-03-15 10:07:03 +00:00
|
|
|
#endif
|
2013-12-10 09:32:22 +00:00
|
|
|
#ifdef CONFIG_AM43XX
|
|
|
|
static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
|
|
|
|
static struct cm_device_inst *cm_device =
|
|
|
|
(struct cm_device_inst *)CM_DEVICE_INST;
|
|
|
|
#endif
|
2012-07-30 21:13:16 +00:00
|
|
|
|
2013-07-18 19:13:04 +00:00
|
|
|
#ifdef CONFIG_TI81XX
|
2013-03-15 10:07:07 +00:00
|
|
|
void config_dmm(const struct dmm_lisa_map_regs *regs)
|
|
|
|
{
|
|
|
|
enable_dmm_clocks();
|
|
|
|
|
|
|
|
writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
|
|
|
|
writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
|
|
|
|
writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
|
|
|
|
writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
|
|
|
|
|
|
|
|
writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
|
|
|
|
writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
|
|
|
|
writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
|
|
|
|
writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
|
|
|
|
}
|
2013-07-18 19:13:04 +00:00
|
|
|
#endif
|
2013-03-15 10:07:07 +00:00
|
|
|
|
2013-07-02 10:05:59 +00:00
|
|
|
#ifndef CONFIG_TI816X
|
2013-03-15 10:07:03 +00:00
|
|
|
static void config_vtp(int nr)
|
2011-10-14 02:58:24 +00:00
|
|
|
{
|
2013-03-15 10:07:03 +00:00
|
|
|
writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
|
|
|
|
&vtpreg[nr]->vtp0ctrlreg);
|
|
|
|
writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
|
|
|
|
&vtpreg[nr]->vtp0ctrlreg);
|
|
|
|
writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
|
|
|
|
&vtpreg[nr]->vtp0ctrlreg);
|
2011-10-14 02:58:24 +00:00
|
|
|
|
|
|
|
/* Poll for READY */
|
2013-03-15 10:07:03 +00:00
|
|
|
while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
|
2011-10-14 02:58:24 +00:00
|
|
|
VTP_CTRL_READY)
|
|
|
|
;
|
|
|
|
}
|
2013-07-02 10:05:59 +00:00
|
|
|
#endif
|
2011-10-14 02:58:24 +00:00
|
|
|
|
2013-07-30 05:18:52 +00:00
|
|
|
void __weak ddr_pll_config(unsigned int ddrpll_m)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-12-10 09:32:21 +00:00
|
|
|
void config_ddr(unsigned int pll, const struct ctrl_ioregs *ioregs,
|
2012-10-18 01:21:12 +00:00
|
|
|
const struct ddr_data *data, const struct cmd_control *ctrl,
|
2013-03-15 10:07:03 +00:00
|
|
|
const struct emif_regs *regs, int nr)
|
2011-10-14 02:58:24 +00:00
|
|
|
{
|
2012-10-18 01:21:12 +00:00
|
|
|
ddr_pll_config(pll);
|
2013-07-02 10:05:59 +00:00
|
|
|
#ifndef CONFIG_TI816X
|
2013-03-15 10:07:03 +00:00
|
|
|
config_vtp(nr);
|
2013-07-02 10:05:59 +00:00
|
|
|
#endif
|
2013-03-15 10:07:03 +00:00
|
|
|
config_cmd_ctrl(ctrl, nr);
|
2011-10-14 02:58:24 +00:00
|
|
|
|
2013-03-15 10:07:03 +00:00
|
|
|
config_ddr_data(data, nr);
|
|
|
|
#ifdef CONFIG_AM33XX
|
2013-12-10 09:32:21 +00:00
|
|
|
config_io_ctrl(ioregs);
|
2011-10-14 02:58:24 +00:00
|
|
|
|
2012-07-30 21:13:56 +00:00
|
|
|
/* Set CKE to be controlled by EMIF/DDR PHY */
|
|
|
|
writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
|
2014-12-22 22:26:11 +00:00
|
|
|
|
2013-03-15 10:07:03 +00:00
|
|
|
#endif
|
2013-12-10 09:32:22 +00:00
|
|
|
#ifdef CONFIG_AM43XX
|
|
|
|
writel(readl(&cm_device->cm_dll_ctrl) & ~0x1, &cm_device->cm_dll_ctrl);
|
2014-06-18 19:22:35 +00:00
|
|
|
while ((readl(&cm_device->cm_dll_ctrl) & CM_DLL_READYST) == 0)
|
2013-12-10 09:32:22 +00:00
|
|
|
;
|
|
|
|
|
|
|
|
config_io_ctrl(ioregs);
|
|
|
|
|
|
|
|
/* Set CKE to be controlled by EMIF/DDR PHY */
|
|
|
|
writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
|
2014-12-22 22:26:11 +00:00
|
|
|
|
2015-06-05 10:21:11 +00:00
|
|
|
if (emif_sdram_type(regs->sdram_config) == EMIF_SDRAM_TYPE_DDR3)
|
|
|
|
/* Allow EMIF to control DDR_RESET */
|
|
|
|
writel(0x00000000, &ddrctrl->ddrioctrl);
|
2013-12-10 09:32:22 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 21:13:56 +00:00
|
|
|
/* Program EMIF instance */
|
2013-03-15 10:07:03 +00:00
|
|
|
config_ddr_phy(regs, nr);
|
|
|
|
set_sdram_timings(regs, nr);
|
2013-12-10 09:32:22 +00:00
|
|
|
if (get_emif_rev(EMIF1_BASE) == EMIF_4D5)
|
|
|
|
config_sdram_emif4d5(regs, nr);
|
|
|
|
else
|
|
|
|
config_sdram(regs, nr);
|
2011-10-14 02:58:24 +00:00
|
|
|
}
|
|
|
|
#endif
|