2 * See file CREDITS for list of people who contributed to this
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 #include <asm/global_data.h>
26 #include <asm/mpc8349_pci.h>
28 #if defined(CONFIG_OF_FLAT_TREE)
30 #elif defined(CONFIG_OF_LIBFDT)
35 DECLARE_GLOBAL_DATA_PTR;
39 /* System RAM mapped to PCI space */
40 #define CONFIG_PCI_SYS_MEM_BUS CFG_SDRAM_BASE
41 #define CONFIG_PCI_SYS_MEM_PHYS CFG_SDRAM_BASE
43 #ifndef CONFIG_PCI_PNP
44 static struct pci_config_table pci_mpc8349emds_config_table[] = {
45 {PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
46 PCI_IDSEL_NUMBER, PCI_ANY_ID,
47 pci_cfgfunc_config_device, {PCI_ENET0_IOADDR,
49 PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER
56 static struct pci_controller pci_hose[] = {
58 #ifndef CONFIG_PCI_PNP
59 config_table:pci_mpc8349emds_config_table,
63 #ifndef CONFIG_PCI_PNP
64 config_table:pci_mpc8349emds_config_table,
69 /**************************************************************************
71 * pib_init() -- initialize the PCA9555PW IO expander on the PIB board
77 u8 val8, orig_i2c_bus;
79 * Assign PIB PMC slot to desired PCI bus
81 /* Switch temporarily to I2C bus #2 */
82 orig_i2c_bus = i2c_get_bus_num();
86 i2c_write(0x23, 0x6, 1, &val8, 1);
87 i2c_write(0x23, 0x7, 1, &val8, 1);
89 i2c_write(0x23, 0x2, 1, &val8, 1);
90 i2c_write(0x23, 0x3, 1, &val8, 1);
93 i2c_write(0x26, 0x6, 1, &val8, 1);
95 i2c_write(0x26, 0x7, 1, &val8, 1);
96 #if defined(PCI_64BIT)
97 val8 = 0xf4; /* PMC2:PCI1/64-bit */
98 #elif defined(PCI_ALL_PCI1)
99 val8 = 0xf3; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI1 */
100 #elif defined(PCI_ONE_PCI1)
101 val8 = 0xf9; /* PMC1:PCI1 PMC2:PCI2 PMC3:PCI2 */
103 val8 = 0xf5; /* PMC1:PCI1 PMC2:PCI1 PMC3:PCI2 */
105 i2c_write(0x26, 0x2, 1, &val8, 1);
107 i2c_write(0x26, 0x3, 1, &val8, 1);
109 i2c_write(0x27, 0x6, 1, &val8, 1);
110 i2c_write(0x27, 0x7, 1, &val8, 1);
112 i2c_write(0x27, 0x2, 1, &val8, 1);
114 i2c_write(0x27, 0x3, 1, &val8, 1);
117 #if defined(PCI_64BIT)
118 printf("PCI1: 64-bit on PMC2\n");
119 #elif defined(PCI_ALL_PCI1)
120 printf("PCI1: 32-bit on PMC1, PMC2, PMC3\n");
121 #elif defined(PCI_ONE_PCI1)
122 printf("PCI1: 32-bit on PMC1\n");
123 printf("PCI2: 32-bit on PMC2, PMC3\n");
125 printf("PCI1: 32-bit on PMC1, PMC2\n");
126 printf("PCI2: 32-bit on PMC3\n");
128 /* Reset to original I2C bus */
129 i2c_set_bus_num(orig_i2c_bus);
132 /**************************************************************************
135 * NOTICE: PCI2 is not currently supported
141 volatile immap_t * immr;
142 volatile clk83xx_t * clk;
143 volatile law83xx_t * pci_law;
144 volatile pot83xx_t * pci_pot;
145 volatile pcictrl83xx_t * pci_ctrl;
146 volatile pciconf83xx_t * pci_conf;
150 struct pci_controller * hose;
152 immr = (immap_t *)CFG_IMMR;
153 clk = (clk83xx_t *)&immr->clk;
154 pci_law = immr->sysconf.pcilaw;
155 pci_pot = immr->ios.pot;
156 pci_ctrl = immr->pci_ctrl;
157 pci_conf = immr->pci_conf;
164 * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
169 clk->occr = 0xff000000;
173 * Release PCI RST Output signal
179 #ifdef CONFIG_MPC83XX_PCI2
185 /* We need to wait at least a 1sec based on PCI specs */
189 for (i = 0; i < 1000; ++i)
194 * Configure PCI Local Access Windows
196 pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
197 pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
199 pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
200 pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_4M;
203 * Configure PCI Outbound Translation Windows
206 /* PCI1 mem space - prefetch */
207 pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
208 pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
209 pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
212 pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
213 pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
214 pci_pot[1].pocmr = POCMR_EN | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
216 /* PCI1 mmio - non-prefetch mem space */
217 pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
218 pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
219 pci_pot[2].pocmr = POCMR_EN | (POCMR_CM_256M & POCMR_CM_MASK);
222 * Configure PCI Inbound Translation Windows
225 /* we need RAM mapped to PCI space for the devices to
226 * access main memory */
227 pci_ctrl[0].pitar1 = 0x0;
228 pci_ctrl[0].pibar1 = 0x0;
229 pci_ctrl[0].piebar1 = 0x0;
230 pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
232 hose->first_busno = 0;
233 hose->last_busno = 0xff;
235 /* PCI memory prefetch space */
236 pci_set_region(hose->regions + 0,
240 PCI_REGION_MEM|PCI_REGION_PREFETCH);
242 /* PCI memory space */
243 pci_set_region(hose->regions + 1,
250 pci_set_region(hose->regions + 2,
256 /* System memory space */
257 pci_set_region(hose->regions + 3,
258 CONFIG_PCI_SYS_MEM_BUS,
259 CONFIG_PCI_SYS_MEM_PHYS,
261 PCI_REGION_MEM | PCI_REGION_MEMORY);
263 hose->region_count = 4;
265 pci_setup_indirect(hose,
269 pci_register_hose(hose);
272 * Write to Command register
275 dev = PCI_BDF(hose->first_busno, 0, 0);
276 pci_hose_read_config_word (hose, dev, PCI_COMMAND, ®16);
277 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
278 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
281 * Clear non-reserved bits in status register.
283 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
284 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
285 pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
287 #ifdef CONFIG_PCI_SCAN_SHOW
288 printf("PCI: Bus Dev VenId DevId Class Int\n");
293 hose->last_busno = pci_hose_scan(hose);
295 #ifdef CONFIG_MPC83XX_PCI2
299 * Configure PCI Outbound Translation Windows
302 /* PCI2 mem space - prefetch */
303 pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
304 pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
305 pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | (POCMR_CM_256M & POCMR_CM_MASK);
308 pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
309 pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
310 pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | (POCMR_CM_1M & POCMR_CM_MASK);
312 /* PCI2 mmio - non-prefetch mem space */
313 pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
314 pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
315 pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | (POCMR_CM_256M & POCMR_CM_MASK);
318 * Configure PCI Inbound Translation Windows
321 /* we need RAM mapped to PCI space for the devices to
322 * access main memory */
323 pci_ctrl[1].pitar1 = 0x0;
324 pci_ctrl[1].pibar1 = 0x0;
325 pci_ctrl[1].piebar1 = 0x0;
326 pci_ctrl[1].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
328 hose->first_busno = pci_hose[0].last_busno + 1;
329 hose->last_busno = 0xff;
331 /* PCI memory prefetch space */
332 pci_set_region(hose->regions + 0,
336 PCI_REGION_MEM|PCI_REGION_PREFETCH);
338 /* PCI memory space */
339 pci_set_region(hose->regions + 1,
346 pci_set_region(hose->regions + 2,
352 /* System memory space */
353 pci_set_region(hose->regions + 3,
354 CONFIG_PCI_SYS_MEM_BUS,
355 CONFIG_PCI_SYS_MEM_PHYS,
357 PCI_REGION_MEM | PCI_REGION_MEMORY);
359 hose->region_count = 4;
361 pci_setup_indirect(hose,
365 pci_register_hose(hose);
368 * Write to Command register
371 dev = PCI_BDF(hose->first_busno, 0, 0);
372 pci_hose_read_config_word (hose, dev, PCI_COMMAND, ®16);
373 reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
374 pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
377 * Clear non-reserved bits in status register.
379 pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
380 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
381 pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
386 hose->last_busno = pci_hose_scan(hose);
391 #if defined(CONFIG_OF_LIBFDT)
393 ft_pci_setup(void *blob, bd_t *bd)
399 nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8500");
400 if (nodeoffset >= 0) {
401 tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
402 tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
403 err = fdt_setprop(blob, nodeoffset, "bus-range",
406 tmp[0] = cpu_to_be32(gd->pci_clk);
407 err = fdt_setprop(blob, nodeoffset, "clock-frequency",
408 tmp, sizeof(tmp[0]));
410 #ifdef CONFIG_MPC83XX_PCI2
411 nodeoffset = fdt_find_node_by_path(blob, "/" OF_SOC "/pci@8600");
412 if (nodeoffset >= 0) {
413 tmp[0] = cpu_to_be32(pci_hose[1].first_busno);
414 tmp[1] = cpu_to_be32(pci_hose[1].last_busno);
415 err = fdt_setprop(blob, nodeoffset, "bus-range",
418 tmp[0] = cpu_to_be32(gd->pci_clk);
419 err = fdt_setprop(blob, nodeoffset, "clock-frequency",
420 tmp, sizeof(tmp[0]));
424 #elif defined(CONFIG_OF_FLAT_TREE)
426 ft_pci_setup(void *blob, bd_t *bd)
431 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
433 p[0] = pci_hose[0].first_busno;
434 p[1] = pci_hose[0].last_busno;
437 #ifdef CONFIG_MPC83XX_PCI2
438 p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8600/bus-range", &len);
440 p[0] = pci_hose[1].first_busno;
441 p[1] = pci_hose[1].last_busno;
445 #endif /* CONFIG_OF_FLAT_TREE */
446 #endif /* CONFIG_PCI */