blob: 01b03866e8b607b71ca8dd9a0c8422700556ab2c [file] [log] [blame]
wdenka445ddf2004-06-09 00:34:46 +00001 /*
wdenk13eb2212004-07-09 23:27:13 +00002 * Copyright 2004 Freescale Semiconductor.
wdenk9c53f402003-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
wdenk9c53f402003-10-15 23:53:47 +000028#include <common.h>
wdenk492b9e72004-08-01 23:02:45 +000029#include <pci.h>
wdenk9c53f402003-10-15 23:53:47 +000030#include <asm/processor.h>
31#include <asm/immap_85xx.h>
32#include <spd.h>
33
wdenka445ddf2004-06-09 00:34:46 +000034#if defined(CONFIG_DDR_ECC)
wdenk13eb2212004-07-09 23:27:13 +000035extern void ddr_enable_ecc(unsigned int dram_size);
wdenka445ddf2004-06-09 00:34:46 +000036#endif
37
wdenk13eb2212004-07-09 23:27:13 +000038extern long int spd_sdram(void);
wdenka445ddf2004-06-09 00:34:46 +000039
wdenk492b9e72004-08-01 23:02:45 +000040void local_bus_init(void);
wdenk13eb2212004-07-09 23:27:13 +000041void sdram_init(void);
42long int fixed_sdram(void);
43
wdenk9c53f402003-10-15 23:53:47 +000044
wdenkda55c6e2004-01-20 23:12:12 +000045int board_early_init_f (void)
wdenk9c53f402003-10-15 23:53:47 +000046{
wdenk492b9e72004-08-01 23:02:45 +000047 return 0;
wdenk9c53f402003-10-15 23:53:47 +000048}
49
50int checkboard (void)
51{
wdenka445ddf2004-06-09 00:34:46 +000052 puts("Board: ADS\n");
wdenk13eb2212004-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
wdenk492b9e72004-08-01 23:02:45 +000061 /*
62 * Initialize local bus.
63 */
64 local_bus_init();
65
wdenka445ddf2004-06-09 00:34:46 +000066 return 0;
wdenk9c53f402003-10-15 23:53:47 +000067}
68
wdenka445ddf2004-06-09 00:34:46 +000069
wdenk13eb2212004-07-09 23:27:13 +000070long int
71initdram(int board_type)
wdenk9c53f402003-10-15 23:53:47 +000072{
73 long dram_size = 0;
74 extern long spd_sdram (void);
75 volatile immap_t *immap = (immap_t *)CFG_IMMR;
wdenk13eb2212004-07-09 23:27:13 +000076
77 puts("Initializing\n");
wdenka445ddf2004-06-09 00:34:46 +000078
wdenk9c53f402003-10-15 23:53:47 +000079#if defined(CONFIG_DDR_DLL)
wdenk13eb2212004-07-09 23:27:13 +000080 {
wdenk492b9e72004-08-01 23:02:45 +000081 volatile ccsr_gur_t *gur= &immap->im_gur;
82 uint temp_ddrdll = 0;
wdenk9c53f402003-10-15 23:53:47 +000083
wdenk492b9e72004-08-01 23:02:45 +000084 /*
85 * Work around to stabilize DDR DLL
86 */
87 temp_ddrdll = gur->ddrdllcr;
88 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
89 asm("sync;isync;msync");
wdenk13eb2212004-07-09 23:27:13 +000090 }
wdenk9c53f402003-10-15 23:53:47 +000091#endif
92
93#if defined(CONFIG_SPD_EEPROM)
94 dram_size = spd_sdram ();
95#else
96 dram_size = fixed_sdram ();
97#endif
98
wdenk13eb2212004-07-09 23:27:13 +000099#if defined(CONFIG_DDR_ECC)
100 /*
101 * Initialize and enable DDR ECC.
102 */
103 ddr_enable_ecc(dram_size);
104#endif
105
106 /*
107 * Initialize SDRAM.
108 */
109 sdram_init();
110
111 puts(" DDR: ");
112 return dram_size;
113}
114
115
116/*
wdenk492b9e72004-08-01 23:02:45 +0000117 * Initialize Local Bus
wdenk13eb2212004-07-09 23:27:13 +0000118 */
119
wdenk492b9e72004-08-01 23:02:45 +0000120void
121local_bus_init(void)
wdenk13eb2212004-07-09 23:27:13 +0000122{
wdenk492b9e72004-08-01 23:02:45 +0000123 volatile immap_t *immap = (immap_t *)CFG_IMMR;
124 volatile ccsr_gur_t *gur = &immap->im_gur;
wdenk13eb2212004-07-09 23:27:13 +0000125 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
wdenk13eb2212004-07-09 23:27:13 +0000126
wdenk492b9e72004-08-01 23:02:45 +0000127 uint clkdiv;
128 uint lbc_hz;
129 sys_info_t sysinfo;
wdenk13eb2212004-07-09 23:27:13 +0000130
131 /*
wdenk492b9e72004-08-01 23:02:45 +0000132 * Errata LBC11.
133 * Fix Local Bus clock glitch when DLL is enabled.
wdenk13eb2212004-07-09 23:27:13 +0000134 *
wdenk492b9e72004-08-01 23:02:45 +0000135 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
136 * If localbus freq is > 133Mhz, DLL can be safely enabled.
137 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk13eb2212004-07-09 23:27:13 +0000138 */
wdenk492b9e72004-08-01 23:02:45 +0000139
140 get_sys_info(&sysinfo);
141 clkdiv = lbc->lcrr & 0x0f;
142 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
143
144 if (lbc_hz < 66) {
145 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
146
147 } else if (lbc_hz >= 133) {
148 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk13eb2212004-07-09 23:27:13 +0000149
wdenk9c53f402003-10-15 23:53:47 +0000150 } else {
wdenk13eb2212004-07-09 23:27:13 +0000151 /*
152 * On REV1 boards, need to change CLKDIV before enable DLL.
153 * Default CLKDIV is 8, change it to 4 temporarily.
154 */
wdenk492b9e72004-08-01 23:02:45 +0000155 uint pvr = get_pvr();
wdenk13eb2212004-07-09 23:27:13 +0000156 uint temp_lbcdll = 0;
wdenka445ddf2004-06-09 00:34:46 +0000157
158 if (pvr == PVR_85xx_REV1) {
wdenk492b9e72004-08-01 23:02:45 +0000159 /* FIXME: Justify the high bit here. */
wdenk13eb2212004-07-09 23:27:13 +0000160 lbc->lcrr = 0x10000004;
wdenka445ddf2004-06-09 00:34:46 +0000161 }
wdenk13eb2212004-07-09 23:27:13 +0000162
wdenk492b9e72004-08-01 23:02:45 +0000163 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
164 udelay(200);
165
166 /*
167 * Sample LBC DLL ctrl reg, upshift it to set the
168 * override bits.
169 */
wdenk9c53f402003-10-15 23:53:47 +0000170 temp_lbcdll = gur->lbcdllcr;
wdenk492b9e72004-08-01 23:02:45 +0000171 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
172 asm("sync;isync;msync");
wdenk9c53f402003-10-15 23:53:47 +0000173 }
wdenk492b9e72004-08-01 23:02:45 +0000174}
175
176
177/*
178 * Initialize SDRAM memory on the Local Bus.
179 */
180
181void
182sdram_init(void)
183{
184 volatile immap_t *immap = (immap_t *)CFG_IMMR;
185 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
186 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
187
188 puts(" SDRAM: ");
189 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk13eb2212004-07-09 23:27:13 +0000190
191 /*
192 * Setup SDRAM Base and Option Registers
193 */
194 lbc->or2 = CFG_OR2_PRELIM;
wdenk9c53f402003-10-15 23:53:47 +0000195 lbc->br2 = CFG_BR2_PRELIM;
196 lbc->lbcr = CFG_LBC_LBCR;
wdenk492b9e72004-08-01 23:02:45 +0000197 asm("msync");
wdenk13eb2212004-07-09 23:27:13 +0000198
wdenk9c53f402003-10-15 23:53:47 +0000199 lbc->lsrt = CFG_LBC_LSRT;
wdenk9c53f402003-10-15 23:53:47 +0000200 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk492b9e72004-08-01 23:02:45 +0000201 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000202
wdenk13eb2212004-07-09 23:27:13 +0000203 /*
204 * Configure the SDRAM controller.
205 */
206 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk492b9e72004-08-01 23:02:45 +0000207 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000208 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000209 ppcDcbf((unsigned long) sdram_addr);
210 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000211
wdenk13eb2212004-07-09 23:27:13 +0000212 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk492b9e72004-08-01 23:02:45 +0000213 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000214 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000215 ppcDcbf((unsigned long) sdram_addr);
216 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000217
wdenk13eb2212004-07-09 23:27:13 +0000218 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk492b9e72004-08-01 23:02:45 +0000219 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000220 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000221 ppcDcbf((unsigned long) sdram_addr);
222 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000223
wdenk13eb2212004-07-09 23:27:13 +0000224 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk492b9e72004-08-01 23:02:45 +0000225 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000226 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000227 ppcDcbf((unsigned long) sdram_addr);
228 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000229
wdenk13eb2212004-07-09 23:27:13 +0000230 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk492b9e72004-08-01 23:02:45 +0000231 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000232 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000233 ppcDcbf((unsigned long) sdram_addr);
234 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000235}
236
237
238#if defined(CFG_DRAM_TEST)
239int testdram (void)
240{
241 uint *pstart = (uint *) CFG_MEMTEST_START;
242 uint *pend = (uint *) CFG_MEMTEST_END;
243 uint *p;
244
245 printf("SDRAM test phase 1:\n");
246 for (p = pstart; p < pend; p++)
247 *p = 0xaaaaaaaa;
248
249 for (p = pstart; p < pend; p++) {
250 if (*p != 0xaaaaaaaa) {
251 printf ("SDRAM test fails at: %08x\n", (uint) p);
252 return 1;
253 }
254 }
255
256 printf("SDRAM test phase 2:\n");
257 for (p = pstart; p < pend; p++)
258 *p = 0x55555555;
259
260 for (p = pstart; p < pend; p++) {
261 if (*p != 0x55555555) {
262 printf ("SDRAM test fails at: %08x\n", (uint) p);
263 return 1;
264 }
265 }
266
267 printf("SDRAM test passed.\n");
268 return 0;
269}
270#endif
271
272
273#if !defined(CONFIG_SPD_EEPROM)
274/*************************************************************************
275 * fixed sdram init -- doesn't use serial presence detect.
276 ************************************************************************/
277long int fixed_sdram (void)
278{
279 #ifndef CFG_RAMBOOT
280 volatile immap_t *immap = (immap_t *)CFG_IMMR;
281 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
282
283 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
284 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
285 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
286 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
287 ddr->sdram_mode = CFG_DDR_MODE;
288 ddr->sdram_interval = CFG_DDR_INTERVAL;
289 #if defined (CONFIG_DDR_ECC)
290 ddr->err_disable = 0x0000000D;
291 ddr->err_sbe = 0x00ff0000;
292 #endif
293 asm("sync;isync;msync");
294 udelay(500);
295 #if defined (CONFIG_DDR_ECC)
296 /* Enable ECC checking */
297 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
298 #else
299 ddr->sdram_cfg = CFG_DDR_CONTROL;
300 #endif
301 asm("sync; isync; msync");
302 udelay(500);
303 #endif
wdenk13eb2212004-07-09 23:27:13 +0000304 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk9c53f402003-10-15 23:53:47 +0000305}
306#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk492b9e72004-08-01 23:02:45 +0000307
308
309#if defined(CONFIG_PCI)
310/*
311 * Initialize PCI Devices, report devices found.
312 */
313
314#ifndef CONFIG_PCI_PNP
315static struct pci_config_table pci_mpc85xxads_config_table[] = {
316 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
317 PCI_IDSEL_NUMBER, PCI_ANY_ID,
318 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
319 PCI_ENET0_MEMADDR,
320 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
321 } },
322 { }
323};
324#endif
325
326
327static struct pci_controller hose = {
328#ifndef CONFIG_PCI_PNP
329 config_table: pci_mpc85xxads_config_table,
330#endif
331};
332
333#endif /* CONFIG_PCI */
334
335
336void
337pci_init_board(void)
338{
339#ifdef CONFIG_PCI
340 extern void pci_mpc85xx_init(struct pci_controller *hose);
341
342 pci_mpc85xx_init(&hose);
343#endif /* CONFIG_PCI */
344}