blob: 4e7f8565183395b4f03fa4a8efbffb05447077bc [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>
32#include <spd.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
wdenk0ac6f8b2004-07-09 23:27:13 +000040extern long int spd_sdram(void);
wdenk97d80fc2004-06-09 00:34:46 +000041
wdenk9aea9532004-08-01 23:02:45 +000042void local_bus_init(void);
wdenk0ac6f8b2004-07-09 23:27:13 +000043void sdram_init(void);
44long int fixed_sdram(void);
45
wdenk42d1f032003-10-15 23:53:47 +000046
wdenkc837dcb2004-01-20 23:12:12 +000047int board_early_init_f (void)
wdenk42d1f032003-10-15 23:53:47 +000048{
wdenk9aea9532004-08-01 23:02:45 +000049 return 0;
wdenk42d1f032003-10-15 23:53:47 +000050}
51
52int checkboard (void)
53{
wdenk97d80fc2004-06-09 00:34:46 +000054 puts("Board: ADS\n");
wdenk0ac6f8b2004-07-09 23:27:13 +000055
56#ifdef CONFIG_PCI
57 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
58 CONFIG_SYS_CLK_FREQ / 1000000);
59#else
60 printf(" PCI1: disabled\n");
61#endif
62
wdenk9aea9532004-08-01 23:02:45 +000063 /*
64 * Initialize local bus.
65 */
66 local_bus_init();
67
wdenk97d80fc2004-06-09 00:34:46 +000068 return 0;
wdenk42d1f032003-10-15 23:53:47 +000069}
70
wdenk97d80fc2004-06-09 00:34:46 +000071
wdenk0ac6f8b2004-07-09 23:27:13 +000072long int
73initdram(int board_type)
wdenk42d1f032003-10-15 23:53:47 +000074{
75 long dram_size = 0;
76 extern long spd_sdram (void);
wdenk0ac6f8b2004-07-09 23:27:13 +000077
78 puts("Initializing\n");
wdenk97d80fc2004-06-09 00:34:46 +000079
wdenk42d1f032003-10-15 23:53:47 +000080#if defined(CONFIG_DDR_DLL)
wdenk0ac6f8b2004-07-09 23:27:13 +000081 {
Kumar Galaf59b55a2007-11-27 23:25:02 -060082 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk9aea9532004-08-01 23:02:45 +000083 uint temp_ddrdll = 0;
wdenk42d1f032003-10-15 23:53:47 +000084
wdenk9aea9532004-08-01 23:02:45 +000085 /*
86 * Work around to stabilize DDR DLL
87 */
88 temp_ddrdll = gur->ddrdllcr;
89 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
90 asm("sync;isync;msync");
wdenk0ac6f8b2004-07-09 23:27:13 +000091 }
wdenk42d1f032003-10-15 23:53:47 +000092#endif
93
94#if defined(CONFIG_SPD_EEPROM)
95 dram_size = spd_sdram ();
96#else
97 dram_size = fixed_sdram ();
98#endif
99
Jon Loeligerd9b94f22005-07-25 14:05:07 -0500100#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
wdenk0ac6f8b2004-07-09 23:27:13 +0000101 /*
102 * Initialize and enable DDR ECC.
103 */
104 ddr_enable_ecc(dram_size);
105#endif
106
107 /*
108 * Initialize SDRAM.
109 */
110 sdram_init();
111
112 puts(" DDR: ");
113 return dram_size;
114}
115
116
117/*
wdenk9aea9532004-08-01 23:02:45 +0000118 * Initialize Local Bus
wdenk0ac6f8b2004-07-09 23:27:13 +0000119 */
120
wdenk9aea9532004-08-01 23:02:45 +0000121void
122local_bus_init(void)
wdenk0ac6f8b2004-07-09 23:27:13 +0000123{
wdenk9aea9532004-08-01 23:02:45 +0000124 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Kumar Galaf59b55a2007-11-27 23:25:02 -0600125 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk0ac6f8b2004-07-09 23:27:13 +0000126 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
wdenk0ac6f8b2004-07-09 23:27:13 +0000127
wdenk9aea9532004-08-01 23:02:45 +0000128 uint clkdiv;
129 uint lbc_hz;
130 sys_info_t sysinfo;
wdenk0ac6f8b2004-07-09 23:27:13 +0000131
132 /*
wdenk9aea9532004-08-01 23:02:45 +0000133 * Errata LBC11.
134 * Fix Local Bus clock glitch when DLL is enabled.
wdenk0ac6f8b2004-07-09 23:27:13 +0000135 *
wdenk9aea9532004-08-01 23:02:45 +0000136 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
137 * If localbus freq is > 133Mhz, DLL can be safely enabled.
138 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk0ac6f8b2004-07-09 23:27:13 +0000139 */
wdenk9aea9532004-08-01 23:02:45 +0000140
141 get_sys_info(&sysinfo);
142 clkdiv = lbc->lcrr & 0x0f;
143 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
144
145 if (lbc_hz < 66) {
146 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
147
148 } else if (lbc_hz >= 133) {
149 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk0ac6f8b2004-07-09 23:27:13 +0000150
wdenk42d1f032003-10-15 23:53:47 +0000151 } else {
wdenk0ac6f8b2004-07-09 23:27:13 +0000152 /*
153 * On REV1 boards, need to change CLKDIV before enable DLL.
154 * Default CLKDIV is 8, change it to 4 temporarily.
155 */
wdenk9aea9532004-08-01 23:02:45 +0000156 uint pvr = get_pvr();
wdenk0ac6f8b2004-07-09 23:27:13 +0000157 uint temp_lbcdll = 0;
wdenk97d80fc2004-06-09 00:34:46 +0000158
159 if (pvr == PVR_85xx_REV1) {
wdenk9aea9532004-08-01 23:02:45 +0000160 /* FIXME: Justify the high bit here. */
wdenk0ac6f8b2004-07-09 23:27:13 +0000161 lbc->lcrr = 0x10000004;
wdenk97d80fc2004-06-09 00:34:46 +0000162 }
wdenk0ac6f8b2004-07-09 23:27:13 +0000163
wdenk9aea9532004-08-01 23:02:45 +0000164 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
165 udelay(200);
166
167 /*
168 * Sample LBC DLL ctrl reg, upshift it to set the
169 * override bits.
170 */
wdenk42d1f032003-10-15 23:53:47 +0000171 temp_lbcdll = gur->lbcdllcr;
wdenk9aea9532004-08-01 23:02:45 +0000172 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
173 asm("sync;isync;msync");
wdenk42d1f032003-10-15 23:53:47 +0000174 }
wdenk9aea9532004-08-01 23:02:45 +0000175}
176
177
178/*
179 * Initialize SDRAM memory on the Local Bus.
180 */
181
182void
183sdram_init(void)
184{
185 volatile immap_t *immap = (immap_t *)CFG_IMMR;
186 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
187 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
188
189 puts(" SDRAM: ");
190 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk0ac6f8b2004-07-09 23:27:13 +0000191
192 /*
193 * Setup SDRAM Base and Option Registers
194 */
195 lbc->or2 = CFG_OR2_PRELIM;
wdenk42d1f032003-10-15 23:53:47 +0000196 lbc->br2 = CFG_BR2_PRELIM;
197 lbc->lbcr = CFG_LBC_LBCR;
wdenk9aea9532004-08-01 23:02:45 +0000198 asm("msync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000199
wdenk42d1f032003-10-15 23:53:47 +0000200 lbc->lsrt = CFG_LBC_LSRT;
wdenk42d1f032003-10-15 23:53:47 +0000201 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk9aea9532004-08-01 23:02:45 +0000202 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000203
204 /*
205 * Configure the SDRAM controller.
206 */
207 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk9aea9532004-08-01 23:02:45 +0000208 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000209 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000210 ppcDcbf((unsigned long) sdram_addr);
211 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000212
213 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk9aea9532004-08-01 23:02:45 +0000214 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000215 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000216 ppcDcbf((unsigned long) sdram_addr);
217 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000218
219 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk9aea9532004-08-01 23:02:45 +0000220 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000221 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000222 ppcDcbf((unsigned long) sdram_addr);
223 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000224
225 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk9aea9532004-08-01 23:02:45 +0000226 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000227 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000228 ppcDcbf((unsigned long) sdram_addr);
229 udelay(100);
wdenk0ac6f8b2004-07-09 23:27:13 +0000230
231 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk9aea9532004-08-01 23:02:45 +0000232 asm("sync");
wdenk0ac6f8b2004-07-09 23:27:13 +0000233 *sdram_addr = 0xff;
wdenk9aea9532004-08-01 23:02:45 +0000234 ppcDcbf((unsigned long) sdram_addr);
235 udelay(100);
wdenk42d1f032003-10-15 23:53:47 +0000236}
237
238
239#if defined(CFG_DRAM_TEST)
240int testdram (void)
241{
242 uint *pstart = (uint *) CFG_MEMTEST_START;
243 uint *pend = (uint *) CFG_MEMTEST_END;
244 uint *p;
245
246 printf("SDRAM test phase 1:\n");
247 for (p = pstart; p < pend; p++)
248 *p = 0xaaaaaaaa;
249
250 for (p = pstart; p < pend; p++) {
251 if (*p != 0xaaaaaaaa) {
252 printf ("SDRAM test fails at: %08x\n", (uint) p);
253 return 1;
254 }
255 }
256
257 printf("SDRAM test phase 2:\n");
258 for (p = pstart; p < pend; p++)
259 *p = 0x55555555;
260
261 for (p = pstart; p < pend; p++) {
262 if (*p != 0x55555555) {
263 printf ("SDRAM test fails at: %08x\n", (uint) p);
264 return 1;
265 }
266 }
267
268 printf("SDRAM test passed.\n");
269 return 0;
270}
271#endif
272
273
274#if !defined(CONFIG_SPD_EEPROM)
275/*************************************************************************
276 * fixed sdram init -- doesn't use serial presence detect.
277 ************************************************************************/
278long int fixed_sdram (void)
279{
280 #ifndef CFG_RAMBOOT
281 volatile immap_t *immap = (immap_t *)CFG_IMMR;
282 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
283
284 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
285 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
286 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
287 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
288 ddr->sdram_mode = CFG_DDR_MODE;
289 ddr->sdram_interval = CFG_DDR_INTERVAL;
290 #if defined (CONFIG_DDR_ECC)
291 ddr->err_disable = 0x0000000D;
292 ddr->err_sbe = 0x00ff0000;
293 #endif
294 asm("sync;isync;msync");
295 udelay(500);
296 #if defined (CONFIG_DDR_ECC)
297 /* Enable ECC checking */
298 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
299 #else
300 ddr->sdram_cfg = CFG_DDR_CONTROL;
301 #endif
302 asm("sync; isync; msync");
303 udelay(500);
304 #endif
wdenk0ac6f8b2004-07-09 23:27:13 +0000305 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk42d1f032003-10-15 23:53:47 +0000306}
307#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk9aea9532004-08-01 23:02:45 +0000308
309
310#if defined(CONFIG_PCI)
311/*
312 * Initialize PCI Devices, report devices found.
313 */
314
wdenk9aea9532004-08-01 23:02:45 +0000315
Matthew McClintock52c7a682006-06-28 10:45:41 -0500316static struct pci_controller hose;
wdenk9aea9532004-08-01 23:02:45 +0000317
318#endif /* CONFIG_PCI */
319
320
321void
322pci_init_board(void)
323{
324#ifdef CONFIG_PCI
wdenk9aea9532004-08-01 23:02:45 +0000325 pci_mpc85xx_init(&hose);
326#endif /* CONFIG_PCI */
327}
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500328
329
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600330#if defined(CONFIG_OF_BOARD_SETUP)
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500331void
332ft_board_setup(void *blob, bd_t *bd)
333{
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600334 int node, tmp[2];
335 const char *path;
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500336
337 ft_cpu_setup(blob, bd);
338
Kumar Gala0fd5ec62007-11-28 22:54:27 -0600339 node = fdt_path_offset(blob, "/aliases");
340 tmp[0] = 0;
341 if (node >= 0) {
342#ifdef CONFIG_PCI
343 path = fdt_getprop(blob, node, "pci0", NULL);
344 if (path) {
345 tmp[1] = hose.last_busno - hose.first_busno;
346 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
347 }
348#endif
Matthew McClintock40d5fa32006-06-28 10:43:36 -0500349 }
350}
351#endif