Merge branch 'for-linus' of git://oss.sgi.com/xfs/xfs
[linux/fpc-iii.git] / arch / arm / mach-kirkwood / pcie.c
blobdee1eff50d3933d2252a2f66aed2f1d7456d69c3
1 /*
2 * arch/arm/mach-kirkwood/pcie.c
4 * PCIe functions for Marvell Kirkwood SoCs
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 */
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <linux/slab.h>
14 #include <linux/mbus.h>
15 #include <asm/irq.h>
16 #include <asm/mach/pci.h>
17 #include <plat/pcie.h>
18 #include <mach/bridge-regs.h>
19 #include "common.h"
22 #define PCIE_BASE ((void __iomem *)PCIE_VIRT_BASE)
24 void __init kirkwood_pcie_id(u32 *dev, u32 *rev)
26 *dev = orion_pcie_dev_id(PCIE_BASE);
27 *rev = orion_pcie_rev(PCIE_BASE);
30 static int pcie_valid_config(int bus, int dev)
33 * Don't go out when trying to access --
34 * 1. nonexisting device on local bus
35 * 2. where there's no device connected (no link)
37 if (bus == 0 && dev == 0)
38 return 1;
40 if (!orion_pcie_link_up(PCIE_BASE))
41 return 0;
43 if (bus == 0 && dev != 1)
44 return 0;
46 return 1;
51 * PCIe config cycles are done by programming the PCIE_CONF_ADDR register
52 * and then reading the PCIE_CONF_DATA register. Need to make sure these
53 * transactions are atomic.
55 static DEFINE_SPINLOCK(kirkwood_pcie_lock);
57 static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
58 int size, u32 *val)
60 unsigned long flags;
61 int ret;
63 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
64 *val = 0xffffffff;
65 return PCIBIOS_DEVICE_NOT_FOUND;
68 spin_lock_irqsave(&kirkwood_pcie_lock, flags);
69 ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
70 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
72 return ret;
75 static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
76 int where, int size, u32 val)
78 unsigned long flags;
79 int ret;
81 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
82 return PCIBIOS_DEVICE_NOT_FOUND;
84 spin_lock_irqsave(&kirkwood_pcie_lock, flags);
85 ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
86 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
88 return ret;
91 static struct pci_ops pcie_ops = {
92 .read = pcie_rd_conf,
93 .write = pcie_wr_conf,
97 static int __init kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
99 struct resource *res;
100 extern unsigned int kirkwood_clk_ctrl;
103 * Generic PCIe unit setup.
105 orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info);
108 * Request resources.
110 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
111 if (!res)
112 panic("pcie_setup unable to alloc resources");
115 * IORESOURCE_IO
117 res[0].name = "PCIe I/O Space";
118 res[0].flags = IORESOURCE_IO;
119 res[0].start = KIRKWOOD_PCIE_IO_BUS_BASE;
120 res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
121 if (request_resource(&ioport_resource, &res[0]))
122 panic("Request PCIe IO resource failed\n");
123 sys->resource[0] = &res[0];
126 * IORESOURCE_MEM
128 res[1].name = "PCIe Memory Space";
129 res[1].flags = IORESOURCE_MEM;
130 res[1].start = KIRKWOOD_PCIE_MEM_BUS_BASE;
131 res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
132 if (request_resource(&iomem_resource, &res[1]))
133 panic("Request PCIe Memory resource failed\n");
134 sys->resource[1] = &res[1];
136 sys->resource[2] = NULL;
137 sys->io_offset = 0;
139 kirkwood_clk_ctrl |= CGC_PEX0;
141 return 1;
144 static void __devinit rc_pci_fixup(struct pci_dev *dev)
147 * Prevent enumeration of root complex.
149 if (dev->bus->parent == NULL && dev->devfn == 0) {
150 int i;
152 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
153 dev->resource[i].start = 0;
154 dev->resource[i].end = 0;
155 dev->resource[i].flags = 0;
159 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
161 static struct pci_bus __init *
162 kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
164 struct pci_bus *bus;
166 if (nr == 0) {
167 bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
168 } else {
169 bus = NULL;
170 BUG();
173 return bus;
176 static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
178 return IRQ_KIRKWOOD_PCIE;
181 static struct hw_pci kirkwood_pci __initdata = {
182 .nr_controllers = 1,
183 .swizzle = pci_std_swizzle,
184 .setup = kirkwood_pcie_setup,
185 .scan = kirkwood_pcie_scan_bus,
186 .map_irq = kirkwood_pcie_map_irq,
189 void __init kirkwood_pcie_init(void)
191 pci_common_init(&kirkwood_pci);