1
2
3
4
5
6
7
8#include <linux/of_device.h>
9#include <linux/kernel.h>
10#include <linux/pci.h>
11#include <linux/slab.h>
12#include <linux/delay.h>
13#include <linux/export.h>
14#include <asm/io.h>
15#include <asm/leon.h>
16#include <asm/vaddrs.h>
17#include <asm/sections.h>
18#include <asm/leon_pci.h>
19
20#include "irq.h"
21
22struct grpci2_barcfg {
23 unsigned long pciadr;
24 unsigned long ahbadr;
25};
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63#undef GRPCI2_DEBUG_CFGACCESS
64
65
66
67
68struct grpci2_regs {
69 unsigned int ctrl;
70 unsigned int sts_cap;
71 int res1;
72 unsigned int io_map;
73 unsigned int dma_ctrl;
74 unsigned int dma_bdbase;
75 int res2[2];
76 unsigned int bars[6];
77 int res3[2];
78 unsigned int ahbmst_map[16];
79
80
81 unsigned int t_ctrl;
82 unsigned int t_cnt;
83 unsigned int t_adpat;
84 unsigned int t_admask;
85 unsigned int t_sigpat;
86 unsigned int t_sigmask;
87 unsigned int t_adstate;
88 unsigned int t_sigstate;
89};
90
91#define REGLOAD(a) (be32_to_cpu(__raw_readl(&(a))))
92#define REGSTORE(a, v) (__raw_writel(cpu_to_be32(v), &(a)))
93
94#define CTRL_BUS_BIT 16
95
96#define CTRL_RESET (1<<31)
97#define CTRL_SI (1<<27)
98#define CTRL_PE (1<<26)
99#define CTRL_EI (1<<25)
100#define CTRL_ER (1<<24)
101#define CTRL_BUS (0xff<<CTRL_BUS_BIT)
102#define CTRL_HOSTINT 0xf
103
104#define STS_HOST_BIT 31
105#define STS_MST_BIT 30
106#define STS_TAR_BIT 29
107#define STS_DMA_BIT 28
108#define STS_DI_BIT 27
109#define STS_HI_BIT 26
110#define STS_IRQMODE_BIT 24
111#define STS_TRACE_BIT 23
112#define STS_CFGERRVALID_BIT 20
113#define STS_CFGERR_BIT 19
114#define STS_INTTYPE_BIT 12
115#define STS_INTSTS_BIT 8
116#define STS_FDEPTH_BIT 2
117#define STS_FNUM_BIT 0
118
119#define STS_HOST (1<<STS_HOST_BIT)
120#define STS_MST (1<<STS_MST_BIT)
121#define STS_TAR (1<<STS_TAR_BIT)
122#define STS_DMA (1<<STS_DMA_BIT)
123#define STS_DI (1<<STS_DI_BIT)
124#define STS_HI (1<<STS_HI_BIT)
125#define STS_IRQMODE (0x3<<STS_IRQMODE_BIT)
126#define STS_TRACE (1<<STS_TRACE_BIT)
127#define STS_CFGERRVALID (1<<STS_CFGERRVALID_BIT)
128#define STS_CFGERR (1<<STS_CFGERR_BIT)
129#define STS_INTTYPE (0x3f<<STS_INTTYPE_BIT)
130#define STS_INTSTS (0xf<<STS_INTSTS_BIT)
131#define STS_FDEPTH (0x7<<STS_FDEPTH_BIT)
132#define STS_FNUM (0x3<<STS_FNUM_BIT)
133
134#define STS_ISYSERR (1<<17)
135#define STS_IDMA (1<<16)
136#define STS_IDMAERR (1<<15)
137#define STS_IMSTABRT (1<<14)
138#define STS_ITGTABRT (1<<13)
139#define STS_IPARERR (1<<12)
140
141#define STS_ERR_IRQ (STS_ISYSERR | STS_IMSTABRT | STS_ITGTABRT | STS_IPARERR)
142
143struct grpci2_bd_chan {
144 unsigned int ctrl;
145 unsigned int nchan;
146 unsigned int nbd;
147 unsigned int res;
148};
149
150#define BD_CHAN_EN 0x80000000
151#define BD_CHAN_TYPE 0x00300000
152#define BD_CHAN_BDCNT 0x0000ffff
153#define BD_CHAN_EN_BIT 31
154#define BD_CHAN_TYPE_BIT 20
155#define BD_CHAN_BDCNT_BIT 0
156
157struct grpci2_bd_data {
158 unsigned int ctrl;
159 unsigned int pci_adr;
160 unsigned int ahb_adr;
161 unsigned int next;
162};
163
164#define BD_DATA_EN 0x80000000
165#define BD_DATA_IE 0x40000000
166#define BD_DATA_DR 0x20000000
167#define BD_DATA_TYPE 0x00300000
168#define BD_DATA_ER 0x00080000
169#define BD_DATA_LEN 0x0000ffff
170#define BD_DATA_EN_BIT 31
171#define BD_DATA_IE_BIT 30
172#define BD_DATA_DR_BIT 29
173#define BD_DATA_TYPE_BIT 20
174#define BD_DATA_ER_BIT 19
175#define BD_DATA_LEN_BIT 0
176
177
178struct grpci2_cap_first {
179 unsigned int ctrl;
180 unsigned int pci2ahb_map[6];
181 unsigned int ext2ahb_map;
182 unsigned int io_map;
183 unsigned int pcibar_size[6];
184};
185#define CAP9_CTRL_OFS 0
186#define CAP9_BAR_OFS 0x4
187#define CAP9_IOMAP_OFS 0x20
188#define CAP9_BARSIZE_OFS 0x24
189
190#define TGT 256
191
192struct grpci2_priv {
193 struct leon_pci_info info;
194 struct grpci2_regs __iomem *regs;
195 char irq;
196 char irq_mode;
197 char bt_enabled;
198 char do_reset;
199 char irq_mask;
200 u32 pciid;
201 unsigned char irq_map[4];
202
203
204 unsigned int virq_err;
205 unsigned int virq_dma;
206
207
208 unsigned long pci_area;
209 unsigned long pci_area_end;
210 unsigned long pci_io;
211 unsigned long pci_conf;
212 unsigned long pci_conf_end;
213 unsigned long pci_io_va;
214
215 struct grpci2_barcfg tgtbars[6];
216};
217
218static DEFINE_SPINLOCK(grpci2_dev_lock);
219static struct grpci2_priv *grpci2priv;
220
221static int grpci2_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
222{
223 struct grpci2_priv *priv = dev->bus->sysdata;
224 int irq_group;
225
226
227 irq_group = slot & 0x3;
228 pin = ((pin - 1) + irq_group) & 0x3;
229
230 return priv->irq_map[pin];
231}
232
233static int grpci2_cfg_r32(struct grpci2_priv *priv, unsigned int bus,
234 unsigned int devfn, int where, u32 *val)
235{
236 unsigned int *pci_conf;
237 unsigned long flags;
238 u32 tmp;
239
240 if (where & 0x3)
241 return -EINVAL;
242
243 if (bus == 0) {
244 devfn += (0x8 * 6);
245 } else if (bus == TGT) {
246 bus = 0;
247 devfn = 0;
248 }
249
250
251 spin_lock_irqsave(&grpci2_dev_lock, flags);
252 REGSTORE(priv->regs->ctrl, (REGLOAD(priv->regs->ctrl) & ~(0xff << 16)) |
253 (bus << 16));
254 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
255
256
257 REGSTORE(priv->regs->sts_cap, (STS_CFGERR | STS_CFGERRVALID));
258
259 pci_conf = (unsigned int *) (priv->pci_conf |
260 (devfn << 8) | (where & 0xfc));
261 tmp = LEON3_BYPASS_LOAD_PA(pci_conf);
262
263
264
265
266 while ((REGLOAD(priv->regs->sts_cap) & STS_CFGERRVALID) == 0)
267 ;
268
269 if (REGLOAD(priv->regs->sts_cap) & STS_CFGERR) {
270 *val = 0xffffffff;
271 } else {
272
273 *val = swab32(tmp);
274 }
275
276 return 0;
277}
278
279static int grpci2_cfg_r16(struct grpci2_priv *priv, unsigned int bus,
280 unsigned int devfn, int where, u32 *val)
281{
282 u32 v;
283 int ret;
284
285 if (where & 0x1)
286 return -EINVAL;
287 ret = grpci2_cfg_r32(priv, bus, devfn, where & ~0x3, &v);
288 *val = 0xffff & (v >> (8 * (where & 0x3)));
289 return ret;
290}
291
292static int grpci2_cfg_r8(struct grpci2_priv *priv, unsigned int bus,
293 unsigned int devfn, int where, u32 *val)
294{
295 u32 v;
296 int ret;
297
298 ret = grpci2_cfg_r32(priv, bus, devfn, where & ~0x3, &v);
299 *val = 0xff & (v >> (8 * (where & 3)));
300
301 return ret;
302}
303
304static int grpci2_cfg_w32(struct grpci2_priv *priv, unsigned int bus,
305 unsigned int devfn, int where, u32 val)
306{
307 unsigned int *pci_conf;
308 unsigned long flags;
309
310 if (where & 0x3)
311 return -EINVAL;
312
313 if (bus == 0) {
314 devfn += (0x8 * 6);
315 } else if (bus == TGT) {
316 bus = 0;
317 devfn = 0;
318 }
319
320
321 spin_lock_irqsave(&grpci2_dev_lock, flags);
322 REGSTORE(priv->regs->ctrl, (REGLOAD(priv->regs->ctrl) & ~(0xff << 16)) |
323 (bus << 16));
324 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
325
326
327 REGSTORE(priv->regs->sts_cap, (STS_CFGERR | STS_CFGERRVALID));
328
329 pci_conf = (unsigned int *) (priv->pci_conf |
330 (devfn << 8) | (where & 0xfc));
331 LEON3_BYPASS_STORE_PA(pci_conf, swab32(val));
332
333
334
335
336 while ((REGLOAD(priv->regs->sts_cap) & STS_CFGERRVALID) == 0)
337 ;
338
339 return 0;
340}
341
342static int grpci2_cfg_w16(struct grpci2_priv *priv, unsigned int bus,
343 unsigned int devfn, int where, u32 val)
344{
345 int ret;
346 u32 v;
347
348 if (where & 0x1)
349 return -EINVAL;
350 ret = grpci2_cfg_r32(priv, bus, devfn, where&~3, &v);
351 if (ret)
352 return ret;
353 v = (v & ~(0xffff << (8 * (where & 0x3)))) |
354 ((0xffff & val) << (8 * (where & 0x3)));
355 return grpci2_cfg_w32(priv, bus, devfn, where & ~0x3, v);
356}
357
358static int grpci2_cfg_w8(struct grpci2_priv *priv, unsigned int bus,
359 unsigned int devfn, int where, u32 val)
360{
361 int ret;
362 u32 v;
363
364 ret = grpci2_cfg_r32(priv, bus, devfn, where & ~0x3, &v);
365 if (ret != 0)
366 return ret;
367 v = (v & ~(0xff << (8 * (where & 0x3)))) |
368 ((0xff & val) << (8 * (where & 0x3)));
369 return grpci2_cfg_w32(priv, bus, devfn, where & ~0x3, v);
370}
371
372
373
374
375static int grpci2_read_config(struct pci_bus *bus, unsigned int devfn,
376 int where, int size, u32 *val)
377{
378 struct grpci2_priv *priv = grpci2priv;
379 unsigned int busno = bus->number;
380 int ret;
381
382 if (PCI_SLOT(devfn) > 15 || busno > 255) {
383 *val = ~0;
384 return 0;
385 }
386
387 switch (size) {
388 case 1:
389 ret = grpci2_cfg_r8(priv, busno, devfn, where, val);
390 break;
391 case 2:
392 ret = grpci2_cfg_r16(priv, busno, devfn, where, val);
393 break;
394 case 4:
395 ret = grpci2_cfg_r32(priv, busno, devfn, where, val);
396 break;
397 default:
398 ret = -EINVAL;
399 break;
400 }
401
402#ifdef GRPCI2_DEBUG_CFGACCESS
403 printk(KERN_INFO "grpci2_read_config: [%02x:%02x:%x] ofs=%d val=%x "
404 "size=%d\n", busno, PCI_SLOT(devfn), PCI_FUNC(devfn), where,
405 *val, size);
406#endif
407
408 return ret;
409}
410
411
412
413
414static int grpci2_write_config(struct pci_bus *bus, unsigned int devfn,
415 int where, int size, u32 val)
416{
417 struct grpci2_priv *priv = grpci2priv;
418 unsigned int busno = bus->number;
419
420 if (PCI_SLOT(devfn) > 15 || busno > 255)
421 return 0;
422
423#ifdef GRPCI2_DEBUG_CFGACCESS
424 printk(KERN_INFO "grpci2_write_config: [%02x:%02x:%x] ofs=%d size=%d "
425 "val=%x\n", busno, PCI_SLOT(devfn), PCI_FUNC(devfn),
426 where, size, val);
427#endif
428
429 switch (size) {
430 default:
431 return -EINVAL;
432 case 1:
433 return grpci2_cfg_w8(priv, busno, devfn, where, val);
434 case 2:
435 return grpci2_cfg_w16(priv, busno, devfn, where, val);
436 case 4:
437 return grpci2_cfg_w32(priv, busno, devfn, where, val);
438 }
439}
440
441static struct pci_ops grpci2_ops = {
442 .read = grpci2_read_config,
443 .write = grpci2_write_config,
444};
445
446
447
448
449
450
451static void grpci2_mask_irq(struct irq_data *data)
452{
453 unsigned long flags;
454 unsigned int irqidx;
455 struct grpci2_priv *priv = grpci2priv;
456
457 irqidx = (unsigned int)data->chip_data - 1;
458 if (irqidx > 3)
459 return;
460
461 spin_lock_irqsave(&grpci2_dev_lock, flags);
462 REGSTORE(priv->regs->ctrl, REGLOAD(priv->regs->ctrl) & ~(1 << irqidx));
463 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
464}
465
466static void grpci2_unmask_irq(struct irq_data *data)
467{
468 unsigned long flags;
469 unsigned int irqidx;
470 struct grpci2_priv *priv = grpci2priv;
471
472 irqidx = (unsigned int)data->chip_data - 1;
473 if (irqidx > 3)
474 return;
475
476 spin_lock_irqsave(&grpci2_dev_lock, flags);
477 REGSTORE(priv->regs->ctrl, REGLOAD(priv->regs->ctrl) | (1 << irqidx));
478 spin_unlock_irqrestore(&grpci2_dev_lock, flags);
479}
480
481static unsigned int grpci2_startup_irq(struct irq_data *data)
482{
483 grpci2_unmask_irq(data);
484 return 0;
485}
486
487static void grpci2_shutdown_irq(struct irq_data *data)
488{
489 grpci2_mask_irq(data);
490}
491
492static struct irq_chip grpci2_irq = {
493 .name = "grpci2",
494 .irq_startup = grpci2_startup_irq,
495 .irq_shutdown = grpci2_shutdown_irq,
496 .irq_mask = grpci2_mask_irq,
497 .irq_unmask = grpci2_unmask_irq,
498};
499
500
501static void grpci2_pci_flow_irq(struct irq_desc *desc)
502{
503 struct grpci2_priv *priv = grpci2priv;
504 int i, ack = 0;
505 unsigned int ctrl, sts_cap, pci_ints;
506
507 ctrl = REGLOAD(priv->regs->ctrl);
508 sts_cap = REGLOAD(priv->regs->sts_cap);
509
510
511 if (sts_cap & STS_ERR_IRQ) {
512 generic_handle_irq(priv->virq_err);
513 ack = 1;
514 }
515
516
517 pci_ints = ((~sts_cap) >> STS_INTSTS_BIT) & ctrl & CTRL_HOSTINT;
518 if (pci_ints) {
519
520 for (i = 0; i < 4; i++) {
521 if (pci_ints & (1 << i))
522 generic_handle_irq(priv->irq_map[i]);
523 }
524 ack = 1;
525 }
526
527
528
529
530
531
532 if ((priv->irq_mode == 0) && (sts_cap & (STS_IDMA | STS_IDMAERR))) {
533 generic_handle_irq(priv->virq_dma);
534 ack = 1;
535 }
536
537
538
539
540
541
542 if (ack)
543 desc->irq_data.chip->irq_eoi(&desc->irq_data);
544}
545
546
547static unsigned int grpci2_build_device_irq(unsigned int irq)
548{
549 unsigned int virq = 0, pil;
550
551 pil = 1 << 8;
552 virq = irq_alloc(irq, pil);
553 if (virq == 0)
554 goto out;
555
556 irq_set_chip_and_handler_name(virq, &grpci2_irq, handle_simple_irq,
557 "pcilvl");
558 irq_set_chip_data(virq, (void *)irq);
559
560out:
561 return virq;
562}
563
564static void grpci2_hw_init(struct grpci2_priv *priv)
565{
566 u32 ahbadr, pciadr, bar_sz, capptr, io_map, data;
567 struct grpci2_regs __iomem *regs = priv->regs;
568 int i;
569 struct grpci2_barcfg *barcfg = priv->tgtbars;
570
571
572 if (priv->do_reset) {
573 printk(KERN_INFO "GRPCI2: Resetting PCI bus\n");
574 REGSTORE(regs->ctrl, CTRL_RESET);
575 ssleep(1);
576 }
577 REGSTORE(regs->ctrl, 0);
578 REGSTORE(regs->sts_cap, ~0);
579 REGSTORE(regs->dma_ctrl, 0);
580 REGSTORE(regs->dma_bdbase, 0);
581
582
583 REGSTORE(regs->io_map, REGLOAD(regs->io_map) & 0x0000ffff);
584
585
586
587
588 for (i = 0; i < 16; i++)
589 REGSTORE(regs->ahbmst_map[i], priv->pci_area);
590
591
592 grpci2_cfg_r32(priv, TGT, 0, PCI_VENDOR_ID, &priv->pciid);
593
594
595 grpci2_cfg_r8(priv, TGT, 0, PCI_CAPABILITY_LIST, &capptr);
596
597
598 grpci2_cfg_r32(priv, TGT, 0, capptr+CAP9_IOMAP_OFS, &io_map);
599 io_map = (io_map & ~0x1) | (priv->bt_enabled ? 1 : 0);
600 grpci2_cfg_w32(priv, TGT, 0, capptr+CAP9_IOMAP_OFS, io_map);
601
602
603
604
605
606
607
608
609
610
611
612 for (i = 0; i < 6; i++) {
613 if (barcfg[i].pciadr != ~0 && barcfg[i].ahbadr != ~0) {
614
615 ahbadr = barcfg[i].ahbadr;
616 pciadr = barcfg[i].pciadr;
617 bar_sz = ((pciadr - 1) & ~pciadr) + 1;
618 } else {
619 if (i == 0) {
620
621 bar_sz = 0xf0000008;
622 ahbadr = 0xf0000000 & (u32)__pa(PAGE_ALIGN(
623 (unsigned long) &_end));
624 pciadr = ahbadr;
625 } else {
626 bar_sz = 0;
627 ahbadr = 0;
628 pciadr = 0;
629 }
630 }
631 grpci2_cfg_w32(priv, TGT, 0, capptr+CAP9_BARSIZE_OFS+i*4,
632 bar_sz);
633 grpci2_cfg_w32(priv, TGT, 0, PCI_BASE_ADDRESS_0+i*4, pciadr);
634 grpci2_cfg_w32(priv, TGT, 0, capptr+CAP9_BAR_OFS+i*4, ahbadr);
635 printk(KERN_INFO " TGT BAR[%d]: 0x%08x (PCI)-> 0x%08x\n",
636 i, pciadr, ahbadr);
637 }
638
639
640 grpci2_cfg_r32(priv, TGT, 0, PCI_COMMAND, &data);
641 data |= (PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
642 grpci2_cfg_w32(priv, TGT, 0, PCI_COMMAND, data);
643
644
645 REGSTORE(regs->ctrl, CTRL_ER | CTRL_PE);
646}
647
648static irqreturn_t grpci2_jump_interrupt(int irq, void *arg)
649{
650 printk(KERN_ERR "GRPCI2: Jump IRQ happened\n");
651 return IRQ_NONE;
652}
653
654
655static irqreturn_t grpci2_err_interrupt(int irq, void *arg)
656{
657 struct grpci2_priv *priv = arg;
658 struct grpci2_regs __iomem *regs = priv->regs;
659 unsigned int status;
660
661 status = REGLOAD(regs->sts_cap);
662 if ((status & STS_ERR_IRQ) == 0)
663 return IRQ_NONE;
664
665 if (status & STS_IPARERR)
666 printk(KERN_ERR "GRPCI2: Parity Error\n");
667
668 if (status & STS_ITGTABRT)
669 printk(KERN_ERR "GRPCI2: Target Abort\n");
670
671 if (status & STS_IMSTABRT)
672 printk(KERN_ERR "GRPCI2: Master Abort\n");
673
674 if (status & STS_ISYSERR)
675 printk(KERN_ERR "GRPCI2: System Error\n");
676
677
678 REGSTORE(regs->sts_cap, status & STS_ERR_IRQ);
679
680 return IRQ_HANDLED;
681}
682
683static int grpci2_of_probe(struct platform_device *ofdev)
684{
685 struct grpci2_regs __iomem *regs;
686 struct grpci2_priv *priv;
687 int err, i, len;
688 const int *tmp;
689 unsigned int capability;
690
691 if (grpci2priv) {
692 printk(KERN_ERR "GRPCI2: only one GRPCI2 core supported\n");
693 return -ENODEV;
694 }
695
696 if (ofdev->num_resources < 3) {
697 printk(KERN_ERR "GRPCI2: not enough APB/AHB resources\n");
698 return -EIO;
699 }
700
701
702 regs = of_ioremap(&ofdev->resource[0], 0,
703 resource_size(&ofdev->resource[0]),
704 "grlib-grpci2 regs");
705 if (regs == NULL) {
706 printk(KERN_ERR "GRPCI2: ioremap failed\n");
707 return -EIO;
708 }
709
710
711
712
713
714 capability = REGLOAD(regs->sts_cap);
715 if ((capability & STS_HOST) || !(capability & STS_MST)) {
716 printk(KERN_INFO "GRPCI2: not in host system slot\n");
717 err = -EIO;
718 goto err1;
719 }
720
721 priv = grpci2priv = kzalloc(sizeof(struct grpci2_priv), GFP_KERNEL);
722 if (grpci2priv == NULL) {
723 err = -ENOMEM;
724 goto err1;
725 }
726 priv->regs = regs;
727 priv->irq = ofdev->archdata.irqs[0];
728 priv->irq_mode = (capability & STS_IRQMODE) >> STS_IRQMODE_BIT;
729
730 printk(KERN_INFO "GRPCI2: host found at %p, irq%d\n", regs, priv->irq);
731
732
733 priv->bt_enabled = 1;
734
735
736 tmp = of_get_property(ofdev->dev.of_node, "barcfg", &len);
737 if (tmp && (len == 2*4*6))
738 memcpy(priv->tgtbars, tmp, 2*4*6);
739 else
740 memset(priv->tgtbars, -1, 2*4*6);
741
742
743 tmp = of_get_property(ofdev->dev.of_node, "irq_mask", &len);
744 if (tmp && (len == 4))
745 priv->do_reset = *tmp;
746 else
747 priv->irq_mask = 0xf;
748
749
750 tmp = of_get_property(ofdev->dev.of_node, "reset", &len);
751 if (tmp && (len == 4))
752 priv->do_reset = *tmp;
753 else
754 priv->do_reset = 0;
755
756
757 priv->pci_area = ofdev->resource[1].start;
758 priv->pci_area_end = ofdev->resource[1].end+1;
759 priv->pci_io = ofdev->resource[2].start;
760 priv->pci_conf = ofdev->resource[2].start + 0x10000;
761 priv->pci_conf_end = priv->pci_conf + 0x10000;
762 priv->pci_io_va = (unsigned long)ioremap(priv->pci_io, 0x10000);
763 if (!priv->pci_io_va) {
764 err = -EIO;
765 goto err2;
766 }
767
768 printk(KERN_INFO
769 "GRPCI2: MEMORY SPACE [0x%08lx - 0x%08lx]\n"
770 " I/O SPACE [0x%08lx - 0x%08lx]\n"
771 " CONFIG SPACE [0x%08lx - 0x%08lx]\n",
772 priv->pci_area, priv->pci_area_end-1,
773 priv->pci_io, priv->pci_conf-1,
774 priv->pci_conf, priv->pci_conf_end-1);
775
776
777
778
779
780
781 memset(&priv->info.io_space, 0, sizeof(struct resource));
782 priv->info.io_space.name = "GRPCI2 PCI I/O Space";
783 priv->info.io_space.start = priv->pci_io_va + 0x1000;
784 priv->info.io_space.end = priv->pci_io_va + 0x10000 - 1;
785 priv->info.io_space.flags = IORESOURCE_IO;
786
787
788
789
790
791 memset(&priv->info.mem_space, 0, sizeof(struct resource));
792 priv->info.mem_space.name = "GRPCI2 PCI MEM Space";
793 priv->info.mem_space.start = priv->pci_area;
794 priv->info.mem_space.end = priv->pci_area_end - 1;
795 priv->info.mem_space.flags = IORESOURCE_MEM;
796
797 if (request_resource(&iomem_resource, &priv->info.mem_space) < 0)
798 goto err3;
799 if (request_resource(&ioport_resource, &priv->info.io_space) < 0)
800 goto err4;
801
802
803 priv->info.busn.name = "GRPCI2 busn";
804 priv->info.busn.start = 0;
805 priv->info.busn.end = 255;
806
807 grpci2_hw_init(priv);
808
809
810
811
812
813 if (priv->irq_mode < 2) {
814
815 leon_update_virq_handling(priv->irq, grpci2_pci_flow_irq,
816 "pcilvl", 0);
817
818 priv->irq_map[0] = grpci2_build_device_irq(1);
819 priv->irq_map[1] = grpci2_build_device_irq(2);
820 priv->irq_map[2] = grpci2_build_device_irq(3);
821 priv->irq_map[3] = grpci2_build_device_irq(4);
822
823 priv->virq_err = grpci2_build_device_irq(5);
824 if (priv->irq_mode & 1)
825 priv->virq_dma = ofdev->archdata.irqs[1];
826 else
827 priv->virq_dma = grpci2_build_device_irq(6);
828
829
830 err = request_irq(priv->irq, grpci2_jump_interrupt, 0,
831 "GRPCI2_JUMP", priv);
832 if (err)
833 printk(KERN_ERR "GRPCI2: ERR IRQ request failed\n");
834 } else {
835
836 for (i = 0; i < 4; i++) {
837
838 leon_update_virq_handling(ofdev->archdata.irqs[i],
839 handle_fasteoi_irq, "pcilvl",
840 1);
841 priv->irq_map[i] = ofdev->archdata.irqs[i];
842 }
843 priv->virq_err = priv->irq_map[0];
844 if (priv->irq_mode & 1)
845 priv->virq_dma = ofdev->archdata.irqs[4];
846 else
847 priv->virq_dma = priv->irq_map[0];
848
849
850 REGSTORE(regs->ctrl, REGLOAD(regs->ctrl)|(priv->irq_mask&0xf));
851 }
852
853
854 err = request_irq(priv->virq_err, grpci2_err_interrupt, IRQF_SHARED,
855 "GRPCI2_ERR", priv);
856 if (err) {
857 printk(KERN_DEBUG "GRPCI2: ERR VIRQ request failed: %d\n", err);
858 goto err5;
859 }
860
861
862
863
864
865 REGSTORE(regs->ctrl, REGLOAD(regs->ctrl) | CTRL_EI | CTRL_SI);
866
867
868 priv->info.ops = &grpci2_ops;
869 priv->info.map_irq = grpci2_map_irq;
870 leon_pci_init(ofdev, &priv->info);
871
872 return 0;
873
874err5:
875 release_resource(&priv->info.io_space);
876err4:
877 release_resource(&priv->info.mem_space);
878err3:
879 err = -ENOMEM;
880 iounmap((void __iomem *)priv->pci_io_va);
881err2:
882 kfree(priv);
883err1:
884 of_iounmap(&ofdev->resource[0], regs,
885 resource_size(&ofdev->resource[0]));
886 return err;
887}
888
889static struct of_device_id grpci2_of_match[] = {
890 {
891 .name = "GAISLER_GRPCI2",
892 },
893 {
894 .name = "01_07c",
895 },
896 {},
897};
898
899static struct platform_driver grpci2_of_driver = {
900 .driver = {
901 .name = "grpci2",
902 .of_match_table = grpci2_of_match,
903 },
904 .probe = grpci2_of_probe,
905};
906
907static int __init grpci2_init(void)
908{
909 return platform_driver_register(&grpci2_of_driver);
910}
911
912subsys_initcall(grpci2_init);
913