linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / arch / arm / mach-iop3xx / iq80331-pci.c
1 /*
2  * arch/arm/mach-iop3xx/iq80331-pci.c
3  *
4  * PCI support for the Intel IQ80331 reference board
5  *
6  * Author: Dave Jiang <dave.jiang@intel.com>
7  * Copyright (C) 2003, 2004 Intel Corp.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 #include <linux/kernel.h>
14 #include <linux/pci.h>
15 #include <linux/init.h>
16 #include <linux/string.h>
17 #include <linux/slab.h>
18
19 #include <asm/hardware.h>
20 #include <asm/irq.h>
21 #include <asm/mach/pci.h>
22 #include <asm/mach-types.h>
23
24 /*
25  * The following macro is used to lookup irqs in a standard table
26  * format for those systems that do not already have PCI
27  * interrupts properly routed.  We assume 1 <= pin <= 4
28  */
29 #define PCI_IRQ_TABLE_LOOKUP(minid,maxid)       \
30 ({ int _ctl_ = -1;                              \
31    unsigned int _idsel = idsel - minid;         \
32    if (_idsel <= maxid)                         \
33       _ctl_ = pci_irq_table[_idsel][pin-1];     \
34    _ctl_; })
35
36 #define INTA    IRQ_IQ80331_INTA
37 #define INTB    IRQ_IQ80331_INTB
38 #define INTC    IRQ_IQ80331_INTC
39 #define INTD    IRQ_IQ80331_INTD
40
41 //#define INTE  IRQ_IQ80331_I82544
42
43 static inline int __init
44 iq80331_map_irq(struct pci_dev *dev, u8 idsel, u8 pin)
45 {
46         static int pci_irq_table[][4] = {
47                 /*
48                  * PCI IDSEL/INTPIN->INTLINE
49                  * A       B       C       D
50                  */
51                 {INTB, INTC, INTD, INTA}, /* PCI-X Slot */
52                 {INTC, INTC, INTC, INTC}, /* GigE  */
53         };
54
55         BUG_ON(pin < 1 || pin > 4);
56
57         return PCI_IRQ_TABLE_LOOKUP(1, 7);
58 }
59
60 static int iq80331_setup(int nr, struct pci_sys_data *sys)
61 {
62         struct resource *res;
63
64         if(nr != 0)
65                 return 0;
66
67         res = kmalloc(sizeof(struct resource) * 2, GFP_KERNEL);
68         if (!res)
69                 panic("PCI: unable to alloc resources");
70
71         memset(res, 0, sizeof(struct resource) * 2);
72
73         res[0].start = IOP331_PCI_LOWER_IO_VA;
74         res[0].end   = IOP331_PCI_UPPER_IO_VA;
75         res[0].name  = "IQ80331 PCI I/O Space";
76         res[0].flags = IORESOURCE_IO;
77
78         res[1].start = IOP331_PCI_LOWER_MEM_PA;
79         res[1].end   = IOP331_PCI_UPPER_MEM_PA;
80         res[1].name  = "IQ80331 PCI Memory Space";
81         res[1].flags = IORESOURCE_MEM;
82
83         request_resource(&ioport_resource, &res[0]);
84         request_resource(&iomem_resource, &res[1]);
85
86         sys->mem_offset = IOP331_PCI_MEM_OFFSET;
87         sys->io_offset  = IOP331_PCI_IO_OFFSET;
88
89         sys->resource[0] = &res[0];
90         sys->resource[1] = &res[1];
91         sys->resource[2] = NULL;
92
93         return 1;
94 }
95
96 static void iq80331_preinit(void)
97 {
98         iop331_init();
99 }
100
101 static struct hw_pci iq80331_pci __initdata = {
102         .swizzle        = pci_std_swizzle,
103         .nr_controllers = 1,
104         .setup          = iq80331_setup,
105         .scan           = iop331_scan_bus,
106         .preinit        = iq80331_preinit,
107         .map_irq        = iq80331_map_irq
108 };
109
110 static int __init iq80331_pci_init(void)
111 {
112         if (machine_is_iq80331())
113                 pci_common_init(&iq80331_pci);
114         return 0;
115 }
116
117 subsys_initcall(iq80331_pci_init);
118
119
120
121