blob: 0644de8825672440d0afc0f7985d4b6990cecf5b [file] [log] [blame]
wdenk42d1f032003-10-15 23:53:47 +00001/*
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
34long int fixed_sdram (void);
35
36/* MPC8540ADS Board Status & Control Registers */
37#if 0
38typedef struct bscr_ {
39 unsigned long bcsr0;
40 unsigned long bcsr1;
41 unsigned long bcsr2;
42 unsigned long bcsr3;
43 unsigned long bcsr4;
44 unsigned long bcsr5;
45 unsigned long bcsr6;
46 unsigned long bcsr7;
47} bcsr_t;
48#endif
49
wdenkc837dcb2004-01-20 23:12:12 +000050int board_early_init_f (void)
wdenk42d1f032003-10-15 23:53:47 +000051{
52#if defined(CONFIG_PCI)
53 volatile immap_t *immr = (immap_t *)CFG_IMMR;
54 volatile ccsr_pcix_t *pci = &immr->im_pcix;
55
56 pci->peer &= 0xffffffdf; /* disable master abort */
57#endif
58 return 0;
59}
60
61int checkboard (void)
62{
63 sys_info_t sysinfo;
64
65 get_sys_info (&sysinfo);
66
67 printf ("Board: Motorola MPC8540ADS Board\n");
68 printf ("\tCPU: %lu MHz\n", sysinfo.freqProcessor / 1000000);
69 printf ("\tCCB: %lu MHz\n", sysinfo.freqSystemBus / 1000000);
70 printf ("\tDDR: %lu MHz\n", sysinfo.freqSystemBus / 2000000);
71 if((CFG_LBC_LCRR & 0x0f) == 2 || (CFG_LBC_LCRR & 0x0f) == 4 \
72 || (CFG_LBC_LCRR & 0x0f) == 8) {
73 printf ("\tLBC: %lu MHz\n", sysinfo.freqSystemBus / 1000000 /(CFG_LBC_LCRR & 0x0f));
74 } else {
75 printf("\tLBC: unknown\n");
76 }
77 printf("L1 D-cache 32KB, L1 I-cache 32KB enabled.\n");
78 return (0);
79}
80
81long int initdram (int board_type)
82{
83 long dram_size = 0;
84 extern long spd_sdram (void);
85 volatile immap_t *immap = (immap_t *)CFG_IMMR;
86#if !defined(CONFIG_RAM_AS_FLASH)
87 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
88 sys_info_t sysinfo;
89 uint temp_lbcdll = 0;
90#endif
91#if !defined(CONFIG_RAM_AS_FLASH) || defined(CONFIG_DDR_DLL)
92 volatile ccsr_gur_t *gur= &immap->im_gur;
93#endif
94#if defined(CONFIG_DDR_DLL)
95 uint temp_ddrdll = 0;
96
97 /* Work around to stabilize DDR DLL */
98 temp_ddrdll = gur->ddrdllcr;
99 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
100 asm("sync;isync;msync");
101#endif
102
103#if defined(CONFIG_SPD_EEPROM)
104 dram_size = spd_sdram ();
105#else
106 dram_size = fixed_sdram ();
107#endif
108
109#if !defined(CONFIG_RAM_AS_FLASH) /* LocalBus is not emulating flash */
110 get_sys_info(&sysinfo);
111 /* if localbus freq is less than 66Mhz,we use bypass mode,otherwise use DLL */
112 if(sysinfo.freqSystemBus/(CFG_LBC_LCRR & 0x0f) < 66000000) {
113 lbc->lcrr = (CFG_LBC_LCRR & 0x0fffffff)| 0x80000000;
114 } else {
115#if defined(CONFIG_MPC85xx_REV1) /* need change CLKDIV before enable DLL */
116 lbc->lcrr = 0x10000004; /* default CLKDIV is 8, change it to 4 temporarily */
117#endif
118 lbc->lcrr = CFG_LBC_LCRR & 0x7fffffff;
119 udelay(200);
120 temp_lbcdll = gur->lbcdllcr;
121 gur->lbcdllcr = ((temp_lbcdll & 0xff) << 16 ) | 0x80000000;
122 asm("sync;isync;msync");
123 }
124 lbc->or2 = CFG_OR2_PRELIM; /* 64MB SDRAM */
125 lbc->br2 = CFG_BR2_PRELIM;
126 lbc->lbcr = CFG_LBC_LBCR;
127 lbc->lsdmr = CFG_LBC_LSDMR_1;
128 asm("sync");
129 (unsigned int) * (ulong *)0 = 0x000000ff;
130 lbc->lsdmr = CFG_LBC_LSDMR_2;
131 asm("sync");
132 (unsigned int) * (ulong *)0 = 0x000000ff;
133 lbc->lsdmr = CFG_LBC_LSDMR_3;
134 asm("sync");
135 (unsigned int) * (ulong *)0 = 0x000000ff;
136 lbc->lsdmr = CFG_LBC_LSDMR_4;
137 asm("sync");
138 (unsigned int) * (ulong *)0 = 0x000000ff;
139 lbc->lsdmr = CFG_LBC_LSDMR_5;
140 asm("sync");
141 lbc->lsrt = CFG_LBC_LSRT;
142 asm("sync");
143 lbc->mrtpr = CFG_LBC_MRTPR;
144 asm("sync");
145#endif
146
147#if defined(CONFIG_DDR_ECC)
148 {
149 /* Initialize all of memory for ECC, then
150 * enable errors */
151 uint *p = 0;
152 uint i = 0;
153 volatile immap_t *immap = (immap_t *)CFG_IMMR;
154 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
155 dma_init();
156 for (*p = 0; p < (uint *)(8 * 1024); p++) {
157 if (((unsigned int)p & 0x1f) == 0) { dcbz(p); }
158 *p = (unsigned int)0xdeadbeef;
159 if (((unsigned int)p & 0x1c) == 0x1c) { dcbf(p); }
160 }
161
162 /* 8K */
163 dma_xfer((uint *)0x2000,0x2000,(uint *)0);
164 /* 16K */
165 dma_xfer((uint *)0x4000,0x4000,(uint *)0);
166 /* 32K */
167 dma_xfer((uint *)0x8000,0x8000,(uint *)0);
168 /* 64K */
169 dma_xfer((uint *)0x10000,0x10000,(uint *)0);
170 /* 128k */
171 dma_xfer((uint *)0x20000,0x20000,(uint *)0);
172 /* 256k */
173 dma_xfer((uint *)0x40000,0x40000,(uint *)0);
174 /* 512k */
175 dma_xfer((uint *)0x80000,0x80000,(uint *)0);
176 /* 1M */
177 dma_xfer((uint *)0x100000,0x100000,(uint *)0);
178 /* 2M */
179 dma_xfer((uint *)0x200000,0x200000,(uint *)0);
180 /* 4M */
181 dma_xfer((uint *)0x400000,0x400000,(uint *)0);
182
183 for (i = 1; i < dram_size / 0x800000; i++) {
184 dma_xfer((uint *)(0x800000*i),0x800000,(uint *)0);
185 }
186
187 /* Enable errors for ECC */
188 ddr->err_disable = 0x00000000;
189 asm("sync;isync;msync");
190 }
191#endif
192
193 return dram_size;
194}
195
196
197#if defined(CFG_DRAM_TEST)
198int testdram (void)
199{
200 uint *pstart = (uint *) CFG_MEMTEST_START;
201 uint *pend = (uint *) CFG_MEMTEST_END;
202 uint *p;
203
204 printf("SDRAM test phase 1:\n");
205 for (p = pstart; p < pend; p++)
206 *p = 0xaaaaaaaa;
207
208 for (p = pstart; p < pend; p++) {
209 if (*p != 0xaaaaaaaa) {
210 printf ("SDRAM test fails at: %08x\n", (uint) p);
211 return 1;
212 }
213 }
214
215 printf("SDRAM test phase 2:\n");
216 for (p = pstart; p < pend; p++)
217 *p = 0x55555555;
218
219 for (p = pstart; p < pend; p++) {
220 if (*p != 0x55555555) {
221 printf ("SDRAM test fails at: %08x\n", (uint) p);
222 return 1;
223 }
224 }
225
226 printf("SDRAM test passed.\n");
227 return 0;
228}
229#endif
230
231
232#if !defined(CONFIG_SPD_EEPROM)
233/*************************************************************************
234 * fixed sdram init -- doesn't use serial presence detect.
235 ************************************************************************/
236long int fixed_sdram (void)
237{
238 #ifndef CFG_RAMBOOT
239 volatile immap_t *immap = (immap_t *)CFG_IMMR;
240 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
241
242 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
243 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
244 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
245 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
246 ddr->sdram_mode = CFG_DDR_MODE;
247 ddr->sdram_interval = CFG_DDR_INTERVAL;
248 #if defined (CONFIG_DDR_ECC)
249 ddr->err_disable = 0x0000000D;
250 ddr->err_sbe = 0x00ff0000;
251 #endif
252 asm("sync;isync;msync");
253 udelay(500);
254 #if defined (CONFIG_DDR_ECC)
255 /* Enable ECC checking */
256 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
257 #else
258 ddr->sdram_cfg = CFG_DDR_CONTROL;
259 #endif
260 asm("sync; isync; msync");
261 udelay(500);
262 #endif
263 return (CFG_SDRAM_SIZE * 1024 * 1024);
264}
265#endif /* !defined(CONFIG_SPD_EEPROM) */