2 * Copyright 2008 Freescale Semiconductor.
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>
28 #include <asm/cache.h>
29 #include <asm/immap_85xx.h>
30 #include <asm/immap_fsl_pci.h>
31 #include <asm/fsl_ddr_sdram.h>
36 #include <spd_sdram.h>
37 #include <fdt_support.h>
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 phys_size_t fixed_sdram(void);
49 printf ("Board: MPC8536DS, System ID: 0x%02x, "
50 "System Version: 0x%02x, FPGA Version: 0x%02x\n",
51 in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER),
52 in8(PIXIS_BASE + PIXIS_PVER));
57 initdram(int board_type)
59 phys_size_t dram_size = 0;
61 puts("Initializing....");
63 #ifdef CONFIG_SPD_EEPROM
64 dram_size = fsl_ddr_sdram();
66 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
68 dram_size *= 0x100000;
70 dram_size = fixed_sdram();
73 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
75 * Initialize and enable DDR ECC.
77 ddr_enable_ecc(dram_size);
83 #if !defined(CONFIG_SPD_EEPROM)
85 * Fixed sdram init -- doesn't use serial presence detect.
88 phys_size_t fixed_sdram (void)
90 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
91 volatile ccsr_ddr_t *ddr= &immap->im_ddr;
94 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
95 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
97 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
98 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
99 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
100 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
101 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
102 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
103 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
104 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
105 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
106 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
108 #if defined (CONFIG_DDR_ECC)
109 ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
110 ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
111 ddr->err_sbe = CONFIG_SYS_DDR_SBE;
117 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
119 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
121 debug("DDR - 1st controller: memory initializing\n");
123 * Poll until memory is initialized.
124 * 512 Meg at 400 might hit this 200 times or so.
126 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) {
129 debug("DDR: memory initialized\n\n");
134 return 512 * 1024 * 1024;
140 static struct pci_controller pci1_hose;
144 static struct pci_controller pcie1_hose;
148 static struct pci_controller pcie2_hose;
152 static struct pci_controller pcie3_hose;
155 int first_free_busno=0;
160 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
161 uint devdisr = gur->devdisr;
163 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
164 uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
165 uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16;
167 debug(" pci_init_board: devdisr=%x, sdrs2_io_sel=%x, io_sel=%x,\
168 host_agent=%x\n", devdisr, sdrs2_io_sel, io_sel, host_agent);
170 if (sdrs2_io_sel == 7)
171 printf(" Serdes2 disalbed\n");
172 else if (sdrs2_io_sel == 4) {
173 printf(" eTSEC1 is in sgmii mode.\n");
174 printf(" eTSEC3 is in sgmii mode.\n");
175 } else if (sdrs2_io_sel == 6)
176 printf(" eTSEC1 is in sgmii mode.\n");
180 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR;
181 extern void fsl_pci_init(struct pci_controller *hose);
182 struct pci_controller *hose = &pcie3_hose;
183 int pcie_ep = (host_agent == 1);
184 int pcie_configured = (io_sel == 7);
186 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
187 printf ("\n PCIE3 connected to Slot3 as %s (base address %x)",
188 pcie_ep ? "End Point" : "Root Complex",
190 if (pci->pme_msg_det) {
191 pci->pme_msg_det = 0xffffffff;
192 debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
197 pci_set_region(hose->regions + 0,
198 CONFIG_SYS_PCI_MEMORY_BUS,
199 CONFIG_SYS_PCI_MEMORY_PHYS,
200 CONFIG_SYS_PCI_MEMORY_SIZE,
201 PCI_REGION_MEM | PCI_REGION_MEMORY);
203 /* outbound memory */
204 pci_set_region(hose->regions + 1,
205 CONFIG_SYS_PCIE3_MEM_BASE,
206 CONFIG_SYS_PCIE3_MEM_PHYS,
207 CONFIG_SYS_PCIE3_MEM_SIZE,
211 pci_set_region(hose->regions + 2,
212 CONFIG_SYS_PCIE3_IO_BASE,
213 CONFIG_SYS_PCIE3_IO_PHYS,
214 CONFIG_SYS_PCIE3_IO_SIZE,
217 hose->region_count = 3;
219 hose->first_busno=first_free_busno;
220 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
224 first_free_busno=hose->last_busno+1;
225 printf (" PCIE3 on bus %02x - %02x\n",
226 hose->first_busno,hose->last_busno);
228 printf (" PCIE3: disabled\n");
233 gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */
238 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR;
239 extern void fsl_pci_init(struct pci_controller *hose);
240 struct pci_controller *hose = &pcie1_hose;
241 int pcie_ep = (host_agent == 5);
242 int pcie_configured = (io_sel == 2 || io_sel == 3
243 || io_sel == 5 || io_sel == 7);
245 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
246 printf ("\n PCIE1 connected to Slot1 as %s (base address %x)",
247 pcie_ep ? "End Point" : "Root Complex",
249 if (pci->pme_msg_det) {
250 pci->pme_msg_det = 0xffffffff;
251 debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
256 pci_set_region(hose->regions + 0,
257 CONFIG_SYS_PCI_MEMORY_BUS,
258 CONFIG_SYS_PCI_MEMORY_PHYS,
259 CONFIG_SYS_PCI_MEMORY_SIZE,
260 PCI_REGION_MEM | PCI_REGION_MEMORY);
262 /* outbound memory */
263 pci_set_region(hose->regions + 1,
264 CONFIG_SYS_PCIE1_MEM_BASE,
265 CONFIG_SYS_PCIE1_MEM_PHYS,
266 CONFIG_SYS_PCIE1_MEM_SIZE,
270 pci_set_region(hose->regions + 2,
271 CONFIG_SYS_PCIE1_IO_BASE,
272 CONFIG_SYS_PCIE1_IO_PHYS,
273 CONFIG_SYS_PCIE1_IO_SIZE,
276 hose->region_count = 3;
277 #ifdef CONFIG_SYS_PCIE1_MEM_BASE2
278 /* outbound memory */
279 pci_set_region(hose->regions + 3,
280 CONFIG_SYS_PCIE1_MEM_BASE2,
281 CONFIG_SYS_PCIE1_MEM_PHYS2,
282 CONFIG_SYS_PCIE1_MEM_SIZE2,
284 hose->region_count++;
286 hose->first_busno=first_free_busno;
288 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
292 first_free_busno=hose->last_busno+1;
293 printf(" PCIE1 on bus %02x - %02x\n",
294 hose->first_busno,hose->last_busno);
297 printf (" PCIE1: disabled\n");
302 gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */
307 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR;
308 extern void fsl_pci_init(struct pci_controller *hose);
309 struct pci_controller *hose = &pcie2_hose;
310 int pcie_ep = (host_agent == 3);
311 int pcie_configured = (io_sel == 5 || io_sel == 7);
313 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){
314 printf ("\n PCIE2 connected to Slot 2 as %s (base address %x)",
315 pcie_ep ? "End Point" : "Root Complex",
317 if (pci->pme_msg_det) {
318 pci->pme_msg_det = 0xffffffff;
319 debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det);
324 pci_set_region(hose->regions + 0,
325 CONFIG_SYS_PCI_MEMORY_BUS,
326 CONFIG_SYS_PCI_MEMORY_PHYS,
327 CONFIG_SYS_PCI_MEMORY_SIZE,
328 PCI_REGION_MEM | PCI_REGION_MEMORY);
330 /* outbound memory */
331 pci_set_region(hose->regions + 1,
332 CONFIG_SYS_PCIE2_MEM_BASE,
333 CONFIG_SYS_PCIE2_MEM_PHYS,
334 CONFIG_SYS_PCIE2_MEM_SIZE,
338 pci_set_region(hose->regions + 2,
339 CONFIG_SYS_PCIE2_IO_BASE,
340 CONFIG_SYS_PCIE2_IO_PHYS,
341 CONFIG_SYS_PCIE2_IO_SIZE,
344 hose->region_count = 3;
345 #ifdef CONFIG_SYS_PCIE2_MEM_BASE2
346 /* outbound memory */
347 pci_set_region(hose->regions + 3,
348 CONFIG_SYS_PCIE2_MEM_BASE2,
349 CONFIG_SYS_PCIE2_MEM_PHYS2,
350 CONFIG_SYS_PCIE2_MEM_SIZE2,
352 hose->region_count++;
354 hose->first_busno=first_free_busno;
355 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
358 first_free_busno=hose->last_busno+1;
359 printf (" PCIE2 on bus %02x - %02x\n",
360 hose->first_busno,hose->last_busno);
363 printf (" PCIE2: disabled\n");
368 gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */
374 volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR;
375 extern void fsl_pci_init(struct pci_controller *hose);
376 struct pci_controller *hose = &pci1_hose;
378 uint pci_agent = (host_agent == 6);
379 uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */
381 uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */
382 uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */
385 if (!(devdisr & MPC85xx_DEVDISR_PCI1)) {
386 printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n",
388 (pci_speed == 33333000) ? "33" :
389 (pci_speed == 66666000) ? "66" : "unknown",
390 pci_clk_sel ? "sync" : "async",
391 pci_agent ? "agent" : "host",
392 pci_arb ? "arbiter" : "external-arbiter",
397 pci_set_region(hose->regions + 0,
398 CONFIG_SYS_PCI_MEMORY_BUS,
399 CONFIG_SYS_PCI_MEMORY_PHYS,
400 CONFIG_SYS_PCI_MEMORY_SIZE,
401 PCI_REGION_MEM | PCI_REGION_MEMORY);
403 /* outbound memory */
404 pci_set_region(hose->regions + 1,
405 CONFIG_SYS_PCI1_MEM_BASE,
406 CONFIG_SYS_PCI1_MEM_PHYS,
407 CONFIG_SYS_PCI1_MEM_SIZE,
411 pci_set_region(hose->regions + 2,
412 CONFIG_SYS_PCI1_IO_BASE,
413 CONFIG_SYS_PCI1_IO_PHYS,
414 CONFIG_SYS_PCI1_IO_SIZE,
416 hose->region_count = 3;
417 #ifdef CONFIG_SYS_PCI1_MEM_BASE2
418 /* outbound memory */
419 pci_set_region(hose->regions + 3,
420 CONFIG_SYS_PCI1_MEM_BASE2,
421 CONFIG_SYS_PCI1_MEM_PHYS2,
422 CONFIG_SYS_PCI1_MEM_SIZE2,
424 hose->region_count++;
426 hose->first_busno=first_free_busno;
427 pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data);
430 first_free_busno=hose->last_busno+1;
431 printf ("PCI on bus %02x - %02x\n",
432 hose->first_busno,hose->last_busno);
434 printf (" PCI: disabled\n");
438 gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */
443 int board_early_init_r(void)
445 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
446 const u8 flash_esel = 1;
449 * Remap Boot flash + PROMJET region to caching-inhibited
450 * so that flash can be erased properly.
453 /* Flush d-cache and invalidate i-cache of any FLASH data */
457 /* invalidate existing TLB entry for flash + promjet */
458 disable_tlb(flash_esel);
460 set_tlb(1, flashbase, flashbase, /* tlb, epn, rpn */
461 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
462 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */
467 #ifdef CONFIG_GET_CLK_FROM_ICS307
468 /* decode S[0-2] to Output Divider (OD) */
471 10, 2, 8, 4, 5, 7, 3, 6
474 /* Calculate frequency being generated by ICS307-02 clock chip based upon
475 * the control bytes being programmed into it. */
476 /* XXX: This function should probably go into a common library */
478 ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2)
480 const unsigned long long InputFrequency = CONFIG_ICS307_REFCLK_HZ;
481 unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
482 unsigned long RDW = cw2 & 0x7F;
483 unsigned long OD = ics307_S_to_OD[cw0 & 0x7];
486 /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */
488 /* cw0: C1 C0 TTL F1 F0 S2 S1 S0
489 * cw1: V8 V7 V6 V5 V4 V3 V2 V1
490 * cw2: V0 R6 R5 R4 R3 R2 R1 R0
492 * R6:R0 = Reference Divider Word (RDW)
493 * V8:V0 = VCO Divider Word (VDW)
494 * S2:S0 = Output Divider Select (OD)
495 * F1:F0 = Function of CLK2 Output
497 * C1:C0 = internal load capacitance for cyrstal
500 /* Adding 1 to get a "nicely" rounded number, but this needs
501 * more tweaking to get a "properly" rounded number. */
503 freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD));
505 debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2,
511 get_board_sys_clk(ulong dummy)
513 return ics307_clk_freq (
514 in8(PIXIS_BASE + PIXIS_VSYSCLK0),
515 in8(PIXIS_BASE + PIXIS_VSYSCLK1),
516 in8(PIXIS_BASE + PIXIS_VSYSCLK2)
521 get_board_ddr_clk(ulong dummy)
523 return ics307_clk_freq (
524 in8(PIXIS_BASE + PIXIS_VDDRCLK0),
525 in8(PIXIS_BASE + PIXIS_VDDRCLK1),
526 in8(PIXIS_BASE + PIXIS_VDDRCLK2)
531 get_board_sys_clk(ulong dummy)
536 i = in8(PIXIS_BASE + PIXIS_SPD);
570 get_board_ddr_clk(ulong dummy)
575 i = in8(PIXIS_BASE + PIXIS_SPD);
609 int is_sata_supported(void)
611 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
612 uint devdisr = gur->devdisr;
614 (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27;
615 if (sdrs2_io_sel & 0x04)
621 #if defined(CONFIG_OF_BOARD_SETUP)
623 ft_board_setup(void *blob, bd_t *bd)
628 ft_cpu_setup(blob, bd);
630 node = fdt_path_offset(blob, "/aliases");
634 path = fdt_getprop(blob, node, "pci0", NULL);
636 tmp[1] = pci1_hose.last_busno - pci1_hose.first_busno;
637 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
641 path = fdt_getprop(blob, node, "pci1", NULL);
643 tmp[1] = pcie2_hose.last_busno - pcie2_hose.first_busno;
644 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
648 path = fdt_getprop(blob, node, "pci2", NULL);
650 tmp[1] = pcie1_hose.last_busno - pcie1_hose.first_busno;
651 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);
655 path = fdt_getprop(blob, node, "pci3", NULL);
657 tmp[1] = pcie3_hose.last_busno - pcie3_hose.first_busno;
658 do_fixup_by_path(blob, path, "bus-range", &tmp, 8, 1);