From 5354774b6b39a11dcad278de2725457c1e860325 Mon Sep 17 00:00:00 2001 From: Jim Liu Date: Tue, 11 Feb 2025 10:02:01 +0800 Subject: net: designware: Add npcm8xx sgmii pcs support The PCS exists only in GMAC1 and relates to SGMII interface and is used to control the SGMII PHY. Signed-off-by: Jim Liu [trini: Adjust slightly for white space and to move 'start' to within if block] --- drivers/net/designware.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 0a1fff38727..2ab03015ffa 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -33,6 +33,9 @@ #include #include #include "designware.h" +#if IS_ENABLED(CONFIG_ARCH_NPCM8XX) +#include +#endif static int dw_mdio_read(struct mii_dev *bus, int addr, int devad, int reg) { @@ -352,10 +355,35 @@ static int dw_adjust_link(struct dw_eth_dev *priv, struct eth_mac_regs *mac_p, (phydev->port == PORT_FIBRE) ? ", fiber mode" : ""); #ifdef CONFIG_ARCH_NPCM8XX + if (phydev->interface == PHY_INTERFACE_MODE_SGMII) { + unsigned int start; + + /* Indirect access to VR_MII_MMD registers */ + writew((VR_MII_MMD >> 9), PCS_BA + PCS_IND_AC); + /* Set PCS_Mode to SGMII */ + clrsetbits_le16(PCS_BA + VR_MII_MMD_AN_CTRL, BIT(1), BIT(2)); + /* Set Auto Speed Mode Change */ + setbits_le16(PCS_BA + VR_MII_MMD_CTRL1, BIT(9)); + /* Indirect access to SR_MII_MMD registers */ + writew((SR_MII_MMD >> 9), PCS_BA + PCS_IND_AC); + /* Restart Auto-Negotiation */ + setbits_le16(PCS_BA + SR_MII_MMD_CTRL, BIT(9) | BIT(12)); + + printf("SGMII PHY Wait for link up \n"); + /* SGMII PHY Wait for link up */ + start = get_timer(0); + while (!(readw(PCS_BA + SR_MII_MMD_STS) & BIT(2))) { + if (get_timer(start) >= LINK_UP_TIMEOUT) { + printf("PHY link up timeout\n"); + return -ETIMEDOUT; + } + mdelay(1); + }; + } /* Pass all Multicast Frames */ setbits_le32(&mac_p->framefilt, BIT(4)); - #endif + return 0; } -- cgit v1.2.3 From 165fba6c91ce99e7ed40a83e11a937e571fe1e1a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:13 +0100 Subject: net: designware: Drop NULL priv assignment This is unnecessary, the unset structure member is initialized to NULL by default, drop the assignment. Reviewed-by: Paul Barker Signed-off-by: Marek Vasut --- drivers/net/designware.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 2ab03015ffa..c17b4078d5a 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -1041,7 +1041,6 @@ struct bb_miiphy_bus bb_miiphy_buses[] = { .get_mdio = dw_eth_bb_get_mdio, .set_mdc = dw_eth_bb_set_mdc, .delay = dw_eth_bb_delay, - .priv = NULL, } }; -- cgit v1.2.3 From bc8d7288e31a43b8ec18d3bf39cc7cb69709251e Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:17 +0100 Subject: net: designware: Reorder bb_miiphy functions Move the bb_miiphy functions before MDIO registration. This is a preparatory patch, the functions will be referenced around the MDIO registration in the follow up patches. No functional change. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 158 +++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 79 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index c17b4078d5a..95a459cec2a 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -226,6 +226,85 @@ static int dw_dm_mdio_init(const char *name, void *priv) } #endif +#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) +static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus) +{ + struct dw_eth_dev *priv = bus->priv; + struct gpio_desc *desc = &priv->mdio_gpio; + + desc->flags = 0; + dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); + + return 0; +} + +static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) +{ + struct dw_eth_dev *priv = bus->priv; + struct gpio_desc *desc = &priv->mdio_gpio; + + desc->flags = 0; + dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_IN); + + return 0; +} + +static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) +{ + struct dw_eth_dev *priv = bus->priv; + + if (v) + dm_gpio_set_value(&priv->mdio_gpio, 1); + else + dm_gpio_set_value(&priv->mdio_gpio, 0); + + return 0; +} + +static int dw_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) +{ + struct dw_eth_dev *priv = bus->priv; + + *v = dm_gpio_get_value(&priv->mdio_gpio); + + return 0; +} + +static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) +{ + struct dw_eth_dev *priv = bus->priv; + + if (v) + dm_gpio_set_value(&priv->mdc_gpio, 1); + else + dm_gpio_set_value(&priv->mdc_gpio, 0); + + return 0; +} + +static int dw_eth_bb_delay(struct bb_miiphy_bus *bus) +{ + struct dw_eth_dev *priv = bus->priv; + + udelay(priv->bb_delay); + return 0; +} + +struct bb_miiphy_bus bb_miiphy_buses[] = { + { + .name = BB_MII_DEVNAME, + .mdio_active = dw_eth_bb_mdio_active, + .mdio_tristate = dw_eth_bb_mdio_tristate, + .set_mdio = dw_eth_bb_set_mdio, + .get_mdio = dw_eth_bb_get_mdio, + .set_mdc = dw_eth_bb_set_mdc, + .delay = dw_eth_bb_delay, + } +}; + +int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); +#endif + static void tx_descs_init(struct dw_eth_dev *priv) { struct eth_dma_regs *dma_p = priv->dma_regs_p; @@ -967,82 +1046,3 @@ static struct pci_device_id supported[] = { }; U_BOOT_PCI_DEVICE(eth_designware, supported); - -#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) -static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus) -{ - struct dw_eth_dev *priv = bus->priv; - struct gpio_desc *desc = &priv->mdio_gpio; - - desc->flags = 0; - dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); - - return 0; -} - -static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) -{ - struct dw_eth_dev *priv = bus->priv; - struct gpio_desc *desc = &priv->mdio_gpio; - - desc->flags = 0; - dm_gpio_set_dir_flags(&priv->mdio_gpio, GPIOD_IS_IN); - - return 0; -} - -static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) -{ - struct dw_eth_dev *priv = bus->priv; - - if (v) - dm_gpio_set_value(&priv->mdio_gpio, 1); - else - dm_gpio_set_value(&priv->mdio_gpio, 0); - - return 0; -} - -static int dw_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) -{ - struct dw_eth_dev *priv = bus->priv; - - *v = dm_gpio_get_value(&priv->mdio_gpio); - - return 0; -} - -static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) -{ - struct dw_eth_dev *priv = bus->priv; - - if (v) - dm_gpio_set_value(&priv->mdc_gpio, 1); - else - dm_gpio_set_value(&priv->mdc_gpio, 0); - - return 0; -} - -static int dw_eth_bb_delay(struct bb_miiphy_bus *bus) -{ - struct dw_eth_dev *priv = bus->priv; - - udelay(priv->bb_delay); - return 0; -} - -struct bb_miiphy_bus bb_miiphy_buses[] = { - { - .name = BB_MII_DEVNAME, - .mdio_active = dw_eth_bb_mdio_active, - .mdio_tristate = dw_eth_bb_mdio_tristate, - .set_mdio = dw_eth_bb_set_mdio, - .get_mdio = dw_eth_bb_get_mdio, - .set_mdc = dw_eth_bb_set_mdc, - .delay = dw_eth_bb_delay, - } -}; - -int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); -#endif -- cgit v1.2.3 From ce6431141a4ad220935bbe27dd12ab569f38e263 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:20 +0100 Subject: net: designware: Drop bus index There is literally one single bbmiiphy bus in this driver, remove the bus index handling. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 95a459cec2a..de697060d28 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -905,8 +905,6 @@ int designware_eth_probe(struct udevice *dev) #if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) if (dev_read_bool(dev, "snps,bitbang-mii")) { - int bus_idx; - debug("\n%s: use bitbang mii..\n", dev->name); ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0, &priv->mdc_gpio, GPIOD_IS_OUT @@ -924,16 +922,11 @@ int designware_eth_probe(struct udevice *dev) } priv->bb_delay = dev_read_u32_default(dev, "snps,bitbang-delay", 1); - for (bus_idx = 0; bus_idx < bb_miiphy_buses_num; bus_idx++) { - if (!bb_miiphy_buses[bus_idx].priv) { - bb_miiphy_buses[bus_idx].priv = priv; - strlcpy(bb_miiphy_buses[bus_idx].name, priv->bus->name, - MDIO_NAME_LEN); - priv->bus->read = bb_miiphy_read; - priv->bus->write = bb_miiphy_write; - break; - } - } + bb_miiphy_buses[0].priv = priv; + strlcpy(bb_miiphy_buses[0].name, priv->bus->name, + MDIO_NAME_LEN); + priv->bus->read = bb_miiphy_read; + priv->bus->write = bb_miiphy_write; } #endif ret = dw_phy_init(priv, dev); -- cgit v1.2.3 From a6a38bba5d14d68d2d86e137b7408393f29c5b7a Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:21 +0100 Subject: net: designware: Extract bbmiiphy initialization into dedicated function Pull the bbmiiphy initialization code from designware_eth_probe() into dedicated function, dw_bb_mdio_init(), just like all the other MDIO initialization functions. Keep check for "snps,bitbang-mii" in the designware_eth_probe(), so the driver can initialize this MDIO only in case the property is present, and initialize regular DW MDIO in case it is not present. The dw_bb_mdio_init() allocates its own MDIO instance, because thus far code gated behind "snps,bitbang-mii" did depend on allocation of MDIO bus by the other two MDIO bus options and then rewrote the newly allocated MDIO bus callbacks, which is wrong, instead allocate proper MDIO bus with the correct callbacks outright. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 95 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 32 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index de697060d28..c88b8df28ed 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -303,6 +303,50 @@ struct bb_miiphy_bus bb_miiphy_buses[] = { }; int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); + +static int dw_bb_mdio_init(const char *name, struct udevice *dev) +{ + struct dw_eth_dev *dwpriv = dev_get_priv(dev); + struct mii_dev *bus = mdio_alloc(); + int ret; + + if (!bus) { + printf("Failed to allocate MDIO bus\n"); + return -ENOMEM; + } + + debug("\n%s: use bitbang mii..\n", dev->name); + ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0, + &dwpriv->mdc_gpio, + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); + if (ret) { + debug("no mdc-gpio\n"); + return ret; + } + ret = gpio_request_by_name(dev, "snps,mdio-gpio", 0, + &dwpriv->mdio_gpio, + GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE); + if (ret) { + debug("no mdio-gpio\n"); + return ret; + } + dwpriv->bb_delay = dev_read_u32_default(dev, "snps,bitbang-delay", 1); + + dwpriv->bus = bus; + dwpriv->dev = dev; + + bb_miiphy_buses[0].priv = dwpriv; + snprintf(bus->name, sizeof(bus->name), "%s", name); + strlcpy(bb_miiphy_buses[0].name, bus->name, MDIO_NAME_LEN); + bus->read = bb_miiphy_read; + bus->write = bb_miiphy_write; +#if CONFIG_IS_ENABLED(DM_GPIO) + bus->reset = dw_mdio_reset; +#endif + bus->priv = dwpriv; + + return mdio_register(bus); +} #endif static void tx_descs_init(struct dw_eth_dev *priv) @@ -801,6 +845,7 @@ int designware_eth_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct dw_eth_dev *priv = dev_get_priv(dev); + bool __maybe_unused bbmiiphy = false; phys_addr_t iobase = pdata->iobase; void *ioaddr; int ret, err; @@ -891,44 +936,30 @@ int designware_eth_probe(struct udevice *dev) priv->interface = pdata->phy_interface; priv->max_speed = pdata->max_speed; -#if IS_ENABLED(CONFIG_DM_MDIO) - ret = dw_dm_mdio_init(dev->name, dev); -#else - ret = dw_mdio_init(dev->name, dev); -#endif - if (ret) { - err = ret; - goto mdio_err; - } - priv->bus = miiphy_get_dev_by_name(dev->name); - priv->dev = dev; - #if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) - if (dev_read_bool(dev, "snps,bitbang-mii")) { - debug("\n%s: use bitbang mii..\n", dev->name); - ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0, - &priv->mdc_gpio, GPIOD_IS_OUT - | GPIOD_IS_OUT_ACTIVE); + bbmiiphy = dev_read_bool(dev, "snps,bitbang-mii"); + if (bbmiiphy) { + ret = dw_bb_mdio_init(dev->name, dev); if (ret) { - debug("no mdc-gpio\n"); - return ret; + err = ret; + goto mdio_err; } - ret = gpio_request_by_name(dev, "snps,mdio-gpio", 0, - &priv->mdio_gpio, GPIOD_IS_OUT - | GPIOD_IS_OUT_ACTIVE); + } else +#endif + { +#if IS_ENABLED(CONFIG_DM_MDIO) + ret = dw_dm_mdio_init(dev->name, dev); +#else + ret = dw_mdio_init(dev->name, dev); +#endif if (ret) { - debug("no mdio-gpio\n"); - return ret; + err = ret; + goto mdio_err; } - priv->bb_delay = dev_read_u32_default(dev, "snps,bitbang-delay", 1); - - bb_miiphy_buses[0].priv = priv; - strlcpy(bb_miiphy_buses[0].name, priv->bus->name, - MDIO_NAME_LEN); - priv->bus->read = bb_miiphy_read; - priv->bus->write = bb_miiphy_write; + priv->bus = miiphy_get_dev_by_name(dev->name); + priv->dev = dev; } -#endif + ret = dw_phy_init(priv, dev); debug("%s, ret=%d\n", __func__, ret); if (!ret) -- cgit v1.2.3 From cbb69c2fafcc7c7e9b2336a658128cb394d8d3e4 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:27 +0100 Subject: net: designware: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks currently listed in bb_miiphy_buses[] array. This is a temporary duplication of assignment to avoid breakage, which will be removed in follow up patches. At this point, the bb_miiphy callbacks can reach these accessors by doing container_of() on struct mii_dev. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index c88b8df28ed..74cf8271e67 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -307,14 +307,17 @@ int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); static int dw_bb_mdio_init(const char *name, struct udevice *dev) { struct dw_eth_dev *dwpriv = dev_get_priv(dev); - struct mii_dev *bus = mdio_alloc(); + struct bb_miiphy_bus *bb_miiphy = bb_miiphy_alloc(); + struct mii_dev *bus; int ret; - if (!bus) { + if (!bb_miiphy) { printf("Failed to allocate MDIO bus\n"); return -ENOMEM; } + bus = &bb_miiphy->mii; + debug("\n%s: use bitbang mii..\n", dev->name); ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0, &dwpriv->mdc_gpio, @@ -345,6 +348,15 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) #endif bus->priv = dwpriv; + /* Copy the bus accessors, name and private data */ + bb_miiphy->mdio_active = dw_eth_bb_mdio_active; + bb_miiphy->mdio_tristate = dw_eth_bb_mdio_tristate; + bb_miiphy->set_mdio = dw_eth_bb_set_mdio; + bb_miiphy->get_mdio = dw_eth_bb_get_mdio; + bb_miiphy->set_mdc = dw_eth_bb_set_mdc; + bb_miiphy->delay = dw_eth_bb_delay; + strlcpy(bb_miiphy->name, bus->name, MDIO_NAME_LEN); + return mdio_register(bus); } #endif @@ -968,7 +980,12 @@ int designware_eth_probe(struct udevice *dev) /* continue here for cleanup if no PHY found */ err = ret; mdio_unregister(priv->bus); - mdio_free(priv->bus); +#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) + if (bbmiiphy) + bb_miiphy_free(container_of(priv->bus, struct bb_miiphy_bus, mii)); + else +#endif + mdio_free(priv->bus); mdio_err: #ifdef CONFIG_CLK -- cgit v1.2.3 From a23f9a786b010177839d6fe9f67c717f17f74368 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:29 +0100 Subject: net: miiphybb: Drop name field from struct bb_miiphy_bus The struct bb_miiphy_bus embeds struct struct mii_dev, which already contains one copy of name field. Drop the duplicate top level copy of name field. The a38x code does static assignment of disparate names, use snprintf(...) to fill in matching name in probe to avoid any breakage. Reviewed-by: Paul Barker Signed-off-by: Marek Vasut --- drivers/net/designware.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 74cf8271e67..5124982e683 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -292,7 +292,6 @@ static int dw_eth_bb_delay(struct bb_miiphy_bus *bus) struct bb_miiphy_bus bb_miiphy_buses[] = { { - .name = BB_MII_DEVNAME, .mdio_active = dw_eth_bb_mdio_active, .mdio_tristate = dw_eth_bb_mdio_tristate, .set_mdio = dw_eth_bb_set_mdio, @@ -340,7 +339,6 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) bb_miiphy_buses[0].priv = dwpriv; snprintf(bus->name, sizeof(bus->name), "%s", name); - strlcpy(bb_miiphy_buses[0].name, bus->name, MDIO_NAME_LEN); bus->read = bb_miiphy_read; bus->write = bb_miiphy_write; #if CONFIG_IS_ENABLED(DM_GPIO) @@ -348,14 +346,13 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) #endif bus->priv = dwpriv; - /* Copy the bus accessors, name and private data */ + /* Copy the bus accessors and private data */ bb_miiphy->mdio_active = dw_eth_bb_mdio_active; bb_miiphy->mdio_tristate = dw_eth_bb_mdio_tristate; bb_miiphy->set_mdio = dw_eth_bb_set_mdio; bb_miiphy->get_mdio = dw_eth_bb_get_mdio; bb_miiphy->set_mdc = dw_eth_bb_set_mdc; bb_miiphy->delay = dw_eth_bb_delay; - strlcpy(bb_miiphy->name, bus->name, MDIO_NAME_LEN); return mdio_register(bus); } -- cgit v1.2.3 From 4e6fed49becc7e8d9639966fd34695583192a3ee Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sat, 22 Feb 2025 21:33:33 +0100 Subject: net: miiphybb: Drop bb_miiphy_buses and bb_miiphy_buses_num Neither bb_miiphy_buses nor bb_miiphy_buses_num are used anymore. Drop both of them. Reviewed-by: Paul Barker Signed-off-by: Marek Vasut --- drivers/net/designware.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 5124982e683..5a6e89c0575 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -290,19 +290,6 @@ static int dw_eth_bb_delay(struct bb_miiphy_bus *bus) return 0; } -struct bb_miiphy_bus bb_miiphy_buses[] = { - { - .mdio_active = dw_eth_bb_mdio_active, - .mdio_tristate = dw_eth_bb_mdio_tristate, - .set_mdio = dw_eth_bb_set_mdio, - .get_mdio = dw_eth_bb_get_mdio, - .set_mdc = dw_eth_bb_set_mdc, - .delay = dw_eth_bb_delay, - } -}; - -int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses); - static int dw_bb_mdio_init(const char *name, struct udevice *dev) { struct dw_eth_dev *dwpriv = dev_get_priv(dev); @@ -337,7 +324,6 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) dwpriv->bus = bus; dwpriv->dev = dev; - bb_miiphy_buses[0].priv = dwpriv; snprintf(bus->name, sizeof(bus->name), "%s", name); bus->read = bb_miiphy_read; bus->write = bb_miiphy_write; -- cgit v1.2.3 From c9671c9036d465e0681d947b0b7a76019a096758 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:42 +0100 Subject: net: miiphybb: Split off struct bb_miiphy_bus_ops Move miiphybb operations into separate struct bb_miiphy_bus_ops structure, add pointer to struct bb_miiphy_bus_ops into the base struct bb_miiphy_bus and access the ops through this pointer in miiphybb generic code. The variable reshuffling in miiphybb.c cannot be easily avoided. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 5a6e89c0575..045bff476d1 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -290,6 +290,15 @@ static int dw_eth_bb_delay(struct bb_miiphy_bus *bus) return 0; } +static const struct bb_miiphy_bus_ops dw_eth_bb_miiphy_bus_ops = { + .mdio_active = dw_eth_bb_mdio_active, + .mdio_tristate = dw_eth_bb_mdio_tristate, + .set_mdio = dw_eth_bb_set_mdio, + .get_mdio = dw_eth_bb_get_mdio, + .set_mdc = dw_eth_bb_set_mdc, + .delay = dw_eth_bb_delay, +}; + static int dw_bb_mdio_init(const char *name, struct udevice *dev) { struct dw_eth_dev *dwpriv = dev_get_priv(dev); @@ -330,16 +339,9 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) #if CONFIG_IS_ENABLED(DM_GPIO) bus->reset = dw_mdio_reset; #endif + bus->ops = &dw_eth_bb_miiphy_bus_ops; bus->priv = dwpriv; - /* Copy the bus accessors and private data */ - bb_miiphy->mdio_active = dw_eth_bb_mdio_active; - bb_miiphy->mdio_tristate = dw_eth_bb_mdio_tristate; - bb_miiphy->set_mdio = dw_eth_bb_set_mdio; - bb_miiphy->get_mdio = dw_eth_bb_get_mdio; - bb_miiphy->set_mdc = dw_eth_bb_set_mdc; - bb_miiphy->delay = dw_eth_bb_delay; - return mdio_register(bus); } #endif -- cgit v1.2.3 From 3374d3783a575db7dd2dc9f2f74b7523e547b130 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:43 +0100 Subject: net: miiphybb: Wrap driver side bb_miiphy_read/write() accessors Do not call bb_miiphy_read()/bb_miiphy_write() accessors directly in drivers, instead call them through wrapper functions. Those are meant to be used as function parameter adaptation layer between struct mii_dev callback function parameters and what the miiphybb does expect and will soon expect. This is a preparatory patch, no functional change. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 045bff476d1..3c3450aa778 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -299,6 +299,18 @@ static const struct bb_miiphy_bus_ops dw_eth_bb_miiphy_bus_ops = { .delay = dw_eth_bb_delay, }; +static int dw_bb_miiphy_read(struct mii_dev *miidev, int addr, + int devad, int reg) +{ + return bb_miiphy_read(miidev, addr, devad, reg); +} + +static int dw_bb_miiphy_write(struct mii_dev *miidev, int addr, + int devad, int reg, u16 value) +{ + return bb_miiphy_write(miidev, addr, devad, reg, value); +} + static int dw_bb_mdio_init(const char *name, struct udevice *dev) { struct dw_eth_dev *dwpriv = dev_get_priv(dev); @@ -334,8 +346,8 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) dwpriv->dev = dev; snprintf(bus->name, sizeof(bus->name), "%s", name); - bus->read = bb_miiphy_read; - bus->write = bb_miiphy_write; + bus->read = dw_bb_miiphy_read; + bus->write = dw_bb_miiphy_write; #if CONFIG_IS_ENABLED(DM_GPIO) bus->reset = dw_mdio_reset; #endif -- cgit v1.2.3 From c5318bdcf80965fddccf68146c7838816aedb154 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:44 +0100 Subject: net: miiphybb: Pass struct bb_miiphy_bus_ops directly to bb_miiphy_read/write() The access to struct bb_miiphy_bus_ops via ops pointer in struct bb_miiphy_bus is not necessary with wrappers added in previous patch. Pass the ops pointer directly to both bb_miiphy_read() and bb_miiphy_write() functions. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 3c3450aa778..2069e34be15 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -302,13 +302,15 @@ static const struct bb_miiphy_bus_ops dw_eth_bb_miiphy_bus_ops = { static int dw_bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg) { - return bb_miiphy_read(miidev, addr, devad, reg); + return bb_miiphy_read(miidev, &dw_eth_bb_miiphy_bus_ops, + addr, devad, reg); } static int dw_bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, u16 value) { - return bb_miiphy_write(miidev, addr, devad, reg, value); + return bb_miiphy_write(miidev, &dw_eth_bb_miiphy_bus_ops, + addr, devad, reg, value); } static int dw_bb_mdio_init(const char *name, struct udevice *dev) @@ -351,7 +353,6 @@ static int dw_bb_mdio_init(const char *name, struct udevice *dev) #if CONFIG_IS_ENABLED(DM_GPIO) bus->reset = dw_mdio_reset; #endif - bus->ops = &dw_eth_bb_miiphy_bus_ops; bus->priv = dwpriv; return mdio_register(bus); -- cgit v1.2.3 From 7cded10da35730ff27062d19b8ad72242be8038f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:45 +0100 Subject: net: miiphybb: Pass struct mii_dev directly to bb_miiphy_read/write() Access to MDIO bus private data can be provided by both struct mii_dev .priv member and struct bb_miiphy_bus .priv member, use the former directly and remove .priv from the later. Drop unused bb_miiphy_getbus(). This removes any dependency on struct bb_miiphy_bus from the miiphybb code, except for helper functions which will be removed later. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 2069e34be15..4827811dce3 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -227,9 +227,9 @@ static int dw_dm_mdio_init(const char *name, void *priv) #endif #if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) -static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus) +static int dw_eth_bb_mdio_active(struct mii_dev *miidev) { - struct dw_eth_dev *priv = bus->priv; + struct dw_eth_dev *priv = miidev->priv; struct gpio_desc *desc = &priv->mdio_gpio; desc->flags = 0; @@ -238,9 +238,9 @@ static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus) return 0; } -static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) +static int dw_eth_bb_mdio_tristate(struct mii_dev *miidev) { - struct dw_eth_dev *priv = bus->priv; + struct dw_eth_dev *priv = miidev->priv; struct gpio_desc *desc = &priv->mdio_gpio; desc->flags = 0; @@ -249,9 +249,9 @@ static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) return 0; } -static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) +static int dw_eth_bb_set_mdio(struct mii_dev *miidev, int v) { - struct dw_eth_dev *priv = bus->priv; + struct dw_eth_dev *priv = miidev->priv; if (v) dm_gpio_set_value(&priv->mdio_gpio, 1); @@ -261,18 +261,18 @@ static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) return 0; } -static int dw_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) +static int dw_eth_bb_get_mdio(struct mii_dev *miidev, int *v) { - struct dw_eth_dev *priv = bus->priv; + struct dw_eth_dev *priv = miidev->priv; *v = dm_gpio_get_value(&priv->mdio_gpio); return 0; } -static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) +static int dw_eth_bb_set_mdc(struct mii_dev *miidev, int v) { - struct dw_eth_dev *priv = bus->priv; + struct dw_eth_dev *priv = miidev->priv; if (v) dm_gpio_set_value(&priv->mdc_gpio, 1); @@ -282,9 +282,9 @@ static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) return 0; } -static int dw_eth_bb_delay(struct bb_miiphy_bus *bus) +static int dw_eth_bb_delay(struct mii_dev *miidev) { - struct dw_eth_dev *priv = bus->priv; + struct dw_eth_dev *priv = miidev->priv; udelay(priv->bb_delay); return 0; -- cgit v1.2.3 From ce7e9a5a636215d2f09ae35acf552b07f4d5b66f Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:47 +0100 Subject: net: designware: Switch back to mdio_alloc() Use mdio_alloc() again to allocate MDIO bus. This is possible because all the miiphybb parameters and ops passing is handled in at bb_miiphy_read()/bb_miiphy_write() level. This also fixes previously missed bb_miiphy_free() in .remove callback of this driver. which does not pose a problem anymore. Fixes: cbb69c2fafcc ("net: designware: Allocate bb_miiphy using bb_miiphy_alloc() and fill in callbacks") Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/designware.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'drivers/net/designware.c') diff --git a/drivers/net/designware.c b/drivers/net/designware.c index 4827811dce3..0f93c25e3fe 100644 --- a/drivers/net/designware.c +++ b/drivers/net/designware.c @@ -316,17 +316,14 @@ static int dw_bb_miiphy_write(struct mii_dev *miidev, int addr, static int dw_bb_mdio_init(const char *name, struct udevice *dev) { struct dw_eth_dev *dwpriv = dev_get_priv(dev); - struct bb_miiphy_bus *bb_miiphy = bb_miiphy_alloc(); - struct mii_dev *bus; + struct mii_dev *bus = mdio_alloc(); int ret; - if (!bb_miiphy) { + if (!bus) { printf("Failed to allocate MDIO bus\n"); return -ENOMEM; } - bus = &bb_miiphy->mii; - debug("\n%s: use bitbang mii..\n", dev->name); ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0, &dwpriv->mdc_gpio, @@ -855,7 +852,6 @@ int designware_eth_probe(struct udevice *dev) { struct eth_pdata *pdata = dev_get_plat(dev); struct dw_eth_dev *priv = dev_get_priv(dev); - bool __maybe_unused bbmiiphy = false; phys_addr_t iobase = pdata->iobase; void *ioaddr; int ret, err; @@ -947,8 +943,7 @@ int designware_eth_probe(struct udevice *dev) priv->max_speed = pdata->max_speed; #if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) - bbmiiphy = dev_read_bool(dev, "snps,bitbang-mii"); - if (bbmiiphy) { + if (dev_read_bool(dev, "snps,bitbang-mii")) { ret = dw_bb_mdio_init(dev->name, dev); if (ret) { err = ret; @@ -978,12 +973,7 @@ int designware_eth_probe(struct udevice *dev) /* continue here for cleanup if no PHY found */ err = ret; mdio_unregister(priv->bus); -#if IS_ENABLED(CONFIG_BITBANGMII) && IS_ENABLED(CONFIG_DM_GPIO) - if (bbmiiphy) - bb_miiphy_free(container_of(priv->bus, struct bb_miiphy_bus, mii)); - else -#endif - mdio_free(priv->bus); + mdio_free(priv->bus); mdio_err: #ifdef CONFIG_CLK -- cgit v1.2.3