blob: dbc9b5e9b8e8d304438f0f9017b6ad0c2ce6c3d6 [file] [log] [blame]
Jon Loeligerdebb7352006-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>
Jon Loeliger4d3d7292006-05-31 11:24:28 -050028#include <command.h>
Jon Loeligerdebb7352006-04-26 17:58:56 -050029#include <pci.h>
30#include <asm/processor.h>
31#include <asm/immap_86xx.h>
32#include <spd.h>
33
34#if defined(CONFIG_OF_FLAT_TREE)
35#include <ft_build.h>
36extern void ft_cpu_setup(void *blob, bd_t *bd);
37#endif
38
Jon Loeliger4d3d7292006-05-31 11:24:28 -050039#include "pixis.h"
40
41
Jon Loeligerdebb7352006-04-26 17:58:56 -050042#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
43extern void ddr_enable_ecc(unsigned int dram_size);
44#endif
45
46extern long int spd_sdram(void);
47
48void local_bus_init(void);
49void sdram_init(void);
50long int fixed_sdram(void);
51
52
53int board_early_init_f (void)
54{
55 return 0;
56}
57
58int checkboard (void)
59{
60 puts("Board: MPC8641HPCN\n");
61
62#ifdef CONFIG_PCI
63
Jon Loeligerdebb7352006-04-26 17:58:56 -050064 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
65 volatile ccsr_gur_t *gur = &immap->im_gur;
66 volatile ccsr_pex_t *pex1 = &immap->im_pex1;
67
68 uint devdisr = gur->devdisr;
69 uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
70 uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
71 uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
72
73
Jon Loeliger5c9efb32006-04-27 10:15:16 -050074 if ((io_sel==2 || io_sel==3 || io_sel==5 \
75 || io_sel==6 || io_sel==7 || io_sel==0xF)
76 && !(devdisr & MPC86xx_DEVDISR_PCIEX1)){
77 debug ("PCI-EXPRESS 1: %s \n",
78 pex1_agent ? "Agent" : "Host");
Jon Loeligerdebb7352006-04-26 17:58:56 -050079 debug("0x%08x=0x%08x ", &pex1->pme_msg_det,pex1->pme_msg_det);
80 if (pex1->pme_msg_det) {
81 pex1->pme_msg_det = 0xffffffff;
Jon Loeliger5c9efb32006-04-27 10:15:16 -050082 debug (" with errors. Clearing. Now 0x%08x",
83 pex1->pme_msg_det);
Jon Loeligerdebb7352006-04-26 17:58:56 -050084 }
85 debug ("\n");
86 } else {
87 printf ("PCI-EXPRESS 1: Disabled\n");
88 }
89
90#else
91 printf("PCI-EXPRESS1: Disabled\n");
92#endif
93
94 /*
95 * Initialize local bus.
96 */
97 local_bus_init();
98
99 return 0;
100}
101
102
103long int
104initdram(int board_type)
105{
106 long dram_size = 0;
107 extern long spd_sdram (void);
108
109#if defined(CONFIG_SPD_EEPROM)
110 dram_size = spd_sdram ();
111#else
112 dram_size = fixed_sdram ();
113#endif
114
115#if defined(CFG_RAMBOOT)
116 puts(" DDR: ");
117 return dram_size;
118#endif
119
120#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
121 /*
122 * Initialize and enable DDR ECC.
123 */
124 ddr_enable_ecc(dram_size);
125#endif
126
Jon Loeligerdebb7352006-04-26 17:58:56 -0500127 puts(" DDR: ");
128 return dram_size;
129}
130
131
132/*
133 * Initialize Local Bus
134 */
135
136void
137local_bus_init(void)
138{
139 volatile immap_t *immap = (immap_t *)CFG_IMMR;
140 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
141
142 uint clkdiv;
143 uint lbc_hz;
144 sys_info_t sysinfo;
145
146 /*
147 * Errata LBC11.
148 * Fix Local Bus clock glitch when DLL is enabled.
149 *
150 * If localbus freq is < 66Mhz, DLL bypass mode must be used.
151 * If localbus freq is > 133Mhz, DLL can be safely enabled.
152 * Between 66 and 133, the DLL is enabled with an override workaround.
153 */
154
155 get_sys_info(&sysinfo);
156 clkdiv = lbc->lcrr & 0x0f;
157 lbc_hz = sysinfo.freqSystemBus / 1000000 / clkdiv;
158}
159
160#if defined(CFG_DRAM_TEST)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500161int testdram(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500162{
163 uint *pstart = (uint *) CFG_MEMTEST_START;
164 uint *pend = (uint *) CFG_MEMTEST_END;
165 uint *p;
166
167 printf("SDRAM test phase 1:\n");
168 for (p = pstart; p < pend; p++)
169 *p = 0xaaaaaaaa;
170
171 for (p = pstart; p < pend; p++) {
172 if (*p != 0xaaaaaaaa) {
173 printf ("SDRAM test fails at: %08x\n", (uint) p);
174 return 1;
175 }
176 }
177
178 printf("SDRAM test phase 2:\n");
179 for (p = pstart; p < pend; p++)
180 *p = 0x55555555;
181
182 for (p = pstart; p < pend; p++) {
183 if (*p != 0x55555555) {
184 printf ("SDRAM test fails at: %08x\n", (uint) p);
185 return 1;
186 }
187 }
188
189 printf("SDRAM test passed.\n");
190 return 0;
191}
192#endif
193
194
195#if !defined(CONFIG_SPD_EEPROM)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500196/*
197 * Fixed sdram init -- doesn't use serial presence detect.
198 */
199long int fixed_sdram(void)
Jon Loeligerdebb7352006-04-26 17:58:56 -0500200{
201#if !defined(CFG_RAMBOOT)
202 volatile immap_t *immap = (immap_t *)CFG_IMMR;
203 volatile ccsr_ddr_t *ddr= &immap->im_ddr1;
204
205 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
206 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
207 ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
208 ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
209 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
210 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
211 ddr->sdram_mode_1 = CFG_DDR_MODE_1;
212 ddr->sdram_mode_2 = CFG_DDR_MODE_2;
213 ddr->sdram_interval = CFG_DDR_INTERVAL;
214 ddr->sdram_data_init = CFG_DDR_DATA_INIT;
215 ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
216 ddr->sdram_ocd_cntl = CFG_DDR_OCD_CTRL;
217 ddr->sdram_ocd_status = CFG_DDR_OCD_STATUS;
218
219#if defined (CONFIG_DDR_ECC)
220 ddr->err_disable = 0x0000008D;
221 ddr->err_sbe = 0x00ff0000;
222#endif
223 asm("sync;isync");
224
225 udelay(500);
226
227#if defined (CONFIG_DDR_ECC)
228 /* Enable ECC checking */
229 ddr->sdram_cfg_1 = (CFG_DDR_CONTROL | 0x20000000);
230#else
231 ddr->sdram_cfg_1 = CFG_DDR_CONTROL;
232 ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
233#endif
234 asm("sync; isync");
235
236 udelay(500);
237#endif
238 return CFG_SDRAM_SIZE * 1024 * 1024;
239}
240#endif /* !defined(CONFIG_SPD_EEPROM) */
241
242
243#if defined(CONFIG_PCI)
244/*
245 * Initialize PCI Devices, report devices found.
246 */
247
248#ifndef CONFIG_PCI_PNP
249static struct pci_config_table pci_fsl86xxads_config_table[] = {
250 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
251 PCI_IDSEL_NUMBER, PCI_ANY_ID,
252 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
253 PCI_ENET0_MEMADDR,
254 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
255 } },
256 { }
257};
258#endif
259
260
261static struct pci_controller hose = {
262#ifndef CONFIG_PCI_PNP
263 config_table: pci_mpc86xxcts_config_table,
264#endif
265};
266
267#endif /* CONFIG_PCI */
268
269
270void
271pci_init_board(void)
272{
273#ifdef CONFIG_PCI
274 extern void pci_mpc86xx_init(struct pci_controller *hose);
275
276 pci_mpc86xx_init(&hose);
277#endif /* CONFIG_PCI */
278}
279
280#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
281void
282ft_board_setup(void *blob, bd_t *bd)
283{
284 u32 *p;
285 int len;
286
287 ft_cpu_setup(blob, bd);
288
289 p = ft_get_prop(blob, "/memory/reg", &len);
290 if (p != NULL) {
291 *p++ = cpu_to_be32(bd->bi_memstart);
292 *p = cpu_to_be32(bd->bi_memsize);
293 }
294
295}
296#endif
297
Jon Loeligerdebb7352006-04-26 17:58:56 -0500298
Jon Loeliger4d3d7292006-05-31 11:24:28 -0500299void
300mpc8641_reset_board(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
301{
302 char cmd;
303 ulong val;
304 ulong corepll;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500305
Jon Loeliger4d3d7292006-05-31 11:24:28 -0500306 if (argc > 1) {
307 cmd = argv[1][1];
308 switch (cmd) {
309 case 'f': /* reset with frequency changed */
310 if (argc < 5)
311 goto my_usage;
312 read_from_px_regs(0);
313
314 val = set_px_sysclk(simple_strtoul(argv[2], NULL, 10));
315
316 corepll = strfractoint(argv[3]);
317 val = val + set_px_corepll(corepll);
318 val = val + set_px_mpxpll(simple_strtoul(argv[4], NULL, 10));
319 if (val == 3) {
320 printf("Setting registers VCFGEN0 and VCTL\n");
321 read_from_px_regs(1);
322 printf("Resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL ....\n");
323 set_px_go();
324 } else
325 goto my_usage;
326
327 while (1); /* Not reached */
328
329 case 'l':
330 if (argv[2][1] == 'f') {
331 read_from_px_regs(0);
332 read_from_px_regs_altbank(0);
333 /* reset with frequency changed */
334 val = set_px_sysclk(simple_strtoul(argv[3], NULL, 10));
335
336 corepll = strfractoint(argv[4]);
337 val = val + set_px_corepll(corepll);
338 val = val + set_px_mpxpll(simple_strtoul(argv[5], NULL, 10));
339 if (val == 3) {
340 printf("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
341 set_altbank();
342 read_from_px_regs(1);
343 read_from_px_regs_altbank(1);
344 printf("Enabling watchdog timer on the FPGA and resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL to boot from the other bank ....\n");
345 set_px_go_with_watchdog();
346 } else
347 goto my_usage;
348
349 while(1); /* Not reached */
350
351 } else if(argv[2][1] == 'd'){
352 /* Reset from next bank without changing frequencies but with watchdog timer enabled */
353 read_from_px_regs(0);
354 read_from_px_regs_altbank(0);
355 printf("Setting registers VCFGEN1, VBOOT, and VCTL\n");
356 set_altbank();
357 read_from_px_regs_altbank(1);
358 printf("Enabling watchdog timer on the FPGA and resetting board to boot from the other bank....\n");
359 set_px_go_with_watchdog();
360 while(1); /* Not reached */
361
362 } else {
363 /* Reset from next bank without changing frequency and without watchdog timer enabled */
364 read_from_px_regs(0);
365 read_from_px_regs_altbank(0);
366 if(argc > 2)
367 goto my_usage;
368 printf("Setting registers VCFGNE1, VBOOT, and VCTL\n");
369 set_altbank();
370 read_from_px_regs_altbank(1);
371 printf("Resetting board to boot from the other bank....\n");
372 set_px_go();
373 }
374
375 default:
376 goto my_usage;
377 }
378
379 my_usage:
380 printf("\nUsage: reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n");
381 printf(" reset altbank [cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>]\n");
382 printf("For example: reset cf 40 2.5 10\n");
383 printf("See MPC8641HPCN Design Workbook for valid values of command line parameters.\n");
384 return;
385
386 } else
387 out8(PIXIS_BASE+PIXIS_RST,0);
388}