2 * Copyright 2004 Freescale Semiconductor.
3 * (C) Copyright 2002,2003, Motorola Inc.
4 * Xianghua Xiao, (X.Xiao@motorola.com)
6 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
8 * See file CREDITS for list of people who contributed to this
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.
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.
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,
30 #include <asm/processor.h>
31 #include <asm/immap_85xx.h>
34 #if defined(CONFIG_OF_FLAT_TREE)
39 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
40 extern void ddr_enable_ecc(unsigned int dram_size);
43 extern long int spd_sdram(void);
45 void local_bus_init(void);
46 void sdram_init(void);
47 long int fixed_sdram(void);
50 int board_early_init_f (void)
60 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
61 CONFIG_SYS_CLK_FREQ / 1000000);
63 printf(" PCI1: disabled\n");
67 * Initialize local bus.
76 initdram(int board_type)
79 extern long spd_sdram (void);
80 volatile immap_t *immap = (immap_t *)CFG_IMMR;
82 puts("Initializing\n");
84 #if defined(CONFIG_DDR_DLL)
86 volatile ccsr_gur_t *gur= &immap->im_gur;
90 * Work around to stabilize DDR DLL
92 temp_ddrdll = gur->ddrdllcr;
93 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
94 asm("sync;isync;msync");
98 #if defined(CONFIG_SPD_EEPROM)
99 dram_size = spd_sdram ();
101 dram_size = fixed_sdram ();
104 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
106 * Initialize and enable DDR ECC.
108 ddr_enable_ecc(dram_size);
122 * Initialize Local Bus
128 volatile immap_t *immap = (immap_t *)CFG_IMMR;
129 volatile ccsr_gur_t *gur = &immap->im_gur;
130 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
138 * Fix Local Bus clock glitch when DLL is enabled.
140 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
141 * If localbus freq is > 133Mhz, DLL can be safely enabled.
142 * Between 66 and 133, the DLL is enabled with an override workaround.
145 get_sys_info(&sysinfo);
146 clkdiv = lbc->lcrr & 0x0f;
147 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
150 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
152 } else if (lbc_hz >= 133) {
153 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
157 * On REV1 boards, need to change CLKDIV before enable DLL.
158 * Default CLKDIV is 8, change it to 4 temporarily.
160 uint pvr = get_pvr();
161 uint temp_lbcdll = 0;
163 if (pvr == PVR_85xx_REV1) {
164 /* FIXME: Justify the high bit here. */
165 lbc->lcrr = 0x10000004;
168 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
172 * Sample LBC DLL ctrl reg, upshift it to set the
175 temp_lbcdll = gur->lbcdllcr;
176 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
177 asm("sync;isync;msync");
183 * Initialize SDRAM memory on the Local Bus.
189 volatile immap_t *immap = (immap_t *)CFG_IMMR;
190 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
191 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
194 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
197 * Setup SDRAM Base and Option Registers
199 lbc->or2 = CFG_OR2_PRELIM;
200 lbc->br2 = CFG_BR2_PRELIM;
201 lbc->lbcr = CFG_LBC_LBCR;
204 lbc->lsrt = CFG_LBC_LSRT;
205 lbc->mrtpr = CFG_LBC_MRTPR;
209 * Configure the SDRAM controller.
211 lbc->lsdmr = CFG_LBC_LSDMR_1;
214 ppcDcbf((unsigned long) sdram_addr);
217 lbc->lsdmr = CFG_LBC_LSDMR_2;
220 ppcDcbf((unsigned long) sdram_addr);
223 lbc->lsdmr = CFG_LBC_LSDMR_3;
226 ppcDcbf((unsigned long) sdram_addr);
229 lbc->lsdmr = CFG_LBC_LSDMR_4;
232 ppcDcbf((unsigned long) sdram_addr);
235 lbc->lsdmr = CFG_LBC_LSDMR_5;
238 ppcDcbf((unsigned long) sdram_addr);
243 #if defined(CFG_DRAM_TEST)
246 uint *pstart = (uint *) CFG_MEMTEST_START;
247 uint *pend = (uint *) CFG_MEMTEST_END;
250 printf("SDRAM test phase 1:\n");
251 for (p = pstart; p < pend; p++)
254 for (p = pstart; p < pend; p++) {
255 if (*p != 0xaaaaaaaa) {
256 printf ("SDRAM test fails at: %08x\n", (uint) p);
261 printf("SDRAM test phase 2:\n");
262 for (p = pstart; p < pend; p++)
265 for (p = pstart; p < pend; p++) {
266 if (*p != 0x55555555) {
267 printf ("SDRAM test fails at: %08x\n", (uint) p);
272 printf("SDRAM test passed.\n");
278 #if !defined(CONFIG_SPD_EEPROM)
279 /*************************************************************************
280 * fixed sdram init -- doesn't use serial presence detect.
281 ************************************************************************/
282 long int fixed_sdram (void)
285 volatile immap_t *immap = (immap_t *)CFG_IMMR;
286 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
288 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
289 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
290 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
291 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
292 ddr->sdram_mode = CFG_DDR_MODE;
293 ddr->sdram_interval = CFG_DDR_INTERVAL;
294 #if defined (CONFIG_DDR_ECC)
295 ddr->err_disable = 0x0000000D;
296 ddr->err_sbe = 0x00ff0000;
298 asm("sync;isync;msync");
300 #if defined (CONFIG_DDR_ECC)
301 /* Enable ECC checking */
302 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
304 ddr->sdram_cfg = CFG_DDR_CONTROL;
306 asm("sync; isync; msync");
309 return CFG_SDRAM_SIZE * 1024 * 1024;
311 #endif /* !defined(CONFIG_SPD_EEPROM) */
314 #if defined(CONFIG_PCI)
316 * Initialize PCI Devices, report devices found.
320 static struct pci_controller hose;
322 #endif /* CONFIG_PCI */
329 pci_mpc85xx_init(&hose);
330 #endif /* CONFIG_PCI */
334 #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
336 ft_board_setup(void *blob, bd_t *bd)
342 ft_pci_setup(blob, bd);
344 ft_cpu_setup(blob, bd);
346 p = ft_get_prop(blob, "/memory/reg", &len);
348 *p++ = cpu_to_be32(bd->bi_memstart);
349 *p = cpu_to_be32(bd->bi_memsize);