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/types.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/delay.h>
18 #include <linux/pci.h>
19 #include <linux/sched.h>
20 #include <linux/ioport.h>
21 #include <linux/errno.h>
22 #include <linux/irq.h>
23 #include <linux/interrupt.h>
25 #include <asm/machvec.h>
27 #include <asm/mpc1211/pci.h>
29 static struct resource mpcpci_io_resource = {
36 static struct resource mpcpci_mem_resource = {
43 static struct pci_ops pci_direct_conf1;
44 struct pci_channel board_pci_channels[] = {
45 {&pci_direct_conf1, &mpcpci_io_resource, &mpcpci_mem_resource, 0, 256},
46 {NULL, NULL, NULL, 0, 0},
50 * Direct access to PCI hardware...
54 #define CONFIG_CMD(bus, devfn, where) (0x80000000 | (bus->number << 16) | (devfn << 8) | (where & ~3))
57 * Functions for accessing PCI configuration space with type 1 accesses
59 static int pci_conf1_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
65 * PCIPDR may only be accessed as 32 bit words,
66 * so we must do byte alignment by hand
68 local_irq_save(flags);
69 writel(CONFIG_CMD(bus,devfn,where), PCIPAR);
71 local_irq_restore(flags);
75 switch (where & 0x3) {
77 *value = (u8)(word >> 24);
80 *value = (u8)(word >> 16);
83 *value = (u8)(word >> 8);
91 switch (where & 0x3) {
93 *value = (u16)(word >> 24);
94 local_irq_save(flags);
95 writel(CONFIG_CMD(bus,devfn,(where+1)), PCIPAR);
97 local_irq_restore(flags);
98 *value |= ((word & 0xff) << 8);
101 *value = (u16)(word >> 16);
104 *value = (u16)(word >> 8);
115 PCIDBG(4,"pci_conf1_read@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),*value);
116 return PCIBIOS_SUCCESSFUL;
120 * Since MPC-1211 only does 32bit access we'll have to do a read,mask,write operation.
121 * We'll allow an odd byte offset, though it should be illegal.
123 static int pci_conf1_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
127 u32 shift = (where & 3) * 8;
130 mask = ((1 << 8) - 1) << shift; // create the byte mask
131 } else if(size == 2){
133 return PCIBIOS_BAD_REGISTER_NUMBER;
134 mask = ((1 << 16) - 1) << shift; // create the word mask
136 local_irq_save(flags);
137 writel(CONFIG_CMD(bus,devfn,where), PCIPAR);
139 writel(value, PCIPDR);
140 local_irq_restore(flags);
141 PCIDBG(4,"pci_conf1_write@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),value);
142 return PCIBIOS_SUCCESSFUL;
144 word = readl(PCIPDR);
146 word |= ((value << shift) & mask);
147 writel(word, PCIPDR);
148 local_irq_restore(flags);
149 PCIDBG(4,"pci_conf1_write@0x%08x=0x%x\n", CONFIG_CMD(bus,devfn,where),word);
150 return PCIBIOS_SUCCESSFUL;
155 static struct pci_ops pci_direct_conf1 = {
156 .read = pci_conf1_read,
157 .write = pci_conf1_write,
160 static void __devinit quirk_ali_ide_ports(struct pci_dev *dev)
162 dev->resource[0].start = 0x1f0;
163 dev->resource[0].end = 0x1f7;
164 dev->resource[0].flags = IORESOURCE_IO;
165 dev->resource[1].start = 0x3f6;
166 dev->resource[1].end = 0x3f6;
167 dev->resource[1].flags = IORESOURCE_IO;
168 dev->resource[2].start = 0x170;
169 dev->resource[2].end = 0x177;
170 dev->resource[2].flags = IORESOURCE_IO;
171 dev->resource[3].start = 0x376;
172 dev->resource[3].end = 0x376;
173 dev->resource[3].flags = IORESOURCE_IO;
174 dev->resource[4].start = 0xf000;
175 dev->resource[4].end = 0xf00f;
176 dev->resource[4].flags = IORESOURCE_IO;
178 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5229, quirk_ali_ide_ports);
180 char * __devinit pcibios_setup(char *str)
186 * Called after each bus is probed, but before its children
190 void __init pcibios_fixup_bus(struct pci_bus *b)
192 pci_read_bridge_bases(b);
198 static inline u8 bridge_swizzle(u8 pin, u8 slot)
200 return (((pin-1) + slot) % 4) + 1;
203 static inline u8 bridge_swizzle_pci_1(u8 pin, u8 slot)
205 return (((pin-1) - slot) & 3) + 1;
208 static u8 __init mpc1211_swizzle(struct pci_dev *dev, u8 *pinp)
214 for ( ; dev->bus->self; dev = dev->bus->self) {
218 if (dev->bus->number == 1) {
219 local_irq_save(flags);
220 writel(0x80000000 | 0x2c, PCIPAR);
221 word = readl(PCIPDR);
222 local_irq_restore(flags);
226 pin = bridge_swizzle_pci_1(pin, PCI_SLOT(dev->devfn));
228 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
230 pin = bridge_swizzle(pin, PCI_SLOT(dev->devfn));
235 return PCI_SLOT(dev->devfn);
238 static int __init map_mpc1211_irq(struct pci_dev *dev, u8 slot, u8 pin)
242 /* now lookup the actual IRQ on a platform specific basis (pci-'platform'.c) */
243 if (dev->bus->number == 0) {
245 case 13: irq = 9; break; /* USB */
246 case 22: irq = 10; break; /* LAN */
247 default: irq = 0; break;
251 case 0: irq = 0; break;
252 case 1: irq = 7; break;
253 case 2: irq = 9; break;
254 case 3: irq = 10; break;
255 case 4: irq = 11; break;
260 PCIDBG(3, "PCI: Error mapping IRQ on device %s\n", pci_name(dev));
264 PCIDBG(2, "Setting IRQ for slot %s to %d\n", pci_name(dev), irq);
269 void __init pcibios_fixup_irqs(void)
271 pci_fixup_irqs(mpc1211_swizzle, map_mpc1211_irq);
274 void pcibios_align_resource(void *data, struct resource *res,
275 resource_size_t size, resource_size_t align)
277 resource_size_t start = res->start;
279 if (res->flags & IORESOURCE_IO) {
280 if (start >= 0x10000UL) {
281 if ((start & 0xffffUL) < 0x4000UL) {
282 start = (start & 0xffff0000UL) + 0x4000UL;
283 } else if ((start & 0xffffUL) >= 0xf000UL) {
284 start = (start & 0xffff0000UL) + 0x10000UL;
289 start = (start + 0x3ff) & ~0x3ff;