blob: a951b9e9a32514c8b2f40da9c4cebd397b0cce1b [file] [log] [blame]
wdenk97d80fc2004-06-09 00:34:46 +00001 /*
wdenk0ac6f8b2004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk42d1f032003-10-15 23:53:47 +00003 * (C) Copyright 2002,2003, Motorola Inc.
4 * Xianghua Xiao, (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2002 Scott McNutt <smcnutt@artesyncp.com>
7 *
8 * See file CREDITS for list of people who contributed to this
9 * project.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 * MA 02111-1307 USA
25 */
26
27
wdenk42d1f032003-10-15 23:53:47 +000028#include <common.h>
wdenk9aea9532004-08-01 23:02:45 +000029#include <pci.h>
wdenk42d1f032003-10-15 23:53:47 +000030#include <asm/processor.h>
31#include <asm/immap_85xx.h>
Jon Loeligera30a5492008-03-04 10:03:03 -060032#include <spd_sdram.h>
Kumar Gala0fd5ec62007-11-28 22:54:27 -060033#include <libfdt.h>
34#include <fdt_support.h>
Matthew McClintock40d5fa32006-06-28 10:43:36 -050035
Jon Loeligerd9b94f22005-07-25 14:05:07 -050036#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000037extern void ddr_enable_ecc(unsigned int dram_size);
wdenk97d80fc2004-06-09 00:34:46 +000038#endif
39
wdenk9aea9532004-08-01 23:02:45 +000040void local_bus_init(void);
wdenk0ac6f8b2004-07-09 23:27:13 +000041void sdram_init(void);
42long int fixed_sdram(void);
43
wdenk42d1f032003-10-15 23:53:47 +000044
wdenkc837dcb2004-01-20 23:12:12 +000045int board_early_init_f (void)
wdenk42d1f032003-10-15 23:53:47 +000046{
wdenk9aea9532004-08-01 23:02:45 +000047 return 0;
wdenk42d1f032003-10-15 23:53:47 +000048}
49
50int checkboard (void)
51{
wdenk97d80fc2004-06-09 00:34:46 +000052 puts("Board: ADS\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000053
54#ifdef CONFIG_PCI
55 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
56 CONFIG_SYS_CLK_FREQ / 1000000);
57#else
58 printf(" PCI1: disabled\n");
59#endif
60
wdenk9aea9532004-08-01 23:02:45 +000061 /*
62 * Initialize local bus.
63 */
64 local_bus_init();
65
wdenk97d80fc2004-06-09 00:34:46 +000066 return 0;
wdenk42d1f032003-10-15 23:53:47 +000067}
68
wdenk97d80fc2004-06-09 00:34:46 +000069
wdenk0ac6f8b2004-07-09 23:27:13 +000070long int
71initdram(int board_type)
wdenk42d1f032003-10-15 23:53:47 +000072{
73 long dram_size = 0;
wdenk0ac6f8b2004-07-09 23:27:13 +000074
75 puts("Initializing\n");
wdenk97d80fc2004-06-09 00:34:46 +000076
wdenk42d1f032003-10-15 23:53:47 +000077#if defined(CONFIG_DDR_DLL)
wdenk0ac6f8b2004-07-09 23:27:13 +000078 {
Kumar Galaf59b55a2007-11-27 23:25:02 -060079 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk9aea9532004-08-01 23:02:45 +000080 uint temp_ddrdll = 0;
wdenk42d1f032003-10-15 23:53:47 +000081
wdenk9aea9532004-08-01 23:02:45 +000082 /*
83 * Work around to stabilize DDR DLL
84 */
85 temp_ddrdll = gur->ddrdllcr;
86 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
87 asm("sync;isync;msync");
wdenk0ac6f8b2004-07-09 23:27:13 +000088 }
wdenk42d1f032003-10-15 23:53:47 +000089#endif
90
91#if defined(CONFIG_SPD_EEPROM)
92 dram_size = spd_sdram ();
93#else
94 dram_size = fixed_sdram ();
95#endif
96
Jon Loeligerd9b94f22005-07-25 14:05:07 -050097#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +000098 /*
99 * Initialize and enable DDR ECC.
100 */
101 ddr_enable_ecc(dram_size);
102#endif
103
104 /*
105 * Initialize SDRAM.
106 */
107 sdram_init();
108
109 puts(" DDR: ");
110 return dram_size;
111}
112
113
114/*
wdenk9aea9532004-08-01 23:02:45 +0000115 * Initialize Local Bus
wdenk0ac6f8b2004-07-09 23:27:13 +0000116 */
117
wdenk9aea9532004-08-01 23:02:45 +0000118void
119local_bus_init(void)
wdenk0ac6f8b2004-07-09 23:27:13 +0000120{
Kumar Galaf59b55a2007-11-27 23:25:02 -0600121 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
Kumar Gala04db4002007-11-29 02:10:09 -0600122 volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
wdenk0ac6f8b2004-07-09 23:27:13 +0000123
wdenk9aea9532004-08-01 23:02:45 +0000124 uint clkdiv;
125 uint lbc_hz;
126 sys_info_t sysinfo;
wdenk0ac6f8b2004-07-09 23:27:13 +0000127
128 /*
wdenk9aea9532004-08-01 23:02:45 +0000129 * Errata LBC11.
130 * Fix Local Bus clock glitch when DLL is enabled.
wdenk0ac6f8b2004-07-09 23:27:13 +0000131 *
wdenk9aea9532004-08-01 23:02:45 +0000132 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
133 * If localbus freq is > 133Mhz, DLL can be safely enabled.
134 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk0ac6f8b2004-07-09 23:27:13 +0000135 */
wdenk9aea9532004-08-01 23:02:45 +0000136
137 get_sys_info(&sysinfo);
138 clkdiv = lbc->lcrr & 0x0f;
139 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
140
141 if (lbc_hz < 66) {
142 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
143
144 } else if (lbc_hz >= 133) {
145 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk0ac6f8b2004-07-09 23:27:13 +0000146
wdenk42d1f032003-10-15 23:53:47 +0000147 } else {
wdenk0ac6f8b2004-07-09 23:27:13 +0000148 /*
149 * On REV1 boards, need to change CLKDIV before enable DLL.
150 * Default CLKDIV is 8, change it to 4 temporarily.
151 */
wdenk9aea9532004-08-01 23:02:45 +0000152 uint pvr = get_pvr();
wdenk0ac6f8b2004-07-09 23:27:13 +0000153 uint temp_lbcdll = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000154
155 if (pvr == PVR_85xx_REV1) {
wdenk9aea9532004-08-01 23:02:45 +0000156 /* FIXME: Justify the high bit here. */
wdenk0ac6f8b2004-07-09 23:27:13 +0000157 lbc->lcrr = 0x10000004;
wdenk97d80fc2004-06-09 00:34:46 +0000158 }
wdenk0ac6f8b2004-07-09 23:27:13 +0000159
wdenk9aea9532004-08-01 23:02:45 +0000160 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
161 udelay(200);
162
163 /*
164 * Sample LBC DLL ctrl reg, upshift it to set the
165 * override bits.
166 */
wdenk42d1f032003-10-15 23:53:47 +0000167 temp_lbcdll = gur->lbcdllcr;
wdenk9aea9532004-08-01 23:02:45 +0000168 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
169 asm("sync;isync;msync");
wdenk42d1f032003-10-15 23:53:47 +0000170 }
wdenk9aea9532004-08-01 23:02:45 +0000171}
172
173
174/*
175 * Initialize SDRAM memory on the Local Bus.
176 */
177
178void
179sdram_init(void)
180{
Kumar Gala04db4002007-11-29 02:10:09 -0600181 volatile ccsr_lbc_t *lbc = (void *)(CFG_MPC85xx_LBC_ADDR);
wdenk9aea9532004-08-01 23:02:45 +0000182 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
183
184 puts(" SDRAM: ");
185 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk0ac6f8b2004-07-09 23:27:13 +0000186
187 /*
188 * Setup SDRAM Base and Option Registers
189 */
190 lbc->or2 = CFG_OR2_PRELIM;
wdenk42d1f032003-10-15 23:53:47 +0000191 lbc->br2 = CFG_BR2_PRELIM;
192 lbc->lbcr = CFG_LBC_LBCR;
wdenk9aea9532004-08-01 23:02:45 +0000193 asm("msync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000194
wdenk42d1f032003-10-15 23:53:47 +0000195 lbc->lsrt = CFG_LBC_LSRT;
wdenk42d1f032003-10-15 23:53:47 +0000196 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk9aea9532004-08-01 23:02:45 +0000197 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000198
199 /*
200 * Configure the SDRAM controller.
201 */
202 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk9aea9532004-08-01 23:02:45 +0000203 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000204 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000205 ppcDcbf((unsigned long) sdram_addr);
206 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000207
208 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk9aea9532004-08-01 23:02:45 +0000209 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000210 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000211 ppcDcbf((unsigned long) sdram_addr);
212 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000213
214 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk9aea9532004-08-01 23:02:45 +0000215 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000216 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000217 ppcDcbf((unsigned long) sdram_addr);
218 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000219
220 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk9aea9532004-08-01 23:02:45 +0000221 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000222 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000223 ppcDcbf((unsigned long) sdram_addr);
224 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000225
226 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk9aea9532004-08-01 23:02:45 +0000227 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000228 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000229 ppcDcbf((unsigned long) sdram_addr);
230 udelay(100);
wdenk42d1f032003-10-15 23:53:47 +0000231}
232
233
234#if defined(CFG_DRAM_TEST)
235int testdram (void)
236{
237 uint *pstart = (uint *) CFG_MEMTEST_START;
238 uint *pend = (uint *) CFG_MEMTEST_END;
239 uint *p;
240
241 printf("SDRAM test phase 1:\n");
242 for (p = pstart; p < pend; p++)
243 *p = 0xaaaaaaaa;
244
245 for (p = pstart; p < pend; p++) {
246 if (*p != 0xaaaaaaaa) {
247 printf ("SDRAM test fails at: %08x\n", (uint) p);
248 return 1;
249 }
250 }
251
252 printf("SDRAM test phase 2:\n");
253 for (p = pstart; p < pend; p++)
254 *p = 0x55555555;
255
256 for (p = pstart; p < pend; p++) {
257 if (*p != 0x55555555) {
258 printf ("SDRAM test fails at: %08x\n", (uint) p);
259 return 1;
260 }
261 }
262
263 printf("SDRAM test passed.\n");
264 return 0;
265}
266#endif
267
268
269#if !defined(CONFIG_SPD_EEPROM)
270/*************************************************************************
271 * fixed sdram init -- doesn't use serial presence detect.
272 ************************************************************************/
273long int fixed_sdram (void)
274{
275 #ifndef CFG_RAMBOOT
Kumar Gala04db4002007-11-29 02:10:09 -0600276 volatile ccsr_ddr_t *ddr= (void *)(CFG_MPC85xx_DDR_ADDR);
wdenk42d1f032003-10-15 23:53:47 +0000277
278 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
279 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
280 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
281 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
282 ddr->sdram_mode = CFG_DDR_MODE;
283 ddr->sdram_interval = CFG_DDR_INTERVAL;
284 #if defined (CONFIG_DDR_ECC)
285 ddr->err_disable = 0x0000000D;
286 ddr->err_sbe = 0x00ff0000;
287 #endif
288 asm("sync;isync;msync");
289 udelay(500);
290 #if defined (CONFIG_DDR_ECC)
291 /* Enable ECC checking */
292 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
293 #else
294 ddr->sdram_cfg = CFG_DDR_CONTROL;
295 #endif
296 asm("sync; isync; msync");
297 udelay(500);
298 #endif
wdenk0ac6f8b2004-07-09 23:27:13 +0000299 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk42d1f032003-10-15 23:53:47 +0000300}
301#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk9aea9532004-08-01 23:02:45 +0000302
303
304#if defined(CONFIG_PCI)
305/*
306 * Initialize PCI Devices, report devices found.
307 */
308
wdenk9aea9532004-08-01 23:02:45 +0000309
Matthew McClintock52c7a682006-06-28 10:45:41 -0500310static struct pci_controller hose;
wdenk9aea9532004-08-01 23:02:45 +0000311
312#endif /* CONFIG_PCI */
313
314
315void
316pci_init_board(void)
317{
318#ifdef CONFIG_PCI
wdenk9aea9532004-08-01 23:02:45 +0000319 pci_mpc85xx_init(&hose);
320#endif /* CONFIG_PCI */
321}
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500322
323
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600324#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500325void
326ft_board_setup(void *blob, bd_t *bd)
327{
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600328 int node, tmp[2];
329 const char *path;
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500330
331 ft_cpu_setup(blob, bd);
332
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600333 node = fdt_path_offset(blob, "/aliases");
334 tmp[0] = 0;
335 if (node >= 0) {
336#ifdef CONFIG_PCI
337 path = fdt_getprop(blob, node, "pci0", NULL);
338 if (path) {
339 tmp[1] = hose.last_busno - hose.first_busno;
340 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
341 }
342#endif
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500343 }
344}
345#endif