All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC 0/2] stmmac: stand alone platform drivers
@ 2015-05-07 18:19 ` Joachim Eastwood
  0 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-07 18:19 UTC (permalink / raw)
  To: arnd; +Cc: peppe.cavallaro, netdev, davem, linux-arm-kernel, Joachim Eastwood

Hi Arnd,

I ran into some issue using a separate platform driver[1] for lpc1850-dwmac.

My dts files looks like this.
mac: ethernet@40010000 {
	compatible = "nxp,lpc1850-dwmac", "snps,dwmac-3.611", "snps,dwmac";
	...
}

On boot the generic driver in stmmac_platform.c would grab the
device, matching on one of generic compat strings and thus blocking
the lpc1850-dwmac driver.

By changing the build order in the Makefile (see patch 1) I managed
to get it working, but I am not sure that is a good solution(?).

Another fix would be to remove the generic compat strings from the
match table in stmmac_platform but there are some dts-files that
only have these compat strings.
See abilis_tb10x.dtsi and exynos5440.dtsi.

I could also remove the generic compat strings from my dts file but
I am not sure that is good solution either. If more glue is
converted this would then be need in those dts files also.


Any advice on how to handle this situation?


[1] http://marc.info/?l=linux-arm-kernel&m=143076781409270&w=2

Joachim Eastwood (2):
  stmac: support standalone platform drivers
  stmac: add dwmac glue for NXP 18xx/43xx family

 drivers/net/ethernet/stmicro/stmmac/Makefile       | 11 ++-
 .../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c    | 98 ++++++++++++++++++++++
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  | 14 ++--
 .../net/ethernet/stmicro/stmmac/stmmac_platform.h  |  4 +
 4 files changed, 120 insertions(+), 7 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c

-- 
1.8.0

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RFC 0/2] stmmac: stand alone platform drivers
@ 2015-05-07 18:19 ` Joachim Eastwood
  0 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-07 18:19 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Arnd,

I ran into some issue using a separate platform driver[1] for lpc1850-dwmac.

My dts files looks like this.
mac: ethernet at 40010000 {
	compatible = "nxp,lpc1850-dwmac", "snps,dwmac-3.611", "snps,dwmac";
	...
}

On boot the generic driver in stmmac_platform.c would grab the
device, matching on one of generic compat strings and thus blocking
the lpc1850-dwmac driver.

By changing the build order in the Makefile (see patch 1) I managed
to get it working, but I am not sure that is a good solution(?).

Another fix would be to remove the generic compat strings from the
match table in stmmac_platform but there are some dts-files that
only have these compat strings.
See abilis_tb10x.dtsi and exynos5440.dtsi.

I could also remove the generic compat strings from my dts file but
I am not sure that is good solution either. If more glue is
converted this would then be need in those dts files also.


Any advice on how to handle this situation?


[1] http://marc.info/?l=linux-arm-kernel&m=143076781409270&w=2

Joachim Eastwood (2):
  stmac: support standalone platform drivers
  stmac: add dwmac glue for NXP 18xx/43xx family

 drivers/net/ethernet/stmicro/stmmac/Makefile       | 11 ++-
 .../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c    | 98 ++++++++++++++++++++++
 .../net/ethernet/stmicro/stmmac/stmmac_platform.c  | 14 ++--
 .../net/ethernet/stmicro/stmmac/stmmac_platform.h  |  4 +
 4 files changed, 120 insertions(+), 7 deletions(-)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c

-- 
1.8.0

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RFC 1/2] stmac: support standalone platform drivers
  2015-05-07 18:19 ` Joachim Eastwood
@ 2015-05-07 18:19   ` Joachim Eastwood
  -1 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-07 18:19 UTC (permalink / raw)
  To: arnd; +Cc: peppe.cavallaro, netdev, davem, linux-arm-kernel, Joachim Eastwood

Prepare the stmmac platform code to support standalone drivers
by exporting the need functions and having of_match_device use
the match table reference already present in the driver struct.

Reorder the build order so that the most specific drivers are
built and registered first.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/Makefile          | 10 ++++++++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 14 +++++++++-----
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h |  4 ++++
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index 73c2715a27f3..f35e2bcde55f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -4,9 +4,15 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o	\
 	      dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o	\
 	      mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o $(stmmac-y)
 
+# ordering matters; keep stmmac_platform.o at the bottom
 obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
-stmmac-platform-objs:= stmmac_platform.o dwmac-meson.o dwmac-sunxi.o	\
-		       dwmac-sti.o dwmac-socfpga.o dwmac-rk.o
+stmmac-platform-objs:= \
+		dwmac-meson.o		\
+		dwmac-rk.o		\
+		dwmac-socfpga.o		\
+		dwmac-sti.o		\
+		dwmac-sunxi.o		\
+		stmmac_platform.o
 
 obj-$(CONFIG_STMMAC_PCI) += stmmac-pci.o
 stmmac-pci-objs:= stmmac_pci.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 705bbdf93940..3263d40e00a7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -128,11 +128,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
 	struct device_node *np = pdev->dev.of_node;
 	struct stmmac_dma_cfg *dma_cfg;
 	const struct of_device_id *device;
+	struct device *dev = &pdev->dev;
 
 	if (!np)
 		return -ENODEV;
 
-	device = of_match_device(stmmac_dt_ids, &pdev->dev);
+	device = of_match_device(dev->driver->of_match_table, dev);
 	if (!device)
 		return -ENODEV;
 
@@ -267,7 +268,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
  * the necessary platform resources, invoke custom helper (if required) and
  * invoke the main probe function.
  */
-static int stmmac_pltfr_probe(struct platform_device *pdev)
+int stmmac_pltfr_probe(struct platform_device *pdev)
 {
 	int ret = 0;
 	struct resource *res;
@@ -373,6 +374,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(stmmac_pltfr_probe);
 
 /**
  * stmmac_pltfr_remove
@@ -380,7 +382,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
  * Description: this function calls the main to free the net resources
  * and calls the platforms hook and release the resources (e.g. mem).
  */
-static int stmmac_pltfr_remove(struct platform_device *pdev)
+int stmmac_pltfr_remove(struct platform_device *pdev)
 {
 	struct net_device *ndev = platform_get_drvdata(pdev);
 	struct stmmac_priv *priv = netdev_priv(ndev);
@@ -394,6 +396,7 @@ static int stmmac_pltfr_remove(struct platform_device *pdev)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(stmmac_pltfr_remove);
 
 #ifdef CONFIG_PM_SLEEP
 /**
@@ -437,8 +440,9 @@ static int stmmac_pltfr_resume(struct device *dev)
 }
 #endif /* CONFIG_PM_SLEEP */
 
-static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops,
-			 stmmac_pltfr_suspend, stmmac_pltfr_resume);
+SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, stmmac_pltfr_suspend,
+				       stmmac_pltfr_resume);
+EXPORT_SYMBOL_GPL(stmmac_pltfr_pm_ops);
 
 static struct platform_driver stmmac_pltfr_driver = {
 	.probe = stmmac_pltfr_probe,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
index 093eb99e5ffd..23d10f6e8846 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
@@ -19,6 +19,10 @@
 #ifndef __STMMAC_PLATFORM_H__
 #define __STMMAC_PLATFORM_H__
 
+int stmmac_pltfr_probe(struct platform_device *pdev);
+int stmmac_pltfr_remove(struct platform_device *pdev);
+extern const struct dev_pm_ops stmmac_pltfr_pm_ops;
+
 extern const struct stmmac_of_data meson6_dwmac_data;
 extern const struct stmmac_of_data sun7i_gmac_data;
 extern const struct stmmac_of_data stih4xx_dwmac_data;
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH RFC 1/2] stmac: support standalone platform drivers
@ 2015-05-07 18:19   ` Joachim Eastwood
  0 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-07 18:19 UTC (permalink / raw)
  To: linux-arm-kernel

Prepare the stmmac platform code to support standalone drivers
by exporting the need functions and having of_match_device use
the match table reference already present in the driver struct.

Reorder the build order so that the most specific drivers are
built and registered first.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/Makefile          | 10 ++++++++--
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 14 +++++++++-----
 drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h |  4 ++++
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index 73c2715a27f3..f35e2bcde55f 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -4,9 +4,15 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o	\
 	      dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o	\
 	      mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o $(stmmac-y)
 
+# ordering matters; keep stmmac_platform.o at the bottom
 obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
-stmmac-platform-objs:= stmmac_platform.o dwmac-meson.o dwmac-sunxi.o	\
-		       dwmac-sti.o dwmac-socfpga.o dwmac-rk.o
+stmmac-platform-objs:= \
+		dwmac-meson.o		\
+		dwmac-rk.o		\
+		dwmac-socfpga.o		\
+		dwmac-sti.o		\
+		dwmac-sunxi.o		\
+		stmmac_platform.o
 
 obj-$(CONFIG_STMMAC_PCI) += stmmac-pci.o
 stmmac-pci-objs:= stmmac_pci.o
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 705bbdf93940..3263d40e00a7 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -128,11 +128,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
 	struct device_node *np = pdev->dev.of_node;
 	struct stmmac_dma_cfg *dma_cfg;
 	const struct of_device_id *device;
+	struct device *dev = &pdev->dev;
 
 	if (!np)
 		return -ENODEV;
 
-	device = of_match_device(stmmac_dt_ids, &pdev->dev);
+	device = of_match_device(dev->driver->of_match_table, dev);
 	if (!device)
 		return -ENODEV;
 
@@ -267,7 +268,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
  * the necessary platform resources, invoke custom helper (if required) and
  * invoke the main probe function.
  */
-static int stmmac_pltfr_probe(struct platform_device *pdev)
+int stmmac_pltfr_probe(struct platform_device *pdev)
 {
 	int ret = 0;
 	struct resource *res;
@@ -373,6 +374,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(stmmac_pltfr_probe);
 
 /**
  * stmmac_pltfr_remove
@@ -380,7 +382,7 @@ static int stmmac_pltfr_probe(struct platform_device *pdev)
  * Description: this function calls the main to free the net resources
  * and calls the platforms hook and release the resources (e.g. mem).
  */
-static int stmmac_pltfr_remove(struct platform_device *pdev)
+int stmmac_pltfr_remove(struct platform_device *pdev)
 {
 	struct net_device *ndev = platform_get_drvdata(pdev);
 	struct stmmac_priv *priv = netdev_priv(ndev);
@@ -394,6 +396,7 @@ static int stmmac_pltfr_remove(struct platform_device *pdev)
 
 	return ret;
 }
+EXPORT_SYMBOL_GPL(stmmac_pltfr_remove);
 
 #ifdef CONFIG_PM_SLEEP
 /**
@@ -437,8 +440,9 @@ static int stmmac_pltfr_resume(struct device *dev)
 }
 #endif /* CONFIG_PM_SLEEP */
 
-static SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops,
-			 stmmac_pltfr_suspend, stmmac_pltfr_resume);
+SIMPLE_DEV_PM_OPS(stmmac_pltfr_pm_ops, stmmac_pltfr_suspend,
+				       stmmac_pltfr_resume);
+EXPORT_SYMBOL_GPL(stmmac_pltfr_pm_ops);
 
 static struct platform_driver stmmac_pltfr_driver = {
 	.probe = stmmac_pltfr_probe,
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
index 093eb99e5ffd..23d10f6e8846 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
@@ -19,6 +19,10 @@
 #ifndef __STMMAC_PLATFORM_H__
 #define __STMMAC_PLATFORM_H__
 
+int stmmac_pltfr_probe(struct platform_device *pdev);
+int stmmac_pltfr_remove(struct platform_device *pdev);
+extern const struct dev_pm_ops stmmac_pltfr_pm_ops;
+
 extern const struct stmmac_of_data meson6_dwmac_data;
 extern const struct stmmac_of_data sun7i_gmac_data;
 extern const struct stmmac_of_data stih4xx_dwmac_data;
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH RFC 2/2] stmac: add dwmac glue for NXP 18xx/43xx family
  2015-05-07 18:19 ` Joachim Eastwood
@ 2015-05-07 18:19   ` Joachim Eastwood
  -1 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-07 18:19 UTC (permalink / raw)
  To: arnd; +Cc: peppe.cavallaro, netdev, davem, linux-arm-kernel, Joachim Eastwood

Add support for using the dwmac on NXP LPC18xx and
LPC43xx devices.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/Makefile       |  1 +
 .../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c    | 98 ++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c

diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index f35e2bcde55f..560642a44134 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -7,6 +7,7 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o	\
 # ordering matters; keep stmmac_platform.o at the bottom
 obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
 stmmac-platform-objs:= \
+		dwmac-lpc18xx.o		\
 		dwmac-meson.o		\
 		dwmac-rk.o		\
 		dwmac-socfpga.o		\
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
new file mode 100644
index 000000000000..ed9ec45cb5ac
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -0,0 +1,98 @@
+/*
+ * STMAC glue for NXP LPC18xx/LPC43xx Ethernet
+ *
+ * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
+#include <linux/phy.h>
+#include <linux/regmap.h>
+#include <linux/stmmac.h>
+
+#include "stmmac_platform.h"
+
+/* Register defines for CREG syscon */
+#define LPC18XX_CREG_CREG6			0x12c
+# define LPC18XX_CREG_CREG6_ETHMODE_MASK	0x7
+# define LPC18XX_CREG_CREG6_ETHMODE_MII		0x0
+# define LPC18XX_CREG_CREG6_ETHMODE_RMII	0x4
+
+struct lpc18xx_dwmac_priv_data {
+	struct regmap *reg;
+	int interface;
+};
+
+static void *lpc18xx_dwmac_setup(struct platform_device *pdev)
+{
+	struct lpc18xx_dwmac_priv_data *dwmac;
+
+	dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
+	if (!dwmac)
+		return ERR_PTR(-ENOMEM);
+
+	dwmac->interface = of_get_phy_mode(pdev->dev.of_node);
+	if (dwmac->interface < 0)
+		return ERR_PTR(dwmac->interface);
+
+	dwmac->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
+	if (IS_ERR(dwmac->reg)) {
+		dev_err(&pdev->dev, "syscon lookup failed\n");
+		return dwmac->reg;
+	}
+
+	return dwmac;
+}
+
+static int lpc18xx_dwmac_init(struct platform_device *pdev, void *priv)
+{
+	struct lpc18xx_dwmac_priv_data *dwmac = priv;
+	u8 ethmode;
+
+	if (dwmac->interface == PHY_INTERFACE_MODE_MII) {
+		ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
+	} else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) {
+		ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
+	} else {
+		dev_err(&pdev->dev, "only MII and RMII mode supported\n");
+		return -EINVAL;
+	}
+
+	regmap_update_bits(dwmac->reg, LPC18XX_CREG_CREG6,
+			   LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
+
+	return 0;
+}
+
+static const struct stmmac_of_data lpc18xx_dwmac_data = {
+	.has_gmac = 1,
+	.setup = lpc18xx_dwmac_setup,
+	.init = lpc18xx_dwmac_init,
+};
+
+static const struct of_device_id lpc18xx_dwmac_match[] = {
+	{ .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
+
+static struct platform_driver lpc18xx_dwmac_driver = {
+	.probe  = stmmac_pltfr_probe,
+	.remove = stmmac_pltfr_remove,
+	.driver = {
+		.name           = "lpc18xx-dwmac",
+		.pm		= &stmmac_pltfr_pm_ops,
+		.of_match_table = lpc18xx_dwmac_match,
+	},
+};
+module_platform_driver(lpc18xx_dwmac_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
+MODULE_DESCRIPTION("Driver for Ethernet on LPC18xx/43xx");
+MODULE_LICENSE("GPL v2");
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH RFC 2/2] stmac: add dwmac glue for NXP 18xx/43xx family
@ 2015-05-07 18:19   ` Joachim Eastwood
  0 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-07 18:19 UTC (permalink / raw)
  To: linux-arm-kernel

Add support for using the dwmac on NXP LPC18xx and
LPC43xx devices.

Signed-off-by: Joachim Eastwood <manabian@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/Makefile       |  1 +
 .../net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c    | 98 ++++++++++++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c

diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile
index f35e2bcde55f..560642a44134 100644
--- a/drivers/net/ethernet/stmicro/stmmac/Makefile
+++ b/drivers/net/ethernet/stmicro/stmmac/Makefile
@@ -7,6 +7,7 @@ stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o	\
 # ordering matters; keep stmmac_platform.o at the bottom
 obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o
 stmmac-platform-objs:= \
+		dwmac-lpc18xx.o		\
 		dwmac-meson.o		\
 		dwmac-rk.o		\
 		dwmac-socfpga.o		\
diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
new file mode 100644
index 000000000000..ed9ec45cb5ac
--- /dev/null
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-lpc18xx.c
@@ -0,0 +1,98 @@
+/*
+ * STMAC glue for NXP LPC18xx/LPC43xx Ethernet
+ *
+ * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2. This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_net.h>
+#include <linux/phy.h>
+#include <linux/regmap.h>
+#include <linux/stmmac.h>
+
+#include "stmmac_platform.h"
+
+/* Register defines for CREG syscon */
+#define LPC18XX_CREG_CREG6			0x12c
+# define LPC18XX_CREG_CREG6_ETHMODE_MASK	0x7
+# define LPC18XX_CREG_CREG6_ETHMODE_MII		0x0
+# define LPC18XX_CREG_CREG6_ETHMODE_RMII	0x4
+
+struct lpc18xx_dwmac_priv_data {
+	struct regmap *reg;
+	int interface;
+};
+
+static void *lpc18xx_dwmac_setup(struct platform_device *pdev)
+{
+	struct lpc18xx_dwmac_priv_data *dwmac;
+
+	dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
+	if (!dwmac)
+		return ERR_PTR(-ENOMEM);
+
+	dwmac->interface = of_get_phy_mode(pdev->dev.of_node);
+	if (dwmac->interface < 0)
+		return ERR_PTR(dwmac->interface);
+
+	dwmac->reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
+	if (IS_ERR(dwmac->reg)) {
+		dev_err(&pdev->dev, "syscon lookup failed\n");
+		return dwmac->reg;
+	}
+
+	return dwmac;
+}
+
+static int lpc18xx_dwmac_init(struct platform_device *pdev, void *priv)
+{
+	struct lpc18xx_dwmac_priv_data *dwmac = priv;
+	u8 ethmode;
+
+	if (dwmac->interface == PHY_INTERFACE_MODE_MII) {
+		ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
+	} else if (dwmac->interface == PHY_INTERFACE_MODE_RMII) {
+		ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
+	} else {
+		dev_err(&pdev->dev, "only MII and RMII mode supported\n");
+		return -EINVAL;
+	}
+
+	regmap_update_bits(dwmac->reg, LPC18XX_CREG_CREG6,
+			   LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
+
+	return 0;
+}
+
+static const struct stmmac_of_data lpc18xx_dwmac_data = {
+	.has_gmac = 1,
+	.setup = lpc18xx_dwmac_setup,
+	.init = lpc18xx_dwmac_init,
+};
+
+static const struct of_device_id lpc18xx_dwmac_match[] = {
+	{ .compatible = "nxp,lpc1850-dwmac", .data = &lpc18xx_dwmac_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
+
+static struct platform_driver lpc18xx_dwmac_driver = {
+	.probe  = stmmac_pltfr_probe,
+	.remove = stmmac_pltfr_remove,
+	.driver = {
+		.name           = "lpc18xx-dwmac",
+		.pm		= &stmmac_pltfr_pm_ops,
+		.of_match_table = lpc18xx_dwmac_match,
+	},
+};
+module_platform_driver(lpc18xx_dwmac_driver);
+
+MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
+MODULE_DESCRIPTION("Driver for Ethernet on LPC18xx/43xx");
+MODULE_LICENSE("GPL v2");
-- 
1.8.0

^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH RFC 0/2] stmmac: stand alone platform drivers
  2015-05-07 18:19 ` Joachim Eastwood
@ 2015-05-08 13:30   ` Arnd Bergmann
  -1 siblings, 0 replies; 14+ messages in thread
From: Arnd Bergmann @ 2015-05-08 13:30 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: peppe.cavallaro, Joachim Eastwood, davem, netdev

On Thursday 07 May 2015 20:19:23 Joachim Eastwood wrote:
> Hi Arnd,
> 
> I ran into some issue using a separate platform driver[1] for lpc1850-dwmac.
> 
> My dts files looks like this.
> mac: ethernet@40010000 {
>         compatible = "nxp,lpc1850-dwmac", "snps,dwmac-3.611", "snps,dwmac";
>         ...
> }
> 
> On boot the generic driver in stmmac_platform.c would grab the
> device, matching on one of generic compat strings and thus blocking
> the lpc1850-dwmac driver.
> 
> By changing the build order in the Makefile (see patch 1) I managed
> to get it working, but I am not sure that is a good solution(?).

Changing the link order in the Makefile is an acceptable solution
for managing initialization order in general, but I think it won't
work here, because if your driver is a loadable module, the base
driver would always be attached first.
 
> Another fix would be to remove the generic compat strings from the
> match table in stmmac_platform but there are some dts-files that
> only have these compat strings.
> See abilis_tb10x.dtsi and exynos5440.dtsi.

Yes, that has a high risk of causing regressions.

> I could also remove the generic compat strings from my dts file but
> I am not sure that is good solution either. If more glue is
> converted this would then be need in those dts files also.

I think it would work if you move the generic strings into a separate
module that is not the one providing the base support. In that case,
the kernel should first try to use the driver that matches the first
compatible string. Can you try that?

	Arnd

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RFC 0/2] stmmac: stand alone platform drivers
@ 2015-05-08 13:30   ` Arnd Bergmann
  0 siblings, 0 replies; 14+ messages in thread
From: Arnd Bergmann @ 2015-05-08 13:30 UTC (permalink / raw)
  To: linux-arm-kernel

On Thursday 07 May 2015 20:19:23 Joachim Eastwood wrote:
> Hi Arnd,
> 
> I ran into some issue using a separate platform driver[1] for lpc1850-dwmac.
> 
> My dts files looks like this.
> mac: ethernet at 40010000 {
>         compatible = "nxp,lpc1850-dwmac", "snps,dwmac-3.611", "snps,dwmac";
>         ...
> }
> 
> On boot the generic driver in stmmac_platform.c would grab the
> device, matching on one of generic compat strings and thus blocking
> the lpc1850-dwmac driver.
> 
> By changing the build order in the Makefile (see patch 1) I managed
> to get it working, but I am not sure that is a good solution(?).

Changing the link order in the Makefile is an acceptable solution
for managing initialization order in general, but I think it won't
work here, because if your driver is a loadable module, the base
driver would always be attached first.
 
> Another fix would be to remove the generic compat strings from the
> match table in stmmac_platform but there are some dts-files that
> only have these compat strings.
> See abilis_tb10x.dtsi and exynos5440.dtsi.

Yes, that has a high risk of causing regressions.

> I could also remove the generic compat strings from my dts file but
> I am not sure that is good solution either. If more glue is
> converted this would then be need in those dts files also.

I think it would work if you move the generic strings into a separate
module that is not the one providing the base support. In that case,
the kernel should first try to use the driver that matches the first
compatible string. Can you try that?

	Arnd

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RFC 0/2] stmmac: stand alone platform drivers
  2015-05-08 13:30   ` Arnd Bergmann
@ 2015-05-12 17:20     ` Joachim Eastwood
  -1 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-12 17:20 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-arm-kernel, peppe.cavallaro, David S. Miller, netdev

On 8 May 2015 at 15:30, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thursday 07 May 2015 20:19:23 Joachim Eastwood wrote:
>> Hi Arnd,
>>
>> I ran into some issue using a separate platform driver[1] for lpc1850-dwmac.
>>
>> My dts files looks like this.
>> mac: ethernet@40010000 {
>>         compatible = "nxp,lpc1850-dwmac", "snps,dwmac-3.611", "snps,dwmac";
>>         ...
>> }
>>
>> On boot the generic driver in stmmac_platform.c would grab the
>> device, matching on one of generic compat strings and thus blocking
>> the lpc1850-dwmac driver.
>>
>> By changing the build order in the Makefile (see patch 1) I managed
>> to get it working, but I am not sure that is a good solution(?).
>
> Changing the link order in the Makefile is an acceptable solution
> for managing initialization order in general, but I think it won't
> work here, because if your driver is a loadable module, the base
> driver would always be attached first.

That is true.

The setup/configuration I am testing doesn't use modules though and
the only way I can get the lpc1850-dwmac driver to probe the device is
to link the generic driver last.

>> Another fix would be to remove the generic compat strings from the
>> match table in stmmac_platform but there are some dts-files that
>> only have these compat strings.
>> See abilis_tb10x.dtsi and exynos5440.dtsi.
>
> Yes, that has a high risk of causing regressions.
>
>> I could also remove the generic compat strings from my dts file but
>> I am not sure that is good solution either. If more glue is
>> converted this would then be need in those dts files also.
>
> I think it would work if you move the generic strings into a separate
> module that is not the one providing the base support. In that case,
> the kernel should first try to use the driver that matches the first
> compatible string. Can you try that?

I have now created a generic dt dwmac driver which contain all compat
strings that doesn't have any match data. As long as this driver is
linked last this works for my built-in drivers configuration. I am not
able to test using modules because of my very limited rootfs. This is
a Cortex-M system after all.

I also converted all the other DT dwmac drivers and the entire patch
set can be found on:
https://github.com/manabian/linux-lpc

After I have done some more cleanups and added proper commit messages
I will put them on netdev again.


regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RFC 0/2] stmmac: stand alone platform drivers
@ 2015-05-12 17:20     ` Joachim Eastwood
  0 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-12 17:20 UTC (permalink / raw)
  To: linux-arm-kernel

On 8 May 2015 at 15:30, Arnd Bergmann <arnd@arndb.de> wrote:
> On Thursday 07 May 2015 20:19:23 Joachim Eastwood wrote:
>> Hi Arnd,
>>
>> I ran into some issue using a separate platform driver[1] for lpc1850-dwmac.
>>
>> My dts files looks like this.
>> mac: ethernet at 40010000 {
>>         compatible = "nxp,lpc1850-dwmac", "snps,dwmac-3.611", "snps,dwmac";
>>         ...
>> }
>>
>> On boot the generic driver in stmmac_platform.c would grab the
>> device, matching on one of generic compat strings and thus blocking
>> the lpc1850-dwmac driver.
>>
>> By changing the build order in the Makefile (see patch 1) I managed
>> to get it working, but I am not sure that is a good solution(?).
>
> Changing the link order in the Makefile is an acceptable solution
> for managing initialization order in general, but I think it won't
> work here, because if your driver is a loadable module, the base
> driver would always be attached first.

That is true.

The setup/configuration I am testing doesn't use modules though and
the only way I can get the lpc1850-dwmac driver to probe the device is
to link the generic driver last.

>> Another fix would be to remove the generic compat strings from the
>> match table in stmmac_platform but there are some dts-files that
>> only have these compat strings.
>> See abilis_tb10x.dtsi and exynos5440.dtsi.
>
> Yes, that has a high risk of causing regressions.
>
>> I could also remove the generic compat strings from my dts file but
>> I am not sure that is good solution either. If more glue is
>> converted this would then be need in those dts files also.
>
> I think it would work if you move the generic strings into a separate
> module that is not the one providing the base support. In that case,
> the kernel should first try to use the driver that matches the first
> compatible string. Can you try that?

I have now created a generic dt dwmac driver which contain all compat
strings that doesn't have any match data. As long as this driver is
linked last this works for my built-in drivers configuration. I am not
able to test using modules because of my very limited rootfs. This is
a Cortex-M system after all.

I also converted all the other DT dwmac drivers and the entire patch
set can be found on:
https://github.com/manabian/linux-lpc

After I have done some more cleanups and added proper commit messages
I will put them on netdev again.


regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RFC 0/2] stmmac: stand alone platform drivers
  2015-05-12 17:20     ` Joachim Eastwood
@ 2015-05-12 19:49       ` Arnd Bergmann
  -1 siblings, 0 replies; 14+ messages in thread
From: Arnd Bergmann @ 2015-05-12 19:49 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Joachim Eastwood, peppe.cavallaro, David S. Miller, netdev

On Tuesday 12 May 2015 19:20:45 Joachim Eastwood wrote:
> 
> I have now created a generic dt dwmac driver which contain all compat
> strings that doesn't have any match data. As long as this driver is
> linked last this works for my built-in drivers configuration. I am not
> able to test using modules because of my very limited rootfs. This is
> a Cortex-M system after all.
> 
> I also converted all the other DT dwmac drivers and the entire patch
> set can be found on:
> https://github.com/manabian/linux-lpc
> 
> After I have done some more cleanups and added proper commit messages
> I will put them on netdev again.
> 
> 

Yes, this looks really nice (with the cleanup bits that are obviously
missing applied), thanks a lot!

We should probably try to keep existing defconfig files working,
which could be done e.g. like

 config DWMAC_ROCKCHIP
	tristate "Rockchip dwmac support"
+	default ARCH_ROCKCHIP
	depends on OF
	select MFD_SYSCON

so that any configuration that currently has ARCH_ROCKCHIP and DW_MAC
enabled ends up with DWMAC_ROCKCHIP enabled as well.

	Arnd

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RFC 0/2] stmmac: stand alone platform drivers
@ 2015-05-12 19:49       ` Arnd Bergmann
  0 siblings, 0 replies; 14+ messages in thread
From: Arnd Bergmann @ 2015-05-12 19:49 UTC (permalink / raw)
  To: linux-arm-kernel

On Tuesday 12 May 2015 19:20:45 Joachim Eastwood wrote:
> 
> I have now created a generic dt dwmac driver which contain all compat
> strings that doesn't have any match data. As long as this driver is
> linked last this works for my built-in drivers configuration. I am not
> able to test using modules because of my very limited rootfs. This is
> a Cortex-M system after all.
> 
> I also converted all the other DT dwmac drivers and the entire patch
> set can be found on:
> https://github.com/manabian/linux-lpc
> 
> After I have done some more cleanups and added proper commit messages
> I will put them on netdev again.
> 
> 

Yes, this looks really nice (with the cleanup bits that are obviously
missing applied), thanks a lot!

We should probably try to keep existing defconfig files working,
which could be done e.g. like

 config DWMAC_ROCKCHIP
	tristate "Rockchip dwmac support"
+	default ARCH_ROCKCHIP
	depends on OF
	select MFD_SYSCON

so that any configuration that currently has ARCH_ROCKCHIP and DW_MAC
enabled ends up with DWMAC_ROCKCHIP enabled as well.

	Arnd

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH RFC 0/2] stmmac: stand alone platform drivers
  2015-05-12 19:49       ` Arnd Bergmann
@ 2015-05-12 20:31         ` Joachim Eastwood
  -1 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-12 20:31 UTC (permalink / raw)
  To: Arnd Bergmann; +Cc: linux-arm-kernel, peppe.cavallaro, David S. Miller, netdev

On 12 May 2015 at 21:49, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tuesday 12 May 2015 19:20:45 Joachim Eastwood wrote:
>>
>> I have now created a generic dt dwmac driver which contain all compat
>> strings that doesn't have any match data. As long as this driver is
>> linked last this works for my built-in drivers configuration. I am not
>> able to test using modules because of my very limited rootfs. This is
>> a Cortex-M system after all.
>>
>> I also converted all the other DT dwmac drivers and the entire patch
>> set can be found on:
>> https://github.com/manabian/linux-lpc
>>
>> After I have done some more cleanups and added proper commit messages
>> I will put them on netdev again.
>>
>>
>
> Yes, this looks really nice (with the cleanup bits that are obviously
> missing applied), thanks a lot!
>
> We should probably try to keep existing defconfig files working,
> which could be done e.g. like
>
>  config DWMAC_ROCKCHIP
>         tristate "Rockchip dwmac support"
> +       default ARCH_ROCKCHIP
>         depends on OF
>         select MFD_SYSCON
>
> so that any configuration that currently has ARCH_ROCKCHIP and DW_MAC
> enabled ends up with DWMAC_ROCKCHIP enabled as well.

Ah, yes, indeed. I will add a default statement in the Kconfig of the
converted drivers.

regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH RFC 0/2] stmmac: stand alone platform drivers
@ 2015-05-12 20:31         ` Joachim Eastwood
  0 siblings, 0 replies; 14+ messages in thread
From: Joachim Eastwood @ 2015-05-12 20:31 UTC (permalink / raw)
  To: linux-arm-kernel

On 12 May 2015 at 21:49, Arnd Bergmann <arnd@arndb.de> wrote:
> On Tuesday 12 May 2015 19:20:45 Joachim Eastwood wrote:
>>
>> I have now created a generic dt dwmac driver which contain all compat
>> strings that doesn't have any match data. As long as this driver is
>> linked last this works for my built-in drivers configuration. I am not
>> able to test using modules because of my very limited rootfs. This is
>> a Cortex-M system after all.
>>
>> I also converted all the other DT dwmac drivers and the entire patch
>> set can be found on:
>> https://github.com/manabian/linux-lpc
>>
>> After I have done some more cleanups and added proper commit messages
>> I will put them on netdev again.
>>
>>
>
> Yes, this looks really nice (with the cleanup bits that are obviously
> missing applied), thanks a lot!
>
> We should probably try to keep existing defconfig files working,
> which could be done e.g. like
>
>  config DWMAC_ROCKCHIP
>         tristate "Rockchip dwmac support"
> +       default ARCH_ROCKCHIP
>         depends on OF
>         select MFD_SYSCON
>
> so that any configuration that currently has ARCH_ROCKCHIP and DW_MAC
> enabled ends up with DWMAC_ROCKCHIP enabled as well.

Ah, yes, indeed. I will add a default statement in the Kconfig of the
converted drivers.

regards,
Joachim Eastwood

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2015-05-12 20:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-07 18:19 [PATCH RFC 0/2] stmmac: stand alone platform drivers Joachim Eastwood
2015-05-07 18:19 ` Joachim Eastwood
2015-05-07 18:19 ` [PATCH RFC 1/2] stmac: support standalone " Joachim Eastwood
2015-05-07 18:19   ` Joachim Eastwood
2015-05-07 18:19 ` [PATCH RFC 2/2] stmac: add dwmac glue for NXP 18xx/43xx family Joachim Eastwood
2015-05-07 18:19   ` Joachim Eastwood
2015-05-08 13:30 ` [PATCH RFC 0/2] stmmac: stand alone platform drivers Arnd Bergmann
2015-05-08 13:30   ` Arnd Bergmann
2015-05-12 17:20   ` Joachim Eastwood
2015-05-12 17:20     ` Joachim Eastwood
2015-05-12 19:49     ` Arnd Bergmann
2015-05-12 19:49       ` Arnd Bergmann
2015-05-12 20:31       ` Joachim Eastwood
2015-05-12 20:31         ` Joachim Eastwood

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.