aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/pci/pci-ar71xx.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/pci/pci-ar71xx.c')
-rw-r--r--arch/mips/pci/pci-ar71xx.c194
1 files changed, 125 insertions, 69 deletions
diff --git a/arch/mips/pci/pci-ar71xx.c b/arch/mips/pci/pci-ar71xx.c
index 6eaa4f2d0e38..412ec025cf55 100644
--- a/arch/mips/pci/pci-ar71xx.c
+++ b/arch/mips/pci/pci-ar71xx.c
@@ -18,26 +18,11 @@
18#include <linux/pci.h> 18#include <linux/pci.h>
19#include <linux/pci_regs.h> 19#include <linux/pci_regs.h>
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/module.h>
22#include <linux/platform_device.h>
21 23
22#include <asm/mach-ath79/ar71xx_regs.h> 24#include <asm/mach-ath79/ar71xx_regs.h>
23#include <asm/mach-ath79/ath79.h> 25#include <asm/mach-ath79/ath79.h>
24#include <asm/mach-ath79/pci.h>
25
26#define AR71XX_PCI_MEM_BASE 0x10000000
27#define AR71XX_PCI_MEM_SIZE 0x07000000
28
29#define AR71XX_PCI_WIN0_OFFS 0x10000000
30#define AR71XX_PCI_WIN1_OFFS 0x11000000
31#define AR71XX_PCI_WIN2_OFFS 0x12000000
32#define AR71XX_PCI_WIN3_OFFS 0x13000000
33#define AR71XX_PCI_WIN4_OFFS 0x14000000
34#define AR71XX_PCI_WIN5_OFFS 0x15000000
35#define AR71XX_PCI_WIN6_OFFS 0x16000000
36#define AR71XX_PCI_WIN7_OFFS 0x07000000
37
38#define AR71XX_PCI_CFG_BASE \
39 (AR71XX_PCI_MEM_BASE + AR71XX_PCI_WIN7_OFFS + 0x10000)
40#define AR71XX_PCI_CFG_SIZE 0x100
41 26
42#define AR71XX_PCI_REG_CRP_AD_CBE 0x00 27#define AR71XX_PCI_REG_CRP_AD_CBE 0x00
43#define AR71XX_PCI_REG_CRP_WRDATA 0x04 28#define AR71XX_PCI_REG_CRP_WRDATA 0x04
@@ -63,8 +48,15 @@
63 48
64#define AR71XX_PCI_IRQ_COUNT 5 49#define AR71XX_PCI_IRQ_COUNT 5
65 50
66static DEFINE_SPINLOCK(ar71xx_pci_lock); 51struct ar71xx_pci_controller {
67static void __iomem *ar71xx_pcicfg_base; 52 void __iomem *cfg_base;
53 spinlock_t lock;
54 int irq;
55 int irq_base;
56 struct pci_controller pci_ctrl;
57 struct resource io_res;
58 struct resource mem_res;
59};
68 60
69/* Byte lane enable bits */ 61/* Byte lane enable bits */
70static const u8 ar71xx_pci_ble_table[4][4] = { 62static const u8 ar71xx_pci_ble_table[4][4] = {
@@ -107,9 +99,18 @@ static inline u32 ar71xx_pci_bus_addr(struct pci_bus *bus, unsigned int devfn,
107 return ret; 99 return ret;
108} 100}
109 101
110static int ar71xx_pci_check_error(int quiet) 102static inline struct ar71xx_pci_controller *
103pci_bus_to_ar71xx_controller(struct pci_bus *bus)
111{ 104{
112 void __iomem *base = ar71xx_pcicfg_base; 105 struct pci_controller *hose;
106
107 hose = (struct pci_controller *) bus->sysdata;
108 return container_of(hose, struct ar71xx_pci_controller, pci_ctrl);
109}
110
111static int ar71xx_pci_check_error(struct ar71xx_pci_controller *apc, int quiet)
112{
113 void __iomem *base = apc->cfg_base;
113 u32 pci_err; 114 u32 pci_err;
114 u32 ahb_err; 115 u32 ahb_err;
115 116
@@ -144,9 +145,10 @@ static int ar71xx_pci_check_error(int quiet)
144 return !!(ahb_err | pci_err); 145 return !!(ahb_err | pci_err);
145} 146}
146 147
147static inline void ar71xx_pci_local_write(int where, int size, u32 value) 148static inline void ar71xx_pci_local_write(struct ar71xx_pci_controller *apc,
149 int where, int size, u32 value)
148{ 150{
149 void __iomem *base = ar71xx_pcicfg_base; 151 void __iomem *base = apc->cfg_base;
150 u32 ad_cbe; 152 u32 ad_cbe;
151 153
152 value = value << (8 * (where & 3)); 154 value = value << (8 * (where & 3));
@@ -162,7 +164,8 @@ static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
162 unsigned int devfn, 164 unsigned int devfn,
163 int where, int size, u32 cmd) 165 int where, int size, u32 cmd)
164{ 166{
165 void __iomem *base = ar71xx_pcicfg_base; 167 struct ar71xx_pci_controller *apc = pci_bus_to_ar71xx_controller(bus);
168 void __iomem *base = apc->cfg_base;
166 u32 addr; 169 u32 addr;
167 170
168 addr = ar71xx_pci_bus_addr(bus, devfn, where); 171 addr = ar71xx_pci_bus_addr(bus, devfn, where);
@@ -171,13 +174,14 @@ static inline int ar71xx_pci_set_cfgaddr(struct pci_bus *bus,
171 __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0), 174 __raw_writel(cmd | ar71xx_pci_get_ble(where, size, 0),
172 base + AR71XX_PCI_REG_CFG_CBE); 175 base + AR71XX_PCI_REG_CFG_CBE);
173 176
174 return ar71xx_pci_check_error(1); 177 return ar71xx_pci_check_error(apc, 1);
175} 178}
176 179
177static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn, 180static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
178 int where, int size, u32 *value) 181 int where, int size, u32 *value)
179{ 182{
180 void __iomem *base = ar71xx_pcicfg_base; 183 struct ar71xx_pci_controller *apc = pci_bus_to_ar71xx_controller(bus);
184 void __iomem *base = apc->cfg_base;
181 unsigned long flags; 185 unsigned long flags;
182 u32 data; 186 u32 data;
183 int err; 187 int err;
@@ -186,7 +190,7 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
186 ret = PCIBIOS_SUCCESSFUL; 190 ret = PCIBIOS_SUCCESSFUL;
187 data = ~0; 191 data = ~0;
188 192
189 spin_lock_irqsave(&ar71xx_pci_lock, flags); 193 spin_lock_irqsave(&apc->lock, flags);
190 194
191 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size, 195 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
192 AR71XX_PCI_CFG_CMD_READ); 196 AR71XX_PCI_CFG_CMD_READ);
@@ -195,7 +199,7 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
195 else 199 else
196 data = __raw_readl(base + AR71XX_PCI_REG_CFG_RDDATA); 200 data = __raw_readl(base + AR71XX_PCI_REG_CFG_RDDATA);
197 201
198 spin_unlock_irqrestore(&ar71xx_pci_lock, flags); 202 spin_unlock_irqrestore(&apc->lock, flags);
199 203
200 *value = (data >> (8 * (where & 3))) & ar71xx_pci_read_mask[size & 7]; 204 *value = (data >> (8 * (where & 3))) & ar71xx_pci_read_mask[size & 7];
201 205
@@ -205,7 +209,8 @@ static int ar71xx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
205static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn, 209static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
206 int where, int size, u32 value) 210 int where, int size, u32 value)
207{ 211{
208 void __iomem *base = ar71xx_pcicfg_base; 212 struct ar71xx_pci_controller *apc = pci_bus_to_ar71xx_controller(bus);
213 void __iomem *base = apc->cfg_base;
209 unsigned long flags; 214 unsigned long flags;
210 int err; 215 int err;
211 int ret; 216 int ret;
@@ -213,7 +218,7 @@ static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
213 value = value << (8 * (where & 3)); 218 value = value << (8 * (where & 3));
214 ret = PCIBIOS_SUCCESSFUL; 219 ret = PCIBIOS_SUCCESSFUL;
215 220
216 spin_lock_irqsave(&ar71xx_pci_lock, flags); 221 spin_lock_irqsave(&apc->lock, flags);
217 222
218 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size, 223 err = ar71xx_pci_set_cfgaddr(bus, devfn, where, size,
219 AR71XX_PCI_CFG_CMD_WRITE); 224 AR71XX_PCI_CFG_CMD_WRITE);
@@ -222,7 +227,7 @@ static int ar71xx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
222 else 227 else
223 __raw_writel(value, base + AR71XX_PCI_REG_CFG_WRDATA); 228 __raw_writel(value, base + AR71XX_PCI_REG_CFG_WRDATA);
224 229
225 spin_unlock_irqrestore(&ar71xx_pci_lock, flags); 230 spin_unlock_irqrestore(&apc->lock, flags);
226 231
227 return ret; 232 return ret;
228} 233}
@@ -232,45 +237,28 @@ static struct pci_ops ar71xx_pci_ops = {
232 .write = ar71xx_pci_write_config, 237 .write = ar71xx_pci_write_config,
233}; 238};
234 239
235static struct resource ar71xx_pci_io_resource = {
236 .name = "PCI IO space",
237 .start = 0,
238 .end = 0,
239 .flags = IORESOURCE_IO,
240};
241
242static struct resource ar71xx_pci_mem_resource = {
243 .name = "PCI memory space",
244 .start = AR71XX_PCI_MEM_BASE,
245 .end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1,
246 .flags = IORESOURCE_MEM
247};
248
249static struct pci_controller ar71xx_pci_controller = {
250 .pci_ops = &ar71xx_pci_ops,
251 .mem_resource = &ar71xx_pci_mem_resource,
252 .io_resource = &ar71xx_pci_io_resource,
253};
254
255static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc) 240static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
256{ 241{
242 struct ar71xx_pci_controller *apc;
257 void __iomem *base = ath79_reset_base; 243 void __iomem *base = ath79_reset_base;
258 u32 pending; 244 u32 pending;
259 245
246 apc = irq_get_handler_data(irq);
247
260 pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) & 248 pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) &
261 __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE); 249 __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
262 250
263 if (pending & AR71XX_PCI_INT_DEV0) 251 if (pending & AR71XX_PCI_INT_DEV0)
264 generic_handle_irq(ATH79_PCI_IRQ(0)); 252 generic_handle_irq(apc->irq_base + 0);
265 253
266 else if (pending & AR71XX_PCI_INT_DEV1) 254 else if (pending & AR71XX_PCI_INT_DEV1)
267 generic_handle_irq(ATH79_PCI_IRQ(1)); 255 generic_handle_irq(apc->irq_base + 1);
268 256
269 else if (pending & AR71XX_PCI_INT_DEV2) 257 else if (pending & AR71XX_PCI_INT_DEV2)
270 generic_handle_irq(ATH79_PCI_IRQ(2)); 258 generic_handle_irq(apc->irq_base + 2);
271 259
272 else if (pending & AR71XX_PCI_INT_CORE) 260 else if (pending & AR71XX_PCI_INT_CORE)
273 generic_handle_irq(ATH79_PCI_IRQ(4)); 261 generic_handle_irq(apc->irq_base + 4);
274 262
275 else 263 else
276 spurious_interrupt(); 264 spurious_interrupt();
@@ -278,10 +266,14 @@ static void ar71xx_pci_irq_handler(unsigned int irq, struct irq_desc *desc)
278 266
279static void ar71xx_pci_irq_unmask(struct irq_data *d) 267static void ar71xx_pci_irq_unmask(struct irq_data *d)
280{ 268{
281 unsigned int irq = d->irq - ATH79_PCI_IRQ_BASE; 269 struct ar71xx_pci_controller *apc;
270 unsigned int irq;
282 void __iomem *base = ath79_reset_base; 271 void __iomem *base = ath79_reset_base;
283 u32 t; 272 u32 t;
284 273
274 apc = irq_data_get_irq_chip_data(d);
275 irq = d->irq - apc->irq_base;
276
285 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE); 277 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
286 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE); 278 __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
287 279
@@ -291,10 +283,14 @@ static void ar71xx_pci_irq_unmask(struct irq_data *d)
291 283
292static void ar71xx_pci_irq_mask(struct irq_data *d) 284static void ar71xx_pci_irq_mask(struct irq_data *d)
293{ 285{
294 unsigned int irq = d->irq - ATH79_PCI_IRQ_BASE; 286 struct ar71xx_pci_controller *apc;
287 unsigned int irq;
295 void __iomem *base = ath79_reset_base; 288 void __iomem *base = ath79_reset_base;
296 u32 t; 289 u32 t;
297 290
291 apc = irq_data_get_irq_chip_data(d);
292 irq = d->irq - apc->irq_base;
293
298 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE); 294 t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
299 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE); 295 __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
300 296
@@ -309,7 +305,7 @@ static struct irq_chip ar71xx_pci_irq_chip = {
309 .irq_mask_ack = ar71xx_pci_irq_mask, 305 .irq_mask_ack = ar71xx_pci_irq_mask,
310}; 306};
311 307
312static __init void ar71xx_pci_irq_init(void) 308static void ar71xx_pci_irq_init(struct ar71xx_pci_controller *apc)
313{ 309{
314 void __iomem *base = ath79_reset_base; 310 void __iomem *base = ath79_reset_base;
315 int i; 311 int i;
@@ -319,15 +315,19 @@ static __init void ar71xx_pci_irq_init(void)
319 315
320 BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR71XX_PCI_IRQ_COUNT); 316 BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR71XX_PCI_IRQ_COUNT);
321 317
322 for (i = ATH79_PCI_IRQ_BASE; 318 apc->irq_base = ATH79_PCI_IRQ_BASE;
323 i < ATH79_PCI_IRQ_BASE + AR71XX_PCI_IRQ_COUNT; i++) 319 for (i = apc->irq_base;
320 i < apc->irq_base + AR71XX_PCI_IRQ_COUNT; i++) {
324 irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip, 321 irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip,
325 handle_level_irq); 322 handle_level_irq);
323 irq_set_chip_data(i, apc);
324 }
326 325
327 irq_set_chained_handler(ATH79_CPU_IRQ_IP2, ar71xx_pci_irq_handler); 326 irq_set_handler_data(apc->irq, apc);
327 irq_set_chained_handler(apc->irq, ar71xx_pci_irq_handler);
328} 328}
329 329
330static __init void ar71xx_pci_reset(void) 330static void ar71xx_pci_reset(void)
331{ 331{
332 void __iomem *ddr_base = ath79_ddr_base; 332 void __iomem *ddr_base = ath79_ddr_base;
333 333
@@ -349,27 +349,83 @@ static __init void ar71xx_pci_reset(void)
349 mdelay(100); 349 mdelay(100);
350} 350}
351 351
352__init int ar71xx_pcibios_init(void) 352static int ar71xx_pci_probe(struct platform_device *pdev)
353{ 353{
354 struct ar71xx_pci_controller *apc;
355 struct resource *res;
354 u32 t; 356 u32 t;
355 357
356 ar71xx_pcicfg_base = ioremap(AR71XX_PCI_CFG_BASE, AR71XX_PCI_CFG_SIZE); 358 apc = devm_kzalloc(&pdev->dev, sizeof(struct ar71xx_pci_controller),
357 if (ar71xx_pcicfg_base == NULL) 359 GFP_KERNEL);
360 if (!apc)
361 return -ENOMEM;
362
363 spin_lock_init(&apc->lock);
364
365 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cfg_base");
366 if (!res)
367 return -EINVAL;
368
369 apc->cfg_base = devm_request_and_ioremap(&pdev->dev, res);
370 if (!apc->cfg_base)
358 return -ENOMEM; 371 return -ENOMEM;
359 372
373 apc->irq = platform_get_irq(pdev, 0);
374 if (apc->irq < 0)
375 return -EINVAL;
376
377 res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
378 if (!res)
379 return -EINVAL;
380
381 apc->io_res.parent = res;
382 apc->io_res.name = "PCI IO space";
383 apc->io_res.start = res->start;
384 apc->io_res.end = res->end;
385 apc->io_res.flags = IORESOURCE_IO;
386
387 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
388 if (!res)
389 return -EINVAL;
390
391 apc->mem_res.parent = res;
392 apc->mem_res.name = "PCI memory space";
393 apc->mem_res.start = res->start;
394 apc->mem_res.end = res->end;
395 apc->mem_res.flags = IORESOURCE_MEM;
396
360 ar71xx_pci_reset(); 397 ar71xx_pci_reset();
361 398
362 /* setup COMMAND register */ 399 /* setup COMMAND register */
363 t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE 400 t = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER | PCI_COMMAND_INVALIDATE
364 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK; 401 | PCI_COMMAND_PARITY | PCI_COMMAND_SERR | PCI_COMMAND_FAST_BACK;
365 ar71xx_pci_local_write(PCI_COMMAND, 4, t); 402 ar71xx_pci_local_write(apc, PCI_COMMAND, 4, t);
366 403
367 /* clear bus errors */ 404 /* clear bus errors */
368 ar71xx_pci_check_error(1); 405 ar71xx_pci_check_error(apc, 1);
406
407 ar71xx_pci_irq_init(apc);
369 408
370 ar71xx_pci_irq_init(); 409 apc->pci_ctrl.pci_ops = &ar71xx_pci_ops;
410 apc->pci_ctrl.mem_resource = &apc->mem_res;
411 apc->pci_ctrl.io_resource = &apc->io_res;
371 412
372 register_pci_controller(&ar71xx_pci_controller); 413 register_pci_controller(&apc->pci_ctrl);
373 414
374 return 0; 415 return 0;
375} 416}
417
418static struct platform_driver ar71xx_pci_driver = {
419 .probe = ar71xx_pci_probe,
420 .driver = {
421 .name = "ar71xx-pci",
422 .owner = THIS_MODULE,
423 },
424};
425
426static int __init ar71xx_pci_init(void)
427{
428 return platform_driver_register(&ar71xx_pci_driver);
429}
430
431postcore_initcall(ar71xx_pci_init);