1 #include <linux/types.h>
5 #include <asm/mach-ralink/rt288x.h>
6 #include <asm/mach-ralink/rt288x_pci.h>
10 #define PCI_ACCESS_READ 0
11 #define PCI_ACCESS_WRITE 1
13 static int config_access(unsigned char access_type, struct pci_bus *bus,
14 unsigned int devfn, unsigned char where, u32 * data)
16 unsigned int slot = PCI_SLOT(devfn);
18 u8 func = PCI_FUNC(devfn);
19 address = (bus->number << 16) | (slot << 11) | (func << 8) | (where& 0xfc) | 0x80000000;
20 writel(address, RT2880_PCI_CONFIG_ADDR);
21 if (access_type == PCI_ACCESS_WRITE)
22 writel(*data, RT2880_PCI_CONFIG_DATA);
24 *data = readl(RT2880_PCI_CONFIG_DATA);
29 pci_config_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
32 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
33 return PCIBIOS_DEVICE_NOT_FOUND;
35 *val = (data >> ((where & 3) << 3)) & 0xff;
37 *val = (data >> ((where & 3) << 3)) & 0xffff;
40 return PCIBIOS_SUCCESSFUL;
44 pci_config_write(struct pci_bus *bus, unsigned int devfn,
45 int where, int size, u32 val)
52 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
53 return PCIBIOS_DEVICE_NOT_FOUND;
55 data = (data & ~(0xff << ((where & 3) << 3))) |
56 (val << ((where & 3) << 3));
58 data = (data & ~(0xffff << ((where & 3) << 3))) |
59 (val << ((where & 3) << 3));
61 if(config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
62 return PCIBIOS_DEVICE_NOT_FOUND;
63 return PCIBIOS_SUCCESSFUL;