[U-Boot] [PATCHv2 16/21] net: sunxi_gmac: Make the sunxi variant of dw driver a subclass

Olliver Schinagl oliver at schinagl.nl
Mon Apr 10 15:33:51 UTC 2017


This patch removes the old sunxi_gmac glue layer and turns it into a
proper sub-class driver.

Signed-off-by: Olliver Schinagl <oliver at schinagl.nl>
---
 arch/arm/include/asm/arch-sunxi/sys_proto.h    |  7 ----
 arch/arm/mach-sunxi/board.c                    |  1 -
 board/sunxi/Makefile                           |  1 -
 drivers/net/Makefile                           |  1 +
 drivers/net/designware.c                       |  1 -
 board/sunxi/gmac.c => drivers/net/sunxi_gmac.c | 52 +++++++++++++++++++++++---
 6 files changed, 47 insertions(+), 16 deletions(-)
 rename board/sunxi/gmac.c => drivers/net/sunxi_gmac.c (69%)

diff --git a/arch/arm/include/asm/arch-sunxi/sys_proto.h b/arch/arm/include/asm/arch-sunxi/sys_proto.h
index 98effbf5c6..42bdfc711a 100644
--- a/arch/arm/include/asm/arch-sunxi/sys_proto.h
+++ b/arch/arm/include/asm/arch-sunxi/sys_proto.h
@@ -23,13 +23,6 @@ void sdelay(unsigned long);
  */
 void return_to_fel(uint32_t lr, uint32_t sp);
 
-/* Board / SoC level designware gmac init */
-#if !defined CONFIG_SPL_BUILD && defined CONFIG_SUNXI_GMAC
-void eth_init_board(void);
-#else
-static inline void eth_init_board(void) {}
-#endif
-
 int sunxi_gen_hwaddr(const int seq, unsigned char *enetaddr);
 
 #endif
diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index 3a5840b9c0..64aed3180c 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -200,7 +200,6 @@ void s_init(void)
 	timer_init();
 	gpio_init();
 	i2c_init_board();
-	eth_init_board();
 }
 
 #ifdef CONFIG_SPL_BUILD
diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile
index 43766e0ef4..f2dba9532a 100644
--- a/board/sunxi/Makefile
+++ b/board/sunxi/Makefile
@@ -9,7 +9,6 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 obj-y	+= board.o
-obj-$(CONFIG_SUNXI_GMAC)	+= gmac.o
 obj-$(CONFIG_SUNXI_AHCI)	+= ahci.o
 obj-$(CONFIG_MACH_SUN4I)	+= dram_sun4i_auto.o
 obj-$(CONFIG_MACH_SUN5I)	+= dram_sun5i_auto.o
diff --git a/drivers/net/Makefile b/drivers/net/Makefile
index c840770bd8..3a0ab139c3 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_E1000) += e1000.o
 obj-$(CONFIG_E1000_SPI) += e1000_spi.o
 obj-$(CONFIG_EEPRO100) += eepro100.o
 obj-$(CONFIG_SUNXI_EMAC) += sunxi_common.o sunxi_emac.o
+obj-$(CONFIG_SUNXI_GMAC) += sunxi_gmac.o
 obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o
 obj-$(CONFIG_ENC28J60) += enc28j60.o
 obj-$(CONFIG_EP93XX) += ep93xx_eth.o
diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index f9fb8e0886..3e18f28232 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -761,7 +761,6 @@ int designware_eth_ofdata_to_platdata(struct udevice *dev)
 }
 
 static const struct udevice_id designware_eth_ids[] = {
-	{ .compatible = "allwinner,sun7i-a20-gmac" },
 	{ .compatible = "altr,socfpga-stmmac" },
 	{ .compatible = "amlogic,meson6-dwmac" },
 	{ .compatible = "amlogic,meson-gx-dwmac" },
diff --git a/board/sunxi/gmac.c b/drivers/net/sunxi_gmac.c
similarity index 69%
rename from board/sunxi/gmac.c
rename to drivers/net/sunxi_gmac.c
index 69eb8ff2d9..15f8164c34 100644
--- a/board/sunxi/gmac.c
+++ b/drivers/net/sunxi_gmac.c
@@ -1,12 +1,24 @@
-#include <common.h>
-#include <netdev.h>
-#include <miiphy.h>
-#include <asm/gpio.h>
-#include <asm/io.h>
+/*
+ * (C) Copyright 2016 Olliver Schinagl <oliver at schinagl.nl>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * Allwinner GMAC ethernet IP driver for U-Boot
+ */
+
+#include <asm/arch/cpu.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/gpio.h>
+#include <asm/io.h>
+#include <common.h>
+#include <dm.h>
+#include <net.h>
+
+#include "designware.h"
 
-void eth_init_board(void)
+DECLARE_GLOBAL_DATA_PTR;
+
+static int sunxi_gmac_eth_probe(struct udevice *dev)
 {
 	int pin;
 	struct sunxi_ccm_reg *const ccm =
@@ -79,4 +91,32 @@ void eth_init_board(void)
 	for (pin = SUNXI_GPA(26); pin <= SUNXI_GPA(27); pin++)
 		sunxi_gpio_set_cfgpin(pin, SUN6I_GPA_GMAC);
 #endif
+
+	return designware_eth_probe(dev);
 }
+
+const struct eth_ops sunxi_gmac_eth_ops = {
+	.start			= designware_eth_start,
+	.send			= designware_eth_send,
+	.recv			= designware_eth_recv,
+	.free_pkt		= designware_eth_free_pkt,
+	.stop			= designware_eth_stop,
+	.write_hwaddr		= designware_eth_write_hwaddr,
+};
+
+static const struct udevice_id sunxi_gmac_eth_ids[] = {
+	{ .compatible = "allwinner,sun7i-a20-gmac" },
+	{ /* sentinel */ },
+};
+
+U_BOOT_DRIVER(eth_sunxi_gmac) = {
+	.name	= "sunxi-gmac",
+	.id	= UCLASS_ETH,
+	.of_match = sunxi_gmac_eth_ids,
+	.ofdata_to_platdata = designware_eth_ofdata_to_platdata,
+	.probe	= sunxi_gmac_eth_probe,
+	.ops	= &sunxi_gmac_eth_ops,
+	.priv_auto_alloc_size = sizeof(struct dw_eth_dev),
+	.platdata_auto_alloc_size = sizeof(struct dw_eth_pdata),
+	.flags = DM_FLAG_ALLOC_PRIV_DMA,
+};
-- 
2.11.0



More information about the U-Boot mailing list