Thread (15 messages) 15 messages, 6 authors, 2019-11-01
STALE2404d

[PATCH 3/5] net: stmmac: pci: Add Loongson GMAC

From: Jiaxun Yang <jiaxun.yang@flygoat.com>
Date: 2019-10-30 14:01:51
Also in: linux-devicetree, linux-ide, linux-mips, linux-pci
Subsystem: networking drivers, stmmac ethernet driver, the rest · Maintainers: Andrew Lunn, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

This device will be setup by parsing DeviceTree node
of pci device.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 .../net/ethernet/stmicro/stmmac/stmmac_pci.c  | 52 ++++++++++++++++++-
 1 file changed, 50 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
index 292045f4581f..640a2a5b8d41 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c
@@ -12,8 +12,11 @@
 #include <linux/clk-provider.h>
 #include <linux/pci.h>
 #include <linux/dmi.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
 
 #include "stmmac.h"
+#include "stmmac_platform.h"
 
 /*
  * This struct is used to associate PCI Function of MAC controller on a board,
@@ -33,6 +36,7 @@ struct stmmac_pci_dmi_data {
 
 struct stmmac_pci_info {
 	int (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);
+	bool of_irq;
 };
 
 static int stmmac_pci_find_phy_addr(struct pci_dev *pdev,
@@ -444,6 +448,30 @@ static const struct stmmac_pci_info snps_gmac5_pci_info = {
 	.setup = snps_gmac5_default_data,
 };
 
+static int loongson_pci_of_setup(struct pci_dev *pdev,
+			struct plat_stmmacenet_data *plat)
+{
+	struct device_node  *np;
+	np = pci_device_to_OF_node(pdev);
+
+	if(!np) {
+		dev_err(&pdev->dev, "Unable to get OF node\n");
+		return -ENODEV;
+	}
+
+	if(!of_device_is_compatible(np, "loongson,pci-gmac")) {
+		dev_err(&pdev->dev, "Device compatible mismatch\n");
+		return -ENODEV;
+	}
+
+	return  stmmac_parse_config_dt(np, plat);
+}
+
+static const struct stmmac_pci_info loongson_of_pci_info = {
+	.setup = loongson_pci_of_setup,
+	.of_irq = true,
+};
+
 /**
  * stmmac_pci_probe
  *
@@ -508,8 +536,27 @@ static int stmmac_pci_probe(struct pci_dev *pdev,
 
 	memset(&res, 0, sizeof(res));
 	res.addr = pcim_iomap_table(pdev)[i];
-	res.wol_irq = pdev->irq;
-	res.irq = pdev->irq;
+
+	if(info->of_irq) {
+		struct device_node  *np;	
+		np = pci_device_to_OF_node(pdev);
+
+		res.irq = of_irq_get_byname(np, "macirq");
+		if (res.irq < 0)
+			return res.irq;
+		res.wol_irq = of_irq_get_byname(np, "eth_wake_irq");
+		if (res.wol_irq < 0) {
+		if (res.wol_irq == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		res.wol_irq = res.irq;
+		}
+		res.lpi_irq = of_irq_get_byname(np, "eth_lpi");
+		if (res.lpi_irq == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+	} else {
+		res.wol_irq = pdev->irq;
+		res.irq = pdev->irq;
+	}
 
 	return stmmac_dvr_probe(&pdev->dev, plat, &res);
 }
@@ -602,6 +649,7 @@ static const struct pci_device_id stmmac_id_table[] = {
 	STMMAC_DEVICE(INTEL, STMMAC_EHL_SGMII1G_ID, ehl_sgmii1g_pci_info),
 	STMMAC_DEVICE(INTEL, STMMAC_TGL_SGMII1G_ID, tgl_sgmii1g_pci_info),
 	STMMAC_DEVICE(SYNOPSYS, STMMAC_GMAC5_ID, snps_gmac5_pci_info),
+	STMMAC_DEVICE(LOONGSON,  PCI_DEVICE_ID_LOONGSON_GMAC, loongson_of_pci_info),
 	{}
 };
 
-- 
2.23.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help