2 * Copyright 2004 Freescale Semiconductor.
4 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
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,
27 #include <asm/processor.h>
28 #include <asm/immap_85xx.h>
31 #include "../common/cadmus.h"
32 #include "../common/eeprom.h"
33 #include "../common/via.h"
35 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
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);
44 int board_early_init_f (void)
51 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
52 volatile ccsr_gur_t *gur = &immap->im_gur;
54 /* PCI slot in USER bits CSR[6:7] by convention. */
55 uint pci_slot = get_pci_slot ();
57 uint pci_dual = get_pci_dual (); /* PCI DUAL in CM_PCI[3] */
58 uint pci1_32 = gur->pordevsr & 0x10000; /* PORDEVSR[15] */
59 uint pci1_clk_sel = gur->porpllsr & 0x8000; /* PORPLLSR[16] */
60 uint pci2_clk_sel = gur->porpllsr & 0x4000; /* PORPLLSR[17] */
62 uint pci1_speed = get_clock_freq (); /* PCI PSPEED in [4:5] */
64 uint cpu_board_rev = get_cpu_board_revision ();
66 printf ("Board: CDS Version 0x%02x, PCI Slot %d\n",
67 get_board_version (), pci_slot);
69 printf ("CPU Board Revision %d.%d (0x%04x)\n",
70 MPC85XX_CPU_BOARD_MAJOR (cpu_board_rev),
71 MPC85XX_CPU_BOARD_MINOR (cpu_board_rev), cpu_board_rev);
73 printf (" PCI1: %d bit, %s MHz, %s\n",
75 (pci1_speed == 33000000) ? "33" :
76 (pci1_speed == 66000000) ? "66" : "unknown",
77 pci1_clk_sel ? "sync" : "async");
80 printf (" PCI2: 32 bit, 66 MHz, %s\n",
81 pci2_clk_sel ? "sync" : "async");
83 printf (" PCI2: disabled\n");
87 * Initialize local bus.
93 * Hack TSEC 3 and 4 IO voltages.
95 gur->tsec34ioovcr = 0xe7e0; /* 1110 0111 1110 0xxx */
101 initdram(int board_type)
104 volatile immap_t *immap = (immap_t *)CFG_IMMR;
106 puts("Initializing\n");
108 #if defined(CONFIG_DDR_DLL)
111 * Work around to stabilize DDR DLL MSYNC_IN.
112 * Errata DDR9 seems to have been fixed.
113 * This is now the workaround for Errata DDR11:
114 * Override DLL = 1, Course Adj = 1, Tap Select = 0
117 volatile ccsr_gur_t *gur= &immap->im_gur;
119 gur->ddrdllcr = 0x81000000;
120 asm("sync;isync;msync");
124 dram_size = spd_sdram();
126 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
128 * Initialize and enable DDR ECC.
130 ddr_enable_ecc(dram_size);
133 * SDRAM Initialization
142 * Initialize Local Bus
147 volatile immap_t *immap = (immap_t *)CFG_IMMR;
148 volatile ccsr_gur_t *gur = &immap->im_gur;
149 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
155 get_sys_info(&sysinfo);
156 clkdiv = (lbc->lcrr & 0x0f) * 2;
157 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
159 gur->lbiuiplldcr1 = 0x00078080;
161 gur->lbiuiplldcr0 = 0x7c0f1bf0;
162 } else if (clkdiv == 8) {
163 gur->lbiuiplldcr0 = 0x6c0f1bf0;
164 } else if (clkdiv == 4) {
165 gur->lbiuiplldcr0 = 0x5c0f1bf0;
168 lbc->lcrr |= 0x00030000;
170 asm("sync;isync;msync");
174 * Initialize SDRAM memory on the Local Bus.
179 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
182 volatile immap_t *immap = (immap_t *)CFG_IMMR;
183 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
184 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
190 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
193 * Setup SDRAM Base and Option Registers
195 lbc->or2 = CFG_OR2_PRELIM;
198 lbc->br2 = CFG_BR2_PRELIM;
201 lbc->lbcr = CFG_LBC_LBCR;
205 lbc->lsrt = CFG_LBC_LSRT;
206 lbc->mrtpr = CFG_LBC_MRTPR;
210 * MPC8548 uses "new" 15-16 style addressing.
212 cpu_board_rev = get_cpu_board_revision();
213 lsdmr_common = CFG_LBC_LSDMR_COMMON;
214 lsdmr_common |= CFG_LBC_LSDMR_BSMA1516;
217 * Issue PRECHARGE ALL command.
219 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
222 ppcDcbf((unsigned long) sdram_addr);
226 * Issue 8 AUTO REFRESH commands.
228 for (idx = 0; idx < 8; idx++) {
229 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
232 ppcDcbf((unsigned long) sdram_addr);
237 * Issue 8 MODE-set command.
239 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
242 ppcDcbf((unsigned long) sdram_addr);
246 * Issue NORMAL OP command.
248 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
251 ppcDcbf((unsigned long) sdram_addr);
252 udelay(200); /* Overkill. Must wait > 200 bus cycles */
254 #endif /* enable SDRAM init */
257 #if defined(CFG_DRAM_TEST)
261 uint *pstart = (uint *) CFG_MEMTEST_START;
262 uint *pend = (uint *) CFG_MEMTEST_END;
265 printf("Testing DRAM from 0x%08x to 0x%08x\n",
269 printf("DRAM test phase 1:\n");
270 for (p = pstart; p < pend; p++)
273 for (p = pstart; p < pend; p++) {
274 if (*p != 0xaaaaaaaa) {
275 printf ("DRAM test fails at: %08x\n", (uint) p);
280 printf("DRAM test phase 2:\n");
281 for (p = pstart; p < pend; p++)
284 for (p = pstart; p < pend; p++) {
285 if (*p != 0x55555555) {
286 printf ("DRAM test fails at: %08x\n", (uint) p);
291 printf("DRAM test passed.\n");
296 #if defined(CONFIG_PCI)
297 /* For some reason the Tundra PCI bridge shows up on itself as a
298 * different device. Work around that by refusing to configure it.
300 void dummy_func(struct pci_controller* hose, pci_dev_t dev, struct pci_config_table *tab) { }
302 static struct pci_config_table pci_mpc85xxcds_config_table[] = {
303 {0x10e3, 0x0513, PCI_ANY_ID, 1, 3, PCI_ANY_ID, dummy_func, {0,0,0}},
304 {0x1106, 0x0686, PCI_ANY_ID, 1, 2, 0, mpc85xx_config_via, {0,0,0}},
305 {0x1106, 0x0571, PCI_ANY_ID, 1, 2, 1, mpc85xx_config_via_usbide, {0,0,0}},
306 {0x1105, 0x3038, PCI_ANY_ID, 1, 2, 2, mpc85xx_config_via_usb, {0,0,0}},
307 {0x1106, 0x3038, PCI_ANY_ID, 1, 2, 3, mpc85xx_config_via_usb2, {0,0,0}},
308 {0x1106, 0x3058, PCI_ANY_ID, 1, 2, 5, mpc85xx_config_via_power, {0,0,0}},
309 {0x1106, 0x3068, PCI_ANY_ID, 1, 2, 6, mpc85xx_config_via_ac97, {0,0,0}}
312 static struct pci_controller hose[] = {
313 { config_table: pci_mpc85xxcds_config_table,},
314 #ifdef CONFIG_MPC85XX_PCI2
319 #endif /* CONFIG_PCI */
325 extern void pci_mpc85xx_init(struct pci_controller **hose);
327 pci_mpc85xx_init(&hose);