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.
11 #include <linux/kernel.h>
12 #include <linux/pci.h>
13 #include <linux/mbus.h>
14 #include <asm/mach/pci.h>
15 #include <plat/pcie.h>
19 #define PCIE_BASE ((void __iomem *)PCIE_VIRT_BASE)
21 void __init kirkwood_pcie_id(u32 *dev, u32 *rev)
23 *dev = orion_pcie_dev_id(PCIE_BASE);
24 *rev = orion_pcie_rev(PCIE_BASE);
27 static int pcie_valid_config(int bus, int dev)
30 * Don't go out when trying to access --
31 * 1. nonexisting device on local bus
32 * 2. where there's no device connected (no link)
34 if (bus == 0 && dev == 0)
37 if (!orion_pcie_link_up(PCIE_BASE))
40 if (bus == 0 && dev != 1)
48 * PCIe config cycles are done by programming the PCIE_CONF_ADDR register
49 * and then reading the PCIE_CONF_DATA register. Need to make sure these
50 * transactions are atomic.
52 static DEFINE_SPINLOCK(kirkwood_pcie_lock);
54 static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
60 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
62 return PCIBIOS_DEVICE_NOT_FOUND;
65 spin_lock_irqsave(&kirkwood_pcie_lock, flags);
66 ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
67 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
72 static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
73 int where, int size, u32 val)
78 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
79 return PCIBIOS_DEVICE_NOT_FOUND;
81 spin_lock_irqsave(&kirkwood_pcie_lock, flags);
82 ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
83 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
88 static struct pci_ops pcie_ops = {
90 .write = pcie_wr_conf,
94 static int kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
99 * Generic PCIe unit setup.
101 orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info);
106 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
108 panic("pcie_setup unable to alloc resources");
113 res[0].name = "PCIe I/O Space";
114 res[0].flags = IORESOURCE_IO;
115 res[0].start = KIRKWOOD_PCIE_IO_PHYS_BASE;
116 res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
117 if (request_resource(&ioport_resource, &res[0]))
118 panic("Request PCIe IO resource failed\n");
119 sys->resource[0] = &res[0];
124 res[1].name = "PCIe Memory Space";
125 res[1].flags = IORESOURCE_MEM;
126 res[1].start = KIRKWOOD_PCIE_MEM_PHYS_BASE;
127 res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
128 if (request_resource(&iomem_resource, &res[1]))
129 panic("Request PCIe Memory resource failed\n");
130 sys->resource[1] = &res[1];
132 sys->resource[2] = NULL;
138 static void __devinit rc_pci_fixup(struct pci_dev *dev)
141 * Prevent enumeration of root complex.
143 if (dev->bus->parent == NULL && dev->devfn == 0) {
146 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
147 dev->resource[i].start = 0;
148 dev->resource[i].end = 0;
149 dev->resource[i].flags = 0;
153 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
155 static struct pci_bus __init *
156 kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
161 bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
170 static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
172 return IRQ_KIRKWOOD_PCIE;
175 static struct hw_pci kirkwood_pci __initdata = {
177 .swizzle = pci_std_swizzle,
178 .setup = kirkwood_pcie_setup,
179 .scan = kirkwood_pcie_scan_bus,
180 .map_irq = kirkwood_pcie_map_irq,
183 void __init kirkwood_pcie_init(void)
185 pci_common_init(&kirkwood_pci);