diff options
Diffstat (limited to 'drivers/net')
68 files changed, 1015 insertions, 946 deletions
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index a6171a7..347fe8a 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig @@ -191,6 +191,11 @@ config CALXEDA_XGMAC This driver supports the XGMAC in Calxeda Highbank and Midway machines. +config DRIVER_DM9000 + bool "Davicom DM9000 controller driver" + help + The Davicom DM9000 parallel bus external ethernet interface chip. + config DWC_ETH_QOS bool "Synopsys DWC Ethernet QOS device support" depends on DM_ETH diff --git a/drivers/net/ag7xxx.c b/drivers/net/ag7xxx.c index 632ab3c..a16c998 100644 --- a/drivers/net/ag7xxx.c +++ b/drivers/net/ag7xxx.c @@ -1254,7 +1254,6 @@ static const struct eth_ops ag7xxx_eth_ops = { static int ag7xxx_eth_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; int ret; pdata->iobase = dev_read_addr(dev); @@ -1265,13 +1264,9 @@ static int ag7xxx_eth_of_to_plat(struct udevice *dev) if (ret <= 0) return ret; - phy_mode = fdt_getprop(gd->fdt_blob, ret, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } return 0; } diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c index eb4cd96..912d28f 100644 --- a/drivers/net/altera_tse.c +++ b/drivers/net/altera_tse.c @@ -435,11 +435,11 @@ static int tse_phy_init(struct altera_tse_priv *priv, void *dev) if (priv->phyaddr) mask = 1 << priv->phyaddr; - phydev = phy_find_by_mask(priv->bus, mask, priv->interface); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, priv->interface); phydev->supported &= PHY_GBIT_FEATURES; phydev->advertising = phydev->supported; @@ -676,17 +676,10 @@ static int altera_tse_probe(struct udevice *dev) static int altera_tse_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; - - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } return 0; } diff --git a/drivers/net/bcm6348-eth.c b/drivers/net/bcm6348-eth.c index 06e0dd7..5317173 100644 --- a/drivers/net/bcm6348-eth.c +++ b/drivers/net/bcm6348-eth.c @@ -415,7 +415,6 @@ static int bcm6348_eth_probe(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct bcm6348_eth_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phy; - const char *phy_mode; int ret, i; /* get base address */ @@ -425,11 +424,8 @@ static int bcm6348_eth_probe(struct udevice *dev) pdata->iobase = (phys_addr_t) priv->base; /* get phy mode */ - pdata->phy_interface = PHY_INTERFACE_MODE_NONE; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -ENODEV; /* get phy */ diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c index 6783956..4e1f8ed 100644 --- a/drivers/net/bcmgenet.c +++ b/drivers/net/bcmgenet.c @@ -526,8 +526,6 @@ static int bcmgenet_phy_init(struct bcmgenet_eth_priv *priv, void *dev) } phydev->advertising = phydev->supported; - phy_connect_dev(phydev, dev); - priv->phydev = phydev; phy_config(priv->phydev); @@ -690,20 +688,14 @@ static int bcmgenet_eth_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct bcmgenet_eth_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phy_node; - const char *phy_mode; int ret; pdata->iobase = dev_read_addr(dev); /* Get phy mode from DT */ - pdata->phy_interface = -1; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, &phy_node); diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 5aaac60..1584b9e 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -914,21 +914,15 @@ int designware_eth_of_to_plat(struct udevice *dev) struct dw_eth_dev *priv = dev_get_priv(dev); #endif struct eth_pdata *pdata = &dw_pdata->eth_pdata; - const char *phy_mode; #if CONFIG_IS_ENABLED(DM_GPIO) int reset_flags = GPIOD_IS_OUT; #endif int ret = 0; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); diff --git a/drivers/net/dm9000x.c b/drivers/net/dm9000x.c index 4f062e9..78ce536 100644 --- a/drivers/net/dm9000x.c +++ b/drivers/net/dm9000x.c @@ -1,86 +1,66 @@ // SPDX-License-Identifier: GPL-2.0+ /* - dm9000.c: Version 1.2 12/15/2003 - - A Davicom DM9000 ISA NIC fast Ethernet driver for Linux. - Copyright (C) 1997 Sten Wang - - (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. - -V0.11 06/20/2001 REG_0A bit3=1, default enable BP with DA match - 06/22/2001 Support DM9801 progrmming - E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000 - E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200 - R17 = (R17 & 0xfff0) | NF + 3 - E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200 - R17 = (R17 & 0xfff0) | NF - -v1.00 modify by simon 2001.9.5 - change for kernel 2.4.x - -v1.1 11/09/2001 fix force mode bug - -v1.2 03/18/2003 Weilun Huang <weilun_huang@davicom.com.tw>: - Fixed phy reset. - Added tx/rx 32 bit mode. - Cleaned up for kernel merge. - --------------------------------------- - - 12/15/2003 Initial port to u-boot by - Sascha Hauer <saschahauer@web.de> - - 06/03/2008 Remy Bohmer <linux@bohmer.net> - - Fixed the driver to work with DM9000A. - (check on ISR receive status bit before reading the - FIFO as described in DM9000 programming guide and - application notes) - - Added autodetect of databus width. - - Made debug code compile again. - - Adapt eth_send such that it matches the DM9000* - application notes. Needed to make it work properly - for DM9000A. - - Adapted reset procedure to match DM9000 application - notes (i.e. double reset) - - some minor code cleanups - These changes are tested with DM9000{A,EP,E} together - with a 200MHz Atmel AT91SAM9261 core - -TODO: external MII is not functional, only internal at the moment. -*/ + * dm9000.c: Version 1.2 12/15/2003 + * + * A Davicom DM9000 ISA NIC fast Ethernet driver for Linux. + * Copyright (C) 1997 Sten Wang + * + * (C)Copyright 1997-1998 DAVICOM Semiconductor,Inc. All Rights Reserved. + * + * V0.11 06/20/2001 REG_0A bit3=1, default enable BP with DA match + * 06/22/2001 Support DM9801 progrmming + * E3: R25 = ((R24 + NF) & 0x00ff) | 0xf000 + * E4: R25 = ((R24 + NF) & 0x00ff) | 0xc200 + * R17 = (R17 & 0xfff0) | NF + 3 + * E5: R25 = ((R24 + NF - 3) & 0x00ff) | 0xc200 + * R17 = (R17 & 0xfff0) | NF + * + * v1.00 modify by simon 2001.9.5 + * change for kernel 2.4.x + * + * v1.1 11/09/2001 fix force mode bug + * + * v1.2 03/18/2003 Weilun Huang <weilun_huang@davicom.com.tw>: + * Fixed phy reset. + * Added tx/rx 32 bit mode. + * Cleaned up for kernel merge. + * + * -------------------------------------- + * + * 12/15/2003 Initial port to u-boot by + * Sascha Hauer <saschahauer@web.de> + * + * 06/03/2008 Remy Bohmer <linux@bohmer.net> + * - Fixed the driver to work with DM9000A. + * (check on ISR receive status bit before reading the + * FIFO as described in DM9000 programming guide and + * application notes) + * - Added autodetect of databus width. + * - Made debug code compile again. + * - Adapt eth_send such that it matches the DM9000* + * application notes. Needed to make it work properly + * for DM9000A. + * - Adapted reset procedure to match DM9000 application + * notes (i.e. double reset) + * - some minor code cleanups + * These changes are tested with DM9000{A,EP,E} together + * with a 200MHz Atmel AT91SAM9261 core + * + * TODO: external MII is not functional, only internal at the moment. + */ #include <common.h> #include <command.h> +#include <dm.h> +#include <malloc.h> #include <net.h> #include <asm/io.h> -#include <dm9000.h> #include <linux/delay.h> #include "dm9000x.h" -/* Board/System/Debug information/definition ---------------- */ - -/* #define CONFIG_DM9000_DEBUG */ - -#ifdef CONFIG_DM9000_DEBUG -#define DM9000_DBG(fmt,args...) printf(fmt, ##args) -#define DM9000_DMP_PACKET(func,packet,length) \ - do { \ - int i; \ - printf("%s: length: %d\n", func, length); \ - for (i = 0; i < length; i++) { \ - if (i % 8 == 0) \ - printf("\n%s: %02x: ", func, i); \ - printf("%02x ", ((unsigned char *) packet)[i]); \ - } printf("\n"); \ - } while(0) -#else -#define DM9000_DBG(fmt,args...) -#define DM9000_DMP_PACKET(func,packet,length) -#endif - /* Structure/enum declaration ------------------------------- */ -typedef struct board_info { +struct dm9000_priv { u32 runt_length_counter; /* counter: RX length < 64byte */ u32 long_length_counter; /* counter: RX length > 1514byte */ u32 reset_counter; /* counter: RESET */ @@ -92,209 +72,261 @@ typedef struct board_info { u8 phy_addr; u8 device_wait_reset; /* device state */ unsigned char srom[128]; - void (*outblk)(volatile void *data_ptr, int count); - void (*inblk)(void *data_ptr, int count); - void (*rx_status)(u16 *RxStatus, u16 *RxLen); - struct eth_device netdev; -} board_info_t; -static board_info_t dm9000_info; - - -/* function declaration ------------------------------------- */ -static int dm9000_probe(void); -static u16 dm9000_phy_read(int); -static void dm9000_phy_write(int, u16); -static u8 DM9000_ior(int); -static void DM9000_iow(int reg, u8 value); + 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 dev; +#endif + void __iomem *base_io; + void __iomem *base_data; +}; /* DM9000 network board routine ---------------------------- */ #ifndef CONFIG_DM9000_BYTE_SWAPPED -#define DM9000_outb(d,r) writeb(d, (volatile u8 *)(r)) -#define DM9000_outw(d,r) writew(d, (volatile u16 *)(r)) -#define DM9000_outl(d,r) writel(d, (volatile u32 *)(r)) -#define DM9000_inb(r) readb((volatile u8 *)(r)) -#define DM9000_inw(r) readw((volatile u16 *)(r)) -#define DM9000_inl(r) readl((volatile u32 *)(r)) +#define dm9000_outb(d, r) writeb((d), (r)) +#define dm9000_outw(d, r) writew((d), (r)) +#define dm9000_outl(d, r) writel((d), (r)) +#define dm9000_inb(r) readb(r) +#define dm9000_inw(r) readw(r) +#define dm9000_inl(r) readl(r) #else -#define DM9000_outb(d, r) __raw_writeb(d, r) -#define DM9000_outw(d, r) __raw_writew(d, r) -#define DM9000_outl(d, r) __raw_writel(d, r) -#define DM9000_inb(r) __raw_readb(r) -#define DM9000_inw(r) __raw_readw(r) -#define DM9000_inl(r) __raw_readl(r) +#define dm9000_outb(d, r) __raw_writeb(d, r) +#define dm9000_outw(d, r) __raw_writew(d, r) +#define dm9000_outl(d, r) __raw_writel(d, r) +#define dm9000_inb(r) __raw_readb(r) +#define dm9000_inw(r) __raw_readw(r) +#define dm9000_inl(r) __raw_readl(r) #endif -#ifdef CONFIG_DM9000_DEBUG -static void -dump_regs(void) -{ - DM9000_DBG("\n"); - DM9000_DBG("NCR (0x00): %02x\n", DM9000_ior(0)); - DM9000_DBG("NSR (0x01): %02x\n", DM9000_ior(1)); - DM9000_DBG("TCR (0x02): %02x\n", DM9000_ior(2)); - DM9000_DBG("TSRI (0x03): %02x\n", DM9000_ior(3)); - DM9000_DBG("TSRII (0x04): %02x\n", DM9000_ior(4)); - DM9000_DBG("RCR (0x05): %02x\n", DM9000_ior(5)); - DM9000_DBG("RSR (0x06): %02x\n", DM9000_ior(6)); - DM9000_DBG("ISR (0xFE): %02x\n", DM9000_ior(DM9000_ISR)); - DM9000_DBG("\n"); +#ifdef DEBUG +static void dm9000_dump_packet(const char *func, u8 *packet, int length) +{ + int i; + + printf("%s: length: %d\n", func, length); + + for (i = 0; i < length; i++) { + if (i % 8 == 0) + printf("\n%s: %02x: ", func, i); + printf("%02x ", packet[i]); + } + + printf("\n"); } +#else +static void dm9000_dump_packet(const char *func, u8 *packet, int length) {} #endif -static void dm9000_outblk_8bit(volatile void *data_ptr, int count) +static void dm9000_outblk_8bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; + for (i = 0; i < count; i++) - DM9000_outb((((u8 *) data_ptr)[i] & 0xff), DM9000_DATA); + dm9000_outb((((u8 *)data_ptr)[i] & 0xff), db->base_data); } -static void dm9000_outblk_16bit(volatile void *data_ptr, int count) +static void dm9000_outblk_16bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - DM9000_outw(((u16 *) data_ptr)[i], DM9000_DATA); + dm9000_outw(((u16 *)data_ptr)[i], db->base_data); } -static void dm9000_outblk_32bit(volatile void *data_ptr, int count) + +static void dm9000_outblk_32bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - DM9000_outl(((u32 *) data_ptr)[i], DM9000_DATA); + dm9000_outl(((u32 *)data_ptr)[i], db->base_data); } -static void dm9000_inblk_8bit(void *data_ptr, int count) +static void dm9000_inblk_8bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; + for (i = 0; i < count; i++) - ((u8 *) data_ptr)[i] = DM9000_inb(DM9000_DATA); + ((u8 *)data_ptr)[i] = dm9000_inb(db->base_data); } -static void dm9000_inblk_16bit(void *data_ptr, int count) +static void dm9000_inblk_16bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 1) / 2; for (i = 0; i < tmplen; i++) - ((u16 *) data_ptr)[i] = DM9000_inw(DM9000_DATA); + ((u16 *)data_ptr)[i] = dm9000_inw(db->base_data); } -static void dm9000_inblk_32bit(void *data_ptr, int count) + +static void dm9000_inblk_32bit(struct dm9000_priv *db, void *data_ptr, int count) { int i; u32 tmplen = (count + 3) / 4; for (i = 0; i < tmplen; i++) - ((u32 *) data_ptr)[i] = DM9000_inl(DM9000_DATA); + ((u32 *)data_ptr)[i] = dm9000_inl(db->base_data); } -static void dm9000_rx_status_32bit(u16 *RxStatus, u16 *RxLen) +static void dm9000_rx_status_32bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen) { u32 tmpdata; - DM9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, db->base_io); - tmpdata = DM9000_inl(DM9000_DATA); - *RxStatus = __le16_to_cpu(tmpdata); - *RxLen = __le16_to_cpu(tmpdata >> 16); + tmpdata = dm9000_inl(db->base_data); + *rxstatus = __le16_to_cpu(tmpdata); + *rxlen = __le16_to_cpu(tmpdata >> 16); } -static void dm9000_rx_status_16bit(u16 *RxStatus, u16 *RxLen) +static void dm9000_rx_status_16bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen) { - DM9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, db->base_io); - *RxStatus = __le16_to_cpu(DM9000_inw(DM9000_DATA)); - *RxLen = __le16_to_cpu(DM9000_inw(DM9000_DATA)); + *rxstatus = __le16_to_cpu(dm9000_inw(db->base_data)); + *rxlen = __le16_to_cpu(dm9000_inw(db->base_data)); } -static void dm9000_rx_status_8bit(u16 *RxStatus, u16 *RxLen) +static void dm9000_rx_status_8bit(struct dm9000_priv *db, u16 *rxstatus, u16 *rxlen) { - DM9000_outb(DM9000_MRCMD, DM9000_IO); + dm9000_outb(DM9000_MRCMD, db->base_io); + + *rxstatus = + __le16_to_cpu(dm9000_inb(db->base_data) + + (dm9000_inb(db->base_data) << 8)); + *rxlen = + __le16_to_cpu(dm9000_inb(db->base_data) + + (dm9000_inb(db->base_data) << 8)); +} - *RxStatus = - __le16_to_cpu(DM9000_inb(DM9000_DATA) + - (DM9000_inb(DM9000_DATA) << 8)); - *RxLen = - __le16_to_cpu(DM9000_inb(DM9000_DATA) + - (DM9000_inb(DM9000_DATA) << 8)); +/* + * Read a byte from I/O port + */ +static u8 dm9000_ior(struct dm9000_priv *db, int reg) +{ + dm9000_outb(reg, db->base_io); + return dm9000_inb(db->base_data); +} + +/* + * Write a byte to I/O port + */ +static void dm9000_iow(struct dm9000_priv *db, int reg, u8 value) +{ + dm9000_outb(reg, db->base_io); + dm9000_outb(value, db->base_data); +} + +/* + * Read a word from phyxcer + */ +static u16 dm9000_phy_read(struct dm9000_priv *db, int reg) +{ + u16 val; + + /* Fill the phyxcer register into REG_0C */ + dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg); + dm9000_iow(db, DM9000_EPCR, 0xc); /* Issue phyxcer read command */ + udelay(100); /* Wait read complete */ + dm9000_iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer read command */ + val = (dm9000_ior(db, DM9000_EPDRH) << 8) | + dm9000_ior(db, DM9000_EPDRL); + + /* The read data keeps on REG_0D & REG_0E */ + debug("%s(0x%x): 0x%x\n", __func__, reg, val); + return val; } /* - Search DM9000 board, allocate space and register it -*/ -int -dm9000_probe(void) + * Write a word to phyxcer + */ +static void dm9000_phy_write(struct dm9000_priv *db, int reg, u16 value) +{ + /* Fill the phyxcer register into REG_0C */ + dm9000_iow(db, DM9000_EPAR, DM9000_PHY | reg); + + /* Fill the written data into REG_0D & REG_0E */ + dm9000_iow(db, DM9000_EPDRL, (value & 0xff)); + dm9000_iow(db, DM9000_EPDRH, ((value >> 8) & 0xff)); + dm9000_iow(db, DM9000_EPCR, 0xa); /* Issue phyxcer write command */ + udelay(500); /* Wait write complete */ + dm9000_iow(db, DM9000_EPCR, 0x0); /* Clear phyxcer write command */ + debug("%s(reg:0x%x, value:0x%x)\n", __func__, reg, value); +} + +/* + * Search DM9000 board, allocate space and register it + */ +static int dm9000_probe(struct dm9000_priv *db) { u32 id_val; - id_val = DM9000_ior(DM9000_VIDL); - id_val |= DM9000_ior(DM9000_VIDH) << 8; - id_val |= DM9000_ior(DM9000_PIDL) << 16; - id_val |= DM9000_ior(DM9000_PIDH) << 24; - if (id_val == DM9000_ID) { - printf("dm9000 i/o: 0x%x, id: 0x%x \n", CONFIG_DM9000_BASE, - id_val); - return 0; - } else { - printf("dm9000 not found at 0x%08x id: 0x%08x\n", - CONFIG_DM9000_BASE, id_val); + + id_val = dm9000_ior(db, DM9000_VIDL); + id_val |= dm9000_ior(db, DM9000_VIDH) << 8; + id_val |= dm9000_ior(db, DM9000_PIDL) << 16; + id_val |= dm9000_ior(db, DM9000_PIDH) << 24; + if (id_val != DM9000_ID) { + printf("dm9000 not found at 0x%p id: 0x%08x\n", + db->base_io, id_val); return -1; } + + printf("dm9000 i/o: 0x%p, id: 0x%x\n", db->base_io, id_val); + return 0; } /* General Purpose dm9000 reset routine */ -static void -dm9000_reset(void) +static void dm9000_reset(struct dm9000_priv *db) { - DM9000_DBG("resetting DM9000\n"); + debug("resetting DM9000\n"); - /* Reset DM9000, - see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 */ + /* + * Reset DM9000, + * see DM9000 Application Notes V1.22 Jun 11, 2004 page 29 + */ /* DEBUG: Make all GPIO0 outputs, all others inputs */ - DM9000_iow(DM9000_GPCR, GPCR_GPIO0_OUT); + dm9000_iow(db, DM9000_GPCR, GPCR_GPIO0_OUT); /* Step 1: Power internal PHY by writing 0 to GPIO0 pin */ - DM9000_iow(DM9000_GPR, 0); + dm9000_iow(db, DM9000_GPR, 0); /* Step 2: Software reset */ - DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); + dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); do { - DM9000_DBG("resetting the DM9000, 1st reset\n"); + debug("resetting the DM9000, 1st reset\n"); udelay(25); /* Wait at least 20 us */ - } while (DM9000_ior(DM9000_NCR) & 1); + } while (dm9000_ior(db, DM9000_NCR) & 1); - DM9000_iow(DM9000_NCR, 0); - DM9000_iow(DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ + dm9000_iow(db, DM9000_NCR, 0); + dm9000_iow(db, DM9000_NCR, (NCR_LBK_INT_MAC | NCR_RST)); /* Issue a second reset */ do { - DM9000_DBG("resetting the DM9000, 2nd reset\n"); + debug("resetting the DM9000, 2nd reset\n"); udelay(25); /* Wait at least 20 us */ - } while (DM9000_ior(DM9000_NCR) & 1); + } while (dm9000_ior(db, DM9000_NCR) & 1); /* Check whether the ethernet controller is present */ - if ((DM9000_ior(DM9000_PIDL) != 0x0) || - (DM9000_ior(DM9000_PIDH) != 0x90)) + if ((dm9000_ior(db, DM9000_PIDL) != 0x0) || + (dm9000_ior(db, DM9000_PIDH) != 0x90)) printf("ERROR: resetting DM9000 -> not responding\n"); } -/* Initialize dm9000 board -*/ -static int dm9000_init(struct eth_device *dev, struct bd_info *bd) +/* Initialize dm9000 board */ +static int dm9000_init_common(struct dm9000_priv *db, u8 enetaddr[6]) { int i, oft, lnk; u8 io_mode; - struct board_info *db = &dm9000_info; - - DM9000_DBG("%s\n", __func__); /* RESET device */ - dm9000_reset(); + dm9000_reset(db); - if (dm9000_probe() < 0) + if (dm9000_probe(db) < 0) return -1; /* Auto-detect 8/16/32 bit mode, ISR Bit 6+7 indicate bus width */ - io_mode = DM9000_ior(DM9000_ISR) >> 6; + io_mode = dm9000_ior(db, DM9000_ISR) >> 6; switch (io_mode) { case 0x0: /* 16-bit mode */ @@ -325,46 +357,45 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* Program operating register, only internal phy supported */ - DM9000_iow(DM9000_NCR, 0x0); + dm9000_iow(db, DM9000_NCR, 0x0); /* TX Polling clear */ - DM9000_iow(DM9000_TCR, 0); + dm9000_iow(db, DM9000_TCR, 0); /* Less 3Kb, 200us */ - DM9000_iow(DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); + dm9000_iow(db, DM9000_BPTR, BPTR_BPHW(3) | BPTR_JPT_600US); /* Flow Control : High/Low Water */ - DM9000_iow(DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); + dm9000_iow(db, DM9000_FCTR, FCTR_HWOT(3) | FCTR_LWOT(8)); /* SH FIXME: This looks strange! Flow Control */ - DM9000_iow(DM9000_FCR, 0x0); + dm9000_iow(db, DM9000_FCR, 0x0); /* Special Mode */ - DM9000_iow(DM9000_SMCR, 0); + dm9000_iow(db, DM9000_SMCR, 0); /* clear TX status */ - DM9000_iow(DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); + dm9000_iow(db, DM9000_NSR, NSR_WAKEST | NSR_TX2END | NSR_TX1END); /* Clear interrupt status */ - DM9000_iow(DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); + dm9000_iow(db, DM9000_ISR, ISR_ROOS | ISR_ROS | ISR_PTS | ISR_PRS); - printf("MAC: %pM\n", dev->enetaddr); - if (!is_valid_ethaddr(dev->enetaddr)) { + printf("MAC: %pM\n", enetaddr); + if (!is_valid_ethaddr(enetaddr)) printf("WARNING: Bad MAC address (uninitialized EEPROM?)\n"); - } /* fill device MAC address registers */ for (i = 0, oft = DM9000_PAR; i < 6; i++, oft++) - DM9000_iow(oft, dev->enetaddr[i]); + dm9000_iow(db, oft, enetaddr[i]); for (i = 0, oft = 0x16; i < 8; i++, oft++) - DM9000_iow(oft, 0xff); + dm9000_iow(db, oft, 0xff); /* read back mac, just to be sure */ for (i = 0, oft = 0x10; i < 6; i++, oft++) - DM9000_DBG("%02x:", DM9000_ior(oft)); - DM9000_DBG("\n"); + debug("%02x:", dm9000_ior(db, oft)); + debug("\n"); /* Activate DM9000 */ /* RX enable */ - DM9000_iow(DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); + dm9000_iow(db, DM9000_RCR, RCR_DIS_LONG | RCR_DIS_CRC | RCR_RXEN); /* Enable TX/RX interrupt mask */ - DM9000_iow(DM9000_IMR, IMR_PAR); + dm9000_iow(db, DM9000_IMR, IMR_PAR); i = 0; - while (!(dm9000_phy_read(1) & 0x20)) { /* autonegation complete bit */ + while (!(dm9000_phy_read(db, 1) & 0x20)) { /* autonegation complete bit */ udelay(1000); i++; if (i == 10000) { @@ -374,7 +405,7 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* see what we've got */ - lnk = dm9000_phy_read(17) >> 12; + lnk = dm9000_phy_read(db, 17) >> 12; printf("operating at "); switch (lnk) { case 1: @@ -398,241 +429,321 @@ static int dm9000_init(struct eth_device *dev, struct bd_info *bd) } /* - Hardware start transmission. - Send a packet to media from the upper layer. -*/ -static int dm9000_send(struct eth_device *netdev, void *packet, int length) + * Hardware start transmission. + * Send a packet to media from the upper layer. + */ +static int dm9000_send_common(struct dm9000_priv *db, void *packet, int length) { int tmo; - struct board_info *db = &dm9000_info; - DM9000_DMP_PACKET(__func__ , packet, length); + dm9000_dump_packet(__func__, packet, length); - DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ + dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ /* Move data to DM9000 TX RAM */ - DM9000_outb(DM9000_MWCMD, DM9000_IO); /* Prepare for TX-data */ + dm9000_outb(DM9000_MWCMD, db->base_io); /* Prepare for TX-data */ /* push the data to the TX-fifo */ - (db->outblk)(packet, length); + db->outblk(db, packet, length); /* Set TX length to DM9000 */ - DM9000_iow(DM9000_TXPLL, length & 0xff); - DM9000_iow(DM9000_TXPLH, (length >> 8) & 0xff); + dm9000_iow(db, DM9000_TXPLL, length & 0xff); + dm9000_iow(db, DM9000_TXPLH, (length >> 8) & 0xff); /* Issue TX polling command */ - DM9000_iow(DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ + dm9000_iow(db, DM9000_TCR, TCR_TXREQ); /* Cleared after TX complete */ /* wait for end of transmission */ tmo = get_timer(0) + 5 * CONFIG_SYS_HZ; - while ( !(DM9000_ior(DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || - !(DM9000_ior(DM9000_ISR) & IMR_PTM) ) { + while (!(dm9000_ior(db, DM9000_NSR) & (NSR_TX1END | NSR_TX2END)) || + !(dm9000_ior(db, DM9000_ISR) & IMR_PTM)) { if (get_timer(0) >= tmo) { printf("transmission timeout\n"); break; } } - DM9000_iow(DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ + dm9000_iow(db, DM9000_ISR, IMR_PTM); /* Clear Tx bit in ISR */ - DM9000_DBG("transmit done\n\n"); + debug("transmit done\n\n"); return 0; } /* - Stop the interface. - The interface is stopped when it is brought. -*/ -static void dm9000_halt(struct eth_device *netdev) + * Stop the interface. + * The interface is stopped when it is brought. + */ +static void dm9000_halt_common(struct dm9000_priv *db) { - DM9000_DBG("%s\n", __func__); - - /* RESET devie */ - dm9000_phy_write(0, 0x8000); /* PHY RESET */ - DM9000_iow(DM9000_GPR, 0x01); /* Power-Down PHY */ - DM9000_iow(DM9000_IMR, 0x80); /* Disable all interrupt */ - DM9000_iow(DM9000_RCR, 0x00); /* Disable RX */ + /* RESET device */ + dm9000_phy_write(db, 0, 0x8000); /* PHY RESET */ + dm9000_iow(db, DM9000_GPR, 0x01); /* Power-Down PHY */ + dm9000_iow(db, DM9000_IMR, 0x80); /* Disable all interrupt */ + dm9000_iow(db, DM9000_RCR, 0x00); /* Disable RX */ } /* - Received a packet and pass to upper layer -*/ -static int dm9000_rx(struct eth_device *netdev) + * Received a packet and pass to upper layer + */ +static int dm9000_recv_common(struct dm9000_priv *db, uchar *rdptr) { u8 rxbyte; - u8 *rdptr = (u8 *)net_rx_packets[0]; - u16 RxStatus, RxLen = 0; - struct board_info *db = &dm9000_info; + u16 rxstatus, rxlen = 0; - /* Check packet ready or not, we must check - the ISR status first for DM9000A */ - if (!(DM9000_ior(DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ + /* + * Check packet ready or not, we must check + * the ISR status first for DM9000A + */ + if (!(dm9000_ior(db, DM9000_ISR) & 0x01)) /* Rx-ISR bit must be set. */ return 0; - DM9000_iow(DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ + dm9000_iow(db, DM9000_ISR, 0x01); /* clear PR status latched in bit 0 */ /* There is _at least_ 1 package in the fifo, read them all */ - for (;;) { - DM9000_ior(DM9000_MRCMDX); /* Dummy read */ - - /* Get most updated data, - only look at bits 0:1, See application notes DM9000 */ - rxbyte = DM9000_inb(DM9000_DATA) & 0x03; - - /* Status check: this byte must be 0 or 1 */ - if (rxbyte > DM9000_PKT_RDY) { - DM9000_iow(DM9000_RCR, 0x00); /* Stop Device */ - DM9000_iow(DM9000_ISR, 0x80); /* Stop INT request */ - printf("DM9000 error: status check fail: 0x%x\n", - rxbyte); - return 0; - } + dm9000_ior(db, DM9000_MRCMDX); /* Dummy read */ + + /* + * Get most updated data, + * only look at bits 0:1, See application notes DM9000 + */ + rxbyte = dm9000_inb(db->base_data) & 0x03; + + /* Status check: this byte must be 0 or 1 */ + if (rxbyte > DM9000_PKT_RDY) { + dm9000_iow(db, DM9000_RCR, 0x00); /* Stop Device */ + dm9000_iow(db, DM9000_ISR, 0x80); /* Stop INT request */ + printf("DM9000 error: status check fail: 0x%x\n", + rxbyte); + return -EINVAL; + } + + if (rxbyte != DM9000_PKT_RDY) + return 0; /* No packet received, ignore */ + + debug("receiving packet\n"); - if (rxbyte != DM9000_PKT_RDY) - return 0; /* No packet received, ignore */ - - DM9000_DBG("receiving packet\n"); - - /* A packet ready now & Get status/length */ - (db->rx_status)(&RxStatus, &RxLen); - - DM9000_DBG("rx status: 0x%04x rx len: %d\n", RxStatus, RxLen); - - /* Move data from DM9000 */ - /* Read received packet from RX SRAM */ - (db->inblk)(rdptr, RxLen); - - if ((RxStatus & 0xbf00) || (RxLen < 0x40) - || (RxLen > DM9000_PKT_MAX)) { - if (RxStatus & 0x100) { - printf("rx fifo error\n"); - } - if (RxStatus & 0x200) { - printf("rx crc error\n"); - } - if (RxStatus & 0x8000) { - printf("rx length error\n"); - } - if (RxLen > DM9000_PKT_MAX) { - printf("rx length too big\n"); - dm9000_reset(); - } - } else { - DM9000_DMP_PACKET(__func__ , rdptr, RxLen); - - DM9000_DBG("passing packet to upper layer\n"); - net_process_received_packet(net_rx_packets[0], RxLen); + /* A packet ready now & Get status/length */ + db->rx_status(db, &rxstatus, &rxlen); + + debug("rx status: 0x%04x rx len: %d\n", rxstatus, rxlen); + + /* Move data from DM9000 */ + /* Read received packet from RX SRAM */ + db->inblk(db, rdptr, rxlen); + + if (rxstatus & 0xbf00 || rxlen < 0x40 || rxlen > DM9000_PKT_MAX) { + if (rxstatus & 0x100) + printf("rx fifo error\n"); + if (rxstatus & 0x200) + printf("rx crc error\n"); + if (rxstatus & 0x8000) + printf("rx length error\n"); + if (rxlen > DM9000_PKT_MAX) { + printf("rx length too big\n"); + dm9000_reset(db); } + return -EINVAL; } - return 0; + + return rxlen; } /* - Read a word data from SROM -*/ + * Read a word data from SROM + */ #if !defined(CONFIG_DM9000_NO_SROM) -void dm9000_read_srom_word(int offset, u8 *to) -{ - DM9000_iow(DM9000_EPAR, offset); - DM9000_iow(DM9000_EPCR, 0x4); - udelay(8000); - DM9000_iow(DM9000_EPCR, 0x0); - to[0] = DM9000_ior(DM9000_EPDRL); - to[1] = DM9000_ior(DM9000_EPDRH); -} - -void dm9000_write_srom_word(int offset, u16 val) +static void dm9000_read_srom_word(struct dm9000_priv *db, int offset, u8 *to) { - DM9000_iow(DM9000_EPAR, offset); - DM9000_iow(DM9000_EPDRH, ((val >> 8) & 0xff)); - DM9000_iow(DM9000_EPDRL, (val & 0xff)); - DM9000_iow(DM9000_EPCR, 0x12); - udelay(8000); - DM9000_iow(DM9000_EPCR, 0); + dm9000_iow(db, DM9000_EPAR, offset); + dm9000_iow(db, DM9000_EPCR, 0x4); + mdelay(8); + dm9000_iow(db, DM9000_EPCR, 0x0); + to[0] = dm9000_ior(db, DM9000_EPDRL); + to[1] = dm9000_ior(db, DM9000_EPDRH); } -#endif -static void dm9000_get_enetaddr(struct eth_device *dev) +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) { -#if !defined(CONFIG_DM9000_NO_SROM) int i; + for (i = 0; i < 3; i++) - dm9000_read_srom_word(i, dev->enetaddr + (2 * i)); -#endif + dm9000_read_srom_word(db, i, enetaddr + (2 * i)); } +#else +static void dm9000_get_enetaddr(struct dm9000_priv *db, u8 *enetaddr) {} +#endif -/* - Read a byte from I/O port -*/ -static u8 -DM9000_ior(int reg) +#ifndef CONFIG_DM_ETH +static int dm9000_init(struct eth_device *dev, struct bd_info *bd) { - DM9000_outb(reg, DM9000_IO); - return DM9000_inb(DM9000_DATA); + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + return dm9000_init_common(db, dev->enetaddr); } -/* - Write a byte to I/O port -*/ -static void -DM9000_iow(int reg, u8 value) +static void dm9000_halt(struct eth_device *dev) { - DM9000_outb(reg, DM9000_IO); - DM9000_outb(value, DM9000_DATA); + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + + dm9000_halt_common(db); } -/* - Read a word from phyxcer -*/ -static u16 -dm9000_phy_read(int reg) +static int dm9000_send(struct eth_device *dev, void *packet, int length) { - u16 val; + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); - /* Fill the phyxcer register into REG_0C */ - DM9000_iow(DM9000_EPAR, DM9000_PHY | reg); - DM9000_iow(DM9000_EPCR, 0xc); /* Issue phyxcer read command */ - udelay(100); /* Wait read complete */ - DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer read command */ - val = (DM9000_ior(DM9000_EPDRH) << 8) | DM9000_ior(DM9000_EPDRL); - - /* The read data keeps on REG_0D & REG_0E */ - DM9000_DBG("dm9000_phy_read(0x%x): 0x%x\n", reg, val); - return val; + return dm9000_send_common(db, packet, length); } -/* - Write a word to phyxcer -*/ -static void -dm9000_phy_write(int reg, u16 value) +static int dm9000_recv(struct eth_device *dev) { + struct dm9000_priv *db = container_of(dev, struct dm9000_priv, dev); + int ret; - /* Fill the phyxcer register into REG_0C */ - DM9000_iow(DM9000_EPAR, DM9000_PHY | reg); + ret = dm9000_recv_common(db, net_rx_packets[0]); + if (ret > 0) + net_process_received_packet(net_rx_packets[0], ret); - /* Fill the written data into REG_0D & REG_0E */ - DM9000_iow(DM9000_EPDRL, (value & 0xff)); - DM9000_iow(DM9000_EPDRH, ((value >> 8) & 0xff)); - DM9000_iow(DM9000_EPCR, 0xa); /* Issue phyxcer write command */ - udelay(500); /* Wait write complete */ - DM9000_iow(DM9000_EPCR, 0x0); /* Clear phyxcer write command */ - DM9000_DBG("dm9000_phy_write(reg:0x%x, value:0x%x)\n", reg, value); + return ret; } int dm9000_initialize(struct bd_info *bis) { - struct eth_device *dev = &(dm9000_info.netdev); + struct dm9000_priv *priv; + struct eth_device *dev; + + priv = calloc(1, sizeof(*priv)); + if (!priv) + return -ENOMEM; + + dev = &priv->dev; + + priv->base_io = (void __iomem *)DM9000_IO; + priv->base_data = (void __iomem *)DM9000_DATA; /* Load MAC address from EEPROM */ - dm9000_get_enetaddr(dev); + dm9000_get_enetaddr(priv, dev->enetaddr); dev->init = dm9000_init; dev->halt = dm9000_halt; dev->send = dm9000_send; - dev->recv = dm9000_rx; + dev->recv = dm9000_recv; strcpy(dev->name, "dm9000"); - eth_register(dev); + eth_register(&priv->dev); + + 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 = (void __iomem *)pdata->iobase; + db->base_data = (void __iomem *)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 diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c index ea0c2cf..9d255cf 100644 --- a/drivers/net/dwc_eth_qos.c +++ b/drivers/net/dwc_eth_qos.c @@ -270,7 +270,7 @@ struct eqos_config { int config_mac; int config_mac_mdio; unsigned int axi_bus_width; - phy_interface_t (*interface)(struct udevice *dev); + phy_interface_t (*interface)(const struct udevice *dev); struct eqos_ops *ops; }; @@ -1682,7 +1682,7 @@ static int eqos_probe_resources_stm32(struct udevice *dev) interface = eqos->config->interface(dev); - if (interface == PHY_INTERFACE_MODE_NONE) { + if (interface == PHY_INTERFACE_MODE_NA) { pr_err("Invalid PHY interface\n"); return -EINVAL; } @@ -1729,21 +1729,7 @@ err_probe: return ret; } -static phy_interface_t eqos_get_interface_stm32(struct udevice *dev) -{ - const char *phy_mode; - phy_interface_t interface = PHY_INTERFACE_MODE_NONE; - - debug("%s(dev=%p):\n", __func__, dev); - - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - interface = phy_get_interface_by_name(phy_mode); - - return interface; -} - -static phy_interface_t eqos_get_interface_tegra186(struct udevice *dev) +static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev) { return PHY_INTERFACE_MODE_MII; } @@ -1757,7 +1743,7 @@ static int eqos_probe_resources_imx(struct udevice *dev) interface = eqos->config->interface(dev); - if (interface == PHY_INTERFACE_MODE_NONE) { + if (interface == PHY_INTERFACE_MODE_NA) { pr_err("Invalid PHY interface\n"); return -EINVAL; } @@ -1766,20 +1752,6 @@ static int eqos_probe_resources_imx(struct udevice *dev) return 0; } -static phy_interface_t eqos_get_interface_imx(struct udevice *dev) -{ - const char *phy_mode; - phy_interface_t interface = PHY_INTERFACE_MODE_NONE; - - debug("%s(dev=%p):\n", __func__, dev); - - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - interface = phy_get_interface_by_name(phy_mode); - - return interface; -} - static int eqos_remove_resources_tegra186(struct udevice *dev) { struct eqos_priv *eqos = dev_get_priv(dev); @@ -1985,7 +1957,7 @@ static const struct eqos_config __maybe_unused eqos_stm32_config = { .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV, .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, .axi_bus_width = EQOS_AXI_WIDTH_64, - .interface = eqos_get_interface_stm32, + .interface = dev_read_phy_mode, .ops = &eqos_stm32_ops }; @@ -2013,7 +1985,7 @@ struct eqos_config __maybe_unused eqos_imx_config = { .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB, .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300, .axi_bus_width = EQOS_AXI_WIDTH_64, - .interface = eqos_get_interface_imx, + .interface = dev_read_phy_mode, .ops = &eqos_imx_ops }; diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c index 1f285f7..27b7744 100644 --- a/drivers/net/eth-phy-uclass.c +++ b/drivers/net/eth-phy-uclass.c @@ -137,7 +137,7 @@ static int eth_phy_of_to_plat(struct udevice *dev) /* search "reset-gpios" in phy node */ ret = gpio_request_by_name(dev, "reset-gpios", 0, &uc_priv->reset_gpio, - GPIOD_IS_OUT); + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); if (ret && ret != -ENOENT) return ret; diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c index 7f146d4..a219aff 100644 --- a/drivers/net/ethoc.c +++ b/drivers/net/ethoc.c @@ -614,11 +614,11 @@ static int ethoc_phy_init(struct ethoc *priv, void *dev) mask = 1 << CONFIG_PHY_ADDR; #endif - phydev = phy_find_by_mask(priv->bus, mask, PHY_INTERFACE_MODE_MII); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, PHY_INTERFACE_MODE_MII); phydev->supported &= PHY_BASIC_FEATURES; phydev->advertising = phydev->supported; diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c index e8ebef0..a623a5c 100644 --- a/drivers/net/fec_mxc.c +++ b/drivers/net/fec_mxc.c @@ -1310,20 +1310,13 @@ static int fecmxc_of_to_plat(struct udevice *dev) int ret = 0; struct eth_pdata *pdata = dev_get_plat(dev); struct fec_priv *priv = dev_get_priv(dev); - const char *phy_mode; pdata->iobase = dev_read_addr(dev); priv->eth = (struct ethernet_regs *)pdata->iobase; - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } #ifdef CONFIG_DM_REGULATOR device_get_supply_regulator(dev, "phy-supply", &priv->phy_supply); @@ -1331,7 +1324,7 @@ static int fecmxc_of_to_plat(struct udevice *dev) #if CONFIG_IS_ENABLED(DM_GPIO) ret = gpio_request_by_name(dev, "phy-reset-gpios", 0, - &priv->phy_reset_gpio, GPIOD_IS_OUT); + &priv->phy_reset_gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); if (ret < 0) return 0; /* property is optional, don't return error! */ diff --git a/drivers/net/fm/b4860.c b/drivers/net/fm/b4860.c index 6e3d008..e622d86 100644 --- a/drivers/net/fm/b4860.c +++ b/drivers/net/fm/b4860.c @@ -55,7 +55,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) #endif if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; /*B4860 has two 10Gig Mac*/ if ((port == FM1_10GEC1 || port == FM1_10GEC2) && @@ -112,7 +112,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) (port == FM1_DTSEC2) || (port == FM1_DTSEC3) || (port == FM1_DTSEC4)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } } } @@ -131,8 +131,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c index 5e0d0bc..1ffe9e2 100644 --- a/drivers/net/fm/eth.c +++ b/drivers/net/fm/eth.c @@ -954,17 +954,6 @@ int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info) return 0; } #else /* CONFIG_DM_ETH */ -#ifdef CONFIG_PHYLIB -phy_interface_t fman_read_sys_if(struct udevice *dev) -{ - const char *if_str; - - if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type"); - debug("MAC system interface mode %s\n", if_str); - - return phy_get_interface_by_name(if_str); -} -#endif static int fm_eth_bind(struct udevice *dev) { @@ -1038,7 +1027,7 @@ static int fm_eth_probe(struct udevice *dev) reg = (void *)(uintptr_t)dev_read_addr(dev); fm_eth->mac_type = dev_get_driver_data(dev); #ifdef CONFIG_PHYLIB - fm_eth->enet_if = fman_read_sys_if(dev); + fm_eth->enet_if = dev_read_phy_mode(dev); #else fm_eth->enet_if = PHY_INTERFACE_MODE_SGMII; printf("%s: warning - unable to determine interface type\n", __func__); diff --git a/drivers/net/fm/init.c b/drivers/net/fm/init.c index 2fed642..af94dab 100644 --- a/drivers/net/fm/init.c +++ b/drivers/net/fm/init.c @@ -130,7 +130,7 @@ static int fm_port_to_index(enum fm_port port) /* * Determine if an interface is actually active based on HW config - * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NONE if + * we expect fman_port_enet_if() to report PHY_INTERFACE_MODE_NA if * the interface is not active based on HW cfg of the SoC */ void fman_enet_init(void) @@ -141,7 +141,7 @@ void fman_enet_init(void) phy_interface_t enet_if; enet_if = fman_port_enet_if(fm_info[i].port); - if (enet_if != PHY_INTERFACE_MODE_NONE) { + if (enet_if != PHY_INTERFACE_MODE_NA) { fm_info[i].enabled = 1; fm_info[i].enet_if = enet_if; } else { @@ -221,12 +221,12 @@ phy_interface_t fm_info_get_enet_if(enum fm_port port) int i = fm_port_to_index(port); if (i == -1) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (fm_info[i].enabled) return fm_info[i].enet_if; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } static void diff --git a/drivers/net/fm/ls1043.c b/drivers/net/fm/ls1043.c index e1abf8f..cd8376a 100644 --- a/drivers/net/fm/ls1043.c +++ b/drivers/net/fm/ls1043.c @@ -54,13 +54,13 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC9))) return PHY_INTERFACE_MODE_XGMII; if ((port == FM1_DTSEC9) && (is_serdes_configured(XFI_FM1_MAC9))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (port == FM1_DTSEC3) if ((rcwsr13 & FSL_CHASSIS2_RCWSR13_EC1) == @@ -107,5 +107,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/ls1046.c b/drivers/net/fm/ls1046.c index 09df0aa..876f48b 100644 --- a/drivers/net/fm/ls1046.c +++ b/drivers/net/fm/ls1046.c @@ -54,19 +54,19 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC9))) return PHY_INTERFACE_MODE_XGMII; if ((port == FM1_DTSEC9) && (is_serdes_configured(XFI_FM1_MAC9))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC2) && (is_serdes_configured(XFI_FM1_MAC10))) return PHY_INTERFACE_MODE_XGMII; if ((port == FM1_DTSEC10) && (is_serdes_configured(XFI_FM1_MAC10))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (port == FM1_DTSEC3) if ((rcwsr13 & FSL_CHASSIS2_RCWSR13_EC1) == @@ -118,5 +118,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p1023.c b/drivers/net/fm/p1023.c index d4167e4..c9b85fc 100644 --- a/drivers/net/fm/p1023.c +++ b/drivers/net/fm/p1023.c @@ -46,7 +46,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 pordevsr = in_be32(&gur->pordevsr); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; /* DTSEC1 can be SGMII, RGMII or RMII */ if (port == FM1_DTSEC1) { @@ -68,5 +68,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_RGMII; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p4080.c b/drivers/net/fm/p4080.c index b78b02d..577ee22 100644 --- a/drivers/net/fm/p4080.c +++ b/drivers/net/fm/p4080.c @@ -54,7 +54,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr11 = in_be32(&gur->rcwsr[11]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1))) return PHY_INTERFACE_MODE_XGMII; @@ -91,8 +91,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p5020.c b/drivers/net/fm/p5020.c index 8189531..8ecc482 100644 --- a/drivers/net/fm/p5020.c +++ b/drivers/net/fm/p5020.c @@ -50,7 +50,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr11 = in_be32(&gur->rcwsr[11]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1))) return PHY_INTERFACE_MODE_XGMII; @@ -82,8 +82,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/p5040.c b/drivers/net/fm/p5040.c index 38744e7..3a1494d 100644 --- a/drivers/net/fm/p5040.c +++ b/drivers/net/fm/p5040.c @@ -56,7 +56,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr11 = in_be32(&gur->rcwsr[11]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XAUI_FM1))) return PHY_INTERFACE_MODE_XGMII; @@ -99,8 +99,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t1024.c b/drivers/net/fm/t1024.c index 696e74c..7110fb4 100644 --- a/drivers/net/fm/t1024.c +++ b/drivers/net/fm/t1024.c @@ -39,7 +39,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1) && (is_serdes_configured(XFI_FM1_MAC1))) return PHY_INTERFACE_MODE_XGMII; @@ -83,5 +83,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t1040.c b/drivers/net/fm/t1040.c index af4f5c5..192f1c6 100644 --- a/drivers/net/fm/t1040.c +++ b/drivers/net/fm/t1040.c @@ -56,8 +56,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t2080.c b/drivers/net/fm/t2080.c index f4d8d2d..bfbd8de 100644 --- a/drivers/net/fm/t2080.c +++ b/drivers/net/fm/t2080.c @@ -47,7 +47,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1 || port == FM1_10GEC2) && ((is_serdes_configured(XAUI_FM1_MAC9)) || @@ -85,8 +85,8 @@ phy_interface_t fman_port_enet_if(enum fm_port port) return PHY_INTERFACE_MODE_SGMII; break; default: - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fm/t4240.c b/drivers/net/fm/t4240.c index f8e63c3..ba7b862 100644 --- a/drivers/net/fm/t4240.c +++ b/drivers/net/fm/t4240.c @@ -61,7 +61,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) u32 rcwsr13 = in_be32(&gur->rcwsr[13]); if (is_device_disabled(port)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM1_10GEC1 || port == FM1_10GEC2) && ((is_serdes_configured(XAUI_FM1_MAC9)) || @@ -73,7 +73,7 @@ phy_interface_t fman_port_enet_if(enum fm_port port) if ((port == FM1_DTSEC9 || port == FM1_DTSEC10) && ((is_serdes_configured(XFI_FM1_MAC9)) || (is_serdes_configured(XFI_FM1_MAC10)))) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if ((port == FM2_10GEC1 || port == FM2_10GEC2) && ((is_serdes_configured(XAUI_FM2_MAC9)) || @@ -166,5 +166,5 @@ phy_interface_t fman_port_enet_if(enum fm_port port) break; } - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c index 915c7c8..1724f94 100644 --- a/drivers/net/fsl_enetc.c +++ b/drivers/net/fsl_enetc.c @@ -260,9 +260,6 @@ static int enetc_init_sxgmii(struct udevice *dev) static void enetc_start_pcs(struct udevice *dev) { struct enetc_priv *priv = dev_get_priv(dev); - const char *if_str; - - priv->if_type = PHY_INTERFACE_MODE_NONE; /* register internal MDIO for debug purposes */ if (enetc_read_port(priv, ENETC_PCAPR0) & ENETC_PCAPRO_MDIO) { @@ -279,14 +276,12 @@ static void enetc_start_pcs(struct udevice *dev) return; } - if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode"); - if (if_str) - priv->if_type = phy_get_interface_by_name(if_str); - else + priv->if_type = dev_read_phy_mode(dev); + if (priv->if_type == PHY_INTERFACE_MODE_NA) { enetc_dbg(dev, "phy-mode property not found, defaulting to SGMII\n"); - if (priv->if_type < 0) - priv->if_type = PHY_INTERFACE_MODE_NONE; + priv->if_type = PHY_INTERFACE_MODE_SGMII; + } switch (priv->if_type) { case PHY_INTERFACE_MODE_SGMII: diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c index aa719d2..78779d7 100644 --- a/drivers/net/ftgmac100.c +++ b/drivers/net/ftgmac100.c @@ -549,17 +549,12 @@ static int ftgmac100_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct ftgmac100_data *priv = dev_get_priv(dev); - const char *phy_mode; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0); diff --git a/drivers/net/higmacv300.c b/drivers/net/higmacv300.c index aa79d6e..1862235 100644 --- a/drivers/net/higmacv300.c +++ b/drivers/net/higmacv300.c @@ -561,19 +561,14 @@ static int higmac_remove(struct udevice *dev) static int higmac_of_to_plat(struct udevice *dev) { struct higmac_priv *priv = dev_get_priv(dev); - int phyintf = PHY_INTERFACE_MODE_NONE; - const char *phy_mode; ofnode phy_node; priv->base = dev_remap_addr_index(dev, 0); priv->macif_ctrl = dev_remap_addr_index(dev, 1); - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) - phyintf = phy_get_interface_by_name(phy_mode); - if (phyintf == PHY_INTERFACE_MODE_NONE) + priv->phyintf = dev_read_phy_mode(dev); + if (priv->phyintf == PHY_INTERFACE_MODE_NA) return -ENODEV; - priv->phyintf = phyintf; phy_node = dev_read_subnode(dev, "phy"); if (!ofnode_valid(phy_node)) { diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c index 725173f..b6f589e 100644 --- a/drivers/net/ldpaa_eth/ldpaa_eth.c +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c @@ -1120,31 +1120,14 @@ static uint32_t ldpaa_eth_get_dpmac_id(struct udevice *dev) return fdtdec_get_uint(gd->fdt_blob, port_node, "reg", -1); } -static const char *ldpaa_eth_get_phy_mode_str(struct udevice *dev) -{ - int port_node = dev_of_offset(dev); - const char *phy_mode_str; - - phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, - "phy-connection-type", NULL); - if (phy_mode_str) - return phy_mode_str; - - phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL); - return phy_mode_str; -} - static int ldpaa_eth_bind(struct udevice *dev) { - const char *phy_mode_str = NULL; uint32_t dpmac_id; char eth_name[16]; int phy_mode = -1; - phy_mode_str = ldpaa_eth_get_phy_mode_str(dev); - if (phy_mode_str) - phy_mode = phy_get_interface_by_name(phy_mode_str); - if (phy_mode == -1) { + phy_mode = dev_read_phy_mode(dev); + if (phy_mode == PHY_INTERFACE_MODE_NA) { dev_err(dev, "incorrect phy mode\n"); return -EINVAL; } @@ -1155,7 +1138,8 @@ static int ldpaa_eth_bind(struct udevice *dev) return -EINVAL; } - sprintf(eth_name, "DPMAC%d@%s", dpmac_id, phy_mode_str); + sprintf(eth_name, "DPMAC%d@%s", dpmac_id, + phy_string_for_interface(phy_mode)); device_set_name(dev, eth_name); return 0; @@ -1164,11 +1148,9 @@ static int ldpaa_eth_bind(struct udevice *dev) static int ldpaa_eth_of_to_plat(struct udevice *dev) { struct ldpaa_eth_priv *priv = dev_get_priv(dev); - const char *phy_mode_str; priv->dpmac_id = ldpaa_eth_get_dpmac_id(dev); - phy_mode_str = ldpaa_eth_get_phy_mode_str(dev); - priv->phy_mode = phy_get_interface_by_name(phy_mode_str); + priv->phy_mode = dev_read_phy_mode(dev); return 0; } diff --git a/drivers/net/ldpaa_eth/ldpaa_wriop.c b/drivers/net/ldpaa_eth/ldpaa_wriop.c index 06a284a..adecb81 100644 --- a/drivers/net/ldpaa_eth/ldpaa_wriop.c +++ b/drivers/net/ldpaa_eth/ldpaa_wriop.c @@ -16,7 +16,7 @@ struct wriop_dpmac_info dpmac_info[NUM_WRIOP_PORTS]; __weak phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtc) { - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) @@ -26,10 +26,10 @@ void wriop_init_dpmac(int sd, int dpmac_id, int lane_prtcl) dpmac_info[dpmac_id].enabled = 0; dpmac_info[dpmac_id].id = 0; - dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NONE; + dpmac_info[dpmac_id].enet_if = PHY_INTERFACE_MODE_NA; enet_if = wriop_dpmac_enet_if(dpmac_id, lane_prtcl); - if (enet_if != PHY_INTERFACE_MODE_NONE) { + if (enet_if != PHY_INTERFACE_MODE_NA) { dpmac_info[dpmac_id].enabled = 1; dpmac_info[dpmac_id].id = dpmac_id; dpmac_info[dpmac_id].enet_if = enet_if; @@ -183,10 +183,10 @@ phy_interface_t wriop_get_enet_if(int dpmac_id) int i = wriop_dpmac_to_index(dpmac_id); if (i == -1) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (dpmac_info[i].enabled) return dpmac_info[i].enet_if; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } diff --git a/drivers/net/ldpaa_eth/ls1088a.c b/drivers/net/ldpaa_eth/ls1088a.c index 54cb16e..943113b 100644 --- a/drivers/net/ldpaa_eth/ls1088a.c +++ b/drivers/net/ldpaa_eth/ls1088a.c @@ -50,7 +50,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) enum srds_prtcl; if (is_device_disabled(dpmac_id + 1)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; switch (lane_prtcl) { case SGMII1: @@ -66,7 +66,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) if (lane_prtcl >= QSGMII_A && lane_prtcl <= QSGMII_B) return PHY_INTERFACE_MODE_QSGMII; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl) diff --git a/drivers/net/ldpaa_eth/ls2080a.c b/drivers/net/ldpaa_eth/ls2080a.c index 49eee04..62e1d6b 100644 --- a/drivers/net/ldpaa_eth/ls2080a.c +++ b/drivers/net/ldpaa_eth/ls2080a.c @@ -62,7 +62,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) enum srds_prtcl; if (is_device_disabled(dpmac_id + 1)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (lane_prtcl >= SGMII1 && lane_prtcl <= SGMII16) return PHY_INTERFACE_MODE_SGMII; @@ -76,7 +76,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) if (lane_prtcl >= QSGMII_A && lane_prtcl <= QSGMII_D) return PHY_INTERFACE_MODE_QSGMII; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } void wriop_init_dpmac_qsgmii(int sd, int lane_prtcl) diff --git a/drivers/net/ldpaa_eth/lx2160a.c b/drivers/net/ldpaa_eth/lx2160a.c index e57f1a1..f0f8ee1 100644 --- a/drivers/net/ldpaa_eth/lx2160a.c +++ b/drivers/net/ldpaa_eth/lx2160a.c @@ -58,7 +58,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) enum srds_prtcl; if (is_device_disabled(dpmac_id)) - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; if (lane_prtcl >= SGMII1 && lane_prtcl <= SGMII18) return PHY_INTERFACE_MODE_SGMII; @@ -78,7 +78,7 @@ phy_interface_t wriop_dpmac_enet_if(int dpmac_id, int lane_prtcl) if (lane_prtcl >= _100GE1 && lane_prtcl <= _100GE2) return PHY_INTERFACE_MODE_CAUI4; - return PHY_INTERFACE_MODE_NONE; + return PHY_INTERFACE_MODE_NA; } #ifdef CONFIG_SYS_FSL_HAS_RGMII diff --git a/drivers/net/macb.c b/drivers/net/macb.c index 37eed59..e02a57b 100644 --- a/drivers/net/macb.c +++ b/drivers/net/macb.c @@ -1360,17 +1360,11 @@ static int macb_eth_probe(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct macb_device *macb = dev_get_priv(dev); struct ofnode_phandle_args phandle_args; - const char *phy_mode; int ret; - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - - if (phy_mode) - macb->phy_interface = phy_get_interface_by_name(phy_mode); - if (macb->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + macb->phy_interface = dev_read_phy_mode(dev); + if (macb->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } /* Read phyaddr from DT */ if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, diff --git a/drivers/net/mdio_mux_sandbox.c b/drivers/net/mdio_mux_sandbox.c index fff6ddb..e1801c1 100644 --- a/drivers/net/mdio_mux_sandbox.c +++ b/drivers/net/mdio_mux_sandbox.c @@ -20,7 +20,6 @@ struct mdio_mux_sandbox_priv { static int mdio_mux_sandbox_mark_selection(struct udevice *dev, int sel) { struct udevice *mdio; - struct mdio_ops *ops; int err; /* @@ -30,9 +29,8 @@ static int mdio_mux_sandbox_mark_selection(struct udevice *dev, int sel) err = uclass_get_device_by_name(UCLASS_MDIO, "mdio-test", &mdio); if (err) return err; - ops = mdio_get_ops(mdio); - return ops->write(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, - SANDBOX_PHY_REG_CNT - 1, (u16)sel); + return dm_mdio_write(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE, + SANDBOX_PHY_REG_CNT - 1, (u16)sel); } static int mdio_mux_sandbox_select(struct udevice *dev, int cur, int sel) diff --git a/drivers/net/mscc_eswitch/jr2_switch.c b/drivers/net/mscc_eswitch/jr2_switch.c index d1e5b61..1462b8f 100644 --- a/drivers/net/mscc_eswitch/jr2_switch.c +++ b/drivers/net/mscc_eswitch/jr2_switch.c @@ -954,7 +954,7 @@ static int jr2_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/luton_switch.c b/drivers/net/mscc_eswitch/luton_switch.c index 73c950d..5e4f00c 100644 --- a/drivers/net/mscc_eswitch/luton_switch.c +++ b/drivers/net/mscc_eswitch/luton_switch.c @@ -685,7 +685,7 @@ static int luton_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy && i >= MAX_INT_PORT) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/ocelot_switch.c b/drivers/net/mscc_eswitch/ocelot_switch.c index d1d0a48..1bf6c42 100644 --- a/drivers/net/mscc_eswitch/ocelot_switch.c +++ b/drivers/net/mscc_eswitch/ocelot_switch.c @@ -608,7 +608,7 @@ static int ocelot_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy && external_bus(priv, i)) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/serval_switch.c b/drivers/net/mscc_eswitch/serval_switch.c index c4b81f7..38ddba1 100644 --- a/drivers/net/mscc_eswitch/serval_switch.c +++ b/drivers/net/mscc_eswitch/serval_switch.c @@ -561,7 +561,7 @@ static int serval_probe(struct udevice *dev) phy = phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); if (phy) board_phy_config(phy); } diff --git a/drivers/net/mscc_eswitch/servalt_switch.c b/drivers/net/mscc_eswitch/servalt_switch.c index f114086..db863c2 100644 --- a/drivers/net/mscc_eswitch/servalt_switch.c +++ b/drivers/net/mscc_eswitch/servalt_switch.c @@ -482,7 +482,7 @@ static int servalt_probe(struct udevice *dev) continue; phy_connect(priv->ports[i].bus, priv->ports[i].phy_addr, dev, - PHY_INTERFACE_MODE_NONE); + PHY_INTERFACE_MODE_NA); } return 0; diff --git a/drivers/net/mt7620-eth.c b/drivers/net/mt7620-eth.c index 222250d..038cba1 100644 --- a/drivers/net/mt7620-eth.c +++ b/drivers/net/mt7620-eth.c @@ -596,7 +596,7 @@ static int mt7620_setup_gmac_mode(struct mt7620_eth_priv *priv, u32 gmac, case PHY_INTERFACE_MODE_RGMII: ge_mode = MT7620_SYSC_GE_RGMII; break; - case PHY_INTERFACE_MODE_NONE: + case PHY_INTERFACE_MODE_NA: if (gmac == 2) ge_mode = MT7620_SYSC_GE_ESW_PHY; else @@ -620,7 +620,7 @@ static void mt7620_gsw_setup_port(struct mt7620_eth_priv *priv, u32 port, { u32 pmcr; - if (port_cfg->mode == PHY_INTERFACE_MODE_NONE) { + if (port_cfg->mode == PHY_INTERFACE_MODE_NA) { if (port == 5) { gsw_write(priv, GSW_PMCR(port), FORCE_MODE); return; @@ -666,7 +666,7 @@ static void mt7620_gsw_setup_phy_polling(struct mt7620_eth_priv *priv) { int phy_addr_st, phy_addr_end; - if (priv->port_cfg[0].mode == PHY_INTERFACE_MODE_NONE) + if (priv->port_cfg[0].mode == PHY_INTERFACE_MODE_NA) priv->ephy_num = NUM_FE_PHYS; else priv->ephy_num = NUM_FE_PHYS - 1; @@ -1048,33 +1048,20 @@ static int mt7620_eth_parse_gsw_port(struct mt7620_eth_priv *priv, u32 idx, ofnode node) { ofnode subnode; - const char *str; - int mode, speed, ret; + int speed, ret; u32 phy_addr; - str = ofnode_read_string(node, "phy-mode"); - if (str) { - mode = phy_get_interface_by_name(str); - if (mode < 0) { - dev_err(priv->dev, "mt7620_eth: invalid phy-mode\n"); - return -EINVAL; - } - - switch (mode) { - case PHY_INTERFACE_MODE_MII: - case PHY_INTERFACE_MODE_RMII: - case PHY_INTERFACE_MODE_RGMII: - case PHY_INTERFACE_MODE_NONE: - break; - default: - dev_err(priv->dev, - "mt7620_eth: unsupported phy-mode\n"); - return -ENOTSUPP; - } + priv->port_cfg[idx].mode = ofnode_read_phy_mode(node); - priv->port_cfg[idx].mode = mode; - } else { - priv->port_cfg[idx].mode = PHY_INTERFACE_MODE_NONE; + switch (priv->port_cfg[idx].mode) { + case PHY_INTERFACE_MODE_MII: + case PHY_INTERFACE_MODE_RMII: + case PHY_INTERFACE_MODE_RGMII: + case PHY_INTERFACE_MODE_NA: + break; + default: + dev_err(priv->dev, "mt7620_eth: unsupported phy-mode\n"); + return -ENOTSUPP; } subnode = ofnode_find_subnode(node, "fixed-link"); @@ -1141,14 +1128,14 @@ static int mt7620_eth_parse_gsw_cfg(struct udevice *dev) if (ret) return ret; } else { - priv->port_cfg[0].mode = PHY_INTERFACE_MODE_NONE; + priv->port_cfg[0].mode = PHY_INTERFACE_MODE_NA; } subnode = ofnode_find_subnode(dev_ofnode(dev), "port5"); if (ofnode_valid(subnode)) return mt7620_eth_parse_gsw_port(priv, 1, subnode); - priv->port_cfg[1].mode = PHY_INTERFACE_MODE_NONE; + priv->port_cfg[1].mode = PHY_INTERFACE_MODE_NA; return 0; } diff --git a/drivers/net/mtk_eth.c b/drivers/net/mtk_eth.c index 26f0284..666ddeb 100644 --- a/drivers/net/mtk_eth.c +++ b/drivers/net/mtk_eth.c @@ -1447,11 +1447,9 @@ static int mtk_eth_of_to_plat(struct udevice *dev) priv->gmac_id = dev_read_u32_default(dev, "mediatek,gmac-id", 0); /* Interface mode is required */ - str = dev_read_string(dev, "phy-mode"); - if (str) { - pdata->phy_interface = phy_get_interface_by_name(str); - priv->phy_interface = pdata->phy_interface; - } else { + pdata->phy_interface = dev_read_phy_mode(dev); + priv->phy_interface = pdata->phy_interface; + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) { printf("error: phy-mode is not set\n"); return -EINVAL; } diff --git a/drivers/net/mvgbe.c b/drivers/net/mvgbe.c index 954bf86..bf5ed55 100644 --- a/drivers/net/mvgbe.c +++ b/drivers/net/mvgbe.c @@ -993,7 +993,6 @@ static int mvgbe_of_to_plat(struct udevice *dev) struct mvgbe_device *dmvgbe = dev_get_priv(dev); void *blob = (void *)gd->fdt_blob; int node = dev_of_offset(dev); - const char *phy_mode; int fl_node; int pnode; unsigned long addr; @@ -1005,10 +1004,8 @@ static int mvgbe_of_to_plat(struct udevice *dev) "marvell,kirkwood-eth-port"); /* Get phy-mode / phy_interface from DT */ - phy_mode = fdt_getprop(gd->fdt_blob, pnode, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - else + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) pdata->phy_interface = PHY_INTERFACE_MODE_GMII; dmvgbe->phy_interface = pdata->phy_interface; diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c index 4a4268c..e2ac4d8 100644 --- a/drivers/net/mvneta.c +++ b/drivers/net/mvneta.c @@ -1799,20 +1799,13 @@ static const struct eth_ops mvneta_ops = { static int mvneta_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; pdata->iobase = dev_read_addr(dev); /* Get phy-mode / phy_interface from DT */ - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } return 0; } diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c index 4c0a7b0..8c9afdf 100644 --- a/drivers/net/mvpp2.c +++ b/drivers/net/mvpp2.c @@ -4786,11 +4786,9 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port) static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) { int port_node = dev_of_offset(dev); - const char *phy_mode_str; int phy_node; u32 id; u32 phyaddr = 0; - int phy_mode = -1; int fixed_link = 0; int ret; @@ -4821,10 +4819,8 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) phyaddr = PHY_MAX_ADDR; } - phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL); - if (phy_mode_str) - phy_mode = phy_get_interface_by_name(phy_mode_str); - if (phy_mode == -1) { + port->phy_interface = dev_read_phy_mode(dev); + if (port->phy_interface == PHY_INTERFACE_MODE_NA) { dev_err(dev, "incorrect phy mode\n"); return -EINVAL; } @@ -4847,7 +4843,6 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port) port->first_rxq = port->id * rxq_number; else port->first_rxq = port->id * port->priv->max_port_rxqs; - port->phy_interface = phy_mode; port->phyaddr = phyaddr; return 0; diff --git a/drivers/net/pch_gbe.c b/drivers/net/pch_gbe.c index fabcf85..f189524 100644 --- a/drivers/net/pch_gbe.c +++ b/drivers/net/pch_gbe.c @@ -416,13 +416,13 @@ static int pch_gbe_phy_init(struct udevice *dev) struct phy_device *phydev; int mask = 0xffffffff; - phydev = phy_find_by_mask(priv->bus, mask, plat->phy_interface); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) { printf("pch_gbe: cannot find the phy\n"); return -1; } - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, plat->phy_interface); phydev->supported &= PHY_GBIT_FEATURES; phydev->advertising = phydev->supported; diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index d40ce92..33a4b6f 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -68,6 +68,11 @@ endif # MV88E61XX_SWITCH config PHYLIB_10G bool "Generic 10G PHY support" +config PHY_ADIN + bool "Analog Devices Industrial Ethernet PHYs" + help + Add support for configuring RGMII on Analog Devices ADIN PHYs. + menuconfig PHY_AQUANTIA bool "Aquantia Ethernet PHYs support" select PHY_GIGE diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 67ca4d3..9d87eb2 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MV88E6352_SWITCH) += mv88e6352.o obj-$(CONFIG_PHYLIB) += phy.o obj-$(CONFIG_PHYLIB_10G) += generic_10g.o +obj-$(CONFIG_PHY_ADIN) += adin.o obj-$(CONFIG_PHY_AQUANTIA) += aquantia.o obj-$(CONFIG_PHY_ATHEROS) += atheros.o obj-$(CONFIG_PHY_BROADCOM) += broadcom.o diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c new file mode 100644 index 0000000..cff841a --- /dev/null +++ b/drivers/net/phy/adin.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0+ +/** + * Driver for Analog Devices Industrial Ethernet PHYs + * + * Copyright 2019 Analog Devices Inc. + * Copyright 2022 Variscite Ltd. + */ +#include <common.h> +#include <phy.h> +#include <linux/bitops.h> +#include <linux/bitfield.h> + +#define PHY_ID_ADIN1300 0x0283bc30 +#define ADIN1300_EXT_REG_PTR 0x10 +#define ADIN1300_EXT_REG_DATA 0x11 +#define ADIN1300_GE_RGMII_CFG 0xff23 +#define ADIN1300_GE_RGMII_RX_MSK GENMASK(8, 6) +#define ADIN1300_GE_RGMII_RX_SEL(x) \ + FIELD_PREP(ADIN1300_GE_RGMII_RX_MSK, x) +#define ADIN1300_GE_RGMII_GTX_MSK GENMASK(5, 3) +#define ADIN1300_GE_RGMII_GTX_SEL(x) \ + FIELD_PREP(ADIN1300_GE_RGMII_GTX_MSK, x) +#define ADIN1300_GE_RGMII_RXID_EN BIT(2) +#define ADIN1300_GE_RGMII_TXID_EN BIT(1) +#define ADIN1300_GE_RGMII_EN BIT(0) + +/* RGMII internal delay settings for rx and tx for ADIN1300 */ +#define ADIN1300_RGMII_1_60_NS 0x0001 +#define ADIN1300_RGMII_1_80_NS 0x0002 +#define ADIN1300_RGMII_2_00_NS 0x0000 +#define ADIN1300_RGMII_2_20_NS 0x0006 +#define ADIN1300_RGMII_2_40_NS 0x0007 + +/** + * struct adin_cfg_reg_map - map a config value to aregister value + * @cfg value in device configuration + * @reg value in the register + */ +struct adin_cfg_reg_map { + int cfg; + int reg; +}; + +static const struct adin_cfg_reg_map adin_rgmii_delays[] = { + { 1600, ADIN1300_RGMII_1_60_NS }, + { 1800, ADIN1300_RGMII_1_80_NS }, + { 2000, ADIN1300_RGMII_2_00_NS }, + { 2200, ADIN1300_RGMII_2_20_NS }, + { 2400, ADIN1300_RGMII_2_40_NS }, + { }, +}; + +static int adin_lookup_reg_value(const struct adin_cfg_reg_map *tbl, int cfg) +{ + size_t i; + + for (i = 0; tbl[i].cfg; i++) { + if (tbl[i].cfg == cfg) + return tbl[i].reg; + } + + return -EINVAL; +} + +static u32 adin_get_reg_value(struct phy_device *phydev, + const char *prop_name, + const struct adin_cfg_reg_map *tbl, + u32 dflt) +{ + u32 val; + int rc; + + ofnode node = phy_get_ofnode(phydev); + if (!ofnode_valid(node)) { + printf("%s: failed to get node\n", __func__); + return -EINVAL; + } + + if (ofnode_read_u32(node, prop_name, &val)) { + printf("%s: failed to find %s, using default %d\n", + __func__, prop_name, dflt); + return dflt; + } + + debug("%s: %s = '%d'\n", __func__, prop_name, val); + + rc = adin_lookup_reg_value(tbl, val); + if (rc < 0) { + printf("%s: Unsupported value %u for %s using default (%u)\n", + __func__, val, prop_name, dflt); + return dflt; + } + + return rc; +} + +/** + * adin_get_phy_mode_override - Get phy-mode override for adin PHY + * + * The function gets phy-mode string from property 'adi,phy-mode-override' + * and return its index in phy_interface_strings table, or -1 in error case. + */ +int adin_get_phy_mode_override(struct phy_device *phydev) +{ + ofnode node = phy_get_ofnode(phydev); + const char *phy_mode_override; + const char *prop_phy_mode_override = "adi,phy-mode-override"; + int override_interface; + + phy_mode_override = ofnode_read_string(node, prop_phy_mode_override); + if (!phy_mode_override) + return -ENODEV; + + debug("%s: %s = '%s'\n", + __func__, prop_phy_mode_override, phy_mode_override); + + override_interface = phy_get_interface_by_name(phy_mode_override); + + if (override_interface < 0) + printf("%s: %s = '%s' is not valid\n", + __func__, prop_phy_mode_override, phy_mode_override); + + return override_interface; +} + +static u16 adin_ext_read(struct phy_device *phydev, const u32 regnum) +{ + u16 val; + + phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_PTR, regnum); + val = phy_read(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_DATA); + + debug("%s: adin@0x%x 0x%x=0x%x\n", __func__, phydev->addr, regnum, val); + + return val; +} + +static int adin_ext_write(struct phy_device *phydev, const u32 regnum, const u16 val) +{ + debug("%s: adin@0x%x 0x%x=0x%x\n", __func__, phydev->addr, regnum, val); + + phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_PTR, regnum); + + return phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_DATA, val); +} + +static int adin_config_rgmii_mode(struct phy_device *phydev) +{ + u16 reg_val; + u32 val; + int phy_mode_override = adin_get_phy_mode_override(phydev); + + if (phy_mode_override >= 0) { + phydev->interface = (phy_interface_t) phy_mode_override; + } + + reg_val = adin_ext_read(phydev, ADIN1300_GE_RGMII_CFG); + + if (!phy_interface_is_rgmii(phydev)) { + /* Disable RGMII */ + reg_val &= ~ADIN1300_GE_RGMII_EN; + return adin_ext_write(phydev, ADIN1300_GE_RGMII_CFG, reg_val); + } + + /* Enable RGMII */ + reg_val |= ADIN1300_GE_RGMII_EN; + + /* Enable / Disable RGMII RX Delay */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { + reg_val |= ADIN1300_GE_RGMII_RXID_EN; + + val = adin_get_reg_value(phydev, "adi,rx-internal-delay-ps", + adin_rgmii_delays, + ADIN1300_RGMII_2_00_NS); + reg_val &= ~ADIN1300_GE_RGMII_RX_MSK; + reg_val |= ADIN1300_GE_RGMII_RX_SEL(val); + } else { + reg_val &= ~ADIN1300_GE_RGMII_RXID_EN; + } + + /* Enable / Disable RGMII RX Delay */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { + reg_val |= ADIN1300_GE_RGMII_TXID_EN; + + val = adin_get_reg_value(phydev, "adi,tx-internal-delay-ps", + adin_rgmii_delays, + ADIN1300_RGMII_2_00_NS); + reg_val &= ~ADIN1300_GE_RGMII_GTX_MSK; + reg_val |= ADIN1300_GE_RGMII_GTX_SEL(val); + } else { + reg_val &= ~ADIN1300_GE_RGMII_TXID_EN; + } + + return adin_ext_write(phydev, ADIN1300_GE_RGMII_CFG, reg_val); +} + +static int adin1300_config(struct phy_device *phydev) +{ + int ret; + + printf("ADIN1300 PHY detected at addr %d\n", phydev->addr); + + ret = adin_config_rgmii_mode(phydev); + + if (ret < 0) + return ret; + + return genphy_config(phydev); +} + +static struct phy_driver ADIN1300_driver = { + .name = "ADIN1300", + .uid = PHY_ID_ADIN1300, + .mask = 0xffffffff, + .features = PHY_GBIT_FEATURES, + .config = adin1300_config, + .startup = genphy_startup, + .shutdown = genphy_shutdown, +}; + +int phy_adin_init(void) +{ + phy_register(&ADIN1300_driver); + + return 0; +} diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c index 83075f7..7e950fe 100644 --- a/drivers/net/phy/aquantia.c +++ b/drivers/net/phy/aquantia.c @@ -305,7 +305,7 @@ struct { u16 syscfg; int cnt; u16 start_rate; -} aquantia_syscfg[PHY_INTERFACE_MODE_COUNT] = { +} aquantia_syscfg[PHY_INTERFACE_MODE_MAX] = { [PHY_INTERFACE_MODE_SGMII] = {0x04b, AQUANTIA_VND1_GSYSCFG_1G, AQUANTIA_VND1_GSTART_RATE_1G}, [PHY_INTERFACE_MODE_2500BASEX] = {0x144, AQUANTIA_VND1_GSYSCFG_2_5G, diff --git a/drivers/net/phy/atheros.c b/drivers/net/phy/atheros.c index f922fec..fa1fe08 100644 --- a/drivers/net/phy/atheros.c +++ b/drivers/net/phy/atheros.c @@ -199,7 +199,7 @@ static int ar803x_of_init(struct phy_device *phydev) node = phy_get_ofnode(phydev); if (!ofnode_valid(node)) - return -EINVAL; + return 0; priv = malloc(sizeof(*priv)); if (!priv) diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index eada454..3d86263 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -158,7 +158,7 @@ static int dp83867_of_init(struct phy_device *phydev) node = phy_get_ofnode(phydev); if (!ofnode_valid(node)) - return -EINVAL; + return 0; /* Optional configuration */ ret = ofnode_read_u32(node, "ti,clk-output-sel", @@ -266,7 +266,7 @@ static int dp83867_of_init(struct phy_device *phydev) static int dp83867_config(struct phy_device *phydev) { struct dp83867_private *dp83867; - unsigned int val, delay, cfg2; + int val, delay, cfg2; int ret, bs; dp83867 = (struct dp83867_private *)phydev->priv; @@ -291,8 +291,11 @@ static int dp83867_config(struct phy_device *phydev) if (phy_interface_is_rgmii(phydev)) { val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); - if (val < 0) + if (val < 0) { + ret = val; goto err_out; + } + val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK; val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT); diff --git a/drivers/net/phy/ethernet_id.c b/drivers/net/phy/ethernet_id.c index 1a78a75..8864f99 100644 --- a/drivers/net/phy/ethernet_id.c +++ b/drivers/net/phy/ethernet_id.c @@ -12,7 +12,7 @@ #include <asm/gpio.h> struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, - int phyaddr, phy_interface_t interface) + int phyaddr) { struct phy_device *phydev; struct ofnode_phandle_args phandle_args; @@ -68,7 +68,7 @@ struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, } id = vendor << 16 | device; - phydev = phy_device_create(bus, phyaddr, id, false, interface); + phydev = phy_device_create(bus, phyaddr, id, false); if (phydev) phydev->node = node; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 3672262..1121b99 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -490,6 +490,9 @@ int phy_init(void) #ifdef CONFIG_MV88E61XX_SWITCH phy_mv88e61xx_init(); #endif +#ifdef CONFIG_PHY_ADIN + phy_adin_init(); +#endif #ifdef CONFIG_PHY_AQUANTIA phy_aquantia_init(); #endif @@ -635,18 +638,17 @@ static int phy_probe(struct phy_device *phydev) return err; } -static struct phy_driver *generic_for_interface(phy_interface_t interface) +static struct phy_driver *generic_for_phy(struct phy_device *phydev) { #ifdef CONFIG_PHYLIB_10G - if (is_10g_interface(interface)) + if (phydev->is_c45) return &gen10g_driver; #endif return &genphy_driver; } -static struct phy_driver *get_phy_driver(struct phy_device *phydev, - phy_interface_t interface) +static struct phy_driver *get_phy_driver(struct phy_device *phydev) { struct list_head *entry; int phy_id = phydev->phy_id; @@ -659,12 +661,11 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev, } /* If we made it here, there's no driver for this PHY */ - return generic_for_interface(interface); + return generic_for_phy(phydev); } struct phy_device *phy_device_create(struct mii_dev *bus, int addr, - u32 phy_id, bool is_c45, - phy_interface_t interface) + u32 phy_id, bool is_c45) { struct phy_device *dev; @@ -683,7 +684,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev->duplex = -1; dev->link = 0; - dev->interface = interface; + dev->interface = PHY_INTERFACE_MODE_NA; #ifdef CONFIG_DM_ETH dev->node = ofnode_null(); @@ -696,7 +697,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev->is_c45 = is_c45; dev->bus = bus; - dev->drv = get_phy_driver(dev, interface); + dev->drv = get_phy_driver(dev); if (phy_probe(dev)) { printf("%s, PHY probe failed\n", __func__); @@ -745,8 +746,7 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) } static struct phy_device *create_phy_by_mask(struct mii_dev *bus, - uint phy_mask, int devad, - phy_interface_t interface) + uint phy_mask, int devad) { u32 phy_id = 0xffffffff; bool is_c45; @@ -767,8 +767,7 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus, /* If the PHY ID is mostly f's, we didn't find anything */ if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) { is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true; - return phy_device_create(bus, addr, phy_id, is_c45, - interface); + return phy_device_create(bus, addr, phy_id, is_c45); } next: phy_mask &= ~(1 << addr); @@ -777,25 +776,22 @@ next: } static struct phy_device *search_for_existing_phy(struct mii_dev *bus, - uint phy_mask, - phy_interface_t interface) + uint phy_mask) { /* If we have one, return the existing device, with new interface */ while (phy_mask) { int addr = ffs(phy_mask) - 1; - if (bus->phymap[addr]) { - bus->phymap[addr]->interface = interface; + if (bus->phymap[addr]) return bus->phymap[addr]; - } + phy_mask &= ~(1 << addr); } return NULL; } static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, - uint phy_mask, - phy_interface_t interface) + uint phy_mask) { struct phy_device *phydev; int devad[] = { @@ -811,13 +807,12 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, int i, devad_cnt; devad_cnt = sizeof(devad)/sizeof(int); - phydev = search_for_existing_phy(bus, phy_mask, interface); + phydev = search_for_existing_phy(bus, phy_mask); if (phydev) return phydev; /* try different access clauses */ for (i = 0; i < devad_cnt; i++) { - phydev = create_phy_by_mask(bus, phy_mask, - devad[i], interface); + phydev = create_phy_by_mask(bus, phy_mask, devad[i]); if (IS_ERR(phydev)) return NULL; if (phydev) @@ -845,10 +840,9 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, * Description: Reads the ID registers of the PHY at @addr on the * @bus, then allocates and returns the phy_device to represent it. */ -static struct phy_device *get_phy_device(struct mii_dev *bus, int addr, - phy_interface_t interface) +static struct phy_device *get_phy_device(struct mii_dev *bus, int addr) { - return get_phy_device_by_mask(bus, 1 << addr, interface); + return get_phy_device_by_mask(bus, 1 << addr); } int phy_reset(struct phy_device *phydev) @@ -862,7 +856,7 @@ int phy_reset(struct phy_device *phydev) #ifdef CONFIG_PHYLIB_10G /* If it's 10G, we need to issue reset through one of the MMDs */ - if (is_10g_interface(phydev->interface)) { + if (phydev->is_c45) { if (!phydev->mmds) gen10g_discover_mmds(phydev); @@ -907,18 +901,12 @@ int miiphy_reset(const char *devname, unsigned char addr) struct mii_dev *bus = miiphy_get_dev_by_name(devname); struct phy_device *phydev; - /* - * miiphy_reset was only used on standard PHYs, so we'll fake it here. - * If later code tries to connect with the right interface, this will - * be corrected by get_phy_device in phy_connect() - */ - phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII); + phydev = get_phy_device(bus, addr); return phy_reset(phydev); } -struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, - phy_interface_t interface) +struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask) { /* Reset the bus */ if (bus->reset) { @@ -928,13 +916,15 @@ struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, mdelay(15); } - return get_phy_device_by_mask(bus, phy_mask, interface); + return get_phy_device_by_mask(bus, phy_mask); } #ifdef CONFIG_DM_ETH -void phy_connect_dev(struct phy_device *phydev, struct udevice *dev) +void phy_connect_dev(struct phy_device *phydev, struct udevice *dev, + phy_interface_t interface) #else -void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) +void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev, + phy_interface_t interface) #endif { /* Soft Reset the PHY */ @@ -945,13 +935,14 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) phydev->dev->name, dev->name); } phydev->dev = dev; - debug("%s connected to %s\n", dev->name, phydev->drv->name); + phydev->interface = interface; + debug("%s connected to %s mode %s\n", dev->name, phydev->drv->name, + phy_string_for_interface(interface)); } #ifdef CONFIG_PHY_XILINX_GMII2RGMII static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, - struct udevice *dev, - phy_interface_t interface) + struct udevice *dev) { struct phy_device *phydev = NULL; ofnode node; @@ -960,8 +951,7 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, node = ofnode_by_compatible(node, "xlnx,gmii-to-rgmii-1.0"); if (ofnode_valid(node)) { phydev = phy_device_create(bus, 0, - PHY_GMII2RGMII_ID, false, - interface); + PHY_GMII2RGMII_ID, false); if (phydev) phydev->node = node; break; @@ -985,41 +975,31 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, */ struct phy_device *fixed_phy_create(ofnode node) { - phy_interface_t interface = PHY_INTERFACE_MODE_NONE; struct phy_device *phydev; - const char *if_str; ofnode subnode; - if_str = ofnode_read_string(node, "phy-mode"); - if (!if_str) { - if_str = ofnode_read_string(node, "phy-interface-type"); - } - if (if_str) { - interface = phy_get_interface_by_name(if_str); - } - subnode = ofnode_find_subnode(node, "fixed-link"); if (!ofnode_valid(subnode)) { return NULL; } - phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface); + phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false); if (phydev) phydev->node = subnode; + phydev->interface = ofnode_read_phy_mode(node); + return phydev; } static struct phy_device *phy_connect_fixed(struct mii_dev *bus, - struct udevice *dev, - phy_interface_t interface) + struct udevice *dev) { ofnode node = dev_ofnode(dev), subnode; struct phy_device *phydev = NULL; if (ofnode_phy_is_fixed_link(node, &subnode)) { - phydev = phy_device_create(bus, 0, PHY_FIXED_ID, - false, interface); + phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false); if (phydev) phydev->node = subnode; } @@ -1042,29 +1022,29 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff; #ifdef CONFIG_PHY_FIXED - phydev = phy_connect_fixed(bus, dev, interface); + phydev = phy_connect_fixed(bus, dev); #endif #ifdef CONFIG_PHY_NCSI if (!phydev) - phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface); + phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false); #endif #ifdef CONFIG_PHY_ETHERNET_ID if (!phydev) - phydev = phy_connect_phy_id(bus, dev, addr, interface); + phydev = phy_connect_phy_id(bus, dev, addr); #endif #ifdef CONFIG_PHY_XILINX_GMII2RGMII if (!phydev) - phydev = phy_connect_gmii2rgmii(bus, dev, interface); + phydev = phy_connect_gmii2rgmii(bus, dev); #endif if (!phydev) - phydev = phy_find_by_mask(bus, mask, interface); + phydev = phy_find_by_mask(bus, mask); if (phydev) - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, interface); else printf("Could not get PHY for %s: addr %d\n", bus->name, addr); return phydev; @@ -1102,18 +1082,6 @@ int phy_shutdown(struct phy_device *phydev) return 0; } -int phy_get_interface_by_name(const char *str) -{ - int i; - - for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) { - if (!strcmp(str, phy_interface_strings[i])) - return i; - } - - return -1; -} - /** * phy_modify - Convenience function for modifying a given PHY register * @phydev: the phy_device struct diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 635c057..7376283 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -26,6 +26,11 @@ static int xilinxgmiitorgmii_config(struct phy_device *phydev) debug("%s\n", __func__); + if (phydev->interface != PHY_INTERFACE_MODE_GMII) { + printf("Incorrect interface type\n"); + return -EINVAL; + } + if (!ofnode_valid(node)) return -EINVAL; @@ -37,13 +42,13 @@ static int xilinxgmiitorgmii_config(struct phy_device *phydev) ext_phyaddr = ofnode_read_u32_default(phandle.node, "reg", -1); ext_phydev = phy_find_by_mask(phydev->bus, - 1 << ext_phyaddr, - PHY_INTERFACE_MODE_RGMII); + 1 << ext_phyaddr); if (!ext_phydev) { printf("%s, No external phy device found\n", __func__); return -EINVAL; } + ext_phydev->interface = PHY_INTERFACE_MODE_RGMII; ext_phydev->node = phandle.node; phydev->priv = ext_phydev; @@ -114,11 +119,6 @@ static int xilinxgmiitorgmii_probe(struct phy_device *phydev) { debug("%s\n", __func__); - if (phydev->interface != PHY_INTERFACE_MODE_GMII) { - printf("Incorrect interface type\n"); - return -EINVAL; - } - phydev->flags |= PHY_FLAG_BROKEN_RESET; return 0; diff --git a/drivers/net/pic32_eth.c b/drivers/net/pic32_eth.c index 5a678d1..1333a3a 100644 --- a/drivers/net/pic32_eth.c +++ b/drivers/net/pic32_eth.c @@ -534,7 +534,6 @@ static int pic32_eth_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct pic32eth_dev *priv = dev_get_priv(dev); - const char *phy_mode; void __iomem *iobase; fdt_addr_t addr; fdt_size_t size; @@ -550,15 +549,9 @@ static int pic32_eth_probe(struct udevice *dev) pdata->iobase = (phys_addr_t)addr; /* get phy mode */ - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } /* get phy addr */ offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev), diff --git a/drivers/net/qe/dm_qe_uec.c b/drivers/net/qe/dm_qe_uec.c index a12c8cd..8fec1c2 100644 --- a/drivers/net/qe/dm_qe_uec.c +++ b/drivers/net/qe/dm_qe_uec.c @@ -1133,19 +1133,12 @@ static int qe_uec_remove(struct udevice *dev) static int qe_uec_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; pdata->iobase = (phys_addr_t)devfdt_get_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), - "phy-connection-type", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } return 0; } diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 4078d33..c286805 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -319,11 +319,11 @@ static int ravb_phy_config(struct udevice *dev) mdelay(1); } - phydev = phy_find_by_mask(eth->bus, mask, pdata->phy_interface); + phydev = phy_find_by_mask(eth->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, pdata->phy_interface); eth->phydev = phydev; @@ -674,20 +674,13 @@ static const struct eth_ops ravb_ops = { int ravb_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; const fdt32_t *cell; - int ret = 0; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } pdata->max_speed = 1000; cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL); @@ -696,7 +689,7 @@ int ravb_of_to_plat(struct udevice *dev) sprintf(bb_miiphy_buses[0].name, dev->name); - return ret; + return 0; } static const struct udevice_id ravb_ids[] = { diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 4055f07..1de3ff8 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -762,11 +762,11 @@ static int sh_eth_phy_config(struct udevice *dev) struct phy_device *phydev; int mask = 0xffffffff; - phydev = phy_find_by_mask(priv->bus, mask, pdata->phy_interface); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, pdata->phy_interface); port_info->phydev = phydev; phy_config(phydev); @@ -915,20 +915,13 @@ static const struct eth_ops sh_ether_ops = { int sh_ether_of_to_plat(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); - const char *phy_mode; const fdt32_t *cell; - int ret = 0; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } pdata->max_speed = 1000; cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL); @@ -937,7 +930,7 @@ int sh_ether_of_to_plat(struct udevice *dev) sprintf(bb_miiphy_buses[0].name, dev->name); - return ret; + return 0; } static const struct udevice_id sh_ether_ids[] = { diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c index ab51552..58276a4 100644 --- a/drivers/net/sni_ave.c +++ b/drivers/net/sni_ave.c @@ -393,11 +393,11 @@ static int ave_phy_init(struct ave_private *priv, void *dev) struct phy_device *phydev; int mask = GENMASK(31, 0), ret; - phydev = phy_find_by_mask(priv->bus, mask, priv->phy_mode); + phydev = phy_find_by_mask(priv->bus, mask); if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, priv->phy_mode); phydev->supported &= PHY_GBIT_FEATURES; if (priv->max_speed) { @@ -738,7 +738,6 @@ static int ave_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct ave_private *priv = dev_get_priv(dev); struct ofnode_phandle_args args; - const char *phy_mode; const u32 *valp; int ret, nc, nr; const char *name; @@ -748,15 +747,10 @@ static int ave_of_to_plat(struct udevice *dev) return -EINVAL; pdata->iobase = dev_read_addr(dev); - pdata->phy_interface = -1; - phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode", - NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode); + + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } pdata->max_speed = 0; valp = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c index 4901321..24caacf 100644 --- a/drivers/net/sni_netsec.c +++ b/drivers/net/sni_netsec.c @@ -1029,19 +1029,13 @@ static int netsec_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct netsec_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phandle_args; - const char *phy_mode; pdata->iobase = dev_read_addr_index(dev, 0); priv->eeprom_base = dev_read_addr_index(dev, 1) - EERPROM_MAP_OFFSET; - pdata->phy_interface = -1; - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - pr_err("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, &phandle_args)) diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c index b23faa2..2220f84 100644 --- a/drivers/net/sun8i_emac.c +++ b/drivers/net/sun8i_emac.c @@ -383,8 +383,6 @@ static int sun8i_phy_init(struct emac_eth_dev *priv, void *dev) if (!phydev) return -ENODEV; - phy_connect_dev(phydev, dev); - priv->phydev = phydev; phy_config(priv->phydev); @@ -795,7 +793,6 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) struct sun8i_eth_pdata *sun8i_pdata = dev_get_plat(dev); struct eth_pdata *pdata = &sun8i_pdata->eth_pdata; struct emac_eth_dev *priv = dev_get_priv(dev); - const char *phy_mode; const fdt32_t *reg; int node = dev_of_offset(dev); int offset = 0; @@ -859,16 +856,10 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev) } priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1); - phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); - - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); printf("phy interface%d\n", pdata->phy_interface); - - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } if (priv->variant == H3_EMAC) { ret = sun8i_handle_internal_phy(dev, priv); diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c index d15b0ad..8625e49 100644 --- a/drivers/net/sunxi_emac.c +++ b/drivers/net/sunxi_emac.c @@ -271,12 +271,11 @@ static int sunxi_emac_init_phy(struct emac_eth_dev *priv, void *dev) if (ret) return ret; - priv->phydev = phy_find_by_mask(priv->bus, mask, - PHY_INTERFACE_MODE_MII); + priv->phydev = phy_find_by_mask(priv->bus, mask); if (!priv->phydev) return -ENODEV; - phy_connect_dev(priv->phydev, dev); + phy_connect_dev(priv->phydev, dev, PHY_INTERFACE_MODE_MII); phy_config(priv->phydev); return 0; diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c index 87f51b3..9580fa3 100644 --- a/drivers/net/ti/am65-cpsw-nuss.c +++ b/drivers/net/ti/am65-cpsw-nuss.c @@ -602,21 +602,14 @@ static int am65_cpsw_ofdata_parse_phy(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct am65_cpsw_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args out_args; - const char *phy_mode; int ret = 0; dev_read_u32(dev, "reg", &priv->port_id); - phy_mode = dev_read_string(dev, "phy-mode"); - if (phy_mode) { - pdata->phy_interface = - phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - dev_err(dev, "Invalid PHY mode '%s', port %u\n", - phy_mode, priv->port_id); - ret = -EINVAL; - goto out; - } + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) { + dev_err(dev, "Invalid PHY mode, port %u\n", priv->port_id); + return -EINVAL; } dev_read_u32(dev, "max-speed", (u32 *)&pdata->max_speed); diff --git a/drivers/net/ti/cpsw.c b/drivers/net/ti/cpsw.c index 68f4191..8988c21 100644 --- a/drivers/net/ti/cpsw.c +++ b/drivers/net/ti/cpsw.c @@ -1194,15 +1194,12 @@ static void cpsw_eth_of_parse_slave(struct cpsw_platform_data *data, { struct ofnode_phandle_args out_args; struct cpsw_slave_data *slave_data; - const char *phy_mode; u32 phy_id[2]; int ret; slave_data = &data->slave_data[slave_index]; - phy_mode = ofnode_read_string(subnode, "phy-mode"); - if (phy_mode) - slave_data->phy_if = phy_get_interface_by_name(phy_mode); + slave_data->phy_if = ofnode_read_phy_mode(subnode); ret = ofnode_parse_phandle_with_args(subnode, "phy-handle", NULL, 0, 0, &out_args); @@ -1348,11 +1345,8 @@ static int cpsw_eth_of_to_plat(struct udevice *dev) } pdata->phy_interface = data->slave_data[data->active_slave].phy_if; - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, - phy_string_for_interface(pdata->phy_interface)); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } return 0; } diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c index 5e8f683..fbec69f 100644 --- a/drivers/net/ti/keystone_net.c +++ b/drivers/net/ti/keystone_net.c @@ -23,7 +23,6 @@ #include <asm/ti-common/keystone_net.h> #include <asm/ti-common/keystone_serdes.h> #include <asm/arch/psc_defs.h> -#include <linux/libfdt.h> #include "cpsw_mdio.h" @@ -91,9 +90,9 @@ struct ks2_eth_priv { struct mii_dev *mdio_bus; int phy_addr; phy_interface_t phy_if; - int phy_of_handle; + ofnode phy_ofnode; int sgmii_link_type; - void *mdio_base; + phys_addr_t mdio_base; struct rx_buff_desc net_rx_buffs; struct pktdma_cfg *netcp_pktdma; void *hd; @@ -570,7 +569,7 @@ static int ks2_eth_probe(struct udevice *dev) * to re-use the same */ mdio_bus = cpsw_mdio_init("ethernet-mdio", - (u32)priv->mdio_base, + priv->mdio_base, EMAC_MDIO_CLOCK_FREQ, EMAC_MDIO_BUS_FREQ); if (!mdio_bus) { @@ -593,8 +592,8 @@ static int ks2_eth_probe(struct udevice *dev) priv->phydev = phy_connect(priv->mdio_bus, priv->phy_addr, dev, priv->phy_if); #ifdef CONFIG_DM_ETH - if (priv->phy_of_handle) - priv->phydev->node = offset_to_ofnode(priv->phy_of_handle); + if (ofnode_valid(priv->phy_ofnode)) + priv->phydev->node = priv->phy_ofnode; #endif phy_config(priv->phydev); } @@ -621,105 +620,88 @@ static const struct eth_ops ks2_eth_ops = { .write_hwaddr = ks2_eth_write_hwaddr, }; -static int ks2_eth_bind_slaves(struct udevice *dev, int gbe, int *gbe_0) +static int ks2_bind_one_slave(struct udevice *dev, ofnode slave, ofnode *gbe_0) { - const void *fdt = gd->fdt_blob; - struct udevice *sl_dev; - int interfaces; - int sec_slave; - int slave; - int ret; char *slave_name; + u32 slave_no; + int ret; - interfaces = fdt_subnode_offset(fdt, gbe, "interfaces"); - fdt_for_each_subnode(slave, fdt, interfaces) { - int slave_no; - - slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); - if (slave_no == -ENOENT) - continue; - - if (slave_no == 0) { - /* This is the current eth device */ - *gbe_0 = slave; - } else { - /* Slave devices to be registered */ - slave_name = malloc(20); - snprintf(slave_name, 20, "netcp@slave-%d", slave_no); - ret = device_bind_driver_to_node(dev, "eth_ks2_sl", - slave_name, offset_to_ofnode(slave), - &sl_dev); - if (ret) { - pr_err("ks2_net - not able to bind slave interfaces\n"); - return ret; - } - } + if (ofnode_read_u32(slave, "slave-port", &slave_no)) + return 0; + + if (gbe_0 && slave_no == 0) { + /* This is the current eth device */ + *gbe_0 = slave; + return 0; + } + + /* Slave devices to be registered */ + slave_name = malloc(20); + snprintf(slave_name, 20, "netcp@slave-%d", slave_no); + ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, slave, + NULL); + if (ret) + pr_err("ks2_net - not able to bind slave interfaces\n"); + + return ret; +} + +static int ks2_eth_bind_slaves(struct udevice *dev, ofnode gbe, ofnode *gbe_0) +{ + ofnode interfaces, sec_slave, slave; + int ret; + + interfaces = ofnode_find_subnode(gbe, "interfaces"); + ofnode_for_each_subnode(slave, interfaces) { + ret = ks2_bind_one_slave(dev, slave, gbe_0); + if (ret) + return ret; } - sec_slave = fdt_subnode_offset(fdt, gbe, "secondary-slave-ports"); - fdt_for_each_subnode(slave, fdt, sec_slave) { - int slave_no; - - slave_no = fdtdec_get_int(fdt, slave, "slave-port", -ENOENT); - if (slave_no == -ENOENT) - continue; - - /* Slave devices to be registered */ - slave_name = malloc(20); - snprintf(slave_name, 20, "netcp@slave-%d", slave_no); - ret = device_bind_driver_to_node(dev, "eth_ks2_sl", slave_name, - offset_to_ofnode(slave), &sl_dev); - if (ret) { - pr_err("ks2_net - not able to bind slave interfaces\n"); + sec_slave = ofnode_find_subnode(gbe, "secondary-slave-ports"); + ofnode_for_each_subnode(slave, sec_slave) { + ret = ks2_bind_one_slave(dev, slave, NULL); + if (ret) return ret; - } } return 0; } -static int ks2_eth_parse_slave_interface(int netcp, int slave, +static int ks2_eth_parse_slave_interface(ofnode netcp, ofnode slave, struct ks2_eth_priv *priv, struct eth_pdata *pdata) { - const void *fdt = gd->fdt_blob; - int mdio; - int phy; + struct ofnode_phandle_args dma_args; + ofnode phy, mdio; int dma_count; - u32 dma_channel[8]; - const char *phy_mode; - priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1); + priv->slave_port = ofnode_read_s32_default(slave, "slave-port", -1); priv->net_rx_buffs.rx_flow = priv->slave_port * 8; /* U-Boot slave port number starts with 1 instead of 0 */ priv->slave_port += 1; - dma_count = fdtdec_get_int_array_count(fdt, netcp, - "ti,navigator-dmas", - dma_channel, 8); - - if (dma_count > (2 * priv->slave_port)) { - int dma_idx; - - dma_idx = priv->slave_port * 2 - 1; - priv->net_rx_buffs.rx_flow = dma_channel[dma_idx]; - } + dma_count = ofnode_count_phandle_with_args(netcp, "ti,navigator-dmas", + NULL, 1); + if (priv->slave_port < dma_count && + !ofnode_parse_phandle_with_args(netcp, "ti,navigator-dmas", NULL, 1, + priv->slave_port - 1, &dma_args)) + priv->net_rx_buffs.rx_flow = dma_args.args[0]; - priv->link_type = fdtdec_get_int(fdt, slave, "link-interface", -1); + priv->link_type = ofnode_read_s32_default(slave, "link-interface", -1); - phy = fdtdec_lookup_phandle(fdt, slave, "phy-handle"); + phy = ofnode_get_phy_node(slave); + priv->phy_ofnode = phy; + if (ofnode_valid(phy)) { + priv->phy_addr = ofnode_read_s32_default(phy, "reg", -1); - if (phy >= 0) { - priv->phy_of_handle = phy; - priv->phy_addr = fdtdec_get_int(fdt, phy, "reg", -1); - - mdio = fdt_parent_offset(fdt, phy); - if (mdio < 0) { + mdio = ofnode_get_parent(phy); + if (!ofnode_valid(mdio)) { pr_err("mdio dt not found\n"); return -ENODEV; } - priv->mdio_base = (void *)fdtdec_get_addr(fdt, mdio, "reg"); + priv->mdio_base = ofnode_get_addr(mdio); } if (priv->link_type == LINK_TYPE_SGMII_MAC_TO_PHY_MODE) { @@ -728,20 +710,19 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, priv->sgmii_link_type = SGMII_LINK_MAC_PHY; priv->has_mdio = true; } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) { - phy_mode = fdt_getprop(fdt, slave, "phy-mode", NULL); - if (phy_mode) { - priv->phy_if = phy_get_interface_by_name(phy_mode); - if (priv->phy_if != PHY_INTERFACE_MODE_RGMII && - priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID && - priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID && - priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) { - pr_err("invalid phy-mode\n"); - return -EINVAL; - } - } else { + priv->phy_if = ofnode_read_phy_mode(slave); + if (priv->phy_if == PHY_INTERFACE_MODE_NA) priv->phy_if = PHY_INTERFACE_MODE_RGMII; - } pdata->phy_interface = priv->phy_if; + + if (priv->phy_if != PHY_INTERFACE_MODE_RGMII && + priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID && + priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID && + priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) { + pr_err("invalid phy-mode\n"); + return -EINVAL; + } + priv->has_mdio = true; } @@ -750,23 +731,19 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave, static int ks2_sl_eth_of_to_plat(struct udevice *dev) { + ofnode slave, interfaces, gbe, netcp_devices, netcp; struct ks2_eth_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); - const void *fdt = gd->fdt_blob; - int slave = dev_of_offset(dev); - int interfaces; - int gbe; - int netcp_devices; - int netcp; - - interfaces = fdt_parent_offset(fdt, slave); - gbe = fdt_parent_offset(fdt, interfaces); - netcp_devices = fdt_parent_offset(fdt, gbe); - netcp = fdt_parent_offset(fdt, netcp_devices); + + slave = dev_ofnode(dev); + interfaces = ofnode_get_parent(slave); + gbe = ofnode_get_parent(interfaces); + netcp_devices = ofnode_get_parent(gbe); + netcp = ofnode_get_parent(netcp_devices); ks2_eth_parse_slave_interface(netcp, slave, priv, pdata); - pdata->iobase = fdtdec_get_addr(fdt, netcp, "reg"); + pdata->iobase = ofnode_get_addr(netcp); return 0; } @@ -775,18 +752,15 @@ static int ks2_eth_of_to_plat(struct udevice *dev) { struct ks2_eth_priv *priv = dev_get_priv(dev); struct eth_pdata *pdata = dev_get_plat(dev); - const void *fdt = gd->fdt_blob; - int gbe_0 = -ENODEV; - int netcp_devices; - int gbe; + ofnode netcp_devices, gbe, gbe_0; - netcp_devices = fdt_subnode_offset(fdt, dev_of_offset(dev), - "netcp-devices"); - gbe = fdt_subnode_offset(fdt, netcp_devices, "gbe"); + netcp_devices = dev_read_subnode(dev, "netcp-devices"); + gbe = ofnode_find_subnode(netcp_devices, "gbe"); + gbe_0 = ofnode_null(); ks2_eth_bind_slaves(dev, gbe, &gbe_0); - ks2_eth_parse_slave_interface(dev_of_offset(dev), gbe_0, priv, pdata); + ks2_eth_parse_slave_interface(dev_ofnode(dev), gbe_0, priv, pdata); pdata->iobase = dev_read_addr(dev); diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index beca886..d69a9ff 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -834,7 +834,6 @@ int tsec_probe(struct udevice *dev) struct ofnode_phandle_args phandle_args; u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE; struct tsec_data *data; - const char *phy_mode; ofnode parent, child; fdt_addr_t reg; u32 max_speed; @@ -894,12 +893,8 @@ int tsec_probe(struct udevice *dev) priv->tbiaddr = tbiaddr; - phy_mode = dev_read_prop(dev, "phy-connection-type", NULL); - if (!phy_mode) - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) pdata->phy_interface = tsec_get_interface(priv); priv->interface = pdata->phy_interface; diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c index f21addb..a471573 100644 --- a/drivers/net/xilinx_axi_emac.c +++ b/drivers/net/xilinx_axi_emac.c @@ -821,7 +821,6 @@ static int axi_emac_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = &plat->eth_pdata; int node = dev_of_offset(dev); int offset = 0; - const char *phy_mode; pdata->iobase = dev_read_addr(dev); plat->mactype = dev_get_driver_data(dev); @@ -850,14 +849,9 @@ static int axi_emac_of_to_plat(struct udevice *dev) plat->phy_of_handle = offset; } - phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - printf("%s: Invalid PHY interface '%s'\n", __func__, - phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node, "xlnx,eth-hasnobuf"); diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c index 4c83ccc..4e8dd4b 100644 --- a/drivers/net/zynq_gem.c +++ b/drivers/net/zynq_gem.c @@ -889,7 +889,6 @@ static int zynq_gem_of_to_plat(struct udevice *dev) struct eth_pdata *pdata = dev_get_plat(dev); struct zynq_gem_priv *priv = dev_get_priv(dev); struct ofnode_phandle_args phandle_args; - const char *phy_mode; pdata->iobase = (phys_addr_t)dev_read_addr(dev); priv->iobase = (struct zynq_gem_regs *)pdata->iobase; @@ -923,13 +922,9 @@ static int zynq_gem_of_to_plat(struct udevice *dev) } } - phy_mode = dev_read_prop(dev, "phy-mode", NULL); - if (phy_mode) - pdata->phy_interface = phy_get_interface_by_name(phy_mode); - if (pdata->phy_interface == -1) { - debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode); + pdata->phy_interface = dev_read_phy_mode(dev); + if (pdata->phy_interface == PHY_INTERFACE_MODE_NA) return -EINVAL; - } priv->interface = pdata->phy_interface; priv->int_pcs = dev_read_bool(dev, "is-internal-pcspma"); |