2 * Copyright 2005 DENX Software Engineering
3 * Copyright 2004 Freescale Semiconductor.
4 * (C) Copyright 2002,2003, Motorola Inc.
5 * Xianghua Xiao, (X.Xiao@motorola.com)
7 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include <asm/processor.h>
32 #include <asm/immap_85xx.h>
35 #if defined(CONFIG_DDR_ECC)
36 extern void ddr_enable_ecc (unsigned int dram_size);
39 extern long int spd_sdram (void);
41 void local_bus_init (void);
42 long int fixed_sdram (void);
45 int board_early_init_f (void)
52 puts ("Board: TQM8540\n");
55 printf ("PCI1: 32 bit, %d MHz (compiled)\n",
56 CONFIG_SYS_CLK_FREQ / 1000000);
58 printf ("PCI1: disabled\n");
61 * Initialize local bus.
69 long int initdram (int board_type)
72 extern long spd_sdram (void);
73 volatile immap_t *immap = (immap_t *) CFG_IMMR;
75 #if defined(CONFIG_DDR_DLL)
77 volatile ccsr_gur_t *gur= &immap->im_gur;
83 * Work around to stabilize DDR DLL
85 gur->ddrdllcr = 0x81000000;
86 asm("sync;isync;msync");
88 while (gur->ddrdllcr != 0x81000100) {
89 gur->devdisr = gur->devdisr | 0x00010000;
90 asm("sync;isync;msync");
93 gur->devdisr = gur->devdisr & 0xfff7ffff;
94 asm("sync;isync;msync");
100 #if defined(CONFIG_SPD_EEPROM)
101 dram_size = spd_sdram ();
103 dram_size = fixed_sdram ();
106 #if defined(CONFIG_DDR_ECC)
108 * Initialize and enable DDR ECC.
110 ddr_enable_ecc (dram_size);
118 * Initialize Local Bus
121 void local_bus_init (void)
123 volatile immap_t *immap = (immap_t *) CFG_IMMR;
124 volatile ccsr_gur_t *gur = &immap->im_gur;
125 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
133 * Fix Local Bus clock glitch when DLL is enabled.
135 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
136 * If localbus freq is > 133Mhz, DLL can be safely enabled.
137 * Between 66 and 133, the DLL is enabled with an override workaround.
140 get_sys_info (&sysinfo);
141 clkdiv = lbc->lcrr & 0x0f;
142 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
145 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
146 lbc->ltedr = 0xa4c80000; /* DK: !!! */
148 } else if (lbc_hz >= 133) {
149 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
153 * On REV1 boards, need to change CLKDIV before enable DLL.
154 * Default CLKDIV is 8, change it to 4 temporarily.
156 uint pvr = get_pvr ();
157 uint temp_lbcdll = 0;
159 if (pvr == PVR_85xx_REV1) {
160 /* FIXME: Justify the high bit here. */
161 lbc->lcrr = 0x10000004;
164 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
168 * Sample LBC DLL ctrl reg, upshift it to set the
171 temp_lbcdll = gur->lbcdllcr;
172 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
173 asm ("sync;isync;msync");
178 #if defined(CFG_DRAM_TEST)
181 uint *pstart = (uint *) CFG_MEMTEST_START;
182 uint *pend = (uint *) CFG_MEMTEST_END;
185 printf ("SDRAM test phase 1:\n");
186 for (p = pstart; p < pend; p++)
189 for (p = pstart; p < pend; p++) {
190 if (*p != 0xaaaaaaaa) {
191 printf ("SDRAM test fails at: %08x\n", (uint) p);
196 printf ("SDRAM test phase 2:\n");
197 for (p = pstart; p < pend; p++)
200 for (p = pstart; p < pend; p++) {
201 if (*p != 0x55555555) {
202 printf ("SDRAM test fails at: %08x\n", (uint) p);
207 printf ("SDRAM test passed.\n");
213 #if !defined(CONFIG_SPD_EEPROM)
214 /*************************************************************************
215 * fixed sdram init -- doesn't use serial presence detect.
216 ************************************************************************/
217 long int fixed_sdram (void)
220 volatile immap_t *immap = (immap_t *) CFG_IMMR;
221 volatile ccsr_ddr_t *ddr = &immap->im_ddr;
223 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
224 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
225 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
226 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
227 ddr->sdram_mode = CFG_DDR_MODE;
228 ddr->sdram_interval = CFG_DDR_INTERVAL;
229 ddr->err_disable = 0x0000000D;
230 #if defined (CONFIG_DDR_ECC)
231 ddr->err_disable = 0x0000000D;
232 ddr->err_sbe = 0x00ff0000;
234 asm ("sync;isync;msync");
236 #if defined (CONFIG_DDR_ECC)
237 /* Enable ECC checking */
238 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
240 ddr->sdram_cfg = CFG_DDR_CONTROL;
242 asm ("sync; isync; msync");
245 return get_ram_size (0, CFG_SDRAM_SIZE * 1024 * 1024);
247 #endif /* !defined(CONFIG_SPD_EEPROM) */
250 #if defined(CONFIG_PCI)
252 * Initialize PCI Devices, report devices found.
255 #ifndef CONFIG_PCI_PNP
256 static struct pci_config_table pci_mpc85xxads_config_table[] = {
257 {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
258 PCI_IDSEL_NUMBER, PCI_ANY_ID,
259 pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
262 PCI_COMMAND_MASTER}},
268 static struct pci_controller hose = {
269 #ifndef CONFIG_PCI_PNP
270 config_table:pci_mpc85xxads_config_table,
274 #endif /* CONFIG_PCI */
277 void pci_init_board (void)
280 extern void pci_mpc85xx_init (struct pci_controller *hose);
282 pci_mpc85xx_init (&hose);
283 #endif /* CONFIG_PCI */