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
13 #include <linux/config.h>
16 #include <linux/kernel.h>
17 #include <linux/pci.h>
18 #include <linux/delay.h>
19 #include <linux/string.h>
20 #include <linux/init.h>
23 #include <asm/pci-bridge.h>
24 #include <asm/machdep.h>
29 /* These definitions are mostly adapted from pm2fb.c */
31 #undef APUS_PCI_MASTER_DEBUG
32 #ifdef APUS_PCI_MASTER_DEBUG
33 #define DPRINTK(a,b...) printk(KERN_DEBUG "apus_pci: %s: " a, __FUNCTION__ , ## b)
35 #define DPRINTK(a,b...)
39 * The _DEFINITIVE_ memory mapping/unmapping functions.
40 * This is due to the fact that they're changing soooo often...
46 #define DEVNO(d) ((d)>>3)
47 #define FNNO(d) ((d)&7)
50 extern unsigned long powerup_PCI_present;
52 static struct pci_controller *apus_hose;
55 void *pci_io_base(unsigned int bus)
62 apus_pcibios_read_config(struct pci_bus *bus, int devfn, int offset,
65 int fnno = FNNO(devfn);
66 int devno = DEVNO(devfn);
67 volatile unsigned char *cfg_data;
69 if (bus->number > 0 || devno != 1) {
71 return PCIBIOS_DEVICE_NOT_FOUND;
73 /* base address + function offset + offset ^ endianness conversion */
74 /* XXX the fnno<<5 bit seems wacky -- paulus */
75 cfg_data = apus_hose->cfg_data + (fnno<<5) + (offset ^ (len - 1));
78 *val = readb(cfg_data);
81 *val = readw(cfg_data);
84 *val = readl(cfg_data);
88 DPRINTK("read b: 0x%x, d: 0x%x, f: 0x%x, o: 0x%x, l: %d, v: 0x%x\n",
89 bus->number, devfn>>3, devfn&7, offset, len, *val);
90 return PCIBIOS_SUCCESSFUL;
94 apus_pcibios_write_config(struct pci_bus *bus, int devfn, int offset,
97 int fnno = FNNO(devfn);
98 int devno = DEVNO(devfn);
99 volatile unsigned char *cfg_data;
101 if (bus->number > 0 || devno != 1) {
102 return PCIBIOS_DEVICE_NOT_FOUND;
104 /* base address + function offset + offset ^ endianness conversion */
105 /* XXX the fnno<<5 bit seems wacky -- paulus */
106 cfg_data = apus_hose->cfg_data + (fnno<<5) + (offset ^ (len - 1));
109 writeb(val, cfg_data); DEFW();
112 writew(val, cfg_data); DEFW();
115 writel(val, cfg_data); DEFW();
119 DPRINTK("write b: 0x%x, d: 0x%x, f: 0x%x, o: 0x%x, l: %d, v: 0x%x\n",
120 bus->number, devfn>>3, devfn&7, offset, len, val);
121 return PCIBIOS_SUCCESSFUL;
124 static struct pci_ops apus_pci_ops = {
125 apus_pcibios_read_config,
126 apus_pcibios_write_config
129 static struct resource pci_mem = { "B/CVisionPPC PCI mem", CVPPC_FB_APERTURE_ONE, CVPPC_PCI_CONFIG, IORESOURCE_MEM };
132 apus_pcibios_fixup(void)
134 /* struct pci_dev *dev = pci_find_slot(0, 1<<3);
135 unsigned int reg, val, offset;*/
137 /* FIXME: interrupt? */
138 /*dev->interrupt = xxx;*/
140 request_resource(&iomem_resource, &pci_mem);
141 printk("%s: PCI mem resource requested\n", __FUNCTION__);
144 static void __init apus_pcibios_fixup_bus(struct pci_bus *bus)
146 bus->resource[1] = &pci_mem;
151 * This is from pm2fb.c again
153 * Check if PCI (B/CVisionPPC) is available, initialize it and set up
154 * the pcibios_* pointers
159 apus_setup_pci_ptrs(void)
161 if (!powerup_PCI_present) {
162 DPRINTK("no PCI bridge detected\n");
165 DPRINTK("Phase5 B/CVisionPPC PCI bridge detected.\n");
167 apus_hose = pcibios_alloc_controller();
169 printk("apus_pci: Can't allocate PCI controller structure\n");
173 if (!(apus_hose->cfg_data = ioremap(CVPPC_PCI_CONFIG, 256))) {
174 printk("apus_pci: unable to map PCI config region\n");
178 if (!(apus_hose->cfg_addr = ioremap(CSPPC_PCI_BRIDGE, 256))) {
179 printk("apus_pci: unable to map PCI bridge\n");
183 writel(CSPPCF_BRIDGE_BIG_ENDIAN, apus_hose->cfg_addr + CSPPC_BRIDGE_ENDIAN);
186 writel(CVPPC_REGS_REGION, apus_hose->cfg_data+ PCI_BASE_ADDRESS_0);
188 writel(CVPPC_FB_APERTURE_ONE, apus_hose->cfg_data + PCI_BASE_ADDRESS_1);
190 writel(CVPPC_FB_APERTURE_TWO, apus_hose->cfg_data + PCI_BASE_ADDRESS_2);
192 writel(CVPPC_ROM_ADDRESS, apus_hose->cfg_data + PCI_ROM_ADDRESS);
195 writel(0xef000000 | PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
196 PCI_COMMAND_MASTER, apus_hose->cfg_data + PCI_COMMAND);
199 apus_hose->first_busno = 0;
200 apus_hose->last_busno = 0;
201 apus_hose->ops = &apus_pci_ops;
202 ppc_md.pcibios_fixup = apus_pcibios_fixup;
203 ppc_md.pcibios_fixup_bus = apus_pcibios_fixup_bus;
208 #endif /* CONFIG_AMIGA */