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

Signed-off-by: Olliver Schinagl <oli...@schinagl.nl>
---
 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/sun7i_mac.c | 52 +++++++++++++++++++++++----
 5 files changed, 47 insertions(+), 9 deletions(-)
 rename board/sunxi/gmac.c => drivers/net/sun7i_mac.c (69%)

diff --git a/arch/arm/mach-sunxi/board.c b/arch/arm/mach-sunxi/board.c
index 65b1ebd837..728da01a49 100644
--- a/arch/arm/mach-sunxi/board.c
+++ b/arch/arm/mach-sunxi/board.c
@@ -207,7 +207,6 @@ void s_init(void)
 #ifndef CONFIG_DM_I2C
        i2c_init_board();
 #endif
-       eth_init_board();
 }
 
 #ifdef CONFIG_SPL_BUILD
diff --git a/board/sunxi/Makefile b/board/sunxi/Makefile
index b4768b9b9b..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_SUN7I_MAC)                += 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 594f54f714..86dee7d746 100644
--- a/drivers/net/Makefile
+++ b/drivers/net/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_E1000) += e1000.o
 obj-$(CONFIG_E1000_SPI) += e1000_spi.o
 obj-$(CONFIG_EEPRO100) += eepro100.o
 obj-$(CONFIG_SUN4I_EMAC) += sunxi_common.o sun4i_mac.o
+obj-$(CONFIG_SUN7I_MAC) += sun7i_mac.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/sun7i_mac.c
similarity index 69%
rename from board/sunxi/gmac.c
rename to drivers/net/sun7i_mac.c
index 69eb8ff2d9..f8c6a58c08 100644
--- a/board/sunxi/gmac.c
+++ b/drivers/net/sun7i_mac.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 <oli...@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 sun7i_mac_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 sun7i_mac_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 sun7i_mac_eth_ids[] = {
+       { .compatible = "allwinner,sun7i-a20-gmac" },
+       { /* sentinel */ },
+};
+
+U_BOOT_DRIVER(eth_sun7i_mac) = {
+       .name   = "sun7i-mac",
+       .id     = UCLASS_ETH,
+       .of_match = sun7i_mac_eth_ids,
+       .ofdata_to_platdata = designware_eth_ofdata_to_platdata,
+       .probe  = sun7i_mac_eth_probe,
+       .ops    = &sun7i_mac_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

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to