Skip to content

Commit 2e3c28c

Browse files
plappermaulkuba-moo
authored andcommitted
net: mdio: realtek-rtl9300: use command runner for read_c22()
Convert the final missing read_c22() path to the new read enabled command runner. Do it the same way as other implementations. - bus calls otto_emdio_read_c22() - this hands over to SoC specific otto_emdio_9300_read_c22() - finally the registers are filled and the runner issued With this cleanup remove the obsolete helper otto_emdio_wait_ready() Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://patch.msgid.link/20260527163449.1294961-5-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent fcce51b commit 2e3c28c

1 file changed

Lines changed: 27 additions & 60 deletions

File tree

drivers/net/mdio/mdio-realtek-rtl9300.c

Lines changed: 27 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ struct otto_emdio_info {
9797
u8 num_buses;
9898
u8 num_ports;
9999
u16 num_pages;
100-
int (*read_c22)(struct mii_bus *bus, int phy_id, int regnum);
100+
int (*read_c22)(struct mii_bus *bus, int port, int regnum, u32 *value);
101101
int (*read_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u32 *value);
102102
int (*write_c22)(struct mii_bus *bus, int port, int regnum, u16 value);
103103
int (*write_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u16 value);
@@ -213,66 +213,17 @@ static int otto_emdio_write_cmd(struct mii_bus *bus, u32 cmd,
213213
return otto_emdio_run_cmd(bus, cmd | priv->info->cmd_write, cmd_data);
214214
}
215215

216-
static int otto_emdio_wait_ready(struct otto_emdio_priv *priv)
216+
static int otto_emdio_9300_read_c22(struct mii_bus *bus, int port, int regnum, u32 *value)
217217
{
218-
struct regmap *regmap = priv->regmap;
219-
u32 cmd_reg, val;
220-
221-
lockdep_assert_held(&priv->lock);
222-
cmd_reg = priv->info->cmd_regs.c22_data; /* shared command/C22 register */
223-
224-
return regmap_read_poll_timeout(regmap, cmd_reg, val, !(val & PHY_CTRL_CMD), 10, 1000);
225-
}
226-
227-
static int otto_emdio_9300_read_c22(struct mii_bus *bus, int phy_id, int regnum)
228-
{
229-
struct otto_emdio_chan *chan = bus->priv;
230-
struct otto_emdio_priv *priv;
231-
u32 io_reg, cmd_reg, val;
232-
struct regmap *regmap;
233-
int port;
234-
int err;
235-
236-
priv = chan->priv;
237-
regmap = priv->regmap;
238-
io_reg = priv->info->cmd_regs.io_data;
239-
cmd_reg = priv->info->cmd_regs.c22_data; /* shared command/C22 register */
240-
241-
port = otto_emdio_phy_to_port(bus, phy_id);
242-
if (port < 0)
243-
return port;
244-
245-
mutex_lock(&priv->lock);
246-
err = otto_emdio_wait_ready(priv);
247-
if (err)
248-
goto out_err;
249-
250-
err = regmap_write(regmap, io_reg, FIELD_PREP(PHY_CTRL_INDATA, port));
251-
if (err)
252-
goto out_err;
253-
254-
val = FIELD_PREP(PHY_CTRL_REG_ADDR, regnum) |
255-
FIELD_PREP(PHY_CTRL_PARK_PAGE, 0x1f) |
256-
FIELD_PREP(PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)) |
257-
PHY_CTRL_READ | PHY_CTRL_TYPE_C22 | PHY_CTRL_CMD;
258-
err = regmap_write(regmap, cmd_reg, val);
259-
if (err)
260-
goto out_err;
261-
262-
err = otto_emdio_wait_ready(priv);
263-
if (err)
264-
goto out_err;
265-
266-
err = regmap_read(regmap, io_reg, &val);
267-
if (err)
268-
goto out_err;
269-
270-
mutex_unlock(&priv->lock);
271-
return FIELD_GET(PHY_CTRL_DATA, val);
218+
struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus);
219+
struct otto_emdio_cmd_regs cmd_data = {
220+
.c22_data = FIELD_PREP(PHY_CTRL_REG_ADDR, regnum) |
221+
FIELD_PREP(PHY_CTRL_PARK_PAGE, 0x1f) |
222+
FIELD_PREP(PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)),
223+
.io_data = FIELD_PREP(PHY_CTRL_INDATA, port),
224+
};
272225

273-
out_err:
274-
mutex_unlock(&priv->lock);
275-
return err;
226+
return otto_emdio_read_cmd(bus, PHY_CTRL_TYPE_C22, &cmd_data, value);
276227
}
277228

278229
static int otto_emdio_9300_write_c22(struct mii_bus *bus, int port, int regnum, u16 value)
@@ -314,6 +265,22 @@ static int otto_emdio_9300_write_c45(struct mii_bus *bus, int port,
314265
return otto_emdio_write_cmd(bus, PHY_CTRL_TYPE_C45, &cmd_data);
315266
}
316267

268+
static int otto_emdio_read_c22(struct mii_bus *bus, int phy_id, int regnum)
269+
{
270+
struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus);
271+
int ret, port;
272+
u32 value;
273+
274+
port = otto_emdio_phy_to_port(bus, phy_id);
275+
if (port < 0)
276+
return port;
277+
278+
scoped_guard(mutex, &priv->lock)
279+
ret = priv->info->read_c22(bus, port, regnum, &value);
280+
281+
return ret ? ret : value;
282+
}
283+
317284
static int otto_emdio_write_c22(struct mii_bus *bus, int phy_id, int regnum, u16 value)
318285
{
319286
struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus);
@@ -437,7 +404,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv
437404
bus->read_c45 = otto_emdio_read_c45;
438405
bus->write_c45 = otto_emdio_write_c45;
439406
} else {
440-
bus->read = priv->info->read_c22;
407+
bus->read = otto_emdio_read_c22;
441408
bus->write = otto_emdio_write_c22;
442409
}
443410
bus->parent = dev;

0 commit comments

Comments
 (0)