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>
34 #if defined(CONFIG_OF_FLAT_TREE)
36 extern void ft_cpu_setup(void *blob, bd_t *bd);
39 #include "../common/pixis.h"
41 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
42 extern void ddr_enable_ecc(unsigned int dram_size);
45 #if defined(CONFIG_SPD_EEPROM)
46 #include "spd_sdram.h"
49 void sdram_init(void);
50 long int fixed_sdram(void);
51 void mpc8610hpcd_diu_init(void);
54 /* called before any console output */
55 int board_early_init_f(void)
57 volatile immap_t *immap = (immap_t *)CFG_IMMR;
58 volatile ccsr_gur_t *gur = &immap->im_gur;
60 gur->gpiocr |= 0x88aa5500; /* DIU16, IR1, UART0, UART2 */
69 /*Do not use 8259PIC*/
70 tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
71 out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val | 0x80);
73 /*For FPGA V7 or higher, set the IRQMAPSEL to 0 to use MAP0 interrupt*/
74 version = in8(PIXIS_BASE + PIXIS_PVER);
76 tmp_val = in8(PIXIS_BASE + PIXIS_BRDCFG0);
77 out8(PIXIS_BASE + PIXIS_BRDCFG0, tmp_val & 0xbf);
80 /* Using this for DIU init before the driver in linux takes over
81 * Enable the TFP410 Encoder (I2C address 0x38)
85 i2c_write(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
86 /* Verify if enabled */
88 i2c_read(0x38, 0x08, 1, &tmp_val, sizeof(tmp_val));
89 debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
92 i2c_write(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
93 /* Verify if enabled */
95 i2c_read(0x38, 0x0A, 1, &tmp_val, sizeof(tmp_val));
96 debug("DVI Encoder Read: 0x%02lx\n",tmp_val);
98 #ifdef CONFIG_FSL_DIU_FB
99 mpc8610hpcd_diu_init();
107 volatile immap_t *immap = (immap_t *)CFG_IMMR;
108 volatile ccsr_local_mcm_t *mcm = &immap->im_local_mcm;
110 puts("Board: MPC8610HPCD\n");
112 mcm->abcr |= 0x00010000; /* 0 */
113 mcm->hpmr3 = 0x80000008; /* 4c */
125 initdram(int board_type)
129 #if defined(CONFIG_SPD_EEPROM)
130 dram_size = spd_sdram();
132 dram_size = fixed_sdram();
135 #if defined(CFG_RAMBOOT)
140 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
142 * Initialize and enable DDR ECC.
144 ddr_enable_ecc(dram_size);
152 #if defined(CFG_DRAM_TEST)
156 uint *pstart = (uint *) CFG_MEMTEST_START;
157 uint *pend = (uint *) CFG_MEMTEST_END;
160 puts("SDRAM test phase 1:\n");
161 for (p = pstart; p < pend; p++)
164 for (p = pstart; p < pend; p++) {
165 if (*p != 0xaaaaaaaa) {
166 printf("SDRAM test fails at: %08x\n", (uint) p);
171 puts("SDRAM test phase 2:\n");
172 for (p = pstart; p < pend; p++)
175 for (p = pstart; p < pend; p++) {
176 if (*p != 0x55555555) {
177 printf("SDRAM test fails at: %08x\n", (uint) p);
182 puts("SDRAM test passed.\n");
188 #if !defined(CONFIG_SPD_EEPROM)
190 * Fixed sdram init -- doesn't use serial presence detect.
193 long int fixed_sdram(void)
195 #if !defined(CFG_RAMBOOT)
196 volatile immap_t *immap = (immap_t *)CFG_IMMR;
197 volatile ccsr_ddr_t *ddr = &immap->im_ddr1;
200 ddr->cs0_bnds = 0x0000001f;
201 ddr->cs0_config = 0x80010202;
203 ddr->ext_refrec = 0x00000000;
204 ddr->timing_cfg_0 = 0x00260802;
205 ddr->timing_cfg_1 = 0x3935d322;
206 ddr->timing_cfg_2 = 0x14904cc8;
207 ddr->sdram_mode_1 = 0x00480432;
208 ddr->sdram_mode_2 = 0x00000000;
209 ddr->sdram_interval = 0x06180fff; /* 0x06180100; */
210 ddr->sdram_data_init = 0xDEADBEEF;
211 ddr->sdram_clk_cntl = 0x03800000;
212 ddr->sdram_cfg_2 = 0x04400010;
214 #if defined(CONFIG_DDR_ECC)
215 ddr->err_int_en = 0x0000000d;
216 ddr->err_disable = 0x00000000;
217 ddr->err_sbe = 0x00010000;
223 ddr->sdram_cfg_1 = 0xc3000000; /* 0xe3008000;*/
226 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
228 debug("DDR - 1st controller: memory initializing\n");
230 * Poll until memory is initialized.
231 * 512 Meg at 400 might hit this 200 times or so.
233 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
236 debug("DDR: memory initialized\n\n");
241 return 512 * 1024 * 1024;
243 return CFG_SDRAM_SIZE * 1024 * 1024;
248 #if defined(CONFIG_PCI)
250 * Initialize PCI Devices, report devices found.
253 #ifndef CONFIG_PCI_PNP
254 static struct pci_config_table pci_fsl86xxads_config_table[] = {
255 {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
256 PCI_IDSEL_NUMBER, PCI_ANY_ID,
257 pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
259 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} },
265 static struct pci_controller pci1_hose = {
266 #ifndef CONFIG_PCI_PNP
267 config_table:pci_mpc86xxcts_config_table
270 #endif /* CONFIG_PCI */
273 static struct pci_controller pcie1_hose;
277 static struct pci_controller pcie2_hose;
280 int first_free_busno = 0;
282 void pci_init_board(void)
284 volatile immap_t *immap = (immap_t *) CFG_CCSRBAR;
285 volatile ccsr_gur_t *gur = &immap->im_gur;
286 uint devdisr = gur->devdisr;
287 uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
288 uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
290 printf( " pci_init_board: devdisr=%x, io_sel=%x, host_agent=%x\n",
291 devdisr, io_sel, host_agent);
296 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE1_ADDR;
297 extern void fsl_pci_init(struct pci_controller *hose);
298 struct pci_controller *hose = &pcie1_hose;
299 int pcie_configured = (io_sel == 1) || (io_sel == 4);
300 int pcie_ep = (host_agent == 0) || (host_agent == 2) ||
303 if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE1)) {
304 printf(" PCIe 1 connected to Uli as %s (base address %x)\n",
305 pcie_ep ? "End Point" : "Root Complex",
307 if (pci->pme_msg_det)
308 pci->pme_msg_det = 0xffffffff;
311 pci_set_region(hose->regions + 0,
315 PCI_REGION_MEM | PCI_REGION_MEMORY);
317 /* outbound memory */
318 pci_set_region(hose->regions + 1,
325 pci_set_region(hose->regions + 2,
331 hose->region_count = 3;
333 hose->first_busno = first_free_busno;
334 pci_setup_indirect(hose, (int)&pci->cfg_addr,
335 (int)&pci->cfg_data);
339 first_free_busno = hose->last_busno + 1;
340 printf(" PCI-Express 1 on bus %02x - %02x\n",
341 hose->first_busno, hose->last_busno);
344 puts(" PCI-Express 1: Disabled\n");
347 puts("PCI-Express 1: Disabled\n");
348 #endif /* CONFIG_PCIE1 */
353 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCIE2_ADDR;
354 extern void fsl_pci_init(struct pci_controller *hose);
355 struct pci_controller *hose = &pcie2_hose;
357 int pcie_configured = (io_sel == 0) || (io_sel == 4);
358 int pcie_ep = (host_agent == 0) || (host_agent == 1) ||
361 if (pcie_configured && !(devdisr & MPC86xx_DEVDISR_PCIE2)) {
362 printf(" PCI-Express 2 connected to slot as %s" \
363 " (base address %x)\n",
364 pcie_ep ? "End Point" : "Root Complex",
366 if (pci->pme_msg_det)
367 pci->pme_msg_det = 0xffffffff;
370 pci_set_region(hose->regions + 0,
374 PCI_REGION_MEM | PCI_REGION_MEMORY);
376 /* outbound memory */
377 pci_set_region(hose->regions + 1,
384 pci_set_region(hose->regions + 2,
390 hose->region_count = 3;
392 hose->first_busno = first_free_busno;
393 pci_setup_indirect(hose, (int)&pci->cfg_addr,
394 (int)&pci->cfg_data);
398 first_free_busno = hose->last_busno + 1;
399 printf(" PCI-Express 2 on bus %02x - %02x\n",
400 hose->first_busno, hose->last_busno);
402 puts(" PCI-Express 2: Disabled\n");
405 puts("PCI-Express 2: Disabled\n");
406 #endif /* CONFIG_PCIE2 */
411 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CFG_PCI1_ADDR;
412 extern void fsl_pci_init(struct pci_controller *hose);
413 struct pci_controller *hose = &pci1_hose;
414 int pci_agent = (host_agent >= 4) && (host_agent <= 6);
416 if ( !(devdisr & MPC86xx_DEVDISR_PCI1)) {
417 printf(" PCI connected to PCI slots as %s" \
418 " (base address %x)\n",
419 pci_agent ? "Agent" : "Host",
423 pci_set_region(hose->regions + 0,
427 PCI_REGION_MEM | PCI_REGION_MEMORY);
429 /* outbound memory */
430 pci_set_region(hose->regions + 1,
437 pci_set_region(hose->regions + 2,
443 hose->region_count = 3;
445 hose->first_busno = first_free_busno;
446 pci_setup_indirect(hose, (int) &pci->cfg_addr,
447 (int) &pci->cfg_data);
451 first_free_busno = hose->last_busno + 1;
452 printf(" PCI on bus %02x - %02x\n",
453 hose->first_busno, hose->last_busno);
457 puts(" PCI: Disabled\n");
459 #endif /* CONFIG_PCI1 */
462 #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
464 ft_board_setup(void *blob, bd_t *bd)
469 ft_cpu_setup(blob, bd);
471 p = ft_get_prop(blob, "/memory/reg", &len);
473 *p++ = cpu_to_be32(bd->bi_memstart);
474 *p = cpu_to_be32(bd->bi_memsize);
478 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8000/bus-range", &len);
481 p[1] = pci1_hose.last_busno - pci1_hose.first_busno;
482 debug("pci@8000 first_busno=%d last_busno=%d\n",p[0],p[1]);
486 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pcie@a000/bus-range", &len);
489 p[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
490 debug("pcie@9000 first_busno=%d last_busno=%d\n",p[0],p[1]);
494 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pcie@9000/bus-range", &len);
497 p[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
498 debug("pcie@9000 first_busno=%d last_busno=%d\n",p[0],p[1]);
507 * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
511 get_board_sys_clk(ulong dummy)
517 a = PIXIS_BASE + PIXIS_SPD;