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 --- include/miiphy.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/miiphy.h b/include/miiphy.h index f2ff7506ee8..5fd86bef882 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -62,14 +62,20 @@ void mdio_list_devices(void); #define BB_MII_DEVNAME "bb_miiphy" -struct bb_miiphy_bus { +struct bb_miiphy_bus; + +struct bb_miiphy_bus_ops { int (*mdio_active)(struct bb_miiphy_bus *bus); int (*mdio_tristate)(struct bb_miiphy_bus *bus); int (*set_mdio)(struct bb_miiphy_bus *bus, int v); int (*get_mdio)(struct bb_miiphy_bus *bus, int *v); int (*set_mdc)(struct bb_miiphy_bus *bus, int v); int (*delay)(struct bb_miiphy_bus *bus); +}; + +struct bb_miiphy_bus { void *priv; + const struct bb_miiphy_bus_ops *ops; struct mii_dev mii; }; -- cgit v1.3.1 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 --- board/gdsys/a38x/ihs_phys.c | 7 ++++--- drivers/net/designware.c | 7 ++++--- drivers/net/phy/miiphybb.c | 13 ++++--------- drivers/net/ravb.c | 7 ++++--- drivers/net/sh_eth.c | 7 ++++--- include/miiphy.h | 8 ++++---- 6 files changed, 24 insertions(+), 25 deletions(-) (limited to 'include') diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 304b5b5f0bc..6176a47cda0 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -231,13 +231,15 @@ static const struct bb_miiphy_bus_ops mii_bb_miiphy_bus_ops = { static int mii_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, &mii_bb_miiphy_bus_ops, + addr, devad, reg); } static int mii_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, &mii_bb_miiphy_bus_ops, + addr, devad, reg, value); } int register_miiphy_bus(uint k, struct mii_dev **bus) @@ -255,7 +257,6 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) mdiodev->write = mii_bb_miiphy_write; /* Copy the bus accessors and private data */ - bb_miiphy->ops = &mii_bb_miiphy_bus_ops; bb_miiphy->priv = &gpio_mii_set[k]; retval = mdio_register(mdiodev); 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); diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index e6106341eb3..9481ba76f51 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -126,21 +126,19 @@ static void miiphy_pre(struct bb_miiphy_bus *bus, const struct bb_miiphy_bus_ops * Returns: * 0 on success */ -int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg) +int bb_miiphy_read(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, + int addr, int devad, int reg) { unsigned short rdreg; /* register working value */ int v; int j; /* counter */ struct bb_miiphy_bus *bus; - const struct bb_miiphy_bus_ops *ops; bus = bb_miiphy_getbus(miidev); if (bus == NULL) { return -1; } - ops = bus->ops; - miiphy_pre(bus, ops, 1, addr, reg); /* tri-state our MDIO I/O pin so we can read */ @@ -198,11 +196,10 @@ int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg) * Returns: * 0 on success */ -int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, - u16 value) +int bb_miiphy_write(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, + int addr, int devad, int reg, u16 value) { struct bb_miiphy_bus *bus; - const struct bb_miiphy_bus_ops *ops; int j; /* counter */ bus = bb_miiphy_getbus(miidev); @@ -211,8 +208,6 @@ int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, return -1; } - ops = bus->ops; - miiphy_pre(bus, ops, 0, addr, reg); /* send the turnaround (10) */ diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 9a17ac97cce..65ba107fc00 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -561,13 +561,15 @@ static const struct bb_miiphy_bus_ops ravb_bb_miiphy_bus_ops = { static int ravb_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, &ravb_bb_miiphy_bus_ops, + addr, devad, reg); } static int ravb_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, &ravb_bb_miiphy_bus_ops, + addr, devad, reg, value); } static int ravb_probe(struct udevice *dev) @@ -599,7 +601,6 @@ static int ravb_probe(struct udevice *dev) snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name); /* Copy the bus accessors and private data */ - bb_miiphy->ops = &ravb_bb_miiphy_bus_ops; bb_miiphy->priv = eth; ret = mdio_register(mdiodev); diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index cef531c8c6f..738dc43cdc7 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -723,13 +723,15 @@ static const struct bb_miiphy_bus_ops sh_ether_bb_miiphy_bus_ops = { static int sh_eth_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, &sh_ether_bb_miiphy_bus_ops, + addr, devad, reg); } static int sh_eth_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, &sh_ether_bb_miiphy_bus_ops, + addr, devad, reg, value); } static int sh_ether_probe(struct udevice *udev) @@ -761,7 +763,6 @@ static int sh_ether_probe(struct udevice *udev) snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name); /* Copy the bus accessors and private data */ - bb_miiphy->ops = &sh_ether_bb_miiphy_bus_ops; bb_miiphy->priv = eth; ret = mdio_register(mdiodev); diff --git a/include/miiphy.h b/include/miiphy.h index 5fd86bef882..31d81b4b551 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -75,16 +75,16 @@ struct bb_miiphy_bus_ops { struct bb_miiphy_bus { void *priv; - const struct bb_miiphy_bus_ops *ops; struct mii_dev mii; }; struct bb_miiphy_bus *bb_miiphy_alloc(void); void bb_miiphy_free(struct bb_miiphy_bus *bus); -int bb_miiphy_read(struct mii_dev *miidev, int addr, int devad, int reg); -int bb_miiphy_write(struct mii_dev *miidev, int addr, int devad, int reg, - u16 value); +int bb_miiphy_read(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, + int addr, int devad, int reg); +int bb_miiphy_write(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, + int addr, int devad, int reg, u16 value); #endif /* phy seed setup */ -- cgit v1.3.1 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 --- board/gdsys/a38x/ihs_phys.c | 29 +++---- drivers/net/designware.c | 24 +++--- drivers/net/phy/miiphybb.c | 188 ++++++++++++++++++++------------------------ drivers/net/ravb.c | 23 +++--- drivers/net/sh_eth.c | 23 +++--- include/miiphy.h | 12 +-- 6 files changed, 142 insertions(+), 157 deletions(-) (limited to 'include') diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 6176a47cda0..86a4049238b 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -123,9 +123,9 @@ struct gpio_mii { { 2, {}, {}, 46, 24, 1 }, }; -static int mii_mdio_init(struct bb_miiphy_bus *bus) +static int mii_mdio_init(const int k) { - struct gpio_mii *gpio_mii = bus->priv; + struct gpio_mii *gpio_mii = &gpio_mii_set[k]; char name[32] = {}; struct udevice *gpio_dev1 = NULL; struct udevice *gpio_dev2 = NULL; @@ -164,27 +164,27 @@ static int mii_mdio_init(struct bb_miiphy_bus *bus) return 0; } -static int mii_mdio_active(struct bb_miiphy_bus *bus) +static int mii_mdio_active(struct mii_dev *miidev) { - struct gpio_mii *gpio_mii = bus->priv; + struct gpio_mii *gpio_mii = miidev->priv; dm_gpio_set_value(&gpio_mii->mdc_gpio, gpio_mii->mdio_value); return 0; } -static int mii_mdio_tristate(struct bb_miiphy_bus *bus) +static int mii_mdio_tristate(struct mii_dev *miidev) { - struct gpio_mii *gpio_mii = bus->priv; + struct gpio_mii *gpio_mii = miidev->priv; dm_gpio_set_dir_flags(&gpio_mii->mdio_gpio, GPIOD_IS_IN); return 0; } -static int mii_set_mdio(struct bb_miiphy_bus *bus, int v) +static int mii_set_mdio(struct mii_dev *miidev, int v) { - struct gpio_mii *gpio_mii = bus->priv; + struct gpio_mii *gpio_mii = miidev->priv; dm_gpio_set_dir_flags(&gpio_mii->mdio_gpio, GPIOD_IS_OUT); dm_gpio_set_value(&gpio_mii->mdio_gpio, v); @@ -193,9 +193,9 @@ static int mii_set_mdio(struct bb_miiphy_bus *bus, int v) return 0; } -static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v) +static int mii_get_mdio(struct mii_dev *miidev, int *v) { - struct gpio_mii *gpio_mii = bus->priv; + struct gpio_mii *gpio_mii = miidev->priv; dm_gpio_set_dir_flags(&gpio_mii->mdio_gpio, GPIOD_IS_IN); *v = (dm_gpio_get_value(&gpio_mii->mdio_gpio)); @@ -203,16 +203,16 @@ static int mii_get_mdio(struct bb_miiphy_bus *bus, int *v) return 0; } -static int mii_set_mdc(struct bb_miiphy_bus *bus, int v) +static int mii_set_mdc(struct mii_dev *miidev, int v) { - struct gpio_mii *gpio_mii = bus->priv; + struct gpio_mii *gpio_mii = miidev->priv; dm_gpio_set_value(&gpio_mii->mdc_gpio, v); return 0; } -static int mii_delay(struct bb_miiphy_bus *bus) +static int mii_delay(struct mii_dev *miidev) { udelay(1); @@ -255,6 +255,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) snprintf(mdiodev->name, MDIO_NAME_LEN, "ihs%d", k); mdiodev->read = mii_bb_miiphy_read; mdiodev->write = mii_bb_miiphy_write; + mdiodev->priv = &gpio_mii_set[k]; /* Copy the bus accessors and private data */ bb_miiphy->priv = &gpio_mii_set[k]; @@ -264,7 +265,7 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) return retval; *bus = &bb_miiphy->mii; - return mii_mdio_init(bb_miiphy); + return mii_mdio_init(k); } struct porttype *get_porttype(uint octo_phy_mask, uint k) 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; diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index 9481ba76f51..60c791b707b 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -18,11 +18,6 @@ #include #include -static inline struct bb_miiphy_bus *bb_miiphy_getbus(struct mii_dev *miidev) -{ - return container_of(miidev, struct bb_miiphy_bus, mii); -} - struct bb_miiphy_bus *bb_miiphy_alloc(void) { struct bb_miiphy_bus *bus; @@ -46,7 +41,7 @@ void bb_miiphy_free(struct bb_miiphy_bus *bus) * Utility to send the preamble, address, and register (common to read * and write). */ -static void miiphy_pre(struct bb_miiphy_bus *bus, const struct bb_miiphy_bus_ops *ops, +static void miiphy_pre(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, char read, unsigned char addr, unsigned char reg) { int j; @@ -59,62 +54,62 @@ static void miiphy_pre(struct bb_miiphy_bus *bus, const struct bb_miiphy_bus_ops * but it is safer and will be much more robust. */ - ops->mdio_active(bus); - ops->set_mdio(bus, 1); + ops->mdio_active(miidev); + ops->set_mdio(miidev, 1); for (j = 0; j < 32; j++) { - ops->set_mdc(bus, 0); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); } /* send the start bit (01) and the read opcode (10) or write (10) */ - ops->set_mdc(bus, 0); - ops->set_mdio(bus, 0); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 0); - ops->set_mdio(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 0); - ops->set_mdio(bus, read); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 0); - ops->set_mdio(bus, !read); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->set_mdio(miidev, 0); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 0); + ops->set_mdio(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 0); + ops->set_mdio(miidev, read); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 0); + ops->set_mdio(miidev, !read); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); /* send the PHY address */ for (j = 0; j < 5; j++) { - ops->set_mdc(bus, 0); + ops->set_mdc(miidev, 0); if ((addr & 0x10) == 0) { - ops->set_mdio(bus, 0); + ops->set_mdio(miidev, 0); } else { - ops->set_mdio(bus, 1); + ops->set_mdio(miidev, 1); } - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); addr <<= 1; } /* send the register address */ for (j = 0; j < 5; j++) { - ops->set_mdc(bus, 0); + ops->set_mdc(miidev, 0); if ((reg & 0x10) == 0) { - ops->set_mdio(bus, 0); + ops->set_mdio(miidev, 0); } else { - ops->set_mdio(bus, 1); + ops->set_mdio(miidev, 1); } - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); reg <<= 1; } } @@ -132,57 +127,51 @@ int bb_miiphy_read(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, unsigned short rdreg; /* register working value */ int v; int j; /* counter */ - struct bb_miiphy_bus *bus; - bus = bb_miiphy_getbus(miidev); - if (bus == NULL) { - return -1; - } - - miiphy_pre(bus, ops, 1, addr, reg); + miiphy_pre(miidev, ops, 1, addr, reg); /* tri-state our MDIO I/O pin so we can read */ - ops->set_mdc(bus, 0); - ops->mdio_tristate(bus); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->mdio_tristate(miidev); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); /* check the turnaround bit: the PHY should be driving it to zero */ - ops->get_mdio(bus, &v); + ops->get_mdio(miidev, &v); if (v != 0) { /* puts ("PHY didn't drive TA low\n"); */ for (j = 0; j < 32; j++) { - ops->set_mdc(bus, 0); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); } /* There is no PHY, return */ return -1; } - ops->set_mdc(bus, 0); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->delay(miidev); /* read 16 bits of register data, MSB first */ rdreg = 0; for (j = 0; j < 16; j++) { - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 1); + ops->delay(miidev); rdreg <<= 1; - ops->get_mdio(bus, &v); + ops->get_mdio(miidev, &v); rdreg |= (v & 0x1); - ops->set_mdc(bus, 0); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->delay(miidev); } - ops->set_mdc(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 0); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 0); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); debug("%s[%s](0x%x) @ 0x%x = 0x%04x\n", __func__, miidev->name, reg, addr, rdreg); @@ -199,51 +188,44 @@ int bb_miiphy_read(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, int bb_miiphy_write(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, int addr, int devad, int reg, u16 value) { - struct bb_miiphy_bus *bus; int j; /* counter */ - bus = bb_miiphy_getbus(miidev); - if (bus == NULL) { - /* Bus not found! */ - return -1; - } - - miiphy_pre(bus, ops, 0, addr, reg); + miiphy_pre(miidev, ops, 0, addr, reg); /* send the turnaround (10) */ - ops->set_mdc(bus, 0); - ops->set_mdio(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); - ops->set_mdc(bus, 0); - ops->set_mdio(bus, 0); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->set_mdc(miidev, 0); + ops->set_mdio(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); + ops->set_mdc(miidev, 0); + ops->set_mdio(miidev, 0); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); /* write 16 bits of register data, MSB first */ for (j = 0; j < 16; j++) { - ops->set_mdc(bus, 0); + ops->set_mdc(miidev, 0); if ((value & 0x00008000) == 0) { - ops->set_mdio(bus, 0); + ops->set_mdio(miidev, 0); } else { - ops->set_mdio(bus, 1); + ops->set_mdio(miidev, 1); } - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); value <<= 1; } /* * Tri-state the MDIO line. */ - ops->mdio_tristate(bus); - ops->set_mdc(bus, 0); - ops->delay(bus); - ops->set_mdc(bus, 1); - ops->delay(bus); + ops->mdio_tristate(miidev); + ops->set_mdc(miidev, 0); + ops->delay(miidev); + ops->set_mdc(miidev, 1); + ops->delay(miidev); return 0; } diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 65ba107fc00..52547b27aff 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -491,27 +491,27 @@ static void ravb_stop(struct udevice *dev) } /* Bitbang MDIO access */ -static int ravb_bb_mdio_active(struct bb_miiphy_bus *bus) +static int ravb_bb_mdio_active(struct mii_dev *miidev) { - struct ravb_priv *eth = bus->priv; + struct ravb_priv *eth = miidev->priv; setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); return 0; } -static int ravb_bb_mdio_tristate(struct bb_miiphy_bus *bus) +static int ravb_bb_mdio_tristate(struct mii_dev *miidev) { - struct ravb_priv *eth = bus->priv; + struct ravb_priv *eth = miidev->priv; clrbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MMD); return 0; } -static int ravb_bb_set_mdio(struct bb_miiphy_bus *bus, int v) +static int ravb_bb_set_mdio(struct mii_dev *miidev, int v) { - struct ravb_priv *eth = bus->priv; + struct ravb_priv *eth = miidev->priv; if (v) setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDO); @@ -521,18 +521,18 @@ static int ravb_bb_set_mdio(struct bb_miiphy_bus *bus, int v) return 0; } -static int ravb_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) +static int ravb_bb_get_mdio(struct mii_dev *miidev, int *v) { - struct ravb_priv *eth = bus->priv; + struct ravb_priv *eth = miidev->priv; *v = (readl(eth->iobase + RAVB_REG_PIR) & PIR_MDI) >> 3; return 0; } -static int ravb_bb_set_mdc(struct bb_miiphy_bus *bus, int v) +static int ravb_bb_set_mdc(struct mii_dev *miidev, int v) { - struct ravb_priv *eth = bus->priv; + struct ravb_priv *eth = miidev->priv; if (v) setbits_le32(eth->iobase + RAVB_REG_PIR, PIR_MDC); @@ -542,7 +542,7 @@ static int ravb_bb_set_mdc(struct bb_miiphy_bus *bus, int v) return 0; } -static int ravb_bb_delay(struct bb_miiphy_bus *bus) +static int ravb_bb_delay(struct mii_dev *miidev) { udelay(10); @@ -598,6 +598,7 @@ static int ravb_probe(struct udevice *dev) mdiodev->read = ravb_bb_miiphy_read; mdiodev->write = ravb_bb_miiphy_write; + mdiodev->priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name); /* Copy the bus accessors and private data */ diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index 738dc43cdc7..c898a2204d8 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -644,9 +644,9 @@ static void sh_ether_stop(struct udevice *dev) } /******* for bb_miiphy *******/ -static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) +static int sh_eth_bb_mdio_active(struct mii_dev *miidev) { - struct sh_eth_dev *eth = bus->priv; + struct sh_eth_dev *eth = miidev->priv; struct sh_eth_info *port_info = ð->port_info[eth->port]; sh_eth_write(port_info, sh_eth_read(port_info, PIR) | PIR_MMD, PIR); @@ -654,9 +654,9 @@ static int sh_eth_bb_mdio_active(struct bb_miiphy_bus *bus) return 0; } -static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) +static int sh_eth_bb_mdio_tristate(struct mii_dev *miidev) { - struct sh_eth_dev *eth = bus->priv; + struct sh_eth_dev *eth = miidev->priv; struct sh_eth_info *port_info = ð->port_info[eth->port]; sh_eth_write(port_info, sh_eth_read(port_info, PIR) & ~PIR_MMD, PIR); @@ -664,9 +664,9 @@ static int sh_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus) return 0; } -static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) +static int sh_eth_bb_set_mdio(struct mii_dev *miidev, int v) { - struct sh_eth_dev *eth = bus->priv; + struct sh_eth_dev *eth = miidev->priv; struct sh_eth_info *port_info = ð->port_info[eth->port]; if (v) @@ -679,9 +679,9 @@ static int sh_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v) return 0; } -static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) +static int sh_eth_bb_get_mdio(struct mii_dev *miidev, int *v) { - struct sh_eth_dev *eth = bus->priv; + struct sh_eth_dev *eth = miidev->priv; struct sh_eth_info *port_info = ð->port_info[eth->port]; *v = (sh_eth_read(port_info, PIR) & PIR_MDI) >> 3; @@ -689,9 +689,9 @@ static int sh_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v) return 0; } -static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) +static int sh_eth_bb_set_mdc(struct mii_dev *miidev, int v) { - struct sh_eth_dev *eth = bus->priv; + struct sh_eth_dev *eth = miidev->priv; struct sh_eth_info *port_info = ð->port_info[eth->port]; if (v) @@ -704,7 +704,7 @@ static int sh_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v) return 0; } -static int sh_eth_bb_delay(struct bb_miiphy_bus *bus) +static int sh_eth_bb_delay(struct mii_dev *miidev) { udelay(10); @@ -760,6 +760,7 @@ static int sh_ether_probe(struct udevice *udev) mdiodev->read = sh_eth_bb_miiphy_read; mdiodev->write = sh_eth_bb_miiphy_write; + mdiodev->priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name); /* Copy the bus accessors and private data */ diff --git a/include/miiphy.h b/include/miiphy.h index 31d81b4b551..9b8b42799c2 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -65,12 +65,12 @@ void mdio_list_devices(void); struct bb_miiphy_bus; struct bb_miiphy_bus_ops { - int (*mdio_active)(struct bb_miiphy_bus *bus); - int (*mdio_tristate)(struct bb_miiphy_bus *bus); - int (*set_mdio)(struct bb_miiphy_bus *bus, int v); - int (*get_mdio)(struct bb_miiphy_bus *bus, int *v); - int (*set_mdc)(struct bb_miiphy_bus *bus, int v); - int (*delay)(struct bb_miiphy_bus *bus); + int (*mdio_active)(struct mii_dev *miidev); + int (*mdio_tristate)(struct mii_dev *miidev); + int (*set_mdio)(struct mii_dev *miidev, int v); + int (*get_mdio)(struct mii_dev *miidev, int *v); + int (*set_mdc)(struct mii_dev *miidev, int v); + int (*delay)(struct mii_dev *miidev); }; struct bb_miiphy_bus { -- cgit v1.3.1 From 596d67e5163834893e9b59d7a5cb9e9a1cd8bc24 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:46 +0100 Subject: net: miiphybb: Drop priv from struct bb_miiphy_bus Remove the priv member from struct bb_miiphy_bus and its assignment from drivers. This turns struct bb_miiphy_bus int struct mii_dev wrapper, to be cleaned up next. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- board/gdsys/a38x/ihs_phys.c | 3 --- drivers/net/ravb.c | 3 --- drivers/net/sh_eth.c | 3 --- include/miiphy.h | 1 - 4 files changed, 10 deletions(-) (limited to 'include') diff --git a/board/gdsys/a38x/ihs_phys.c b/board/gdsys/a38x/ihs_phys.c index 86a4049238b..7aa427e0312 100644 --- a/board/gdsys/a38x/ihs_phys.c +++ b/board/gdsys/a38x/ihs_phys.c @@ -257,9 +257,6 @@ int register_miiphy_bus(uint k, struct mii_dev **bus) mdiodev->write = mii_bb_miiphy_write; mdiodev->priv = &gpio_mii_set[k]; - /* Copy the bus accessors and private data */ - bb_miiphy->priv = &gpio_mii_set[k]; - retval = mdio_register(mdiodev); if (retval < 0) return retval; diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c index 52547b27aff..dcd8ba9283f 100644 --- a/drivers/net/ravb.c +++ b/drivers/net/ravb.c @@ -601,9 +601,6 @@ static int ravb_probe(struct udevice *dev) mdiodev->priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), dev->name); - /* Copy the bus accessors and private data */ - bb_miiphy->priv = eth; - ret = mdio_register(mdiodev); if (ret < 0) goto err_mdio_register; diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c index c898a2204d8..c2e2f3fc6c6 100644 --- a/drivers/net/sh_eth.c +++ b/drivers/net/sh_eth.c @@ -763,9 +763,6 @@ static int sh_ether_probe(struct udevice *udev) mdiodev->priv = eth; snprintf(mdiodev->name, sizeof(mdiodev->name), udev->name); - /* Copy the bus accessors and private data */ - bb_miiphy->priv = eth; - ret = mdio_register(mdiodev); if (ret < 0) goto err_mdio_register; diff --git a/include/miiphy.h b/include/miiphy.h index 9b8b42799c2..d2678379a1b 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -74,7 +74,6 @@ struct bb_miiphy_bus_ops { }; struct bb_miiphy_bus { - void *priv; struct mii_dev mii; }; -- cgit v1.3.1 From 256306593ecdde5fe01ecc5108d564e76ea8ba65 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:51 +0100 Subject: net: miiphybb: Drop bb_miiphy_alloc()/bb_miiphy_free() and struct bb_miiphy_bus These functions are no longer necessary, remove them. The struct bb_miiphy_bus is no longer necessary either, remove it as well. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- drivers/net/phy/miiphybb.c | 19 ------------------- include/miiphy.h | 9 --------- 2 files changed, 28 deletions(-) (limited to 'include') diff --git a/drivers/net/phy/miiphybb.c b/drivers/net/phy/miiphybb.c index 60c791b707b..76463da7299 100644 --- a/drivers/net/phy/miiphybb.c +++ b/drivers/net/phy/miiphybb.c @@ -14,28 +14,9 @@ #include #include -#include #include #include -struct bb_miiphy_bus *bb_miiphy_alloc(void) -{ - struct bb_miiphy_bus *bus; - - bus = malloc(sizeof(*bus)); - if (!bus) - return bus; - - mdio_init(&bus->mii); - - return bus; -} - -void bb_miiphy_free(struct bb_miiphy_bus *bus) -{ - free(bus); -} - /***************************************************************************** * * Utility to send the preamble, address, and register (common to read diff --git a/include/miiphy.h b/include/miiphy.h index d2678379a1b..dc8ae0caca6 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -62,8 +62,6 @@ void mdio_list_devices(void); #define BB_MII_DEVNAME "bb_miiphy" -struct bb_miiphy_bus; - struct bb_miiphy_bus_ops { int (*mdio_active)(struct mii_dev *miidev); int (*mdio_tristate)(struct mii_dev *miidev); @@ -73,13 +71,6 @@ struct bb_miiphy_bus_ops { int (*delay)(struct mii_dev *miidev); }; -struct bb_miiphy_bus { - struct mii_dev mii; -}; - -struct bb_miiphy_bus *bb_miiphy_alloc(void); -void bb_miiphy_free(struct bb_miiphy_bus *bus); - int bb_miiphy_read(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, int addr, int devad, int reg); int bb_miiphy_write(struct mii_dev *miidev, const struct bb_miiphy_bus_ops *ops, -- cgit v1.3.1 From 33ccfae85372285690d8bd8256d994d7cb917cbf Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Sun, 2 Mar 2025 02:24:52 +0100 Subject: net: miiphybb: Drop mdio_init() Inline mdio_init() back into mdio_alloc(), separate access to mdio_init() is no longer necessary. Signed-off-by: Marek Vasut Reviewed-by: Paul Barker --- common/miiphyutil.c | 13 ++++--------- include/miiphy.h | 1 - 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/common/miiphyutil.c b/common/miiphyutil.c index 3d960c259b5..274e88a4921 100644 --- a/common/miiphyutil.c +++ b/common/miiphyutil.c @@ -55,14 +55,6 @@ struct mii_dev *miiphy_get_dev_by_name(const char *devname) return NULL; } -void mdio_init(struct mii_dev *bus) -{ - memset(bus, 0, sizeof(*bus)); - - /* initialize mii_dev struct fields */ - INIT_LIST_HEAD(&bus->link); -} - struct mii_dev *mdio_alloc(void) { struct mii_dev *bus; @@ -71,7 +63,10 @@ struct mii_dev *mdio_alloc(void) if (!bus) return bus; - mdio_init(bus); + memset(bus, 0, sizeof(*bus)); + + /* initialize mii_dev struct fields */ + INIT_LIST_HEAD(&bus->link); return bus; } diff --git a/include/miiphy.h b/include/miiphy.h index dc8ae0caca6..00d0b9b6a43 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -42,7 +42,6 @@ struct phy_device *mdio_phydev_for_ethname(const char *devname); void miiphy_listdev(void); -void mdio_init(struct mii_dev *bus); struct mii_dev *mdio_alloc(void); void mdio_free(struct mii_dev *bus); int mdio_register(struct mii_dev *bus); -- cgit v1.3.1