blob: b824b3dc1f0ca119414408a90890ad2c5826a0c2 [file] [log] [blame]
wdenk03f5c552004-10-10 21:21:55 +00001/*
2 * Copyright 2004 Freescale Semiconductor.
3 *
4 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
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.
13 *
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.
18 *
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,
22 * MA 02111-1307 USA
23 */
24
25
26#include <common.h>
27#include <pci.h>
28#include <asm/processor.h>
29#include <asm/immap_85xx.h>
30#include <spd.h>
31
32#include "../common/cadmus.h"
33#include "../common/eeprom.h"
34
35#if defined(CONFIG_DDR_ECC)
36extern void ddr_enable_ecc(unsigned int dram_size);
37#endif
38
39extern long int spd_sdram(void);
40
41void local_bus_init(void);
42void sdram_init(void);
43
44
45
46int
47board_early_init_f(void)
48{
49 return 0;
50}
51
52
53int
54checkboard(void)
55{
56 volatile immap_t *immap = (immap_t *)CFG_CCSRBAR;
57 volatile ccsr_gur_t *gur = &immap->im_gur;
58
59 /* PCI slot in USER bits CSR[6:7] by convention. */
60 uint pci_slot = get_pci_slot();
61
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] */
66
67 uint pci1_speed = get_clock_freq(); /* PCI PSPEED in [4:5] */
68
69 uint cpu_board_rev = get_cpu_board_revision();
70
71 printf("Board: CDS Version 0x%02x, PCI Slot %d\n",
72 get_board_version(),
73 pci_slot);
74
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),
78 cpu_board_rev);
79
80 printf(" PCI1: %d bit, %s MHz, %s\n",
81 (pci1_32) ? 32 : 64,
82 (pci1_speed == 33000000) ? "33" :
83 (pci1_speed == 66000000) ? "66" : "unknown",
84 pci1_clk_sel ? "sync" : "async"
85 );
86
87 if (pci_dual) {
88 printf(" PCI2: 32 bit, 66 MHz, %s\n",
89 pci2_clk_sel ? "sync" : "async"
90 );
91 } else {
92 printf(" PCI2: disabled\n");
93 }
94
95 /*
96 * Initialize local bus.
97 */
98 local_bus_init();
99
100 return 0;
101}
102
103
104long int
105initdram(int board_type)
106{
107 long dram_size = 0;
108 volatile immap_t *immap = (immap_t *)CFG_IMMR;
109
110 puts("Initializing\n");
111
112#if defined(CONFIG_DDR_DLL)
113 {
114 /*
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
119 */
120
121 volatile ccsr_gur_t *gur= &immap->im_gur;
122
123 gur->ddrdllcr = 0x81000000;
124 asm("sync;isync;msync");
125 udelay(200);
126 }
127#endif
128
129 dram_size = spd_sdram();
130
131
132#if defined(CONFIG_DDR_ECC)
133 /*
134 * Initialize and enable DDR ECC.
135 */
136 ddr_enable_ecc(dram_size);
137#endif
138
139
140 /*
141 * SDRAM Initialization
142 */
143 sdram_init();
144
145 puts(" DDR: ");
146 return dram_size;
147}
148
149
150/*
151 * Initialize Local Bus
152 */
153
154void
155local_bus_init(void)
156{
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;
160
161 uint clkdiv;
162 uint lbc_hz;
163 sys_info_t sysinfo;
164 uint temp_lbcdll;
165
166 /*
167 * Errata LBC11.
168 * Fix Local Bus clock glitch when DLL is enabled.
169 *
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.
173 */
174
175 get_sys_info(&sysinfo);
176 clkdiv = lbc->lcrr & 0x0f;
177 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
178
179 if (lbc_hz < 66) {
180 lbc->lcrr |= 0x80000000; /* DLL Bypass */
181
182 } else if (lbc_hz >= 133) {
183 lbc->lcrr &= (~0x80000000); /* DLL Enabled */
184
185 } else {
186 lbc->lcrr &= (~0x8000000); /* DLL Enabled */
187 udelay(200);
188
189 /*
190 * Sample LBC DLL ctrl reg, upshift it to set the
191 * override bits.
192 */
193 temp_lbcdll = gur->lbcdllcr;
194 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
195 asm("sync;isync;msync");
196 }
197}
198
199
200/*
201 * Initialize SDRAM memory on the Local Bus.
202 */
203
204void
205sdram_init(void)
206{
207#if defined(CFG_OR2_PRELIM) && defined(CFG_BR2_PRELIM)
208
209 uint idx;
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;
213 uint cpu_board_rev;
214 uint lsdmr_common;
215
216 puts(" SDRAM: ");
217
218 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
219
220 /*
221 * Setup SDRAM Base and Option Registers
222 */
223 lbc->or2 = CFG_OR2_PRELIM;
224 asm("msync");
225
226 lbc->br2 = CFG_BR2_PRELIM;
227 asm("msync");
228
229 lbc->lbcr = CFG_LBC_LBCR;
230 asm("msync");
231
232
233 lbc->lsrt = CFG_LBC_LSRT;
234 lbc->mrtpr = CFG_LBC_MRTPR;
235 asm("msync");
236
237 /*
238 * Determine which address lines to use baed on CPU board rev.
239 */
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;
246 } else {
247 /*
248 * Assume something unable to identify itself is
249 * really old, and likely has lines 16/17 mapped.
250 */
251 lsdmr_common |= CFG_LBC_LSDMR_BSMA1617;
252 }
253
254 /*
255 * Issue PRECHARGE ALL command.
256 */
257 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_PCHALL;
258 asm("sync;msync");
259 *sdram_addr = 0xff;
260 ppcDcbf((unsigned long) sdram_addr);
261 udelay(100);
262
263 /*
264 * Issue 8 AUTO REFRESH commands.
265 */
266 for (idx = 0; idx < 8; idx++) {
267 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_ARFRSH;
268 asm("sync;msync");
269 *sdram_addr = 0xff;
270 ppcDcbf((unsigned long) sdram_addr);
271 udelay(100);
272 }
273
274 /*
275 * Issue 8 MODE-set command.
276 */
277 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_MRW;
278 asm("sync;msync");
279 *sdram_addr = 0xff;
280 ppcDcbf((unsigned long) sdram_addr);
281 udelay(100);
282
283 /*
284 * Issue NORMAL OP command.
285 */
286 lbc->lsdmr = lsdmr_common | CFG_LBC_LSDMR_OP_NORMAL;
287 asm("sync;msync");
288 *sdram_addr = 0xff;
289 ppcDcbf((unsigned long) sdram_addr);
290 udelay(200); /* Overkill. Must wait > 200 bus cycles */
291
292#endif /* enable SDRAM init */
293}
294
295
296#if defined(CFG_DRAM_TEST)
297int
298testdram(void)
299{
300 uint *pstart = (uint *) CFG_MEMTEST_START;
301 uint *pend = (uint *) CFG_MEMTEST_END;
302 uint *p;
303
304 printf("Testing DRAM from 0x%08x to 0x%08x\n",
305 CFG_MEMTEST_START,
306 CFG_MEMTEST_END);
307
308 printf("DRAM test phase 1:\n");
309 for (p = pstart; p < pend; p++)
310 *p = 0xaaaaaaaa;
311
312 for (p = pstart; p < pend; p++) {
313 if (*p != 0xaaaaaaaa) {
314 printf ("DRAM test fails at: %08x\n", (uint) p);
315 return 1;
316 }
317 }
318
319 printf("DRAM test phase 2:\n");
320 for (p = pstart; p < pend; p++)
321 *p = 0x55555555;
322
323 for (p = pstart; p < pend; p++) {
324 if (*p != 0x55555555) {
325 printf ("DRAM test fails at: %08x\n", (uint) p);
326 return 1;
327 }
328 }
329
330 printf("DRAM test passed.\n");
331 return 0;
332}
333#endif
334
335
336
337#if defined(CONFIG_PCI)
338
339/*
340 * Initialize PCI Devices, report devices found.
341 */
342
343#ifndef CONFIG_PCI_PNP
344static 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,
348 PCI_ENET0_MEMADDR,
349 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
350 } },
351 { }
352};
353#endif
354
355
356static struct pci_controller hose = {
357#ifndef CONFIG_PCI_PNP
358 config_table: pci_mpc85xxcds_config_table,
359#endif
360};
361
362#endif /* CONFIG_PCI */
363
364
365void
366pci_init_board(void)
367{
368#ifdef CONFIG_PCI
369 extern void pci_mpc85xx_init(struct pci_controller *hose);
370
371 pci_mpc85xx_init(&hose);
372#endif
373}