Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 Freescale Semiconductor, Inc. |
| 3 | * Dave Liu <daveliu@freescale.com> |
| 4 | * |
| 5 | * CREDITS: Kim Phillips contribute to LIBFDT code |
| 6 | * |
| 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. |
| 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <i2c.h> |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 15 | #include <asm/io.h> |
| 16 | #include <asm/fsl_serdes.h> |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 17 | #include <spd_sdram.h> |
Anton Vorontsov | 32b1b70 | 2008-10-02 18:32:25 +0400 | [diff] [blame] | 18 | #include <tsec.h> |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 19 | #include <libfdt.h> |
Anton Vorontsov | 504867a | 2008-10-14 22:58:53 +0400 | [diff] [blame] | 20 | #include <fdt_support.h> |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 21 | #include "../common/pq-mds-pib.h" |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 22 | |
| 23 | int board_early_init_f(void) |
| 24 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 25 | u8 *bcsr = (u8 *)CONFIG_SYS_BCSR; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 26 | |
| 27 | /* Enable flash write */ |
| 28 | bcsr[0x9] &= ~0x04; |
| 29 | /* Clear all of the interrupt of BCSR */ |
| 30 | bcsr[0xe] = 0xff; |
| 31 | |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 32 | #ifdef CONFIG_FSL_SERDES |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 34 | u32 spridr = in_be32(&immr->sysconf.spridr); |
| 35 | |
| 36 | /* we check only part num, and don't look for CPU revisions */ |
Dave Liu | 1f2f86e | 2008-03-31 17:05:12 +0800 | [diff] [blame] | 37 | switch (PARTID_NO_E(spridr)) { |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 38 | case SPR_8377: |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 39 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
| 40 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 41 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 42 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 43 | break; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 44 | case SPR_8378: |
Anton Vorontsov | 32b1b70 | 2008-10-02 18:32:25 +0400 | [diff] [blame] | 45 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SGMII, |
| 46 | FSL_SERDES_CLK_125, FSL_SERDES_VDD_1V); |
Anton Vorontsov | 642016b | 2008-10-02 18:31:53 +0400 | [diff] [blame] | 47 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 48 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 49 | break; |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 50 | case SPR_8379: |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 51 | fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
| 52 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
Kim Phillips | ecb2d6f | 2008-03-28 10:19:07 -0500 | [diff] [blame] | 53 | fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA, |
Dave Liu | b8dc587 | 2008-03-26 22:56:36 +0800 | [diff] [blame] | 54 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
| 55 | break; |
| 56 | default: |
| 57 | printf("serdes not configured: unknown CPU part number: " |
| 58 | "%04x\n", spridr >> 16); |
| 59 | break; |
| 60 | } |
| 61 | #endif /* CONFIG_FSL_SERDES */ |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 62 | return 0; |
| 63 | } |
| 64 | |
Anton Vorontsov | 32b1b70 | 2008-10-02 18:32:25 +0400 | [diff] [blame] | 65 | #if defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) |
| 66 | int board_eth_init(bd_t *bd) |
| 67 | { |
| 68 | struct tsec_info_struct tsec_info[2]; |
| 69 | struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR; |
| 70 | u32 rcwh = in_be32(&im->reset.rcwh); |
| 71 | u32 tsec_mode; |
| 72 | int num = 0; |
| 73 | |
| 74 | /* New line after Net: */ |
| 75 | printf("\n"); |
| 76 | |
| 77 | #ifdef CONFIG_TSEC1 |
| 78 | SET_STD_TSEC_INFO(tsec_info[num], 1); |
| 79 | |
| 80 | printf(CONFIG_TSEC1_NAME ": "); |
| 81 | |
| 82 | tsec_mode = rcwh & HRCWH_TSEC1M_MASK; |
| 83 | if (tsec_mode == HRCWH_TSEC1M_IN_RGMII) { |
| 84 | printf("RGMII\n"); |
| 85 | /* this is default, no need to fixup */ |
| 86 | } else if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) { |
| 87 | printf("SGMII\n"); |
| 88 | tsec_info[num].phyaddr = TSEC1_PHY_ADDR_SGMII; |
| 89 | tsec_info[num].flags = TSEC_GIGABIT; |
| 90 | } else { |
| 91 | printf("unsupported PHY type\n"); |
| 92 | } |
| 93 | num++; |
| 94 | #endif |
| 95 | #ifdef CONFIG_TSEC2 |
| 96 | SET_STD_TSEC_INFO(tsec_info[num], 2); |
| 97 | |
| 98 | printf(CONFIG_TSEC2_NAME ": "); |
| 99 | |
| 100 | tsec_mode = rcwh & HRCWH_TSEC2M_MASK; |
| 101 | if (tsec_mode == HRCWH_TSEC2M_IN_RGMII) { |
| 102 | printf("RGMII\n"); |
| 103 | /* this is default, no need to fixup */ |
| 104 | } else if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) { |
| 105 | printf("SGMII\n"); |
| 106 | tsec_info[num].phyaddr = TSEC2_PHY_ADDR_SGMII; |
| 107 | tsec_info[num].flags = TSEC_GIGABIT; |
| 108 | } else { |
| 109 | printf("unsupported PHY type\n"); |
| 110 | } |
| 111 | num++; |
| 112 | #endif |
| 113 | return tsec_eth_init(bd, tsec_info, num); |
| 114 | } |
| 115 | |
| 116 | static void __ft_tsec_fixup(void *blob, bd_t *bd, const char *alias, |
| 117 | int phy_addr) |
| 118 | { |
| 119 | const char *phy_type = "sgmii"; |
| 120 | const u32 *ph; |
| 121 | int off; |
| 122 | int err; |
| 123 | |
| 124 | off = fdt_path_offset(blob, alias); |
| 125 | if (off < 0) { |
| 126 | printf("WARNING: could not find %s alias: %s.\n", alias, |
| 127 | fdt_strerror(off)); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | err = fdt_setprop(blob, off, "phy-connection-type", phy_type, |
| 132 | strlen(phy_type) + 1); |
| 133 | if (err) { |
| 134 | printf("WARNING: could not set phy-connection-type for %s: " |
| 135 | "%s.\n", alias, fdt_strerror(err)); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | ph = (u32 *)fdt_getprop(blob, off, "phy-handle", 0); |
| 140 | if (!ph) { |
| 141 | printf("WARNING: could not get phy-handle for %s.\n", |
| 142 | alias); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | off = fdt_node_offset_by_phandle(blob, *ph); |
| 147 | if (off < 0) { |
| 148 | printf("WARNING: could not get phy node for %s: %s\n", alias, |
| 149 | fdt_strerror(off)); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | phy_addr = cpu_to_fdt32(phy_addr); |
| 154 | err = fdt_setprop(blob, off, "reg", &phy_addr, sizeof(phy_addr)); |
| 155 | if (err < 0) { |
| 156 | printf("WARNING: could not set phy node's reg for %s: " |
| 157 | "%s.\n", alias, fdt_strerror(err)); |
| 158 | return; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | static void ft_tsec_fixup(void *blob, bd_t *bd) |
| 163 | { |
| 164 | struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR; |
| 165 | u32 rcwh = in_be32(&im->reset.rcwh); |
| 166 | u32 tsec_mode; |
| 167 | |
| 168 | #ifdef CONFIG_TSEC1 |
| 169 | tsec_mode = rcwh & HRCWH_TSEC1M_MASK; |
| 170 | if (tsec_mode == HRCWH_TSEC1M_IN_SGMII) |
| 171 | __ft_tsec_fixup(blob, bd, "ethernet0", TSEC1_PHY_ADDR_SGMII); |
| 172 | #endif |
| 173 | |
| 174 | #ifdef CONFIG_TSEC2 |
| 175 | tsec_mode = rcwh & HRCWH_TSEC2M_MASK; |
| 176 | if (tsec_mode == HRCWH_TSEC2M_IN_SGMII) |
| 177 | __ft_tsec_fixup(blob, bd, "ethernet1", TSEC2_PHY_ADDR_SGMII); |
| 178 | #endif |
| 179 | } |
| 180 | #else |
| 181 | static inline void ft_tsec_fixup(void *blob, bd_t *bd) {} |
| 182 | #endif /* defined(CONFIG_TSEC1) || defined(CONFIG_TSEC2) */ |
| 183 | |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 184 | int board_early_init_r(void) |
| 185 | { |
| 186 | #ifdef CONFIG_PQ_MDS_PIB |
| 187 | pib_init(); |
| 188 | #endif |
| 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
| 193 | extern void ddr_enable_ecc(unsigned int dram_size); |
| 194 | #endif |
| 195 | int fixed_sdram(void); |
| 196 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 197 | phys_size_t initdram(int board_type) |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 198 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 199 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 200 | u32 msize = 0; |
| 201 | |
| 202 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) |
| 203 | return -1; |
| 204 | |
| 205 | #if defined(CONFIG_SPD_EEPROM) |
| 206 | msize = spd_sdram(); |
| 207 | #else |
| 208 | msize = fixed_sdram(); |
| 209 | #endif |
| 210 | |
| 211 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC) |
| 212 | /* Initialize DDR ECC byte */ |
| 213 | ddr_enable_ecc(msize * 1024 * 1024); |
| 214 | #endif |
| 215 | |
| 216 | /* return total bus DDR size(bytes) */ |
| 217 | return (msize * 1024 * 1024); |
| 218 | } |
| 219 | |
| 220 | #if !defined(CONFIG_SPD_EEPROM) |
| 221 | /************************************************************************* |
| 222 | * fixed sdram init -- doesn't use serial presence detect. |
| 223 | ************************************************************************/ |
| 224 | int fixed_sdram(void) |
| 225 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 226 | volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
| 227 | u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 228 | u32 msize_log2 = __ilog2(msize); |
| 229 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 230 | im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 231 | im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); |
| 232 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 233 | #if (CONFIG_SYS_DDR_SIZE != 512) |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 234 | #warning Currenly any ddr size other than 512 is not supported |
| 235 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 236 | im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 237 | udelay(50000); |
| 238 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 239 | im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 240 | udelay(1000); |
| 241 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 242 | im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 243 | im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 244 | udelay(1000); |
| 245 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 246 | im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 247 | im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 248 | im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 249 | im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 250 | im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG; |
| 251 | im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2; |
| 252 | im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE; |
| 253 | im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2; |
| 254 | im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 255 | __asm__ __volatile__("sync"); |
| 256 | udelay(1000); |
| 257 | |
| 258 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; |
| 259 | udelay(2000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 260 | return CONFIG_SYS_DDR_SIZE; |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 261 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 262 | #endif /*!CONFIG_SYS_SPD_EEPROM */ |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 263 | |
| 264 | int checkboard(void) |
| 265 | { |
| 266 | puts("Board: Freescale MPC837xEMDS\n"); |
| 267 | return 0; |
| 268 | } |
| 269 | |
Anton Vorontsov | 30c6992 | 2008-10-02 19:17:33 +0400 | [diff] [blame] | 270 | #ifdef CONFIG_PCI |
| 271 | int board_pci_host_broken(void) |
| 272 | { |
| 273 | struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR; |
| 274 | const u32 rcw_mask = HRCWH_PCI1_ARBITER_ENABLE | HRCWH_PCI_HOST; |
| 275 | const char *pci_ea = getenv("pci_external_arbiter"); |
| 276 | |
| 277 | /* It's always OK in case of external arbiter. */ |
| 278 | if (pci_ea && !strcmp(pci_ea, "yes")) |
| 279 | return 0; |
| 280 | |
| 281 | if ((in_be32(&im->reset.rcwh) & rcw_mask) != rcw_mask) |
| 282 | return 1; |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | static void ft_pci_fixup(void *blob, bd_t *bd) |
| 288 | { |
| 289 | const char *status = "broken (no arbiter)"; |
| 290 | int off; |
| 291 | int err; |
| 292 | |
| 293 | off = fdt_path_offset(blob, "pci0"); |
| 294 | if (off < 0) { |
| 295 | printf("WARNING: could not find pci0 alias: %s.\n", |
| 296 | fdt_strerror(off)); |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | err = fdt_setprop(blob, off, "status", status, strlen(status) + 1); |
| 301 | if (err) { |
| 302 | printf("WARNING: could not set status for pci0: %s.\n", |
| 303 | fdt_strerror(err)); |
| 304 | return; |
| 305 | } |
| 306 | } |
| 307 | #endif |
| 308 | |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 309 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 310 | void ft_board_setup(void *blob, bd_t *bd) |
| 311 | { |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 312 | ft_cpu_setup(blob, bd); |
Anton Vorontsov | 32b1b70 | 2008-10-02 18:32:25 +0400 | [diff] [blame] | 313 | ft_tsec_fixup(blob, bd); |
Anton Vorontsov | 504867a | 2008-10-14 22:58:53 +0400 | [diff] [blame] | 314 | fdt_fixup_dr_usb(blob, bd); |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 315 | #ifdef CONFIG_PCI |
| 316 | ft_pci_setup(blob, bd); |
Anton Vorontsov | 30c6992 | 2008-10-02 19:17:33 +0400 | [diff] [blame] | 317 | if (board_pci_host_broken()) |
| 318 | ft_pci_fixup(blob, bd); |
Dave Liu | b19ecd3 | 2007-09-18 12:37:57 +0800 | [diff] [blame] | 319 | #endif |
| 320 | } |
| 321 | #endif /* CONFIG_OF_BOARD_SETUP */ |