blob: 4557ac5255c1fda03f7fe43025d93f333465a677 [file] [log] [blame]
Kumar Gala7d13d212006-01-13 11:19:58 -06001/*
2 * FSL SoC setup code
3 *
4 * Maintained by Kumar Gala (see MAINTAINERS for contact information)
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
Kumar Gala7d13d212006-01-13 11:19:58 -060012#include <linux/stddef.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/errno.h>
16#include <linux/pci.h>
17#include <linux/delay.h>
18#include <linux/irq.h>
19#include <linux/module.h>
20
21#include <asm/system.h>
22#include <asm/atomic.h>
23#include <asm/io.h>
24#include <asm/pci-bridge.h>
25#include <asm/prom.h>
26#include <sysdev/fsl_soc.h>
27
28#undef DEBUG
29
30#ifdef DEBUG
31#define DBG(x...) printk(x)
32#else
33#define DBG(x...)
34#endif
35
36int mpc83xx_pci2_busno;
37
Kumar Gala30f59332006-02-02 13:50:44 -060038int mpc83xx_exclude_device(u_char bus, u_char devfn)
39{
40 if (bus == 0 && PCI_SLOT(devfn) == 0)
41 return PCIBIOS_DEVICE_NOT_FOUND;
42 if (mpc83xx_pci2_busno)
43 if (bus == (mpc83xx_pci2_busno) && PCI_SLOT(devfn) == 0)
44 return PCIBIOS_DEVICE_NOT_FOUND;
45 return PCIBIOS_SUCCESSFUL;
46}
47
Kim Phillipsf1f17712006-08-25 11:59:22 -050048void __init mpc83xx_pcibios_fixup(void)
49{
50 struct pci_dev *dev = NULL;
51
52 /* map all the PCI irqs */
53 for_each_pci_dev(dev)
54 pci_read_irq_line(dev);
55}
56
Kumar Gala7d13d212006-01-13 11:19:58 -060057int __init add_bridge(struct device_node *dev)
58{
59 int len;
60 struct pci_controller *hose;
61 struct resource rsrc;
Jeremy Kerr8efca492006-07-12 15:39:42 +100062 const int *bus_range;
Kumar Gala7d13d212006-01-13 11:19:58 -060063 int primary = 1, has_address = 0;
64 phys_addr_t immr = get_immrbase();
65
66 DBG("Adding PCI host bridge %s\n", dev->full_name);
67
68 /* Fetch host bridge registers address */
69 has_address = (of_address_to_resource(dev, 0, &rsrc) == 0);
70
71 /* Get bus range if any */
Jeremy Kerr8efca492006-07-12 15:39:42 +100072 bus_range = get_property(dev, "bus-range", &len);
Kumar Gala7d13d212006-01-13 11:19:58 -060073 if (bus_range == NULL || len < 2 * sizeof(int)) {
74 printk(KERN_WARNING "Can't get bus-range for %s, assume"
75 " bus 0\n", dev->full_name);
76 }
77
78 hose = pcibios_alloc_controller();
79 if (!hose)
80 return -ENOMEM;
81 hose->arch_data = dev;
82 hose->set_cfg_type = 1;
83
84 hose->first_busno = bus_range ? bus_range[0] : 0;
85 hose->last_busno = bus_range ? bus_range[1] : 0xff;
86
87 /* MPC83xx supports up to two host controllers one at 0x8500 from immrbar
88 * the other at 0x8600, we consider the 0x8500 the primary controller
89 */
90 /* PCI 1 */
91 if ((rsrc.start & 0xfffff) == 0x8500) {
92 setup_indirect_pci(hose, immr + 0x8300, immr + 0x8304);
93 }
Kumar Galae060e082006-02-02 13:51:10 -060094 /* PCI 2 */
Kumar Gala7d13d212006-01-13 11:19:58 -060095 if ((rsrc.start & 0xfffff) == 0x8600) {
96 setup_indirect_pci(hose, immr + 0x8380, immr + 0x8384);
97 primary = 0;
98 hose->bus_offset = hose->first_busno;
99 mpc83xx_pci2_busno = hose->first_busno;
100 }
101
Greg Kroah-Hartman685143a2006-06-12 15:18:31 -0700102 printk(KERN_INFO "Found MPC83xx PCI host bridge at 0x%016llx. "
Kumar Gala7d13d212006-01-13 11:19:58 -0600103 "Firmware bus number: %d->%d\n",
Greg Kroah-Hartman685143a2006-06-12 15:18:31 -0700104 (unsigned long long)rsrc.start, hose->first_busno,
105 hose->last_busno);
Kumar Gala7d13d212006-01-13 11:19:58 -0600106
107 DBG(" ->Hose at 0x%p, cfg_addr=0x%p,cfg_data=0x%p\n",
Kumar Galae060e082006-02-02 13:51:10 -0600108 hose, hose->cfg_addr, hose->cfg_data);
Kumar Gala7d13d212006-01-13 11:19:58 -0600109
110 /* Interpret the "ranges" property */
111 /* This also maps the I/O region and sets isa_io/mem_base */
112 pci_process_bridge_OF_ranges(hose, dev, primary);
113
114 return 0;
115}