[PATCH 15/16] net: dm9000: Add DM support

Ramon Fried rfried.dev at gmail.com
Tue Apr 12 21:51:41 CEST 2022


On Mon, Apr 11, 2022 at 8:56 PM Marek Vasut <marex at denx.de> wrote:
>
> Add support for U-Boot DM and DT probing.
>
> Signed-off-by: Marek Vasut <marex at denx.de>
> Cc: Joe Hershberger <joe.hershberger at ni.com>
> Cc: Ramon Fried <rfried.dev at gmail.com>
> ---
>  drivers/net/dm9000x.c | 118 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 118 insertions(+)
>
> diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c
> index 84b012ec65d..d63a7c442c9 100644
> --- a/drivers/net/dm9000x.c
> +++ b/drivers/net/dm9000x.c
> @@ -51,6 +51,7 @@
>
>  #include <common.h>
>  #include <command.h>
> +#include <dm.h>
>  #include <net.h>
>  #include <asm/io.h>
>  #include <linux/delay.h>
> @@ -73,7 +74,9 @@ struct dm9000_priv {
>         void (*outblk)(struct dm9000_priv *db, void *data_ptr, int count);
>         void (*inblk)(struct dm9000_priv *db, void *data_ptr, int count);
>         void (*rx_status)(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen);
> +#ifndef CONFIG_DM_ETH
>         struct eth_device netdev;
> +#endif
>         phys_addr_t base_io;
>         phys_addr_t base_data;
>  };
> @@ -568,6 +571,7 @@ static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr)
>  static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {}
>  #endif
>
> +#ifndef CONFIG_DM_ETH
>  static int dm9000_init(struct eth_device *dev, struct bd_info *bd)
>  {
>         struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev);
> @@ -625,3 +629,117 @@ int dm9000_initialize(struct bd_info *bis)
>
>         return 0;
>  }
> +#else  /* ifdef CONFIG_DM_ETH */
> +static int dm9000_start(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +
> +       return dm9000_init_common(db, pdata->enetaddr);
> +}
> +
> +static void dm9000_stop(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +
> +       dm9000_halt_common(db);
> +}
> +
> +static int dm9000_send(struct udevice *dev, void *packet, int length)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       int ret;
> +
> +       ret = dm9000_send_common(db, packet, length);
> +
> +       return ret ? 0 : -ETIMEDOUT;
> +}
> +
> +static int dm9000_recv(struct udevice *dev, int flags, uchar **packetp)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       uchar *data = net_rx_packets[0];
> +       int ret;
> +
> +       ret = dm9000_recv_common(db, data);
> +       if (ret)
> +               *packetp = (void *)data;
> +
> +       return ret ? ret : -EAGAIN;
> +}
> +
> +static int dm9000_write_hwaddr(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +       int i, oft;
> +
> +       /* fill device MAC address registers */
> +       for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++)
> +               dm9000_iow(db, oft, pdata->enetaddr[i]);
> +
> +       for (i = 0, oft = 0x16; i < 8; i++, oft++)
> +               dm9000_iow(db, oft, 0xff);
> +
> +       /* read back mac, just to be sure */
> +       for (i = 0, oft = 0x10; i < 6; i++, oft++)
> +               debug("%02x:", dm9000_ior(db, oft));
> +
> +       debug("\n");
> +
> +       return 0;
> +}
> +
> +static int dm9000_read_rom_hwaddr(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +
> +       dm9000_get_enetaddr(db, pdata->enetaddr);
> +
> +       return !is_valid_ethaddr(pdata->enetaddr);
> +}
> +
> +static int dm9000_bind(struct udevice *dev)
> +{
> +       return device_set_name(dev, dev->name);
> +}
> +
> +static int dm9000_of_to_plat(struct udevice *dev)
> +{
> +       struct dm9000_priv *db = dev_get_priv(dev);
> +       struct eth_pdata *pdata = dev_get_plat(dev);
> +
> +       pdata->iobase = dev_read_addr_index(dev, 0);
> +       db->base_io = pdata->iobase;
> +       db->base_data = dev_read_addr_index(dev, 1);
> +
> +       return 0;
> +}
> +
> +static const struct eth_ops dm9000_ops = {
> +       .start          = dm9000_start,
> +       .stop           = dm9000_stop,
> +       .send           = dm9000_send,
> +       .recv           = dm9000_recv,
> +       .write_hwaddr   = dm9000_write_hwaddr,
> +       .read_rom_hwaddr = dm9000_read_rom_hwaddr,
> +};
> +
> +static const struct udevice_id dm9000_ids[] = {
> +       { .compatible = "davicom,dm9000" },
> +       { }
> +};
> +
> +U_BOOT_DRIVER(dm9000) = {
> +       .name           = "eth_dm9000",
> +       .id             = UCLASS_ETH,
> +       .of_match       = dm9000_ids,
> +       .bind           = dm9000_bind,
> +       .of_to_plat = dm9000_of_to_plat,
> +       .ops            = &dm9000_ops,
> +       .priv_auto      = sizeof(struct dm9000_priv),
> +       .plat_auto      = sizeof(struct eth_pdata),
> +       .flags          = DM_FLAG_ALLOC_PRIV_DMA,
> +};
> +#endif
> --
> 2.35.1
>
Reviewed-by: Ramon Fried <rfried.dev at gmail.com>


More information about the U-Boot mailing list