mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-09 14:50:19 +00:00
net: dsa: mt7530: simplify core operations
The core_rmw() function calls core_read_mmd_indirect() to read the requested register, and then calls core_write_mmd_indirect() to write the requested value to the register. Because Clause 22 is used to access Clause 45 registers, some operations on core_write_mmd_indirect() are unnecessarily run. Get rid of core_read_mmd_indirect() and core_write_mmd_indirect(), and run only the necessary operations on core_write() and core_rmw(). Reviewed-by: Daniel Golle <daniel@makrotopia.org> Tested-by: Daniel Golle <daniel@makrotopia.org> Signed-off-by: Arınç ÜNAL <arinc.unal@arinc9.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
868ff5f494
commit
7c5e37d7ee
@ -74,81 +74,6 @@ static const struct mt7530_mib_desc mt7530_mib[] = {
|
|||||||
MIB_DESC(1, 0xb8, "RxArlDrop"),
|
MIB_DESC(1, 0xb8, "RxArlDrop"),
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Since phy_device has not yet been created and
|
|
||||||
* phy_{read,write}_mmd_indirect is not available, we provide our own
|
|
||||||
* core_{read,write}_mmd_indirect with core_{clear,write,set} wrappers
|
|
||||||
* to complete this function.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
core_read_mmd_indirect(struct mt7530_priv *priv, int prtad, int devad)
|
|
||||||
{
|
|
||||||
struct mii_bus *bus = priv->bus;
|
|
||||||
int value, ret;
|
|
||||||
|
|
||||||
/* Write the desired MMD Devad */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_CTRL, devad);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Write the desired MMD register address */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_DATA, prtad);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Select the Function : DATA with no post increment */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Read the content of the MMD's selected register */
|
|
||||||
value = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_DATA);
|
|
||||||
|
|
||||||
return value;
|
|
||||||
err:
|
|
||||||
dev_err(&bus->dev, "failed to read mmd register\n");
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
core_write_mmd_indirect(struct mt7530_priv *priv, int prtad,
|
|
||||||
int devad, u32 data)
|
|
||||||
{
|
|
||||||
struct mii_bus *bus = priv->bus;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Write the desired MMD Devad */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_CTRL, devad);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Write the desired MMD register address */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_DATA, prtad);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Select the Function : DATA with no post increment */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_CTRL, devad | MII_MMD_CTRL_NOINCR);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
/* Write the data into MMD's selected register */
|
|
||||||
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
|
||||||
MII_MMD_DATA, data);
|
|
||||||
err:
|
|
||||||
if (ret < 0)
|
|
||||||
dev_err(&bus->dev,
|
|
||||||
"failed to write mmd register\n");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mt7530_mutex_lock(struct mt7530_priv *priv)
|
mt7530_mutex_lock(struct mt7530_priv *priv)
|
||||||
{
|
{
|
||||||
@ -166,9 +91,35 @@ mt7530_mutex_unlock(struct mt7530_priv *priv)
|
|||||||
static void
|
static void
|
||||||
core_write(struct mt7530_priv *priv, u32 reg, u32 val)
|
core_write(struct mt7530_priv *priv, u32 reg, u32 val)
|
||||||
{
|
{
|
||||||
|
struct mii_bus *bus = priv->bus;
|
||||||
|
int ret;
|
||||||
|
|
||||||
mt7530_mutex_lock(priv);
|
mt7530_mutex_lock(priv);
|
||||||
|
|
||||||
core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
|
/* Write the desired MMD Devad */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_CTRL, MDIO_MMD_VEND2);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Write the desired MMD register address */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_DATA, reg);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Select the Function : DATA with no post increment */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Write the data into MMD's selected register */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_DATA, val);
|
||||||
|
err:
|
||||||
|
if (ret < 0)
|
||||||
|
dev_err(&bus->dev, "failed to write mmd register\n");
|
||||||
|
|
||||||
mt7530_mutex_unlock(priv);
|
mt7530_mutex_unlock(priv);
|
||||||
}
|
}
|
||||||
@ -176,14 +127,41 @@ core_write(struct mt7530_priv *priv, u32 reg, u32 val)
|
|||||||
static void
|
static void
|
||||||
core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
|
core_rmw(struct mt7530_priv *priv, u32 reg, u32 mask, u32 set)
|
||||||
{
|
{
|
||||||
|
struct mii_bus *bus = priv->bus;
|
||||||
u32 val;
|
u32 val;
|
||||||
|
int ret;
|
||||||
|
|
||||||
mt7530_mutex_lock(priv);
|
mt7530_mutex_lock(priv);
|
||||||
|
|
||||||
val = core_read_mmd_indirect(priv, reg, MDIO_MMD_VEND2);
|
/* Write the desired MMD Devad */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_CTRL, MDIO_MMD_VEND2);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Write the desired MMD register address */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_DATA, reg);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Select the Function : DATA with no post increment */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_CTRL, MDIO_MMD_VEND2 | MII_MMD_CTRL_NOINCR);
|
||||||
|
if (ret < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
|
/* Read the content of the MMD's selected register */
|
||||||
|
val = bus->read(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_DATA);
|
||||||
val &= ~mask;
|
val &= ~mask;
|
||||||
val |= set;
|
val |= set;
|
||||||
core_write_mmd_indirect(priv, reg, MDIO_MMD_VEND2, val);
|
/* Write the data into MMD's selected register */
|
||||||
|
ret = bus->write(bus, MT753X_CTRL_PHY_ADDR(priv->mdiodev->addr),
|
||||||
|
MII_MMD_DATA, val);
|
||||||
|
err:
|
||||||
|
if (ret < 0)
|
||||||
|
dev_err(&bus->dev, "failed to write mmd register\n");
|
||||||
|
|
||||||
mt7530_mutex_unlock(priv);
|
mt7530_mutex_unlock(priv);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user