1 #include <linux/types.h>
5 #include <asm/mach-ralink/rt288x.h>
6 #include <asm/mach-ralink/rt288x_pci.h>
8 #define PCI_ACCESS_READ 0
9 #define PCI_ACCESS_WRITE 1
11 static int config_access(unsigned char access_type
, struct pci_bus
*bus
,
12 unsigned int devfn
, unsigned char where
, u32
* data
)
14 unsigned int slot
= PCI_SLOT(devfn
);
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
);
22 *data
= readl(RT2880_PCI_CONFIG_DATA
);
27 pci_config_read(struct pci_bus
*bus
, unsigned int devfn
, int where
, int size
, u32
* val
)
30 if(config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
31 return PCIBIOS_DEVICE_NOT_FOUND
;
33 *val
= (data
>> ((where
& 3) << 3)) & 0xff;
35 *val
= (data
>> ((where
& 3) << 3)) & 0xffff;
38 return PCIBIOS_SUCCESSFUL
;
42 pci_config_write(struct pci_bus
*bus
, unsigned int devfn
,
43 int where
, int size
, u32 val
)
50 if(config_access(PCI_ACCESS_READ
, bus
, devfn
, where
, &data
))
51 return PCIBIOS_DEVICE_NOT_FOUND
;
53 data
= (data
& ~(0xff << ((where
& 3) << 3))) |
54 (val
<< ((where
& 3) << 3));
56 data
= (data
& ~(0xffff << ((where
& 3) << 3))) |
57 (val
<< ((where
& 3) << 3));
59 if(config_access(PCI_ACCESS_WRITE
, bus
, devfn
, where
, &data
))
60 return PCIBIOS_DEVICE_NOT_FOUND
;
61 return PCIBIOS_SUCCESSFUL
;