blob: d02a7eff3c370659c73971ae7bb608e05b1d92a3 [file] [log] [blame]
Jon Loeliger5c8aa972006-04-26 17:58:56 -05001/*
2 * Copyright 2004 Freescale Semiconductor.
3 * Jeff Brown (jeffrey@freescale.com)
4 * Srikanth Srinivasan (srikanth.srinivasan@freescale.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#include <common.h>
28#include <pci.h>
29#include <asm/processor.h>
30#include <asm/immap_86xx.h>
31#include <spd.h>
32
33#if defined(CONFIG_OF_FLAT_TREE)
34#include <ft_build.h>
35extern void ft_cpu_setup(void *blob, bd_t *bd);
36#endif
37
38#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
39extern void ddr_enable_ecc(unsigned int dram_size);
40#endif
41
42extern long int spd_sdram(void);
43
44void local_bus_init(void);
45void sdram_init(void);
46long int fixed_sdram(void);
47
48
49int board_early_init_f (void)
50{
51 return 0;
52}
53
54int checkboard (void)
55{
56 puts("Board: MPC8641HPCN\n");
57
58#ifdef CONFIG_PCI
59
Jon Loeliger5c8aa972006-04-26 17:58:56 -050060 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
61 volatile ccsr_gur_t *gur = &immap->im_gur;
62 volatile ccsr_pex_t *pex1 = &immap->im_pex1;
63
64 uint devdisr = gur->devdisr;
65 uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
66 uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
67 uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
68
69
Jon Loeliger465b9d82006-04-27 10:15:16 -050070 if ((io_sel==2 || io_sel==3 || io_sel==5 \
71 || io_sel==6 || io_sel==7 || io_sel==0xF)
72 && !(devdisr & MPC86xx_DEVDISR_PCIEX1)){
73 debug ("PCI-EXPRESS 1: %s \n",
74 pex1_agent ? "Agent" : "Host");
Jon Loeliger5c8aa972006-04-26 17:58:56 -050075 debug("0x%08x=0x%08x ", &pex1->pme_msg_det,pex1->pme_msg_det);
76 if (pex1->pme_msg_det) {
77 pex1->pme_msg_det = 0xffffffff;
Jon Loeliger465b9d82006-04-27 10:15:16 -050078 debug (" with errors. Clearing. Now 0x%08x",
79 pex1->pme_msg_det);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050080 }
81 debug ("\n");
82 } else {
83 printf ("PCI-EXPRESS 1: Disabled\n");
84 }
85
86#else
87 printf("PCI-EXPRESS1: Disabled\n");
88#endif
89
90 /*
91 * Initialize local bus.
92 */
93 local_bus_init();
94
95 return 0;
96}
97
98
99long int
100initdram(int board_type)
101{
102 long dram_size = 0;
103 extern long spd_sdram (void);
104
105#if defined(CONFIG_SPD_EEPROM)
106 dram_size = spd_sdram ();
107#else
108 dram_size = fixed_sdram ();
109#endif
110
111#if defined(CFG_RAMBOOT)
112 puts(" DDR: ");
113 return dram_size;
114#endif
115
116#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
117 /*
118 * Initialize and enable DDR ECC.
119 */
120 ddr_enable_ecc(dram_size);
121#endif
122
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500123 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;
136 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
137
138 uint clkdiv;
139 uint lbc_hz;
140 sys_info_t sysinfo;
141
142 /*
143 * Errata LBC11.
144 * Fix Local Bus clock glitch when DLL is enabled.
145 *
146 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
147 * If localbus freq is > 133Mhz, DLL can be safely enabled.
148 * Between 66 and 133, the DLL is enabled with an override workaround.
149 */
150
151 get_sys_info(&sysinfo);
152 clkdiv = lbc->lcrr & 0x0f;
153 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
154}
155
156#if defined(CFG_DRAM_TEST)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500157int testdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500158{
159 uint *pstart = (uint *) CFG_MEMTEST_START;
160 uint *pend = (uint *) CFG_MEMTEST_END;
161 uint *p;
162
163 printf("SDRAM test phase 1:\n");
164 for (p = pstart; p < pend; p++)
165 *p = 0xaaaaaaaa;
166
167 for (p = pstart; p < pend; p++) {
168 if (*p != 0xaaaaaaaa) {
169 printf ("SDRAM test fails at: %08x\n", (uint) p);
170 return 1;
171 }
172 }
173
174 printf("SDRAM test phase 2:\n");
175 for (p = pstart; p < pend; p++)
176 *p = 0x55555555;
177
178 for (p = pstart; p < pend; p++) {
179 if (*p != 0x55555555) {
180 printf ("SDRAM test fails at: %08x\n", (uint) p);
181 return 1;
182 }
183 }
184
185 printf("SDRAM test passed.\n");
186 return 0;
187}
188#endif
189
190
191#if !defined(CONFIG_SPD_EEPROM)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500192/*
193 * Fixed sdram init -- doesn't use serial presence detect.
194 */
195long int fixed_sdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500196{
197#if !defined(CFG_RAMBOOT)
198 volatile immap_t *immap = (immap_t *)CFG_IMMR;
199 volatile ccsr_ddr_t *ddr= &immap->im_ddr1;
200
201 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
202 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
203 ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
204 ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
205 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
206 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
207 ddr->sdram_mode_1 = CFG_DDR_MODE_1;
208 ddr->sdram_mode_2 = CFG_DDR_MODE_2;
209 ddr->sdram_interval = CFG_DDR_INTERVAL;
210 ddr->sdram_data_init = CFG_DDR_DATA_INIT;
211 ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
212 ddr->sdram_ocd_cntl = CFG_DDR_OCD_CTRL;
213 ddr->sdram_ocd_status = CFG_DDR_OCD_STATUS;
214
215#if defined (CONFIG_DDR_ECC)
216 ddr->err_disable = 0x0000008D;
217 ddr->err_sbe = 0x00ff0000;
218#endif
219 asm("sync;isync");
220
221 udelay(500);
222
223#if defined (CONFIG_DDR_ECC)
224 /* Enable ECC checking */
225 ddr->sdram_cfg_1 = (CFG_DDR_CONTROL | 0x20000000);
226#else
227 ddr->sdram_cfg_1 = CFG_DDR_CONTROL;
228 ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
229#endif
230 asm("sync; isync");
231
232 udelay(500);
233#endif
234 return CFG_SDRAM_SIZE * 1024 * 1024;
235}
236#endif /* !defined(CONFIG_SPD_EEPROM) */
237
238
239#if defined(CONFIG_PCI)
240/*
241 * Initialize PCI Devices, report devices found.
242 */
243
244#ifndef CONFIG_PCI_PNP
245static struct pci_config_table pci_fsl86xxads_config_table[] = {
246 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
247 PCI_IDSEL_NUMBER, PCI_ANY_ID,
248 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
249 PCI_ENET0_MEMADDR,
250 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
251 } },
252 { }
253};
254#endif
255
256
257static struct pci_controller hose = {
258#ifndef CONFIG_PCI_PNP
259 config_table: pci_mpc86xxcts_config_table,
260#endif
261};
262
263#endif /* CONFIG_PCI */
264
265
266void
267pci_init_board(void)
268{
269#ifdef CONFIG_PCI
270 extern void pci_mpc86xx_init(struct pci_controller *hose);
271
272 pci_mpc86xx_init(&hose);
273#endif /* CONFIG_PCI */
274}
275
276#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
277void
278ft_board_setup(void *blob, bd_t *bd)
279{
280 u32 *p;
281 int len;
282
283 ft_cpu_setup(blob, bd);
284
285 p = ft_get_prop(blob, "/memory/reg", &len);
286 if (p != NULL) {
287 *p++ = cpu_to_be32(bd->bi_memstart);
288 *p = cpu_to_be32(bd->bi_memsize);
289 }
290
291}
292#endif
293
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500294
295