2 * Copyright 2007 Freescale Semiconductor, Inc.
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/processor.h>
27 #include <asm/immap_86xx.h>
28 #include <asm/immap_fsl_pci.h>
33 #if defined(CONFIG_OF_FLAT_TREE)
35 extern void ft_cpu_setup(void *blob, bd_t *bd);
38 #include "../common/pixis.h"
40 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
41 extern void ddr_enable_ecc(unsigned int dram_size);
44 #if defined(CONFIG_SPD_EEPROM)
45 #include "spd_sdram.h"
48 void sdram_init(void);
49 long int fixed_sdram(void);
51 /* called before any console output */
52 int board_early_init_f(void)
54 volatile immap_t *immap = (immap_t *)CFG_IMMR;
55 volatile ccsr_gur_t *gur = &immap->im_gur;
57 gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
66 /*Do not use 8259PIC*/
67 tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
68 out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val | 0x80);
70 /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
71 version = in8(PIXIS_BASE + PIXIS_PVER);
73 tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
74 out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val & 0xbf);
77 /* Using this for DIU init before the driver in linux takes over
78 * Enable the TFP410 Encoder (I2C address 0x38)
82 i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
83 /* Verify if enabled */
85 i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
86 debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
89 i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
90 /* Verify if enabled */
92 i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
93 debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
95 #ifdef CONFIG_FSL_DIU_FB
96 mpc8610hpcd_diu_init();
104 volatile immap_t *immap = (immap_t *)CFG_IMMR;
105 volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
107 puts("Board: MPC8610HPCD\n");
109 mcm->abcr |= 0x00010000; /* 0 */
110 mcm->hpmr3 = 0x80000008; /* 4c */
122 initdram(int board_type)
126 #if defined(CONFIG_SPD_EEPROM)
127 dram_size = spd_sdram();
129 dram_size = fixed_sdram();
132 #if defined(CFG_RAMBOOT)
137 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
139 * Initialize and enable DDR ECC.
141 ddr_enable_ecc(dram_size);
149 #if defined(CFG_DRAM_TEST)
153 uint *pstart = (uint *) CFG_MEMTEST_START;
154 uint *pend = (uint *) CFG_MEMTEST_END;
157 puts("SDRAM test phase 1:\n");
158 for (p = pstart; p < pend; p++)
161 for (p = pstart; p < pend; p++) {
162 if (*p != 0xaaaaaaaa) {
163 printf("SDRAM test fails at: %08x\n", (uint) p);
168 puts("SDRAM test phase 2:\n");
169 for (p = pstart; p < pend; p++)
172 for (p = pstart; p < pend; p++) {
173 if (*p != 0x55555555) {
174 printf("SDRAM test fails at: %08x\n", (uint) p);
179 puts("SDRAM test passed.\n");
185 #if !defined(CONFIG_SPD_EEPROM)
187 * Fixed sdram init -- doesn't use serial presence detect.
190 long int fixed_sdram(void)
192 #if !defined(CFG_RAMBOOT)
193 volatile immap_t *immap = (immap_t *)CFG_IMMR;
194 volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
197 ddr->cs0_bnds = 0x0000001f;
198 ddr->cs0_config = 0x80010202;
200 ddr->ext_refrec = 0x00000000;
201 ddr->timing_cfg_0 = 0x00260802;
202 ddr->timing_cfg_1 = 0x3935d322;
203 ddr->timing_cfg_2 = 0x14904cc8;
204 ddr->sdram_mode_1 = 0x00480432;
205 ddr->sdram_mode_2 = 0x00000000;
206 ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
207 ddr->sdram_data_init = 0xDEADBEEF;
208 ddr->sdram_clk_cntl = 0x03800000;
209 ddr->sdram_cfg_2 = 0x04400010;
211 #if defined(CONFIG_DDR_ECC)
212 ddr->err_int_en = 0x0000000d;
213 ddr->err_disable = 0x00000000;
214 ddr->err_sbe = 0x00010000;
220 ddr->sdram_cfg_1 = 0xc3000000; /* 0xe3008000;*/
223 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
225 debug("DDR - 1st controller: memory initializing\n");
227 * Poll until memory is initialized.
228 * 512 Meg at 400 might hit this 200 times or so.
230 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
233 debug("DDR: memory initialized\n\n");
238 return 512 * 1024 * 1024;
240 return CFG_SDRAM_SIZE * 1024 * 1024;
245 #if defined(CONFIG_PCI)
247 * Initialize PCI Devices, report devices found.
250 #ifndef CONFIG_PCI_PNP
251 static struct pci_config_table pci_fsl86xxads_config_table[] = {
252 {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
253 PCI_IDSEL_NUMBER, PCI_ANY_ID,
254 pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
256 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
262 static struct pci_controller pci1_hose = {
263 #ifndef CONFIG_PCI_PNP
264 config_table:pci_mpc86xxcts_config_table
267 #endif /* CONFIG_PCI */
270 static struct pci_controller pcie1_hose;
274 static struct pci_controller pcie2_hose;
277 int first_free_busno = 0;
279 void pci_init_board(void)
281 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
282 volatile ccsr_gur_t *gur = &immap->im_gur;
283 uint devdisr = gur->devdisr;
284 uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
285 uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
287 printf( " pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
288 devdisr, io_sel, host_agent);
293 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
294 extern void fsl_pci_init(struct pci_controller *hose);
295 struct pci_controller *hose = &pcie1_hose;
296 int pcie_configured = (io_sel == 1) || (io_sel == 4);
297 int pcie_ep = (host_agent == 0) || (host_agent == 2) ||
300 if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE1)) {
301 printf(" PCIe 1 connected to Uli as %s (base address %x)\n",
302 pcie_ep ? "End Point" : "Root Complex",
304 if (pci->pme_msg_det)
305 pci->pme_msg_det = 0xffffffff;
308 pci_set_region(hose->regions + 0,
312 PCI_REGION_MEM | PCI_REGION_MEMORY);
314 /* outbound memory */
315 pci_set_region(hose->regions + 1,
322 pci_set_region(hose->regions + 2,
328 hose->region_count = 3;
330 hose->first_busno = first_free_busno;
331 pci_setup_indirect(hose, (int)&pci->cfg_addr,
332 (int)&pci->cfg_data);
336 first_free_busno = hose->last_busno + 1;
337 printf(" PCI-Express 1 on bus %02x - %02x\n",
338 hose->first_busno, hose->last_busno);
341 puts(" PCI-Express 1: Disabled\n");
344 puts("PCI-Express 1: Disabled\n");
345 #endif /* CONFIG_PCIE1 */
350 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
351 extern void fsl_pci_init(struct pci_controller *hose);
352 struct pci_controller *hose = &pcie2_hose;
354 int pcie_configured = (io_sel == 0) || (io_sel == 4);
355 int pcie_ep = (host_agent == 0) || (host_agent == 1) ||
358 if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE2)) {
359 printf(" PCI-Express 2 connected to slot as %s" \
360 " (base address %x)\n",
361 pcie_ep ? "End Point" : "Root Complex",
363 if (pci->pme_msg_det)
364 pci->pme_msg_det = 0xffffffff;
367 pci_set_region(hose->regions + 0,
371 PCI_REGION_MEM | PCI_REGION_MEMORY);
373 /* outbound memory */
374 pci_set_region(hose->regions + 1,
381 pci_set_region(hose->regions + 2,
387 hose->region_count = 3;
389 hose->first_busno = first_free_busno;
390 pci_setup_indirect(hose, (int)&pci->cfg_addr,
391 (int)&pci->cfg_data);
395 first_free_busno = hose->last_busno + 1;
396 printf(" PCI-Express 2 on bus %02x - %02x\n",
397 hose->first_busno, hose->last_busno);
399 puts(" PCI-Express 2: Disabled\n");
402 puts("PCI-Express 2: Disabled\n");
403 #endif /* CONFIG_PCIE2 */
408 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
409 extern void fsl_pci_init(struct pci_controller *hose);
410 struct pci_controller *hose = &pci1_hose;
411 int pci_agent = (host_agent >= 4) && (host_agent <= 6);
413 if ( !(devdisr & MPC86xx_DEVDISR_PCI1)) {
414 printf(" PCI connected to PCI slots as %s" \
415 " (base address %x)\n",
416 pci_agent ? "Agent" : "Host",
420 pci_set_region(hose->regions + 0,
424 PCI_REGION_MEM | PCI_REGION_MEMORY);
426 /* outbound memory */
427 pci_set_region(hose->regions + 1,
434 pci_set_region(hose->regions + 2,
440 hose->region_count = 3;
442 hose->first_busno = first_free_busno;
443 pci_setup_indirect(hose, (int) &pci->cfg_addr,
444 (int) &pci->cfg_data);
448 first_free_busno = hose->last_busno + 1;
449 printf(" PCI on bus %02x - %02x\n",
450 hose->first_busno, hose->last_busno);
454 puts(" PCI: Disabled\n");
456 #endif /* CONFIG_PCI1 */
459 #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
461 ft_board_setup(void *blob, bd_t *bd)
466 ft_cpu_setup(blob, bd);
468 p = ft_get_prop(blob, "/memory/reg", &len);
470 *p++ = cpu_to_be32(bd->bi_memstart);
471 *p = cpu_to_be32(bd->bi_memsize);
475 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8000/bus-range", &len);
478 p[1] = pci1_hose.last_busno - pci1_hose.first_busno;
479 debug("pci@8000 first_busno=%d last_busno=%d\n",p[0],p[1]);
483 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pcie@a000/bus-range", &len);
486 p[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
487 debug("pcie@9000 first_busno=%d last_busno=%d\n",p[0],p[1]);
491 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pcie@9000/bus-range", &len);
494 p[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
495 debug("pcie@9000 first_busno=%d last_busno=%d\n",p[0],p[1]);
504 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
508 get_board_sys_clk(ulong dummy)
514 a = PIXIS_BASE + PIXIS_SPD;