blob: fbcb397290a4c11ba1d743ae0aa65950b7c8f078 [file] [log] [blame]
wdenk97d80fc2004-06-09 00:34:46 +00001 /*
wdenk0ac6f8b2004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk42d1f032003-10-15 23:53:47 +00003 * (C) Copyright 2002,2003, Motorola Inc.
4 * Xianghua Xiao, (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27
wdenk42d1f032003-10-15 23:53:47 +000028#include <common.h>
wdenk9aea9532004-08-01 23:02:45 +000029#include <pci.h>
wdenk42d1f032003-10-15 23:53:47 +000030#include <asm/processor.h>
31#include <asm/immap_85xx.h>
32#include <spd.h>
33
Matthew McClintock40d5fa32006-06-28 10:43:36 -050034#if defined(CONFIG_OF_FLAT_TREE)
35#include <ft_build.h>
36extern void ft_cpu_setup(void *blob, bd_t *bd);
37#endif
38
39
Jon Loeligerd9b94f22005-07-25 14:05:07 -050040#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000041extern void ddr_enable_ecc(unsigned int dram_size);
wdenk97d80fc2004-06-09 00:34:46 +000042#endif
43
wdenk0ac6f8b2004-07-09 23:27:13 +000044extern long int spd_sdram(void);
wdenk97d80fc2004-06-09 00:34:46 +000045
wdenk9aea9532004-08-01 23:02:45 +000046void local_bus_init(void);
wdenk0ac6f8b2004-07-09 23:27:13 +000047void sdram_init(void);
48long int fixed_sdram(void);
49
wdenk42d1f032003-10-15 23:53:47 +000050
wdenkc837dcb2004-01-20 23:12:12 +000051int board_early_init_f (void)
wdenk42d1f032003-10-15 23:53:47 +000052{
wdenk9aea9532004-08-01 23:02:45 +000053 return 0;
wdenk42d1f032003-10-15 23:53:47 +000054}
55
56int checkboard (void)
57{
wdenk97d80fc2004-06-09 00:34:46 +000058 puts("Board: ADS\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000059
60#ifdef CONFIG_PCI
61 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
62 CONFIG_SYS_CLK_FREQ / 1000000);
63#else
64 printf(" PCI1: disabled\n");
65#endif
66
wdenk9aea9532004-08-01 23:02:45 +000067 /*
68 * Initialize local bus.
69 */
70 local_bus_init();
71
wdenk97d80fc2004-06-09 00:34:46 +000072 return 0;
wdenk42d1f032003-10-15 23:53:47 +000073}
74
wdenk97d80fc2004-06-09 00:34:46 +000075
wdenk0ac6f8b2004-07-09 23:27:13 +000076long int
77initdram(int board_type)
wdenk42d1f032003-10-15 23:53:47 +000078{
79 long dram_size = 0;
80 extern long spd_sdram (void);
81 volatile immap_t *immap = (immap_t *)CFG_IMMR;
wdenk0ac6f8b2004-07-09 23:27:13 +000082
83 puts("Initializing\n");
wdenk97d80fc2004-06-09 00:34:46 +000084
wdenk42d1f032003-10-15 23:53:47 +000085#if defined(CONFIG_DDR_DLL)
wdenk0ac6f8b2004-07-09 23:27:13 +000086 {
wdenk9aea9532004-08-01 23:02:45 +000087 volatile ccsr_gur_t *gur= &immap->im_gur;
88 uint temp_ddrdll = 0;
wdenk42d1f032003-10-15 23:53:47 +000089
wdenk9aea9532004-08-01 23:02:45 +000090 /*
91 * Work around to stabilize DDR DLL
92 */
93 temp_ddrdll = gur->ddrdllcr;
94 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
95 asm("sync;isync;msync");
wdenk0ac6f8b2004-07-09 23:27:13 +000096 }
wdenk42d1f032003-10-15 23:53:47 +000097#endif
98
99#if defined(CONFIG_SPD_EEPROM)
100 dram_size = spd_sdram ();
101#else
102 dram_size = fixed_sdram ();
103#endif
104
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500105#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +0000106 /*
107 * Initialize and enable DDR ECC.
108 */
109 ddr_enable_ecc(dram_size);
110#endif
111
112 /*
113 * Initialize SDRAM.
114 */
115 sdram_init();
116
117 puts(" DDR: ");
118 return dram_size;
119}
120
121
122/*
wdenk9aea9532004-08-01 23:02:45 +0000123 * Initialize Local Bus
wdenk0ac6f8b2004-07-09 23:27:13 +0000124 */
125
wdenk9aea9532004-08-01 23:02:45 +0000126void
127local_bus_init(void)
wdenk0ac6f8b2004-07-09 23:27:13 +0000128{
wdenk9aea9532004-08-01 23:02:45 +0000129 volatile immap_t *immap = (immap_t *)CFG_IMMR;
130 volatile ccsr_gur_t *gur = &immap->im_gur;
wdenk0ac6f8b2004-07-09 23:27:13 +0000131 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
wdenk0ac6f8b2004-07-09 23:27:13 +0000132
wdenk9aea9532004-08-01 23:02:45 +0000133 uint clkdiv;
134 uint lbc_hz;
135 sys_info_t sysinfo;
wdenk0ac6f8b2004-07-09 23:27:13 +0000136
137 /*
wdenk9aea9532004-08-01 23:02:45 +0000138 * Errata LBC11.
139 * Fix Local Bus clock glitch when DLL is enabled.
wdenk0ac6f8b2004-07-09 23:27:13 +0000140 *
wdenk9aea9532004-08-01 23:02:45 +0000141 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
142 * If localbus freq is > 133Mhz, DLL can be safely enabled.
143 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk0ac6f8b2004-07-09 23:27:13 +0000144 */
wdenk9aea9532004-08-01 23:02:45 +0000145
146 get_sys_info(&sysinfo);
147 clkdiv = lbc->lcrr & 0x0f;
148 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
149
150 if (lbc_hz < 66) {
151 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
152
153 } else if (lbc_hz >= 133) {
154 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk0ac6f8b2004-07-09 23:27:13 +0000155
wdenk42d1f032003-10-15 23:53:47 +0000156 } else {
wdenk0ac6f8b2004-07-09 23:27:13 +0000157 /*
158 * On REV1 boards, need to change CLKDIV before enable DLL.
159 * Default CLKDIV is 8, change it to 4 temporarily.
160 */
wdenk9aea9532004-08-01 23:02:45 +0000161 uint pvr = get_pvr();
wdenk0ac6f8b2004-07-09 23:27:13 +0000162 uint temp_lbcdll = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000163
164 if (pvr == PVR_85xx_REV1) {
wdenk9aea9532004-08-01 23:02:45 +0000165 /* FIXME: Justify the high bit here. */
wdenk0ac6f8b2004-07-09 23:27:13 +0000166 lbc->lcrr = 0x10000004;
wdenk97d80fc2004-06-09 00:34:46 +0000167 }
wdenk0ac6f8b2004-07-09 23:27:13 +0000168
wdenk9aea9532004-08-01 23:02:45 +0000169 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
170 udelay(200);
171
172 /*
173 * Sample LBC DLL ctrl reg, upshift it to set the
174 * override bits.
175 */
wdenk42d1f032003-10-15 23:53:47 +0000176 temp_lbcdll = gur->lbcdllcr;
wdenk9aea9532004-08-01 23:02:45 +0000177 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
178 asm("sync;isync;msync");
wdenk42d1f032003-10-15 23:53:47 +0000179 }
wdenk9aea9532004-08-01 23:02:45 +0000180}
181
182
183/*
184 * Initialize SDRAM memory on the Local Bus.
185 */
186
187void
188sdram_init(void)
189{
190 volatile immap_t *immap = (immap_t *)CFG_IMMR;
191 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
192 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
193
194 puts(" SDRAM: ");
195 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk0ac6f8b2004-07-09 23:27:13 +0000196
197 /*
198 * Setup SDRAM Base and Option Registers
199 */
200 lbc->or2 = CFG_OR2_PRELIM;
wdenk42d1f032003-10-15 23:53:47 +0000201 lbc->br2 = CFG_BR2_PRELIM;
202 lbc->lbcr = CFG_LBC_LBCR;
wdenk9aea9532004-08-01 23:02:45 +0000203 asm("msync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000204
wdenk42d1f032003-10-15 23:53:47 +0000205 lbc->lsrt = CFG_LBC_LSRT;
wdenk42d1f032003-10-15 23:53:47 +0000206 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk9aea9532004-08-01 23:02:45 +0000207 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000208
209 /*
210 * Configure the SDRAM controller.
211 */
212 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk9aea9532004-08-01 23:02:45 +0000213 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000214 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000215 ppcDcbf((unsigned long) sdram_addr);
216 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000217
218 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk9aea9532004-08-01 23:02:45 +0000219 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000220 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000221 ppcDcbf((unsigned long) sdram_addr);
222 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000223
224 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk9aea9532004-08-01 23:02:45 +0000225 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000226 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000227 ppcDcbf((unsigned long) sdram_addr);
228 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000229
230 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk9aea9532004-08-01 23:02:45 +0000231 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000232 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000233 ppcDcbf((unsigned long) sdram_addr);
234 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000235
236 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk9aea9532004-08-01 23:02:45 +0000237 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000238 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000239 ppcDcbf((unsigned long) sdram_addr);
240 udelay(100);
wdenk42d1f032003-10-15 23:53:47 +0000241}
242
243
244#if defined(CFG_DRAM_TEST)
245int testdram (void)
246{
247 uint *pstart = (uint *) CFG_MEMTEST_START;
248 uint *pend = (uint *) CFG_MEMTEST_END;
249 uint *p;
250
251 printf("SDRAM test phase 1:\n");
252 for (p = pstart; p < pend; p++)
253 *p = 0xaaaaaaaa;
254
255 for (p = pstart; p < pend; p++) {
256 if (*p != 0xaaaaaaaa) {
257 printf ("SDRAM test fails at: %08x\n", (uint) p);
258 return 1;
259 }
260 }
261
262 printf("SDRAM test phase 2:\n");
263 for (p = pstart; p < pend; p++)
264 *p = 0x55555555;
265
266 for (p = pstart; p < pend; p++) {
267 if (*p != 0x55555555) {
268 printf ("SDRAM test fails at: %08x\n", (uint) p);
269 return 1;
270 }
271 }
272
273 printf("SDRAM test passed.\n");
274 return 0;
275}
276#endif
277
278
279#if !defined(CONFIG_SPD_EEPROM)
280/*************************************************************************
281 * fixed sdram init -- doesn't use serial presence detect.
282 ************************************************************************/
283long int fixed_sdram (void)
284{
285 #ifndef CFG_RAMBOOT
286 volatile immap_t *immap = (immap_t *)CFG_IMMR;
287 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
288
289 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
290 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
291 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
292 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
293 ddr->sdram_mode = CFG_DDR_MODE;
294 ddr->sdram_interval = CFG_DDR_INTERVAL;
295 #if defined (CONFIG_DDR_ECC)
296 ddr->err_disable = 0x0000000D;
297 ddr->err_sbe = 0x00ff0000;
298 #endif
299 asm("sync;isync;msync");
300 udelay(500);
301 #if defined (CONFIG_DDR_ECC)
302 /* Enable ECC checking */
303 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
304 #else
305 ddr->sdram_cfg = CFG_DDR_CONTROL;
306 #endif
307 asm("sync; isync; msync");
308 udelay(500);
309 #endif
wdenk0ac6f8b2004-07-09 23:27:13 +0000310 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk42d1f032003-10-15 23:53:47 +0000311}
312#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk9aea9532004-08-01 23:02:45 +0000313
314
315#if defined(CONFIG_PCI)
316/*
317 * Initialize PCI Devices, report devices found.
318 */
319
wdenk9aea9532004-08-01 23:02:45 +0000320
Matthew McClintock52c7a682006-06-28 10:45:41 -0500321static struct pci_controller hose;
wdenk9aea9532004-08-01 23:02:45 +0000322
323#endif /* CONFIG_PCI */
324
325
326void
327pci_init_board(void)
328{
329#ifdef CONFIG_PCI
330 extern void pci_mpc85xx_init(struct pci_controller *hose);
331
332 pci_mpc85xx_init(&hose);
333#endif /* CONFIG_PCI */
334}
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500335
336
337#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
338void
339ft_board_setup(void *blob, bd_t *bd)
340{
341 u32 *p;
342 int len;
343
Matthew McClintock52c7a682006-06-28 10:45:41 -0500344#ifdef CONFIG_PCI
345 ft_pci_setup(blob, bd);
346#endif
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500347 ft_cpu_setup(blob, bd);
348
349 p = ft_get_prop(blob, "/memory/reg", &len);
350 if (p != NULL) {
351 *p++ = cpu_to_be32(bd->bi_memstart);
352 *p = cpu_to_be32(bd->bi_memsize);
353 }
354}
355#endif