Convert the read_c45() path to the new read enabled command runner. Do it the same way as the write C22/C45 implementation. - bus calls otto_emdio_read_c45() - this handed over to SoC specific otto_emdio_9300_read_c45() - finally the registers are filled and the runner issued Signed-off-by: Markus Stockhausen --- drivers/net/mdio/mdio-realtek-rtl9300.c | 78 +++++++++---------------- 1 file changed, 26 insertions(+), 52 deletions(-) diff --git a/drivers/net/mdio/mdio-realtek-rtl9300.c b/drivers/net/mdio/mdio-realtek-rtl9300.c index 6f4affe0696d..10a433e497a1 100644 --- a/drivers/net/mdio/mdio-realtek-rtl9300.c +++ b/drivers/net/mdio/mdio-realtek-rtl9300.c @@ -96,7 +96,7 @@ struct otto_emdio_info { u8 num_ports; u16 num_pages; int (*read_c22)(struct mii_bus *bus, int phy_id, int regnum); - int (*read_c45)(struct mii_bus *bus, int phy_id, int dev_addr, int regnum); + int (*read_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u32 *value); int (*write_c22)(struct mii_bus *bus, int port, int regnum, u16 value); int (*write_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u16 value); }; @@ -268,58 +268,16 @@ static int otto_emdio_9300_write_c22(struct mii_bus *bus, int port, int regnum, return otto_emdio_run_cmd(bus, PHY_CTRL_TYPE_C22 | PHY_CTRL_WRITE, &cmd_regs, NULL); } -static int otto_emdio_9300_read_c45(struct mii_bus *bus, int phy_id, int dev_addr, int regnum) +static int otto_emdio_9300_read_c45(struct mii_bus *bus, int port, + int dev_addr, int regnum, u32 *value) { - struct otto_emdio_chan *chan = bus->priv; - struct otto_emdio_priv *priv; - u32 io_reg, cmd_reg, val; - struct regmap *regmap; - int port; - int err; - - priv = chan->priv; - regmap = priv->regmap; - io_reg = priv->info->cmd_regs.io_data; - cmd_reg = priv->info->cmd_regs.c22_data; /* shared command/C22 register */ - - port = otto_emdio_phy_to_port(bus, phy_id); - if (port < 0) - return port; - - mutex_lock(&priv->lock); - err = otto_emdio_wait_ready(priv); - if (err) - goto out_err; - - val = FIELD_PREP(PHY_CTRL_INDATA, port); - err = regmap_write(regmap, io_reg, val); - if (err) - goto out_err; - - val = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) | - FIELD_PREP(PHY_CTRL_MMD_REG, regnum); - err = regmap_write(regmap, priv->info->cmd_regs.c45_data, val); - if (err) - goto out_err; - - err = regmap_write(regmap, cmd_reg, PHY_CTRL_READ | PHY_CTRL_TYPE_C45 | PHY_CTRL_CMD); - if (err) - goto out_err; - - err = otto_emdio_wait_ready(priv); - if (err) - goto out_err; - - err = regmap_read(regmap, io_reg, &val); - if (err) - goto out_err; - - mutex_unlock(&priv->lock); - return FIELD_GET(PHY_CTRL_DATA, val); + struct otto_emdio_cmd_regs cmd_regs = { + .c45_data = FIELD_PREP(PHY_CTRL_MMD_DEVAD, dev_addr) | + FIELD_PREP(PHY_CTRL_MMD_REG, regnum), + .io_data = FIELD_PREP(PHY_CTRL_INDATA, port), + }; -out_err: - mutex_unlock(&priv->lock); - return err; + return otto_emdio_run_cmd(bus, PHY_CTRL_TYPE_C45 | PHY_CTRL_READ, &cmd_regs, value); } static int otto_emdio_9300_write_c45(struct mii_bus *bus, int port, @@ -350,6 +308,22 @@ static int otto_emdio_write_c22(struct mii_bus *bus, int phy_id, int regnum, u16 return ret; } +static int otto_emdio_read_c45(struct mii_bus *bus, int phy_id, int dev_addr, int regnum) +{ + struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus); + int ret, port; + u32 value; + + port = otto_emdio_phy_to_port(bus, phy_id); + if (port < 0) + return port; + + scoped_guard(mutex, &priv->lock) + ret = (*priv->info->read_c45)(bus, port, dev_addr, regnum, &value); + + return ret ? ret : value; +} + static int otto_emdio_write_c45(struct mii_bus *bus, int phy_id, int dev_addr, int regnum, u16 value) { @@ -439,7 +413,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv bus->name = "Realtek Switch MDIO Bus"; if (priv->smi_bus_is_c45[mdio_bus]) { - bus->read_c45 = priv->info->read_c45; + bus->read_c45 = otto_emdio_read_c45; bus->write_c45 = otto_emdio_write_c45; } else { bus->read = priv->info->read_c22; -- 2.54.0