Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sh / boards / mpc1211 / pci.c
blobba3a6543975227fb6a40c3a6f93f18c3989a884c
1 /*
2 * Low-Level PCI Support for the MPC-1211(CTP/PCI/MPC-SH02)
4 * (c) 2002-2003 Saito.K & Jeanne
6 * Dustin McIntire (dustin@sensoria.com)
7 * Derived from arch/i386/kernel/pci-*.c which bore the message:
8 * (c) 1999--2000 Martin Mares <mj@ucw.cz>
9 *
10 * May be copied or modified under the terms of the GNU General Public
11 * License. See linux/COPYING for more information.
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/delay.h>
19 #include <linux/pci.h>
20 #include <linux/sched.h>
21 #include <linux/ioport.h>
22 #include <linux/errno.h>
23 #include <linux/irq.h>
24 #include <linux/interrupt.h>
26 #include <asm/machvec.h>
27 #include <asm/io.h>
28 #include <asm/mpc1211/pci.h>
30 static struct resource mpcpci_io_resource = {
31 "MPCPCI IO",
32 0x00000000,
33 0xffffffff,
34 IORESOURCE_IO
37 static struct resource mpcpci_mem_resource = {
38 "MPCPCI mem",
39 0x00000000,
40 0xffffffff,
41 IORESOURCE_MEM
44 static struct pci_ops pci_direct_conf1;
45 struct pci_channel board_pci_channels[] = {
46 {&pci_direct_conf1, &mpcpci_io_resource, &mpcpci_mem_resource, 0, 256},
47 {NULL, NULL, NULL, 0, 0},
51 * Direct access to PCI hardware...
55 #define CONFIG_CMD(bus, devfn, where) (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
58 * Functions for accessing PCI configuration space with type 1 accesses
60 static int pci_conf1_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
62 u32 word;
63 unsigned long flags;
65 /*
66 * PCIPDR may only be accessed as 32 bit words,
67 * so we must do byte alignment by hand
69 local_irq_save(flags);
70 writel(CONFIG_CMD(bus,devfn,where), PCIPAR);
71 word = readl(PCIPDR);
72 local_irq_restore(flags);
74 switch (size) {
75 case 1:
76 switch (where & 0x3) {
77 case 3:
78 *value = (u8)(word >> 24);
79 break;
80 case 2:
81 *value = (u8)(word >> 16);
82 break;
83 case 1:
84 *value = (u8)(word >> 8);
85 break;
86 default:
87 *value = (u8)word;
88 break;
90 break;
91 case 2:
92 switch (where & 0x3) {
93 case 3:
94 *value = (u16)(word >> 24);
95 local_irq_save(flags);
96 writel(CONFIG_CMD(bus,devfn,(where+1)), PCIPAR);
97 word = readl(PCIPDR);
98 local_irq_restore(flags);
99 *value |= ((word & 0xff) << 8);
100 break;
101 case 2:
102 *value = (u16)(word >> 16);
103 break;
104 case 1:
105 *value = (u16)(word >> 8);
106 break;
107 default:
108 *value = (u16)word;
109 break;
111 break;
112 case 4:
113 *value = word;
114 break;
116 PCIDBG(4,"pci_conf1_read@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),*value);
117 return PCIBIOS_SUCCESSFUL;
121 * Since MPC-1211 only does 32bit access we'll have to do a read,mask,write operation.
122 * We'll allow an odd byte offset, though it should be illegal.
124 static int pci_conf1_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
126 u32 word,mask = 0;
127 unsigned long flags;
128 u32 shift = (where & 3) * 8;
130 if(size == 1) {
131 mask = ((1 << 8) - 1) << shift; // create the byte mask
132 } else if(size == 2){
133 if(shift == 24)
134 return PCIBIOS_BAD_REGISTER_NUMBER;
135 mask = ((1 << 16) - 1) << shift; // create the word mask
137 local_irq_save(flags);
138 writel(CONFIG_CMD(bus,devfn,where), PCIPAR);
139 if(size == 4){
140 writel(value, PCIPDR);
141 local_irq_restore(flags);
142 PCIDBG(4,"pci_conf1_write@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),value);
143 return PCIBIOS_SUCCESSFUL;
145 word = readl(PCIPDR);
146 word &= ~mask;
147 word |= ((value << shift) & mask);
148 writel(word, PCIPDR);
149 local_irq_restore(flags);
150 PCIDBG(4,"pci_conf1_write@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),word);
151 return PCIBIOS_SUCCESSFUL;
154 #undef CONFIG_CMD
156 static struct pci_ops pci_direct_conf1 = {
157 .read = pci_conf1_read,
158 .write = pci_conf1_write,
161 static void __devinit quirk_ali_ide_ports(struct pci_dev *dev)
163 dev->resource[0].start = 0x1f0;
164 dev->resource[0].end = 0x1f7;
165 dev->resource[0].flags = IORESOURCE_IO;
166 dev->resource[1].start = 0x3f6;
167 dev->resource[1].end = 0x3f6;
168 dev->resource[1].flags = IORESOURCE_IO;
169 dev->resource[2].start = 0x170;
170 dev->resource[2].end = 0x177;
171 dev->resource[2].flags = IORESOURCE_IO;
172 dev->resource[3].start = 0x376;
173 dev->resource[3].end = 0x376;
174 dev->resource[3].flags = IORESOURCE_IO;
175 dev->resource[4].start = 0xf000;
176 dev->resource[4].end = 0xf00f;
177 dev->resource[4].flags = IORESOURCE_IO;
179 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5229, quirk_ali_ide_ports);
181 char * __devinit pcibios_setup(char *str)
183 return str;
187 * Called after each bus is probed, but before its children
188 * are examined.
191 void __init pcibios_fixup_bus(struct pci_bus *b)
193 pci_read_bridge_bases(b);
197 * IRQ functions
199 static inline u8 bridge_swizzle(u8 pin, u8 slot)
201 return (((pin-1) + slot) % 4) + 1;
204 static inline u8 bridge_swizzle_pci_1(u8 pin, u8 slot)
206 return (((pin-1) - slot) & 3) + 1;
209 static u8 __init mpc1211_swizzle(struct pci_dev *dev, u8 *pinp)
211 unsigned long flags;
212 u8 pin = *pinp;
213 u32 word;
215 for ( ; dev->bus->self; dev = dev->bus->self) {
216 if (!pin)
217 continue;
219 if (dev->bus->number == 1) {
220 local_irq_save(flags);
221 writel(0x80000000 | 0x2c, PCIPAR);
222 word = readl(PCIPDR);
223 local_irq_restore(flags);
224 word >>= 16;
226 if (word == 0x0001)
227 pin = bridge_swizzle_pci_1(pin, PCI_SLOT(dev->devfn));
228 else
229 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
230 } else
231 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
234 *pinp = pin;
236 return PCI_SLOT(dev->devfn);
239 static int __init map_mpc1211_irq(struct pci_dev *dev, u8 slot, u8 pin)
241 int irq = -1;
243 /* now lookup the actual IRQ on a platform specific basis (pci-'platform'.c) */
244 if (dev->bus->number == 0) {
245 switch (slot) {
246 case 13: irq = 9; break; /* USB */
247 case 22: irq = 10; break; /* LAN */
248 default: irq = 0; break;
250 } else {
251 switch (pin) {
252 case 0: irq = 0; break;
253 case 1: irq = 7; break;
254 case 2: irq = 9; break;
255 case 3: irq = 10; break;
256 case 4: irq = 11; break;
260 if( irq < 0 ) {
261 PCIDBG(3, "PCI: Error mapping IRQ on device %s\n", pci_name(dev));
262 return irq;
265 PCIDBG(2, "Setting IRQ for slot %s to %d\n", pci_name(dev), irq);
267 return irq;
270 void __init pcibios_fixup_irqs(void)
272 pci_fixup_irqs(mpc1211_swizzle, map_mpc1211_irq);
275 void pcibios_align_resource(void *data, struct resource *res,
276 unsigned long size, unsigned long align)
278 unsigned long start = res->start;
280 if (res->flags & IORESOURCE_IO) {
281 if (start >= 0x10000UL) {
282 if ((start & 0xffffUL) < 0x4000UL) {
283 start = (start & 0xffff0000UL) + 0x4000UL;
284 } else if ((start & 0xffffUL) >= 0xf000UL) {
285 start = (start & 0xffff0000UL) + 0x10000UL;
287 res->start = start;
288 } else {
289 if (start & 0x300) {
290 start = (start + 0x3ff) & ~0x3ff;
291 res->start = start;