2 * arch/ppc/platforms/k2_pci.c
4 * PCI support for SBS K2
6 * Author: Matt Porter <mporter@mvista.com>
8 * Copyright 2001 MontaVista Software Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/pci.h>
19 #include <linux/slab.h>
21 #include <asm/byteorder.h>
23 #include <asm/uaccess.h>
24 #include <asm/machdep.h>
25 #include <asm/pci-bridge.h>
32 #define DBG(x...) printk(x)
37 static inline int __init
38 k2_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin)
40 struct pci_controller *hose = pci_bus_to_hose(dev->bus->number);
42 * Check our hose index. If we are zero then we are on the
43 * local PCI hose, otherwise we are on the cPCI hose.
47 static char pci_irq_table[][4] =
49 * PCI IDSEL/INTPIN->INTLINE
53 {1, 0, 0, 0}, /* Ethernet */
54 {5, 5, 5, 5}, /* PMC Site 1 */
55 {6, 6, 6, 6}, /* PMC Site 2 */
56 {0, 0, 0, 0}, /* unused */
57 {0, 0, 0, 0}, /* unused */
58 {0, 0, 0, 0}, /* PCI-ISA Bridge */
59 {0, 0, 0, 0}, /* unused */
60 {0, 0, 0, 0}, /* unused */
61 {0, 0, 0, 0}, /* unused */
62 {0, 0, 0, 0}, /* unused */
63 {0, 0, 0, 0}, /* unused */
64 {0, 0, 0, 0}, /* unused */
65 {0, 0, 0, 0}, /* unused */
66 {0, 0, 0, 0}, /* unused */
67 {15, 0, 0, 0}, /* M5229 IDE */
69 const long min_idsel = 3, max_idsel = 17, irqs_per_slot = 4;
70 return PCI_IRQ_TABLE_LOOKUP;
74 static char pci_irq_table[][4] =
76 * PCI IDSEL/INTPIN->INTLINE
80 {10, 11, 12, 9}, /* cPCI slot 8 */
81 {11, 12, 9, 10}, /* cPCI slot 7 */
82 {12, 9, 10, 11}, /* cPCI slot 6 */
83 {9, 10, 11, 12}, /* cPCI slot 5 */
84 {10, 11, 12, 9}, /* cPCI slot 4 */
85 {11, 12, 9, 10}, /* cPCI slot 3 */
86 {12, 9, 10, 11}, /* cPCI slot 2 */
88 const long min_idsel = 15, max_idsel = 21, irqs_per_slot = 4;
89 return PCI_IRQ_TABLE_LOOKUP;
93 void k2_pcibios_fixup(void)
95 #if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
96 struct pci_dev *ide_dev;
99 * Enable DMA support on hdc
101 ide_dev = pci_find_device(PCI_VENDOR_ID_AL,
102 PCI_DEVICE_ID_AL_M5229,
107 unsigned long ide_dma_base;
109 ide_dma_base = pci_resource_start(ide_dev, 4);
110 outb(0x00, ide_dma_base+0x2);
111 outb(0x20, ide_dma_base+0xa);
116 void k2_setup_hoses(void)
118 struct pci_controller *hose_a, *hose_b;
121 * Reconfigure CPC710 memory map so
122 * we have some more PCI memory space.
126 __raw_writel(0x808000e0, PGCHP); /* Set FPHB mode */
129 __raw_writel(0x00000000, K2_PCI32_BAR+PIBAR); /* PCI I/O base */
130 __raw_writel(0x00000000, K2_PCI32_BAR+PMBAR); /* PCI Mem base */
131 __raw_writel(0xf0000000, K2_PCI32_BAR+MSIZE); /* 256MB */
132 __raw_writel(0xfff00000, K2_PCI32_BAR+IOSIZE); /* 1MB */
133 __raw_writel(0xc0000000, K2_PCI32_BAR+SMBAR); /* Base@0xc0000000 */
134 __raw_writel(0x80000000, K2_PCI32_BAR+SIBAR); /* Base@0x80000000 */
135 __raw_writel(0x000000c0, K2_PCI32_BAR+PSSIZE); /* 1GB space */
136 __raw_writel(0x000000c0, K2_PCI32_BAR+PPSIZE); /* 1GB space */
137 __raw_writel(0x00000000, K2_PCI32_BAR+BARPS); /* Base@0x00000000 */
138 __raw_writel(0x00000000, K2_PCI32_BAR+BARPP); /* Base@0x00000000 */
139 __raw_writel(0x00000080, K2_PCI32_BAR+PSBAR); /* Base@0x80 */
140 __raw_writel(0x00000000, K2_PCI32_BAR+PPBAR);
142 __raw_writel(0xc0000000, K2_PCI32_BAR+BPMDLK);
143 __raw_writel(0xd0000000, K2_PCI32_BAR+TPMDLK);
144 __raw_writel(0x80000000, K2_PCI32_BAR+BIODLK);
145 __raw_writel(0x80100000, K2_PCI32_BAR+TIODLK);
146 __raw_writel(0xe0008000, K2_PCI32_BAR+DLKCTRL);
147 __raw_writel(0xffffffff, K2_PCI32_BAR+DLKDEV);
150 __raw_writel(0x00100000, K2_PCI64_BAR+PIBAR); /* PCI I/O base */
151 __raw_writel(0x10000000, K2_PCI64_BAR+PMBAR); /* PCI Mem base */
152 __raw_writel(0xf0000000, K2_PCI64_BAR+MSIZE); /* 256MB */
153 __raw_writel(0xfff00000, K2_PCI64_BAR+IOSIZE); /* 1MB */
154 __raw_writel(0xd0000000, K2_PCI64_BAR+SMBAR); /* Base@0xd0000000 */
155 __raw_writel(0x80100000, K2_PCI64_BAR+SIBAR); /* Base@0x80100000 */
156 __raw_writel(0x000000c0, K2_PCI64_BAR+PSSIZE); /* 1GB space */
157 __raw_writel(0x000000c0, K2_PCI64_BAR+PPSIZE); /* 1GB space */
158 __raw_writel(0x00000000, K2_PCI64_BAR+BARPS); /* Base@0x00000000 */
159 __raw_writel(0x00000000, K2_PCI64_BAR+BARPP); /* Base@0x00000000 */
161 /* Setup PCI32 hose */
162 hose_a = pcibios_alloc_controller();
166 hose_a->first_busno = 0;
167 hose_a->last_busno = 0xff;
168 hose_a->pci_mem_offset = K2_PCI32_MEM_BASE;
170 pci_init_resource(&hose_a->io_resource,
174 "PCI32 host bridge");
176 pci_init_resource(&hose_a->mem_resources[0],
177 K2_PCI32_LOWER_MEM + K2_PCI32_MEM_BASE,
178 K2_PCI32_UPPER_MEM + K2_PCI32_MEM_BASE,
180 "PCI32 host bridge");
182 hose_a->io_space.start = K2_PCI32_LOWER_IO;
183 hose_a->io_space.end = K2_PCI32_UPPER_IO;
184 hose_a->mem_space.start = K2_PCI32_LOWER_MEM;
185 hose_a->mem_space.end = K2_PCI32_UPPER_MEM;
186 hose_a->io_base_virt = (void *)K2_ISA_IO_BASE;
188 setup_indirect_pci(hose_a, K2_PCI32_CONFIG_ADDR, K2_PCI32_CONFIG_DATA);
190 /* Initialize PCI32 bus registers */
191 early_write_config_byte(hose_a,
195 hose_a->first_busno);
197 early_write_config_byte(hose_a,
200 CPC710_SUB_BUS_NUMBER,
203 /* Enable PCI interrupt polling */
204 early_write_config_byte(hose_a,
210 /* Route polled PCI interrupts */
211 early_write_config_byte(hose_a,
217 early_write_config_byte(hose_a,
223 early_write_config_byte(hose_a,
229 early_write_config_byte(hose_a,
235 /* route secondary IDE channel interrupt to IRQ 15 */
236 early_write_config_byte(hose_a,
242 /* enable IDE controller IDSEL */
243 early_write_config_byte(hose_a,
249 /* Enable IDE function */
250 early_write_config_byte(hose_a,
256 /* Set M5229 IDE controller to native mode */
257 early_write_config_byte(hose_a,
263 hose_a->last_busno = pciauto_bus_scan(hose_a, hose_a->first_busno);
265 /* Write out correct max subordinate bus number for hose A */
266 early_write_config_byte(hose_a,
269 CPC710_SUB_BUS_NUMBER,
272 /* Only setup PCI64 hose if we are in the system slot */
273 if (!(readb(K2_MISC_REG) & K2_SYS_SLOT_MASK))
275 /* Setup PCI64 hose */
276 hose_b = pcibios_alloc_controller();
280 hose_b->first_busno = hose_a->last_busno + 1;
281 hose_b->last_busno = 0xff;
283 /* Reminder: quit changing the following, it is correct. */
284 hose_b->pci_mem_offset = K2_PCI32_MEM_BASE;
286 pci_init_resource(&hose_b->io_resource,
290 "PCI64 host bridge");
292 pci_init_resource(&hose_b->mem_resources[0],
293 K2_PCI64_LOWER_MEM + K2_PCI32_MEM_BASE,
294 K2_PCI64_UPPER_MEM + K2_PCI32_MEM_BASE,
296 "PCI64 host bridge");
298 hose_b->io_space.start = K2_PCI64_LOWER_IO;
299 hose_b->io_space.end = K2_PCI64_UPPER_IO;
300 hose_b->mem_space.start = K2_PCI64_LOWER_MEM;
301 hose_b->mem_space.end = K2_PCI64_UPPER_MEM;
302 hose_b->io_base_virt = (void *)K2_ISA_IO_BASE;
304 setup_indirect_pci(hose_b,
305 K2_PCI64_CONFIG_ADDR,
306 K2_PCI64_CONFIG_DATA);
308 /* Initialize PCI64 bus registers */
309 early_write_config_byte(hose_b,
312 CPC710_SUB_BUS_NUMBER,
315 early_write_config_byte(hose_b,
319 hose_b->first_busno);
321 hose_b->last_busno = pciauto_bus_scan(hose_b,
322 hose_b->first_busno);
324 /* Write out correct max subordinate bus number for hose B */
325 early_write_config_byte(hose_b,
328 CPC710_SUB_BUS_NUMBER,
331 /* Configure PCI64 PSBAR */
332 early_write_config_dword(hose_b,
336 K2_PCI64_SYS_MEM_BASE);
339 /* Configure i8259 level/edge settings */
343 #ifdef CONFIG_CPC710_DATA_GATHERING
346 tmp = __raw_readl(ABCNTL);
347 /* Enable data gathering on both PCI interfaces */
348 __raw_writel(tmp | 0x05000000, ABCNTL);
352 ppc_md.pcibios_fixup = k2_pcibios_fixup;
353 ppc_md.pci_swizzle = common_swizzle;
354 ppc_md.pci_map_irq = k2_map_irq;