aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergio Paracuellos <sergio.paracuellos@gmail.com>2018-07-09 22:21:04 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-07-10 12:44:55 +0200
commit2427d174a476199111a20e74f76fda21296134f7 (patch)
treea5e875a9772c1ccb3a584c5d01c1ebd67d1d3923
parentfc4afdfea0428f8a564b62a6d668da95935b6cbf (diff)
downloadstaging-2427d174a476199111a20e74f76fda21296134f7.tar.gz
staging: mt7621-pci: factor out mt7621_pci_get_cfgaddr function
To get config address the same pattern is repeated in some functions along the code. Factor out a new mt7621_pci_get_cfgaddr for calculate it and use it in convenient places. Adjust types to match to u32 where is neccesary. Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/staging/mt7621-pci/pci-mt7621.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 89a57a02ae577..4f568401b37ec 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -177,19 +177,26 @@ static int pcie_link_status = 0;
#define PCI_ACCESS_WRITE_2 4
#define PCI_ACCESS_WRITE_4 5
+static inline u32 mt7621_pci_get_cfgaddr(unsigned int bus, unsigned int slot,
+ unsigned int func, unsigned int where)
+{
+ return (((where & 0xF00) >> 8) << 24) | (bus << 16) | (slot << 11) |
+ (func << 8) | (where & 0xfc) | 0x80000000;
+}
+
static int config_access(unsigned char access_type, struct pci_bus *bus,
unsigned int devfn, unsigned int where, u32 *data)
{
unsigned int slot = PCI_SLOT(devfn);
u8 func = PCI_FUNC(devfn);
- uint32_t address_reg, data_reg;
+ u32 address_reg, data_reg;
unsigned int address;
address_reg = RALINK_PCI_CONFIG_ADDR;
data_reg = RALINK_PCI_CONFIG_DATA_VIRTUAL_REG;
- address = (((where&0xF00)>>8)<<24) |(bus->number << 16) | (slot << 11) |
- (func << 8) | (where & 0xfc) | 0x80000000;
+ address = mt7621_pci_get_cfgaddr(bus->number, slot, func, where);
+
MV_WRITE(address_reg, address);
switch (access_type) {
@@ -305,11 +312,11 @@ static struct pci_controller mt7621_controller = {
static void
read_config(unsigned long bus, unsigned long dev, unsigned long func, unsigned long reg, unsigned long *val)
{
- unsigned int address_reg, data_reg, address;
+ u32 address_reg, data_reg, address;
address_reg = RALINK_PCI_CONFIG_ADDR;
data_reg = RALINK_PCI_CONFIG_DATA_VIRTUAL_REG;
- address = (((reg & 0xF00)>>8)<<24) | (bus << 16) | (dev << 11) | (func << 8) | (reg & 0xfc) | 0x80000000 ;
+ address = mt7621_pci_get_cfgaddr(bus, dev, func, reg);
MV_WRITE(address_reg, address);
MV_READ(data_reg, val);
return;
@@ -318,11 +325,11 @@ read_config(unsigned long bus, unsigned long dev, unsigned long func, unsigned l
static void
write_config(unsigned long bus, unsigned long dev, unsigned long func, unsigned long reg, unsigned long val)
{
- unsigned int address_reg, data_reg, address;
+ u32 address_reg, data_reg, address;
address_reg = RALINK_PCI_CONFIG_ADDR;
data_reg = RALINK_PCI_CONFIG_DATA_VIRTUAL_REG;
- address = (((reg & 0xF00)>>8)<<24) | (bus << 16) | (dev << 11) | (func << 8) | (reg & 0xfc) | 0x80000000 ;
+ address = mt7621_pci_get_cfgaddr(bus, dev, func, reg);
MV_WRITE(address_reg, address);
MV_WRITE(data_reg, val);
return;