blob: aa84e961736a67cc64b8343fe6066588fca0604e [file] [log] [blame]
Chandan Nath62d7fe7c2011-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 Rinib971dfa2012-07-03 09:20:06 -070024#include <asm/arch/sys_proto.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000025#include <asm/io.h>
Tom Rinifda35eb2012-07-03 08:51:34 -070026#include <asm/emif.h>
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000027
28DECLARE_GLOBAL_DATA_PTR;
29
Chandan Nath62d7fe7c2011-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 Nath8a8f0842012-01-09 20:38:59 +000046#ifdef CONFIG_SPL_BUILD
Matt Porter4fab8d72013-03-15 10:07:07 +000047static struct dmm_lisa_map_regs *hw_lisa_map_regs =
48 (struct dmm_lisa_map_regs *)DMM_BASE;
Matt Porter3ba65f92013-03-15 10:07:03 +000049static struct vtp_reg *vtpreg[2] = {
50 (struct vtp_reg *)VTP0_CTRL_ADDR,
51 (struct vtp_reg *)VTP1_CTRL_ADDR};
52#ifdef CONFIG_AM33XX
Tom Rini942d3f02012-07-30 14:13:16 -070053static struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
Matt Porter3ba65f92013-03-15 10:07:03 +000054#endif
Tom Rini942d3f02012-07-30 14:13:16 -070055
Matt Porter4fab8d72013-03-15 10:07:07 +000056void config_dmm(const struct dmm_lisa_map_regs *regs)
57{
58 enable_dmm_clocks();
59
60 writel(0, &hw_lisa_map_regs->dmm_lisa_map_3);
61 writel(0, &hw_lisa_map_regs->dmm_lisa_map_2);
62 writel(0, &hw_lisa_map_regs->dmm_lisa_map_1);
63 writel(0, &hw_lisa_map_regs->dmm_lisa_map_0);
64
65 writel(regs->dmm_lisa_map_3, &hw_lisa_map_regs->dmm_lisa_map_3);
66 writel(regs->dmm_lisa_map_2, &hw_lisa_map_regs->dmm_lisa_map_2);
67 writel(regs->dmm_lisa_map_1, &hw_lisa_map_regs->dmm_lisa_map_1);
68 writel(regs->dmm_lisa_map_0, &hw_lisa_map_regs->dmm_lisa_map_0);
69}
70
Matt Porter3ba65f92013-03-15 10:07:03 +000071static void config_vtp(int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000072{
Matt Porter3ba65f92013-03-15 10:07:03 +000073 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_ENABLE,
74 &vtpreg[nr]->vtp0ctrlreg);
75 writel(readl(&vtpreg[nr]->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
76 &vtpreg[nr]->vtp0ctrlreg);
77 writel(readl(&vtpreg[nr]->vtp0ctrlreg) | VTP_CTRL_START_EN,
78 &vtpreg[nr]->vtp0ctrlreg);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000079
80 /* Poll for READY */
Matt Porter3ba65f92013-03-15 10:07:03 +000081 while ((readl(&vtpreg[nr]->vtp0ctrlreg) & VTP_CTRL_READY) !=
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000082 VTP_CTRL_READY)
83 ;
84}
85
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000086void config_ddr(unsigned int pll, unsigned int ioctrl,
87 const struct ddr_data *data, const struct cmd_control *ctrl,
Matt Porter3ba65f92013-03-15 10:07:03 +000088 const struct emif_regs *regs, int nr)
Chandan Nath62d7fe7c2011-10-14 02:58:24 +000089{
Tom Rini318f27c2012-07-30 14:13:56 -070090 enable_emif_clocks();
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000091 ddr_pll_config(pll);
Matt Porter3ba65f92013-03-15 10:07:03 +000092 config_vtp(nr);
93 config_cmd_ctrl(ctrl, nr);
Tom Rini318f27c2012-07-30 14:13:56 -070094
Matt Porter3ba65f92013-03-15 10:07:03 +000095 config_ddr_data(data, nr);
96#ifdef CONFIG_AM33XX
Peter Korsgaardc00f69d2012-10-18 01:21:12 +000097 config_io_ctrl(ioctrl);
Tom Rini318f27c2012-07-30 14:13:56 -070098
99 /* Set CKE to be controlled by EMIF/DDR PHY */
100 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
Matt Porter3ba65f92013-03-15 10:07:03 +0000101#endif
Tom Rini318f27c2012-07-30 14:13:56 -0700102
103 /* Program EMIF instance */
Matt Porter3ba65f92013-03-15 10:07:03 +0000104 config_ddr_phy(regs, nr);
105 set_sdram_timings(regs, nr);
106 config_sdram(regs, nr);
Chandan Nath62d7fe7c2011-10-14 02:58:24 +0000107}
108#endif