2 * Copyright 2004 Freescale Semiconductor.
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <asm/processor.h>
29 #include <asm/immap_85xx.h>
32 #include "../common/cadmus.h"
33 #include "../common/eeprom.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 void sdram_init(void);
47 board_early_init_f(void)
56 volatile immap_t *immap = (immap_t *)CFG_CCSRBAR;
57 volatile ccsr_gur_t *gur = &immap->im_gur;
59 /* PCI slot in USER bits CSR[6:7] by convention. */
60 uint pci_slot = get_pci_slot();
62 uint pci_dual = get_pci_dual(); /* PCI DUAL in CM_PCI[3] */
63 uint pci1_32 = gur->pordevsr & 0x10000; /* PORDEVSR[15] */
64 uint pci1_clk_sel = gur->porpllsr & 0x8000; /* PORPLLSR[16] */
65 uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
67 uint pci1_speed = get_clock_freq(); /* PCI PSPEED in [4:5] */
69 uint cpu_board_rev = get_cpu_board_revision();
71 printf("Board: CDS Version 0x%02x, PCI Slot %d\n",
75 printf("CPU Board Revision %d.%d (0x%04x)\n",
76 MPC85XX_CPU_BOARD_MAJOR(cpu_board_rev),
77 MPC85XX_CPU_BOARD_MINOR(cpu_board_rev),
80 printf(" PCI1: %d bit, %s MHz, %s\n",
82 (pci1_speed == 33000000) ? "33" :
83 (pci1_speed == 66000000) ? "66" : "unknown",
84 pci1_clk_sel ? "sync" : "async"
88 printf(" PCI2: 32 bit, 66 MHz, %s\n",
89 pci2_clk_sel ? "sync" : "async"
92 printf(" PCI2: disabled\n");
96 * Initialize local bus.
105 initdram(int board_type)
108 volatile immap_t *immap = (immap_t *)CFG_IMMR;
110 puts("Initializing\n");
112 #if defined(CONFIG_DDR_DLL)
115 * Work around to stabilize DDR DLL MSYNC_IN.
116 * Errata DDR9 seems to have been fixed.
117 * This is now the workaround for Errata DDR11:
118 * Override DLL = 1, Course Adj = 1, Tap Select = 0
121 volatile ccsr_gur_t *gur= &immap->im_gur;
123 gur->ddrdllcr = 0x81000000;
124 asm("sync;isync;msync");
129 dram_size = spd_sdram();
132 #if defined(CONFIG_DDR_ECC)
134 * Initialize and enable DDR ECC.
136 ddr_enable_ecc(dram_size);
141 * SDRAM Initialization
151 * Initialize Local Bus
157 volatile immap_t *immap = (immap_t *)CFG_IMMR;
158 volatile ccsr_gur_t *gur = &immap->im_gur;
159 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
168 * Fix Local Bus clock glitch when DLL is enabled.
170 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
171 * If localbus freq is > 133Mhz, DLL can be safely enabled.
172 * Between 66 and 133, the DLL is enabled with an override workaround.
175 get_sys_info(&sysinfo);
176 clkdiv = lbc->lcrr & 0x0f;
177 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
180 lbc->lcrr |= 0x80000000; /* DLL Bypass */
182 } else if (lbc_hz >= 133) {
183 lbc->lcrr &= (~0x80000000); /* DLL Enabled */
186 lbc->lcrr &= (~0x8000000); /* DLL Enabled */
190 * Sample LBC DLL ctrl reg, upshift it to set the
193 temp_lbcdll = gur->lbcdllcr;
194 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
195 asm("sync;isync;msync");
201 * Initialize SDRAM memory on the Local Bus.
207 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
210 volatile immap_t *immap = (immap_t *)CFG_IMMR;
211 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
212 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
218 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
221 * Setup SDRAM Base and Option Registers
223 lbc->or2 = CFG_OR2_PRELIM;
226 lbc->br2 = CFG_BR2_PRELIM;
229 lbc->lbcr = CFG_LBC_LBCR;
233 lbc->lsrt = CFG_LBC_LSRT;
234 lbc->mrtpr = CFG_LBC_MRTPR;
238 * Determine which address lines to use baed on CPU board rev.
240 cpu_board_rev = get_cpu_board_revision();
241 lsdmr_common = CFG_LBC_LSDMR_COMMON;
242 if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_0) {
243 lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
244 } else if (cpu_board_rev == MPC85XX_CPU_BOARD_REV_1_1) {
245 lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
248 * Assume something unable to identify itself is
249 * really old, and likely has lines 16/17 mapped.
251 lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
255 * Issue PRECHARGE ALL command.
257 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
260 ppcDcbf((unsigned long) sdram_addr);
264 * Issue 8 AUTO REFRESH commands.
266 for (idx = 0; idx < 8; idx++) {
267 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
270 ppcDcbf((unsigned long) sdram_addr);
275 * Issue 8 MODE-set command.
277 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
280 ppcDcbf((unsigned long) sdram_addr);
284 * Issue NORMAL OP command.
286 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
289 ppcDcbf((unsigned long) sdram_addr);
290 udelay(200); /* Overkill. Must wait > 200 bus cycles */
292 #endif /* enable SDRAM init */
296 #if defined(CFG_DRAM_TEST)
300 uint *pstart = (uint *) CFG_MEMTEST_START;
301 uint *pend = (uint *) CFG_MEMTEST_END;
304 printf("Testing DRAM from 0x%08x to 0x%08x\n",
308 printf("DRAM test phase 1:\n");
309 for (p = pstart; p < pend; p++)
312 for (p = pstart; p < pend; p++) {
313 if (*p != 0xaaaaaaaa) {
314 printf ("DRAM test fails at: %08x\n", (uint) p);
319 printf("DRAM test phase 2:\n");
320 for (p = pstart; p < pend; p++)
323 for (p = pstart; p < pend; p++) {
324 if (*p != 0x55555555) {
325 printf ("DRAM test fails at: %08x\n", (uint) p);
330 printf("DRAM test passed.\n");
337 #if defined(CONFIG_PCI)
340 * Initialize PCI Devices, report devices found.
343 #ifndef CONFIG_PCI_PNP
344 static struct pci_config_table pci_mpc85xxcds_config_table[] = {
345 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
346 PCI_IDSEL_NUMBER, PCI_ANY_ID,
347 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
349 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
356 static struct pci_controller hose = {
357 #ifndef CONFIG_PCI_PNP
358 config_table: pci_mpc85xxcds_config_table,
362 #endif /* CONFIG_PCI */
369 extern void pci_mpc85xx_init(struct pci_controller *hose);
371 pci_mpc85xx_init(&hose);