blob: 2db8b3256b8628e97a15911c4e47f12f91d758c9 [file] [log] [blame]
wdenka445ddf2004-06-09 00:34:46 +00001 /*
wdenk13eb2212004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk9c53f402003-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
wdenk9c53f402003-10-15 23:53:47 +000028#include <common.h>
wdenk492b9e72004-08-01 23:02:45 +000029#include <pci.h>
wdenk9c53f402003-10-15 23:53:47 +000030#include <asm/processor.h>
31#include <asm/immap_85xx.h>
32#include <spd.h>
33
Matthew McClintock148e26a2006-06-28 10:43:36 -050034#if defined(CONFIG_OF_FLAT_TREE)
35#include <ft_build.h>
Matthew McClintock148e26a2006-06-28 10:43:36 -050036#endif
37
38
Jon Loeliger77a4f6e2005-07-25 14:05:07 -050039#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk13eb2212004-07-09 23:27:13 +000040extern void ddr_enable_ecc(unsigned int dram_size);
wdenka445ddf2004-06-09 00:34:46 +000041#endif
42
wdenk13eb2212004-07-09 23:27:13 +000043extern long int spd_sdram(void);
wdenka445ddf2004-06-09 00:34:46 +000044
wdenk492b9e72004-08-01 23:02:45 +000045void local_bus_init(void);
wdenk13eb2212004-07-09 23:27:13 +000046void sdram_init(void);
47long int fixed_sdram(void);
48
wdenk9c53f402003-10-15 23:53:47 +000049
wdenkda55c6e2004-01-20 23:12:12 +000050int board_early_init_f (void)
wdenk9c53f402003-10-15 23:53:47 +000051{
wdenk492b9e72004-08-01 23:02:45 +000052 return 0;
wdenk9c53f402003-10-15 23:53:47 +000053}
54
55int checkboard (void)
56{
wdenka445ddf2004-06-09 00:34:46 +000057 puts("Board: ADS\n");
wdenk13eb2212004-07-09 23:27:13 +000058
59#ifdef CONFIG_PCI
60 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
61 CONFIG_SYS_CLK_FREQ / 1000000);
62#else
63 printf(" PCI1: disabled\n");
64#endif
65
wdenk492b9e72004-08-01 23:02:45 +000066 /*
67 * Initialize local bus.
68 */
69 local_bus_init();
70
wdenka445ddf2004-06-09 00:34:46 +000071 return 0;
wdenk9c53f402003-10-15 23:53:47 +000072}
73
wdenka445ddf2004-06-09 00:34:46 +000074
wdenk13eb2212004-07-09 23:27:13 +000075long int
76initdram(int board_type)
wdenk9c53f402003-10-15 23:53:47 +000077{
78 long dram_size = 0;
79 extern long spd_sdram (void);
wdenk13eb2212004-07-09 23:27:13 +000080
81 puts("Initializing\n");
wdenka445ddf2004-06-09 00:34:46 +000082
wdenk9c53f402003-10-15 23:53:47 +000083#if defined(CONFIG_DDR_DLL)
wdenk13eb2212004-07-09 23:27:13 +000084 {
Kumar Galaec1340d2007-11-27 23:25:02 -060085 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk492b9e72004-08-01 23:02:45 +000086 uint temp_ddrdll = 0;
wdenk9c53f402003-10-15 23:53:47 +000087
wdenk492b9e72004-08-01 23:02:45 +000088 /*
89 * Work around to stabilize DDR DLL
90 */
91 temp_ddrdll = gur->ddrdllcr;
92 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
93 asm("sync;isync;msync");
wdenk13eb2212004-07-09 23:27:13 +000094 }
wdenk9c53f402003-10-15 23:53:47 +000095#endif
96
97#if defined(CONFIG_SPD_EEPROM)
98 dram_size = spd_sdram ();
99#else
100 dram_size = fixed_sdram ();
101#endif
102
Jon Loeliger77a4f6e2005-07-25 14:05:07 -0500103#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk13eb2212004-07-09 23:27:13 +0000104 /*
105 * Initialize and enable DDR ECC.
106 */
107 ddr_enable_ecc(dram_size);
108#endif
109
110 /*
111 * Initialize SDRAM.
112 */
113 sdram_init();
114
115 puts(" DDR: ");
116 return dram_size;
117}
118
119
120/*
wdenk492b9e72004-08-01 23:02:45 +0000121 * Initialize Local Bus
wdenk13eb2212004-07-09 23:27:13 +0000122 */
123
wdenk492b9e72004-08-01 23:02:45 +0000124void
125local_bus_init(void)
wdenk13eb2212004-07-09 23:27:13 +0000126{
wdenk492b9e72004-08-01 23:02:45 +0000127 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Kumar Galaec1340d2007-11-27 23:25:02 -0600128 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk13eb2212004-07-09 23:27:13 +0000129 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
wdenk13eb2212004-07-09 23:27:13 +0000130
wdenk492b9e72004-08-01 23:02:45 +0000131 uint clkdiv;
132 uint lbc_hz;
133 sys_info_t sysinfo;
wdenk13eb2212004-07-09 23:27:13 +0000134
135 /*
wdenk492b9e72004-08-01 23:02:45 +0000136 * Errata LBC11.
137 * Fix Local Bus clock glitch when DLL is enabled.
wdenk13eb2212004-07-09 23:27:13 +0000138 *
wdenk492b9e72004-08-01 23:02:45 +0000139 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
140 * If localbus freq is > 133Mhz, DLL can be safely enabled.
141 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk13eb2212004-07-09 23:27:13 +0000142 */
wdenk492b9e72004-08-01 23:02:45 +0000143
144 get_sys_info(&sysinfo);
145 clkdiv = lbc->lcrr & 0x0f;
146 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
147
148 if (lbc_hz < 66) {
149 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
150
151 } else if (lbc_hz >= 133) {
152 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk13eb2212004-07-09 23:27:13 +0000153
wdenk9c53f402003-10-15 23:53:47 +0000154 } else {
wdenk13eb2212004-07-09 23:27:13 +0000155 /*
156 * On REV1 boards, need to change CLKDIV before enable DLL.
157 * Default CLKDIV is 8, change it to 4 temporarily.
158 */
wdenk492b9e72004-08-01 23:02:45 +0000159 uint pvr = get_pvr();
wdenk13eb2212004-07-09 23:27:13 +0000160 uint temp_lbcdll = 0;
wdenka445ddf2004-06-09 00:34:46 +0000161
162 if (pvr == PVR_85xx_REV1) {
wdenk492b9e72004-08-01 23:02:45 +0000163 /* FIXME: Justify the high bit here. */
wdenk13eb2212004-07-09 23:27:13 +0000164 lbc->lcrr = 0x10000004;
wdenka445ddf2004-06-09 00:34:46 +0000165 }
wdenk13eb2212004-07-09 23:27:13 +0000166
wdenk492b9e72004-08-01 23:02:45 +0000167 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
168 udelay(200);
169
170 /*
171 * Sample LBC DLL ctrl reg, upshift it to set the
172 * override bits.
173 */
wdenk9c53f402003-10-15 23:53:47 +0000174 temp_lbcdll = gur->lbcdllcr;
wdenk492b9e72004-08-01 23:02:45 +0000175 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
176 asm("sync;isync;msync");
wdenk9c53f402003-10-15 23:53:47 +0000177 }
wdenk492b9e72004-08-01 23:02:45 +0000178}
179
180
181/*
182 * Initialize SDRAM memory on the Local Bus.
183 */
184
185void
186sdram_init(void)
187{
188 volatile immap_t *immap = (immap_t *)CFG_IMMR;
189 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
190 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
191
192 puts(" SDRAM: ");
193 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk13eb2212004-07-09 23:27:13 +0000194
195 /*
196 * Setup SDRAM Base and Option Registers
197 */
198 lbc->or2 = CFG_OR2_PRELIM;
wdenk9c53f402003-10-15 23:53:47 +0000199 lbc->br2 = CFG_BR2_PRELIM;
200 lbc->lbcr = CFG_LBC_LBCR;
wdenk492b9e72004-08-01 23:02:45 +0000201 asm("msync");
wdenk13eb2212004-07-09 23:27:13 +0000202
wdenk9c53f402003-10-15 23:53:47 +0000203 lbc->lsrt = CFG_LBC_LSRT;
wdenk9c53f402003-10-15 23:53:47 +0000204 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk492b9e72004-08-01 23:02:45 +0000205 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000206
wdenk13eb2212004-07-09 23:27:13 +0000207 /*
208 * Configure the SDRAM controller.
209 */
210 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk492b9e72004-08-01 23:02:45 +0000211 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000212 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000213 ppcDcbf((unsigned long) sdram_addr);
214 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000215
wdenk13eb2212004-07-09 23:27:13 +0000216 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk492b9e72004-08-01 23:02:45 +0000217 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000218 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000219 ppcDcbf((unsigned long) sdram_addr);
220 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000221
wdenk13eb2212004-07-09 23:27:13 +0000222 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk492b9e72004-08-01 23:02:45 +0000223 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000224 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000225 ppcDcbf((unsigned long) sdram_addr);
226 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000227
wdenk13eb2212004-07-09 23:27:13 +0000228 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk492b9e72004-08-01 23:02:45 +0000229 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000230 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000231 ppcDcbf((unsigned long) sdram_addr);
232 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000233
wdenk13eb2212004-07-09 23:27:13 +0000234 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk492b9e72004-08-01 23:02:45 +0000235 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000236 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000237 ppcDcbf((unsigned long) sdram_addr);
238 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000239}
240
241
242#if defined(CFG_DRAM_TEST)
243int testdram (void)
244{
245 uint *pstart = (uint *) CFG_MEMTEST_START;
246 uint *pend = (uint *) CFG_MEMTEST_END;
247 uint *p;
248
249 printf("SDRAM test phase 1:\n");
250 for (p = pstart; p < pend; p++)
251 *p = 0xaaaaaaaa;
252
253 for (p = pstart; p < pend; p++) {
254 if (*p != 0xaaaaaaaa) {
255 printf ("SDRAM test fails at: %08x\n", (uint) p);
256 return 1;
257 }
258 }
259
260 printf("SDRAM test phase 2:\n");
261 for (p = pstart; p < pend; p++)
262 *p = 0x55555555;
263
264 for (p = pstart; p < pend; p++) {
265 if (*p != 0x55555555) {
266 printf ("SDRAM test fails at: %08x\n", (uint) p);
267 return 1;
268 }
269 }
270
271 printf("SDRAM test passed.\n");
272 return 0;
273}
274#endif
275
276
277#if !defined(CONFIG_SPD_EEPROM)
278/*************************************************************************
279 * fixed sdram init -- doesn't use serial presence detect.
280 ************************************************************************/
281long int fixed_sdram (void)
282{
283 #ifndef CFG_RAMBOOT
284 volatile immap_t *immap = (immap_t *)CFG_IMMR;
285 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
286
287 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
288 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
289 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
290 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
291 ddr->sdram_mode = CFG_DDR_MODE;
292 ddr->sdram_interval = CFG_DDR_INTERVAL;
293 #if defined (CONFIG_DDR_ECC)
294 ddr->err_disable = 0x0000000D;
295 ddr->err_sbe = 0x00ff0000;
296 #endif
297 asm("sync;isync;msync");
298 udelay(500);
299 #if defined (CONFIG_DDR_ECC)
300 /* Enable ECC checking */
301 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
302 #else
303 ddr->sdram_cfg = CFG_DDR_CONTROL;
304 #endif
305 asm("sync; isync; msync");
306 udelay(500);
307 #endif
wdenk13eb2212004-07-09 23:27:13 +0000308 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk9c53f402003-10-15 23:53:47 +0000309}
310#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk492b9e72004-08-01 23:02:45 +0000311
312
313#if defined(CONFIG_PCI)
314/*
315 * Initialize PCI Devices, report devices found.
316 */
317
wdenk492b9e72004-08-01 23:02:45 +0000318
Matthew McClintock8c0da862006-06-28 10:45:41 -0500319static struct pci_controller hose;
wdenk492b9e72004-08-01 23:02:45 +0000320
321#endif /* CONFIG_PCI */
322
323
324void
325pci_init_board(void)
326{
327#ifdef CONFIG_PCI
wdenk492b9e72004-08-01 23:02:45 +0000328 pci_mpc85xx_init(&hose);
329#endif /* CONFIG_PCI */
330}
Matthew McClintock148e26a2006-06-28 10:43:36 -0500331
332
333#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
334void
335ft_board_setup(void *blob, bd_t *bd)
336{
337 u32 *p;
338 int len;
339
Matthew McClintock8c0da862006-06-28 10:45:41 -0500340#ifdef CONFIG_PCI
341 ft_pci_setup(blob, bd);
342#endif
Matthew McClintock148e26a2006-06-28 10:43:36 -0500343 ft_cpu_setup(blob, bd);
344
345 p = ft_get_prop(blob, "/memory/reg", &len);
346 if (p != NULL) {
347 *p++ = cpu_to_be32(bd->bi_memstart);
348 *p = cpu_to_be32(bd->bi_memsize);
349 }
350}
351#endif