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>
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>
28 #include <asm/mpc1211/pci.h>
30 static struct resource mpcpci_io_resource = {
37 static struct resource mpcpci_mem_resource = {
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)
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);
72 local_irq_restore(flags);
76 switch (where & 0x3) {
78 *value = (u8)(word >> 24);
81 *value = (u8)(word >> 16);
84 *value = (u8)(word >> 8);
92 switch (where & 0x3) {
94 *value = (u16)(word >> 24);
95 local_irq_save(flags);
96 writel(CONFIG_CMD(bus,devfn,(where+1)), PCIPAR);
98 local_irq_restore(flags);
99 *value |= ((word & 0xff) << 8);
102 *value = (u16)(word >> 16);
105 *value = (u16)(word >> 8);
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)
128 u32 shift = (where & 3) * 8;
131 mask = ((1 << 8) - 1) << shift; // create the byte mask
132 } else if(size == 2){
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);
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);
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;
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)
187 * Called after each bus is probed, but before its children
191 void __init pcibios_fixup_bus(struct pci_bus *b)
193 pci_read_bridge_bases(b);
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)
215 for ( ; dev->bus->self; dev = dev->bus->self) {
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);
227 pin = bridge_swizzle_pci_1(pin, PCI_SLOT(dev->devfn));
229 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
231 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
236 return PCI_SLOT(dev->devfn);
239 static int __init map_mpc1211_irq(struct pci_dev *dev, u8 slot, u8 pin)
243 /* now lookup the actual IRQ on a platform specific basis (pci-'platform'.c) */
244 if (dev->bus->number == 0) {
246 case 13: irq = 9; break; /* USB */
247 case 22: irq = 10; break; /* LAN */
248 default: irq = 0; break;
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;
261 PCIDBG(3, "PCI: Error mapping IRQ on device %s\n", pci_name(dev));
265 PCIDBG(2, "Setting IRQ for slot %s to %d\n", pci_name(dev), 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;
290 start = (start + 0x3ff) & ~0x3ff;