1 #include <linux/types.h>
3 #include <linux/kernel.h>
4 #include <linux/slab.h>
5 #include <linux/version.h>
8 #include <linux/init.h>
9 #include <linux/mod_devicetable.h>
10 #include <asm/mach-rt288x/rt288x.h>
11 #include <asm/mach-rt288x/rt288x_pci.h>
15 #define PCI_ACCESS_READ 0
16 #define PCI_ACCESS_WRITE 1
18 static int config_access(unsigned char access_type, struct pci_bus *bus,
19 unsigned int devfn, unsigned char where, u32 * data)
21 unsigned int slot = PCI_SLOT(devfn);
23 u8 func = PCI_FUNC(devfn);
24 address = (bus->number << 16) | (slot << 11) | (func << 8) | (where& 0xfc) | 0x80000000;
25 writel(address, RT2880_PCI_CONFIG_ADDR);
26 if (access_type == PCI_ACCESS_WRITE)
27 writel(*data, RT2880_PCI_CONFIG_DATA);
29 *data = readl(RT2880_PCI_CONFIG_DATA);
34 pci_config_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
37 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
38 return PCIBIOS_DEVICE_NOT_FOUND;
40 *val = (data >> ((where & 3) << 3)) & 0xff;
42 *val = (data >> ((where & 3) << 3)) & 0xffff;
45 return PCIBIOS_SUCCESSFUL;
49 pci_config_write(struct pci_bus *bus, unsigned int devfn,
50 int where, int size, u32 val)
57 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
58 return PCIBIOS_DEVICE_NOT_FOUND;
60 data = (data & ~(0xff << ((where & 3) << 3))) |
61 (val << ((where & 3) << 3));
63 data = (data & ~(0xffff << ((where & 3) << 3))) |
64 (val << ((where & 3) << 3));
66 if(config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
67 return PCIBIOS_DEVICE_NOT_FOUND;
68 return PCIBIOS_SUCCESSFUL;