[U-Boot] [PATCH] net: davinci_emac: use driver model (CONFIG_DM_ETH)

Bartosz Golaszewski brgl at bgdev.pl
Fri May 10 12:21:48 UTC 2019


czw., 9 maj 2019 o 20:48 Joe Hershberger <joe.hershberger at ni.com> napisaƂ(a):
>
> On Tue, Apr 30, 2019 at 11:04 AM Bartosz Golaszewski <brgl at bgdev.pl> wrote:
> >
> > From: Bartosz Golaszewski <bgolaszewski at baylibre.com>
> >
> > 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

> >
> > 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.
> >
> > Signed-off-by: Bartosz Golaszewski <bgolaszewski at baylibre.com>
> > ---
> > 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(-)
> >
> > diff --git a/arch/arm/mach-davinci/cpu.c b/arch/arm/mach-davinci/cpu.c
> > index f97ad3fc74..9fd6564d04 100644
> > --- a/arch/arm/mach-davinci/cpu.c
> > +++ b/arch/arm/mach-davinci/cpu.c
> > @@ -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;
> > -}
> > diff --git a/arch/arm/mach-omap2/omap3/emac.c b/arch/arm/mach-omap2/omap3/emac.c
> > index c79e870183..fb0c9188f5 100644
> > --- a/arch/arm/mach-omap2/omap3/emac.c
> > +++ b/arch/arm/mach-omap2/omap3/emac.c
> > @@ -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;
> >  }
> > diff --git a/board/davinci/da8xxevm/da850evm.c b/board/davinci/da8xxevm/da850evm.c
> > index 1bc26828bf..0d2bc5fb32 100644
> > --- a/board/davinci/da8xxevm/da850evm.c
> > +++ b/board/davinci/da8xxevm/da850evm.c
> > @@ -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;
> >  }
> > diff --git a/board/davinci/da8xxevm/omapl138_lcdk.c b/board/davinci/da8xxevm/omapl138_lcdk.c
> > index 2c2f885d43..ef9656add8 100644
> > --- a/board/davinci/da8xxevm/omapl138_lcdk.c
> > +++ b/board/davinci/da8xxevm/omapl138_lcdk.c
> > @@ -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
> > diff --git a/board/logicpd/am3517evm/am3517evm.c b/board/logicpd/am3517evm/am3517evm.c
> > index 10031a4801..bfd4e78274 100644
> > --- a/board/logicpd/am3517evm/am3517evm.c
> > +++ b/board/logicpd/am3517evm/am3517evm.c
> > @@ -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;
> > diff --git a/board/ti/ti816x/evm.c b/board/ti/ti816x/evm.c
> > index 07a084bab8..240df8cbe1 100644
> > --- a/board/ti/ti816x/evm.c
> > +++ b/board/ti/ti816x/evm.c
> > @@ -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
> > diff --git a/configs/am3517_evm_defconfig b/configs/am3517_evm_defconfig
> > index b9f59f3291..0ea28a20b2 100644
> > --- a/configs/am3517_evm_defconfig
> > +++ b/configs/am3517_evm_defconfig
> > @@ -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
> > diff --git a/configs/da850_am18xxevm_defconfig b/configs/da850_am18xxevm_defconfig
> > index f098222113..6227cafc90 100644
> > --- a/configs/da850_am18xxevm_defconfig
> > +++ b/configs/da850_am18xxevm_defconfig
> > @@ -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
> > diff --git a/configs/da850evm_defconfig b/configs/da850evm_defconfig
> > index 221c204af0..78eadc6330 100644
> > --- a/configs/da850evm_defconfig
> > +++ b/configs/da850evm_defconfig
> > @@ -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
> > diff --git a/configs/da850evm_direct_nor_defconfig b/configs/da850evm_direct_nor_defconfig
> > index 166e77b8e3..2dd82d68b9 100644
> > --- a/configs/da850evm_direct_nor_defconfig
> > +++ b/configs/da850evm_direct_nor_defconfig
> > @@ -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
> > diff --git a/configs/omapl138_lcdk_defconfig b/configs/omapl138_lcdk_defconfig
> > index e43141844a..0600ac3f4a 100644
> > --- a/configs/omapl138_lcdk_defconfig
> > +++ b/configs/omapl138_lcdk_defconfig
> > @@ -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
> > diff --git a/configs/ti816x_evm_defconfig b/configs/ti816x_evm_defconfig
> > index bf877f596b..131b25a188 100644
> > --- a/configs/ti816x_evm_defconfig
> > +++ b/configs/ti816x_evm_defconfig
> > @@ -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
> > diff --git a/drivers/net/ti/davinci_emac.c b/drivers/net/ti/davinci_emac.c
> > index 9d53984973..3252a235d2 100644
> > --- a/drivers/net/ti/davinci_emac.c
> > +++ b/drivers/net/ti/davinci_emac.c
> > @@ -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)
> > @@ -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.
>
> >  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
> > @@ -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.
>
> >         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)
> > @@ -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.
>
> >  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");
> >
> > @@ -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.
>
> >         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.
>
> >  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");
> >
> > @@ -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.
>
> > +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.
>
> >         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.
>
> >  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.
>
> > @@ -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);
> >  }
> >
> > @@ -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.
>
> >  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();
> >
> > @@ -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.
>
> > +       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


More information about the U-Boot mailing list