ramips: remove unneccesary includes from the rt288x pci code
[librecmc/librecmc.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 #ifdef CONFIG_PCI
9
10 #define PCI_ACCESS_READ  0
11 #define PCI_ACCESS_WRITE 1
12
13 static int config_access(unsigned char access_type, struct pci_bus *bus,
14         unsigned int devfn, unsigned char where, u32 * data)
15 {
16         unsigned int slot = PCI_SLOT(devfn);
17         unsigned int address;
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);
23         else
24                 *data = readl(RT2880_PCI_CONFIG_DATA);
25         return 0;
26 }
27
28 int
29 pci_config_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
30 {
31         u32 data = 0;
32         if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
33                 return PCIBIOS_DEVICE_NOT_FOUND;
34         if(size == 1)
35                 *val = (data >> ((where & 3) << 3)) & 0xff;
36         else if(size == 2)
37                 *val = (data >> ((where & 3) << 3)) & 0xffff;
38         else
39                 *val = data;
40         return PCIBIOS_SUCCESSFUL;
41 }
42
43 int
44 pci_config_write(struct pci_bus *bus, unsigned int devfn,
45         int where, int size, u32 val)
46 {
47         u32 data = 0;
48         if(size == 4)
49         {
50                 data = val;
51         } else {
52                 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
53                         return PCIBIOS_DEVICE_NOT_FOUND;
54                 if(size == 1)
55                         data = (data & ~(0xff << ((where & 3) << 3))) |
56                                 (val << ((where & 3) << 3));
57                 else if(size == 2)
58                         data = (data & ~(0xffff << ((where & 3) << 3))) |
59                                 (val << ((where & 3) << 3));
60         }
61         if(config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
62                 return PCIBIOS_DEVICE_NOT_FOUND;
63         return PCIBIOS_SUCCESSFUL;
64 }
65 #endif