Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 Freescale Semiconductor, Inc. |
| 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 | |
| 13 | /* |
| 14 | * PCI Configuration space access support for MPC83xx PCI Bridge |
| 15 | */ |
| 16 | #include <asm/mmu.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <common.h> |
| 19 | #include <pci.h> |
| 20 | #include <i2c.h> |
Kim Phillips | 781e026 | 2007-02-28 00:02:04 -0600 | [diff] [blame] | 21 | #if defined(CONFIG_OF_FLAT_TREE) |
| 22 | #include <ft_build.h> |
| 23 | #endif |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame^] | 24 | #if defined(CONFIG_OF_LIBFDT) |
| 25 | #include <libfdt.h> |
| 26 | #include <libfdt_env.h> |
| 27 | #endif |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 28 | |
Timur Tabi | be5e618 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 29 | #include <asm/fsl_i2c.h> |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 30 | |
| 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
| 33 | #if defined(CONFIG_PCI) |
| 34 | #define PCI_FUNCTION_CONFIG 0x44 |
| 35 | #define PCI_FUNCTION_CFG_LOCK 0x20 |
| 36 | |
| 37 | /* |
| 38 | * Initialize PCI Devices, report devices found |
| 39 | */ |
| 40 | #ifndef CONFIG_PCI_PNP |
| 41 | static struct pci_config_table pci_mpc83xxemds_config_table[] = { |
| 42 | { |
| 43 | PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, |
| 44 | pci_cfgfunc_config_device, |
| 45 | {PCI_ENET0_IOADDR, |
| 46 | PCI_ENET0_MEMADDR, |
| 47 | PCI_COMMON_MEMORY | PCI_COMMAND_MASTER} |
| 48 | }, |
| 49 | {} |
| 50 | } |
| 51 | #endif |
| 52 | static struct pci_controller hose[] = { |
| 53 | { |
| 54 | #ifndef CONFIG_PCI_PNP |
| 55 | config_table:pci_mpc83xxemds_config_table, |
| 56 | #endif |
| 57 | }, |
| 58 | }; |
| 59 | |
| 60 | /********************************************************************** |
| 61 | * pci_init_board() |
| 62 | *********************************************************************/ |
| 63 | void pci_init_board(void) |
| 64 | #ifdef CONFIG_PCISLAVE |
| 65 | { |
| 66 | u16 reg16; |
| 67 | volatile immap_t *immr; |
| 68 | volatile law83xx_t *pci_law; |
| 69 | volatile pot83xx_t *pci_pot; |
| 70 | volatile pcictrl83xx_t *pci_ctrl; |
| 71 | volatile pciconf83xx_t *pci_conf; |
| 72 | |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 73 | immr = (immap_t *) CFG_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 74 | pci_law = immr->sysconf.pcilaw; |
| 75 | pci_pot = immr->ios.pot; |
| 76 | pci_ctrl = immr->pci_ctrl; |
| 77 | pci_conf = immr->pci_conf; |
| 78 | /* |
| 79 | * Configure PCI Inbound Translation Windows |
| 80 | */ |
| 81 | pci_ctrl[0].pitar0 = 0x0; |
| 82 | pci_ctrl[0].pibar0 = 0x0; |
| 83 | pci_ctrl[0].piwar0 = PIWAR_EN | PIWAR_RTT_SNOOP | |
| 84 | PIWAR_WTT_SNOOP | PIWAR_IWS_4K; |
| 85 | |
| 86 | pci_ctrl[0].pitar1 = 0x0; |
| 87 | pci_ctrl[0].pibar1 = 0x0; |
| 88 | pci_ctrl[0].piebar1 = 0x0; |
| 89 | pci_ctrl[0].piwar1 &= ~PIWAR_EN; |
| 90 | |
| 91 | pci_ctrl[0].pitar2 = 0x0; |
| 92 | pci_ctrl[0].pibar2 = 0x0; |
| 93 | pci_ctrl[0].piebar2 = 0x0; |
| 94 | pci_ctrl[0].piwar2 &= ~PIWAR_EN; |
| 95 | |
| 96 | hose[0].first_busno = 0; |
| 97 | hose[0].last_busno = 0xff; |
| 98 | pci_setup_indirect(&hose[0], |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 99 | (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304)); |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 100 | reg16 = 0xff; |
| 101 | |
| 102 | pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0), |
| 103 | PCI_COMMAND, ®16); |
| 104 | reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MEMORY; |
| 105 | pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0), |
| 106 | PCI_COMMAND, reg16); |
| 107 | |
| 108 | /* |
| 109 | * Clear non-reserved bits in status register. |
| 110 | */ |
| 111 | pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0), |
| 112 | PCI_STATUS, 0xffff); |
| 113 | pci_hose_write_config_byte(&hose[0], PCI_BDF(0, 0, 0), |
| 114 | PCI_LATENCY_TIMER, 0x80); |
| 115 | |
| 116 | /* |
| 117 | * Unlock configuration lock in PCI function configuration register. |
| 118 | */ |
| 119 | pci_hose_read_config_word(&hose[0], PCI_BDF(0, 0, 0), |
| 120 | PCI_FUNCTION_CONFIG, ®16); |
| 121 | reg16 &= ~(PCI_FUNCTION_CFG_LOCK); |
| 122 | pci_hose_write_config_word(&hose[0], PCI_BDF(0, 0, 0), |
| 123 | PCI_FUNCTION_CONFIG, reg16); |
| 124 | |
| 125 | printf("Enabled PCI 32bit Agent Mode\n"); |
| 126 | } |
| 127 | #else |
| 128 | { |
| 129 | volatile immap_t *immr; |
| 130 | volatile clk83xx_t *clk; |
| 131 | volatile law83xx_t *pci_law; |
| 132 | volatile pot83xx_t *pci_pot; |
| 133 | volatile pcictrl83xx_t *pci_ctrl; |
| 134 | volatile pciconf83xx_t *pci_conf; |
| 135 | |
| 136 | u8 val8, orig_i2c_bus; |
| 137 | u16 reg16; |
| 138 | u32 val32; |
| 139 | u32 dev; |
| 140 | |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 141 | immr = (immap_t *) CFG_IMMR; |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 142 | clk = (clk83xx_t *) & immr->clk; |
| 143 | pci_law = immr->sysconf.pcilaw; |
| 144 | pci_pot = immr->ios.pot; |
| 145 | pci_ctrl = immr->pci_ctrl; |
| 146 | pci_conf = immr->pci_conf; |
| 147 | /* |
| 148 | * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode |
| 149 | */ |
| 150 | val32 = clk->occr; |
| 151 | udelay(2000); |
| 152 | #if defined(PCI_66M) |
| 153 | clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2; |
| 154 | printf("PCI clock is 66MHz\n"); |
| 155 | #elif defined(PCI_33M) |
| 156 | clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2 | |
| 157 | OCCR_PCICD0 | OCCR_PCICD1 | OCCR_PCICD2 | OCCR_PCICR; |
| 158 | printf("PCI clock is 33MHz\n"); |
| 159 | #else |
| 160 | clk->occr = OCCR_PCICOE0 | OCCR_PCICOE1 | OCCR_PCICOE2; |
| 161 | printf("PCI clock is 66MHz\n"); |
| 162 | #endif |
| 163 | udelay(2000); |
| 164 | |
| 165 | /* |
| 166 | * Configure PCI Local Access Windows |
| 167 | */ |
| 168 | pci_law[0].bar = CFG_PCI_MEM_PHYS & LAWBAR_BAR; |
| 169 | pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_512M; |
| 170 | |
| 171 | pci_law[1].bar = CFG_PCI_IO_PHYS & LAWBAR_BAR; |
| 172 | pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_1M; |
| 173 | |
| 174 | /* |
| 175 | * Configure PCI Outbound Translation Windows |
| 176 | */ |
| 177 | |
| 178 | /* PCI mem space - prefetch */ |
| 179 | pci_pot[0].potar = (CFG_PCI_MEM_BASE >> 12) & POTAR_TA_MASK; |
| 180 | pci_pot[0].pobar = (CFG_PCI_MEM_PHYS >> 12) & POBAR_BA_MASK; |
| 181 | pci_pot[0].pocmr = |
| 182 | POCMR_EN | POCMR_SE | (POCMR_CM_256M & POCMR_CM_MASK); |
| 183 | |
| 184 | /* PCI mmio - non-prefetch mem space */ |
| 185 | pci_pot[1].potar = (CFG_PCI_MMIO_BASE >> 12) & POTAR_TA_MASK; |
| 186 | pci_pot[1].pobar = (CFG_PCI_MMIO_PHYS >> 12) & POBAR_BA_MASK; |
| 187 | pci_pot[1].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK); |
| 188 | |
| 189 | /* PCI IO space */ |
| 190 | pci_pot[2].potar = (CFG_PCI_IO_BASE >> 12) & POTAR_TA_MASK; |
| 191 | pci_pot[2].pobar = (CFG_PCI_IO_PHYS >> 12) & POBAR_BA_MASK; |
| 192 | pci_pot[2].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK); |
| 193 | |
| 194 | /* |
| 195 | * Configure PCI Inbound Translation Windows |
| 196 | */ |
| 197 | pci_ctrl[0].pitar1 = (CFG_PCI_SLV_MEM_LOCAL >> 12) & PITAR_TA_MASK; |
| 198 | pci_ctrl[0].pibar1 = (CFG_PCI_SLV_MEM_BUS >> 12) & PIBAR_MASK; |
| 199 | pci_ctrl[0].piebar1 = 0x0; |
| 200 | pci_ctrl[0].piwar1 = |
| 201 | PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | |
| 202 | PIWAR_IWS_2G; |
| 203 | |
| 204 | /* |
| 205 | * Assign PIB PMC slot to desired PCI bus |
| 206 | */ |
| 207 | |
Timur Tabi | 9ca880a | 2006-10-31 21:23:16 -0600 | [diff] [blame] | 208 | /* Switch temporarily to I2C bus #2 */ |
| 209 | orig_i2c_bus = i2c_get_bus_num(); |
Timur Tabi | be5e618 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 210 | i2c_set_bus_num(1); |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 211 | |
| 212 | val8 = 0; |
| 213 | i2c_write(0x23, 0x6, 1, &val8, 1); |
| 214 | i2c_write(0x23, 0x7, 1, &val8, 1); |
| 215 | val8 = 0xff; |
| 216 | i2c_write(0x23, 0x2, 1, &val8, 1); |
| 217 | i2c_write(0x23, 0x3, 1, &val8, 1); |
| 218 | |
| 219 | val8 = 0; |
| 220 | i2c_write(0x26, 0x6, 1, &val8, 1); |
| 221 | val8 = 0x34; |
| 222 | i2c_write(0x26, 0x7, 1, &val8, 1); |
| 223 | |
| 224 | val8 = 0xf3; /*PMC1, PMC2, PMC3 slot to PCI bus */ |
| 225 | i2c_write(0x26, 0x2, 1, &val8, 1); |
| 226 | val8 = 0xff; |
| 227 | i2c_write(0x26, 0x3, 1, &val8, 1); |
| 228 | |
| 229 | val8 = 0; |
| 230 | i2c_write(0x27, 0x6, 1, &val8, 1); |
| 231 | i2c_write(0x27, 0x7, 1, &val8, 1); |
| 232 | val8 = 0xff; |
| 233 | i2c_write(0x27, 0x2, 1, &val8, 1); |
| 234 | val8 = 0xef; |
| 235 | i2c_write(0x27, 0x3, 1, &val8, 1); |
| 236 | asm("eieio"); |
| 237 | |
Timur Tabi | 9ca880a | 2006-10-31 21:23:16 -0600 | [diff] [blame] | 238 | /* Reset to original I2C bus */ |
Timur Tabi | be5e618 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 239 | i2c_set_bus_num(orig_i2c_bus); |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 240 | |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 241 | /* |
| 242 | * Release PCI RST Output signal |
| 243 | */ |
| 244 | udelay(2000); |
| 245 | pci_ctrl[0].gcr = 1; |
| 246 | udelay(2000); |
| 247 | |
| 248 | hose[0].first_busno = 0; |
| 249 | hose[0].last_busno = 0xff; |
| 250 | |
| 251 | /* PCI memory prefetch space */ |
| 252 | pci_set_region(hose[0].regions + 0, |
| 253 | CFG_PCI_MEM_BASE, |
| 254 | CFG_PCI_MEM_PHYS, |
| 255 | CFG_PCI_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH); |
| 256 | |
| 257 | /* PCI memory space */ |
| 258 | pci_set_region(hose[0].regions + 1, |
| 259 | CFG_PCI_MMIO_BASE, |
| 260 | CFG_PCI_MMIO_PHYS, CFG_PCI_MMIO_SIZE, PCI_REGION_MEM); |
| 261 | |
| 262 | /* PCI IO space */ |
| 263 | pci_set_region(hose[0].regions + 2, |
| 264 | CFG_PCI_IO_BASE, |
| 265 | CFG_PCI_IO_PHYS, CFG_PCI_IO_SIZE, PCI_REGION_IO); |
| 266 | |
| 267 | /* System memory space */ |
| 268 | pci_set_region(hose[0].regions + 3, |
| 269 | CFG_PCI_SLV_MEM_LOCAL, |
| 270 | CFG_PCI_SLV_MEM_BUS, |
| 271 | CFG_PCI_SLV_MEM_SIZE, |
| 272 | PCI_REGION_MEM | PCI_REGION_MEMORY); |
| 273 | |
| 274 | hose[0].region_count = 4; |
| 275 | |
| 276 | pci_setup_indirect(&hose[0], |
Timur Tabi | d239d74 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 277 | (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304)); |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 278 | |
| 279 | pci_register_hose(hose); |
| 280 | |
| 281 | /* |
| 282 | * Write command register |
| 283 | */ |
| 284 | reg16 = 0xff; |
| 285 | dev = PCI_BDF(0, 0, 0); |
| 286 | pci_hose_read_config_word(&hose[0], dev, PCI_COMMAND, ®16); |
| 287 | reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY; |
| 288 | pci_hose_write_config_word(&hose[0], dev, PCI_COMMAND, reg16); |
| 289 | |
| 290 | /* |
| 291 | * Clear non-reserved bits in status register. |
| 292 | */ |
| 293 | pci_hose_write_config_word(&hose[0], dev, PCI_STATUS, 0xffff); |
| 294 | pci_hose_write_config_byte(&hose[0], dev, PCI_LATENCY_TIMER, 0x80); |
| 295 | pci_hose_write_config_byte(&hose[0], dev, PCI_CACHE_LINE_SIZE, 0x08); |
| 296 | |
| 297 | printf("PCI 32bit bus on PMC1 & PMC2 & PMC3\n"); |
| 298 | |
| 299 | /* |
| 300 | * Hose scan. |
| 301 | */ |
| 302 | hose->last_busno = pci_hose_scan(hose); |
| 303 | } |
| 304 | #endif /* CONFIG_PCISLAVE */ |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 305 | |
Gerald Van Baren | 213bf8c | 2007-03-31 12:23:51 -0400 | [diff] [blame^] | 306 | #if defined(CONFIG_OF_LIBFDT) |
| 307 | void |
| 308 | ft_pci_setup(void *blob, bd_t *bd) |
| 309 | { |
| 310 | int nodeoffset; |
| 311 | int err; |
| 312 | int tmp[2]; |
| 313 | |
| 314 | nodeoffset = fdt_path_offset (fdt, "/" OF_SOC "/pci@8500"); |
| 315 | if (nodeoffset >= 0) { |
| 316 | tmp[0] = cpu_to_be32(hose[0].first_busno); |
| 317 | tmp[1] = cpu_to_be32(hose[0].last_busno); |
| 318 | err = fdt_setprop(fdt, nodeoffset, "bus-range", tmp, sizeof(tmp)); |
| 319 | } |
| 320 | } |
| 321 | #endif /* CONFIG_OF_LIBFDT */ |
Kim Phillips | bf0b542 | 2006-11-01 00:10:40 -0600 | [diff] [blame] | 322 | #ifdef CONFIG_OF_FLAT_TREE |
| 323 | void |
| 324 | ft_pci_setup(void *blob, bd_t *bd) |
| 325 | { |
| 326 | u32 *p; |
| 327 | int len; |
| 328 | |
| 329 | p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len); |
| 330 | if (p != NULL) { |
| 331 | p[0] = hose[0].first_busno; |
| 332 | p[1] = hose[0].last_busno; |
| 333 | } |
| 334 | } |
| 335 | #endif /* CONFIG_OF_FLAT_TREE */ |
Dave Liu | 5f82043 | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 336 | #endif /* CONFIG_PCI */ |