[PATCH v2 11/18] staging: mt7621-pci: factor out mt7621_pci_configure function

Sergio Paracuellos sergio.paracuellos at gmail.com
Sun Jul 8 12:57:19 UTC 2018


Factor out mt7621_pci_configure function to avoid a lot of
duplicated code in driver probe function.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos at gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 35 ++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index c41fc18..5d56f84 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -468,6 +468,18 @@ static void mt7621_pci_enable(u8 controller)
 	printk("PCIE%d enabled\n", controller);
 }
 
+static void mt7621_pci_configure(u8 controller)
+{
+	u32 val;
+
+	val = read_config(controller, 0x4);
+	write_config(controller, 0x4, (val | 0x4));
+	val = read_config(controller, 0x70c);
+	val &= ~(0xff) << 8;
+	val |= 0x50 << 8;
+	write_config(controller, 0x70c, val);
+}
+
 static int mt7621_pci_probe(struct platform_device *pdev)
 {
 	int i;
@@ -568,28 +580,15 @@ pcie(2/1/0) link status	pcie2_num	pcie1_num	pcie0_num
 
 	switch (pcie_link_status) {
 	case 7:
-		val = read_config(2, 0x4);
-		write_config(2, 0x4, (val | 0x4));
-		val = read_config(2, 0x70c);
-		val &= ~(0xff)<<8;
-		val |= 0x50<<8;
-		write_config(2, 0x70c, val);
+		mt7621_pci_configure(2);
+		break;
 	case 3:
 	case 5:
 	case 6:
-		val = read_config(1, 0x4);
-		write_config(1, 0x4, (val | 0x4));
-		val = read_config(1, 0x70c);
-		val &= ~(0xff)<<8;
-		val |= 0x50<<8;
-		write_config(1, 0x70c, val);
+		mt7621_pci_configure(1);
+		break;
 	default:
-		val = read_config(0, 0x4);
-		write_config(0, 0x4, (val | 0x4)); //bus master enable
-		val = read_config(0, 0x70c);
-		val &= ~(0xff)<<8;
-		val |= 0x50<<8;
-		write_config(0, 0x70c, val);
+		mt7621_pci_configure(0);
 	}
 
 	pci_load_of_ranges(&mt7621_controller, pdev->dev.of_node);
-- 
2.7.4



More information about the devel mailing list