blob: c97e8ba15e15bf7f3080a1c8e9ddd11c2095c3ec [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{
47#if defined(CONFIG_PCI)
wdenk492b9e72004-08-01 23:02:45 +000048 volatile immap_t *immr = (immap_t *)CFG_IMMR;
49 volatile ccsr_pcix_t *pci = &immr->im_pcix;
wdenk9c53f402003-10-15 23:53:47 +000050
wdenk492b9e72004-08-01 23:02:45 +000051 pci->peer &= 0xffffffdf; /* disable master abort */
wdenk9c53f402003-10-15 23:53:47 +000052#endif
wdenk13eb2212004-07-09 23:27:13 +000053
wdenk492b9e72004-08-01 23:02:45 +000054 return 0;
wdenk9c53f402003-10-15 23:53:47 +000055}
56
57int checkboard (void)
58{
wdenka445ddf2004-06-09 00:34:46 +000059 puts("Board: ADS\n");
wdenk13eb2212004-07-09 23:27:13 +000060
61#ifdef CONFIG_PCI
62 printf(" PCI1: 32 bit, %d MHz (compiled)\n",
63 CONFIG_SYS_CLK_FREQ / 1000000);
64#else
65 printf(" PCI1: disabled\n");
66#endif
67
wdenk492b9e72004-08-01 23:02:45 +000068 /*
69 * Initialize local bus.
70 */
71 local_bus_init();
72
wdenka445ddf2004-06-09 00:34:46 +000073 return 0;
wdenk9c53f402003-10-15 23:53:47 +000074}
75
wdenka445ddf2004-06-09 00:34:46 +000076
wdenk13eb2212004-07-09 23:27:13 +000077long int
78initdram(int board_type)
wdenk9c53f402003-10-15 23:53:47 +000079{
80 long dram_size = 0;
81 extern long spd_sdram (void);
82 volatile immap_t *immap = (immap_t *)CFG_IMMR;
wdenk13eb2212004-07-09 23:27:13 +000083
84 puts("Initializing\n");
wdenka445ddf2004-06-09 00:34:46 +000085
wdenk9c53f402003-10-15 23:53:47 +000086#if defined(CONFIG_DDR_DLL)
wdenk13eb2212004-07-09 23:27:13 +000087 {
wdenk492b9e72004-08-01 23:02:45 +000088 volatile ccsr_gur_t *gur= &immap->im_gur;
89 uint temp_ddrdll = 0;
wdenk9c53f402003-10-15 23:53:47 +000090
wdenk492b9e72004-08-01 23:02:45 +000091 /*
92 * Work around to stabilize DDR DLL
93 */
94 temp_ddrdll = gur->ddrdllcr;
95 gur->ddrdllcr = ((temp_ddrdll & 0xff) << 16) | 0x80000000;
96 asm("sync;isync;msync");
wdenk13eb2212004-07-09 23:27:13 +000097 }
wdenk9c53f402003-10-15 23:53:47 +000098#endif
99
100#if defined(CONFIG_SPD_EEPROM)
101 dram_size = spd_sdram ();
102#else
103 dram_size = fixed_sdram ();
104#endif
105
wdenk13eb2212004-07-09 23:27:13 +0000106#if defined(CONFIG_DDR_ECC)
107 /*
108 * Initialize and enable DDR ECC.
109 */
110 ddr_enable_ecc(dram_size);
111#endif
112
113 /*
114 * Initialize SDRAM.
115 */
116 sdram_init();
117
118 puts(" DDR: ");
119 return dram_size;
120}
121
122
123/*
wdenk492b9e72004-08-01 23:02:45 +0000124 * Initialize Local Bus
wdenk13eb2212004-07-09 23:27:13 +0000125 */
126
wdenk492b9e72004-08-01 23:02:45 +0000127void
128local_bus_init(void)
wdenk13eb2212004-07-09 23:27:13 +0000129{
wdenk492b9e72004-08-01 23:02:45 +0000130 volatile immap_t *immap = (immap_t *)CFG_IMMR;
131 volatile ccsr_gur_t *gur = &immap->im_gur;
wdenk13eb2212004-07-09 23:27:13 +0000132 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
wdenk13eb2212004-07-09 23:27:13 +0000133
wdenk492b9e72004-08-01 23:02:45 +0000134 uint clkdiv;
135 uint lbc_hz;
136 sys_info_t sysinfo;
wdenk13eb2212004-07-09 23:27:13 +0000137
138 /*
wdenk492b9e72004-08-01 23:02:45 +0000139 * Errata LBC11.
140 * Fix Local Bus clock glitch when DLL is enabled.
wdenk13eb2212004-07-09 23:27:13 +0000141 *
wdenk492b9e72004-08-01 23:02:45 +0000142 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
143 * If localbus freq is > 133Mhz, DLL can be safely enabled.
144 * Between 66 and 133, the DLL is enabled with an override workaround.
wdenk13eb2212004-07-09 23:27:13 +0000145 */
wdenk492b9e72004-08-01 23:02:45 +0000146
147 get_sys_info(&sysinfo);
148 clkdiv = lbc->lcrr & 0x0f;
149 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
150
151 if (lbc_hz < 66) {
152 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
153
154 } else if (lbc_hz >= 133) {
155 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
wdenk13eb2212004-07-09 23:27:13 +0000156
wdenk9c53f402003-10-15 23:53:47 +0000157 } else {
wdenk13eb2212004-07-09 23:27:13 +0000158 /*
159 * On REV1 boards, need to change CLKDIV before enable DLL.
160 * Default CLKDIV is 8, change it to 4 temporarily.
161 */
wdenk492b9e72004-08-01 23:02:45 +0000162 uint pvr = get_pvr();
wdenk13eb2212004-07-09 23:27:13 +0000163 uint temp_lbcdll = 0;
wdenka445ddf2004-06-09 00:34:46 +0000164
165 if (pvr == PVR_85xx_REV1) {
wdenk492b9e72004-08-01 23:02:45 +0000166 /* FIXME: Justify the high bit here. */
wdenk13eb2212004-07-09 23:27:13 +0000167 lbc->lcrr = 0x10000004;
wdenka445ddf2004-06-09 00:34:46 +0000168 }
wdenk13eb2212004-07-09 23:27:13 +0000169
wdenk492b9e72004-08-01 23:02:45 +0000170 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
171 udelay(200);
172
173 /*
174 * Sample LBC DLL ctrl reg, upshift it to set the
175 * override bits.
176 */
wdenk9c53f402003-10-15 23:53:47 +0000177 temp_lbcdll = gur->lbcdllcr;
wdenk492b9e72004-08-01 23:02:45 +0000178 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
179 asm("sync;isync;msync");
wdenk9c53f402003-10-15 23:53:47 +0000180 }
wdenk492b9e72004-08-01 23:02:45 +0000181}
182
183
184/*
185 * Initialize SDRAM memory on the Local Bus.
186 */
187
188void
189sdram_init(void)
190{
191 volatile immap_t *immap = (immap_t *)CFG_IMMR;
192 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
193 uint *sdram_addr = (uint *)CFG_LBC_SDRAM_BASE;
194
195 puts(" SDRAM: ");
196 print_size (CFG_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
wdenk13eb2212004-07-09 23:27:13 +0000197
198 /*
199 * Setup SDRAM Base and Option Registers
200 */
201 lbc->or2 = CFG_OR2_PRELIM;
wdenk9c53f402003-10-15 23:53:47 +0000202 lbc->br2 = CFG_BR2_PRELIM;
203 lbc->lbcr = CFG_LBC_LBCR;
wdenk492b9e72004-08-01 23:02:45 +0000204 asm("msync");
wdenk13eb2212004-07-09 23:27:13 +0000205
wdenk9c53f402003-10-15 23:53:47 +0000206 lbc->lsrt = CFG_LBC_LSRT;
wdenk9c53f402003-10-15 23:53:47 +0000207 lbc->mrtpr = CFG_LBC_MRTPR;
wdenk492b9e72004-08-01 23:02:45 +0000208 asm("sync");
wdenk9c53f402003-10-15 23:53:47 +0000209
wdenk13eb2212004-07-09 23:27:13 +0000210 /*
211 * Configure the SDRAM controller.
212 */
213 lbc->lsdmr = CFG_LBC_LSDMR_1;
wdenk492b9e72004-08-01 23:02:45 +0000214 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000215 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000216 ppcDcbf((unsigned long) sdram_addr);
217 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000218
wdenk13eb2212004-07-09 23:27:13 +0000219 lbc->lsdmr = CFG_LBC_LSDMR_2;
wdenk492b9e72004-08-01 23:02:45 +0000220 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000221 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000222 ppcDcbf((unsigned long) sdram_addr);
223 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000224
wdenk13eb2212004-07-09 23:27:13 +0000225 lbc->lsdmr = CFG_LBC_LSDMR_3;
wdenk492b9e72004-08-01 23:02:45 +0000226 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000227 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000228 ppcDcbf((unsigned long) sdram_addr);
229 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000230
wdenk13eb2212004-07-09 23:27:13 +0000231 lbc->lsdmr = CFG_LBC_LSDMR_4;
wdenk492b9e72004-08-01 23:02:45 +0000232 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000233 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000234 ppcDcbf((unsigned long) sdram_addr);
235 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000236
wdenk13eb2212004-07-09 23:27:13 +0000237 lbc->lsdmr = CFG_LBC_LSDMR_5;
wdenk492b9e72004-08-01 23:02:45 +0000238 asm("sync");
wdenk13eb2212004-07-09 23:27:13 +0000239 *sdram_addr = 0xff;
wdenk492b9e72004-08-01 23:02:45 +0000240 ppcDcbf((unsigned long) sdram_addr);
241 udelay(100);
wdenk9c53f402003-10-15 23:53:47 +0000242}
243
244
245#if defined(CFG_DRAM_TEST)
246int testdram (void)
247{
248 uint *pstart = (uint *) CFG_MEMTEST_START;
249 uint *pend = (uint *) CFG_MEMTEST_END;
250 uint *p;
251
252 printf("SDRAM test phase 1:\n");
253 for (p = pstart; p < pend; p++)
254 *p = 0xaaaaaaaa;
255
256 for (p = pstart; p < pend; p++) {
257 if (*p != 0xaaaaaaaa) {
258 printf ("SDRAM test fails at: %08x\n", (uint) p);
259 return 1;
260 }
261 }
262
263 printf("SDRAM test phase 2:\n");
264 for (p = pstart; p < pend; p++)
265 *p = 0x55555555;
266
267 for (p = pstart; p < pend; p++) {
268 if (*p != 0x55555555) {
269 printf ("SDRAM test fails at: %08x\n", (uint) p);
270 return 1;
271 }
272 }
273
274 printf("SDRAM test passed.\n");
275 return 0;
276}
277#endif
278
279
280#if !defined(CONFIG_SPD_EEPROM)
281/*************************************************************************
282 * fixed sdram init -- doesn't use serial presence detect.
283 ************************************************************************/
284long int fixed_sdram (void)
285{
286 #ifndef CFG_RAMBOOT
287 volatile immap_t *immap = (immap_t *)CFG_IMMR;
288 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
289
290 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
291 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
292 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
293 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
294 ddr->sdram_mode = CFG_DDR_MODE;
295 ddr->sdram_interval = CFG_DDR_INTERVAL;
296 #if defined (CONFIG_DDR_ECC)
297 ddr->err_disable = 0x0000000D;
298 ddr->err_sbe = 0x00ff0000;
299 #endif
300 asm("sync;isync;msync");
301 udelay(500);
302 #if defined (CONFIG_DDR_ECC)
303 /* Enable ECC checking */
304 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
305 #else
306 ddr->sdram_cfg = CFG_DDR_CONTROL;
307 #endif
308 asm("sync; isync; msync");
309 udelay(500);
310 #endif
wdenk13eb2212004-07-09 23:27:13 +0000311 return CFG_SDRAM_SIZE * 1024 * 1024;
wdenk9c53f402003-10-15 23:53:47 +0000312}
313#endif /* !defined(CONFIG_SPD_EEPROM) */
wdenk492b9e72004-08-01 23:02:45 +0000314
315
316#if defined(CONFIG_PCI)
317/*
318 * Initialize PCI Devices, report devices found.
319 */
320
321#ifndef CONFIG_PCI_PNP
322static struct pci_config_table pci_mpc85xxads_config_table[] = {
323 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
324 PCI_IDSEL_NUMBER, PCI_ANY_ID,
325 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
326 PCI_ENET0_MEMADDR,
327 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
328 } },
329 { }
330};
331#endif
332
333
334static struct pci_controller hose = {
335#ifndef CONFIG_PCI_PNP
336 config_table: pci_mpc85xxads_config_table,
337#endif
338};
339
340#endif /* CONFIG_PCI */
341
342
343void
344pci_init_board(void)
345{
346#ifdef CONFIG_PCI
347 extern void pci_mpc85xx_init(struct pci_controller *hose);
348
349 pci_mpc85xx_init(&hose);
350#endif /* CONFIG_PCI */
351}