Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved. |
| 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 | |
| 25 | #ifdef CONFIG_PCI |
| 26 | |
| 27 | #include <asm/mmu.h> |
| 28 | #include <asm/global_data.h> |
| 29 | #include <pci.h> |
| 30 | #include <asm/mpc8349_pci.h> |
| 31 | #include <i2c.h> |
| 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | /* System RAM mapped to PCI space */ |
| 36 | #define CONFIG_PCI_SYS_MEM_BUS CFG_SDRAM_BASE |
| 37 | #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE |
| 38 | |
| 39 | #ifndef CONFIG_PCI_PNP |
| 40 | static struct pci_config_table pci_mpc8349itx_config_table[] = { |
| 41 | { |
| 42 | PCI_ANY_ID, |
| 43 | PCI_ANY_ID, |
| 44 | PCI_ANY_ID, |
| 45 | PCI_ANY_ID, |
| 46 | PCI_IDSEL_NUMBER, |
| 47 | PCI_ANY_ID, |
| 48 | pci_cfgfunc_config_device, |
| 49 | { |
| 50 | PCI_ENET0_IOADDR, |
| 51 | PCI_ENET0_MEMADDR, |
| 52 | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER} |
| 53 | }, |
| 54 | {} |
| 55 | }; |
| 56 | #endif |
| 57 | |
| 58 | static struct pci_controller pci_hose[] = { |
| 59 | { |
| 60 | #ifndef CONFIG_PCI_PNP |
| 61 | config_table:pci_mpc8349itx_config_table, |
| 62 | #endif |
| 63 | }, |
| 64 | { |
| 65 | #ifndef CONFIG_PCI_PNP |
| 66 | config_table:pci_mpc8349itx_config_table, |
| 67 | #endif |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | /************************************************************************** |
| 72 | * pci_init_board() |
| 73 | * |
| 74 | * NOTICE: PCI2 is not currently supported |
| 75 | * |
| 76 | */ |
| 77 | void pci_init_board(void) |
| 78 | { |
| 79 | volatile immap_t *immr; |
| 80 | volatile clk83xx_t *clk; |
| 81 | volatile law83xx_t *pci_law; |
| 82 | volatile pot83xx_t *pci_pot; |
| 83 | volatile pcictrl83xx_t *pci_ctrl; |
| 84 | volatile pciconf83xx_t *pci_conf; |
| 85 | u8 reg8; |
| 86 | u16 reg16; |
| 87 | u32 reg32; |
| 88 | u32 dev; |
| 89 | struct pci_controller *hose; |
| 90 | |
| 91 | immr = (immap_t *) CFG_IMMRBAR; |
| 92 | clk = (clk83xx_t *) & immr->clk; |
| 93 | pci_law = immr->sysconf.pcilaw; |
| 94 | pci_pot = immr->ios.pot; |
| 95 | pci_ctrl = immr->pci_ctrl; |
| 96 | pci_conf = immr->pci_conf; |
| 97 | |
| 98 | hose = &pci_hose[0]; |
| 99 | |
| 100 | /* |
| 101 | * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode |
| 102 | */ |
| 103 | |
| 104 | reg32 = clk->occr; |
| 105 | udelay(2000); |
| 106 | |
| 107 | #ifdef CONFIG_HARD_I2C |
| 108 | i2c_set_bus_num(I2C_BUS_2); |
| 109 | /* Read the PCI_M66EN jumper setting */ |
| 110 | if ((i2c_read(CFG_I2C_8574_ADDR2, 0, 0, ®8, sizeof(reg8)) == 0) || |
| 111 | (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, ®8, sizeof(reg8)) == 0)) { |
| 112 | if (reg8 & I2C_8574_PCI66) |
| 113 | clk->occr = 0xff000000; /* 66 MHz PCI */ |
| 114 | else |
| 115 | clk->occr = 0xff600001; /* 33 MHz PCI */ |
| 116 | } else { |
| 117 | clk->occr = 0xff600001; /* 33 MHz PCI */ |
| 118 | } |
| 119 | #else |
| 120 | clk->occr = 0xff000000; /* 66 MHz PCI */ |
| 121 | #endif |
| 122 | |
| 123 | udelay(2000); |
| 124 | |
| 125 | /* |
| 126 | * Release PCI RST Output signal |
| 127 | */ |
| 128 | pci_ctrl[0].gcr = 0; |
| 129 | udelay(2000); |
| 130 | pci_ctrl[0].gcr = 1; |
| 131 | |
| 132 | #ifdef CONFIG_MPC83XX_PCI2 |
| 133 | pci_ctrl[1].gcr = 0; |
| 134 | udelay(2000); |
| 135 | pci_ctrl[1].gcr = 1; |
| 136 | #endif |
| 137 | |
| 138 | /* We need to wait at least a 1sec based on PCI specs */ |
| 139 | { |
| 140 | int i; |
| 141 | |
| 142 | for (i = 0; i < 1000; i++) |
| 143 | udelay(1000); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Configure PCI Local Access Windows |
| 148 | */ |
| 149 | pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR; |
| 150 | pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G; |
| 151 | |
| 152 | pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 153 | pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 154 | |
| 155 | /* |
| 156 | * Configure PCI Outbound Translation Windows |
| 157 | */ |
| 158 | |
| 159 | /* PCI1 mem space - prefetch */ |
| 160 | pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK; |
| 161 | pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 162 | pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | POCMR_CM_256M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 163 | |
| 164 | /* PCI1 IO space */ |
| 165 | pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK; |
| 166 | pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 167 | pci_pot[1].pocmr = POCMR_EN | POCMR_IO | POCMR_CM_16M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 168 | |
| 169 | /* PCI1 mmio - non-prefetch mem space */ |
| 170 | pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK; |
| 171 | pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 172 | pci_pot[2].pocmr = POCMR_EN | POCMR_CM_256M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 173 | |
| 174 | /* |
| 175 | * Configure PCI Inbound Translation Windows |
| 176 | */ |
| 177 | |
| 178 | /* we need RAM mapped to PCI space for the devices to |
| 179 | * access main memory */ |
| 180 | pci_ctrl[0].pitar1 = 0x0; |
| 181 | pci_ctrl[0].pibar1 = 0x0; |
| 182 | pci_ctrl[0].piebar1 = 0x0; |
| 183 | pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | |
| 184 | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1); |
| 185 | |
| 186 | hose->first_busno = 0; |
| 187 | hose->last_busno = 0xff; |
| 188 | |
| 189 | /* PCI memory prefetch space */ |
| 190 | pci_set_region(hose->regions + 0, |
| 191 | CFG_PCI1_MEM_BASE, |
| 192 | CFG_PCI1_MEM_PHYS, |
| 193 | CFG_PCI1_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH); |
| 194 | |
| 195 | /* PCI memory space */ |
| 196 | pci_set_region(hose->regions + 1, |
| 197 | CFG_PCI1_MMIO_BASE, |
| 198 | CFG_PCI1_MMIO_PHYS, CFG_PCI1_MMIO_SIZE, PCI_REGION_MEM); |
| 199 | |
| 200 | /* PCI IO space */ |
| 201 | pci_set_region(hose->regions + 2, |
| 202 | CFG_PCI1_IO_BASE, |
| 203 | CFG_PCI1_IO_PHYS, CFG_PCI1_IO_SIZE, PCI_REGION_IO); |
| 204 | |
| 205 | /* System memory space */ |
| 206 | pci_set_region(hose->regions + 3, |
| 207 | CONFIG_PCI_SYS_MEM_BUS, |
| 208 | CONFIG_PCI_SYS_MEM_PHYS, |
| 209 | gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 210 | |
| 211 | hose->region_count = 4; |
| 212 | |
| 213 | pci_setup_indirect(hose, |
| 214 | (CFG_IMMRBAR + 0x8300), (CFG_IMMRBAR + 0x8304)); |
| 215 | |
| 216 | pci_register_hose(hose); |
| 217 | |
| 218 | /* |
| 219 | * Write to Command register |
| 220 | */ |
| 221 | reg16 = 0xff; |
| 222 | dev = PCI_BDF(hose->first_busno, 0, 0); |
| 223 | pci_hose_read_config_word(hose, dev, PCI_COMMAND, ®16); |
| 224 | reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 225 | pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16); |
| 226 | |
| 227 | /* |
| 228 | * Clear non-reserved bits in status register. |
| 229 | */ |
| 230 | pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff); |
| 231 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80); |
| 232 | pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08); |
| 233 | |
| 234 | #ifdef CONFIG_PCI_SCAN_SHOW |
| 235 | printf("PCI: Bus Dev VenId DevId Class Int\n"); |
| 236 | #endif |
| 237 | /* |
| 238 | * Hose scan. |
| 239 | */ |
| 240 | hose->last_busno = pci_hose_scan(hose); |
| 241 | |
| 242 | #ifdef CONFIG_MPC83XX_PCI2 |
| 243 | hose = &pci_hose[1]; |
| 244 | |
| 245 | /* |
| 246 | * Configure PCI Outbound Translation Windows |
| 247 | */ |
| 248 | |
| 249 | /* PCI2 mem space - prefetch */ |
| 250 | pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK; |
| 251 | pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 252 | pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | POCMR_CM_256M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 253 | |
| 254 | /* PCI2 IO space */ |
| 255 | pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK; |
| 256 | pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 257 | pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | POCMR_CM_16M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 258 | |
| 259 | /* PCI2 mmio - non-prefetch mem space */ |
| 260 | pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK; |
| 261 | pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK; |
Timur Tabi | 9888333 | 2006-10-31 19:14:41 -0600 | [diff] [blame] | 262 | pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_CM_256M; |
Timur Tabi | 2ad6b51 | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * Configure PCI Inbound Translation Windows |
| 266 | */ |
| 267 | |
| 268 | /* we need RAM mapped to PCI space for the devices to |
| 269 | * access main memory */ |
| 270 | pci_ctrl[1].pitar1 = 0x0; |
| 271 | pci_ctrl[1].pibar1 = 0x0; |
| 272 | pci_ctrl[1].piebar1 = 0x0; |
| 273 | pci_ctrl[1].piwar1 = |
| 274 | PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | |
| 275 | (__ilog2(gd->ram_size) - 1); |
| 276 | |
| 277 | hose->first_busno = pci_hose[0].last_busno + 1; |
| 278 | hose->last_busno = 0xff; |
| 279 | |
| 280 | /* PCI memory prefetch space */ |
| 281 | pci_set_region(hose->regions + 0, |
| 282 | CFG_PCI2_MEM_BASE, |
| 283 | CFG_PCI2_MEM_PHYS, |
| 284 | CFG_PCI2_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH); |
| 285 | |
| 286 | /* PCI memory space */ |
| 287 | pci_set_region(hose->regions + 1, |
| 288 | CFG_PCI2_MMIO_BASE, |
| 289 | CFG_PCI2_MMIO_PHYS, CFG_PCI2_MMIO_SIZE, PCI_REGION_MEM); |
| 290 | |
| 291 | /* PCI IO space */ |
| 292 | pci_set_region(hose->regions + 2, |
| 293 | CFG_PCI2_IO_BASE, |
| 294 | CFG_PCI2_IO_PHYS, CFG_PCI2_IO_SIZE, PCI_REGION_IO); |
| 295 | |
| 296 | /* System memory space */ |
| 297 | pci_set_region(hose->regions + 3, |
| 298 | CONFIG_PCI_SYS_MEM_BUS, |
| 299 | CONFIG_PCI_SYS_MEM_PHYS, |
| 300 | gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 301 | |
| 302 | hose->region_count = 4; |
| 303 | |
| 304 | pci_setup_indirect(hose, |
| 305 | (CFG_IMMRBAR + 0x8380), (CFG_IMMRBAR + 0x8384)); |
| 306 | |
| 307 | pci_register_hose(hose); |
| 308 | |
| 309 | /* |
| 310 | * Write to Command register |
| 311 | */ |
| 312 | reg16 = 0xff; |
| 313 | dev = PCI_BDF(hose->first_busno, 0, 0); |
| 314 | pci_hose_read_config_word(hose, dev, PCI_COMMAND, ®16); |
| 315 | reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 316 | pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16); |
| 317 | |
| 318 | /* |
| 319 | * Clear non-reserved bits in status register. |
| 320 | */ |
| 321 | pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff); |
| 322 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80); |
| 323 | pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08); |
| 324 | |
| 325 | /* |
| 326 | * Hose scan. |
| 327 | */ |
| 328 | hose->last_busno = pci_hose_scan(hose); |
| 329 | #endif |
| 330 | } |
| 331 | |
| 332 | #endif /* CONFIG_PCI */ |