blob: 0b08df20398e607b2c523c373ed35124d0c1e209 [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>
Jon Loeliger72f8a8e2006-05-31 11:24:28 -050028#include <command.h>
Jon Loeliger5c8aa972006-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 Loeliger72f8a8e2006-05-31 11:24:28 -050039#include "pixis.h"
40
41
Jon Loeliger5c8aa972006-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
Jon Loeliger5c8aa972006-04-26 17:58:56 -050048void sdram_init(void);
49long int fixed_sdram(void);
50
51
52int board_early_init_f (void)
53{
54 return 0;
55}
56
57int checkboard (void)
58{
59 puts("Board: MPC8641HPCN\n");
60
61#ifdef CONFIG_PCI
62
Jon Loeliger5c8aa972006-04-26 17:58:56 -050063 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
64 volatile ccsr_gur_t *gur = &immap->im_gur;
65 volatile ccsr_pex_t *pex1 = &immap->im_pex1;
66
67 uint devdisr = gur->devdisr;
68 uint io_sel = (gur->pordevsr & MPC86xx_PORDEVSR_IO_SEL) >> 16;
69 uint host1_agent = (gur->porbmsr & MPC86xx_PORBMSR_HA) >> 17;
70 uint pex1_agent = (host1_agent == 0) || (host1_agent == 1);
71
72
Jon Loeliger465b9d82006-04-27 10:15:16 -050073 if ((io_sel==2 || io_sel==3 || io_sel==5 \
74 || io_sel==6 || io_sel==7 || io_sel==0xF)
75 && !(devdisr & MPC86xx_DEVDISR_PCIEX1)){
76 debug ("PCI-EXPRESS 1: %s \n",
77 pex1_agent ? "Agent" : "Host");
Jon Loeliger5c8aa972006-04-26 17:58:56 -050078 debug("0x%08x=0x%08x ", &pex1->pme_msg_det,pex1->pme_msg_det);
79 if (pex1->pme_msg_det) {
80 pex1->pme_msg_det = 0xffffffff;
Jon Loeliger465b9d82006-04-27 10:15:16 -050081 debug (" with errors. Clearing. Now 0x%08x",
82 pex1->pme_msg_det);
Jon Loeliger5c8aa972006-04-26 17:58:56 -050083 }
84 debug ("\n");
85 } else {
86 printf ("PCI-EXPRESS 1: Disabled\n");
87 }
88
89#else
90 printf("PCI-EXPRESS1: Disabled\n");
91#endif
92
Jon Loeliger5c8aa972006-04-26 17:58:56 -050093 return 0;
94}
95
96
97long int
98initdram(int board_type)
99{
100 long dram_size = 0;
101 extern long spd_sdram (void);
102
103#if defined(CONFIG_SPD_EEPROM)
104 dram_size = spd_sdram ();
105#else
106 dram_size = fixed_sdram ();
107#endif
108
109#if defined(CFG_RAMBOOT)
110 puts(" DDR: ");
111 return dram_size;
112#endif
113
114#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
115 /*
116 * Initialize and enable DDR ECC.
117 */
118 ddr_enable_ecc(dram_size);
119#endif
120
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500121 puts(" DDR: ");
122 return dram_size;
123}
124
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500125
126#if defined(CFG_DRAM_TEST)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500127int testdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500128{
129 uint *pstart = (uint *) CFG_MEMTEST_START;
130 uint *pend = (uint *) CFG_MEMTEST_END;
131 uint *p;
132
133 printf("SDRAM test phase 1:\n");
134 for (p = pstart; p < pend; p++)
135 *p = 0xaaaaaaaa;
136
137 for (p = pstart; p < pend; p++) {
138 if (*p != 0xaaaaaaaa) {
139 printf ("SDRAM test fails at: %08x\n", (uint) p);
140 return 1;
141 }
142 }
143
144 printf("SDRAM test phase 2:\n");
145 for (p = pstart; p < pend; p++)
146 *p = 0x55555555;
147
148 for (p = pstart; p < pend; p++) {
149 if (*p != 0x55555555) {
150 printf ("SDRAM test fails at: %08x\n", (uint) p);
151 return 1;
152 }
153 }
154
155 printf("SDRAM test passed.\n");
156 return 0;
157}
158#endif
159
160
161#if !defined(CONFIG_SPD_EEPROM)
Jon Loeliger465b9d82006-04-27 10:15:16 -0500162/*
163 * Fixed sdram init -- doesn't use serial presence detect.
164 */
165long int fixed_sdram(void)
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500166{
167#if !defined(CFG_RAMBOOT)
168 volatile immap_t *immap = (immap_t *)CFG_IMMR;
169 volatile ccsr_ddr_t *ddr= &immap->im_ddr1;
170
171 ddr->cs0_bnds = CFG_DDR_CS0_BNDS;
172 ddr->cs0_config = CFG_DDR_CS0_CONFIG;
173 ddr->ext_refrec = CFG_DDR_EXT_REFRESH;
174 ddr->timing_cfg_0 = CFG_DDR_TIMING_0;
175 ddr->timing_cfg_1 = CFG_DDR_TIMING_1;
176 ddr->timing_cfg_2 = CFG_DDR_TIMING_2;
177 ddr->sdram_mode_1 = CFG_DDR_MODE_1;
178 ddr->sdram_mode_2 = CFG_DDR_MODE_2;
179 ddr->sdram_interval = CFG_DDR_INTERVAL;
180 ddr->sdram_data_init = CFG_DDR_DATA_INIT;
181 ddr->sdram_clk_cntl = CFG_DDR_CLK_CTRL;
182 ddr->sdram_ocd_cntl = CFG_DDR_OCD_CTRL;
183 ddr->sdram_ocd_status = CFG_DDR_OCD_STATUS;
184
185#if defined (CONFIG_DDR_ECC)
186 ddr->err_disable = 0x0000008D;
187 ddr->err_sbe = 0x00ff0000;
188#endif
189 asm("sync;isync");
190
191 udelay(500);
192
193#if defined (CONFIG_DDR_ECC)
194 /* Enable ECC checking */
195 ddr->sdram_cfg_1 = (CFG_DDR_CONTROL | 0x20000000);
196#else
197 ddr->sdram_cfg_1 = CFG_DDR_CONTROL;
198 ddr->sdram_cfg_2 = CFG_DDR_CONTROL2;
199#endif
200 asm("sync; isync");
201
202 udelay(500);
203#endif
204 return CFG_SDRAM_SIZE * 1024 * 1024;
205}
206#endif /* !defined(CONFIG_SPD_EEPROM) */
207
208
209#if defined(CONFIG_PCI)
210/*
211 * Initialize PCI Devices, report devices found.
212 */
213
214#ifndef CONFIG_PCI_PNP
215static struct pci_config_table pci_fsl86xxads_config_table[] = {
216 { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
217 PCI_IDSEL_NUMBER, PCI_ANY_ID,
218 pci_cfgfunc_config_device, { PCI_ENET0_IOADDR,
219 PCI_ENET0_MEMADDR,
220 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
221 } },
222 { }
223};
224#endif
225
226
227static struct pci_controller hose = {
228#ifndef CONFIG_PCI_PNP
229 config_table: pci_mpc86xxcts_config_table,
230#endif
231};
232
233#endif /* CONFIG_PCI */
234
235
236void
237pci_init_board(void)
238{
239#ifdef CONFIG_PCI
240 extern void pci_mpc86xx_init(struct pci_controller *hose);
241
242 pci_mpc86xx_init(&hose);
243#endif /* CONFIG_PCI */
244}
245
246#if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
247void
248ft_board_setup(void *blob, bd_t *bd)
249{
250 u32 *p;
251 int len;
252
253 ft_cpu_setup(blob, bd);
254
255 p = ft_get_prop(blob, "/memory/reg", &len);
256 if (p != NULL) {
257 *p++ = cpu_to_be32(bd->bi_memstart);
258 *p = cpu_to_be32(bd->bi_memsize);
259 }
260
261}
262#endif
263
Jon Loeliger72f8a8e2006-05-31 11:24:28 -0500264
265void
266mpc8641_reset_board(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
267{
268 char cmd;
269 ulong val;
270 ulong corepll;
271
272 if (argc > 1) {
273 cmd = argv[1][1];
274 switch (cmd) {
275 case 'f': /* reset with frequency changed */
276 if (argc < 5)
277 goto my_usage;
278 read_from_px_regs(0);
279
280 val = set_px_sysclk(simple_strtoul(argv[2], NULL, 10));
281
282 corepll = strfractoint(argv[3]);
283 val = val + set_px_corepll(corepll);
284 val = val + set_px_mpxpll(simple_strtoul(argv[4], NULL, 10));
285 if (val == 3) {
286 printf("Setting registers VCFGEN0 and VCTL\n");
287 read_from_px_regs(1);
288 printf("Resetting board with values from VSPEED0, VSPEED1, VCLKH, and VCLKL ....\n");
289 set_px_go();
290 } else
291 goto my_usage;
292
293 while (1); /* Not reached */
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500294
Jon Loeliger72f8a8e2006-05-31 11:24:28 -0500295 case 'l':
296 if (argv[2][1] == 'f') {
297 read_from_px_regs(0);
298 read_from_px_regs_altbank(0);
299 /* reset with frequency changed */
300 val = set_px_sysclk(simple_strtoul(argv[3], NULL, 10));
Jon Loeliger5c8aa972006-04-26 17:58:56 -0500301
Jon Loeliger72f8a8e2006-05-31 11:24:28 -0500302 corepll = strfractoint(argv[4]);
303 val = val + set_px_corepll(corepll);
304 val = val + set_px_mpxpll(simple_strtoul(argv[5], NULL, 10));
305 if (val == 3) {
306 printf("Setting registers VCFGEN0, VCFGEN1, VBOOT, and VCTL\n");
307 set_altbank();
308 read_from_px_regs(1);
309 read_from_px_regs_altbank(1);
310 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");
311 set_px_go_with_watchdog();
312 } else
313 goto my_usage;
314
315 while(1); /* Not reached */
316
317 } else if(argv[2][1] == 'd'){
318 /* Reset from next bank without changing frequencies but with watchdog timer enabled */
319 read_from_px_regs(0);
320 read_from_px_regs_altbank(0);
321 printf("Setting registers VCFGEN1, VBOOT, and VCTL\n");
322 set_altbank();
323 read_from_px_regs_altbank(1);
324 printf("Enabling watchdog timer on the FPGA and resetting board to boot from the other bank....\n");
325 set_px_go_with_watchdog();
326 while(1); /* Not reached */
327
328 } else {
329 /* Reset from next bank without changing frequency and without watchdog timer enabled */
330 read_from_px_regs(0);
331 read_from_px_regs_altbank(0);
332 if(argc > 2)
333 goto my_usage;
334 printf("Setting registers VCFGNE1, VBOOT, and VCTL\n");
335 set_altbank();
336 read_from_px_regs_altbank(1);
337 printf("Resetting board to boot from the other bank....\n");
338 set_px_go();
339 }
340
341 default:
342 goto my_usage;
343 }
344
345 my_usage:
346 printf("\nUsage: reset cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>\n");
347 printf(" reset altbank [cf <SYSCLK freq> <COREPLL ratio> <MPXPLL ratio>]\n");
348 printf("For example: reset cf 40 2.5 10\n");
349 printf("See MPC8641HPCN Design Workbook for valid values of command line parameters.\n");
350 return;
351
352 } else
353 out8(PIXIS_BASE+PIXIS_RST,0);
354}