From patchwork Sun May 3 18:52:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 244946 List-Id: U-Boot discussion From: olteanv at gmail.com (Vladimir Oltean) Date: Sun, 3 May 2020 21:52:25 +0300 Subject: [RFC PATCH 1/3] phy: make phy_connect_fixed work with a null mdio bus In-Reply-To: <20200503185227.28731-1-olteanv@gmail.com> References: <20200503185227.28731-1-olteanv@gmail.com> Message-ID: <20200503185227.28731-2-olteanv@gmail.com> From: Vladimir Oltean It is utterly pointless to require an MDIO bus pointer for a fixed PHY device. The fixed.c implementation does not require it, only phy_device_create. Fix that. Signed-off-by: Vladimir Oltean Reviewed-by: Hou Zhiqiang --- drivers/net/phy/phy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 9a66e62e8974..dcef1aaf2026 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -651,7 +651,7 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev = malloc(sizeof(*dev)); if (!dev) { printf("Failed to allocate PHY device for %s:%d\n", - bus->name, addr); + bus ? bus->name : "(null bus)", addr); return NULL; } @@ -679,7 +679,7 @@ static struct phy_device *phy_device_create(struct mii_dev *bus, int addr, return NULL; } - if (addr >= 0 && addr < PHY_MAX_ADDR) + if (addr >= 0 && addr < PHY_MAX_ADDR && phy_id != PHY_FIXED_ID) bus->phymap[addr] = dev; return dev; From patchwork Sun May 3 18:52:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 244947 List-Id: U-Boot discussion From: olteanv at gmail.com (Vladimir Oltean) Date: Sun, 3 May 2020 21:52:26 +0300 Subject: [RFC PATCH 2/3] configs: enable DM_MDIO for LS1021A-TWR and LS1021A-TSN In-Reply-To: <20200503185227.28731-1-olteanv@gmail.com> References: <20200503185227.28731-1-olteanv@gmail.com> Message-ID: <20200503185227.28731-3-olteanv@gmail.com> From: Vladimir Oltean The tsec driver now requires DM_MDIO when DM_ETH is enabled. To avoid build errors, enable DM_MDIO in these boards' configs before we actually add DM_MDIO support to tsec. Signed-off-by: Vladimir Oltean --- configs/ls1021atsn_qspi_defconfig | 1 + configs/ls1021atsn_sdcard_defconfig | 1 + configs/ls1021atwr_nor_SECURE_BOOT_defconfig | 1 + configs/ls1021atwr_nor_defconfig | 1 + configs/ls1021atwr_nor_lpuart_defconfig | 1 + configs/ls1021atwr_qspi_defconfig | 1 + configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig | 1 + configs/ls1021atwr_sdcard_ifc_defconfig | 1 + configs/ls1021atwr_sdcard_qspi_defconfig | 1 + 9 files changed, 9 insertions(+) diff --git a/configs/ls1021atsn_qspi_defconfig b/configs/ls1021atsn_qspi_defconfig index f1c010b5e916..debd52f2b236 100644 --- a/configs/ls1021atsn_qspi_defconfig +++ b/configs/ls1021atsn_qspi_defconfig @@ -38,6 +38,7 @@ CONFIG_PHY_ATHEROS=y CONFIG_PHY_BROADCOM=y CONFIG_PHY_FIXED=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_MII=y CONFIG_TSEC_ENET=y diff --git a/configs/ls1021atsn_sdcard_defconfig b/configs/ls1021atsn_sdcard_defconfig index 3550d16af8d6..de66c84314f4 100644 --- a/configs/ls1021atsn_sdcard_defconfig +++ b/configs/ls1021atsn_sdcard_defconfig @@ -50,6 +50,7 @@ CONFIG_PHY_ATHEROS=y CONFIG_PHY_BROADCOM=y CONFIG_PHY_FIXED=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_MII=y CONFIG_TSEC_ENET=y diff --git a/configs/ls1021atwr_nor_SECURE_BOOT_defconfig b/configs/ls1021atwr_nor_SECURE_BOOT_defconfig index 85c19a66cda0..0e80182d7bee 100644 --- a/configs/ls1021atwr_nor_SECURE_BOOT_defconfig +++ b/configs/ls1021atwr_nor_SECURE_BOOT_defconfig @@ -39,6 +39,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_CFI=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y diff --git a/configs/ls1021atwr_nor_defconfig b/configs/ls1021atwr_nor_defconfig index 88462493a553..a71e036b4a49 100644 --- a/configs/ls1021atwr_nor_defconfig +++ b/configs/ls1021atwr_nor_defconfig @@ -39,6 +39,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_CFI=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y diff --git a/configs/ls1021atwr_nor_lpuart_defconfig b/configs/ls1021atwr_nor_lpuart_defconfig index 5ec13aaafd67..60daf3ef2b2d 100644 --- a/configs/ls1021atwr_nor_lpuart_defconfig +++ b/configs/ls1021atwr_nor_lpuart_defconfig @@ -41,6 +41,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_CFI=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y diff --git a/configs/ls1021atwr_qspi_defconfig b/configs/ls1021atwr_qspi_defconfig index 82339c98cf38..09a6a2918c39 100644 --- a/configs/ls1021atwr_qspi_defconfig +++ b/configs/ls1021atwr_qspi_defconfig @@ -41,6 +41,7 @@ CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_STMICRO=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y diff --git a/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig b/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig index a18b192176b3..4298b57aead9 100644 --- a/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig +++ b/configs/ls1021atwr_sdcard_ifc_SECURE_BOOT_defconfig @@ -53,6 +53,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_CFI=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y diff --git a/configs/ls1021atwr_sdcard_ifc_defconfig b/configs/ls1021atwr_sdcard_ifc_defconfig index fac41154456a..571fde20edac 100644 --- a/configs/ls1021atwr_sdcard_ifc_defconfig +++ b/configs/ls1021atwr_sdcard_ifc_defconfig @@ -54,6 +54,7 @@ CONFIG_SYS_FLASH_USE_BUFFER_WRITE=y CONFIG_SYS_FLASH_CFI=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y diff --git a/configs/ls1021atwr_sdcard_qspi_defconfig b/configs/ls1021atwr_sdcard_qspi_defconfig index 80a0e9171739..6af5289e38bb 100644 --- a/configs/ls1021atwr_sdcard_qspi_defconfig +++ b/configs/ls1021atwr_sdcard_qspi_defconfig @@ -53,6 +53,7 @@ CONFIG_SPI_FLASH_ATMEL=y CONFIG_SPI_FLASH_STMICRO=y CONFIG_PHY_ATHEROS=y CONFIG_DM_ETH=y +CONFIG_DM_MDIO=y CONFIG_PHY_GIGE=y CONFIG_E1000=y CONFIG_MII=y From patchwork Sun May 3 18:52:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 244948 List-Id: U-Boot discussion From: olteanv at gmail.com (Vladimir Oltean) Date: Sun, 3 May 2020 21:52:27 +0300 Subject: [RFC PATCH 3/3] net: tsec: convert fsl_pq_mdio to DM_MDIO In-Reply-To: <20200503185227.28731-1-olteanv@gmail.com> References: <20200503185227.28731-1-olteanv@gmail.com> Message-ID: <20200503185227.28731-4-olteanv@gmail.com> From: Vladimir Oltean For the platforms on which the eTSEC driver uses DM_ETH, convert its MDIO controller code to also use DM_MDIO. Note that for handling the TBI PHY (the MAC PCS for SGMII), we still don't register a udevice for it, since we can drive it locally and there is no point in doing otherwise. Signed-off-by: Vladimir Oltean --- drivers/net/fsl_mdio.c | 66 ++++++++++++++++++++++++++++++++++++++---- drivers/net/tsec.c | 50 ++++++++++---------------------- include/fsl_mdio.h | 4 +-- 3 files changed, 78 insertions(+), 42 deletions(-) diff --git a/drivers/net/fsl_mdio.c b/drivers/net/fsl_mdio.c index 894b52ee66f4..284508062c8e 100644 --- a/drivers/net/fsl_mdio.c +++ b/drivers/net/fsl_mdio.c @@ -8,9 +8,11 @@ #include #include #include +#include #include #include #include +#include void tsec_local_mdio_write(struct tsec_mii_mng __iomem *phyregs, int port_addr, int dev_addr, int regnum, int value) @@ -56,11 +58,8 @@ int tsec_local_mdio_read(struct tsec_mii_mng __iomem *phyregs, int port_addr, return value; } -static int fsl_pq_mdio_reset(struct mii_dev *bus) +int fsl_pq_mdio_reset(struct tsec_mii_mng __iomem *regs) { - struct tsec_mii_mng __iomem *regs = - (struct tsec_mii_mng __iomem *)bus->priv; - /* Reset MII (due to new addresses) */ out_be32(®s->miimcfg, MIIMCFG_RESET_MGMT); @@ -72,6 +71,7 @@ static int fsl_pq_mdio_reset(struct mii_dev *bus) return 0; } +#ifndef CONFIG_DM_MDIO int tsec_phy_read(struct mii_dev *bus, int addr, int dev_addr, int regnum) { struct tsec_mii_mng __iomem *phyregs = @@ -91,6 +91,11 @@ int tsec_phy_write(struct mii_dev *bus, int addr, int dev_addr, int regnum, return 0; } +static int tsec_mdio_reset(struct mii_dev *bus) +{ + return fsl_pq_mdio_reset(bus->priv); +} + int fsl_pq_mdio_init(bd_t *bis, struct fsl_pq_mdio_info *info) { struct mii_dev *bus = mdio_alloc(); @@ -102,10 +107,61 @@ int fsl_pq_mdio_init(bd_t *bis, struct fsl_pq_mdio_info *info) bus->read = tsec_phy_read; bus->write = tsec_phy_write; - bus->reset = fsl_pq_mdio_reset; + bus->reset = tsec_mdio_reset; strcpy(bus->name, info->name); bus->priv = (void *)info->regs; return mdio_register(bus); } +#endif + +#ifdef CONFIG_DM_MDIO +static int dm_fsl_pq_mdio_read(struct udevice *dev, int addr, int devad, + int reg) +{ + struct fsl_pq_mdio_info *info = dev_get_priv(dev); + + return tsec_local_mdio_read(info->regs, addr, devad, reg); +} + +static int dm_fsl_pq_mdio_write(struct udevice *dev, int addr, int devad, + int reg, u16 val) +{ + struct fsl_pq_mdio_info *info = dev_get_priv(dev); + + tsec_local_mdio_write(info->regs, addr, devad, reg, val); + + return 0; +} + +static int fsl_pq_mdio_probe(struct udevice *dev) +{ + struct fsl_pq_mdio_info *info = dev_get_priv(dev); + fdt_addr_t reg; + + reg = devfdt_get_addr(dev); + info->regs = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0, MAP_NOCACHE); + + return fsl_pq_mdio_reset(info->regs); +} + +static const struct mdio_ops fsl_pq_mdio_ops = { + .read = dm_fsl_pq_mdio_read, + .write = dm_fsl_pq_mdio_write, +}; + +static const struct udevice_id fsl_pq_mdio_ids[] = { + { .compatible = "fsl,etsec2-mdio" }, + { } +}; + +U_BOOT_DRIVER(fsl_pq_mdio) = { + .name = "fsl_pq_mdio", + .id = UCLASS_MDIO, + .of_match = fsl_pq_mdio_ids, + .probe = fsl_pq_mdio_probe, + .ops = &fsl_pq_mdio_ops, + .priv_auto_alloc_size = sizeof(struct fsl_pq_mdio_info), +}; +#endif diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c index 842cddf2297a..93f151a8a6db 100644 --- a/drivers/net/tsec.c +++ b/drivers/net/tsec.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -679,8 +680,15 @@ static int init_phy(struct tsec_private *priv) if (priv->interface == PHY_INTERFACE_MODE_SGMII) tsec_configure_serdes(priv); +#ifdef CONFIG_DM_ETH + if (ofnode_valid(ofnode_find_subnode(priv->dev->node, "fixed-link"))) + phydev = phy_connect(NULL, 0, priv->dev, priv->interface); + else + phydev = dm_eth_phy_connect(priv->dev); +#else phydev = phy_connect(priv->bus, priv->phyaddr, priv->dev, priv->interface); +#endif if (!phydev) return 0; @@ -785,14 +793,17 @@ int tsec_standard_init(bd_t *bis) return tsec_eth_init(bis, tsec_info, ARRAY_SIZE(tsec_info)); } #else /* CONFIG_DM_ETH */ + +#ifndef CONFIG_DM_MDIO +#error "TSEC with DM_ETH also requires DM_MDIO" +#endif + int tsec_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_platdata(dev); struct tsec_private *priv = dev_get_priv(dev); - struct tsec_mii_mng __iomem *ext_phyregs_mii; struct ofnode_phandle_args phandle_args; u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE; - struct fsl_pq_mdio_info mdio_info; const char *phy_mode; fdt_addr_t reg; ofnode parent; @@ -801,31 +812,6 @@ int tsec_probe(struct udevice *dev) pdata->iobase = (phys_addr_t)dev_read_addr(dev); priv->regs = dev_remap_addr(dev); - if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, - &phandle_args)) { - printf("phy-handle does not exist under tsec %s\n", dev->name); - return -ENOENT; - } else { - int reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); - - priv->phyaddr = reg; - } - - parent = ofnode_get_parent(phandle_args.node); - if (!ofnode_valid(parent)) { - printf("No parent node for PHY?\n"); - return -ENOENT; - } - - reg = ofnode_get_addr_index(parent, 0); - if (reg == FDT_ADDR_T_NONE) { - printf("No 'reg' property of MII for external PHY\n"); - return -ENOENT; - } - - ext_phyregs_mii = map_physmem(reg + TSEC_MDIO_REGS_OFFSET, 0, - MAP_NOCACHE); - ret = dev_read_phandle_with_args(dev, "tbi-handle", NULL, 0, 0, &phandle_args); if (ret == 0) { @@ -860,14 +846,10 @@ int tsec_probe(struct udevice *dev) /* Initialize flags */ priv->flags = TSEC_GIGABIT; - if (priv->interface == PHY_INTERFACE_MODE_SGMII) + if (priv->interface == PHY_INTERFACE_MODE_SGMII) { priv->flags |= TSEC_SGMII; - - mdio_info.regs = ext_phyregs_mii; - mdio_info.name = (char *)dev->name; - ret = fsl_pq_mdio_init(NULL, &mdio_info); - if (ret) - return ret; + fsl_pq_mdio_reset(priv->phyregs_sgmii); + } /* Reset the MAC */ setbits_be32(&priv->regs->maccfg1, MACCFG1_SOFT_RESET); diff --git a/include/fsl_mdio.h b/include/fsl_mdio.h index b87346ce7ca1..11a6d588aff3 100644 --- a/include/fsl_mdio.h +++ b/include/fsl_mdio.h @@ -46,9 +46,7 @@ void tsec_local_mdio_write(struct tsec_mii_mng __iomem *phyregs, int port_addr, int dev_addr, int reg, int value); int tsec_local_mdio_read(struct tsec_mii_mng __iomem *phyregs, int port_addr, int dev_addr, int regnum); -int tsec_phy_read(struct mii_dev *bus, int addr, int dev_addr, int regnum); -int tsec_phy_write(struct mii_dev *bus, int addr, int dev_addr, int regnum, - u16 value); +int fsl_pq_mdio_reset(struct tsec_mii_mng __iomem *regs); int memac_mdio_write(struct mii_dev *bus, int port_addr, int dev_addr, int regnum, u16 value); int memac_mdio_read(struct mii_dev *bus, int port_addr, int dev_addr,