aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-kirkwood/pcie.c
diff options
context:
space:
mode:
authorSaeed Bishara <saeed@marvell.com>2010-06-08 07:21:34 -0400
committerNicolas Pitre <nico@fluxnic.net>2010-07-16 22:01:59 -0400
commitffd58bd2e45168de21d257d26ee32843b286d3b3 (patch)
tree6015a09c82add039c532a6cc41502c5eae31ccd4 /arch/arm/mach-kirkwood/pcie.c
parent35fe2fc44ac4202261317ccce2ef69991bc01c57 (diff)
[ARM] Kirkwood: add support for PCIe1
This patch extends the kirkwood's PCIe support up to 2 controllers as in the 6282 devices. Signed-off-by: Saeed Bishara <saeed@marvell.com> Signed-off-by: Nicolas Pitre <nico@fluxnic.net>
Diffstat (limited to 'arch/arm/mach-kirkwood/pcie.c')
-rw-r--r--arch/arm/mach-kirkwood/pcie.c188
1 files changed, 142 insertions, 46 deletions
diff --git a/arch/arm/mach-kirkwood/pcie.c b/arch/arm/mach-kirkwood/pcie.c
index dee1eff50d39..49c4fc6b7a59 100644
--- a/arch/arm/mach-kirkwood/pcie.c
+++ b/arch/arm/mach-kirkwood/pcie.c
@@ -18,29 +18,43 @@
18#include <mach/bridge-regs.h> 18#include <mach/bridge-regs.h>
19#include "common.h" 19#include "common.h"
20 20
21void __init kirkwood_pcie_id(u32 *dev, u32 *rev)
22{
23 *dev = orion_pcie_dev_id((void __iomem *)PCIE_VIRT_BASE);
24 *rev = orion_pcie_rev((void __iomem *)PCIE_VIRT_BASE);
25}
21 26
22#define PCIE_BASE ((void __iomem *)PCIE_VIRT_BASE) 27struct pcie_port {
28 u8 root_bus_nr;
29 void __iomem *base;
30 spinlock_t conf_lock;
31 int irq;
32 struct resource res[2];
33};
23 34
24void __init kirkwood_pcie_id(u32 *dev, u32 *rev) 35static int pcie_port_map[2];
36static int num_pcie_ports;
37
38static inline struct pcie_port *bus_to_port(struct pci_bus *bus)
25{ 39{
26 *dev = orion_pcie_dev_id(PCIE_BASE); 40 struct pci_sys_data *sys = bus->sysdata;
27 *rev = orion_pcie_rev(PCIE_BASE); 41 return sys->private_data;
28} 42}
29 43
30static int pcie_valid_config(int bus, int dev) 44static int pcie_valid_config(struct pcie_port *pp, int bus, int dev)
31{ 45{
32 /* 46 /*
33 * Don't go out when trying to access -- 47 * Don't go out when trying to access --
34 * 1. nonexisting device on local bus 48 * 1. nonexisting device on local bus
35 * 2. where there's no device connected (no link) 49 * 2. where there's no device connected (no link)
36 */ 50 */
37 if (bus == 0 && dev == 0) 51 if (bus == pp->root_bus_nr && dev == 0)
38 return 1; 52 return 1;
39 53
40 if (!orion_pcie_link_up(PCIE_BASE)) 54 if (!orion_pcie_link_up(pp->base))
41 return 0; 55 return 0;
42 56
43 if (bus == 0 && dev != 1) 57 if (bus == pp->root_bus_nr && dev != 1)
44 return 0; 58 return 0;
45 59
46 return 1; 60 return 1;
@@ -52,22 +66,22 @@ static int pcie_valid_config(int bus, int dev)
52 * and then reading the PCIE_CONF_DATA register. Need to make sure these 66 * and then reading the PCIE_CONF_DATA register. Need to make sure these
53 * transactions are atomic. 67 * transactions are atomic.
54 */ 68 */
55static DEFINE_SPINLOCK(kirkwood_pcie_lock);
56 69
57static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where, 70static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
58 int size, u32 *val) 71 int size, u32 *val)
59{ 72{
73 struct pcie_port *pp = bus_to_port(bus);
60 unsigned long flags; 74 unsigned long flags;
61 int ret; 75 int ret;
62 76
63 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) { 77 if (pcie_valid_config(pp, bus->number, PCI_SLOT(devfn)) == 0) {
64 *val = 0xffffffff; 78 *val = 0xffffffff;
65 return PCIBIOS_DEVICE_NOT_FOUND; 79 return PCIBIOS_DEVICE_NOT_FOUND;
66 } 80 }
67 81
68 spin_lock_irqsave(&kirkwood_pcie_lock, flags); 82 spin_lock_irqsave(&pp->conf_lock, flags);
69 ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val); 83 ret = orion_pcie_rd_conf(pp->base, bus, devfn, where, size, val);
70 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags); 84 spin_unlock_irqrestore(&pp->conf_lock, flags);
71 85
72 return ret; 86 return ret;
73} 87}
@@ -75,15 +89,16 @@ static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
75static int pcie_wr_conf(struct pci_bus *bus, u32 devfn, 89static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
76 int where, int size, u32 val) 90 int where, int size, u32 val)
77{ 91{
92 struct pcie_port *pp = bus_to_port(bus);
78 unsigned long flags; 93 unsigned long flags;
79 int ret; 94 int ret;
80 95
81 if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) 96 if (pcie_valid_config(pp, bus->number, PCI_SLOT(devfn)) == 0)
82 return PCIBIOS_DEVICE_NOT_FOUND; 97 return PCIBIOS_DEVICE_NOT_FOUND;
83 98
84 spin_lock_irqsave(&kirkwood_pcie_lock, flags); 99 spin_lock_irqsave(&pp->conf_lock, flags);
85 ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val); 100 ret = orion_pcie_wr_conf(pp->base, bus, devfn, where, size, val);
86 spin_unlock_irqrestore(&kirkwood_pcie_lock, flags); 101 spin_unlock_irqrestore(&pp->conf_lock, flags);
87 102
88 return ret; 103 return ret;
89} 104}
@@ -93,50 +108,112 @@ static struct pci_ops pcie_ops = {
93 .write = pcie_wr_conf, 108 .write = pcie_wr_conf,
94}; 109};
95 110
96 111static int __init pcie0_ioresources_setup(struct pci_sys_data *sys)
97static int __init kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
98{ 112{
99 struct resource *res; 113 struct pcie_port *pp = (struct pcie_port *)sys->private_data;
100 extern unsigned int kirkwood_clk_ctrl;
101 114
102 /* 115 /*
103 * Generic PCIe unit setup. 116 * IORESOURCE_IO
104 */ 117 */
105 orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info); 118 pp->res[0].name = "PCIe 0 I/O Space";
119 pp->res[0].start = KIRKWOOD_PCIE_IO_PHYS_BASE;
120 pp->res[0].end = pp->res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
121 pp->res[0].flags = IORESOURCE_IO;
122 if (request_resource(&ioport_resource, &pp->res[0]))
123 panic("Request PCIe 0 IO resource failed\n");
124 sys->resource[0] = &pp->res[0];
106 125
107 /* 126 /*
108 * Request resources. 127 * IORESOURCE_MEM
109 */ 128 */
110 res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL); 129 pp->res[1].name = "PCIe 0 MEM";
111 if (!res) 130 pp->res[1].start = KIRKWOOD_PCIE_MEM_PHYS_BASE;
112 panic("pcie_setup unable to alloc resources"); 131 pp->res[1].end = pp->res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
132 pp->res[1].flags = IORESOURCE_MEM;
133 if (request_resource(&iomem_resource, &pp->res[1]))
134 panic("Request PCIe 0 Memory resource failed\n");
135 sys->resource[1] = &pp->res[1];
136
137 sys->resource[2] = NULL;
138 sys->io_offset = 0;
139
140 return 1;
141}
142
143static int __init pcie1_ioresources_setup(struct pci_sys_data *sys)
144{
145 struct pcie_port *pp = (struct pcie_port *)sys->private_data;
113 146
114 /* 147 /*
115 * IORESOURCE_IO 148 * IORESOURCE_IO
116 */ 149 */
117 res[0].name = "PCIe I/O Space"; 150 pp->res[0].name = "PCIe 1 I/O Space";
118 res[0].flags = IORESOURCE_IO; 151 pp->res[0].start = KIRKWOOD_PCIE1_IO_PHYS_BASE;
119 res[0].start = KIRKWOOD_PCIE_IO_BUS_BASE; 152 pp->res[0].end = pp->res[0].start + KIRKWOOD_PCIE1_IO_SIZE - 1;
120 res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1; 153 pp->res[0].flags = IORESOURCE_IO;
121 if (request_resource(&ioport_resource, &res[0])) 154 if (request_resource(&ioport_resource, &pp->res[0]))
122 panic("Request PCIe IO resource failed\n"); 155 panic("Request PCIe 1 IO resource failed\n");
123 sys->resource[0] = &res[0]; 156 sys->resource[0] = &pp->res[0];
124 157
125 /* 158 /*
126 * IORESOURCE_MEM 159 * IORESOURCE_MEM
127 */ 160 */
128 res[1].name = "PCIe Memory Space"; 161 pp->res[1].name = "PCIe 1 MEM";
129 res[1].flags = IORESOURCE_MEM; 162 pp->res[1].start = KIRKWOOD_PCIE1_MEM_PHYS_BASE;
130 res[1].start = KIRKWOOD_PCIE_MEM_BUS_BASE; 163 pp->res[1].end = pp->res[1].start + KIRKWOOD_PCIE1_MEM_SIZE - 1;
131 res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1; 164 pp->res[1].flags = IORESOURCE_MEM;
132 if (request_resource(&iomem_resource, &res[1])) 165 if (request_resource(&iomem_resource, &pp->res[1]))
133 panic("Request PCIe Memory resource failed\n"); 166 panic("Request PCIe 1 Memory resource failed\n");
134 sys->resource[1] = &res[1]; 167 sys->resource[1] = &pp->res[1];
135 168
136 sys->resource[2] = NULL; 169 sys->resource[2] = NULL;
137 sys->io_offset = 0; 170 sys->io_offset = 0;
138 171
139 kirkwood_clk_ctrl |= CGC_PEX0; 172 return 1;
173}
174
175static int __init kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
176{
177 extern unsigned int kirkwood_clk_ctrl;
178 struct pcie_port *pp;
179 int index;
180
181 if (nr >= num_pcie_ports)
182 return 0;
183
184 index = pcie_port_map[nr];
185 printk(KERN_INFO "PCI: bus%d uses PCIe port %d\n", sys->busnr, index);
186
187 pp = kzalloc(sizeof(*pp), GFP_KERNEL);
188 if (!pp)
189 panic("PCIe: failed to allocate pcie_port data");
190 sys->private_data = pp;
191 pp->root_bus_nr = sys->busnr;
192 spin_lock_init(&pp->conf_lock);
193
194 switch (index) {
195 case 0:
196 pp->base = (void __iomem *)PCIE_VIRT_BASE;
197 pp->irq = IRQ_KIRKWOOD_PCIE;
198 kirkwood_clk_ctrl |= CGC_PEX0;
199 pcie0_ioresources_setup(sys);
200 break;
201 case 1:
202 pp->base = (void __iomem *)PCIE1_VIRT_BASE;
203 pp->irq = IRQ_KIRKWOOD_PCIE1;
204 kirkwood_clk_ctrl |= CGC_PEX1;
205 pcie1_ioresources_setup(sys);
206 break;
207 default:
208 panic("PCIe setup: invalid controller");
209 }
210
211 /*
212 * Generic PCIe unit setup.
213 */
214 orion_pcie_set_local_bus_nr(pp->base, sys->busnr);
215
216 orion_pcie_setup(pp->base, &kirkwood_mbus_dram_info);
140 217
141 return 1; 218 return 1;
142} 219}
@@ -163,7 +240,7 @@ kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
163{ 240{
164 struct pci_bus *bus; 241 struct pci_bus *bus;
165 242
166 if (nr == 0) { 243 if (nr < num_pcie_ports) {
167 bus = pci_scan_bus(sys->busnr, &pcie_ops, sys); 244 bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
168 } else { 245 } else {
169 bus = NULL; 246 bus = NULL;
@@ -175,18 +252,37 @@ kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
175 252
176static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin) 253static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
177{ 254{
178 return IRQ_KIRKWOOD_PCIE; 255 struct pcie_port *pp = bus_to_port(dev->bus);
256
257 return pp->irq;
179} 258}
180 259
181static struct hw_pci kirkwood_pci __initdata = { 260static struct hw_pci kirkwood_pci __initdata = {
182 .nr_controllers = 1,
183 .swizzle = pci_std_swizzle, 261 .swizzle = pci_std_swizzle,
184 .setup = kirkwood_pcie_setup, 262 .setup = kirkwood_pcie_setup,
185 .scan = kirkwood_pcie_scan_bus, 263 .scan = kirkwood_pcie_scan_bus,
186 .map_irq = kirkwood_pcie_map_irq, 264 .map_irq = kirkwood_pcie_map_irq,
187}; 265};
188 266
189void __init kirkwood_pcie_init(void) 267static void __init add_pcie_port(int index, unsigned long base)
268{
269 printk(KERN_INFO "Kirkwood PCIe port %d: ", index);
270
271 if (orion_pcie_link_up((void __iomem *)base)) {
272 printk(KERN_INFO "link up\n");
273 pcie_port_map[num_pcie_ports++] = index;
274 } else
275 printk(KERN_INFO "link down, ignoring\n");
276}
277
278void __init kirkwood_pcie_init(unsigned int portmask)
190{ 279{
280 if (portmask & KW_PCIE0)
281 add_pcie_port(0, PCIE_VIRT_BASE);
282
283 if (portmask & KW_PCIE1)
284 add_pcie_port(1, PCIE1_VIRT_BASE);
285
286 kirkwood_pci.nr_controllers = num_pcie_ports;
191 pci_common_init(&kirkwood_pci); 287 pci_common_init(&kirkwood_pci);
192} 288}