1e58fe957SKim Phillips /*
2e58fe957SKim Phillips  * Copyright (C) Freescale Semiconductor, Inc. 2006. All rights reserved.
3e58fe957SKim Phillips  *
4e58fe957SKim Phillips  * See file CREDITS for list of people who contributed to this
5e58fe957SKim Phillips  * project.
6e58fe957SKim Phillips  *
7e58fe957SKim Phillips  * This program is free software; you can redistribute it and/or
8e58fe957SKim Phillips  * modify it under the terms of the GNU General Public License as
9e58fe957SKim Phillips  * published by the Free Software Foundation; either version 2 of
10e58fe957SKim Phillips  * the License, or (at your option) any later version.
11e58fe957SKim Phillips  *
12e58fe957SKim Phillips  * This program is distributed in the hope that it will be useful,
13e58fe957SKim Phillips  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14e58fe957SKim Phillips  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15e58fe957SKim Phillips  * GNU General Public License for more details.
16e58fe957SKim Phillips  *
17e58fe957SKim Phillips  * You should have received a copy of the GNU General Public License
18e58fe957SKim Phillips  * along with this program; if not, write to the Free Software
19e58fe957SKim Phillips  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20e58fe957SKim Phillips  * MA 02111-1307 USA
21e58fe957SKim Phillips  */
22e58fe957SKim Phillips 
23e58fe957SKim Phillips #include <common.h>
24e58fe957SKim Phillips 
25e58fe957SKim Phillips #ifdef CONFIG_PCI
26e58fe957SKim Phillips 
27e58fe957SKim Phillips #include <asm/mmu.h>
28e58fe957SKim Phillips #include <asm/global_data.h>
29e58fe957SKim Phillips #include <pci.h>
30e58fe957SKim Phillips #include <asm/mpc8349_pci.h>
31e58fe957SKim Phillips #include <i2c.h>
32e58fe957SKim Phillips #if defined(CONFIG_OF_FLAT_TREE)
33e58fe957SKim Phillips #include <ft_build.h>
34e58fe957SKim Phillips #elif defined(CONFIG_OF_LIBFDT)
35e58fe957SKim Phillips #include <libfdt.h>
36*5b8bc606SKim Phillips #include <fdt_support.h>
37e58fe957SKim Phillips #endif
38e58fe957SKim Phillips 
39e58fe957SKim Phillips DECLARE_GLOBAL_DATA_PTR;
40e58fe957SKim Phillips 
41e58fe957SKim Phillips /* System RAM mapped to PCI space */
42e58fe957SKim Phillips #define CONFIG_PCI_SYS_MEM_BUS	CFG_SDRAM_BASE
43e58fe957SKim Phillips #define CONFIG_PCI_SYS_MEM_PHYS	CFG_SDRAM_BASE
44e58fe957SKim Phillips 
45e58fe957SKim Phillips #ifndef CONFIG_PCI_PNP
46e58fe957SKim Phillips static struct pci_config_table pci_mpc8349itx_config_table[] = {
47e58fe957SKim Phillips 	{
48e58fe957SKim Phillips 	 PCI_ANY_ID,
49e58fe957SKim Phillips 	 PCI_ANY_ID,
50e58fe957SKim Phillips 	 PCI_ANY_ID,
51e58fe957SKim Phillips 	 PCI_ANY_ID,
52e58fe957SKim Phillips 	 PCI_IDSEL_NUMBER,
53e58fe957SKim Phillips 	 PCI_ANY_ID,
54e58fe957SKim Phillips 	 pci_cfgfunc_config_device,
55e58fe957SKim Phillips 	 {
56e58fe957SKim Phillips 	  PCI_ENET0_IOADDR,
57e58fe957SKim Phillips 	  PCI_ENET0_MEMADDR,
58e58fe957SKim Phillips 	  PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER}
59e58fe957SKim Phillips 	 },
60e58fe957SKim Phillips 	{}
61e58fe957SKim Phillips };
62e58fe957SKim Phillips #endif
63e58fe957SKim Phillips 
64e58fe957SKim Phillips static struct pci_controller pci_hose[] = {
65e58fe957SKim Phillips 	{
66e58fe957SKim Phillips #ifndef CONFIG_PCI_PNP
67e58fe957SKim Phillips 	      config_table:pci_mpc8349itx_config_table,
68e58fe957SKim Phillips #endif
69e58fe957SKim Phillips 	 },
70e58fe957SKim Phillips 	{
71e58fe957SKim Phillips #ifndef CONFIG_PCI_PNP
72e58fe957SKim Phillips 	      config_table:pci_mpc8349itx_config_table,
73e58fe957SKim Phillips #endif
74e58fe957SKim Phillips 	 }
75e58fe957SKim Phillips };
76e58fe957SKim Phillips 
77e58fe957SKim Phillips /**************************************************************************
78e58fe957SKim Phillips  * pci_init_board()
79e58fe957SKim Phillips  *
80e58fe957SKim Phillips  * NOTICE: PCI2 is not currently supported
81e58fe957SKim Phillips  *
82e58fe957SKim Phillips  */
83e58fe957SKim Phillips void pci_init_board(void)
84e58fe957SKim Phillips {
85e58fe957SKim Phillips 	volatile immap_t *immr;
86e58fe957SKim Phillips 	volatile clk83xx_t *clk;
87e58fe957SKim Phillips 	volatile law83xx_t *pci_law;
88e58fe957SKim Phillips 	volatile pot83xx_t *pci_pot;
89e58fe957SKim Phillips 	volatile pcictrl83xx_t *pci_ctrl;
90e58fe957SKim Phillips 	volatile pciconf83xx_t *pci_conf;
91e58fe957SKim Phillips 	u8 reg8;
92e58fe957SKim Phillips 	u16 reg16;
93e58fe957SKim Phillips 	u32 reg32;
94e58fe957SKim Phillips 	u32 dev;
95e58fe957SKim Phillips 	struct pci_controller *hose;
96e58fe957SKim Phillips 
97e58fe957SKim Phillips 	immr = (immap_t *) CFG_IMMR;
98e58fe957SKim Phillips 	clk = (clk83xx_t *) & immr->clk;
99e58fe957SKim Phillips 	pci_law = immr->sysconf.pcilaw;
100e58fe957SKim Phillips 	pci_pot = immr->ios.pot;
101e58fe957SKim Phillips 	pci_ctrl = immr->pci_ctrl;
102e58fe957SKim Phillips 	pci_conf = immr->pci_conf;
103e58fe957SKim Phillips 
104e58fe957SKim Phillips 	hose = &pci_hose[0];
105e58fe957SKim Phillips 
106e58fe957SKim Phillips 	/*
107e58fe957SKim Phillips 	 * Configure PCI controller and PCI_CLK_OUTPUT both in 66M mode
108e58fe957SKim Phillips 	 */
109e58fe957SKim Phillips 
110e58fe957SKim Phillips 	reg32 = clk->occr;
111e58fe957SKim Phillips 	udelay(2000);
112e58fe957SKim Phillips 
113e58fe957SKim Phillips #ifdef CONFIG_HARD_I2C
114e58fe957SKim Phillips 	i2c_set_bus_num(1);
115e58fe957SKim Phillips 	/* Read the PCI_M66EN jumper setting */
116e58fe957SKim Phillips 	if ((i2c_read(CFG_I2C_8574_ADDR2, 0, 0, &reg8, sizeof(reg8)) == 0) ||
117e58fe957SKim Phillips 	    (i2c_read(CFG_I2C_8574A_ADDR2, 0, 0, &reg8, sizeof(reg8)) == 0)) {
118e58fe957SKim Phillips 		if (reg8 & I2C_8574_PCI66)
119e58fe957SKim Phillips 			clk->occr = 0xff000000;	/* 66 MHz PCI */
120e58fe957SKim Phillips 		else
121e58fe957SKim Phillips 			clk->occr = 0xff600001;	/* 33 MHz PCI */
122e58fe957SKim Phillips 	} else {
123e58fe957SKim Phillips 		clk->occr = 0xff600001;	/* 33 MHz PCI */
124e58fe957SKim Phillips 	}
125e58fe957SKim Phillips #else
126e58fe957SKim Phillips 	clk->occr = 0xff000000;	/* 66 MHz PCI */
127e58fe957SKim Phillips #endif
128e58fe957SKim Phillips 
129e58fe957SKim Phillips 	udelay(2000);
130e58fe957SKim Phillips 
131e58fe957SKim Phillips 	/*
132e58fe957SKim Phillips 	 * Release PCI RST Output signal
133e58fe957SKim Phillips 	 */
134e58fe957SKim Phillips 	pci_ctrl[0].gcr = 0;
135e58fe957SKim Phillips 	udelay(2000);
136e58fe957SKim Phillips 	pci_ctrl[0].gcr = 1;
137e58fe957SKim Phillips 
138e58fe957SKim Phillips #ifdef CONFIG_MPC83XX_PCI2
139e58fe957SKim Phillips 	pci_ctrl[1].gcr = 0;
140e58fe957SKim Phillips 	udelay(2000);
141e58fe957SKim Phillips 	pci_ctrl[1].gcr = 1;
142e58fe957SKim Phillips #endif
143e58fe957SKim Phillips 
144e58fe957SKim Phillips 	/* We need to wait at least a 1sec based on PCI specs */
145e58fe957SKim Phillips 	{
146e58fe957SKim Phillips 		int i;
147e58fe957SKim Phillips 
148e58fe957SKim Phillips 		for (i = 0; i < 1000; i++)
149e58fe957SKim Phillips 			udelay(1000);
150e58fe957SKim Phillips 	}
151e58fe957SKim Phillips 
152e58fe957SKim Phillips 	/*
153e58fe957SKim Phillips 	 * Configure PCI Local Access Windows
154e58fe957SKim Phillips 	 */
155e58fe957SKim Phillips 	pci_law[0].bar = CFG_PCI1_MEM_PHYS & LAWBAR_BAR;
156e58fe957SKim Phillips 	pci_law[0].ar = LAWAR_EN | LAWAR_SIZE_1G;
157e58fe957SKim Phillips 
158e58fe957SKim Phillips 	pci_law[1].bar = CFG_PCI1_IO_PHYS & LAWBAR_BAR;
159e58fe957SKim Phillips 	pci_law[1].ar = LAWAR_EN | LAWAR_SIZE_32M;
160e58fe957SKim Phillips 
161e58fe957SKim Phillips 	/*
162e58fe957SKim Phillips 	 * Configure PCI Outbound Translation Windows
163e58fe957SKim Phillips 	 */
164e58fe957SKim Phillips 
165e58fe957SKim Phillips 	/* PCI1 mem space - prefetch */
166e58fe957SKim Phillips 	pci_pot[0].potar = (CFG_PCI1_MEM_BASE >> 12) & POTAR_TA_MASK;
167e58fe957SKim Phillips 	pci_pot[0].pobar = (CFG_PCI1_MEM_PHYS >> 12) & POBAR_BA_MASK;
168e58fe957SKim Phillips 	pci_pot[0].pocmr = POCMR_EN | POCMR_PREFETCH_EN | POCMR_CM_256M;
169e58fe957SKim Phillips 
170e58fe957SKim Phillips 	/* PCI1 IO space */
171e58fe957SKim Phillips 	pci_pot[1].potar = (CFG_PCI1_IO_BASE >> 12) & POTAR_TA_MASK;
172e58fe957SKim Phillips 	pci_pot[1].pobar = (CFG_PCI1_IO_PHYS >> 12) & POBAR_BA_MASK;
173e58fe957SKim Phillips 	pci_pot[1].pocmr = POCMR_EN | POCMR_IO | POCMR_CM_16M;
174e58fe957SKim Phillips 
175e58fe957SKim Phillips 	/* PCI1 mmio - non-prefetch mem space */
176e58fe957SKim Phillips 	pci_pot[2].potar = (CFG_PCI1_MMIO_BASE >> 12) & POTAR_TA_MASK;
177e58fe957SKim Phillips 	pci_pot[2].pobar = (CFG_PCI1_MMIO_PHYS >> 12) & POBAR_BA_MASK;
178e58fe957SKim Phillips 	pci_pot[2].pocmr = POCMR_EN | POCMR_CM_256M;
179e58fe957SKim Phillips 
180e58fe957SKim Phillips 	/*
181e58fe957SKim Phillips 	 * Configure PCI Inbound Translation Windows
182e58fe957SKim Phillips 	 */
183e58fe957SKim Phillips 
184e58fe957SKim Phillips 	/* we need RAM mapped to PCI space for the devices to
185e58fe957SKim Phillips 	 * access main memory */
186e58fe957SKim Phillips 	pci_ctrl[0].pitar1 = 0x0;
187e58fe957SKim Phillips 	pci_ctrl[0].pibar1 = 0x0;
188e58fe957SKim Phillips 	pci_ctrl[0].piebar1 = 0x0;
189e58fe957SKim Phillips 	pci_ctrl[0].piwar1 = PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP |
190e58fe957SKim Phillips 	    PIWAR_WTT_SNOOP | (__ilog2(gd->ram_size) - 1);
191e58fe957SKim Phillips 
192e58fe957SKim Phillips 	hose->first_busno = 0;
193e58fe957SKim Phillips 	hose->last_busno = 0xff;
194e58fe957SKim Phillips 
195e58fe957SKim Phillips 	/* PCI memory prefetch space */
196e58fe957SKim Phillips 	pci_set_region(hose->regions + 0,
197e58fe957SKim Phillips 		       CFG_PCI1_MEM_BASE,
198e58fe957SKim Phillips 		       CFG_PCI1_MEM_PHYS,
199e58fe957SKim Phillips 		       CFG_PCI1_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
200e58fe957SKim Phillips 
201e58fe957SKim Phillips 	/* PCI memory space */
202e58fe957SKim Phillips 	pci_set_region(hose->regions + 1,
203e58fe957SKim Phillips 		       CFG_PCI1_MMIO_BASE,
204e58fe957SKim Phillips 		       CFG_PCI1_MMIO_PHYS, CFG_PCI1_MMIO_SIZE, PCI_REGION_MEM);
205e58fe957SKim Phillips 
206e58fe957SKim Phillips 	/* PCI IO space */
207e58fe957SKim Phillips 	pci_set_region(hose->regions + 2,
208e58fe957SKim Phillips 		       CFG_PCI1_IO_BASE,
209e58fe957SKim Phillips 		       CFG_PCI1_IO_PHYS, CFG_PCI1_IO_SIZE, PCI_REGION_IO);
210e58fe957SKim Phillips 
211e58fe957SKim Phillips 	/* System memory space */
212e58fe957SKim Phillips 	pci_set_region(hose->regions + 3,
213e58fe957SKim Phillips 		       CONFIG_PCI_SYS_MEM_BUS,
214e58fe957SKim Phillips 		       CONFIG_PCI_SYS_MEM_PHYS,
215e58fe957SKim Phillips 		       gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
216e58fe957SKim Phillips 
217e58fe957SKim Phillips 	hose->region_count = 4;
218e58fe957SKim Phillips 
219e58fe957SKim Phillips 	pci_setup_indirect(hose,
220e58fe957SKim Phillips 			   (CFG_IMMR + 0x8300), (CFG_IMMR + 0x8304));
221e58fe957SKim Phillips 
222e58fe957SKim Phillips 	pci_register_hose(hose);
223e58fe957SKim Phillips 
224e58fe957SKim Phillips 	/*
225e58fe957SKim Phillips 	 * Write to Command register
226e58fe957SKim Phillips 	 */
227e58fe957SKim Phillips 	reg16 = 0xff;
228e58fe957SKim Phillips 	dev = PCI_BDF(hose->first_busno, 0, 0);
229e58fe957SKim Phillips 	pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
230e58fe957SKim Phillips 	reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
231e58fe957SKim Phillips 	pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
232e58fe957SKim Phillips 
233e58fe957SKim Phillips 	/*
234e58fe957SKim Phillips 	 * Clear non-reserved bits in status register.
235e58fe957SKim Phillips 	 */
236e58fe957SKim Phillips 	pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
237e58fe957SKim Phillips 	pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
238e58fe957SKim Phillips 	pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
239e58fe957SKim Phillips 
240e58fe957SKim Phillips #ifdef CONFIG_PCI_SCAN_SHOW
241e58fe957SKim Phillips 	printf("PCI:   Bus Dev VenId DevId Class Int\n");
242e58fe957SKim Phillips #endif
243e58fe957SKim Phillips 	/*
244e58fe957SKim Phillips 	 * Hose scan.
245e58fe957SKim Phillips 	 */
246e58fe957SKim Phillips 	hose->last_busno = pci_hose_scan(hose);
247e58fe957SKim Phillips 
248e58fe957SKim Phillips #ifdef CONFIG_MPC83XX_PCI2
249e58fe957SKim Phillips 	hose = &pci_hose[1];
250e58fe957SKim Phillips 
251e58fe957SKim Phillips 	/*
252e58fe957SKim Phillips 	 * Configure PCI Outbound Translation Windows
253e58fe957SKim Phillips 	 */
254e58fe957SKim Phillips 
255e58fe957SKim Phillips 	/* PCI2 mem space - prefetch */
256e58fe957SKim Phillips 	pci_pot[3].potar = (CFG_PCI2_MEM_BASE >> 12) & POTAR_TA_MASK;
257e58fe957SKim Phillips 	pci_pot[3].pobar = (CFG_PCI2_MEM_PHYS >> 12) & POBAR_BA_MASK;
258e58fe957SKim Phillips 	pci_pot[3].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_PREFETCH_EN | POCMR_CM_256M;
259e58fe957SKim Phillips 
260e58fe957SKim Phillips 	/* PCI2 IO space */
261e58fe957SKim Phillips 	pci_pot[4].potar = (CFG_PCI2_IO_BASE >> 12) & POTAR_TA_MASK;
262e58fe957SKim Phillips 	pci_pot[4].pobar = (CFG_PCI2_IO_PHYS >> 12) & POBAR_BA_MASK;
263e58fe957SKim Phillips 	pci_pot[4].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_IO | POCMR_CM_16M;
264e58fe957SKim Phillips 
265e58fe957SKim Phillips 	/* PCI2 mmio - non-prefetch mem space */
266e58fe957SKim Phillips 	pci_pot[5].potar = (CFG_PCI2_MMIO_BASE >> 12) & POTAR_TA_MASK;
267e58fe957SKim Phillips 	pci_pot[5].pobar = (CFG_PCI2_MMIO_PHYS >> 12) & POBAR_BA_MASK;
268e58fe957SKim Phillips 	pci_pot[5].pocmr = POCMR_EN | POCMR_PCI2 | POCMR_CM_256M;
269e58fe957SKim Phillips 
270e58fe957SKim Phillips 	/*
271e58fe957SKim Phillips 	 * Configure PCI Inbound Translation Windows
272e58fe957SKim Phillips 	 */
273e58fe957SKim Phillips 
274e58fe957SKim Phillips 	/* we need RAM mapped to PCI space for the devices to
275e58fe957SKim Phillips 	 * access main memory */
276e58fe957SKim Phillips 	pci_ctrl[1].pitar1 = 0x0;
277e58fe957SKim Phillips 	pci_ctrl[1].pibar1 = 0x0;
278e58fe957SKim Phillips 	pci_ctrl[1].piebar1 = 0x0;
279e58fe957SKim Phillips 	pci_ctrl[1].piwar1 =
280e58fe957SKim Phillips 	    PIWAR_EN | PIWAR_PF | PIWAR_RTT_SNOOP | PIWAR_WTT_SNOOP |
281e58fe957SKim Phillips 	    (__ilog2(gd->ram_size) - 1);
282e58fe957SKim Phillips 
283e58fe957SKim Phillips 	hose->first_busno = pci_hose[0].last_busno + 1;
284e58fe957SKim Phillips 	hose->last_busno = 0xff;
285e58fe957SKim Phillips 
286e58fe957SKim Phillips 	/* PCI memory prefetch space */
287e58fe957SKim Phillips 	pci_set_region(hose->regions + 0,
288e58fe957SKim Phillips 		       CFG_PCI2_MEM_BASE,
289e58fe957SKim Phillips 		       CFG_PCI2_MEM_PHYS,
290e58fe957SKim Phillips 		       CFG_PCI2_MEM_SIZE, PCI_REGION_MEM | PCI_REGION_PREFETCH);
291e58fe957SKim Phillips 
292e58fe957SKim Phillips 	/* PCI memory space */
293e58fe957SKim Phillips 	pci_set_region(hose->regions + 1,
294e58fe957SKim Phillips 		       CFG_PCI2_MMIO_BASE,
295e58fe957SKim Phillips 		       CFG_PCI2_MMIO_PHYS, CFG_PCI2_MMIO_SIZE, PCI_REGION_MEM);
296e58fe957SKim Phillips 
297e58fe957SKim Phillips 	/* PCI IO space */
298e58fe957SKim Phillips 	pci_set_region(hose->regions + 2,
299e58fe957SKim Phillips 		       CFG_PCI2_IO_BASE,
300e58fe957SKim Phillips 		       CFG_PCI2_IO_PHYS, CFG_PCI2_IO_SIZE, PCI_REGION_IO);
301e58fe957SKim Phillips 
302e58fe957SKim Phillips 	/* System memory space */
303e58fe957SKim Phillips 	pci_set_region(hose->regions + 3,
304e58fe957SKim Phillips 		       CONFIG_PCI_SYS_MEM_BUS,
305e58fe957SKim Phillips 		       CONFIG_PCI_SYS_MEM_PHYS,
306e58fe957SKim Phillips 		       gd->ram_size, PCI_REGION_MEM | PCI_REGION_MEMORY);
307e58fe957SKim Phillips 
308e58fe957SKim Phillips 	hose->region_count = 4;
309e58fe957SKim Phillips 
310e58fe957SKim Phillips 	pci_setup_indirect(hose,
311e58fe957SKim Phillips 			   (CFG_IMMR + 0x8380), (CFG_IMMR + 0x8384));
312e58fe957SKim Phillips 
313e58fe957SKim Phillips 	pci_register_hose(hose);
314e58fe957SKim Phillips 
315e58fe957SKim Phillips 	/*
316e58fe957SKim Phillips 	 * Write to Command register
317e58fe957SKim Phillips 	 */
318e58fe957SKim Phillips 	reg16 = 0xff;
319e58fe957SKim Phillips 	dev = PCI_BDF(hose->first_busno, 0, 0);
320e58fe957SKim Phillips 	pci_hose_read_config_word(hose, dev, PCI_COMMAND, &reg16);
321e58fe957SKim Phillips 	reg16 |= PCI_COMMAND_SERR | PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
322e58fe957SKim Phillips 	pci_hose_write_config_word(hose, dev, PCI_COMMAND, reg16);
323e58fe957SKim Phillips 
324e58fe957SKim Phillips 	/*
325e58fe957SKim Phillips 	 * Clear non-reserved bits in status register.
326e58fe957SKim Phillips 	 */
327e58fe957SKim Phillips 	pci_hose_write_config_word(hose, dev, PCI_STATUS, 0xffff);
328e58fe957SKim Phillips 	pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, 0x80);
329e58fe957SKim Phillips 	pci_hose_write_config_byte(hose, dev, PCI_CACHE_LINE_SIZE, 0x08);
330e58fe957SKim Phillips 
331e58fe957SKim Phillips 	/*
332e58fe957SKim Phillips 	 * Hose scan.
333e58fe957SKim Phillips 	 */
334e58fe957SKim Phillips 	hose->last_busno = pci_hose_scan(hose);
335e58fe957SKim Phillips #endif
336e58fe957SKim Phillips }
337e58fe957SKim Phillips 
338e58fe957SKim Phillips #if defined(CONFIG_OF_LIBFDT)
339*5b8bc606SKim Phillips void ft_pci_setup(void *blob, bd_t *bd)
340e58fe957SKim Phillips {
341e58fe957SKim Phillips 	int nodeoffset;
342e58fe957SKim Phillips 	int tmp[2];
343*5b8bc606SKim Phillips 	const char *path;
344e58fe957SKim Phillips 
345*5b8bc606SKim Phillips 	nodeoffset = fdt_path_offset(blob, "/aliases");
346e58fe957SKim Phillips 	if (nodeoffset >= 0) {
347*5b8bc606SKim Phillips 		path = fdt_getprop(blob, nodeoffset, "pci0", NULL);
348*5b8bc606SKim Phillips 		if (path) {
349e58fe957SKim Phillips 			tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
350e58fe957SKim Phillips 			tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
351*5b8bc606SKim Phillips 			do_fixup_by_path(blob, path, "bus-range",
352*5b8bc606SKim Phillips 				&tmp, sizeof(tmp), 1);
353e58fe957SKim Phillips 
354e58fe957SKim Phillips 			tmp[0] = cpu_to_be32(gd->pci_clk);
355*5b8bc606SKim Phillips 			do_fixup_by_path(blob, path, "clock-frequency",
356*5b8bc606SKim Phillips 				&tmp, sizeof(tmp[0]), 1);
357e58fe957SKim Phillips 		}
358e58fe957SKim Phillips #ifdef CONFIG_MPC83XX_PCI2
359*5b8bc606SKim Phillips 		path = fdt_getprop(blob, nodeoffset, "pci1", NULL);
360*5b8bc606SKim Phillips 		if (path) {
361*5b8bc606SKim Phillips 			tmp[0] = cpu_to_be32(pci_hose[0].first_busno);
362*5b8bc606SKim Phillips 			tmp[1] = cpu_to_be32(pci_hose[0].last_busno);
363*5b8bc606SKim Phillips 			do_fixup_by_path(blob, path, "bus-range",
364*5b8bc606SKim Phillips 				&tmp, sizeof(tmp), 1);
365e58fe957SKim Phillips 
366e58fe957SKim Phillips 			tmp[0] = cpu_to_be32(gd->pci_clk);
367*5b8bc606SKim Phillips 			do_fixup_by_path(blob, path, "clock-frequency",
368*5b8bc606SKim Phillips 				&tmp, sizeof(tmp[0]), 1);
369e58fe957SKim Phillips 		}
370e58fe957SKim Phillips #endif
371e58fe957SKim Phillips 	}
372*5b8bc606SKim Phillips }
373e58fe957SKim Phillips #elif defined(CONFIG_OF_FLAT_TREE)
374e58fe957SKim Phillips void
375e58fe957SKim Phillips ft_pci_setup(void *blob, bd_t *bd)
376e58fe957SKim Phillips {
377e58fe957SKim Phillips        	u32 *p;
378e58fe957SKim Phillips        	int len;
379e58fe957SKim Phillips 
380e58fe957SKim Phillips        	p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8500/bus-range", &len);
381e58fe957SKim Phillips        	if (p != NULL) {
382e58fe957SKim Phillips 		p[0] = pci_hose[0].first_busno;
383e58fe957SKim Phillips 		p[1] = pci_hose[0].last_busno;
384e58fe957SKim Phillips        	}
385e58fe957SKim Phillips 
386e58fe957SKim Phillips #ifdef CONFIG_MPC83XX_PCI2
387e58fe957SKim Phillips 	p = (u32 *)ft_get_prop(blob, "/" OF_SOC "/pci@8600/bus-range", &len);
388e58fe957SKim Phillips 	if (p != NULL) {
389e58fe957SKim Phillips 		p[0] = pci_hose[1].first_busno;
390e58fe957SKim Phillips 		p[1] = pci_hose[1].last_busno;
391e58fe957SKim Phillips 	}
392e58fe957SKim Phillips #endif
393e58fe957SKim Phillips }
394e58fe957SKim Phillips #endif /* CONFIG_OF_FLAT_TREE */
395e58fe957SKim Phillips #endif /* CONFIG_PCI */
396