blob: 15e948c5171751ae6d2ced3d1c4b5f03ec491b2a [file] [log] [blame]
wdenk6d3c6d12005-04-03 22:35:21 +00001 /*
2 * Copyright 2004 Freescale Semiconductor.
3 * (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
28#include <common.h>
29#include <pci.h>
30#include <asm/processor.h>
31#include <asm/immap_85xx.h>
32#include <spd.h>
33
34#if defined(CONFIG_DDR_ECC)
35extern void ddr_enable_ecc(unsigned int dram_size);
36#endif
37
38extern long int spd_sdram(void);
39
40void local_bus_init(void);
41void sdram_init(void);
42long int fixed_sdram(void);
43
44
45int board_early_init_f (void)
46{
47#if defined(CONFIG_PCI)
48 volatile immap_t *immr = (immap_t *)CFG_IMMR;
49 volatile ccsr_pcix_t *pci = &immr->im_pcix;
50
51 pci->peer &= 0xffffffdf; /* disable master abort */
52#endif
53
54 return 0;
55}
56
57int checkboard (void)
58{
59 puts("Board: MicroSys PM854\n");
60
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
68 /*
69 * Initialize local bus.
70 */
71 local_bus_init();
72
73 return 0;
74}
75
76
77long int
78initdram(int board_type)
79{
80 long dram_size = 0;
81 extern long spd_sdram (void);
wdenk6d3c6d12005-04-03 22:35:21 +000082
83 puts("Initializing\n");
84
85#if defined(CONFIG_DDR_DLL)
86 {
Kumar Galaec1340d2007-11-27 23:25:02 -060087 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk6d3c6d12005-04-03 22:35:21 +000088 int i,x;
wdenkbc3202a2005-04-03 23:11:38 +000089
wdenk6d3c6d12005-04-03 22:35:21 +000090 x = 10;
wdenkbc3202a2005-04-03 23:11:38 +000091
wdenk6d3c6d12005-04-03 22:35:21 +000092 /*
93 * Work around to stabilize DDR DLL
94 */
95 gur->ddrdllcr = 0x81000000;
96 asm("sync;isync;msync");
97 udelay (200);
98 while (gur->ddrdllcr != 0x81000100)
99 {
100 gur->devdisr = gur->devdisr | 0x00010000;
101 asm("sync;isync;msync");
102 for (i=0; i<x; i++)
103 ;
104 gur->devdisr = gur->devdisr & 0xfff7ffff;
105 asm("sync;isync;msync");
106 x++;
107 }
wdenkbc3202a2005-04-03 23:11:38 +0000108 }
wdenk6d3c6d12005-04-03 22:35:21 +0000109#endif
110
111#if defined(CONFIG_SPD_EEPROM)
112 dram_size = spd_sdram ();
113#else
114 dram_size = fixed_sdram ();
115#endif
116
117#if defined(CONFIG_DDR_ECC)
118 /*
119 * Initialize and enable DDR ECC.
120 */
121 ddr_enable_ecc(dram_size);
122#endif
123 puts(" DDR: ");
124 return dram_size;
125}
126
127
128/*
129 * Initialize Local Bus
130 */
131
132void
133local_bus_init(void)
134{
135 volatile immap_t *immap = (immap_t *)CFG_IMMR;
Kumar Galaec1340d2007-11-27 23:25:02 -0600136 volatile ccsr_gur_t *gur = (void *)(CFG_MPC85xx_GUTS_ADDR);
wdenk6d3c6d12005-04-03 22:35:21 +0000137 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
138
139 uint clkdiv;
140 uint lbc_hz;
141 sys_info_t sysinfo;
142
143 /*
144 * Errata LBC11.
145 * Fix Local Bus clock glitch when DLL is enabled.
146 *
147 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
148 * If localbus freq is > 133Mhz, DLL can be safely enabled.
149 * Between 66 and 133, the DLL is enabled with an override workaround.
150 */
151
152 get_sys_info(&sysinfo);
153 clkdiv = lbc->lcrr & 0x0f;
154 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
155
156 if (lbc_hz < 66) {
157 lbc->lcrr = CFG_LBC_LCRR | 0x80000000; /* DLL Bypass */
158
159 } else if (lbc_hz >= 133) {
160 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
161
162 } else {
163 /*
164 * On REV1 boards, need to change CLKDIV before enable DLL.
165 * Default CLKDIV is 8, change it to 4 temporarily.
166 */
167 uint pvr = get_pvr();
168 uint temp_lbcdll = 0;
169
170 if (pvr == PVR_85xx_REV1) {
171 /* FIXME: Justify the high bit here. */
172 lbc->lcrr = 0x10000004;
173 }
174
175 lbc->lcrr = CFG_LBC_LCRR & (~0x80000000); /* DLL Enabled */
176 udelay(200);
177
178 /*
179 * Sample LBC DLL ctrl reg, upshift it to set the
180 * override bits.
181 */
182 temp_lbcdll = gur->lbcdllcr;
183 gur->lbcdllcr = (((temp_lbcdll & 0xff) << 16) | 0x80000000);
184 asm("sync;isync;msync");
185 }
186}
187
188
189#if defined(CFG_DRAM_TEST)
190int testdram (void)
191{
192 uint *pstart = (uint *) CFG_MEMTEST_START;
193 uint *pend = (uint *) CFG_MEMTEST_END;
194 uint *p;
195
196 printf("SDRAM test phase 1:\n");
197 for (p = pstart; p < pend; p++)
198 *p = 0xaaaaaaaa;
199
200 for (p = pstart; p < pend; p++) {
201 if (*p != 0xaaaaaaaa) {
202 printf ("SDRAM test fails at: %08x\n", (uint) p);
203 return 1;
204 }
205 }
206
207 printf("SDRAM test phase 2:\n");
208 for (p = pstart; p < pend; p++)
209 *p = 0x55555555;
210
211 for (p = pstart; p < pend; p++) {
212 if (*p != 0x55555555) {
213 printf ("SDRAM test fails at: %08x\n", (uint) p);
214 return 1;
215 }
216 }
217
218 printf("SDRAM test passed.\n");
219 return 0;
220}
221#endif
222
223
224#if !defined(CONFIG_SPD_EEPROM)
225/*************************************************************************
226 * fixed sdram init -- doesn't use serial presence detect.
227 ************************************************************************/
228long int fixed_sdram (void)
229{
230 #ifndef CFG_RAMBOOT
231 volatile immap_t *immap = (immap_t *)CFG_IMMR;
232 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
233
234 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
235 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
236 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
237 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
238 ddr->sdram_mode = CFG_DDR_MODE;
239 ddr->sdram_interval = CFG_DDR_INTERVAL;
240 #if defined (CONFIG_DDR_ECC)
241 ddr->err_disable = 0x0000000D;
242 ddr->err_sbe = 0x00ff0000;
243 #endif
244 asm("sync;isync;msync");
245 udelay(500);
246 #if defined (CONFIG_DDR_ECC)
247 /* Enable ECC checking */
248 ddr->sdram_cfg = (CFG_DDR_CONTROL | 0x20000000);
249 #else
250 ddr->sdram_cfg = CFG_DDR_CONTROL;
251 #endif
252 asm("sync; isync; msync");
253 udelay(500);
254 #endif
255 return CFG_SDRAM_SIZE * 1024 * 1024;
256}
257#endif /* !defined(CONFIG_SPD_EEPROM) */
258
259
260#if defined(CONFIG_PCI)
261/*
262 * Initialize PCI Devices, report devices found.
263 */
264
265#ifndef CONFIG_PCI_PNP
266static struct pci_config_table pci_pm854_config_table[] = {
267 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
268 PCI_IDSEL_NUMBER, PCI_ANY_ID,
269 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
270 PCI_ENET0_MEMADDR,
271 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
272 } },
273 { }
274};
275#endif
276
277
278static struct pci_controller hose = {
279#ifndef CONFIG_PCI_PNP
280 config_table: pci_pm854_config_table,
281#endif
282};
283
284#endif /* CONFIG_PCI */
285
286
287void
288pci_init_board(void)
289{
290#ifdef CONFIG_PCI
wdenk6d3c6d12005-04-03 22:35:21 +0000291 pci_mpc85xx_init(&hose);
292#endif /* CONFIG_PCI */
293}