2 * Copyright (C) 2007,2010 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
5 * CREDITS: Kim Phillips contribute to LIBFDT code
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.
17 #include <asm/fsl_mpc83xx_serdes.h>
18 #include <asm/fsl_enet.h>
19 #include <spd_sdram.h>
22 #include <fdt_support.h>
23 #include <fsl_esdhc.h>
27 #include "../common/pq-mds-pib.h"
29 int board_early_init_f(void)
31 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
33 /* Enable flash write */
35 /* Clear all of the interrupt of BCSR */
38 #ifdef CONFIG_FSL_SERDES
39 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
40 u32 spridr = in_be32(&immr->sysconf.spridr);
42 /* we check only part num, and don't look for CPU revisions */
43 switch (PARTID_NO_E(spridr)) {
45 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
46 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
49 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SGMII,
50 FSL_SERDES_CLK_125, FSL_SERDES_VDD_1V);
53 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
54 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
55 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
56 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
59 printf("serdes not configured: unknown CPU part number: "
60 "%04x\n", spridr >> 16);
63 #endif /* CONFIG_FSL_SERDES */
67 #ifdef CONFIG_FSL_ESDHC
68 int board_mmc_init(bd_t *bd)
70 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
71 u8 *bcsr = (u8 *)CONFIG_SYS_BCSR;
73 if (!hwconfig("esdhc"))
76 /* Set SPI_SD, SER_SD, and IRQ4_WP so that SD signals go through */
79 /* Set proper bits in SICR to allow SD signals through */
80 clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
81 clrsetbits_be32(&im->sysconf.sicrh, SICRH_GPIO2_E | SICRH_SPI,
82 SICRH_GPIO2_E_SD | SICRH_SPI_SD);
84 return fsl_esdhc_mmc_init(bd);
88 #if defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2)
89 int board_eth_init(bd_t *bd)
91 struct fsl_pq_mdio_info mdio_info;
92 struct tsec_info_struct tsec_info[2];
93 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
94 u32 rcwh = in_be32(&im->reset.rcwh);
98 /* New line after Net: */
102 SET_STD_TSEC_INFO(tsec_info[num], 1);
104 printf(CONFIG_TSEC1_NAME ": ");
106 tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
107 if (tsec_mode == HRCWH_TSEC1M_IN_RGMII) {
109 /* this is default, no need to fixup */
110 } else if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) {
112 tsec_info[num].phyaddr = TSEC1_PHY_ADDR_SGMII;
113 tsec_info[num].flags = TSEC_GIGABIT;
115 printf("unsupported PHY type\n");
120 SET_STD_TSEC_INFO(tsec_info[num], 2);
122 printf(CONFIG_TSEC2_NAME ": ");
124 tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
125 if (tsec_mode == HRCWH_TSEC2M_IN_RGMII) {
127 /* this is default, no need to fixup */
128 } else if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) {
130 tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII;
131 tsec_info[num].flags = TSEC_GIGABIT;
133 printf("unsupported PHY type\n");
138 mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR;
139 mdio_info.name = DEFAULT_MII_NAME;
140 fsl_pq_mdio_init(bd, &mdio_info);
142 return tsec_eth_init(bd, tsec_info, num);
145 static void __ft_tsec_fixup(void *blob, bd_t *bd, const char *alias,
152 off = fdt_path_offset(blob, alias);
154 printf("WARNING: could not find %s alias: %s.\n", alias,
159 err = fdt_fixup_phy_connection(blob, off, PHY_INTERFACE_MODE_SGMII);
162 printf("WARNING: could not set phy-connection-type for %s: "
163 "%s.\n", alias, fdt_strerror(err));
167 ph = (u32 *)fdt_getprop(blob, off, "phy-handle", 0);
169 printf("WARNING: could not get phy-handle for %s.\n",
174 off = fdt_node_offset_by_phandle(blob, *ph);
176 printf("WARNING: could not get phy node for %s: %s\n", alias,
181 phy_addr = cpu_to_fdt32(phy_addr);
182 err = fdt_setprop(blob, off, "reg", &phy_addr, sizeof(phy_addr));
184 printf("WARNING: could not set phy node's reg for %s: "
185 "%s.\n", alias, fdt_strerror(err));
190 static void ft_tsec_fixup(void *blob, bd_t *bd)
192 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
193 u32 rcwh = in_be32(&im->reset.rcwh);
197 tsec_mode = rcwh & HRCWH_TSEC1M_MASK;
198 if (tsec_mode == HRCWH_TSEC1M_IN_SGMII)
199 __ft_tsec_fixup(blob, bd, "ethernet0", TSEC1_PHY_ADDR_SGMII);
203 tsec_mode = rcwh & HRCWH_TSEC2M_MASK;
204 if (tsec_mode == HRCWH_TSEC2M_IN_SGMII)
205 __ft_tsec_fixup(blob, bd, "ethernet1", TSEC2_PHY_ADDR_SGMII);
209 static inline void ft_tsec_fixup(void *blob, bd_t *bd) {}
210 #endif /* defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) */
212 int board_early_init_r(void)
214 #ifdef CONFIG_PQ_MDS_PIB
220 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
221 extern void ddr_enable_ecc(unsigned int dram_size);
223 int fixed_sdram(void);
225 phys_size_t initdram(int board_type)
227 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
230 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
233 #if defined(CONFIG_SPD_EEPROM)
236 msize = fixed_sdram();
239 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
240 /* Initialize DDR ECC byte */
241 ddr_enable_ecc(msize * 1024 * 1024);
244 /* return total bus DDR size(bytes) */
245 return (msize * 1024 * 1024);
248 #if !defined(CONFIG_SPD_EEPROM)
249 /*************************************************************************
250 * fixed sdram init -- doesn't use serial presence detect.
251 ************************************************************************/
252 int fixed_sdram(void)
254 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
255 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
256 u32 msize_log2 = __ilog2(msize);
258 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
259 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
261 #if (CONFIG_SYS_DDR_SIZE != 512)
262 #warning Currenly any ddr size other than 512 is not supported
264 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
267 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
270 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
271 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
274 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
275 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
276 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
277 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
278 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
279 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
280 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
281 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
282 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
283 __asm__ __volatile__("sync");
286 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
288 return CONFIG_SYS_DDR_SIZE;
290 #endif /*!CONFIG_SYS_SPD_EEPROM */
294 puts("Board: Freescale MPC837xEMDS\n");
299 int board_pci_host_broken(void)
301 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
302 const u32 rcw_mask = HRCWH_PCI1_ARBITER_ENABLE | HRCWH_PCI_HOST;
304 /* It's always OK in case of external arbiter. */
305 if (hwconfig_subarg_cmp("pci", "arbiter", "external"))
308 if ((in_be32(&im->reset.rcwh) & rcw_mask) != rcw_mask)
314 static void ft_pci_fixup(void *blob, bd_t *bd)
316 const char *status = "broken (no arbiter)";
320 off = fdt_path_offset(blob, "pci0");
322 printf("WARNING: could not find pci0 alias: %s.\n",
327 err = fdt_setprop(blob, off, "status", status, strlen(status) + 1);
329 printf("WARNING: could not set status for pci0: %s.\n",
336 #if defined(CONFIG_OF_BOARD_SETUP)
337 void ft_board_setup(void *blob, bd_t *bd)
339 ft_cpu_setup(blob, bd);
340 ft_tsec_fixup(blob, bd);
341 fdt_fixup_dr_usb(blob, bd);
342 fdt_fixup_esdhc(blob, bd);
344 ft_pci_setup(blob, bd);
345 if (board_pci_host_broken())
346 ft_pci_fixup(blob, bd);
347 ft_pcie_fixup(blob, bd);
350 #endif /* CONFIG_OF_BOARD_SETUP */