Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2008 Freescale Semiconductor. |
| 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 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 | * 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. |
| 16 | * |
| 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, |
| 20 | * MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #include <common.h> |
| 24 | #include <command.h> |
| 25 | #include <pci.h> |
| 26 | #include <asm/processor.h> |
| 27 | #include <asm/mmu.h> |
Kumar Gala | 7c0d4a7 | 2008-09-22 14:11:11 -0500 | [diff] [blame] | 28 | #include <asm/cache.h> |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 29 | #include <asm/immap_85xx.h> |
| 30 | #include <asm/immap_fsl_pci.h> |
| 31 | #include <asm/fsl_ddr_sdram.h> |
| 32 | #include <asm/io.h> |
| 33 | #include <spd.h> |
| 34 | #include <miiphy.h> |
| 35 | #include <libfdt.h> |
| 36 | #include <spd_sdram.h> |
| 37 | #include <fdt_support.h> |
Jason Jin | 2e26d83 | 2008-10-10 11:41:00 +0800 | [diff] [blame] | 38 | #include <tsec.h> |
| 39 | #include <netdev.h> |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 40 | |
| 41 | #include "../common/pixis.h" |
Jason Jin | 2e26d83 | 2008-10-10 11:41:00 +0800 | [diff] [blame] | 42 | #include "../common/sgmii_riser.h" |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 43 | |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 44 | phys_size_t fixed_sdram(void); |
| 45 | |
| 46 | int checkboard (void) |
| 47 | { |
| 48 | printf ("Board: MPC8536DS, System ID: 0x%02x, " |
| 49 | "System Version: 0x%02x, FPGA Version: 0x%02x\n", |
| 50 | in8(PIXIS_BASE + PIXIS_ID), in8(PIXIS_BASE + PIXIS_VER), |
| 51 | in8(PIXIS_BASE + PIXIS_PVER)); |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | phys_size_t |
| 56 | initdram(int board_type) |
| 57 | { |
| 58 | phys_size_t dram_size = 0; |
| 59 | |
| 60 | puts("Initializing...."); |
| 61 | |
| 62 | #ifdef CONFIG_SPD_EEPROM |
| 63 | dram_size = fsl_ddr_sdram(); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 64 | #else |
| 65 | dram_size = fixed_sdram(); |
| 66 | #endif |
Dave Liu | e57f0fa | 2008-10-28 17:53:45 +0800 | [diff] [blame] | 67 | dram_size = setup_ddr_tlbs(dram_size / 0x100000); |
| 68 | dram_size *= 0x100000; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 69 | |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 70 | puts(" DDR: "); |
| 71 | return dram_size; |
| 72 | } |
| 73 | |
| 74 | #if !defined(CONFIG_SPD_EEPROM) |
| 75 | /* |
| 76 | * Fixed sdram init -- doesn't use serial presence detect. |
| 77 | */ |
| 78 | |
| 79 | phys_size_t fixed_sdram (void) |
| 80 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 82 | volatile ccsr_ddr_t *ddr= &immap->im_ddr; |
| 83 | uint d_init; |
| 84 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS; |
| 86 | ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 87 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 88 | ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3; |
| 89 | ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0; |
| 90 | ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1; |
| 91 | ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2; |
| 92 | ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1; |
| 93 | ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2; |
| 94 | ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL; |
| 95 | ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT; |
| 96 | ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL; |
| 97 | ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 98 | |
| 99 | #if defined (CONFIG_DDR_ECC) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 100 | ddr->err_int_en = CONFIG_SYS_DDR_ERR_INT_EN; |
| 101 | ddr->err_disable = CONFIG_SYS_DDR_ERR_DIS; |
| 102 | ddr->err_sbe = CONFIG_SYS_DDR_SBE; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 103 | #endif |
| 104 | asm("sync;isync"); |
| 105 | |
| 106 | udelay(500); |
| 107 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 108 | ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 109 | |
| 110 | #if defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
| 111 | d_init = 1; |
| 112 | debug("DDR - 1st controller: memory initializing\n"); |
| 113 | /* |
| 114 | * Poll until memory is initialized. |
| 115 | * 512 Meg at 400 might hit this 200 times or so. |
| 116 | */ |
| 117 | while ((ddr->sdram_cfg_2 & (d_init << 4)) != 0) { |
| 118 | udelay(1000); |
| 119 | } |
| 120 | debug("DDR: memory initialized\n\n"); |
| 121 | asm("sync; isync"); |
| 122 | udelay(500); |
| 123 | #endif |
| 124 | |
| 125 | return 512 * 1024 * 1024; |
| 126 | } |
| 127 | |
| 128 | #endif |
| 129 | |
| 130 | #ifdef CONFIG_PCI1 |
| 131 | static struct pci_controller pci1_hose; |
| 132 | #endif |
| 133 | |
| 134 | #ifdef CONFIG_PCIE1 |
| 135 | static struct pci_controller pcie1_hose; |
| 136 | #endif |
| 137 | |
| 138 | #ifdef CONFIG_PCIE2 |
| 139 | static struct pci_controller pcie2_hose; |
| 140 | #endif |
| 141 | |
| 142 | #ifdef CONFIG_PCIE3 |
| 143 | static struct pci_controller pcie3_hose; |
| 144 | #endif |
| 145 | |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 146 | extern int fsl_pci_setup_inbound_windows(struct pci_region *r); |
| 147 | extern void fsl_pci_init(struct pci_controller *hose); |
| 148 | |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 149 | int first_free_busno=0; |
| 150 | |
| 151 | void |
| 152 | pci_init_board(void) |
| 153 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 154 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 155 | uint devdisr = gur->devdisr; |
| 156 | uint sdrs2_io_sel = |
| 157 | (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; |
| 158 | uint io_sel = (gur->pordevsr & MPC85xx_PORDEVSR_IO_SEL) >> 19; |
| 159 | uint host_agent = (gur->porbmsr & MPC85xx_PORBMSR_HA) >> 16; |
| 160 | |
| 161 | debug(" pci_init_board: devdisr=%x, sdrs2_io_sel=%x, io_sel=%x,\ |
| 162 | host_agent=%x\n", devdisr, sdrs2_io_sel, io_sel, host_agent); |
| 163 | |
| 164 | if (sdrs2_io_sel == 7) |
| 165 | printf(" Serdes2 disalbed\n"); |
| 166 | else if (sdrs2_io_sel == 4) { |
| 167 | printf(" eTSEC1 is in sgmii mode.\n"); |
| 168 | printf(" eTSEC3 is in sgmii mode.\n"); |
| 169 | } else if (sdrs2_io_sel == 6) |
| 170 | printf(" eTSEC1 is in sgmii mode.\n"); |
| 171 | |
| 172 | #ifdef CONFIG_PCIE3 |
| 173 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 174 | volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE3_ADDR; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 175 | struct pci_controller *hose = &pcie3_hose; |
| 176 | int pcie_ep = (host_agent == 1); |
| 177 | int pcie_configured = (io_sel == 7); |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 178 | struct pci_region *r = hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 179 | |
| 180 | if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){ |
| 181 | printf ("\n PCIE3 connected to Slot3 as %s (base address %x)", |
| 182 | pcie_ep ? "End Point" : "Root Complex", |
| 183 | (uint)pci); |
| 184 | if (pci->pme_msg_det) { |
| 185 | pci->pme_msg_det = 0xffffffff; |
| 186 | debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det); |
| 187 | } |
| 188 | printf ("\n"); |
| 189 | |
| 190 | /* inbound */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 191 | r += fsl_pci_setup_inbound_windows(r); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 192 | |
| 193 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 194 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 195 | CONFIG_SYS_PCIE3_MEM_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 196 | CONFIG_SYS_PCIE3_MEM_PHYS, |
| 197 | CONFIG_SYS_PCIE3_MEM_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 198 | PCI_REGION_MEM); |
| 199 | |
| 200 | /* outbound io */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 201 | pci_set_region(r++, |
Kumar Gala | 5f91ef6 | 2008-12-02 16:08:37 -0600 | [diff] [blame^] | 202 | CONFIG_SYS_PCIE3_IO_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 203 | CONFIG_SYS_PCIE3_IO_PHYS, |
| 204 | CONFIG_SYS_PCIE3_IO_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 205 | PCI_REGION_IO); |
| 206 | |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 207 | hose->region_count = r - hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 208 | |
| 209 | hose->first_busno=first_free_busno; |
| 210 | pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data); |
| 211 | |
| 212 | fsl_pci_init(hose); |
| 213 | |
| 214 | first_free_busno=hose->last_busno+1; |
| 215 | printf (" PCIE3 on bus %02x - %02x\n", |
| 216 | hose->first_busno,hose->last_busno); |
| 217 | } else { |
| 218 | printf (" PCIE3: disabled\n"); |
| 219 | } |
| 220 | |
| 221 | } |
| 222 | #else |
| 223 | gur->devdisr |= MPC85xx_DEVDISR_PCIE3; /* disable */ |
| 224 | #endif |
| 225 | |
| 226 | #ifdef CONFIG_PCIE1 |
| 227 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 228 | volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE1_ADDR; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 229 | struct pci_controller *hose = &pcie1_hose; |
| 230 | int pcie_ep = (host_agent == 5); |
| 231 | int pcie_configured = (io_sel == 2 || io_sel == 3 |
| 232 | || io_sel == 5 || io_sel == 7); |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 233 | struct pci_region *r = hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 234 | |
| 235 | if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){ |
| 236 | printf ("\n PCIE1 connected to Slot1 as %s (base address %x)", |
| 237 | pcie_ep ? "End Point" : "Root Complex", |
| 238 | (uint)pci); |
| 239 | if (pci->pme_msg_det) { |
| 240 | pci->pme_msg_det = 0xffffffff; |
| 241 | debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det); |
| 242 | } |
| 243 | printf ("\n"); |
| 244 | |
| 245 | /* inbound */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 246 | r += fsl_pci_setup_inbound_windows(r); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 247 | |
| 248 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 249 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 250 | CONFIG_SYS_PCIE1_MEM_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 251 | CONFIG_SYS_PCIE1_MEM_PHYS, |
| 252 | CONFIG_SYS_PCIE1_MEM_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 253 | PCI_REGION_MEM); |
| 254 | |
| 255 | /* outbound io */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 256 | pci_set_region(r++, |
Kumar Gala | 5f91ef6 | 2008-12-02 16:08:37 -0600 | [diff] [blame^] | 257 | CONFIG_SYS_PCIE1_IO_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 258 | CONFIG_SYS_PCIE1_IO_PHYS, |
| 259 | CONFIG_SYS_PCIE1_IO_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 260 | PCI_REGION_IO); |
| 261 | |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 262 | #ifdef CONFIG_SYS_PCIE1_MEM_BUS2 |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 263 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 264 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 265 | CONFIG_SYS_PCIE1_MEM_BUS2, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 266 | CONFIG_SYS_PCIE1_MEM_PHYS2, |
| 267 | CONFIG_SYS_PCIE1_MEM_SIZE2, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 268 | PCI_REGION_MEM); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 269 | #endif |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 270 | hose->region_count = r - hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 271 | hose->first_busno=first_free_busno; |
| 272 | |
| 273 | pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data); |
| 274 | |
| 275 | fsl_pci_init(hose); |
| 276 | |
| 277 | first_free_busno=hose->last_busno+1; |
| 278 | printf(" PCIE1 on bus %02x - %02x\n", |
| 279 | hose->first_busno,hose->last_busno); |
| 280 | |
| 281 | } else { |
| 282 | printf (" PCIE1: disabled\n"); |
| 283 | } |
| 284 | |
| 285 | } |
| 286 | #else |
| 287 | gur->devdisr |= MPC85xx_DEVDISR_PCIE; /* disable */ |
| 288 | #endif |
| 289 | |
| 290 | #ifdef CONFIG_PCIE2 |
| 291 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 292 | volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCIE2_ADDR; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 293 | struct pci_controller *hose = &pcie2_hose; |
| 294 | int pcie_ep = (host_agent == 3); |
| 295 | int pcie_configured = (io_sel == 5 || io_sel == 7); |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 296 | struct pci_region *r = hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 297 | |
| 298 | if (pcie_configured && !(devdisr & MPC85xx_DEVDISR_PCIE)){ |
| 299 | printf ("\n PCIE2 connected to Slot 2 as %s (base address %x)", |
| 300 | pcie_ep ? "End Point" : "Root Complex", |
| 301 | (uint)pci); |
| 302 | if (pci->pme_msg_det) { |
| 303 | pci->pme_msg_det = 0xffffffff; |
| 304 | debug (" with errors. Clearing. Now 0x%08x",pci->pme_msg_det); |
| 305 | } |
| 306 | printf ("\n"); |
| 307 | |
| 308 | /* inbound */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 309 | r += fsl_pci_setup_inbound_windows(r); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 310 | |
| 311 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 312 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 313 | CONFIG_SYS_PCIE2_MEM_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 314 | CONFIG_SYS_PCIE2_MEM_PHYS, |
| 315 | CONFIG_SYS_PCIE2_MEM_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 316 | PCI_REGION_MEM); |
| 317 | |
| 318 | /* outbound io */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 319 | pci_set_region(r++, |
Kumar Gala | 5f91ef6 | 2008-12-02 16:08:37 -0600 | [diff] [blame^] | 320 | CONFIG_SYS_PCIE2_IO_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 321 | CONFIG_SYS_PCIE2_IO_PHYS, |
| 322 | CONFIG_SYS_PCIE2_IO_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 323 | PCI_REGION_IO); |
| 324 | |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 325 | #ifdef CONFIG_SYS_PCIE2_MEM_BUS2 |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 326 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 327 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 328 | CONFIG_SYS_PCIE2_MEM_BUS2, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 329 | CONFIG_SYS_PCIE2_MEM_PHYS2, |
| 330 | CONFIG_SYS_PCIE2_MEM_SIZE2, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 331 | PCI_REGION_MEM); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 332 | #endif |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 333 | hose->region_count = r - hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 334 | hose->first_busno=first_free_busno; |
| 335 | pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data); |
| 336 | |
| 337 | fsl_pci_init(hose); |
| 338 | first_free_busno=hose->last_busno+1; |
| 339 | printf (" PCIE2 on bus %02x - %02x\n", |
| 340 | hose->first_busno,hose->last_busno); |
| 341 | |
| 342 | } else { |
| 343 | printf (" PCIE2: disabled\n"); |
| 344 | } |
| 345 | |
| 346 | } |
| 347 | #else |
| 348 | gur->devdisr |= MPC85xx_DEVDISR_PCIE2; /* disable */ |
| 349 | #endif |
| 350 | |
| 351 | |
| 352 | #ifdef CONFIG_PCI1 |
| 353 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 354 | volatile ccsr_fsl_pci_t *pci = (ccsr_fsl_pci_t *) CONFIG_SYS_PCI1_ADDR; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 355 | struct pci_controller *hose = &pci1_hose; |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 356 | struct pci_region *r = hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 357 | |
| 358 | uint pci_agent = (host_agent == 6); |
| 359 | uint pci_speed = 66666000; /*get_clock_freq (); PCI PSPEED in [4:5] */ |
| 360 | uint pci_32 = 1; |
| 361 | uint pci_arb = gur->pordevsr & MPC85xx_PORDEVSR_PCI1_ARB; /* PORDEVSR[14] */ |
| 362 | uint pci_clk_sel = gur->porpllsr & MPC85xx_PORDEVSR_PCI1_SPD; /* PORPLLSR[16] */ |
| 363 | |
| 364 | |
| 365 | if (!(devdisr & MPC85xx_DEVDISR_PCI1)) { |
| 366 | printf ("\n PCI: %d bit, %s MHz, %s, %s, %s (base address %x)\n", |
| 367 | (pci_32) ? 32 : 64, |
| 368 | (pci_speed == 33333000) ? "33" : |
| 369 | (pci_speed == 66666000) ? "66" : "unknown", |
| 370 | pci_clk_sel ? "sync" : "async", |
| 371 | pci_agent ? "agent" : "host", |
| 372 | pci_arb ? "arbiter" : "external-arbiter", |
| 373 | (uint)pci |
| 374 | ); |
| 375 | |
| 376 | /* inbound */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 377 | r += fsl_pci_setup_inbound_windows(r); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 378 | |
| 379 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 380 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 381 | CONFIG_SYS_PCI1_MEM_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 382 | CONFIG_SYS_PCI1_MEM_PHYS, |
| 383 | CONFIG_SYS_PCI1_MEM_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 384 | PCI_REGION_MEM); |
| 385 | |
| 386 | /* outbound io */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 387 | pci_set_region(r++, |
Kumar Gala | 5f91ef6 | 2008-12-02 16:08:37 -0600 | [diff] [blame^] | 388 | CONFIG_SYS_PCI1_IO_BUS, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 389 | CONFIG_SYS_PCI1_IO_PHYS, |
| 390 | CONFIG_SYS_PCI1_IO_SIZE, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 391 | PCI_REGION_IO); |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 392 | |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 393 | #ifdef CONFIG_SYS_PCI1_MEM_BUS2 |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 394 | /* outbound memory */ |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 395 | pci_set_region(r++, |
Kumar Gala | 10795f4 | 2008-12-02 16:08:36 -0600 | [diff] [blame] | 396 | CONFIG_SYS_PCI1_MEM_BUS2, |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 397 | CONFIG_SYS_PCI1_MEM_PHYS2, |
| 398 | CONFIG_SYS_PCI1_MEM_SIZE2, |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 399 | PCI_REGION_MEM); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 400 | #endif |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 401 | hose->region_count = r - hose->regions; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 402 | hose->first_busno=first_free_busno; |
| 403 | pci_setup_indirect(hose, (int) &pci->cfg_addr, (int) &pci->cfg_data); |
| 404 | |
| 405 | fsl_pci_init(hose); |
| 406 | first_free_busno=hose->last_busno+1; |
| 407 | printf ("PCI on bus %02x - %02x\n", |
| 408 | hose->first_busno,hose->last_busno); |
| 409 | } else { |
| 410 | printf (" PCI: disabled\n"); |
| 411 | } |
| 412 | } |
| 413 | #else |
| 414 | gur->devdisr |= MPC85xx_DEVDISR_PCI1; /* disable */ |
| 415 | #endif |
| 416 | } |
| 417 | |
| 418 | |
| 419 | int board_early_init_r(void) |
| 420 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 421 | const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 422 | const u8 flash_esel = 1; |
| 423 | |
| 424 | /* |
| 425 | * Remap Boot flash + PROMJET region to caching-inhibited |
| 426 | * so that flash can be erased properly. |
| 427 | */ |
| 428 | |
Kumar Gala | 7c0d4a7 | 2008-09-22 14:11:11 -0500 | [diff] [blame] | 429 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
Wolfgang Denk | 3cbd823 | 2008-11-02 16:14:22 +0100 | [diff] [blame] | 430 | flush_dcache(); |
| 431 | invalidate_icache(); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 432 | |
| 433 | /* invalidate existing TLB entry for flash + promjet */ |
| 434 | disable_tlb(flash_esel); |
| 435 | |
Kumar Gala | c953ddf | 2008-12-02 14:19:34 -0600 | [diff] [blame] | 436 | set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, /* tlb, epn, rpn */ |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 437 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */ |
| 438 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); /* ts, esel, tsize, iprot */ |
| 439 | |
| 440 | return 0; |
| 441 | } |
| 442 | |
| 443 | #ifdef CONFIG_GET_CLK_FROM_ICS307 |
| 444 | /* decode S[0-2] to Output Divider (OD) */ |
| 445 | static unsigned char |
| 446 | ics307_S_to_OD[] = { |
| 447 | 10, 2, 8, 4, 5, 7, 3, 6 |
| 448 | }; |
| 449 | |
| 450 | /* Calculate frequency being generated by ICS307-02 clock chip based upon |
| 451 | * the control bytes being programmed into it. */ |
| 452 | /* XXX: This function should probably go into a common library */ |
| 453 | static unsigned long |
| 454 | ics307_clk_freq (unsigned char cw0, unsigned char cw1, unsigned char cw2) |
| 455 | { |
| 456 | const unsigned long long InputFrequency = CONFIG_ICS307_REFCLK_HZ; |
| 457 | unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1); |
| 458 | unsigned long RDW = cw2 & 0x7F; |
| 459 | unsigned long OD = ics307_S_to_OD[cw0 & 0x7]; |
| 460 | unsigned long freq; |
| 461 | |
| 462 | /* CLK1Frequency = InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD) */ |
| 463 | |
| 464 | /* cw0: C1 C0 TTL F1 F0 S2 S1 S0 |
| 465 | * cw1: V8 V7 V6 V5 V4 V3 V2 V1 |
| 466 | * cw2: V0 R6 R5 R4 R3 R2 R1 R0 |
| 467 | * |
| 468 | * R6:R0 = Reference Divider Word (RDW) |
| 469 | * V8:V0 = VCO Divider Word (VDW) |
| 470 | * S2:S0 = Output Divider Select (OD) |
| 471 | * F1:F0 = Function of CLK2 Output |
| 472 | * TTL = duty cycle |
| 473 | * C1:C0 = internal load capacitance for cyrstal |
| 474 | */ |
| 475 | |
| 476 | /* Adding 1 to get a "nicely" rounded number, but this needs |
| 477 | * more tweaking to get a "properly" rounded number. */ |
| 478 | |
| 479 | freq = 1 + (InputFrequency * 2 * (VDW + 8) / ((RDW + 2) * OD)); |
| 480 | |
| 481 | debug("ICS307: CW[0-2]: %02X %02X %02X => %u Hz\n", cw0, cw1, cw2, |
| 482 | freq); |
| 483 | return freq; |
| 484 | } |
| 485 | |
| 486 | unsigned long |
| 487 | get_board_sys_clk(ulong dummy) |
| 488 | { |
| 489 | return ics307_clk_freq ( |
| 490 | in8(PIXIS_BASE + PIXIS_VSYSCLK0), |
| 491 | in8(PIXIS_BASE + PIXIS_VSYSCLK1), |
| 492 | in8(PIXIS_BASE + PIXIS_VSYSCLK2) |
| 493 | ); |
| 494 | } |
| 495 | |
| 496 | unsigned long |
| 497 | get_board_ddr_clk(ulong dummy) |
| 498 | { |
| 499 | return ics307_clk_freq ( |
| 500 | in8(PIXIS_BASE + PIXIS_VDDRCLK0), |
| 501 | in8(PIXIS_BASE + PIXIS_VDDRCLK1), |
| 502 | in8(PIXIS_BASE + PIXIS_VDDRCLK2) |
| 503 | ); |
| 504 | } |
| 505 | #else |
| 506 | unsigned long |
| 507 | get_board_sys_clk(ulong dummy) |
| 508 | { |
| 509 | u8 i; |
| 510 | ulong val = 0; |
| 511 | |
| 512 | i = in8(PIXIS_BASE + PIXIS_SPD); |
| 513 | i &= 0x07; |
| 514 | |
| 515 | switch (i) { |
| 516 | case 0: |
| 517 | val = 33333333; |
| 518 | break; |
| 519 | case 1: |
| 520 | val = 40000000; |
| 521 | break; |
| 522 | case 2: |
| 523 | val = 50000000; |
| 524 | break; |
| 525 | case 3: |
| 526 | val = 66666666; |
| 527 | break; |
| 528 | case 4: |
| 529 | val = 83333333; |
| 530 | break; |
| 531 | case 5: |
| 532 | val = 100000000; |
| 533 | break; |
| 534 | case 6: |
| 535 | val = 133333333; |
| 536 | break; |
| 537 | case 7: |
| 538 | val = 166666666; |
| 539 | break; |
| 540 | } |
| 541 | |
| 542 | return val; |
| 543 | } |
| 544 | |
| 545 | unsigned long |
| 546 | get_board_ddr_clk(ulong dummy) |
| 547 | { |
| 548 | u8 i; |
| 549 | ulong val = 0; |
| 550 | |
| 551 | i = in8(PIXIS_BASE + PIXIS_SPD); |
| 552 | i &= 0x38; |
| 553 | i >>= 3; |
| 554 | |
| 555 | switch (i) { |
| 556 | case 0: |
| 557 | val = 33333333; |
| 558 | break; |
| 559 | case 1: |
| 560 | val = 40000000; |
| 561 | break; |
| 562 | case 2: |
| 563 | val = 50000000; |
| 564 | break; |
| 565 | case 3: |
| 566 | val = 66666666; |
| 567 | break; |
| 568 | case 4: |
| 569 | val = 83333333; |
| 570 | break; |
| 571 | case 5: |
| 572 | val = 100000000; |
| 573 | break; |
| 574 | case 6: |
| 575 | val = 133333333; |
| 576 | break; |
| 577 | case 7: |
| 578 | val = 166666666; |
| 579 | break; |
| 580 | } |
| 581 | return val; |
| 582 | } |
| 583 | #endif |
| 584 | |
Heiko Schocher | 374b903 | 2008-10-15 09:51:19 +0200 | [diff] [blame] | 585 | int is_sata_supported(void) |
Jason Jin | 0f8cbc1 | 2008-10-10 11:41:01 +0800 | [diff] [blame] | 586 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 587 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Jason Jin | 0f8cbc1 | 2008-10-10 11:41:01 +0800 | [diff] [blame] | 588 | uint sdrs2_io_sel = |
| 589 | (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; |
| 590 | if (sdrs2_io_sel & 0x04) |
| 591 | return 0; |
| 592 | |
| 593 | return 1; |
| 594 | } |
| 595 | |
Jason Jin | 2e26d83 | 2008-10-10 11:41:00 +0800 | [diff] [blame] | 596 | int board_eth_init(bd_t *bis) |
| 597 | { |
| 598 | #ifdef CONFIG_TSEC_ENET |
| 599 | struct tsec_info_struct tsec_info[2]; |
| 600 | volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
| 601 | int num = 0; |
| 602 | uint sdrs2_io_sel = |
| 603 | (gur->pordevsr & MPC85xx_PORDEVSR_SRDS2_IO_SEL) >> 27; |
| 604 | |
| 605 | #ifdef CONFIG_TSEC1 |
| 606 | SET_STD_TSEC_INFO(tsec_info[num], 1); |
| 607 | if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) { |
| 608 | tsec_info[num].phyaddr = 0; |
| 609 | tsec_info[num].flags |= TSEC_SGMII; |
| 610 | } |
| 611 | num++; |
| 612 | #endif |
| 613 | #ifdef CONFIG_TSEC3 |
| 614 | SET_STD_TSEC_INFO(tsec_info[num], 3); |
| 615 | if (sdrs2_io_sel == 4) { |
| 616 | tsec_info[num].phyaddr = 1; |
| 617 | tsec_info[num].flags |= TSEC_SGMII; |
| 618 | } |
| 619 | num++; |
| 620 | #endif |
| 621 | |
| 622 | if (!num) { |
| 623 | printf("No TSECs initialized\n"); |
| 624 | return 0; |
| 625 | } |
| 626 | |
| 627 | if ((sdrs2_io_sel == 4) || (sdrs2_io_sel == 6)) |
| 628 | fsl_sgmii_riser_init(tsec_info, num); |
| 629 | |
| 630 | tsec_eth_init(bis, tsec_info, num); |
| 631 | #endif |
| 632 | return pci_eth_init(bis); |
| 633 | } |
| 634 | |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 635 | #if defined(CONFIG_OF_BOARD_SETUP) |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 636 | extern void ft_fsl_pci_setup(void *blob, const char *pci_alias, |
Wolfgang Denk | 3cbd823 | 2008-11-02 16:14:22 +0100 | [diff] [blame] | 637 | struct pci_controller *hose); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 638 | |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 639 | void ft_board_setup(void *blob, bd_t *bd) |
| 640 | { |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 641 | ft_cpu_setup(blob, bd); |
| 642 | |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 643 | #ifdef CONFIG_PCI1 |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 644 | ft_fsl_pci_setup(blob, "pci0", &pci1_hose); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 645 | #endif |
| 646 | #ifdef CONFIG_PCIE2 |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 647 | ft_fsl_pci_setup(blob, "pci1", &pcie2_hose); |
| 648 | #endif |
| 649 | #ifdef CONFIG_PCIE2 |
| 650 | ft_fsl_pci_setup(blob, "pci2", &pcie1_hose); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 651 | #endif |
| 652 | #ifdef CONFIG_PCIE1 |
Kumar Gala | 2dba0de | 2008-10-21 08:28:33 -0500 | [diff] [blame] | 653 | ft_fsl_pci_setup(blob, "pci3", &pcie3_hose); |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 654 | #endif |
Kumar Gala | 9490a7f | 2008-07-25 13:31:05 -0500 | [diff] [blame] | 655 | } |
| 656 | #endif |