blob: 3bb91d3c90b274eaaf21dcedbf238ebd85bcd950 [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
30struct ddr_regs *ddrregs = (struct ddr_regs *)DDR_PHY_BASE_ADDR;
31struct vtp_reg *vtpreg = (struct vtp_reg *)VTP0_CTRL_ADDR;
32struct ddr_ctrl *ddrctrl = (struct ddr_ctrl *)DDR_CTRL_ADDR;
33
Chandan Nath98b036e2011-10-14 02:58:24 +000034int dram_init(void)
35{
36 /* dram_init must store complete ramsize in gd->ram_size */
37 gd->ram_size = get_ram_size(
38 (void *)CONFIG_SYS_SDRAM_BASE,
39 CONFIG_MAX_RAM_BANK_SIZE);
40 return 0;
41}
42
43void dram_init_banksize(void)
44{
45 gd->bd->bi_dram[0].start = CONFIG_SYS_SDRAM_BASE;
46 gd->bd->bi_dram[0].size = gd->ram_size;
47}
48
49
Chandan Nath77a73fe2012-01-09 20:38:59 +000050#ifdef CONFIG_SPL_BUILD
Tom Rini1652dd52012-07-03 08:48:46 -070051static const struct ddr_data ddr2_data = {
52 .datardsratio0 = ((DDR2_RD_DQS<<30)|(DDR2_RD_DQS<<20)
53 |(DDR2_RD_DQS<<10)|(DDR2_RD_DQS<<0)),
Tom Rini1652dd52012-07-03 08:48:46 -070054 .datawdsratio0 = ((DDR2_WR_DQS<<30)|(DDR2_WR_DQS<<20)
55 |(DDR2_WR_DQS<<10)|(DDR2_WR_DQS<<0)),
Tom Rini1652dd52012-07-03 08:48:46 -070056 .datawiratio0 = ((DDR2_PHY_WRLVL<<30)|(DDR2_PHY_WRLVL<<20)
57 |(DDR2_PHY_WRLVL<<10)|(DDR2_PHY_WRLVL<<0)),
Tom Rini1652dd52012-07-03 08:48:46 -070058 .datagiratio0 = ((DDR2_PHY_GATELVL<<30)|(DDR2_PHY_GATELVL<<20)
59 |(DDR2_PHY_GATELVL<<10)|(DDR2_PHY_GATELVL<<0)),
Tom Rini1652dd52012-07-03 08:48:46 -070060 .datafwsratio0 = ((DDR2_PHY_FIFO_WE<<30)|(DDR2_PHY_FIFO_WE<<20)
61 |(DDR2_PHY_FIFO_WE<<10)|(DDR2_PHY_FIFO_WE<<0)),
Tom Rini1652dd52012-07-03 08:48:46 -070062 .datawrsratio0 = ((DDR2_PHY_WR_DATA<<30)|(DDR2_PHY_WR_DATA<<20)
63 |(DDR2_PHY_WR_DATA<<10)|(DDR2_PHY_WR_DATA<<0)),
Tom Rini3e444582012-07-30 11:49:47 -070064 .datauserank0delay = DDR2_PHY_RANK0_DELAY,
Tom Rini1652dd52012-07-03 08:48:46 -070065 .datadldiff0 = PHY_DLL_LOCK_DIFF,
66};
Chandan Nath98b036e2011-10-14 02:58:24 +000067
Tom Rini1652dd52012-07-03 08:48:46 -070068static const struct cmd_control ddr2_cmd_ctrl_data = {
69 .cmd0csratio = DDR2_RATIO,
Tom Rini1652dd52012-07-03 08:48:46 -070070 .cmd0dldiff = DDR2_DLL_LOCK_DIFF,
71 .cmd0iclkout = DDR2_INVERT_CLKOUT,
Chandan Nath98b036e2011-10-14 02:58:24 +000072
Tom Rini1652dd52012-07-03 08:48:46 -070073 .cmd1csratio = DDR2_RATIO,
Tom Rini1652dd52012-07-03 08:48:46 -070074 .cmd1dldiff = DDR2_DLL_LOCK_DIFF,
75 .cmd1iclkout = DDR2_INVERT_CLKOUT,
Chandan Nath98b036e2011-10-14 02:58:24 +000076
Tom Rini1652dd52012-07-03 08:48:46 -070077 .cmd2csratio = DDR2_RATIO,
Tom Rini1652dd52012-07-03 08:48:46 -070078 .cmd2dldiff = DDR2_DLL_LOCK_DIFF,
79 .cmd2iclkout = DDR2_INVERT_CLKOUT,
80};
Chandan Nath98b036e2011-10-14 02:58:24 +000081
Tom Rinib668ae42012-07-24 14:55:38 -070082static const struct emif_regs ddr2_emif_reg_data = {
83 .sdram_config = DDR2_EMIF_SDCFG,
84 .ref_ctrl = DDR2_EMIF_SDREF,
85 .sdram_tim1 = DDR2_EMIF_TIM1,
86 .sdram_tim2 = DDR2_EMIF_TIM2,
87 .sdram_tim3 = DDR2_EMIF_TIM3,
88 .emif_ddr_phy_ctlr_1 = DDR2_EMIF_READ_LATENCY,
89};
90
Chandan Nath98b036e2011-10-14 02:58:24 +000091static void config_vtp(void)
92{
93 writel(readl(&vtpreg->vtp0ctrlreg) | VTP_CTRL_ENABLE,
94 &vtpreg->vtp0ctrlreg);
95 writel(readl(&vtpreg->vtp0ctrlreg) & (~VTP_CTRL_START_EN),
96 &vtpreg->vtp0ctrlreg);
97 writel(readl(&vtpreg->vtp0ctrlreg) | VTP_CTRL_START_EN,
98 &vtpreg->vtp0ctrlreg);
99
100 /* Poll for READY */
101 while ((readl(&vtpreg->vtp0ctrlreg) & VTP_CTRL_READY) !=
102 VTP_CTRL_READY)
103 ;
104}
105
Tom Rini3fd44562012-07-03 08:51:34 -0700106void config_ddr(short ddr_type)
Chandan Nath98b036e2011-10-14 02:58:24 +0000107{
Chandan Nath98b036e2011-10-14 02:58:24 +0000108 enable_emif_clocks();
109
Tom Rini3fd44562012-07-03 08:51:34 -0700110 if (ddr_type == EMIF_REG_SDRAM_TYPE_DDR2) {
Tom Rini034aba72012-07-03 09:20:06 -0700111 ddr_pll_config(266);
Tom Rini3fd44562012-07-03 08:51:34 -0700112 config_vtp();
Chandan Nath98b036e2011-10-14 02:58:24 +0000113
Tom Rini3fd44562012-07-03 08:51:34 -0700114 config_cmd_ctrl(&ddr2_cmd_ctrl_data);
Chandan Nath98b036e2011-10-14 02:58:24 +0000115
Tom Rini3fd44562012-07-03 08:51:34 -0700116 config_ddr_data(0, &ddr2_data);
117 config_ddr_data(1, &ddr2_data);
Chandan Nath98b036e2011-10-14 02:58:24 +0000118
Tom Rinib239b3b2012-07-24 16:31:26 -0700119 config_io_ctrl(DDR2_IOCTRL_VALUE);
Chandan Nath98b036e2011-10-14 02:58:24 +0000120
Tom Rinide3c5702012-07-24 14:03:24 -0700121 /* Set CKE to be controlled by EMIF/DDR PHY */
122 writel(DDR_CKE_CTRL_NORMAL, &ddrctrl->ddrckectrl);
Chandan Nath98b036e2011-10-14 02:58:24 +0000123
Tom Rinib668ae42012-07-24 14:55:38 -0700124 /* Program EMIF instance */
125 config_ddr_phy(&ddr2_emif_reg_data);
126 set_sdram_timings(&ddr2_emif_reg_data);
127 config_sdram(&ddr2_emif_reg_data);
Tom Rini3fd44562012-07-03 08:51:34 -0700128 }
Chandan Nath98b036e2011-10-14 02:58:24 +0000129}
130#endif