2 * Copyright 2004 Freescale Semiconductor.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/processor.h>
27 #include <asm/immap_85xx.h>
30 #include "../common/cadmus.h"
31 #include "../common/eeprom.h"
33 #if defined(CONFIG_DDR_ECC)
34 extern void ddr_enable_ecc(unsigned int dram_size
);
37 extern long int spd_sdram(void);
39 void local_bus_init(void);
40 void sdram_init(void);
45 board_early_init_f(void)
54 volatile immap_t
*immap
= (immap_t
*)CFG_CCSRBAR
;
55 volatile ccsr_gur_t
*gur
= &immap
->im_gur
;
57 /* PCI slot in USER bits CSR[6:7] by convention. */
58 uint pci_slot
= get_pci_slot();
60 uint pci_dual
= get_pci_dual(); /* PCI DUAL in CM_PCI[3] */
61 uint pci1_32
= gur
->pordevsr
& 0x10000; /* PORDEVSR[15] */
62 uint pci1_clk_sel
= gur
->porpllsr
& 0x8000; /* PORPLLSR[16] */
63 uint pci2_clk_sel
= gur
->porpllsr
& 0x4000; /* PORPLLSR[17] */
65 uint pci1_speed
= get_clock_freq(); /* PCI PSPEED in [4:5] */
67 uint cpu_board_rev
= get_cpu_board_revision();
69 printf("Board: CDS Version 0x%02x, PCI Slot %d\n",
73 printf("CPU Board Revision %d.%d (0x%04x)\n",
74 MPC85XX_CPU_BOARD_MAJOR(cpu_board_rev
),
75 MPC85XX_CPU_BOARD_MINOR(cpu_board_rev
),
78 printf(" PCI1: %d bit, %s MHz, %s\n",
80 (pci1_speed
== 33000000) ? "33" :
81 (pci1_speed
== 66000000) ? "66" : "unknown",
82 pci1_clk_sel
? "sync" : "async"
86 printf(" PCI2: 32 bit, 66 MHz, %s\n",
87 pci2_clk_sel
? "sync" : "async"
90 printf(" PCI2: disabled\n");
94 * Initialize local bus.
103 initdram(int board_type
)
106 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
108 puts("Initializing\n");
110 #if defined(CONFIG_DDR_DLL)
113 * Work around to stabilize DDR DLL MSYNC_IN.
114 * Errata DDR9 seems to have been fixed.
115 * This is now the workaround for Errata DDR11:
116 * Override DLL = 1, Course Adj = 1, Tap Select = 0
119 volatile ccsr_gur_t
*gur
= &immap
->im_gur
;
121 gur
->ddrdllcr
= 0x81000000;
122 asm("sync;isync;msync");
127 dram_size
= spd_sdram();
130 #if defined(CONFIG_DDR_ECC)
132 * Initialize and enable DDR ECC.
134 ddr_enable_ecc(dram_size
);
139 * SDRAM Initialization
149 * Initialize Local Bus
155 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
156 volatile ccsr_gur_t
*gur
= &immap
->im_gur
;
157 volatile ccsr_lbc_t
*lbc
= &immap
->im_lbc
;
166 * Fix Local Bus clock glitch when DLL is enabled.
168 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
169 * If localbus freq is > 133Mhz, DLL can be safely enabled.
170 * Between 66 and 133, the DLL is enabled with an override workaround.
173 get_sys_info(&sysinfo
);
174 clkdiv
= lbc
->lcrr
& 0x0f;
175 lbc_hz
= sysinfo
.freqSystemBus
/ 1000000 / clkdiv
;
178 lbc
->lcrr
|= 0x80000000; /* DLL Bypass */
180 } else if (lbc_hz
>= 133) {
181 lbc
->lcrr
&= (~0x80000000); /* DLL Enabled */
184 lbc
->lcrr
&= (~0x8000000); /* DLL Enabled */
188 * Sample LBC DLL ctrl reg, upshift it to set the
191 temp_lbcdll
= gur
->lbcdllcr
;
192 gur
->lbcdllcr
= (((temp_lbcdll
& 0xff) << 16) | 0x80000000);
193 asm("sync;isync;msync");
199 * Initialize SDRAM memory on the Local Bus.
205 #if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
208 volatile immap_t
*immap
= (immap_t
*)CFG_IMMR
;
209 volatile ccsr_lbc_t
*lbc
= &immap
->im_lbc
;
210 uint
*sdram_addr
= (uint
*)CFG_LBC_SDRAM_BASE
;
216 print_size (CFG_LBC_SDRAM_SIZE
* 1024 * 1024, "\n");
219 * Setup SDRAM Base and Option Registers
221 lbc
->or2
= CFG_OR2_PRELIM
;
224 lbc
->br2
= CFG_BR2_PRELIM
;
227 lbc
->lbcr
= CFG_LBC_LBCR
;
231 lbc
->lsrt
= CFG_LBC_LSRT
;
232 lbc
->mrtpr
= CFG_LBC_MRTPR
;
236 * Determine which address lines to use baed on CPU board rev.
238 cpu_board_rev
= get_cpu_board_revision();
239 lsdmr_common
= CFG_LBC_LSDMR_COMMON
;
240 if (cpu_board_rev
== MPC85XX_CPU_BOARD_REV_1_0
) {
241 lsdmr_common
|= CFG_LBC_LSDMR_BSMA1617
;
242 } else if (cpu_board_rev
== MPC85XX_CPU_BOARD_REV_1_1
) {
243 lsdmr_common
|= CFG_LBC_LSDMR_BSMA1516
;
246 * Assume something unable to identify itself is
247 * really old, and likely has lines 16/17 mapped.
249 lsdmr_common
|= CFG_LBC_LSDMR_BSMA1617
;
253 * Issue PRECHARGE ALL command.
255 lbc
->lsdmr
= lsdmr_common
| CFG_LBC_LSDMR_OP_PCHALL
;
258 ppcDcbf((unsigned long) sdram_addr
);
262 * Issue 8 AUTO REFRESH commands.
264 for (idx
= 0; idx
< 8; idx
++) {
265 lbc
->lsdmr
= lsdmr_common
| CFG_LBC_LSDMR_OP_ARFRSH
;
268 ppcDcbf((unsigned long) sdram_addr
);
273 * Issue 8 MODE-set command.
275 lbc
->lsdmr
= lsdmr_common
| CFG_LBC_LSDMR_OP_MRW
;
278 ppcDcbf((unsigned long) sdram_addr
);
282 * Issue NORMAL OP command.
284 lbc
->lsdmr
= lsdmr_common
| CFG_LBC_LSDMR_OP_NORMAL
;
287 ppcDcbf((unsigned long) sdram_addr
);
288 udelay(200); /* Overkill. Must wait > 200 bus cycles */
290 #endif /* enable SDRAM init */
294 #if defined(CFG_DRAM_TEST)
298 uint
*pstart
= (uint
*) CFG_MEMTEST_START
;
299 uint
*pend
= (uint
*) CFG_MEMTEST_END
;
302 printf("Testing DRAM from 0x%08x to 0x%08x\n",
306 printf("DRAM test phase 1:\n");
307 for (p
= pstart
; p
< pend
; p
++)
310 for (p
= pstart
; p
< pend
; p
++) {
311 if (*p
!= 0xaaaaaaaa) {
312 printf ("DRAM test fails at: %08x\n", (uint
) p
);
317 printf("DRAM test phase 2:\n");
318 for (p
= pstart
; p
< pend
; p
++)
321 for (p
= pstart
; p
< pend
; p
++) {
322 if (*p
!= 0x55555555) {
323 printf ("DRAM test fails at: %08x\n", (uint
) p
);
328 printf("DRAM test passed.\n");
335 #if defined(CONFIG_PCI)
338 * Initialize PCI Devices, report devices found.
341 #ifndef CONFIG_PCI_PNP
342 static struct pci_config_table pci_mpc85xxcds_config_table
[] = {
343 { PCI_ANY_ID
, PCI_ANY_ID
, PCI_ANY_ID
, PCI_ANY_ID
,
344 PCI_IDSEL_NUMBER
, PCI_ANY_ID
,
345 pci_cfgfunc_config_device
, { PCI_ENET0_IOADDR
,
347 PCI_COMMAND_MEMORY
| PCI_COMMAND_MASTER
354 static struct pci_controller hose
= {
355 #ifndef CONFIG_PCI_PNP
356 config_table
: pci_mpc85xxcds_config_table
,
360 #endif /* CONFIG_PCI */
367 extern void pci_mpc85xx_init(struct pci_controller
*hose
);
369 pci_mpc85xx_init(&hose
);