ramips: remove unneccesary ifdefs from the rt288x pci code
[openwrt/svn-archive/archive.git] / target / linux / ramips / files / arch / mips / pci / ops-rt288x.c
1 #include <linux/types.h>
2 #include <linux/pci.h>
3 #include <linux/io.h>
4
5 #include <asm/mach-ralink/rt288x.h>
6 #include <asm/mach-ralink/rt288x_pci.h>
7
8 #define PCI_ACCESS_READ 0
9 #define PCI_ACCESS_WRITE 1
10
11 static int config_access(unsigned char access_type, struct pci_bus *bus,
12 unsigned int devfn, unsigned char where, u32 * data)
13 {
14 unsigned int slot = PCI_SLOT(devfn);
15 unsigned int address;
16 u8 func = PCI_FUNC(devfn);
17 address = (bus->number << 16) | (slot << 11) | (func << 8) | (where& 0xfc) | 0x80000000;
18 writel(address, RT2880_PCI_CONFIG_ADDR);
19 if (access_type == PCI_ACCESS_WRITE)
20 writel(*data, RT2880_PCI_CONFIG_DATA);
21 else
22 *data = readl(RT2880_PCI_CONFIG_DATA);
23 return 0;
24 }
25
26 int
27 pci_config_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
28 {
29 u32 data = 0;
30 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
31 return PCIBIOS_DEVICE_NOT_FOUND;
32 if(size == 1)
33 *val = (data >> ((where & 3) << 3)) & 0xff;
34 else if(size == 2)
35 *val = (data >> ((where & 3) << 3)) & 0xffff;
36 else
37 *val = data;
38 return PCIBIOS_SUCCESSFUL;
39 }
40
41 int
42 pci_config_write(struct pci_bus *bus, unsigned int devfn,
43 int where, int size, u32 val)
44 {
45 u32 data = 0;
46 if(size == 4)
47 {
48 data = val;
49 } else {
50 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
51 return PCIBIOS_DEVICE_NOT_FOUND;
52 if(size == 1)
53 data = (data & ~(0xff << ((where & 3) << 3))) |
54 (val << ((where & 3) << 3));
55 else if(size == 2)
56 data = (data & ~(0xffff << ((where & 3) << 3))) |
57 (val << ((where & 3) << 3));
58 }
59 if(config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
60 return PCIBIOS_DEVICE_NOT_FOUND;
61 return PCIBIOS_SUCCESSFUL;
62 }