2 * Copyright 2007-2009 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>
28 #include <asm/cache.h>
29 #include <asm/immap_85xx.h>
30 #include <asm/fsl_pci.h>
31 #include <asm/fsl_ddr_sdram.h>
35 #include <fdt_support.h>
37 #include <asm/fsl_law.h>
41 #include "../common/sgmii_riser.h"
43 DECLARE_GLOBAL_DATA_PTR;
45 phys_size_t fixed_sdram(void);
50 u8 *pixis_base = (u8 *)PIXIS_BASE;
52 puts("Board: P2020DS ");
53 #ifdef CONFIG_PHYS_64BIT
54 puts("(36-bit addrmap) ");
57 printf("Sys ID: 0x%02x, "
58 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
59 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
60 in_8(pixis_base + PIXIS_PVER));
62 sw7 = in_8(pixis_base + PIXIS_SW(7));
63 switch ((sw7 & PIXIS_SW7_LBMAP) >> 6) {
66 printf ("vBank: %d\n", ((sw7 & PIXIS_SW7_VBANK) >> 4));
77 phys_size_t initdram(int board_type)
79 phys_size_t dram_size = 0;
81 puts("Initializing....");
83 #ifdef CONFIG_SPD_EEPROM
84 dram_size = fsl_ddr_sdram();
86 dram_size = fixed_sdram();
88 if (set_ddr_laws(CONFIG_SYS_DDR_SDRAM_BASE,
90 LAW_TRGT_IF_DDR) < 0) {
91 printf("ERROR setting Local Access Windows for DDR\n");
95 dram_size = setup_ddr_tlbs(dram_size / 0x100000);
96 dram_size *= 0x100000;
102 #if !defined(CONFIG_SPD_EEPROM)
104 * Fixed sdram init -- doesn't use serial presence detect.
107 phys_size_t fixed_sdram(void)
109 volatile ccsr_ddr_t *ddr = (ccsr_ddr_t *)CONFIG_SYS_MPC85xx_DDR_ADDR;
112 ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
113 ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
114 ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
115 ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
116 ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
117 ddr->sdram_md_cntl = CONFIG_SYS_DDR_MODE_CTRL;
118 ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
119 ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
120 ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
121 ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
122 ddr->ddr_zq_cntl = CONFIG_SYS_DDR_ZQ_CNTL;
123 ddr->ddr_wrlvl_cntl = CONFIG_SYS_DDR_WRLVL_CNTL;
124 ddr->ddr_cdr1 = CONFIG_SYS_DDR_CDR1;
125 ddr->timing_cfg_4 = CONFIG_SYS_DDR_TIMING_4;
126 ddr->timing_cfg_5 = CONFIG_SYS_DDR_TIMING_5;
128 if (!strcmp("performance", getenv("perf_mode"))) {
129 /* Performance Mode Values */
131 ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG_PERF;
132 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS_PERF;
133 ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS_PERF;
134 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1_PERF;
135 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2_PERF;
141 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL_PERF;
143 /* Stable Mode Values */
145 ddr->cs1_config = CONFIG_SYS_DDR_CS1_CONFIG;
146 ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
147 ddr->cs1_bnds = CONFIG_SYS_DDR_CS1_BNDS;
148 ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
149 ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
151 /* ECC will be assumed in stable mode */
152 ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN;
153 ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS;
154 ddr->err_sbe = CONFIG_SYS_DDR_SBE;
160 ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
163 #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
165 debug("DDR - 1st controller: memory initializing\n");
167 * Poll until memory is initialized.
168 * 512 Meg at 400 might hit this 200 times or so.
170 while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0)
172 debug("DDR: memory initialized\n\n");
177 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
183 static struct pci_controller pcie1_hose;
187 static struct pci_controller pcie2_hose;
191 static struct pci_controller pcie3_hose;
195 void pci_init_board(void)
197 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
198 struct fsl_pci_info pci_info[3];
199 u32 devdisr, pordevsr, io_sel;
200 int first_free_busno = 0;
203 int pcie_ep, pcie_configured;
205 devdisr = in_be32(&gur->devdisr);
206 pordevsr = in_be32(&gur->pordevsr);
207 io_sel = (pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19;
209 debug (" pci_init_board: devdisr=%x, io_sel=%x\n", devdisr, io_sel);
211 if (!(pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
212 printf(" eTSEC2 is in sgmii mode.\n");
213 if (!(pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
214 printf(" eTSEC3 is in sgmii mode.\n");
218 pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_2, io_sel);
220 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE2)) {
221 SET_STD_PCIE_INFO(pci_info[num], 2);
222 pcie_ep = fsl_setup_hose(&pcie2_hose, pci_info[num].regs);
223 printf(" PCIE2 connected to ULI as %s (base addr %lx)\n",
224 pcie_ep ? "Endpoint" : "Root Complex",
226 first_free_busno = fsl_pci_init_port(&pci_info[num++],
227 &pcie2_hose, first_free_busno);
230 * The workaround doesn't work on p2020 because the location
231 * we try and read isn't valid on p2020, fix this later
235 * Activate ULI1575 legacy chip by performing a fake
236 * memory access. Needed to make ULI RTC work.
237 * Device 1d has the first on-board memory BAR.
240 pci_hose_read_config_dword(hose, PCI_BDF(2, 0x1d, 0),
241 PCI_BASE_ADDRESS_1, &temp32);
242 if (temp32 >= CONFIG_SYS_PCIE3_MEM_BUS) {
243 void *p = pci_mem_to_virt(PCI_BDF(2, 0x1d, 0),
245 debug(" uli1575 read to %p\n", p);
250 printf(" PCIE2: disabled\n");
254 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE2); /* disable */
258 pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_3, io_sel);
260 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE3)) {
261 SET_STD_PCIE_INFO(pci_info[num], 3);
262 pcie_ep = fsl_setup_hose(&pcie3_hose, pci_info[num].regs);
263 printf(" PCIE3 connected to Slot 1 as %s (base addr %lx)\n",
264 pcie_ep ? "Endpoint" : "Root Complex",
266 first_free_busno = fsl_pci_init_port(&pci_info[num++],
267 &pcie3_hose, first_free_busno);
269 printf(" PCIE3: disabled\n");
273 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE3); /* disable */
277 pcie_configured = is_fsl_pci_cfg(LAW_TRGT_IF_PCIE_1, io_sel);
279 if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)) {
280 SET_STD_PCIE_INFO(pci_info[num], 1);
281 pcie_ep = fsl_setup_hose(&pcie1_hose, pci_info[num].regs);
282 printf(" PCIE1 connected to Slot 2 as %s (base addr %lx)\n",
283 pcie_ep ? "Endpoint" : "Root Complex",
285 first_free_busno = fsl_pci_init_port(&pci_info[num++],
286 &pcie1_hose, first_free_busno);
288 printf(" PCIE1: disabled\n");
292 setbits_be32(&gur->devdisr, MPC85xx_DEVDISR_PCIE); /* disable */
297 int board_early_init_r(void)
299 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
300 const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
303 * Remap Boot flash + PROMJET region to caching-inhibited
304 * so that flash can be erased properly.
307 /* Flush d-cache and invalidate i-cache of any FLASH data */
311 /* invalidate existing TLB entry for flash + promjet */
312 disable_tlb(flash_esel);
314 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
315 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
316 0, flash_esel, BOOKE_PAGESZ_256M, 1);
321 #ifdef CONFIG_GET_CLK_FROM_ICS307
322 /* decode S[0-2] to Output Divider (OD) */
323 static unsigned char ics307_S_to_OD[] = {
324 10, 2, 8, 4, 5, 7, 3, 6
327 /* Calculate frequency being generated by ICS307-02 clock chip based upon
328 * the control bytes being programmed into it. */
329 /* XXX: This function should probably go into a common library */
331 ics307_clk_freq(unsigned char cw0, unsigned char cw1, unsigned char cw2)
333 const unsigned long InputFrequency = CONFIG_ICS307_REFCLK_HZ;
334 unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
335 unsigned long RDW = cw2 & 0x7F;
336 unsigned long OD = ics307_S_to_OD[cw0 & 0x7];
339 /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */
341 /* cw0: C1 C0 TTL F1 F0 S2 S1 S0
342 * cw1: V8 V7 V6 V5 V4 V3 V2 V1
343 * cw2: V0 R6 R5 R4 R3 R2 R1 R0
345 * R6:R0 = Reference Divider Word (RDW)
346 * V8:V0 = VCO Divider Word (VDW)
347 * S2:S0 = Output Divider Select (OD)
348 * F1:F0 = Function of CLK2 Output
350 * C1:C0 = internal load capacitance for cyrstal
353 /* Adding 1 to get a "nicely" rounded number, but this needs
354 * more tweaking to get a "properly" rounded number. */
356 freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD));
358 debug("ICS307: CW[0-2]: %02X %02X %02X => %lu Hz\n", cw0, cw1, cw2,
363 unsigned long get_board_sys_clk(ulong dummy)
368 unsigned long get_board_ddr_clk(ulong dummy)
374 calculate_board_sys_clk(ulong dummy)
377 u8 *pixis_base = (u8 *)PIXIS_BASE;
379 val = ics307_clk_freq(
380 in_8(pixis_base + PIXIS_VSYSCLK0),
381 in_8(pixis_base + PIXIS_VSYSCLK1),
382 in_8(pixis_base + PIXIS_VSYSCLK2));
383 debug("sysclk val = %lu\n", val);
388 calculate_board_ddr_clk(ulong dummy)
391 u8 *pixis_base = (u8 *)PIXIS_BASE;
393 val = ics307_clk_freq(
394 in_8(pixis_base + PIXIS_VDDRCLK0),
395 in_8(pixis_base + PIXIS_VDDRCLK1),
396 in_8(pixis_base + PIXIS_VDDRCLK2));
397 debug("ddrclk val = %lu\n", val);
401 unsigned long get_board_sys_clk(ulong dummy)
405 u8 *pixis_base = (u8 *)PIXIS_BASE;
407 i = in_8(pixis_base + PIXIS_SPD);
440 unsigned long get_board_ddr_clk(ulong dummy)
444 u8 *pixis_base = (u8 *)PIXIS_BASE;
446 i = in_8(pixis_base + PIXIS_SPD);
480 #ifdef CONFIG_TSEC_ENET
481 int board_eth_init(bd_t *bis)
483 struct tsec_info_struct tsec_info[4];
484 volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
488 SET_STD_TSEC_INFO(tsec_info[num], 1);
492 SET_STD_TSEC_INFO(tsec_info[num], 2);
493 if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII2_DIS))
494 tsec_info[num].flags |= TSEC_SGMII;
498 SET_STD_TSEC_INFO(tsec_info[num], 3);
499 if (!(gur->pordevsr & MPC85xx_PORDEVSR_SGMII3_DIS))
500 tsec_info[num].flags |= TSEC_SGMII;
505 printf("No TSECs initialized\n");
510 #ifdef CONFIG_FSL_SGMII_RISER
511 fsl_sgmii_riser_init(tsec_info, num);
514 tsec_eth_init(bis, tsec_info, num);
516 return pci_eth_init(bis);
520 #if defined(CONFIG_OF_BOARD_SETUP)
521 void ft_board_setup(void *blob, bd_t *bd)
526 ft_cpu_setup(blob, bd);
528 base = getenv_bootm_low();
529 size = getenv_bootm_size();
531 fdt_fixup_memory(blob, (u64)base, (u64)size);
534 ft_fsl_pci_setup(blob, "pci0", &pcie3_hose);
537 ft_fsl_pci_setup(blob, "pci1", &pcie2_hose);
540 ft_fsl_pci_setup(blob, "pci2", &pcie1_hose);
542 #ifdef CONFIG_FSL_SGMII_RISER
543 fsl_sgmii_riser_fdt_fixup(blob);
549 void board_lmb_reserve(struct lmb *lmb)
551 cpu_mp_lmb_reserve(lmb);