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>
15 #include <asm/mach/pci.h>
16 #include <plat/pcie.h>
20 #define PCIE_BASE ((void __iomem *)PCIE_VIRT_BASE)
22 void __init kirkwood_pcie_id(u32 *dev, u32 *rev)
24 *dev = orion_pcie_dev_id(PCIE_BASE);
25 *rev = orion_pcie_rev(PCIE_BASE);
28 static int pcie_valid_config(int bus, int dev)
31 * Don't go out when trying to access --
32 * 1. nonexisting device on local bus
33 * 2. where there's no device connected (no link)
35 if (bus == 0 && dev == 0)
38 if (!orion_pcie_link_up(PCIE_BASE))
41 if (bus == 0 && dev != 1)
49 * PCIe config cycles are done by programming the PCIE_CONF_ADDR register
50 * and then reading the PCIE_CONF_DATA register. Need to make sure these
51 * transactions are atomic.
53 static DEFINE_SPINLOCK(kirkwood_pcie_lock);
55 static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
61 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
63 return PCIBIOS_DEVICE_NOT_FOUND;
66 spin_lock_irqsave(&kirkwood_pcie_lock, flags);
67 ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
68 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
73 static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
74 int where, int size, u32 val)
79 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
80 return PCIBIOS_DEVICE_NOT_FOUND;
82 spin_lock_irqsave(&kirkwood_pcie_lock, flags);
83 ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
84 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
89 static struct pci_ops pcie_ops = {
91 .write = pcie_wr_conf,
95 static int kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
100 * Generic PCIe unit setup.
102 orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info);
107 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
109 panic("pcie_setup unable to alloc resources");
114 res[0].name = "PCIe I/O Space";
115 res[0].flags = IORESOURCE_IO;
116 res[0].start = KIRKWOOD_PCIE_IO_PHYS_BASE;
117 res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
118 if (request_resource(&ioport_resource, &res[0]))
119 panic("Request PCIe IO resource failed\n");
120 sys->resource[0] = &res[0];
125 res[1].name = "PCIe Memory Space";
126 res[1].flags = IORESOURCE_MEM;
127 res[1].start = KIRKWOOD_PCIE_MEM_PHYS_BASE;
128 res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
129 if (request_resource(&iomem_resource, &res[1]))
130 panic("Request PCIe Memory resource failed\n");
131 sys->resource[1] = &res[1];
133 sys->resource[2] = NULL;
139 static void __devinit rc_pci_fixup(struct pci_dev *dev)
142 * Prevent enumeration of root complex.
144 if (dev->bus->parent == NULL && dev->devfn == 0) {
147 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
148 dev->resource[i].start = 0;
149 dev->resource[i].end = 0;
150 dev->resource[i].flags = 0;
154 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL, PCI_ANY_ID, rc_pci_fixup);
156 static struct pci_bus __init *
157 kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
162 bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
171 static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
173 return IRQ_KIRKWOOD_PCIE;
176 static struct hw_pci kirkwood_pci __initdata = {
178 .swizzle = pci_std_swizzle,
179 .setup = kirkwood_pcie_setup,
180 .scan = kirkwood_pcie_scan_bus,
181 .map_irq = kirkwood_pcie_map_irq,
184 void __init kirkwood_pcie_init(void)
186 pci_common_init(&kirkwood_pci);