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