4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * (C) Copyright 2004 Red Hat, Inc.
8 * 2005 (c) MontaVista Software, Inc.
9 * Vitaly Bordug <vbordug@ru.mvista.com>
11 * See file CREDITS for list of people who contributed to this
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.
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.
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,
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>
38 #include <asm/byteorder.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>
48 #include "m82xx_pci.h"
55 pq2pci_map_irq(struct pci_dev
*dev
, unsigned char idsel
, unsigned char pin
)
57 static char pci_irq_table
[][4] =
59 * PCI IDSEL/INTPIN->INTLINE
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 */
68 const long min_idsel
= 22, max_idsel
= 24, irqs_per_slot
= 4;
69 return PCI_IRQ_TABLE_LOOKUP
;
73 pq2pci_mask_irq(unsigned int irq
)
75 int bit
= irq
- NR_CPM_INTS
;
77 *(volatile unsigned long *) PCI_INT_MASK_REG
|= (1 << (31 - bit
));
82 pq2pci_unmask_irq(unsigned int irq
)
84 int bit
= irq
- NR_CPM_INTS
;
86 *(volatile unsigned long *) PCI_INT_MASK_REG
&= ~(1 << (31 - bit
));
91 pq2pci_mask_and_ack(unsigned int irq
)
93 int bit
= irq
- NR_CPM_INTS
;
95 *(volatile unsigned long *) PCI_INT_MASK_REG
|= (1 << (31 - bit
));
100 pq2pci_end_irq(unsigned int irq
)
102 int bit
= irq
- NR_CPM_INTS
;
104 *(volatile unsigned long *) PCI_INT_MASK_REG
&= ~(1 << (31 - bit
));
108 struct hw_interrupt_type pq2pci_ic
= {
120 pq2pci_irq_demux(int irq
, void *dev_id
)
122 unsigned long stat
, mask
, pend
;
126 stat
= *(volatile unsigned long *) PCI_INT_STAT_REG
;
127 mask
= *(volatile unsigned long *) PCI_INT_MASK_REG
;
128 pend
= stat
& ~mask
& 0xf0000000;
131 for (bit
= 0; pend
!= 0; ++bit
, pend
<<= 1) {
132 if (pend
& 0x80000000)
133 __do_IRQ(NR_CPM_INTS
+ bit
);
140 static struct irqaction pq2pci_irqaction
= {
141 .handler
= pq2pci_irq_demux
,
142 .flags
= IRQF_DISABLED
,
143 .mask
= CPU_MASK_NONE
,
144 .name
= "PQ2 PCI cascade",
149 pq2pci_init_irq(void)
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;
161 for (irq
= NR_CPM_INTS
; irq
< NR_CPM_INTS
+ 4; irq
++)
162 irq_desc
[irq
].chip
= &pq2pci_ic
;
164 /* make PCI IRQ level sensitive */
165 immap
->im_intctl
.ic_siexr
&=
166 ~(1 << (14 - (PCI_INT_TO_SIU
- SIU_INT_IRQ1
)));
168 /* mask all PCI interrupts */
169 *(volatile unsigned long *) PCI_INT_MASK_REG
|= 0xfff00000;
171 /* install the demultiplexer for the PCI cascade interrupt */
172 setup_irq(PCI_INT_TO_SIU
, &pq2pci_irqaction
);
177 pq2pci_exclude_device(u_char bus
, u_char devfn
)
179 return PCIBIOS_SUCCESSFUL
;
182 /* PCI bus configuration registers.
185 pq2ads_setup_pci(struct pci_controller
*hose
)
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 */
204 External Master 1 0b0111
205 External Master 2 0b1000
206 External Master 3 0b1001
207 The rest are reserved
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
;
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.
217 immap
->im_memctl
.memc_pcimsk0
= M82xx_PCI_PRIM_WND_SIZE
;
218 immap
->im_memctl
.memc_pcibr0
= M82xx_PCI_PRIM_WND_BASE
| PCIBR_ENABLE
;
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
;
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
;
236 #elif defined CONFIG_PQ2FADS
238 * Setting required to enable IRQ1-IRQ7 (SIUMCR [DPPC]),
239 * and local bus for PCI (SIUMCR [LBPC]).
241 immap
->im_siu_conf
.siu_82xx
.sc_siumcr
= (immap
->im_siu_conf
.siu_82xx
.sc_siumcr
&
242 ~(SIUMCR_L2CPC11
| SIUMCR_LBPC11
| SIUMCR_CS10PC11
| SIUMCR_APPC11
) |
243 SIUMCR_BBD
| SIUMCR_LBPC01
| SIUMCR_DPPC11
| SIUMCR_APPC10
);
246 immap
->im_pci
.pci_gcr
= cpu_to_le32(PCIGCR_PCI_BUS_EN
);
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)66666666/freq
;
253 /* due to PCI Local Bus spec, some devices needs to wait such a long
254 time after RST deassertion. More specifically, 0.508s for 66MHz & twice more for 33 */
255 printk("%s: The PCI bus is %d Mhz.\nWaiting %s after deasserting RST...\n",__FILE__
,freq
,
256 (time
==1) ? "0.5 seconds":"1 second" );
260 for(i
=0;i
<(500*time
);i
++)
264 /* setup ATU registers */
265 immap
->im_pci
.pci_pocmr0
= cpu_to_le32(POCMR_ENABLE
| POCMR_PCI_IO
|
266 ((~(M82xx_PCI_IO_SIZE
- 1U)) >> POTA_ADDR_SHIFT
));
267 immap
->im_pci
.pci_potar0
= cpu_to_le32(M82xx_PCI_LOWER_IO
>> POTA_ADDR_SHIFT
);
268 immap
->im_pci
.pci_pobar0
= cpu_to_le32(M82xx_PCI_IO_BASE
>> POTA_ADDR_SHIFT
);
270 /* Set-up non-prefetchable window */
271 immap
->im_pci
.pci_pocmr1
= cpu_to_le32(POCMR_ENABLE
| ((~(M82xx_PCI_MMIO_SIZE
-1U)) >> POTA_ADDR_SHIFT
));
272 immap
->im_pci
.pci_potar1
= cpu_to_le32(M82xx_PCI_LOWER_MMIO
>> POTA_ADDR_SHIFT
);
273 immap
->im_pci
.pci_pobar1
= cpu_to_le32((M82xx_PCI_LOWER_MMIO
- M82xx_PCI_MMIO_OFFSET
) >> POTA_ADDR_SHIFT
);
275 /* Set-up prefetchable window */
276 immap
->im_pci
.pci_pocmr2
= cpu_to_le32(POCMR_ENABLE
|POCMR_PREFETCH_EN
|
277 (~(M82xx_PCI_MEM_SIZE
-1U) >> POTA_ADDR_SHIFT
));
278 immap
->im_pci
.pci_potar2
= cpu_to_le32(M82xx_PCI_LOWER_MEM
>> POTA_ADDR_SHIFT
);
279 immap
->im_pci
.pci_pobar2
= cpu_to_le32((M82xx_PCI_LOWER_MEM
- M82xx_PCI_MEM_OFFSET
) >> POTA_ADDR_SHIFT
);
281 /* Inbound transactions from PCI memory space */
282 immap
->im_pci
.pci_picmr0
= cpu_to_le32(PICMR_ENABLE
| PICMR_PREFETCH_EN
|
283 ((~(M82xx_PCI_SLAVE_MEM_SIZE
-1U)) >> PITA_ADDR_SHIFT
));
284 immap
->im_pci
.pci_pibar0
= cpu_to_le32(M82xx_PCI_SLAVE_MEM_BUS
>> PITA_ADDR_SHIFT
);
285 immap
->im_pci
.pci_pitar0
= cpu_to_le32(M82xx_PCI_SLAVE_MEM_LOCAL
>> PITA_ADDR_SHIFT
);
287 #if defined CONFIG_ADS8272
288 /* PCI int highest prio */
289 immap
->im_siu_conf
.siu_82xx
.sc_ppc_alrh
= 0x01236745;
290 #elif defined CONFIG_PQ2FADS
291 immap
->im_siu_conf
.siu_82xx
.sc_ppc_alrh
= 0x03124567;
293 /* park bus on PCI */
294 immap
->im_siu_conf
.siu_82xx
.sc_ppc_acr
= PPC_ACR_BUS_PARK_PCI
;
296 /* Enable bus mastering and inbound memory transactions */
297 early_read_config_dword(hose
, hose
->first_busno
, 0, PCI_COMMAND
, &val
);
299 val
|= PCI_COMMAND_MEMORY
|PCI_COMMAND_MASTER
;
300 early_write_config_dword(hose
, hose
->first_busno
, 0, PCI_COMMAND
, val
);
304 void __init
pq2_find_bridges(void)
306 extern int pci_assign_all_buses
;
307 struct pci_controller
* hose
;
310 pci_assign_all_buses
= 1;
312 hose
= pcibios_alloc_controller();
317 ppc_md
.pci_swizzle
= common_swizzle
;
319 hose
->first_busno
= 0;
320 hose
->bus_offset
= 0;
321 hose
->last_busno
= 0xff;
323 #ifdef CONFIG_ADS8272
324 hose
->set_cfg_type
= 1;
327 setup_m8260_indirect_pci(hose
,
328 (unsigned long)&cpm2_immr
->im_pci
.pci_cfg_addr
,
329 (unsigned long)&cpm2_immr
->im_pci
.pci_cfg_data
);
331 /* Make sure it is a supported bridge */
332 early_read_config_dword(hose
,
337 switch (host_bridge
) {
338 case PCI_DEVICE_ID_MPC8265
:
340 case PCI_DEVICE_ID_MPC8272
:
343 printk("Attempting to use unrecognized host bridge ID"
344 " 0x%08x.\n", host_bridge
);
348 pq2ads_setup_pci(hose
);
350 hose
->io_space
.start
= M82xx_PCI_LOWER_IO
;
351 hose
->io_space
.end
= M82xx_PCI_UPPER_IO
;
352 hose
->mem_space
.start
= M82xx_PCI_LOWER_MEM
;
353 hose
->mem_space
.end
= M82xx_PCI_UPPER_MMIO
;
354 hose
->pci_mem_offset
= M82xx_PCI_MEM_OFFSET
;
357 (unsigned long) ioremap(M82xx_PCI_IO_BASE
,
359 hose
->io_base_virt
= (void *) isa_io_base
;
361 /* setup resources */
362 pci_init_resource(&hose
->mem_resources
[0],
365 IORESOURCE_MEM
|IORESOURCE_PREFETCH
, "PCI prefetchable memory");
367 pci_init_resource(&hose
->mem_resources
[1],
368 M82xx_PCI_LOWER_MMIO
,
369 M82xx_PCI_UPPER_MMIO
,
370 IORESOURCE_MEM
, "PCI memory");
372 pci_init_resource(&hose
->io_resource
,
375 IORESOURCE_IO
| 1, "PCI I/O");
377 ppc_md
.pci_exclude_device
= pq2pci_exclude_device
;
378 hose
->last_busno
= pciauto_bus_scan(hose
, hose
->first_busno
);
380 ppc_md
.pci_map_irq
= pq2pci_map_irq
;
381 ppc_md
.pcibios_fixup
= NULL
;
382 ppc_md
.pcibios_fixup_bus
= NULL
;