1 #include <linux/types.h>
3 #include <linux/kernel.h>
4 #include <linux/slab.h>
5 #include <linux/version.h>
8 #include <linux/init.h>
9 #include <linux/mod_devicetable.h>
11 #include <asm/mach-ralink/rt288x.h>
12 #include <asm/mach-ralink/rt288x_pci.h>
16 #define PCI_ACCESS_READ 0
17 #define PCI_ACCESS_WRITE 1
19 static int config_access(unsigned char access_type
, struct pci_bus
*bus
,
20 unsigned int devfn
, unsigned char where
, u32
* data
)
22 unsigned int slot
= PCI_SLOT(devfn
);
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
);
30 *data
= readl(RT2880_PCI_CONFIG_DATA
);
35 pci_config_read(struct pci_bus
*bus
, unsigned int devfn
, int where
, int size
, u32
* val
)
38 if(config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
39 return PCIBIOS_DEVICE_NOT_FOUND
;
41 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
43 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
46 return PCIBIOS_SUCCESSFUL
;
50 pci_config_write(struct pci_bus
*bus
, unsigned int devfn
,
51 int where
, int size
, u32 val
)
58 if(config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
59 return PCIBIOS_DEVICE_NOT_FOUND
;
61 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
62 (val
<< ((where
& 3) << 3));
64 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
65 (val
<< ((where
& 3) << 3));
67 if(config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
68 return PCIBIOS_DEVICE_NOT_FOUND
;
69 return PCIBIOS_SUCCESSFUL
;