Skip to contentSkip to conversation

net: davinci_emac: use driver model (CONFIG_DM_ETH)

PATCH New Bartosz Golaszewski 4 participants 6 messages Apr 30, 2019 – May 10, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: davinci_emac: use driver model (CONFIG_DM_ETH)

From: Bartosz Golaszewski <[email protected]>

Add support for CONFIG_DM_ETH to the davinci_emac driver. Optimally we should only support DM-enabled platforms but there are several non-DT boards that still use it so either we need to keep supporting it or drop the boards from u-boot. For now we're stuck with ugly ifdefs.

This patch adds support for driver-model to the driver and converts all platforms that use the driver model to selecting CONFIG_DM_ETH.

Tested on da850-evm and da850-lcdk.

---
NOTE: I'm currently working on modernizing da850 support in u-boot. This patch is just the first step - I plan on improving the emac driver in general but I'll be OoO until end of next week, so I decided to post it already for reviews.

Does anyone know what the status is on boards like twister, ea20 etc. that use davinci_emac, but don't use the driver model? Dropping them would make it easier to clean up this driver.

This patch applies on top of my previous series[1].

[1] https://lists.denx.de/pipermail/u-boot/2019-April/367236.html

 arch/arm/mach-davinci/cpu.c            |  13 ---
 arch/arm/mach-omap2/omap3/emac.c       |   3 +-
 board/davinci/da8xxevm/da850evm.c      |   5 --
 board/davinci/da8xxevm/omapl138_lcdk.c |  14 ----
 board/logicpd/am3517evm/am3517evm.c    |   1 -
 board/ti/ti816x/evm.c                  |   3 +-
 configs/am3517_evm_defconfig           |   1 +
 configs/da850_am18xxevm_defconfig      |   1 +
 configs/da850evm_defconfig             |   1 +
 configs/da850evm_direct_nor_defconfig  |   1 +
 configs/omapl138_lcdk_defconfig        |   1 +
 configs/ti816x_evm_defconfig           |   1 +
 drivers/net/ti/davinci_emac.c          | 109 +++++++++++++++++++++----
 13 files changed, 100 insertions(+), 54 deletions(-)
arch/arm/mach-davinci/cpu.c +0 -13
index f97ad3fc74..9fd6564d04 100644
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
@@ -90,15 +89,3 @@ int set_cpu_clk_info(void)
 	gd->bd->bi_dsp_freq = 0;
 	return 0;
 }
-
-/*
- * Initializes on-chip ethernet controllers.
- * to override, implement board_eth_init()
- */
-int cpu_eth_init(bd_t *bis)
-{
-#if defined(CONFIG_DRIVER_TI_EMAC)
-	davinci_emac_initialize();
-#endif
-	return 0;
-}
arch/arm/mach-omap2/omap3/emac.c +1 -2
index c79e870183..fb0c9188f5 100644
@@ -7,7 +7,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/am35x_def.h>
 
@@ -24,5 +23,5 @@ int cpu_eth_init(bd_t *bis)
 	reset &= ~CPGMACSS_SW_RST;
 	writel(reset, &am35x_scm_general_regs->ip_sw_reset);
 
-	return davinci_emac_initialize();
+	return 0;
 }
board/davinci/da8xxevm/da850evm.c +0 -5
index 1bc26828bf..0d2bc5fb32 100644
@@ -13,7 +13,6 @@
 #include <environment.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -472,10 +471,6 @@ int board_eth_init(bd_t *bis)
 	if (rmii_hw_init())
 		printf("RMII hardware init failed!!!\n");
 #endif
-	if (!davinci_emac_initialize()) {
-		printf("Error: Ethernet init failed!\n");
-		return -1;
-	}
 
 	return 0;
 }
board/davinci/da8xxevm/omapl138_lcdk.c +0 -14
index 2c2f885d43..ef9656add8 100644
@@ -11,7 +11,6 @@
 #include <common.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -229,19 +228,6 @@ int board_init(void)
 
 #ifdef CONFIG_DRIVER_TI_EMAC
 
-/*
- * Initializes on-board ethernet controllers.
- */
-int board_eth_init(bd_t *bis)
-{
-	if (!davinci_emac_initialize()) {
-		printf("Error: Ethernet init failed!\n");
-		return -1;
-	}
-
-	return 0;
-}
-
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
 #define CFG_MAC_ADDR_SPI_BUS	0
board/logicpd/am3517evm/am3517evm.c +0 -1
index 10031a4801..bfd4e78274 100644
@@ -28,7 +28,6 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
 #include <i2c.h>
-#include <netdev.h>
 #include "am3517evm.h"
 
 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c +1 -2
index 07a084bab8..240df8cbe1 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <environment.h>
 #include <spl.h>
-#include <netdev.h>
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -56,7 +55,7 @@ int board_eth_init(bd_t *bis)
 			printf("Unable to read MAC address. Set <ethaddr>\n");
 	}
 
-	return davinci_emac_initialize();
+	return 0;
 }
 
 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig +1 -0
index b9f59f3291..0ea28a20b2 100644
@@ -45,6 +45,7 @@ CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850_am18xxevm_defconfig +1 -0
index f098222113..6227cafc90 100644
@@ -52,6 +52,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/da850evm_defconfig +1 -0
index 221c204af0..78eadc6330 100644
@@ -60,6 +60,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850evm_direct_nor_defconfig +1 -0
index 166e77b8e3..2dd82d68b9 100644
@@ -51,6 +51,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/omapl138_lcdk_defconfig +1 -0
index e43141844a..0600ac3f4a 100644
@@ -51,6 +51,7 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/ti816x_evm_defconfig +1 -0
index bf877f596b..131b25a188 100644
@@ -46,6 +46,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
drivers/net/ti/davinci_emac.c +92 -17

199 lines not on this page · raw message

Signature · 1 line
2.21.0
#1 lore raw

PATCH 1/1 net: davinci_emac: use driver model (CONFIG_DM_ETH)

Quoted 8 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

Add support for CONFIG_DM_ETH to the davinci_emac driver. Optimally we should only support DM-enabled platforms but there are several non-DT boards that still use it so either we need to keep supporting it or drop the boards from u-boot. For now we're stuck with ugly ifdefs.

Which boards are still not using DM that you refer to here?

Quoted 263 lines

This patch adds support for driver-model to the driver and converts all platforms that use the driver model to selecting CONFIG_DM_ETH.

Tested on da850-evm and da850-lcdk.

---
NOTE: I'm currently working on modernizing da850 support in u-boot. This patch is just the first step - I plan on improving the emac driver in general but I'll be OoO until end of next week, so I decided to post it already for reviews.

Does anyone know what the status is on boards like twister, ea20 etc. that use davinci_emac, but don't use the driver model? Dropping them would make it easier to clean up this driver.

This patch applies on top of my previous series[1].

[1] https://lists.denx.de/pipermail/u-boot/2019-April/367236.html

 arch/arm/mach-davinci/cpu.c            |  13 ---
 arch/arm/mach-omap2/omap3/emac.c       |   3 +-
 board/davinci/da8xxevm/da850evm.c      |   5 --
 board/davinci/da8xxevm/omapl138_lcdk.c |  14 ----
 board/logicpd/am3517evm/am3517evm.c    |   1 -
 board/ti/ti816x/evm.c                  |   3 +-
 configs/am3517_evm_defconfig           |   1 +
 configs/da850_am18xxevm_defconfig      |   1 +
 configs/da850evm_defconfig             |   1 +
 configs/da850evm_direct_nor_defconfig  |   1 +
 configs/omapl138_lcdk_defconfig        |   1 +
 configs/ti816x_evm_defconfig           |   1 +
 drivers/net/ti/davinci_emac.c          | 109 +++++++++++++++++++++----
 13 files changed, 100 insertions(+), 54 deletions(-)
arch/arm/mach-davinci/cpu.c +0 -13
index f97ad3fc74..9fd6564d04 100644
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
@@ -90,15 +89,3 @@ int set_cpu_clk_info(void)
        gd->bd->bi_dsp_freq = 0;
        return 0;
 }
-
-/*
- * Initializes on-chip ethernet controllers.
- * to override, implement board_eth_init()
- */
-int cpu_eth_init(bd_t *bis)
-{
-#if defined(CONFIG_DRIVER_TI_EMAC)
-       davinci_emac_initialize();
-#endif
-       return 0;
-}
arch/arm/mach-omap2/omap3/emac.c +1 -2
index c79e870183..fb0c9188f5 100644
@@ -7,7 +7,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/am35x_def.h>
 
@@ -24,5 +23,5 @@ int cpu_eth_init(bd_t *bis)
        reset &= ~CPGMACSS_SW_RST;
        writel(reset, &am35x_scm_general_regs->ip_sw_reset);
 
-       return davinci_emac_initialize();
+       return 0;
 }
board/davinci/da8xxevm/da850evm.c +0 -5
index 1bc26828bf..0d2bc5fb32 100644
@@ -13,7 +13,6 @@
 #include <environment.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -472,10 +471,6 @@ int board_eth_init(bd_t *bis)
        if (rmii_hw_init())
                printf("RMII hardware init failed!!!\n");
 #endif
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
 
        return 0;
 }
board/davinci/da8xxevm/omapl138_lcdk.c +0 -14
index 2c2f885d43..ef9656add8 100644
@@ -11,7 +11,6 @@
 #include <common.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -229,19 +228,6 @@ int board_init(void)
 
 #ifdef CONFIG_DRIVER_TI_EMAC
 
-/*
- * Initializes on-board ethernet controllers.
- */
-int board_eth_init(bd_t *bis)
-{
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
 #define CFG_MAC_ADDR_SPI_BUS   0
board/logicpd/am3517evm/am3517evm.c +0 -1
index 10031a4801..bfd4e78274 100644
@@ -28,7 +28,6 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
 #include <i2c.h>
-#include <netdev.h>
 #include "am3517evm.h"
 
 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c +1 -2
index 07a084bab8..240df8cbe1 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <environment.h>
 #include <spl.h>
-#include <netdev.h>
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -56,7 +55,7 @@ int board_eth_init(bd_t *bis)
                        printf("Unable to read MAC address. Set <ethaddr>\n");
        }
 
-       return davinci_emac_initialize();
+       return 0;
 }
 
 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig +1 -0
index b9f59f3291..0ea28a20b2 100644
@@ -45,6 +45,7 @@ CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850_am18xxevm_defconfig +1 -0
index f098222113..6227cafc90 100644
@@ -52,6 +52,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/da850evm_defconfig +1 -0
index 221c204af0..78eadc6330 100644
@@ -60,6 +60,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850evm_direct_nor_defconfig +1 -0
index 166e77b8e3..2dd82d68b9 100644
@@ -51,6 +51,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/omapl138_lcdk_defconfig +1 -0
index e43141844a..0600ac3f4a 100644
@@ -51,6 +51,7 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/ti816x_evm_defconfig +1 -0
index bf877f596b..131b25a188 100644
@@ -46,6 +46,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
drivers/net/ti/davinci_emac.c +3 -1
index 9d53984973..3252a235d2 100644
@@ -26,11 +26,13 @@
 #include <net.h>
 #include <miiphy.h>
 #include <malloc.h>
-#include <netdev.h>
 #include <linux/compiler.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/io.h>
 #include "davinci_emac.h"
+#ifndef CONFIG_DM_ETH
+#include <netdev.h>
+#endif
 
 unsigned int   emac_dbg = 0;
 #define debug_emac(fmt,args...)        if (emac_dbg) printf(fmt,##args)

drivers/net/ti/davinci_emac.c static u_int8_t num_phy; · line 112

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -107,10 +109,16 @@ static u_int8_t   num_phy;
 
 phy_t                          phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 15 lines
drivers/net/ti/davinci_emac.c +7 -2
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_write_hwaddr(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       unsigned long           mac_hi;
-       unsigned long           mac_lo;
+#ifdef CONFIG_DM_ETH
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+#endif
+       unsigned long mac_hi, mac_lo;
 
        /*
         * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast

drivers/net/ti/davinci_emac.c static int davinci_eth_set_mac_addr(struct eth_device *dev) · line 130

Quoted 5 lines
drivers/net/ti/davinci_emac.c +2 -0
@@ -118,12 +126,22 @@ static int davinci_eth_set_mac_addr(struct eth_device *dev)
         *  Using channel 0 only - other channels are disabled
         *  */
        writel(0, &adap_emac->MACINDEX);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 18 lines
drivers/net/ti/davinci_emac.c +8 -0
        mac_hi = (dev->enetaddr[3] << 24) |
                 (dev->enetaddr[2] << 16) |
                 (dev->enetaddr[1] << 8)  |
                 (dev->enetaddr[0]);
        mac_lo = (dev->enetaddr[5] << 8) |
                 (dev->enetaddr[4]);
+#else /* with CONFIG_DM_ETH */
+       mac_hi = (pdata->enetaddr[3] << 24) |
+                (pdata->enetaddr[2] << 16) |
+                (pdata->enetaddr[1] << 8)  |
+                (pdata->enetaddr[0]);
+       mac_lo = (pdata->enetaddr[5] << 8) |
+                (pdata->enetaddr[4]);
+#endif /* CONFIG_DM_ETH */
 
        writel(mac_hi, &adap_emac->MACADDRHI);
 #if defined(DAVINCI_EMAC_VERSION2)

drivers/net/ti/davinci_emac.c static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr) · line 432

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -411,13 +429,17 @@ static void  __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr)
 }
 
 /* Eth device open */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 19 lines
drivers/net/ti/davinci_emac.c +8 -5
 static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_start(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       dv_reg_p                addr;
-       u_int32_t               clkdiv, cnt, mac_control;
-       uint16_t                __maybe_unused lpa_val;
-       volatile emac_desc      *rx_desc;
-       int                     index;
+       u32 clkdiv, cnt, mac_control;
+       volatile emac_desc *rx_desc;
+       u16 __maybe_unused lpa_val;
+       dv_reg_p addr;
+       int index;
 
        debug_emac("+ emac_open\n");
 

drivers/net/ti/davinci_emac.c static int davinci_eth_open(struct eth_device *dev, bd_t *bis) · line 472

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -447,7 +469,11 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        writel(1, &adap_emac->TXCONTROL);
        writel(1, &adap_emac->RXCONTROL);
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static void davinci_eth_ch_teardown(int ch) · line 617

Quoted 12 lines
drivers/net/ti/davinci_emac.c +4 -0
        davinci_eth_set_mac_addr(dev);
+#else /* with CONFIG_DM_ETH */
+       davinci_emac_write_hwaddr(dev);
+#endif /* CONFIG_DM_ETH */
 
        /* Set DMA 8 TX / 8 RX Head pointers to 0 */
        addr = &adap_emac->TX0HDP;
@@ -588,7 +614,11 @@ static void davinci_eth_ch_teardown(int ch)
 }
 
 /* Eth device close */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 8 lines
drivers/net/ti/davinci_emac.c +3 -0
 static void davinci_eth_close(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static void davinci_emac_stop(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
        debug_emac("+ emac_close\n");
 

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 652

Quoted 6 lines
drivers/net/ti/davinci_emac.c +1 -2
@@ -619,11 +649,15 @@ static int tx_send_loop = 0;
  * This function sends a single packet on the network and returns
  * positive number (number of bytes transmitted) or negative for error
  */
-static int davinci_eth_send_packet (struct eth_device *dev,
-                                       void *packet, int length)
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 660

Quoted 10 lines
drivers/net/ti/davinci_emac.c +7 -2
+static int davinci_eth_send_packet(struct eth_device *dev,
+                                  void *packet, int length)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_send(struct udevice *dev,
+                            void *packet, int length)
+#endif /* CONFIG_DM_ETH */
 {
-       int ret_status = -1;
-       int index;
+       int ret_status = -1, index;

I'm not sure why you are mixing these formatting changes (which look bad anyway) with the substantive changes. Please drop them.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 709

Quoted 8 lines
drivers/net/ti/davinci_emac.c +1 -0
        tx_send_loop = 0;
 
        index = get_active_phy();
@@ -672,7 +706,11 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 /*
  * This function handles receipt of a packet from the network
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 716

Quoted 7 lines
drivers/net/ti/davinci_emac.c +3 -0
 static int davinci_eth_rcv_packet (struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp)
+#endif /* CONFIG_DM_ETH */
 {
        volatile emac_desc *rx_curr_desc;
        volatile emac_desc *curr_desc;

Please remove the call to net_process_received_packet() and split the descriptor cleanup into a free_pkt() operation.

Quoted 11 lines
drivers/net/ti/davinci_emac.c +3 -0
@@ -742,6 +780,9 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                }
                return (ret);
        }
+#ifdef CONFIG_DM_ETH
+       *packetp = rx_curr_desc->buffer;
+#endif
        return (0);
 }
 

drivers/net/ti/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device *dev) · line 794

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -750,12 +791,16 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
  * EMAC modules power or pin multiplexors, that is done by board_init()
  * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 25 lines
drivers/net/ti/davinci_emac.c +8 -4
 int davinci_emac_initialize(void)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_probe(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       u_int32_t       phy_id;
-       u_int16_t       tmp;
-       int             i;
-       int             ret;
+       int i, ret;
+       u32 phy_id;
+       u16 tmp;
+#ifndef CONFIG_DM_ETH
        struct eth_device *dev;
 
        dev = malloc(sizeof *dev);
@@ -774,6 +819,7 @@ int davinci_emac_initialize(void)
        dev->write_hwaddr = davinci_eth_set_mac_addr;
 
        eth_register(dev);
+#endif /* CONFIG_DM_ETH */
 
        davinci_eth_mdio_enable();
 

drivers/net/ti/davinci_emac.c int davinci_emac_initialize(void) · line 904

Quoted 6 lines
drivers/net/ti/davinci_emac.c +2 -1
@@ -854,5 +900,34 @@ int davinci_emac_initialize(void)
                        phy[i].auto_negotiate(i);
        }
 #endif
-       return(1);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 36 lines
drivers/net/ti/davinci_emac.c +28 -1
+       return 1;
+#else /* with CONFIG_DM_ETH */
+       return 0;
+#endif /* CONFIG_DM_ETH */
 }
+
+#ifdef CONFIG_DM_ETH
+static const struct eth_ops davinci_emac_ops = {
+       .start          = davinci_emac_start,
+       .send           = davinci_emac_send,
+       .recv           = davinci_emac_recv,
+       .stop           = davinci_emac_stop,
+       .write_hwaddr   = davinci_emac_write_hwaddr,
+};
+
+static const struct udevice_id davinci_emac_ids[] = {
+       { .compatible = "ti,davinci-dm6467-emac" },
+       { }
+};
+
+U_BOOT_DRIVER(davinci_emac) = {
+       .name           = "davinci_emac",
+       .id             = UCLASS_ETH,
+       .of_match       = davinci_emac_ids,
+       .probe          = davinci_emac_probe,
+       .ops            = &davinci_emac_ops,
+       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
+#endif /* CONFIG_DM_ETH */
--

2.21.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#2 lore raw

PATCH 1/1 net: davinci_emac: use driver model (CONFIG_DM_ETH)

czw., 9 maj 2019 o 20:48 Joe Hershberger <[email protected]> napisaÅ‚(a):

Quoted 13 lines · Bartosz Golaszewski
Quoted 8 lines

From: Bartosz Golaszewski <[email protected]>

Add support for CONFIG_DM_ETH to the davinci_emac driver. Optimally we should only support DM-enabled platforms but there are several non-DT boards that still use it so either we need to keep supporting it or drop the boards from u-boot. For now we're stuck with ugly ifdefs.

Which boards are still not using DM that you refer to here?

The following configs define CONFIG_DRIVER_TI_EMAC=y and don't define CONFIG_DM=y:

am3517_evm_defconfig
calimain_defconfig
cm_t3517_defconfig
ea20_defconfig
eco5pk_defconfig
ipam390_defconfig
mcx_defconfig
mt_ventoux_defconfig
twister_defconfig

Are these still maintained?

Best regards,
Bartosz Golaszewski

Quoted 509 lines
Quoted 263 lines

This patch adds support for driver-model to the driver and converts all platforms that use the driver model to selecting CONFIG_DM_ETH.

Tested on da850-evm and da850-lcdk.

---
NOTE: I'm currently working on modernizing da850 support in u-boot. This patch is just the first step - I plan on improving the emac driver in general but I'll be OoO until end of next week, so I decided to post it already for reviews.

Does anyone know what the status is on boards like twister, ea20 etc. that use davinci_emac, but don't use the driver model? Dropping them would make it easier to clean up this driver.

This patch applies on top of my previous series[1].

[1] https://lists.denx.de/pipermail/u-boot/2019-April/367236.html

 arch/arm/mach-davinci/cpu.c            |  13 ---
 arch/arm/mach-omap2/omap3/emac.c       |   3 +-
 board/davinci/da8xxevm/da850evm.c      |   5 --
 board/davinci/da8xxevm/omapl138_lcdk.c |  14 ----
 board/logicpd/am3517evm/am3517evm.c    |   1 -
 board/ti/ti816x/evm.c                  |   3 +-
 configs/am3517_evm_defconfig           |   1 +
 configs/da850_am18xxevm_defconfig      |   1 +
 configs/da850evm_defconfig             |   1 +
 configs/da850evm_direct_nor_defconfig  |   1 +
 configs/omapl138_lcdk_defconfig        |   1 +
 configs/ti816x_evm_defconfig           |   1 +
 drivers/net/ti/davinci_emac.c          | 109 +++++++++++++++++++++----
 13 files changed, 100 insertions(+), 54 deletions(-)
arch/arm/mach-davinci/cpu.c +0 -13
index f97ad3fc74..9fd6564d04 100644
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
@@ -90,15 +89,3 @@ int set_cpu_clk_info(void)
        gd->bd->bi_dsp_freq = 0;
        return 0;
 }
-
-/*
- * Initializes on-chip ethernet controllers.
- * to override, implement board_eth_init()
- */
-int cpu_eth_init(bd_t *bis)
-{
-#if defined(CONFIG_DRIVER_TI_EMAC)
-       davinci_emac_initialize();
-#endif
-       return 0;
-}
arch/arm/mach-omap2/omap3/emac.c +1 -2
index c79e870183..fb0c9188f5 100644
@@ -7,7 +7,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/am35x_def.h>
 
@@ -24,5 +23,5 @@ int cpu_eth_init(bd_t *bis)
        reset &= ~CPGMACSS_SW_RST;
        writel(reset, &am35x_scm_general_regs->ip_sw_reset);
 
-       return davinci_emac_initialize();
+       return 0;
 }
board/davinci/da8xxevm/da850evm.c +0 -5
index 1bc26828bf..0d2bc5fb32 100644
@@ -13,7 +13,6 @@
 #include <environment.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -472,10 +471,6 @@ int board_eth_init(bd_t *bis)
        if (rmii_hw_init())
                printf("RMII hardware init failed!!!\n");
 #endif
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
 
        return 0;
 }
board/davinci/da8xxevm/omapl138_lcdk.c +0 -14
index 2c2f885d43..ef9656add8 100644
@@ -11,7 +11,6 @@
 #include <common.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -229,19 +228,6 @@ int board_init(void)
 
 #ifdef CONFIG_DRIVER_TI_EMAC
 
-/*
- * Initializes on-board ethernet controllers.
- */
-int board_eth_init(bd_t *bis)
-{
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
 #define CFG_MAC_ADDR_SPI_BUS   0
board/logicpd/am3517evm/am3517evm.c +0 -1
index 10031a4801..bfd4e78274 100644
@@ -28,7 +28,6 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
 #include <i2c.h>
-#include <netdev.h>
 #include "am3517evm.h"
 
 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c +1 -2
index 07a084bab8..240df8cbe1 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <environment.h>
 #include <spl.h>
-#include <netdev.h>
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -56,7 +55,7 @@ int board_eth_init(bd_t *bis)
                        printf("Unable to read MAC address. Set <ethaddr>\n");
        }
 
-       return davinci_emac_initialize();
+       return 0;
 }
 
 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig +1 -0
index b9f59f3291..0ea28a20b2 100644
@@ -45,6 +45,7 @@ CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850_am18xxevm_defconfig +1 -0
index f098222113..6227cafc90 100644
@@ -52,6 +52,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/da850evm_defconfig +1 -0
index 221c204af0..78eadc6330 100644
@@ -60,6 +60,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850evm_direct_nor_defconfig +1 -0
index 166e77b8e3..2dd82d68b9 100644
@@ -51,6 +51,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/omapl138_lcdk_defconfig +1 -0
index e43141844a..0600ac3f4a 100644
@@ -51,6 +51,7 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/ti816x_evm_defconfig +1 -0
index bf877f596b..131b25a188 100644
@@ -46,6 +46,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
drivers/net/ti/davinci_emac.c +3 -1
index 9d53984973..3252a235d2 100644
@@ -26,11 +26,13 @@
 #include <net.h>
 #include <miiphy.h>
 #include <malloc.h>
-#include <netdev.h>
 #include <linux/compiler.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/io.h>
 #include "davinci_emac.h"
+#ifndef CONFIG_DM_ETH
+#include <netdev.h>
+#endif
 
 unsigned int   emac_dbg = 0;
 #define debug_emac(fmt,args...)        if (emac_dbg) printf(fmt,##args)

drivers/net/ti/davinci_emac.c static u_int8_t num_phy; · line 112

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -107,10 +109,16 @@ static u_int8_t   num_phy;
 
 phy_t                          phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 15 lines
drivers/net/ti/davinci_emac.c +7 -2
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_write_hwaddr(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       unsigned long           mac_hi;
-       unsigned long           mac_lo;
+#ifdef CONFIG_DM_ETH
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+#endif
+       unsigned long mac_hi, mac_lo;
 
        /*
         * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast

drivers/net/ti/davinci_emac.c static int davinci_eth_set_mac_addr(struct eth_device *dev) · line 130

Quoted 5 lines
drivers/net/ti/davinci_emac.c +2 -0
@@ -118,12 +126,22 @@ static int davinci_eth_set_mac_addr(struct eth_device *dev)
         *  Using channel 0 only - other channels are disabled
         *  */
        writel(0, &adap_emac->MACINDEX);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 18 lines
drivers/net/ti/davinci_emac.c +8 -0
        mac_hi = (dev->enetaddr[3] << 24) |
                 (dev->enetaddr[2] << 16) |
                 (dev->enetaddr[1] << 8)  |
                 (dev->enetaddr[0]);
        mac_lo = (dev->enetaddr[5] << 8) |
                 (dev->enetaddr[4]);
+#else /* with CONFIG_DM_ETH */
+       mac_hi = (pdata->enetaddr[3] << 24) |
+                (pdata->enetaddr[2] << 16) |
+                (pdata->enetaddr[1] << 8)  |
+                (pdata->enetaddr[0]);
+       mac_lo = (pdata->enetaddr[5] << 8) |
+                (pdata->enetaddr[4]);
+#endif /* CONFIG_DM_ETH */
 
        writel(mac_hi, &adap_emac->MACADDRHI);
 #if defined(DAVINCI_EMAC_VERSION2)

drivers/net/ti/davinci_emac.c static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr) · line 432

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -411,13 +429,17 @@ static void  __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr)
 }
 
 /* Eth device open */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 19 lines
drivers/net/ti/davinci_emac.c +8 -5
 static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_start(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       dv_reg_p                addr;
-       u_int32_t               clkdiv, cnt, mac_control;
-       uint16_t                __maybe_unused lpa_val;
-       volatile emac_desc      *rx_desc;
-       int                     index;
+       u32 clkdiv, cnt, mac_control;
+       volatile emac_desc *rx_desc;
+       u16 __maybe_unused lpa_val;
+       dv_reg_p addr;
+       int index;
 
        debug_emac("+ emac_open\n");
 

drivers/net/ti/davinci_emac.c static int davinci_eth_open(struct eth_device *dev, bd_t *bis) · line 472

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -447,7 +469,11 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        writel(1, &adap_emac->TXCONTROL);
        writel(1, &adap_emac->RXCONTROL);
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static void davinci_eth_ch_teardown(int ch) · line 617

Quoted 12 lines
drivers/net/ti/davinci_emac.c +4 -0
        davinci_eth_set_mac_addr(dev);
+#else /* with CONFIG_DM_ETH */
+       davinci_emac_write_hwaddr(dev);
+#endif /* CONFIG_DM_ETH */
 
        /* Set DMA 8 TX / 8 RX Head pointers to 0 */
        addr = &adap_emac->TX0HDP;
@@ -588,7 +614,11 @@ static void davinci_eth_ch_teardown(int ch)
 }
 
 /* Eth device close */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 8 lines
drivers/net/ti/davinci_emac.c +3 -0
 static void davinci_eth_close(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static void davinci_emac_stop(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
        debug_emac("+ emac_close\n");
 

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 652

Quoted 6 lines
drivers/net/ti/davinci_emac.c +1 -2
@@ -619,11 +649,15 @@ static int tx_send_loop = 0;
  * This function sends a single packet on the network and returns
  * positive number (number of bytes transmitted) or negative for error
  */
-static int davinci_eth_send_packet (struct eth_device *dev,
-                                       void *packet, int length)
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 660

Quoted 10 lines
drivers/net/ti/davinci_emac.c +7 -2
+static int davinci_eth_send_packet(struct eth_device *dev,
+                                  void *packet, int length)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_send(struct udevice *dev,
+                            void *packet, int length)
+#endif /* CONFIG_DM_ETH */
 {
-       int ret_status = -1;
-       int index;
+       int ret_status = -1, index;

I'm not sure why you are mixing these formatting changes (which look bad anyway) with the substantive changes. Please drop them.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 709

Quoted 8 lines
drivers/net/ti/davinci_emac.c +1 -0
        tx_send_loop = 0;
 
        index = get_active_phy();
@@ -672,7 +706,11 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 /*
  * This function handles receipt of a packet from the network
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 716

Quoted 7 lines
drivers/net/ti/davinci_emac.c +3 -0
 static int davinci_eth_rcv_packet (struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp)
+#endif /* CONFIG_DM_ETH */
 {
        volatile emac_desc *rx_curr_desc;
        volatile emac_desc *curr_desc;

Please remove the call to net_process_received_packet() and split the descriptor cleanup into a free_pkt() operation.

Quoted 11 lines
drivers/net/ti/davinci_emac.c +3 -0
@@ -742,6 +780,9 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                }
                return (ret);
        }
+#ifdef CONFIG_DM_ETH
+       *packetp = rx_curr_desc->buffer;
+#endif
        return (0);
 }
 

drivers/net/ti/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device *dev) · line 794

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -750,12 +791,16 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
  * EMAC modules power or pin multiplexors, that is done by board_init()
  * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 25 lines
drivers/net/ti/davinci_emac.c +8 -4
 int davinci_emac_initialize(void)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_probe(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       u_int32_t       phy_id;
-       u_int16_t       tmp;
-       int             i;
-       int             ret;
+       int i, ret;
+       u32 phy_id;
+       u16 tmp;
+#ifndef CONFIG_DM_ETH
        struct eth_device *dev;
 
        dev = malloc(sizeof *dev);
@@ -774,6 +819,7 @@ int davinci_emac_initialize(void)
        dev->write_hwaddr = davinci_eth_set_mac_addr;
 
        eth_register(dev);
+#endif /* CONFIG_DM_ETH */
 
        davinci_eth_mdio_enable();
 

drivers/net/ti/davinci_emac.c int davinci_emac_initialize(void) · line 904

Quoted 6 lines
drivers/net/ti/davinci_emac.c +2 -1
@@ -854,5 +900,34 @@ int davinci_emac_initialize(void)
                        phy[i].auto_negotiate(i);
        }
 #endif
-       return(1);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 36 lines
drivers/net/ti/davinci_emac.c +28 -1
+       return 1;
+#else /* with CONFIG_DM_ETH */
+       return 0;
+#endif /* CONFIG_DM_ETH */
 }
+
+#ifdef CONFIG_DM_ETH
+static const struct eth_ops davinci_emac_ops = {
+       .start          = davinci_emac_start,
+       .send           = davinci_emac_send,
+       .recv           = davinci_emac_recv,
+       .stop           = davinci_emac_stop,
+       .write_hwaddr   = davinci_emac_write_hwaddr,
+};
+
+static const struct udevice_id davinci_emac_ids[] = {
+       { .compatible = "ti,davinci-dm6467-emac" },
+       { }
+};
+
+U_BOOT_DRIVER(davinci_emac) = {
+       .name           = "davinci_emac",
+       .id             = UCLASS_ETH,
+       .of_match       = davinci_emac_ids,
+       .probe          = davinci_emac_probe,
+       .ops            = &davinci_emac_ops,
+       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
+#endif /* CONFIG_DM_ETH */
--

2.21.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#3 lore raw

PATCH 1/1 net: davinci_emac: use driver model (CONFIG_DM_ETH)

Quoted 29 lines · Bartosz Golaszewski

czw., 9 maj 2019 o 20:48 Joe Hershberger <[email protected]> napisaÅ‚(a):

Quoted 13 lines · Bartosz Golaszewski
Quoted 8 lines

From: Bartosz Golaszewski <[email protected]>

Add support for CONFIG_DM_ETH to the davinci_emac driver. Optimally we should only support DM-enabled platforms but there are several non-DT boards that still use it so either we need to keep supporting it or drop the boards from u-boot. For now we're stuck with ugly ifdefs.

Which boards are still not using DM that you refer to here?

The following configs define CONFIG_DRIVER_TI_EMAC=y and don't define CONFIG_DM=y:

am3517_evm_defconfig
calimain_defconfig
cm_t3517_defconfig
ea20_defconfig
eco5pk_defconfig
ipam390_defconfig
mcx_defconfig
mt_ventoux_defconfig
twister_defconfig

Quoted 1 line

Are these still maintained?

I am still maintaining the am3517_evm. Config DM is being set for it. The following are set in Kconfig:
select DM
select DM_GPIO
select DM_I2C
select DM_MMC
select DM_SERIAL
imply CMD_DM

The last time I ran some spot checks the ethernet was working. I haven't checked lately. Is there something you need me to check?

adam

Quoted 513 lines

Best regards,
Bartosz Golaszewski

Quoted 509 lines
Quoted 263 lines

This patch adds support for driver-model to the driver and converts all platforms that use the driver model to selecting CONFIG_DM_ETH.

Tested on da850-evm and da850-lcdk.

---
NOTE: I'm currently working on modernizing da850 support in u-boot. This patch is just the first step - I plan on improving the emac driver in general but I'll be OoO until end of next week, so I decided to post it already for reviews.

Does anyone know what the status is on boards like twister, ea20 etc. that use davinci_emac, but don't use the driver model? Dropping them would make it easier to clean up this driver.

This patch applies on top of my previous series[1].

[1] https://lists.denx.de/pipermail/u-boot/2019-April/367236.html

 arch/arm/mach-davinci/cpu.c            |  13 ---
 arch/arm/mach-omap2/omap3/emac.c       |   3 +-
 board/davinci/da8xxevm/da850evm.c      |   5 --
 board/davinci/da8xxevm/omapl138_lcdk.c |  14 ----
 board/logicpd/am3517evm/am3517evm.c    |   1 -
 board/ti/ti816x/evm.c                  |   3 +-
 configs/am3517_evm_defconfig           |   1 +
 configs/da850_am18xxevm_defconfig      |   1 +
 configs/da850evm_defconfig             |   1 +
 configs/da850evm_direct_nor_defconfig  |   1 +
 configs/omapl138_lcdk_defconfig        |   1 +
 configs/ti816x_evm_defconfig           |   1 +
 drivers/net/ti/davinci_emac.c          | 109 +++++++++++++++++++++----
 13 files changed, 100 insertions(+), 54 deletions(-)
arch/arm/mach-davinci/cpu.c +0 -13
index f97ad3fc74..9fd6564d04 100644
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
@@ -90,15 +89,3 @@ int set_cpu_clk_info(void)
        gd->bd->bi_dsp_freq = 0;
        return 0;
 }
-
-/*
- * Initializes on-chip ethernet controllers.
- * to override, implement board_eth_init()
- */
-int cpu_eth_init(bd_t *bis)
-{
-#if defined(CONFIG_DRIVER_TI_EMAC)
-       davinci_emac_initialize();
-#endif
-       return 0;
-}
arch/arm/mach-omap2/omap3/emac.c +1 -2
index c79e870183..fb0c9188f5 100644
@@ -7,7 +7,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/am35x_def.h>
 
@@ -24,5 +23,5 @@ int cpu_eth_init(bd_t *bis)
        reset &= ~CPGMACSS_SW_RST;
        writel(reset, &am35x_scm_general_regs->ip_sw_reset);
 
-       return davinci_emac_initialize();
+       return 0;
 }
board/davinci/da8xxevm/da850evm.c +0 -5
index 1bc26828bf..0d2bc5fb32 100644
@@ -13,7 +13,6 @@
 #include <environment.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -472,10 +471,6 @@ int board_eth_init(bd_t *bis)
        if (rmii_hw_init())
                printf("RMII hardware init failed!!!\n");
 #endif
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
 
        return 0;
 }
board/davinci/da8xxevm/omapl138_lcdk.c +0 -14
index 2c2f885d43..ef9656add8 100644
@@ -11,7 +11,6 @@
 #include <common.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -229,19 +228,6 @@ int board_init(void)
 
 #ifdef CONFIG_DRIVER_TI_EMAC
 
-/*
- * Initializes on-board ethernet controllers.
- */
-int board_eth_init(bd_t *bis)
-{
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
 #define CFG_MAC_ADDR_SPI_BUS   0
board/logicpd/am3517evm/am3517evm.c +0 -1
index 10031a4801..bfd4e78274 100644
@@ -28,7 +28,6 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
 #include <i2c.h>
-#include <netdev.h>
 #include "am3517evm.h"
 
 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c +1 -2
index 07a084bab8..240df8cbe1 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <environment.h>
 #include <spl.h>
-#include <netdev.h>
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -56,7 +55,7 @@ int board_eth_init(bd_t *bis)
                        printf("Unable to read MAC address. Set <ethaddr>\n");
        }
 
-       return davinci_emac_initialize();
+       return 0;
 }
 
 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig +1 -0
index b9f59f3291..0ea28a20b2 100644
@@ -45,6 +45,7 @@ CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850_am18xxevm_defconfig +1 -0
index f098222113..6227cafc90 100644
@@ -52,6 +52,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/da850evm_defconfig +1 -0
index 221c204af0..78eadc6330 100644
@@ -60,6 +60,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850evm_direct_nor_defconfig +1 -0
index 166e77b8e3..2dd82d68b9 100644
@@ -51,6 +51,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/omapl138_lcdk_defconfig +1 -0
index e43141844a..0600ac3f4a 100644
@@ -51,6 +51,7 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/ti816x_evm_defconfig +1 -0
index bf877f596b..131b25a188 100644
@@ -46,6 +46,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
drivers/net/ti/davinci_emac.c +3 -1
index 9d53984973..3252a235d2 100644
@@ -26,11 +26,13 @@
 #include <net.h>
 #include <miiphy.h>
 #include <malloc.h>
-#include <netdev.h>
 #include <linux/compiler.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/io.h>
 #include "davinci_emac.h"
+#ifndef CONFIG_DM_ETH
+#include <netdev.h>
+#endif
 
 unsigned int   emac_dbg = 0;
 #define debug_emac(fmt,args...)        if (emac_dbg) printf(fmt,##args)

drivers/net/ti/davinci_emac.c static u_int8_t num_phy; · line 112

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -107,10 +109,16 @@ static u_int8_t   num_phy;
 
 phy_t                          phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 15 lines
drivers/net/ti/davinci_emac.c +7 -2
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_write_hwaddr(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       unsigned long           mac_hi;
-       unsigned long           mac_lo;
+#ifdef CONFIG_DM_ETH
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+#endif
+       unsigned long mac_hi, mac_lo;
 
        /*
         * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast

drivers/net/ti/davinci_emac.c static int davinci_eth_set_mac_addr(struct eth_device *dev) · line 130

Quoted 5 lines
drivers/net/ti/davinci_emac.c +2 -0
@@ -118,12 +126,22 @@ static int davinci_eth_set_mac_addr(struct eth_device *dev)
         *  Using channel 0 only - other channels are disabled
         *  */
        writel(0, &adap_emac->MACINDEX);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 18 lines
drivers/net/ti/davinci_emac.c +8 -0
        mac_hi = (dev->enetaddr[3] << 24) |
                 (dev->enetaddr[2] << 16) |
                 (dev->enetaddr[1] << 8)  |
                 (dev->enetaddr[0]);
        mac_lo = (dev->enetaddr[5] << 8) |
                 (dev->enetaddr[4]);
+#else /* with CONFIG_DM_ETH */
+       mac_hi = (pdata->enetaddr[3] << 24) |
+                (pdata->enetaddr[2] << 16) |
+                (pdata->enetaddr[1] << 8)  |
+                (pdata->enetaddr[0]);
+       mac_lo = (pdata->enetaddr[5] << 8) |
+                (pdata->enetaddr[4]);
+#endif /* CONFIG_DM_ETH */
 
        writel(mac_hi, &adap_emac->MACADDRHI);
 #if defined(DAVINCI_EMAC_VERSION2)

drivers/net/ti/davinci_emac.c static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr) · line 432

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -411,13 +429,17 @@ static void  __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr)
 }
 
 /* Eth device open */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 19 lines
drivers/net/ti/davinci_emac.c +8 -5
 static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_start(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       dv_reg_p                addr;
-       u_int32_t               clkdiv, cnt, mac_control;
-       uint16_t                __maybe_unused lpa_val;
-       volatile emac_desc      *rx_desc;
-       int                     index;
+       u32 clkdiv, cnt, mac_control;
+       volatile emac_desc *rx_desc;
+       u16 __maybe_unused lpa_val;
+       dv_reg_p addr;
+       int index;
 
        debug_emac("+ emac_open\n");
 

drivers/net/ti/davinci_emac.c static int davinci_eth_open(struct eth_device *dev, bd_t *bis) · line 472

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -447,7 +469,11 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        writel(1, &adap_emac->TXCONTROL);
        writel(1, &adap_emac->RXCONTROL);
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static void davinci_eth_ch_teardown(int ch) · line 617

Quoted 12 lines
drivers/net/ti/davinci_emac.c +4 -0
        davinci_eth_set_mac_addr(dev);
+#else /* with CONFIG_DM_ETH */
+       davinci_emac_write_hwaddr(dev);
+#endif /* CONFIG_DM_ETH */
 
        /* Set DMA 8 TX / 8 RX Head pointers to 0 */
        addr = &adap_emac->TX0HDP;
@@ -588,7 +614,11 @@ static void davinci_eth_ch_teardown(int ch)
 }
 
 /* Eth device close */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 8 lines
drivers/net/ti/davinci_emac.c +3 -0
 static void davinci_eth_close(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static void davinci_emac_stop(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
        debug_emac("+ emac_close\n");
 

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 652

Quoted 6 lines
drivers/net/ti/davinci_emac.c +1 -2
@@ -619,11 +649,15 @@ static int tx_send_loop = 0;
  * This function sends a single packet on the network and returns
  * positive number (number of bytes transmitted) or negative for error
  */
-static int davinci_eth_send_packet (struct eth_device *dev,
-                                       void *packet, int length)
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 660

Quoted 10 lines
drivers/net/ti/davinci_emac.c +7 -2
+static int davinci_eth_send_packet(struct eth_device *dev,
+                                  void *packet, int length)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_send(struct udevice *dev,
+                            void *packet, int length)
+#endif /* CONFIG_DM_ETH */
 {
-       int ret_status = -1;
-       int index;
+       int ret_status = -1, index;

I'm not sure why you are mixing these formatting changes (which look bad anyway) with the substantive changes. Please drop them.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 709

Quoted 8 lines
drivers/net/ti/davinci_emac.c +1 -0
        tx_send_loop = 0;
 
        index = get_active_phy();
@@ -672,7 +706,11 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 /*
  * This function handles receipt of a packet from the network
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 716

Quoted 7 lines
drivers/net/ti/davinci_emac.c +3 -0
 static int davinci_eth_rcv_packet (struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp)
+#endif /* CONFIG_DM_ETH */
 {
        volatile emac_desc *rx_curr_desc;
        volatile emac_desc *curr_desc;

Please remove the call to net_process_received_packet() and split the descriptor cleanup into a free_pkt() operation.

Quoted 11 lines
drivers/net/ti/davinci_emac.c +3 -0
@@ -742,6 +780,9 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                }
                return (ret);
        }
+#ifdef CONFIG_DM_ETH
+       *packetp = rx_curr_desc->buffer;
+#endif
        return (0);
 }
 

drivers/net/ti/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device *dev) · line 794

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -750,12 +791,16 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
  * EMAC modules power or pin multiplexors, that is done by board_init()
  * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 25 lines
drivers/net/ti/davinci_emac.c +8 -4
 int davinci_emac_initialize(void)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_probe(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       u_int32_t       phy_id;
-       u_int16_t       tmp;
-       int             i;
-       int             ret;
+       int i, ret;
+       u32 phy_id;
+       u16 tmp;
+#ifndef CONFIG_DM_ETH
        struct eth_device *dev;
 
        dev = malloc(sizeof *dev);
@@ -774,6 +819,7 @@ int davinci_emac_initialize(void)
        dev->write_hwaddr = davinci_eth_set_mac_addr;
 
        eth_register(dev);
+#endif /* CONFIG_DM_ETH */
 
        davinci_eth_mdio_enable();
 

drivers/net/ti/davinci_emac.c int davinci_emac_initialize(void) · line 904

Quoted 6 lines
drivers/net/ti/davinci_emac.c +2 -1
@@ -854,5 +900,34 @@ int davinci_emac_initialize(void)
                        phy[i].auto_negotiate(i);
        }
 #endif
-       return(1);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 36 lines
drivers/net/ti/davinci_emac.c +28 -1
+       return 1;
+#else /* with CONFIG_DM_ETH */
+       return 0;
+#endif /* CONFIG_DM_ETH */
 }
+
+#ifdef CONFIG_DM_ETH
+static const struct eth_ops davinci_emac_ops = {
+       .start          = davinci_emac_start,
+       .send           = davinci_emac_send,
+       .recv           = davinci_emac_recv,
+       .stop           = davinci_emac_stop,
+       .write_hwaddr   = davinci_emac_write_hwaddr,
+};
+
+static const struct udevice_id davinci_emac_ids[] = {
+       { .compatible = "ti,davinci-dm6467-emac" },
+       { }
+};
+
+U_BOOT_DRIVER(davinci_emac) = {
+       .name           = "davinci_emac",
+       .id             = UCLASS_ETH,
+       .of_match       = davinci_emac_ids,
+       .probe          = davinci_emac_probe,
+       .ops            = &davinci_emac_ops,
+       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
+#endif /* CONFIG_DM_ETH */
--

2.21.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#4 lore raw

PATCH 1/1 net: davinci_emac: use driver model (CONFIG_DM_ETH)

pt., 10 maj 2019 o 14:31 Adam Ford <[email protected]> napisał(a):

Quoted 42 lines · Bartosz Golaszewski
Quoted 29 lines

czw., 9 maj 2019 o 20:48 Joe Hershberger <[email protected]> napisał(a):

Quoted 13 lines · Bartosz Golaszewski
Quoted 8 lines

From: Bartosz Golaszewski <[email protected]>

Add support for CONFIG_DM_ETH to the davinci_emac driver. Optimally we should only support DM-enabled platforms but there are several non-DT boards that still use it so either we need to keep supporting it or drop the boards from u-boot. For now we're stuck with ugly ifdefs.

Which boards are still not using DM that you refer to here?

The following configs define CONFIG_DRIVER_TI_EMAC=y and don't define CONFIG_DM=y:

am3517_evm_defconfig
calimain_defconfig
cm_t3517_defconfig
ea20_defconfig
eco5pk_defconfig
ipam390_defconfig
mcx_defconfig
mt_ventoux_defconfig
twister_defconfig

Quoted 1 line

Are these still maintained?

I am still maintaining the am3517_evm. Config DM is being set for it. The following are set in Kconfig:
select DM
select DM_GPIO
select DM_I2C
select DM_MMC
select DM_SERIAL
imply CMD_DM

Quoted 3 lines

The last time I ran some spot checks the ethernet was working. I haven't checked lately. Is there something you need me to check?

Ok, so I need to go through these and see if DM is not selected from Kconfig. I'm pretty sure there was at least one for which the build broke if I dropped the emac initialization function. Let me check...

Bart

Quoted 514 lines

adam

Quoted 513 lines

Best regards,
Bartosz Golaszewski

Quoted 509 lines
Quoted 263 lines

This patch adds support for driver-model to the driver and converts all platforms that use the driver model to selecting CONFIG_DM_ETH.

Tested on da850-evm and da850-lcdk.

---
NOTE: I'm currently working on modernizing da850 support in u-boot. This patch is just the first step - I plan on improving the emac driver in general but I'll be OoO until end of next week, so I decided to post it already for reviews.

Does anyone know what the status is on boards like twister, ea20 etc. that use davinci_emac, but don't use the driver model? Dropping them would make it easier to clean up this driver.

This patch applies on top of my previous series[1].

[1] https://lists.denx.de/pipermail/u-boot/2019-April/367236.html

 arch/arm/mach-davinci/cpu.c            |  13 ---
 arch/arm/mach-omap2/omap3/emac.c       |   3 +-
 board/davinci/da8xxevm/da850evm.c      |   5 --
 board/davinci/da8xxevm/omapl138_lcdk.c |  14 ----
 board/logicpd/am3517evm/am3517evm.c    |   1 -
 board/ti/ti816x/evm.c                  |   3 +-
 configs/am3517_evm_defconfig           |   1 +
 configs/da850_am18xxevm_defconfig      |   1 +
 configs/da850evm_defconfig             |   1 +
 configs/da850evm_direct_nor_defconfig  |   1 +
 configs/omapl138_lcdk_defconfig        |   1 +
 configs/ti816x_evm_defconfig           |   1 +
 drivers/net/ti/davinci_emac.c          | 109 +++++++++++++++++++++----
 13 files changed, 100 insertions(+), 54 deletions(-)
arch/arm/mach-davinci/cpu.c +0 -13
index f97ad3fc74..9fd6564d04 100644
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
@@ -90,15 +89,3 @@ int set_cpu_clk_info(void)
        gd->bd->bi_dsp_freq = 0;
        return 0;
 }
-
-/*
- * Initializes on-chip ethernet controllers.
- * to override, implement board_eth_init()
- */
-int cpu_eth_init(bd_t *bis)
-{
-#if defined(CONFIG_DRIVER_TI_EMAC)
-       davinci_emac_initialize();
-#endif
-       return 0;
-}
arch/arm/mach-omap2/omap3/emac.c +1 -2
index c79e870183..fb0c9188f5 100644
@@ -7,7 +7,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/am35x_def.h>
 
@@ -24,5 +23,5 @@ int cpu_eth_init(bd_t *bis)
        reset &= ~CPGMACSS_SW_RST;
        writel(reset, &am35x_scm_general_regs->ip_sw_reset);
 
-       return davinci_emac_initialize();
+       return 0;
 }
board/davinci/da8xxevm/da850evm.c +0 -5
index 1bc26828bf..0d2bc5fb32 100644
@@ -13,7 +13,6 @@
 #include <environment.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -472,10 +471,6 @@ int board_eth_init(bd_t *bis)
        if (rmii_hw_init())
                printf("RMII hardware init failed!!!\n");
 #endif
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
 
        return 0;
 }
board/davinci/da8xxevm/omapl138_lcdk.c +0 -14
index 2c2f885d43..ef9656add8 100644
@@ -11,7 +11,6 @@
 #include <common.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -229,19 +228,6 @@ int board_init(void)
 
 #ifdef CONFIG_DRIVER_TI_EMAC
 
-/*
- * Initializes on-board ethernet controllers.
- */
-int board_eth_init(bd_t *bis)
-{
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
 #define CFG_MAC_ADDR_SPI_BUS   0
board/logicpd/am3517evm/am3517evm.c +0 -1
index 10031a4801..bfd4e78274 100644
@@ -28,7 +28,6 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
 #include <i2c.h>
-#include <netdev.h>
 #include "am3517evm.h"
 
 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c +1 -2
index 07a084bab8..240df8cbe1 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <environment.h>
 #include <spl.h>
-#include <netdev.h>
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -56,7 +55,7 @@ int board_eth_init(bd_t *bis)
                        printf("Unable to read MAC address. Set <ethaddr>\n");
        }
 
-       return davinci_emac_initialize();
+       return 0;
 }
 
 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig +1 -0
index b9f59f3291..0ea28a20b2 100644
@@ -45,6 +45,7 @@ CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850_am18xxevm_defconfig +1 -0
index f098222113..6227cafc90 100644
@@ -52,6 +52,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/da850evm_defconfig +1 -0
index 221c204af0..78eadc6330 100644
@@ -60,6 +60,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850evm_direct_nor_defconfig +1 -0
index 166e77b8e3..2dd82d68b9 100644
@@ -51,6 +51,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/omapl138_lcdk_defconfig +1 -0
index e43141844a..0600ac3f4a 100644
@@ -51,6 +51,7 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/ti816x_evm_defconfig +1 -0
index bf877f596b..131b25a188 100644
@@ -46,6 +46,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
drivers/net/ti/davinci_emac.c +3 -1
index 9d53984973..3252a235d2 100644
@@ -26,11 +26,13 @@
 #include <net.h>
 #include <miiphy.h>
 #include <malloc.h>
-#include <netdev.h>
 #include <linux/compiler.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/io.h>
 #include "davinci_emac.h"
+#ifndef CONFIG_DM_ETH
+#include <netdev.h>
+#endif
 
 unsigned int   emac_dbg = 0;
 #define debug_emac(fmt,args...)        if (emac_dbg) printf(fmt,##args)

drivers/net/ti/davinci_emac.c static u_int8_t num_phy; · line 112

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -107,10 +109,16 @@ static u_int8_t   num_phy;
 
 phy_t                          phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 15 lines
drivers/net/ti/davinci_emac.c +7 -2
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_write_hwaddr(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       unsigned long           mac_hi;
-       unsigned long           mac_lo;
+#ifdef CONFIG_DM_ETH
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+#endif
+       unsigned long mac_hi, mac_lo;
 
        /*
         * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast

drivers/net/ti/davinci_emac.c static int davinci_eth_set_mac_addr(struct eth_device *dev) · line 130

Quoted 5 lines
drivers/net/ti/davinci_emac.c +2 -0
@@ -118,12 +126,22 @@ static int davinci_eth_set_mac_addr(struct eth_device *dev)
         *  Using channel 0 only - other channels are disabled
         *  */
        writel(0, &adap_emac->MACINDEX);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 18 lines
drivers/net/ti/davinci_emac.c +8 -0
        mac_hi = (dev->enetaddr[3] << 24) |
                 (dev->enetaddr[2] << 16) |
                 (dev->enetaddr[1] << 8)  |
                 (dev->enetaddr[0]);
        mac_lo = (dev->enetaddr[5] << 8) |
                 (dev->enetaddr[4]);
+#else /* with CONFIG_DM_ETH */
+       mac_hi = (pdata->enetaddr[3] << 24) |
+                (pdata->enetaddr[2] << 16) |
+                (pdata->enetaddr[1] << 8)  |
+                (pdata->enetaddr[0]);
+       mac_lo = (pdata->enetaddr[5] << 8) |
+                (pdata->enetaddr[4]);
+#endif /* CONFIG_DM_ETH */
 
        writel(mac_hi, &adap_emac->MACADDRHI);
 #if defined(DAVINCI_EMAC_VERSION2)

drivers/net/ti/davinci_emac.c static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr) · line 432

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -411,13 +429,17 @@ static void  __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr)
 }
 
 /* Eth device open */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 19 lines
drivers/net/ti/davinci_emac.c +8 -5
 static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_start(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       dv_reg_p                addr;
-       u_int32_t               clkdiv, cnt, mac_control;
-       uint16_t                __maybe_unused lpa_val;
-       volatile emac_desc      *rx_desc;
-       int                     index;
+       u32 clkdiv, cnt, mac_control;
+       volatile emac_desc *rx_desc;
+       u16 __maybe_unused lpa_val;
+       dv_reg_p addr;
+       int index;
 
        debug_emac("+ emac_open\n");
 

drivers/net/ti/davinci_emac.c static int davinci_eth_open(struct eth_device *dev, bd_t *bis) · line 472

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -447,7 +469,11 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        writel(1, &adap_emac->TXCONTROL);
        writel(1, &adap_emac->RXCONTROL);
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static void davinci_eth_ch_teardown(int ch) · line 617

Quoted 12 lines
drivers/net/ti/davinci_emac.c +4 -0
        davinci_eth_set_mac_addr(dev);
+#else /* with CONFIG_DM_ETH */
+       davinci_emac_write_hwaddr(dev);
+#endif /* CONFIG_DM_ETH */
 
        /* Set DMA 8 TX / 8 RX Head pointers to 0 */
        addr = &adap_emac->TX0HDP;
@@ -588,7 +614,11 @@ static void davinci_eth_ch_teardown(int ch)
 }
 
 /* Eth device close */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 8 lines
drivers/net/ti/davinci_emac.c +3 -0
 static void davinci_eth_close(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static void davinci_emac_stop(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
        debug_emac("+ emac_close\n");
 

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 652

Quoted 6 lines
drivers/net/ti/davinci_emac.c +1 -2
@@ -619,11 +649,15 @@ static int tx_send_loop = 0;
  * This function sends a single packet on the network and returns
  * positive number (number of bytes transmitted) or negative for error
  */
-static int davinci_eth_send_packet (struct eth_device *dev,
-                                       void *packet, int length)
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 660

Quoted 10 lines
drivers/net/ti/davinci_emac.c +7 -2
+static int davinci_eth_send_packet(struct eth_device *dev,
+                                  void *packet, int length)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_send(struct udevice *dev,
+                            void *packet, int length)
+#endif /* CONFIG_DM_ETH */
 {
-       int ret_status = -1;
-       int index;
+       int ret_status = -1, index;

I'm not sure why you are mixing these formatting changes (which look bad anyway) with the substantive changes. Please drop them.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 709

Quoted 8 lines
drivers/net/ti/davinci_emac.c +1 -0
        tx_send_loop = 0;
 
        index = get_active_phy();
@@ -672,7 +706,11 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 /*
  * This function handles receipt of a packet from the network
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 716

Quoted 7 lines
drivers/net/ti/davinci_emac.c +3 -0
 static int davinci_eth_rcv_packet (struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp)
+#endif /* CONFIG_DM_ETH */
 {
        volatile emac_desc *rx_curr_desc;
        volatile emac_desc *curr_desc;

Please remove the call to net_process_received_packet() and split the descriptor cleanup into a free_pkt() operation.

Quoted 11 lines
drivers/net/ti/davinci_emac.c +3 -0
@@ -742,6 +780,9 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                }
                return (ret);
        }
+#ifdef CONFIG_DM_ETH
+       *packetp = rx_curr_desc->buffer;
+#endif
        return (0);
 }
 

drivers/net/ti/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device *dev) · line 794

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -750,12 +791,16 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
  * EMAC modules power or pin multiplexors, that is done by board_init()
  * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 25 lines
drivers/net/ti/davinci_emac.c +8 -4
 int davinci_emac_initialize(void)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_probe(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       u_int32_t       phy_id;
-       u_int16_t       tmp;
-       int             i;
-       int             ret;
+       int i, ret;
+       u32 phy_id;
+       u16 tmp;
+#ifndef CONFIG_DM_ETH
        struct eth_device *dev;
 
        dev = malloc(sizeof *dev);
@@ -774,6 +819,7 @@ int davinci_emac_initialize(void)
        dev->write_hwaddr = davinci_eth_set_mac_addr;
 
        eth_register(dev);
+#endif /* CONFIG_DM_ETH */
 
        davinci_eth_mdio_enable();
 

drivers/net/ti/davinci_emac.c int davinci_emac_initialize(void) · line 904

Quoted 6 lines
drivers/net/ti/davinci_emac.c +2 -1
@@ -854,5 +900,34 @@ int davinci_emac_initialize(void)
                        phy[i].auto_negotiate(i);
        }
 #endif
-       return(1);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 36 lines
drivers/net/ti/davinci_emac.c +28 -1
+       return 1;
+#else /* with CONFIG_DM_ETH */
+       return 0;
+#endif /* CONFIG_DM_ETH */
 }
+
+#ifdef CONFIG_DM_ETH
+static const struct eth_ops davinci_emac_ops = {
+       .start          = davinci_emac_start,
+       .send           = davinci_emac_send,
+       .recv           = davinci_emac_recv,
+       .stop           = davinci_emac_stop,
+       .write_hwaddr   = davinci_emac_write_hwaddr,
+};
+
+static const struct udevice_id davinci_emac_ids[] = {
+       { .compatible = "ti,davinci-dm6467-emac" },
+       { }
+};
+
+U_BOOT_DRIVER(davinci_emac) = {
+       .name           = "davinci_emac",
+       .id             = UCLASS_ETH,
+       .of_match       = davinci_emac_ids,
+       .probe          = davinci_emac_probe,
+       .ops            = &davinci_emac_ops,
+       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
+#endif /* CONFIG_DM_ETH */
--

2.21.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#5 lore raw

PATCH 1/1 net: davinci_emac: use driver model (CONFIG_DM_ETH)

pt., 10 maj 2019 o 14:51 Bartosz Golaszewski <[email protected]> napisał(a):

Quoted 44 lines

pt., 10 maj 2019 o 14:31 Adam Ford <[email protected]> napisał(a):

Quoted 42 lines · Bartosz Golaszewski
Quoted 29 lines

czw., 9 maj 2019 o 20:48 Joe Hershberger <[email protected]> napisał(a):

Quoted 13 lines · Bartosz Golaszewski
Quoted 8 lines

From: Bartosz Golaszewski <[email protected]>

Add support for CONFIG_DM_ETH to the davinci_emac driver. Optimally we should only support DM-enabled platforms but there are several non-DT boards that still use it so either we need to keep supporting it or drop the boards from u-boot. For now we're stuck with ugly ifdefs.

Which boards are still not using DM that you refer to here?

The following configs define CONFIG_DRIVER_TI_EMAC=y and don't define CONFIG_DM=y:

am3517_evm_defconfig
calimain_defconfig
cm_t3517_defconfig
ea20_defconfig
eco5pk_defconfig
ipam390_defconfig
mcx_defconfig
mt_ventoux_defconfig
twister_defconfig

Quoted 1 line

Are these still maintained?

I am still maintaining the am3517_evm. Config DM is being set for it. The following are set in Kconfig:
select DM
select DM_GPIO
select DM_I2C
select DM_MMC
select DM_SERIAL
imply CMD_DM

Quoted 8 lines
Quoted 3 lines

The last time I ran some spot checks the ethernet was working. I haven't checked lately. Is there something you need me to check?

Ok, so I need to go through these and see if DM is not selected from Kconfig. I'm pretty sure there was at least one for which the build broke if I dropped the emac initialization function. Let me check...

Ok, confirmed that the following configs DO NOT select CONFIG_DM in any way:

calimain_defconfig
cm_t3517_defconfig
ea20_defconfig
eco5pk_defconfig
ipam390_defconfig
mcx_defconfig
mt_ventoux_defconfig
twister_defconfig

I Cc'ed some of the maintainers:

+ Manfred, Christoph, Igor, Sefano, Raphael, Heiko, Anatloij

Hi guys,

do you have any plans to add support for the driver model for these platforms?

Best regards,
Bartosz Golaszewski

Quoted 516 lines

Bart

Quoted 514 lines

adam

Quoted 513 lines

Best regards,
Bartosz Golaszewski

Quoted 509 lines
Quoted 263 lines

This patch adds support for driver-model to the driver and converts all platforms that use the driver model to selecting CONFIG_DM_ETH.

Tested on da850-evm and da850-lcdk.

---
NOTE: I'm currently working on modernizing da850 support in u-boot. This patch is just the first step - I plan on improving the emac driver in general but I'll be OoO until end of next week, so I decided to post it already for reviews.

Does anyone know what the status is on boards like twister, ea20 etc. that use davinci_emac, but don't use the driver model? Dropping them would make it easier to clean up this driver.

This patch applies on top of my previous series[1].

[1] https://lists.denx.de/pipermail/u-boot/2019-April/367236.html

 arch/arm/mach-davinci/cpu.c            |  13 ---
 arch/arm/mach-omap2/omap3/emac.c       |   3 +-
 board/davinci/da8xxevm/da850evm.c      |   5 --
 board/davinci/da8xxevm/omapl138_lcdk.c |  14 ----
 board/logicpd/am3517evm/am3517evm.c    |   1 -
 board/ti/ti816x/evm.c                  |   3 +-
 configs/am3517_evm_defconfig           |   1 +
 configs/da850_am18xxevm_defconfig      |   1 +
 configs/da850evm_defconfig             |   1 +
 configs/da850evm_direct_nor_defconfig  |   1 +
 configs/omapl138_lcdk_defconfig        |   1 +
 configs/ti816x_evm_defconfig           |   1 +
 drivers/net/ti/davinci_emac.c          | 109 +++++++++++++++++++++----
 13 files changed, 100 insertions(+), 54 deletions(-)
arch/arm/mach-davinci/cpu.c +0 -13
index f97ad3fc74..9fd6564d04 100644
@@ -5,7 +5,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/arch/hardware.h>
 #include <asm/io.h>
 
@@ -90,15 +89,3 @@ int set_cpu_clk_info(void)
        gd->bd->bi_dsp_freq = 0;
        return 0;
 }
-
-/*
- * Initializes on-chip ethernet controllers.
- * to override, implement board_eth_init()
- */
-int cpu_eth_init(bd_t *bis)
-{
-#if defined(CONFIG_DRIVER_TI_EMAC)
-       davinci_emac_initialize();
-#endif
-       return 0;
-}
arch/arm/mach-omap2/omap3/emac.c +1 -2
index c79e870183..fb0c9188f5 100644
@@ -7,7 +7,6 @@
  */
 
 #include <common.h>
-#include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/am35x_def.h>
 
@@ -24,5 +23,5 @@ int cpu_eth_init(bd_t *bis)
        reset &= ~CPGMACSS_SW_RST;
        writel(reset, &am35x_scm_general_regs->ip_sw_reset);
 
-       return davinci_emac_initialize();
+       return 0;
 }
board/davinci/da8xxevm/da850evm.c +0 -5
index 1bc26828bf..0d2bc5fb32 100644
@@ -13,7 +13,6 @@
 #include <environment.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -472,10 +471,6 @@ int board_eth_init(bd_t *bis)
        if (rmii_hw_init())
                printf("RMII hardware init failed!!!\n");
 #endif
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
 
        return 0;
 }
board/davinci/da8xxevm/omapl138_lcdk.c +0 -14
index 2c2f885d43..ef9656add8 100644
@@ -11,7 +11,6 @@
 #include <common.h>
 #include <i2c.h>
 #include <net.h>
-#include <netdev.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <asm/arch/hardware.h>
@@ -229,19 +228,6 @@ int board_init(void)
 
 #ifdef CONFIG_DRIVER_TI_EMAC
 
-/*
- * Initializes on-board ethernet controllers.
- */
-int board_eth_init(bd_t *bis)
-{
-       if (!davinci_emac_initialize()) {
-               printf("Error: Ethernet init failed!\n");
-               return -1;
-       }
-
-       return 0;
-}
-
 #endif /* CONFIG_DRIVER_TI_EMAC */
 
 #define CFG_MAC_ADDR_SPI_BUS   0
board/logicpd/am3517evm/am3517evm.c +0 -1
index 10031a4801..bfd4e78274 100644
@@ -28,7 +28,6 @@
 #include <linux/usb/gadget.h>
 #include <linux/usb/musb.h>
 #include <i2c.h>
-#include <netdev.h>
 #include "am3517evm.h"
 
 DECLARE_GLOBAL_DATA_PTR;
board/ti/ti816x/evm.c +1 -2
index 07a084bab8..240df8cbe1 100644
@@ -9,7 +9,6 @@
 #include <common.h>
 #include <environment.h>
 #include <spl.h>
-#include <netdev.h>
 #include <asm/cache.h>
 #include <asm/io.h>
 #include <asm/arch/clock.h>
@@ -56,7 +55,7 @@ int board_eth_init(bd_t *bis)
                        printf("Unable to read MAC address. Set <ethaddr>\n");
        }
 
-       return davinci_emac_initialize();
+       return 0;
 }
 
 #ifdef CONFIG_SPL_BUILD
configs/am3517_evm_defconfig +1 -0
index b9f59f3291..0ea28a20b2 100644
@@ -45,6 +45,7 @@ CONFIG_SYS_NAND_U_BOOT_LOCATIONS=y
 CONFIG_SYS_NAND_U_BOOT_OFFS=0x80000
 CONFIG_SPL_NAND_SIMPLE=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850_am18xxevm_defconfig +1 -0
index f098222113..6227cafc90 100644
@@ -52,6 +52,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/da850evm_defconfig +1 -0
index 221c204af0..78eadc6330 100644
@@ -60,6 +60,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/da850evm_direct_nor_defconfig +1 -0
index 166e77b8e3..2dd82d68b9 100644
@@ -51,6 +51,7 @@ CONFIG_SPI_FLASH=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_PINCTRL=y
 CONFIG_PINCTRL_SINGLE=y
configs/omapl138_lcdk_defconfig +1 -0
index e43141844a..0600ac3f4a 100644
@@ -51,6 +51,7 @@ CONFIG_SF_DEFAULT_SPEED=30000000
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_DM_SERIAL=y
 CONFIG_SYS_NS16550=y
configs/ti816x_evm_defconfig +1 -0
index bf877f596b..131b25a188 100644
@@ -46,6 +46,7 @@ CONFIG_MMC_OMAP_HS=y
 CONFIG_NAND=y
 CONFIG_SYS_NAND_BUSWIDTH_16BIT=y
 CONFIG_MII=y
+CONFIG_DM_ETH=y
 CONFIG_DRIVER_TI_EMAC=y
 CONFIG_SYS_NS16550=y
 CONFIG_SPI=y
drivers/net/ti/davinci_emac.c +3 -1
index 9d53984973..3252a235d2 100644
@@ -26,11 +26,13 @@
 #include <net.h>
 #include <miiphy.h>
 #include <malloc.h>
-#include <netdev.h>
 #include <linux/compiler.h>
 #include <asm/arch/emac_defs.h>
 #include <asm/io.h>
 #include "davinci_emac.h"
+#ifndef CONFIG_DM_ETH
+#include <netdev.h>
+#endif
 
 unsigned int   emac_dbg = 0;
 #define debug_emac(fmt,args...)        if (emac_dbg) printf(fmt,##args)

drivers/net/ti/davinci_emac.c static u_int8_t num_phy; · line 112

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -107,10 +109,16 @@ static u_int8_t   num_phy;
 
 phy_t                          phy[CONFIG_SYS_DAVINCI_EMAC_PHY_COUNT];
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 15 lines
drivers/net/ti/davinci_emac.c +7 -2
 static int davinci_eth_set_mac_addr(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_write_hwaddr(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       unsigned long           mac_hi;
-       unsigned long           mac_lo;
+#ifdef CONFIG_DM_ETH
+       struct eth_pdata *pdata = dev_get_platdata(dev);
+#endif
+       unsigned long mac_hi, mac_lo;
 
        /*
         * Set MAC Addresses & Init multicast Hash to 0 (disable any multicast

drivers/net/ti/davinci_emac.c static int davinci_eth_set_mac_addr(struct eth_device *dev) · line 130

Quoted 5 lines
drivers/net/ti/davinci_emac.c +2 -0
@@ -118,12 +126,22 @@ static int davinci_eth_set_mac_addr(struct eth_device *dev)
         *  Using channel 0 only - other channels are disabled
         *  */
        writel(0, &adap_emac->MACINDEX);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 18 lines
drivers/net/ti/davinci_emac.c +8 -0
        mac_hi = (dev->enetaddr[3] << 24) |
                 (dev->enetaddr[2] << 16) |
                 (dev->enetaddr[1] << 8)  |
                 (dev->enetaddr[0]);
        mac_lo = (dev->enetaddr[5] << 8) |
                 (dev->enetaddr[4]);
+#else /* with CONFIG_DM_ETH */
+       mac_hi = (pdata->enetaddr[3] << 24) |
+                (pdata->enetaddr[2] << 16) |
+                (pdata->enetaddr[1] << 8)  |
+                (pdata->enetaddr[0]);
+       mac_lo = (pdata->enetaddr[5] << 8) |
+                (pdata->enetaddr[4]);
+#endif /* CONFIG_DM_ETH */
 
        writel(mac_hi, &adap_emac->MACADDRHI);
 #if defined(DAVINCI_EMAC_VERSION2)

drivers/net/ti/davinci_emac.c static void __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr) · line 432

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -411,13 +429,17 @@ static void  __attribute__((unused)) davinci_eth_gigabit_enable(int phy_addr)
 }
 
 /* Eth device open */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 19 lines
drivers/net/ti/davinci_emac.c +8 -5
 static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_start(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       dv_reg_p                addr;
-       u_int32_t               clkdiv, cnt, mac_control;
-       uint16_t                __maybe_unused lpa_val;
-       volatile emac_desc      *rx_desc;
-       int                     index;
+       u32 clkdiv, cnt, mac_control;
+       volatile emac_desc *rx_desc;
+       u16 __maybe_unused lpa_val;
+       dv_reg_p addr;
+       int index;
 
        debug_emac("+ emac_open\n");
 

drivers/net/ti/davinci_emac.c static int davinci_eth_open(struct eth_device *dev, bd_t *bis) · line 472

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -447,7 +469,11 @@ static int davinci_eth_open(struct eth_device *dev, bd_t *bis)
        writel(1, &adap_emac->TXCONTROL);
        writel(1, &adap_emac->RXCONTROL);
 
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static void davinci_eth_ch_teardown(int ch) · line 617

Quoted 12 lines
drivers/net/ti/davinci_emac.c +4 -0
        davinci_eth_set_mac_addr(dev);
+#else /* with CONFIG_DM_ETH */
+       davinci_emac_write_hwaddr(dev);
+#endif /* CONFIG_DM_ETH */
 
        /* Set DMA 8 TX / 8 RX Head pointers to 0 */
        addr = &adap_emac->TX0HDP;
@@ -588,7 +614,11 @@ static void davinci_eth_ch_teardown(int ch)
 }
 
 /* Eth device close */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 8 lines
drivers/net/ti/davinci_emac.c +3 -0
 static void davinci_eth_close(struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static void davinci_emac_stop(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
        debug_emac("+ emac_close\n");
 

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 652

Quoted 6 lines
drivers/net/ti/davinci_emac.c +1 -2
@@ -619,11 +649,15 @@ static int tx_send_loop = 0;
  * This function sends a single packet on the network and returns
  * positive number (number of bytes transmitted) or negative for error
  */
-static int davinci_eth_send_packet (struct eth_device *dev,
-                                       void *packet, int length)
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int tx_send_loop = 0; · line 660

Quoted 10 lines
drivers/net/ti/davinci_emac.c +7 -2
+static int davinci_eth_send_packet(struct eth_device *dev,
+                                  void *packet, int length)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_send(struct udevice *dev,
+                            void *packet, int length)
+#endif /* CONFIG_DM_ETH */
 {
-       int ret_status = -1;
-       int index;
+       int ret_status = -1, index;

I'm not sure why you are mixing these formatting changes (which look bad anyway) with the substantive changes. Please drop them.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 709

Quoted 8 lines
drivers/net/ti/davinci_emac.c +1 -0
        tx_send_loop = 0;
 
        index = get_active_phy();
@@ -672,7 +706,11 @@ static int davinci_eth_send_packet (struct eth_device *dev,
 /*
  * This function handles receipt of a packet from the network
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

drivers/net/ti/davinci_emac.c static int davinci_eth_send_packet (struct eth_device *dev, · line 716

Quoted 7 lines
drivers/net/ti/davinci_emac.c +3 -0
 static int davinci_eth_rcv_packet (struct eth_device *dev)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_recv(struct udevice *dev, int flags, uchar **packetp)
+#endif /* CONFIG_DM_ETH */
 {
        volatile emac_desc *rx_curr_desc;
        volatile emac_desc *curr_desc;

Please remove the call to net_process_received_packet() and split the descriptor cleanup into a free_pkt() operation.

Quoted 11 lines
drivers/net/ti/davinci_emac.c +3 -0
@@ -742,6 +780,9 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
                }
                return (ret);
        }
+#ifdef CONFIG_DM_ETH
+       *packetp = rx_curr_desc->buffer;
+#endif
        return (0);
 }
 

drivers/net/ti/davinci_emac.c static int davinci_eth_rcv_packet (struct eth_device *dev) · line 794

Quoted 4 lines
drivers/net/ti/davinci_emac.c +1 -0
@@ -750,12 +791,16 @@ static int davinci_eth_rcv_packet (struct eth_device *dev)
  * EMAC modules power or pin multiplexors, that is done by board_init()
  * much earlier in bootup process. Returns 1 on success, 0 otherwise.
  */
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 25 lines
drivers/net/ti/davinci_emac.c +8 -4
 int davinci_emac_initialize(void)
+#else /* with CONFIG_DM_ETH */
+static int davinci_emac_probe(struct udevice *dev)
+#endif /* CONFIG_DM_ETH */
 {
-       u_int32_t       phy_id;
-       u_int16_t       tmp;
-       int             i;
-       int             ret;
+       int i, ret;
+       u32 phy_id;
+       u16 tmp;
+#ifndef CONFIG_DM_ETH
        struct eth_device *dev;
 
        dev = malloc(sizeof *dev);
@@ -774,6 +819,7 @@ int davinci_emac_initialize(void)
        dev->write_hwaddr = davinci_eth_set_mac_addr;
 
        eth_register(dev);
+#endif /* CONFIG_DM_ETH */
 
        davinci_eth_mdio_enable();
 

drivers/net/ti/davinci_emac.c int davinci_emac_initialize(void) · line 904

Quoted 6 lines
drivers/net/ti/davinci_emac.c +2 -1
@@ -854,5 +900,34 @@ int davinci_emac_initialize(void)
                        phy[i].auto_negotiate(i);
        }
 #endif
-       return(1);
+
+#ifndef CONFIG_DM_ETH

When you have both cases, please use positive logic. Flip the cases and use #ifdef.

Quoted 36 lines
drivers/net/ti/davinci_emac.c +28 -1
+       return 1;
+#else /* with CONFIG_DM_ETH */
+       return 0;
+#endif /* CONFIG_DM_ETH */
 }
+
+#ifdef CONFIG_DM_ETH
+static const struct eth_ops davinci_emac_ops = {
+       .start          = davinci_emac_start,
+       .send           = davinci_emac_send,
+       .recv           = davinci_emac_recv,
+       .stop           = davinci_emac_stop,
+       .write_hwaddr   = davinci_emac_write_hwaddr,
+};
+
+static const struct udevice_id davinci_emac_ids[] = {
+       { .compatible = "ti,davinci-dm6467-emac" },
+       { }
+};
+
+U_BOOT_DRIVER(davinci_emac) = {
+       .name           = "davinci_emac",
+       .id             = UCLASS_ETH,
+       .of_match       = davinci_emac_ids,
+       .probe          = davinci_emac_probe,
+       .ops            = &davinci_emac_ops,
+       .platdata_auto_alloc_size = sizeof(struct eth_pdata),
+};
+#endif /* CONFIG_DM_ETH */
--

2.21.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot