adds pci support for rt288x
[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/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 #include <asm/mach-rt288x/rt288x.h>
11 #include <asm/mach-rt288x/rt288x_pci.h>
12
13 #ifdef CONFIG_PCI
14
15 #define PCI_ACCESS_READ 0
16 #define PCI_ACCESS_WRITE 1
17
18 static int config_access(unsigned char access_type, struct pci_bus *bus,
19 unsigned int devfn, unsigned char where, u32 * data)
20 {
21 unsigned int slot = PCI_SLOT(devfn);
22 unsigned int address;
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);
28 else
29 *data = readl(RT2880_PCI_CONFIG_DATA);
30 return 0;
31 }
32
33 int
34 pci_config_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 * val)
35 {
36 u32 data = 0;
37 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
38 return PCIBIOS_DEVICE_NOT_FOUND;
39 if(size == 1)
40 *val = (data >> ((where & 3) << 3)) & 0xff;
41 else if(size == 2)
42 *val = (data >> ((where & 3) << 3)) & 0xffff;
43 else
44 *val = data;
45 return PCIBIOS_SUCCESSFUL;
46 }
47
48 int
49 pci_config_write(struct pci_bus *bus, unsigned int devfn,
50 int where, int size, u32 val)
51 {
52 u32 data = 0;
53 if(size == 4)
54 {
55 data = val;
56 } else {
57 if(config_access(PCI_ACCESS_READ, bus, devfn, where, &data))
58 return PCIBIOS_DEVICE_NOT_FOUND;
59 if(size == 1)
60 data = (data & ~(0xff << ((where & 3) << 3))) |
61 (val << ((where & 3) << 3));
62 else if(size == 2)
63 data = (data & ~(0xffff << ((where & 3) << 3))) |
64 (val << ((where & 3) << 3));
65 }
66 if(config_access(PCI_ACCESS_WRITE, bus, devfn, where, &data))
67 return PCIBIOS_DEVICE_NOT_FOUND;
68 return PCIBIOS_SUCCESSFUL;
69 }
70 #endif