[PATCH u-boot-net v3 05/14] treewide: use dm_mdio_read/write/reset() wrappers

Marek Behún
2022-03-29T20:10:33Z

Use the new dm_mdio_read/write/reset() wrappers treewide, instead of
always getting and dereferencing MDIO operations structure pointer.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
---
drivers/net/mdio_mux_sandbox.c | 6 ++----
net/mdio-mux-uclass.c | 16 ++++------------
net/mdio-uclass.c | 19 ++++---------------
test/dm/mdio.c | 18 +++++++++---------
test/dm/mdio_mux.c | 16 ++++++++--------
5 files changed, 27 insertions(+), 48 deletions(-)

diff --git a/drivers/net/mdio_mux_sandbox.c b/drivers/net/mdio_mux_sandbox.c
index fff6ddb2f1..e1801c1426 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/net/mdio-mux-uclass.c b/net/mdio-mux-uclass.c
index 780526c19e..94b90e0657 100644
--- a/net/mdio-mux-uclass.c
+++ b/net/mdio-mux-uclass.c
@@ -54,11 +54,6 @@ static struct udevice *mmux_get_parent_mdio(struct udevice *mux)
return pdata->mdio_parent;
}

-static struct mdio_ops *mmux_get_mdio_parent_ops(struct udevice *mux)
-{
- return mdio_get_ops(mmux_get_parent_mdio(mux));
-}
-
/* call driver select function before performing MDIO r/w */
static int mmux_change_sel(struct udevice *ch, bool sel)
{
@@ -90,14 +85,13 @@ static int mmux_read(struct udevice *ch, int addr, int devad,
{
struct udevice *mux = ch->parent;
struct udevice *parent_mdio = mmux_get_parent_mdio(mux);
- struct mdio_ops *parent_ops = mmux_get_mdio_parent_ops(mux);
int err;

err = mmux_change_sel(ch, true);
if (err)
return err;

- err = parent_ops->read(parent_mdio, addr, devad, reg);
+ err = dm_mdio_read(parent_mdio, addr, devad, reg);
mmux_change_sel(ch, false);

return err;
@@ -109,14 +103,13 @@ static int mmux_write(struct udevice *ch, int addr, int devad,
{
struct udevice *mux = ch->parent;
struct udevice *parent_mdio = mmux_get_parent_mdio(mux);
- struct mdio_ops *parent_ops = mmux_get_mdio_parent_ops(mux);
int err;

err = mmux_change_sel(ch, true);
if (err)
return err;

- err = parent_ops->write(parent_mdio, addr, devad, reg, val);
+ err = dm_mdio_write(parent_mdio, addr, devad, reg, val);
mmux_change_sel(ch, false);

return err;
@@ -127,18 +120,17 @@ static int mmux_reset(struct udevice *ch)
{
struct udevice *mux = ch->parent;
struct udevice *parent_mdio = mmux_get_parent_mdio(mux);
- struct mdio_ops *parent_ops = mmux_get_mdio_parent_ops(mux);
int err;

/* reset is optional, if it's not implemented just exit */
- if (!parent_ops->reset)
+ if (!mdio_get_ops(parent_mdio)->reset)
return 0;

err = mmux_change_sel(ch, true);
if (err)
return err;

- err = parent_ops->reset(parent_mdio);
+ err = dm_mdio_reset(parent_mdio);
mmux_change_sel(ch, false);

return err;
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
index 887c228167..bef8280e21 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -95,27 +95,18 @@ int dm_mdio_reset(struct udevice *mdio_dev)
*/
static int mdio_read(struct mii_dev *mii_bus, int addr, int devad, int reg)
{
- struct udevice *dev = mii_bus->priv;
-
- return mdio_get_ops(dev)->read(dev, addr, devad, reg);
+ return dm_mdio_read(mii_bus->priv, addr, devad, reg);
}

static int mdio_write(struct mii_dev *mii_bus, int addr, int devad, int reg,
u16 val)
{
- struct udevice *dev = mii_bus->priv;
-
- return mdio_get_ops(dev)->write(dev, addr, devad, reg, val);
+ return dm_mdio_write(mii_bus->priv, addr, devad, reg, val);
}

static int mdio_reset(struct mii_dev *mii_bus)
{
- struct udevice *dev = mii_bus->priv;
-
- if (mdio_get_ops(dev)->reset)
- return mdio_get_ops(dev)->reset(dev);
- else
- return 0;
+ return dm_mdio_reset(mii_bus->priv);
}

static int dm_mdio_post_probe(struct udevice *dev)
@@ -135,10 +126,8 @@ static int dm_mdio_post_probe(struct udevice *dev)
static int dm_mdio_pre_remove(struct udevice *dev)
{
struct mdio_perdev_priv *pdata = dev_get_uclass_priv(dev);
- struct mdio_ops *ops = mdio_get_ops(dev);

- if (ops->reset)
- ops->reset(dev);
+ dm_mdio_reset(dev);
mdio_unregister(pdata->mii_bus);
mdio_free(pdata->mii_bus);

diff --git a/test/dm/mdio.c b/test/dm/mdio.c
index 64347e1275..f863c52645 100644
--- a/test/dm/mdio.c
+++ b/test/dm/mdio.c
@@ -38,18 +38,18 @@ static int dm_test_mdio(struct unit_test_state *uts)
ut_assertnonnull(ops->read);
ut_assertnonnull(ops->write);

- ut_assertok(ops->write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG, TEST_REG_VALUE));
- reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG);
+ ut_assertok(dm_mdio_write(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG, TEST_REG_VALUE));
+ reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG);
ut_asserteq(reg, TEST_REG_VALUE);

- ut_assert(ops->read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG) != 0);
+ ut_assert(dm_mdio_read(dev, SANDBOX_PHY_ADDR + 1, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG) != 0);

- ut_assertok(ops->reset(dev));
- reg = ops->read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG);
+ ut_assertok(dm_mdio_reset(dev));
+ reg = dm_mdio_read(dev, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG);
ut_asserteq(reg, 0);

return 0;
diff --git a/test/dm/mdio_mux.c b/test/dm/mdio_mux.c
index 950f385d17..bfe3518221 100644
--- a/test/dm/mdio_mux.c
+++ b/test/dm/mdio_mux.c
@@ -57,22 +57,22 @@ static int dm_test_mdio_mux(struct unit_test_state *uts)
* is selected to the selection #. Just reading that register from
* either of the child buses should return the id of the child bus
*/
- reg = ops->read(mdio_ch0, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG_CNT - 1);
+ reg = dm_mdio_read(mdio_ch0, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG_CNT - 1);
ut_asserteq(reg, 0);

- reg = ops->read(mdio_ch1, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG_CNT - 1);
+ reg = dm_mdio_read(mdio_ch1, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG_CNT - 1);
ut_asserteq(reg, 1);

mmops->select(mux, MDIO_MUX_SELECT_NONE, 5);
- reg = ops_parent->read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG_CNT - 1);
+ reg = dm_mdio_read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG_CNT - 1);
ut_asserteq(reg, 5);

mmops->deselect(mux, 5);
- reg = ops_parent->read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
- SANDBOX_PHY_REG_CNT - 1);
+ reg = dm_mdio_read(mdio, SANDBOX_PHY_ADDR, MDIO_DEVAD_NONE,
+ SANDBOX_PHY_REG_CNT - 1);
ut_asserteq(reg, (u16)MDIO_MUX_SELECT_NONE);

return 0;
--
2.34.1