2 * Copyright (C) Michel Dänzer <michdaen@iiic.ethz.ch>
6 * Currently, only B/CVisionPPC cards (Permedia2) are supported.
8 * Thanks to Geert Uytterhoeven for the idea:
9 * Read values from given config space(s) for the first devices, -1 otherwise
15 #include <linux/kernel.h>
16 #include <linux/pci.h>
17 #include <linux/delay.h>
18 #include <linux/string.h>
19 #include <linux/init.h>
22 #include <asm/pci-bridge.h>
23 #include <asm/machdep.h>
28 /* These definitions are mostly adapted from pm2fb.c */
30 #undef APUS_PCI_MASTER_DEBUG
31 #ifdef APUS_PCI_MASTER_DEBUG
32 #define DPRINTK(a,b...) printk(KERN_DEBUG "apus_pci: %s: " a, __FUNCTION__ , ## b)
34 #define DPRINTK(a,b...)
38 * The _DEFINITIVE_ memory mapping/unmapping functions.
39 * This is due to the fact that they're changing soooo often...
45 #define DEVNO(d) ((d)>>3)
46 #define FNNO(d) ((d)&7)
49 extern unsigned long powerup_PCI_present
;
51 static struct pci_controller
*apus_hose
;
54 void *pci_io_base(unsigned int bus
)
61 apus_pcibios_read_config(struct pci_bus
*bus
, int devfn
, int offset
,
64 int fnno
= FNNO(devfn
);
65 int devno
= DEVNO(devfn
);
66 volatile unsigned char *cfg_data
;
68 if (bus
->number
> 0 || devno
!= 1) {
70 return PCIBIOS_DEVICE_NOT_FOUND
;
72 /* base address + function offset + offset ^ endianness conversion */
73 /* XXX the fnno<<5 bit seems wacky -- paulus */
74 cfg_data
= apus_hose
->cfg_data
+ (fnno
<<5) + (offset
^ (len
- 1));
77 *val
= readb(cfg_data
);
80 *val
= readw(cfg_data
);
83 *val
= readl(cfg_data
);
87 DPRINTK("read b: 0x%x, d: 0x%x, f: 0x%x, o: 0x%x, l: %d, v: 0x%x\n",
88 bus
->number
, devfn
>>3, devfn
&7, offset
, len
, *val
);
89 return PCIBIOS_SUCCESSFUL
;
93 apus_pcibios_write_config(struct pci_bus
*bus
, int devfn
, int offset
,
96 int fnno
= FNNO(devfn
);
97 int devno
= DEVNO(devfn
);
98 volatile unsigned char *cfg_data
;
100 if (bus
->number
> 0 || devno
!= 1) {
101 return PCIBIOS_DEVICE_NOT_FOUND
;
103 /* base address + function offset + offset ^ endianness conversion */
104 /* XXX the fnno<<5 bit seems wacky -- paulus */
105 cfg_data
= apus_hose
->cfg_data
+ (fnno
<<5) + (offset
^ (len
- 1));
108 writeb(val
, cfg_data
); DEFW();
111 writew(val
, cfg_data
); DEFW();
114 writel(val
, cfg_data
); DEFW();
118 DPRINTK("write b: 0x%x, d: 0x%x, f: 0x%x, o: 0x%x, l: %d, v: 0x%x\n",
119 bus
->number
, devfn
>>3, devfn
&7, offset
, len
, val
);
120 return PCIBIOS_SUCCESSFUL
;
123 static struct pci_ops apus_pci_ops
= {
124 apus_pcibios_read_config
,
125 apus_pcibios_write_config
128 static struct resource pci_mem
= { "B/CVisionPPC PCI mem", CVPPC_FB_APERTURE_ONE
, CVPPC_PCI_CONFIG
, IORESOURCE_MEM
};
131 apus_pcibios_fixup(void)
133 /* struct pci_dev *dev = pci_find_slot(0, 1<<3);
134 unsigned int reg, val, offset;*/
136 /* FIXME: interrupt? */
137 /*dev->interrupt = xxx;*/
139 request_resource(&iomem_resource
, &pci_mem
);
140 printk("%s: PCI mem resource requested\n", __FUNCTION__
);
143 static void __init
apus_pcibios_fixup_bus(struct pci_bus
*bus
)
145 bus
->resource
[1] = &pci_mem
;
150 * This is from pm2fb.c again
152 * Check if PCI (B/CVisionPPC) is available, initialize it and set up
153 * the pcibios_* pointers
158 apus_setup_pci_ptrs(void)
160 if (!powerup_PCI_present
) {
161 DPRINTK("no PCI bridge detected\n");
164 DPRINTK("Phase5 B/CVisionPPC PCI bridge detected.\n");
166 apus_hose
= pcibios_alloc_controller();
168 printk("apus_pci: Can't allocate PCI controller structure\n");
172 if (!(apus_hose
->cfg_data
= ioremap(CVPPC_PCI_CONFIG
, 256))) {
173 printk("apus_pci: unable to map PCI config region\n");
177 if (!(apus_hose
->cfg_addr
= ioremap(CSPPC_PCI_BRIDGE
, 256))) {
178 printk("apus_pci: unable to map PCI bridge\n");
182 writel(CSPPCF_BRIDGE_BIG_ENDIAN
, apus_hose
->cfg_addr
+ CSPPC_BRIDGE_ENDIAN
);
185 writel(CVPPC_REGS_REGION
, apus_hose
->cfg_data
+ PCI_BASE_ADDRESS_0
);
187 writel(CVPPC_FB_APERTURE_ONE
, apus_hose
->cfg_data
+ PCI_BASE_ADDRESS_1
);
189 writel(CVPPC_FB_APERTURE_TWO
, apus_hose
->cfg_data
+ PCI_BASE_ADDRESS_2
);
191 writel(CVPPC_ROM_ADDRESS
, apus_hose
->cfg_data
+ PCI_ROM_ADDRESS
);
194 writel(0xef000000 | PCI_COMMAND_IO
| PCI_COMMAND_MEMORY
|
195 PCI_COMMAND_MASTER
, apus_hose
->cfg_data
+ PCI_COMMAND
);
198 apus_hose
->first_busno
= 0;
199 apus_hose
->last_busno
= 0;
200 apus_hose
->ops
= &apus_pci_ops
;
201 ppc_md
.pcibios_fixup
= apus_pcibios_fixup
;
202 ppc_md
.pcibios_fixup_bus
= apus_pcibios_fixup_bus
;
207 #endif /* CONFIG_AMIGA */