diff options
Diffstat (limited to 'arch/ppc/syslib/m82xx_pci.c')
-rw-r--r-- | arch/ppc/syslib/m82xx_pci.c | 383 |
1 files changed, 383 insertions, 0 deletions
diff --git a/arch/ppc/syslib/m82xx_pci.c b/arch/ppc/syslib/m82xx_pci.c new file mode 100644 index 000000000000..5e7a7edcea74 --- /dev/null +++ b/arch/ppc/syslib/m82xx_pci.c | |||
@@ -0,0 +1,383 @@ | |||
1 | /* | ||
2 | * | ||
3 | * (C) Copyright 2003 | ||
4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. | ||
5 | * | ||
6 | * (C) Copyright 2004 Red Hat, Inc. | ||
7 | * | ||
8 | * 2005 (c) MontaVista Software, Inc. | ||
9 | * Vitaly Bordug <vbordug@ru.mvista.com> | ||
10 | * | ||
11 | * See file CREDITS for list of people who contributed to this | ||
12 | * project. | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License as | ||
16 | * published by the Free Software Foundation; either version 2 of | ||
17 | * the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This program is distributed in the hope that it will be useful, | ||
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
22 | * GNU General Public License for more details. | ||
23 | * | ||
24 | * You should have received a copy of the GNU General Public License | ||
25 | * along with this program; if not, write to the Free Software | ||
26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, | ||
27 | * MA 02111-1307 USA | ||
28 | */ | ||
29 | |||
30 | #include <linux/kernel.h> | ||
31 | #include <linux/init.h> | ||
32 | #include <linux/pci.h> | ||
33 | #include <linux/slab.h> | ||
34 | #include <linux/delay.h> | ||
35 | #include <linux/irq.h> | ||
36 | #include <linux/interrupt.h> | ||
37 | |||
38 | #include <asm/byteorder.h> | ||
39 | #include <asm/io.h> | ||
40 | #include <asm/irq.h> | ||
41 | #include <asm/uaccess.h> | ||
42 | #include <asm/machdep.h> | ||
43 | #include <asm/pci-bridge.h> | ||
44 | #include <asm/immap_cpm2.h> | ||
45 | #include <asm/mpc8260.h> | ||
46 | #include <asm/cpm2.h> | ||
47 | |||
48 | #include "m82xx_pci.h" | ||
49 | |||
50 | /* | ||
51 | * Interrupt routing | ||
52 | */ | ||
53 | |||
54 | static inline int | ||
55 | pq2pci_map_irq(struct pci_dev *dev, unsigned char idsel, unsigned char pin) | ||
56 | { | ||
57 | static char pci_irq_table[][4] = | ||
58 | /* | ||
59 | * PCI IDSEL/INTPIN->INTLINE | ||
60 | * A B C D | ||
61 | */ | ||
62 | { | ||
63 | { PIRQA, PIRQB, PIRQC, PIRQD }, /* IDSEL 22 - PCI slot 0 */ | ||
64 | { PIRQD, PIRQA, PIRQB, PIRQC }, /* IDSEL 23 - PCI slot 1 */ | ||
65 | { PIRQC, PIRQD, PIRQA, PIRQB }, /* IDSEL 24 - PCI slot 2 */ | ||
66 | }; | ||
67 | |||
68 | const long min_idsel = 22, max_idsel = 24, irqs_per_slot = 4; | ||
69 | return PCI_IRQ_TABLE_LOOKUP; | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | pq2pci_mask_irq(unsigned int irq) | ||
74 | { | ||
75 | int bit = irq - NR_CPM_INTS; | ||
76 | |||
77 | *(volatile unsigned long *) PCI_INT_MASK_REG |= (1 << (31 - bit)); | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | static void | ||
82 | pq2pci_unmask_irq(unsigned int irq) | ||
83 | { | ||
84 | int bit = irq - NR_CPM_INTS; | ||
85 | |||
86 | *(volatile unsigned long *) PCI_INT_MASK_REG &= ~(1 << (31 - bit)); | ||
87 | return; | ||
88 | } | ||
89 | |||
90 | static void | ||
91 | pq2pci_mask_and_ack(unsigned int irq) | ||
92 | { | ||
93 | int bit = irq - NR_CPM_INTS; | ||
94 | |||
95 | *(volatile unsigned long *) PCI_INT_MASK_REG |= (1 << (31 - bit)); | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | static void | ||
100 | pq2pci_end_irq(unsigned int irq) | ||
101 | { | ||
102 | int bit = irq - NR_CPM_INTS; | ||
103 | |||
104 | *(volatile unsigned long *) PCI_INT_MASK_REG &= ~(1 << (31 - bit)); | ||
105 | return; | ||
106 | } | ||
107 | |||
108 | struct hw_interrupt_type pq2pci_ic = { | ||
109 | "PQ2 PCI", | ||
110 | NULL, | ||
111 | NULL, | ||
112 | pq2pci_unmask_irq, | ||
113 | pq2pci_mask_irq, | ||
114 | pq2pci_mask_and_ack, | ||
115 | pq2pci_end_irq, | ||
116 | 0 | ||
117 | }; | ||
118 | |||
119 | static irqreturn_t | ||
120 | pq2pci_irq_demux(int irq, void *dev_id, struct pt_regs *regs) | ||
121 | { | ||
122 | unsigned long stat, mask, pend; | ||
123 | int bit; | ||
124 | |||
125 | for(;;) { | ||
126 | stat = *(volatile unsigned long *) PCI_INT_STAT_REG; | ||
127 | mask = *(volatile unsigned long *) PCI_INT_MASK_REG; | ||
128 | pend = stat & ~mask & 0xf0000000; | ||
129 | if (!pend) | ||
130 | break; | ||
131 | for (bit = 0; pend != 0; ++bit, pend <<= 1) { | ||
132 | if (pend & 0x80000000) | ||
133 | __do_IRQ(NR_CPM_INTS + bit, regs); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | return IRQ_HANDLED; | ||
138 | } | ||
139 | |||
140 | static struct irqaction pq2pci_irqaction = { | ||
141 | .handler = pq2pci_irq_demux, | ||
142 | .flags = SA_INTERRUPT, | ||
143 | .mask = CPU_MASK_NONE, | ||
144 | .name = "PQ2 PCI cascade", | ||
145 | }; | ||
146 | |||
147 | |||
148 | void | ||
149 | pq2pci_init_irq(void) | ||
150 | { | ||
151 | int irq; | ||
152 | volatile cpm2_map_t *immap = cpm2_immr; | ||
153 | #if defined CONFIG_ADS8272 | ||
154 | /* configure chip select for PCI interrupt controller */ | ||
155 | immap->im_memctl.memc_br3 = PCI_INT_STAT_REG | 0x00001801; | ||
156 | immap->im_memctl.memc_or3 = 0xffff8010; | ||
157 | #elif defined CONFIG_PQ2FADS | ||
158 | immap->im_memctl.memc_br8 = PCI_INT_STAT_REG | 0x00001801; | ||
159 | immap->im_memctl.memc_or8 = 0xffff8010; | ||
160 | #endif | ||
161 | for (irq = NR_CPM_INTS; irq < NR_CPM_INTS + 4; irq++) | ||
162 | irq_desc[irq].handler = &pq2pci_ic; | ||
163 | |||
164 | /* make PCI IRQ level sensitive */ | ||
165 | immap->im_intctl.ic_siexr &= | ||
166 | ~(1 << (14 - (PCI_INT_TO_SIU - SIU_INT_IRQ1))); | ||
167 | |||
168 | /* mask all PCI interrupts */ | ||
169 | *(volatile unsigned long *) PCI_INT_MASK_REG |= 0xfff00000; | ||
170 | |||
171 | /* install the demultiplexer for the PCI cascade interrupt */ | ||
172 | setup_irq(PCI_INT_TO_SIU, &pq2pci_irqaction); | ||
173 | return; | ||
174 | } | ||
175 | |||
176 | static int | ||
177 | pq2pci_exclude_device(u_char bus, u_char devfn) | ||
178 | { | ||
179 | return PCIBIOS_SUCCESSFUL; | ||
180 | } | ||
181 | |||
182 | /* PCI bus configuration registers. | ||
183 | */ | ||
184 | static void | ||
185 | pq2ads_setup_pci(struct pci_controller *hose) | ||
186 | { | ||
187 | __u32 val; | ||
188 | volatile cpm2_map_t *immap = cpm2_immr; | ||
189 | bd_t* binfo = (bd_t*) __res; | ||
190 | u32 sccr = immap->im_clkrst.car_sccr; | ||
191 | uint pci_div,freq,time; | ||
192 | /* PCI int lowest prio */ | ||
193 | /* Each 4 bits is a device bus request and the MS 4bits | ||
194 | is highest priority */ | ||
195 | /* Bus 4bit value | ||
196 | --- ---------- | ||
197 | CPM high 0b0000 | ||
198 | CPM middle 0b0001 | ||
199 | CPM low 0b0010 | ||
200 | PCI reguest 0b0011 | ||
201 | Reserved 0b0100 | ||
202 | Reserved 0b0101 | ||
203 | Internal Core 0b0110 | ||
204 | External Master 1 0b0111 | ||
205 | External Master 2 0b1000 | ||
206 | External Master 3 0b1001 | ||
207 | The rest are reserved | ||
208 | */ | ||
209 | immap->im_siu_conf.siu_82xx.sc_ppc_alrh = 0x61207893; | ||
210 | /* park bus on core */ | ||
211 | immap->im_siu_conf.siu_82xx.sc_ppc_acr = PPC_ACR_BUS_PARK_CORE; | ||
212 | /* | ||
213 | * Set up master windows that allow the CPU to access PCI space. These | ||
214 | * windows are set up using the two SIU PCIBR registers. | ||
215 | */ | ||
216 | |||
217 | immap->im_memctl.memc_pcimsk0 = M82xx_PCI_PRIM_WND_SIZE; | ||
218 | immap->im_memctl.memc_pcibr0 = M82xx_PCI_PRIM_WND_BASE | PCIBR_ENABLE; | ||
219 | |||
220 | #ifdef M82xx_PCI_SEC_WND_SIZE | ||
221 | immap->im_memctl.memc_pcimsk1 = M82xx_PCI_SEC_WND_SIZE; | ||
222 | immap->im_memctl.memc_pcibr1 = M82xx_PCI_SEC_WND_BASE | PCIBR_ENABLE; | ||
223 | #endif | ||
224 | |||
225 | #if defined CONFIG_ADS8272 | ||
226 | immap->im_siu_conf.siu_82xx.sc_siumcr = | ||
227 | (immap->im_siu_conf.siu_82xx.sc_siumcr & | ||
228 | ~(SIUMCR_BBD | SIUMCR_ESE | SIUMCR_PBSE | | ||
229 | SIUMCR_CDIS | SIUMCR_DPPC11 | SIUMCR_L2CPC11 | | ||
230 | SIUMCR_LBPC11 | SIUMCR_APPC11 | | ||
231 | SIUMCR_CS10PC11 | SIUMCR_BCTLC11 | SIUMCR_MMR11)) | | ||
232 | SIUMCR_DPPC11 | SIUMCR_L2CPC01 | SIUMCR_LBPC00 | | ||
233 | SIUMCR_APPC10 | SIUMCR_CS10PC00 | | ||
234 | SIUMCR_BCTLC00 | SIUMCR_MMR11 ; | ||
235 | |||
236 | #elif defined CONFIG_PQ2FADS | ||
237 | /* | ||
238 | * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]), | ||
239 | * and local bus for PCI (SIUMCR [LBPC]). | ||
240 | */ | ||
241 | immap->im_siu_conf.siu_82xx.sc_siumcr = (immap->im_siu_conf.sc_siumcr & | ||
242 | ~(SIUMCR_L2PC11 | SIUMCR_LBPC11 | SIUMCR_CS10PC11 | SIUMCR_APPC11) | | ||
243 | SIUMCR_BBD | SIUMCR_LBPC01 | SIUMCR_DPPC11 | SIUMCR_APPC10; | ||
244 | #endif | ||
245 | /* Enable PCI */ | ||
246 | immap->im_pci.pci_gcr = cpu_to_le32(PCIGCR_PCI_BUS_EN); | ||
247 | |||
248 | pci_div = ( (sccr & SCCR_PCI_MODCK) ? 2 : 1) * | ||
249 | ( ( (sccr & SCCR_PCIDF_MSK) >> SCCR_PCIDF_SHIFT) + 1); | ||
250 | freq = (uint)((2*binfo->bi_cpmfreq)/(pci_div)); | ||
251 | time = (int)666666/freq; | ||
252 | /* due to PCI Local Bus spec, some devices needs to wait such a long | ||
253 | time after RST deassertion. More specifically, 0.508s for 66MHz & twice more for 33 */ | ||
254 | printk("%s: The PCI bus is %d Mhz.\nWaiting %s after deasserting RST...\n",__FILE__,freq, | ||
255 | (time==1) ? "0.5 seconds":"1 second" ); | ||
256 | |||
257 | { | ||
258 | int i; | ||
259 | for(i=0;i<(500*time);i++) | ||
260 | udelay(1000); | ||
261 | } | ||
262 | |||
263 | /* setup ATU registers */ | ||
264 | immap->im_pci.pci_pocmr0 = cpu_to_le32(POCMR_ENABLE | POCMR_PCI_IO | | ||
265 | ((~(M82xx_PCI_IO_SIZE - 1U)) >> POTA_ADDR_SHIFT)); | ||
266 | immap->im_pci.pci_potar0 = cpu_to_le32(M82xx_PCI_LOWER_IO >> POTA_ADDR_SHIFT); | ||
267 | immap->im_pci.pci_pobar0 = cpu_to_le32(M82xx_PCI_IO_BASE >> POTA_ADDR_SHIFT); | ||
268 | |||
269 | /* Set-up non-prefetchable window */ | ||
270 | immap->im_pci.pci_pocmr1 = cpu_to_le32(POCMR_ENABLE | ((~(M82xx_PCI_MMIO_SIZE-1U)) >> POTA_ADDR_SHIFT)); | ||
271 | immap->im_pci.pci_potar1 = cpu_to_le32(M82xx_PCI_LOWER_MMIO >> POTA_ADDR_SHIFT); | ||
272 | immap->im_pci.pci_pobar1 = cpu_to_le32((M82xx_PCI_LOWER_MMIO - M82xx_PCI_MMIO_OFFSET) >> POTA_ADDR_SHIFT); | ||
273 | |||
274 | /* Set-up prefetchable window */ | ||
275 | immap->im_pci.pci_pocmr2 = cpu_to_le32(POCMR_ENABLE |POCMR_PREFETCH_EN | | ||
276 | (~(M82xx_PCI_MEM_SIZE-1U) >> POTA_ADDR_SHIFT)); | ||
277 | immap->im_pci.pci_potar2 = cpu_to_le32(M82xx_PCI_LOWER_MEM >> POTA_ADDR_SHIFT); | ||
278 | immap->im_pci.pci_pobar2 = cpu_to_le32((M82xx_PCI_LOWER_MEM - M82xx_PCI_MEM_OFFSET) >> POTA_ADDR_SHIFT); | ||
279 | |||
280 | /* Inbound transactions from PCI memory space */ | ||
281 | immap->im_pci.pci_picmr0 = cpu_to_le32(PICMR_ENABLE | PICMR_PREFETCH_EN | | ||
282 | ((~(M82xx_PCI_SLAVE_MEM_SIZE-1U)) >> PITA_ADDR_SHIFT)); | ||
283 | immap->im_pci.pci_pibar0 = cpu_to_le32(M82xx_PCI_SLAVE_MEM_BUS >> PITA_ADDR_SHIFT); | ||
284 | immap->im_pci.pci_pitar0 = cpu_to_le32(M82xx_PCI_SLAVE_MEM_LOCAL>> PITA_ADDR_SHIFT); | ||
285 | |||
286 | #if defined CONFIG_ADS8272 | ||
287 | /* PCI int highest prio */ | ||
288 | immap->im_siu_conf.siu_82xx.sc_ppc_alrh = 0x01236745; | ||
289 | #elif defined CONFIG_PQ2FADS | ||
290 | immap->im_siu_conf.siu_82xx.sc_ppc_alrh = 0x03124567; | ||
291 | #endif | ||
292 | /* park bus on PCI */ | ||
293 | immap->im_siu_conf.siu_82xx.sc_ppc_acr = PPC_ACR_BUS_PARK_PCI; | ||
294 | |||
295 | /* Enable bus mastering and inbound memory transactions */ | ||
296 | early_read_config_dword(hose, hose->first_busno, 0, PCI_COMMAND, &val); | ||
297 | val &= 0xffff0000; | ||
298 | val |= PCI_COMMAND_MEMORY|PCI_COMMAND_MASTER; | ||
299 | early_write_config_dword(hose, hose->first_busno, 0, PCI_COMMAND, val); | ||
300 | |||
301 | } | ||
302 | |||
303 | void __init pq2_find_bridges(void) | ||
304 | { | ||
305 | extern int pci_assign_all_busses; | ||
306 | struct pci_controller * hose; | ||
307 | int host_bridge; | ||
308 | |||
309 | pci_assign_all_busses = 1; | ||
310 | |||
311 | hose = pcibios_alloc_controller(); | ||
312 | |||
313 | if (!hose) | ||
314 | return; | ||
315 | |||
316 | ppc_md.pci_swizzle = common_swizzle; | ||
317 | |||
318 | hose->first_busno = 0; | ||
319 | hose->bus_offset = 0; | ||
320 | hose->last_busno = 0xff; | ||
321 | |||
322 | #ifdef CONFIG_ADS8272 | ||
323 | hose->set_cfg_type = 1; | ||
324 | #endif | ||
325 | |||
326 | setup_m8260_indirect_pci(hose, | ||
327 | (unsigned long)&cpm2_immr->im_pci.pci_cfg_addr, | ||
328 | (unsigned long)&cpm2_immr->im_pci.pci_cfg_data); | ||
329 | |||
330 | /* Make sure it is a supported bridge */ | ||
331 | early_read_config_dword(hose, | ||
332 | 0, | ||
333 | PCI_DEVFN(0,0), | ||
334 | PCI_VENDOR_ID, | ||
335 | &host_bridge); | ||
336 | switch (host_bridge) { | ||
337 | case PCI_DEVICE_ID_MPC8265: | ||
338 | break; | ||
339 | case PCI_DEVICE_ID_MPC8272: | ||
340 | break; | ||
341 | default: | ||
342 | printk("Attempting to use unrecognized host bridge ID" | ||
343 | " 0x%08x.\n", host_bridge); | ||
344 | break; | ||
345 | } | ||
346 | |||
347 | pq2ads_setup_pci(hose); | ||
348 | |||
349 | hose->io_space.start = M82xx_PCI_LOWER_IO; | ||
350 | hose->io_space.end = M82xx_PCI_UPPER_IO; | ||
351 | hose->mem_space.start = M82xx_PCI_LOWER_MEM; | ||
352 | hose->mem_space.end = M82xx_PCI_UPPER_MMIO; | ||
353 | hose->pci_mem_offset = M82xx_PCI_MEM_OFFSET; | ||
354 | |||
355 | isa_io_base = | ||
356 | (unsigned long) ioremap(M82xx_PCI_IO_BASE, | ||
357 | M82xx_PCI_IO_SIZE); | ||
358 | hose->io_base_virt = (void *) isa_io_base; | ||
359 | |||
360 | /* setup resources */ | ||
361 | pci_init_resource(&hose->mem_resources[0], | ||
362 | M82xx_PCI_LOWER_MEM, | ||
363 | M82xx_PCI_UPPER_MEM, | ||
364 | IORESOURCE_MEM|IORESOURCE_PREFETCH, "PCI prefetchable memory"); | ||
365 | |||
366 | pci_init_resource(&hose->mem_resources[1], | ||
367 | M82xx_PCI_LOWER_MMIO, | ||
368 | M82xx_PCI_UPPER_MMIO, | ||
369 | IORESOURCE_MEM, "PCI memory"); | ||
370 | |||
371 | pci_init_resource(&hose->io_resource, | ||
372 | M82xx_PCI_LOWER_IO, | ||
373 | M82xx_PCI_UPPER_IO, | ||
374 | IORESOURCE_IO | 1, "PCI I/O"); | ||
375 | |||
376 | ppc_md.pci_exclude_device = pq2pci_exclude_device; | ||
377 | hose->last_busno = pciauto_bus_scan(hose, hose->first_busno); | ||
378 | |||
379 | ppc_md.pci_map_irq = pq2pci_map_irq; | ||
380 | ppc_md.pcibios_fixup = NULL; | ||
381 | ppc_md.pcibios_fixup_bus = NULL; | ||
382 | |||
383 | } | ||