treewide: use dm_mdio_read/write/reset() wrappers
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>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
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 @@
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 @@
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 780526c..94b90e0 100644
--- a/net/mdio-mux-uclass.c
+++ b/net/mdio-mux-uclass.c
@@ -54,11 +54,6 @@
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 @@
{
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 @@
{
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 @@
{
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 887c228..bef8280 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -95,27 +95,18 @@
*/
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_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 64347e1..f863c52 100644
--- a/test/dm/mdio.c
+++ b/test/dm/mdio.c
@@ -38,18 +38,18 @@
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 950f385..bfe3518 100644
--- a/test/dm/mdio_mux.c
+++ b/test/dm/mdio_mux.c
@@ -57,22 +57,22 @@
* 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;