]> git.sur5r.net Git - u-boot/blob - cpu/arm_cortexa8/omap3/mem.c
Merge branch 'mimc200' into next
[u-boot] / cpu / arm_cortexa8 / omap3 / mem.c
1 /*
2  * (C) Copyright 2008
3  * Texas Instruments, <www.ti.com>
4  *
5  * Author :
6  *     Manikandan Pillai <mani.pillai@ti.com>
7  *
8  * Initial Code from:
9  *     Richard Woodruff <r-woodruff2@ti.com>
10  *     Syed Mohammed Khasim <khasim@ti.com>
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25  * MA 02111-1307 USA
26  */
27
28 #include <common.h>
29 #include <asm/io.h>
30 #include <asm/arch/mem.h>
31 #include <asm/arch/sys_proto.h>
32 #include <command.h>
33
34 /*
35  * Only One NAND allowed on board at a time.
36  * The GPMC CS Base for the same
37  */
38 unsigned int boot_flash_base;
39 unsigned int boot_flash_off;
40 unsigned int boot_flash_sec;
41 unsigned int boot_flash_type;
42 volatile unsigned int boot_flash_env_addr;
43
44 #if defined(CONFIG_CMD_NAND)
45 static u32 gpmc_m_nand[GPMC_MAX_REG] = {
46         M_NAND_GPMC_CONFIG1,
47         M_NAND_GPMC_CONFIG2,
48         M_NAND_GPMC_CONFIG3,
49         M_NAND_GPMC_CONFIG4,
50         M_NAND_GPMC_CONFIG5,
51         M_NAND_GPMC_CONFIG6, 0
52 };
53
54 gpmc_csx_t *nand_cs_base;
55 gpmc_t *gpmc_cfg_base;
56
57 #if defined(CONFIG_ENV_IS_IN_NAND)
58 #define GPMC_CS 0
59 #else
60 #define GPMC_CS 1
61 #endif
62
63 #endif
64
65 #if defined(CONFIG_CMD_ONENAND)
66 static u32 gpmc_onenand[GPMC_MAX_REG] = {
67         ONENAND_GPMC_CONFIG1,
68         ONENAND_GPMC_CONFIG2,
69         ONENAND_GPMC_CONFIG3,
70         ONENAND_GPMC_CONFIG4,
71         ONENAND_GPMC_CONFIG5,
72         ONENAND_GPMC_CONFIG6, 0
73 };
74
75 gpmc_csx_t *onenand_cs_base;
76
77 #if defined(CONFIG_ENV_IS_IN_ONENAND)
78 #define GPMC_CS 0
79 #else
80 #define GPMC_CS 1
81 #endif
82
83 #endif
84
85 static sdrc_t *sdrc_base = (sdrc_t *)OMAP34XX_SDRC_BASE;
86
87 /**************************************************************************
88  * make_cs1_contiguous() - for es2 and above remap cs1 behind cs0 to allow
89  *  command line mem=xyz use all memory with out discontinuous support
90  *  compiled in.  Could do it at the ATAG, but there really is two banks...
91  * Called as part of 2nd phase DDR init.
92  **************************************************************************/
93 void make_cs1_contiguous(void)
94 {
95         u32 size, a_add_low, a_add_high;
96
97         size = get_sdr_cs_size(CS0);
98         size /= SZ_32M;                 /* find size to offset CS1 */
99         a_add_high = (size & 3) << 8;   /* set up low field */
100         a_add_low = (size & 0x3C) >> 2; /* set up high field */
101         writel((a_add_high | a_add_low), &sdrc_base->cs_cfg);
102
103 }
104
105 /********************************************************
106  *  mem_ok() - test used to see if timings are correct
107  *             for a part. Helps in guessing which part
108  *             we are currently using.
109  *******************************************************/
110 u32 mem_ok(u32 cs)
111 {
112         u32 val1, val2, addr;
113         u32 pattern = 0x12345678;
114
115         addr = OMAP34XX_SDRC_CS0 + get_sdr_cs_offset(cs);
116
117         writel(0x0, addr + 0x400);      /* clear pos A */
118         writel(pattern, addr);          /* pattern to pos B */
119         writel(0x0, addr + 4);          /* remove pattern off the bus */
120         val1 = readl(addr + 0x400);     /* get pos A value */
121         val2 = readl(addr);             /* get val2 */
122
123         if ((val1 != 0) || (val2 != pattern))   /* see if pos A val changed */
124                 return 0;
125         else
126                 return 1;
127 }
128
129 /********************************************************
130  *  sdrc_init() - init the sdrc chip selects CS0 and CS1
131  *  - early init routines, called from flash or
132  *  SRAM.
133  *******************************************************/
134 void sdrc_init(void)
135 {
136         /* only init up first bank here */
137         do_sdrc_init(CS0, EARLY_INIT);
138 }
139
140 /*************************************************************************
141  * do_sdrc_init(): initialize the SDRAM for use.
142  *  -code sets up SDRAM basic SDRC timings for CS0
143  *  -optimal settings can be placed here, or redone after i2c
144  *      inspection of board info
145  *
146  *  - code called once in C-Stack only context for CS0 and a possible 2nd
147  *      time depending on memory configuration from stack+global context
148  **************************************************************************/
149
150 void do_sdrc_init(u32 cs, u32 early)
151 {
152         sdrc_actim_t *sdrc_actim_base;
153
154         if(cs)
155                 sdrc_actim_base = (sdrc_actim_t *)SDRC_ACTIM_CTRL1_BASE;
156         else
157                 sdrc_actim_base = (sdrc_actim_t *)SDRC_ACTIM_CTRL0_BASE;
158
159         if (early) {
160                 /* reset sdrc controller */
161                 writel(SOFTRESET, &sdrc_base->sysconfig);
162                 wait_on_value(RESETDONE, RESETDONE, &sdrc_base->status,
163                               12000000);
164                 writel(0, &sdrc_base->sysconfig);
165
166                 /* setup sdrc to ball mux */
167                 writel(SDP_SDRC_SHARING, &sdrc_base->sharing);
168
169                 /* Disable Power Down of CKE cuz of 1 CKE on combo part */
170                 writel(SRFRONRESET | PAGEPOLICY_HIGH, &sdrc_base->power);
171
172                 writel(ENADLL | DLLPHASE_90, &sdrc_base->dlla_ctrl);
173                 sdelay(0x20000);
174         }
175
176         writel(RASWIDTH_13BITS | CASWIDTH_10BITS | ADDRMUXLEGACY |
177                 RAMSIZE_128 | BANKALLOCATION | B32NOT16 | B32NOT16 |
178                 DEEPPD | DDR_SDRAM, &sdrc_base->cs[cs].mcfg);
179         writel(ARCV | ARE_ARCV_1, &sdrc_base->cs[cs].rfr_ctrl);
180         writel(V_ACTIMA_165, &sdrc_actim_base->ctrla);
181         writel(V_ACTIMB_165, &sdrc_actim_base->ctrlb);
182
183         writel(CMD_NOP, &sdrc_base ->cs[cs].manual);
184         writel(CMD_PRECHARGE, &sdrc_base->cs[cs].manual);
185         writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
186         writel(CMD_AUTOREFRESH, &sdrc_base->cs[cs].manual);
187
188         /*
189          * CAS latency 3, Write Burst = Read Burst, Serial Mode,
190          * Burst length = 4
191          */
192         writel(CASL3 | BURSTLENGTH4, &sdrc_base->cs[cs].mr);
193
194         if (!mem_ok(cs))
195                 writel(0, &sdrc_base->cs[cs].mcfg);
196 }
197
198 void enable_gpmc_config(u32 *gpmc_config, gpmc_csx_t *gpmc_cs_base, u32 base,
199                         u32 size)
200 {
201         writel(0, &gpmc_cs_base->config7);
202         sdelay(1000);
203         /* Delay for settling */
204         writel(gpmc_config[0], &gpmc_cs_base->config1);
205         writel(gpmc_config[1], &gpmc_cs_base->config2);
206         writel(gpmc_config[2], &gpmc_cs_base->config3);
207         writel(gpmc_config[3], &gpmc_cs_base->config4);
208         writel(gpmc_config[4], &gpmc_cs_base->config5);
209         writel(gpmc_config[5], &gpmc_cs_base->config6);
210         /* Enable the config */
211         writel((((size & 0xF) << 8) | ((base >> 24) & 0x3F) |
212                 (1 << 6)), &gpmc_cs_base->config7);
213         sdelay(2000);
214 }
215
216 /*****************************************************
217  * gpmc_init(): init gpmc bus
218  * Init GPMC for x16, MuxMode (SDRAM in x32).
219  * This code can only be executed from SRAM or SDRAM.
220  *****************************************************/
221 void gpmc_init(void)
222 {
223         /* putting a blanket check on GPMC based on ZeBu for now */
224         u32 *gpmc_config = NULL;
225         gpmc_t *gpmc_base = (gpmc_t *)GPMC_BASE;
226         gpmc_csx_t *gpmc_cs_base = (gpmc_csx_t *)GPMC_CONFIG_CS0_BASE;
227         u32 base = 0;
228         u32 size = 0;
229         u32 f_off = CONFIG_SYS_MONITOR_LEN;
230         u32 f_sec = 0;
231         u32 config = 0;
232
233         /* global settings */
234         writel(0, &gpmc_base->irqenable); /* isr's sources masked */
235         writel(0, &gpmc_base->timeout_control);/* timeout disable */
236
237         config = readl(&gpmc_base->config);
238         config &= (~0xf00);
239         writel(config, &gpmc_base->config);
240
241         /*
242          * Disable the GPMC0 config set by ROM code
243          * It conflicts with our MPDB (both at 0x08000000)
244          */
245         writel(0, &gpmc_cs_base->config7);
246         sdelay(1000);
247
248 #if defined(CONFIG_CMD_NAND)    /* CS 0 */
249         gpmc_config = gpmc_m_nand;
250         gpmc_cfg_base = gpmc_base;
251         nand_cs_base = (gpmc_csx_t *)(GPMC_CONFIG_CS0_BASE +
252                                         (GPMC_CS * GPMC_CONFIG_WIDTH));
253         base = PISMO1_NAND_BASE;
254         size = PISMO1_NAND_SIZE;
255         enable_gpmc_config(gpmc_config, nand_cs_base, base, size);
256 #if defined(CONFIG_ENV_IS_IN_NAND)
257         f_off = SMNAND_ENV_OFFSET;
258         f_sec = SZ_128K;
259         /* env setup */
260         boot_flash_base = base;
261         boot_flash_off = f_off;
262         boot_flash_sec = f_sec;
263         boot_flash_env_addr = f_off;
264 #endif
265 #endif
266
267 #if defined(CONFIG_CMD_ONENAND)
268         gpmc_config = gpmc_onenand;
269         onenand_cs_base = (gpmc_csx_t *)(GPMC_CONFIG_CS0_BASE +
270                                         (GPMC_CS * GPMC_CONFIG_WIDTH));
271         base = PISMO1_ONEN_BASE;
272         size = PISMO1_ONEN_SIZE;
273         enable_gpmc_config(gpmc_config, onenand_cs_base, base, size);
274 #if defined(CONFIG_ENV_IS_IN_ONENAND)
275         f_off = ONENAND_ENV_OFFSET;
276         f_sec = SZ_128K;
277         /* env setup */
278         boot_flash_base = base;
279         boot_flash_off = f_off;
280         boot_flash_sec = f_sec;
281         boot_flash_env_addr = f_off;
282 #endif
283 #endif
284 }