blob: 01e3a5204ea96f7a91d2ab9da6d64ee31a311d94 [file] [log] [blame]
Chandan Nath98b036e2011-10-14 02:58:24 +00001/*
2 * emif4.c
3 *
4 * AM33XX emif4 configuration file
5 *
6 * Copyright (C) 2011, Texas Instruments, Incorporated - http://www.ti.com/
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR /PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <common.h>
20#include <asm/arch/cpu.h>
21#include <asm/arch/ddr_defs.h>
22#include <asm/arch/hardware.h>
23#include <asm/arch/clock.h>
Tom Rini034aba72012-07-03 09:20:06 -070024#include <asm/arch/sys_proto.h>
Chandan Nath98b036e2011-10-14 02:58:24 +000025#include <asm/io.h>
Tom Rini3fd44562012-07-03 08:51:34 -070026#include <asm/emif.h>
Chandan Nath98b036e2011-10-14 02:58:24 +000027
28DECLARE_GLOBAL_DATA_PTR;
29
Chandan Nath98b036e2011-10-14 02:58:24 +000030int dram_init(void)
31{
32 /* dram_init must store complete ramsize in gd->ram_size */
33 gd->ram_size = get_ram_size(
34 (void *)CONFIG_SYS_SDRAM_BASE,
35 CONFIG_MAX_RAM_BANK_SIZE);
36 return 0;
37}
38
39void dram_init_banksize(void)
40{
41 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
42 gd->bd->bi_dram[0].size = gd->ram_size;
43}
44
45
Chandan Nath77a73fe2012-01-09 20:38:59 +000046#ifdef CONFIG_SPL_BUILD
Tom Rini4d451122012-07-30 14:13:16 -070047static struct vtp_reg *vtpreg = (struct vtp_reg *)VTP0_CTRL_ADDR;
48static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
49
Chandan Nath98b036e2011-10-14 02:58:24 +000050static void config_vtp(void)
51{
52 writel(readl(&vtpreg->vtp0ctrlreg) | VTP_CTRL_ENABLE,
53 &vtpreg->vtp0ctrlreg);
54 writel(readl(&vtpreg->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
55 &vtpreg->vtp0ctrlreg);
56 writel(readl(&vtpreg->vtp0ctrlreg) | VTP_CTRL_START_EN,
57 &vtpreg->vtp0ctrlreg);
58
59 /* Poll for READY */
60 while ((readl(&vtpreg->vtp0ctrlreg) & VTP_CTRL_READY) !=
61 VTP_CTRL_READY)
62 ;
63}
64
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000065void config_ddr(unsigned int pll, unsigned int ioctrl,
66 const struct ddr_data *data, const struct cmd_control *ctrl,
67 const struct emif_regs *regs)
Chandan Nath98b036e2011-10-14 02:58:24 +000068{
Tom Rini4b020fe2012-07-30 14:13:56 -070069 enable_emif_clocks();
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000070 ddr_pll_config(pll);
Tom Rini4b020fe2012-07-30 14:13:56 -070071 config_vtp();
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000072 config_cmd_ctrl(ctrl);
Chandan Nath98b036e2011-10-14 02:58:24 +000073
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000074 config_ddr_data(0, data);
75 config_ddr_data(1, data);
Chandan Nath98b036e2011-10-14 02:58:24 +000076
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000077 config_io_ctrl(ioctrl);
Chandan Nath98b036e2011-10-14 02:58:24 +000078
Tom Rini4b020fe2012-07-30 14:13:56 -070079 /* Set CKE to be controlled by EMIF/DDR PHY */
80 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
Chandan Nath98b036e2011-10-14 02:58:24 +000081
Tom Rini4b020fe2012-07-30 14:13:56 -070082 /* Program EMIF instance */
Peter Korsgaardeb6cf7b2012-10-18 01:21:12 +000083 config_ddr_phy(regs);
84 set_sdram_timings(regs);
85 config_sdram(regs);
Chandan Nath98b036e2011-10-14 02:58:24 +000086}
87#endif