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>
This commit is contained in:
Marek Behún 2022-04-07 00:32:59 +02:00 committed by Ramon Fried
parent 351bfa6ebd
commit 1776a24bbb
5 changed files with 27 additions and 48 deletions

View File

@ -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)

View File

@ -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;

View File

@ -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);

View File

@ -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;

View File

@ -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;