diff mbox series

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

Message ID 20191030135347.3636-4-jiaxun.yang@flygoat.com
State Not Applicable
Headers show
Series PCI Devices for Loongson PCH | expand

Commit Message

Jiaxun Yang Oct. 30, 2019, 1:53 p.m. UTC
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(-)

Comments

Bjorn Helgaas Oct. 30, 2019, 8:36 p.m. UTC | #1
On Wed, Oct 30, 2019 at 09:53:45PM +0800, Jiaxun Yang wrote:
> This device will be setup by parsing DeviceTree node
> of pci device.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>

> +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) {

Please pay attention to the existing coding style in the file and
follow it.  In this and other cases below, add a space in "if (".

> +	if(!of_device_is_compatible(np, "loongson,pci-gmac")) {

> +	return  stmmac_parse_config_dt(np, plat);

Remove the double space here.

> +	if(info->of_irq) {

> +	STMMAC_DEVICE(LOONGSON,  PCI_DEVICE_ID_LOONGSON_GMAC, loongson_of_pci_info),

And here.
diff mbox series

Patch

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),
 	{}
 };