blob: 0dd1955431dc89787a9c70289e328fae483881ce [file] [log] [blame]
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -04001/*
2 * Functions related to OMAP3 SDRC.
3 *
4 * This file has been created after exctracting and consolidating
5 * the SDRC related content from mem.c and board.c, also created
6 * generic init function (mem_init).
7 *
8 * Copyright (C) 2004-2010
9 * Texas Instruments Incorporated - http://www.ti.com/
10 *
Simon Schwarzee50ca92011-09-14 15:15:37 -040011 * Copyright (C) 2011
12 * Corscience GmbH & Co. KG - Simon Schwarz <schwarz@corscience.de>
13 *
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -040014 * Author :
15 * Vaibhav Hiremath <hvaibhav@ti.com>
16 *
17 * Original implementation by (mem.c, board.c) :
18 * Sunil Kumar <sunilsaini05@gmail.com>
19 * Shashi Ranjan <shashiranjanmca05@gmail.com>
20 * Manikandan Pillai <mani.pillai@ti.com>
21 *
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License as
24 * published by the Free Software Foundation; either version 2 of
25 * the License, or (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
35 * MA 02111-1307 USA
36 */
37
38#include <common.h>
39#include <asm/io.h>
40#include <asm/arch/mem.h>
41#include <asm/arch/sys_proto.h>
42
Nishanth Menonedded0e42010-12-11 11:41:42 -050043DECLARE_GLOBAL_DATA_PTR;
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -040044extern omap3_sysinfo sysinfo;
45
46static struct sdrc *sdrc_base = (struct sdrc *)OMAP34XX_SDRC_BASE;
47
48/*
49 * is_mem_sdr -
50 * - Return 1 if mem type in use is SDR
51 */
52u32 is_mem_sdr(void)
53{
54 if (readl(&sdrc_base->cs[CS0].mr) == SDRC_MR_0_SDR)
55 return 1;
56 return 0;
57}
58
59/*
60 * make_cs1_contiguous -
61 * - For es2 and above remap cs1 behind cs0 to allow command line
62 * mem=xyz use all memory with out discontinuous support compiled in.
63 * Could do it at the ATAG, but there really is two banks...
64 * - Called as part of 2nd phase DDR init.
65 */
66void make_cs1_contiguous(void)
67{
68 u32 size, a_add_low, a_add_high;
69
70 size = get_sdr_cs_size(CS0);
71 size >>= 25; /* divide by 32 MiB to find size to offset CS1 */
72 a_add_high = (size & 3) << 8; /* set up low field */
73 a_add_low = (size & 0x3C) >> 2; /* set up high field */
74 writel((a_add_high | a_add_low), &sdrc_base->cs_cfg);
75
76}
77
78
79/*
80 * get_sdr_cs_size -
81 * - Get size of chip select 0/1
82 */
83u32 get_sdr_cs_size(u32 cs)
84{
85 u32 size;
86
87 /* get ram size field */
88 size = readl(&sdrc_base->cs[cs].mcfg) >> 8;
89 size &= 0x3FF; /* remove unwanted bits */
90 size <<= 21; /* multiply by 2 MiB to find size in MB */
91 return size;
92}
93
94/*
95 * get_sdr_cs_offset -
96 * - Get offset of cs from cs0 start
97 */
98u32 get_sdr_cs_offset(u32 cs)
99{
100 u32 offset;
101
102 if (!cs)
103 return 0;
104
105 offset = readl(&sdrc_base->cs_cfg);
Steve Sakoman39789592010-09-30 21:46:52 -0700106 offset = (offset & 15) << 27 | (offset & 0x30) << 17;
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400107
108 return offset;
109}
110
111/*
112 * do_sdrc_init -
113 * - Initialize the SDRAM for use.
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400114 * - code called once in C-Stack only context for CS0 and a possible 2nd
115 * time depending on memory configuration from stack+global context
116 */
117void do_sdrc_init(u32 cs, u32 early)
118{
Steve Sakomana7561cc2010-08-19 20:09:57 -0700119 struct sdrc_actim *sdrc_actim_base0, *sdrc_actim_base1;
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400120
121 if (early) {
122 /* reset sdrc controller */
123 writel(SOFTRESET, &sdrc_base->sysconfig);
124 wait_on_value(RESETDONE, RESETDONE, &sdrc_base->status,
125 12000000);
126 writel(0, &sdrc_base->sysconfig);
127
128 /* setup sdrc to ball mux */
129 writel(SDRC_SHARING, &sdrc_base->sharing);
130
131 /* Disable Power Down of CKE cuz of 1 CKE on combo part */
132 writel(WAKEUPPROC | SRFRONRESET | PAGEPOLICY_HIGH,
133 &sdrc_base->power);
134
135 writel(ENADLL | DLLPHASE_90, &sdrc_base->dlla_ctrl);
136 sdelay(0x20000);
137 }
Simon Schwarzee50ca92011-09-14 15:15:37 -0400138
139/* As long as V_MCFG and V_RFR_CTRL is not defined for all OMAP3 boards we need
140 * to prevent this to be build in non-SPL build */
141#ifdef CONFIG_SPL_BUILD
142 /* If we use a SPL there is no x-loader nor config header so we have
143 * to do the job ourselfs
144 */
145 if (cs == CS0) {
146 sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
147
148 /* General SDRC config */
149 writel(V_MCFG, &sdrc_base->cs[cs].mcfg);
150 writel(V_RFR_CTRL, &sdrc_base->cs[cs].rfr_ctrl);
151
152 /* AC timings */
153 writel(V_ACTIMA_165, &sdrc_actim_base0->ctrla);
154 writel(V_ACTIMB_165, &sdrc_actim_base0->ctrlb);
155
156 /* Initialize */
157 writel(CMD_NOP, &sdrc_base->cs[cs].manual);
158 writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
159 writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
160 writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
161
162 writel(V_MR, &sdrc_base->cs[cs].mr);
163 }
164#endif
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400165
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400166 /*
Steve Sakomana7561cc2010-08-19 20:09:57 -0700167 * SDRC timings are set up by x-load or config header
168 * We don't need to redo them here.
169 * Older x-loads configure only CS0
170 * configure CS1 to handle this ommission
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400171 */
Simon Schwarzee50ca92011-09-14 15:15:37 -0400172 if (cs == CS1) {
Steve Sakomana7561cc2010-08-19 20:09:57 -0700173 sdrc_actim_base0 = (struct sdrc_actim *)SDRC_ACTIM_CTRL0_BASE;
174 sdrc_actim_base1 = (struct sdrc_actim *)SDRC_ACTIM_CTRL1_BASE;
175 writel(readl(&sdrc_base->cs[CS0].mcfg),
176 &sdrc_base->cs[CS1].mcfg);
177 writel(readl(&sdrc_base->cs[CS0].rfr_ctrl),
178 &sdrc_base->cs[CS1].rfr_ctrl);
179 writel(readl(&sdrc_actim_base0->ctrla),
180 &sdrc_actim_base1->ctrla);
181 writel(readl(&sdrc_actim_base0->ctrlb),
182 &sdrc_actim_base1->ctrlb);
Heiko Schochera1e1aec2010-11-04 16:05:25 -0400183
184 writel(CMD_NOP, &sdrc_base->cs[cs].manual);
185 writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
186 writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
187 writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
188 writel(readl(&sdrc_base->cs[CS0].mr),
189 &sdrc_base->cs[CS1].mr);
Steve Sakomana7561cc2010-08-19 20:09:57 -0700190 }
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400191
Steve Sakomana7561cc2010-08-19 20:09:57 -0700192 /*
193 * Test ram in this bank
194 * Disable if bad or not present
195 */
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400196 if (!mem_ok(cs))
197 writel(0, &sdrc_base->cs[cs].mcfg);
198}
199
200/*
201 * dram_init -
202 * - Sets uboots idea of sdram size
203 */
204int dram_init(void)
205{
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400206 unsigned int size0 = 0, size1 = 0;
207
208 size0 = get_sdr_cs_size(CS0);
209 /*
210 * If a second bank of DDR is attached to CS1 this is
211 * where it can be started. Early init code will init
212 * memory on CS0.
213 */
214 if ((sysinfo.mtype == DDR_COMBO) || (sysinfo.mtype == DDR_STACKED)) {
215 do_sdrc_init(CS1, NOT_EARLY);
216 make_cs1_contiguous();
217
218 size1 = get_sdr_cs_size(CS1);
219 }
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200220 gd->ram_size = size0 + size1;
221
222 return 0;
223}
224
225void dram_init_banksize (void)
226{
Heiko Schocher56d0a4d2010-09-17 13:10:41 +0200227 unsigned int size0 = 0, size1 = 0;
228
229 size0 = get_sdr_cs_size(CS0);
230 size1 = get_sdr_cs_size(CS1);
231
232 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
233 gd->bd->bi_dram[0].size = size0;
234 gd->bd->bi_dram[1].start = PHYS_SDRAM_1 + get_sdr_cs_offset(CS1);
235 gd->bd->bi_dram[1].size = size1;
236}
Vaibhav Hiremath558d23d2010-06-07 15:20:34 -0400237
238/*
239 * mem_init -
240 * - Init the sdrc chip,
241 * - Selects CS0 and CS1,
242 */
243void mem_init(void)
244{
245 /* only init up first bank here */
246 do_sdrc_init(CS0, EARLY_INIT);
247}