update to 2.6.22-rc6
[openwrt/staging/florian.git] / target / linux / adm5120-2.6 / files / arch / mips / pci / fixup-adm5120.c
1 /*
2 * $Id$
3 *
4 * ADM5120 specific PCI fixups
5 *
6 * Copyright (C) ADMtek Incorporated.
7 * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
8 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
9 * Copyright (C) 2007 OpenWrt.org
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301, USA.
25 *
26 */
27
28 #include <linux/autoconf.h>
29 #include <linux/types.h>
30 #include <linux/kernel.h>
31 #include <linux/init.h>
32 #include <linux/pci.h>
33 #include <linux/pci_ids.h>
34 #include <linux/pci_regs.h>
35
36 #include <asm/delay.h>
37 #include <asm/bootinfo.h>
38
39 #include <asm/mach-adm5120/adm5120_info.h>
40 #include <asm/mach-adm5120/adm5120_defs.h>
41 #include <asm/mach-adm5120/adm5120_irq.h>
42
43 struct adm5120_pci_irq {
44 u8 slot;
45 u8 func;
46 u8 pin;
47 unsigned irq;
48 };
49
50 #define PCIIRQ(s,f,p,i) { \
51 .slot = (s), \
52 .func = (f), \
53 .pin = (p), \
54 .irq = (i) \
55 }
56
57 static struct adm5120_pci_irq default_pci_irqs[] __initdata = {
58 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
59 };
60
61 static struct adm5120_pci_irq rb1xx_pci_irqs[] __initdata = {
62 PCIIRQ(1, 0, 1, ADM5120_IRQ_PCI0),
63 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI1),
64 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI2)
65 };
66
67 static struct adm5120_pci_irq cas771_pci_irqs[] __initdata = {
68 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
69 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI1),
70 PCIIRQ(3, 2, 3, ADM5120_IRQ_PCI2)
71 };
72
73 static struct adm5120_pci_irq np28g_pci_irqs[] __initdata = {
74 PCIIRQ(2, 0, 1, ADM5120_IRQ_PCI0),
75 PCIIRQ(3, 0, 1, ADM5120_IRQ_PCI0),
76 PCIIRQ(3, 1, 2, ADM5120_IRQ_PCI1),
77 PCIIRQ(3, 2, 3, ADM5120_IRQ_PCI2)
78 };
79
80 #define GETMAP(n) do { \
81 nr_irqs = ARRAY_SIZE(n ## _pci_irqs); \
82 p = n ## _pci_irqs; \
83 } while (0)
84
85 int __init pcibios_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
86 {
87 struct adm5120_pci_irq *p;
88 int nr_irqs;
89 int i;
90 int irq;
91
92 irq = -1;
93 if (slot < 1 || slot > 3) {
94 printk(KERN_ALERT "PCI: slot number %u is not supported\n",
95 slot);
96 goto out;
97 }
98
99 GETMAP(default);
100
101 switch (mips_machtype) {
102 case MACH_ADM5120_RB_111:
103 case MACH_ADM5120_RB_112:
104 case MACH_ADM5120_RB_133:
105 case MACH_ADM5120_RB_133C:
106 case MACH_ADM5120_RB_153:
107 GETMAP(rb1xx);
108 break;
109 case MACH_ADM5120_NP28G:
110 GETMAP(np28g);
111 break;
112 case MACH_ADM5120_P335:
113 case MACH_ADM5120_P334WT:
114 /* using default mapping */
115 break;
116 case MACH_ADM5120_CAS771:
117 GETMAP(cas771);
118 break;
119
120 case MACH_ADM5120_NP27G:
121 case MACH_ADM5120_NP28GHS:
122 case MACH_ADM5120_WP54AG:
123 case MACH_ADM5120_WP54G:
124 case MACH_ADM5120_WP54G_WRT:
125 case MACH_ADM5120_WPP54AG:
126 case MACH_ADM5120_WPP54G:
127 default:
128 printk(KERN_ALERT "PCI: irq map is unknown for %s, using "
129 "defaults.\n", adm5120_board_name());
130 break;
131 }
132
133 for (i=0; i<nr_irqs; i++, p++) {
134 if ((p->slot == slot) && (PCI_FUNC(dev->devfn) == p->func) &&
135 (p->pin == pin)) {
136 irq = p->irq;
137 break;
138 }
139 }
140
141 if (irq < 0) {
142 printk(KERN_ALERT "PCI: no irq found for %s pin:%u\n",
143 pci_name(dev), pin);
144 } else {
145 printk(KERN_INFO "PCI: mapping irq for %s pin:%u, irq:%d\n",
146 pci_name(dev), pin, irq);
147 }
148
149 out:
150 return irq;
151 }
152
153 static void adm5120_pci_fixup(struct pci_dev *dev)
154 {
155 if (dev->devfn != 0)
156 return;
157
158 /* setup COMMAND register */
159 pci_write_config_word(dev, PCI_COMMAND,
160 (PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER));
161
162 /* setup CACHE_LINE_SIZE register */
163 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 4);
164
165 /* setting up BARS */
166 pci_write_config_dword(dev, PCI_BASE_ADDRESS_0, 0);
167 pci_write_config_dword(dev, PCI_BASE_ADDRESS_1, 0);
168 }
169
170 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ADMTEK, PCI_DEVICE_ID_ADMTEK_ADM5120,
171 adm5120_pci_fixup);
172
173 int pcibios_plat_dev_init(struct pci_dev *dev)
174 {
175 return 0;
176 }
177