blob: c90dbc762cc8688d545dff772a51185517ba5d64 [file] [log] [blame]
Lunsheng Wangb0e32942005-07-29 10:20:29 -05001/*
2 * (C) Copyright 2002,2003, Motorola Inc.
3 * Xianghua Xiao, (X.Xiao@motorola.com)
4 *
5 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26
27extern long int spd_sdram (void);
28
29#include <common.h>
30#include <asm/processor.h>
31#include <asm/immap_85xx.h>
32#include <spd.h>
33
34
35
36long int fixed_sdram (void);
37
38/* MPC8540ADS Board Status & Control Registers */
39#if 0
40typedef struct bscr_ {
41 unsigned long bcsr0;
42 unsigned long bcsr1;
43 unsigned long bcsr2;
44 unsigned long bcsr3;
45 unsigned long bcsr4;
46 unsigned long bcsr5;
47 unsigned long bcsr6;
48 unsigned long bcsr7;
49} bcsr_t;
50#endif
51
52
53
54int board_pre_init (void)
55{
56#if defined(CONFIG_PCI)
57 volatile immap_t *immr = (immap_t *)CFG_IMMR;
58 volatile ccsr_pcix_t *pci = &immr->im_pcix;
59
60 pci->peer &= 0xffffffdf; /* disable master abort */
61#endif
62 return 0;
63}
64
65int checkboard (void)
66{
67 sys_info_t sysinfo;
68
69 get_sys_info (&sysinfo);
70
71 printf ("Board: Freescale MPC8540EVAL Board\n");
72 printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
73 printf ("\tCCB: %lu MHz\n", sysinfo.freqSystemBus / 1000000);
74 printf ("\tDDR: %lu MHz\n", sysinfo.freqSystemBus / 2000000);
75 if((CFG_LBC_LCRR & 0x0f) == 2 || (CFG_LBC_LCRR & 0x0f) == 4 \
76 || (CFG_LBC_LCRR & 0x0f) == 8) {
77 printf ("\tLBC: %lu MHz\n", sysinfo.freqSystemBus / 1000000 /(CFG_LBC_LCRR & 0x0f));
78 } else {
79 printf("\tLBC: unknown\n");
80 }
81 printf("L1 D-cache 32KB, L1 I-cache 32KB enabled.\n");
82 return (0);
83}
84
85long int initdram (int board_type)
86{
87 long dram_size = 0;
88 extern long spd_sdram (void);
89 volatile immap_t *immap = (immap_t *)CFG_IMMR;
90#if !defined(CONFIG_RAM_AS_FLASH)
91 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
92 sys_info_t sysinfo;
93 uint temp_lbcdll = 0;
94#endif
95#if !defined(CONFIG_RAM_AS_FLASH) || defined(CONFIG_DDR_DLL)
96 volatile ccsr_gur_t *gur= &immap->im_gur;
97#endif
98
99#if defined(CONFIG_DDR_DLL)
100 uint temp_ddrdll = 0;
101
102 /* Work around to stabilize DDR DLL */
103 temp_ddrdll = gur->ddrdllcr;
104 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
105 asm("sync;isync;msync");
106#endif
107
108#if defined(CONFIG_SPD_EEPROM)
109 dram_size = spd_sdram ();
110#else
111 dram_size = fixed_sdram ();
112#endif
113
114#if defined(CFG_RAMBOOT)
115 return dram_size;
116#endif
117
118#if !defined(CONFIG_RAM_AS_FLASH) /* LocalBus is not emulating flash */
119 get_sys_info(&sysinfo);
120 /* if localbus freq is less than 66Mhz,we use bypass mode,otherwise use DLL */
121 if(sysinfo.freqSystemBus/(CFG_LBC_LCRR & 0x0f) < 66000000) {
122 lbc->lcrr = (CFG_LBC_LCRR & 0x0fffffff)| 0x80000000;
123 } else {
124 lbc->lcrr = CFG_LBC_LCRR & 0x7fffffff;
125 udelay(200);
126 temp_lbcdll = gur->lbcdllcr;
127 gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16 ) | 0x80000000;
128 asm("sync;isync;msync");
129 }
130 lbc->or2 = CFG_OR2_PRELIM; /* 64MB SDRAM */
131 lbc->br2 = CFG_BR2_PRELIM;
132 lbc->lbcr = CFG_LBC_LBCR;
133 lbc->lsdmr = CFG_LBC_LSDMR_1;
134 asm("sync");
135 * (ulong *)0 = 0x000000ff;
136 lbc->lsdmr = CFG_LBC_LSDMR_2;
137 asm("sync");
138 * (ulong *)0 = 0x000000ff;
139 lbc->lsdmr = CFG_LBC_LSDMR_3;
140 asm("sync");
141 * (ulong *)0 = 0x000000ff;
142 lbc->lsdmr = CFG_LBC_LSDMR_4;
143 asm("sync");
144 * (ulong *)0 = 0x000000ff;
145 lbc->lsdmr = CFG_LBC_LSDMR_5;
146 asm("sync");
147 lbc->lsrt = CFG_LBC_LSRT;
148 asm("sync");
149 lbc->mrtpr = CFG_LBC_MRTPR;
150 asm("sync");
151#endif
152
153#if defined(CONFIG_DDR_ECC)
154 {
155 /* Initialize all of memory for ECC, then
156 * enable errors */
157 uint *p = 0;
158 uint i = 0;
159 volatile immap_t *immap = (immap_t *)CFG_IMMR;
160 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
161 dma_init();
162 for (*p = 0; p < (uint *)(8 * 1024); p++) {
163 if (((unsigned int)p & 0x1f) == 0) { dcbz(p); }
164 *p = (unsigned int)0xdeadbeef;
165 if (((unsigned int)p & 0x1c) == 0x1c) { dcbf(p); }
166 }
167
168 /* 8K */
169 dma_xfer((uint *)0x2000,0x2000,(uint *)0);
170 /* 16K */
171 dma_xfer((uint *)0x4000,0x4000,(uint *)0);
172 /* 32K */
173 dma_xfer((uint *)0x8000,0x8000,(uint *)0);
174 /* 64K */
175 dma_xfer((uint *)0x10000,0x10000,(uint *)0);
176 /* 128k */
177 dma_xfer((uint *)0x20000,0x20000,(uint *)0);
178 /* 256k */
179 dma_xfer((uint *)0x40000,0x40000,(uint *)0);
180 /* 512k */
181 dma_xfer((uint *)0x80000,0x80000,(uint *)0);
182 /* 1M */
183 dma_xfer((uint *)0x100000,0x100000,(uint *)0);
184 /* 2M */
185 dma_xfer((uint *)0x200000,0x200000,(uint *)0);
186 /* 4M */
187 dma_xfer((uint *)0x400000,0x400000,(uint *)0);
188
189 for (i = 1; i < dram_size / 0x800000; i++) {
190 dma_xfer((uint *)(0x800000*i),0x800000,(uint *)0);
191 }
192
193 /* Enable errors for ECC */
194 ddr->err_disable = 0x00000000;
195 asm("sync;isync;msync");
196 }
197#endif
198
199 return dram_size;
200}
201
202
203#if defined(CFG_DRAM_TEST)
204int testdram (void)
205{
206 uint *pstart = (uint *) CFG_MEMTEST_START;
207 uint *pend = (uint *) CFG_MEMTEST_END;
208 uint *p;
209
210 printf("SDRAM test phase 1:\n");
211 for (p = pstart; p < pend; p++)
212 *p = 0xaaaaaaaa;
213
214 for (p = pstart; p < pend; p++) {
215 if (*p != 0xaaaaaaaa) {
216 printf ("SDRAM test fails at: %08x\n", (uint) p);
217 return 1;
218 }
219 }
220
221 printf("SDRAM test phase 2:\n");
222 for (p = pstart; p < pend; p++)
223 *p = 0x55555555;
224
225 for (p = pstart; p < pend; p++) {
226 if (*p != 0x55555555) {
227 printf ("SDRAM test fails at: %08x\n", (uint) p);
228 return 1;
229 }
230 }
231
232 printf("SDRAM test passed.\n");
233 return 0;
234}
235#endif
236
237
238#if !defined(CONFIG_SPD_EEPROM)
239/*************************************************************************
240 * fixed sdram init -- doesn't use serial presence detect.
241 ************************************************************************/
242long int fixed_sdram (void)
243{
244 #ifndef CFG_RAMBOOT
245 volatile immap_t *immap = (immap_t *)CFG_IMMR;
246 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
247
248 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
249 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
250 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
251 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
252 ddr->sdram_mode = CFG_DDR_MODE;
253 ddr->sdram_interval = CFG_DDR_INTERVAL;
254 #if defined (CONFIG_DDR_ECC)
255 ddr->err_disable = 0x0000000D;
256 ddr->err_sbe = 0x00ff0000;
257 #endif
258 asm("sync;isync;msync");
259 udelay(500);
260 #if defined (CONFIG_DDR_ECC)
261 /* Enable ECC checking */
262 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
263 #else
264 ddr->sdram_cfg = CFG_DDR_CONTROL;
265 #endif
266 asm("sync; isync; msync");
267 udelay(500);
268 #endif
269 return (CFG_SDRAM_SIZE * 1024 * 1024);
270}
271#endif /* !defined(CONFIG_SPD_EEPROM) */