Skip to content

Commit 9cd5993

Browse files
plappermaulkuba-moo
authored andcommitted
net: mdio: realtek-rtl9300: use command runner for write_c22()
Now that the driver has a generic command runner make use of it in the write_c22() path. For this. - add generic otto_emdio_write_c22() helper that will be called by bus - convert otto_emdio_9300_write_c22() to new command runner logic Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Link: https://patch.msgid.link/20260527163449.1294961-3-markus.stockhausen@gmx.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 9ccb438 commit 9cd5993

1 file changed

Lines changed: 27 additions & 54 deletions

File tree

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

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct otto_emdio_info {
9898
u16 num_pages;
9999
int (*read_c22)(struct mii_bus *bus, int phy_id, int regnum);
100100
int (*read_c45)(struct mii_bus *bus, int phy_id, int dev_addr, int regnum);
101-
int (*write_c22)(struct mii_bus *bus, int phy_id, int regnum, u16 value);
101+
int (*write_c22)(struct mii_bus *bus, int port, int regnum, u16 value);
102102
int (*write_c45)(struct mii_bus *bus, int port, int dev_addr, int regnum, u16 value);
103103
};
104104

@@ -254,60 +254,18 @@ static int otto_emdio_9300_read_c22(struct mii_bus *bus, int phy_id, int regnum)
254254
return err;
255255
}
256256

257-
static int otto_emdio_9300_write_c22(struct mii_bus *bus, int phy_id, int regnum, u16 value)
257+
static int otto_emdio_9300_write_c22(struct mii_bus *bus, int port, int regnum, u16 value)
258258
{
259-
struct otto_emdio_chan *chan = bus->priv;
260-
struct otto_emdio_priv *priv;
261-
u32 io_reg, cmd_reg, val;
262-
struct regmap *regmap;
263-
int port;
264-
int err;
265-
266-
priv = chan->priv;
267-
regmap = priv->regmap;
268-
io_reg = priv->info->cmd_regs.io_data;
269-
cmd_reg = priv->info->cmd_regs.c22_data; /* shared command/C22 register */
270-
271-
port = otto_emdio_phy_to_port(bus, phy_id);
272-
if (port < 0)
273-
return port;
274-
275-
mutex_lock(&priv->lock);
276-
err = otto_emdio_wait_ready(priv);
277-
if (err)
278-
goto out_err;
279-
280-
err = regmap_write(regmap, priv->info->cmd_regs.port_mask_low, BIT(port));
281-
if (err)
282-
goto out_err;
283-
284-
err = regmap_write(regmap, io_reg, FIELD_PREP(PHY_CTRL_INDATA, value));
285-
if (err)
286-
goto out_err;
287-
288-
val = FIELD_PREP(PHY_CTRL_REG_ADDR, regnum) |
289-
FIELD_PREP(PHY_CTRL_PARK_PAGE, 0x1f) |
290-
FIELD_PREP(PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)) |
291-
PHY_CTRL_WRITE | PHY_CTRL_TYPE_C22 | PHY_CTRL_CMD;
292-
err = regmap_write(regmap, cmd_reg, val);
293-
if (err)
294-
goto out_err;
295-
296-
err = regmap_read_poll_timeout(regmap, cmd_reg, val, !(val & PHY_CTRL_CMD), 10, 100);
297-
if (err)
298-
goto out_err;
299-
300-
if (val & PHY_CTRL_FAIL) {
301-
err = -ENXIO;
302-
goto out_err;
303-
}
304-
305-
mutex_unlock(&priv->lock);
306-
return 0;
259+
struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus);
260+
struct otto_emdio_cmd_regs cmd_data = {
261+
.c22_data = FIELD_PREP(PHY_CTRL_REG_ADDR, regnum) |
262+
FIELD_PREP(PHY_CTRL_PARK_PAGE, 0x1f) |
263+
FIELD_PREP(PHY_CTRL_MAIN_PAGE, RAW_PAGE(priv)),
264+
.io_data = FIELD_PREP(PHY_CTRL_INDATA, value),
265+
.port_mask_low = BIT(port),
266+
};
307267

308-
out_err:
309-
mutex_unlock(&priv->lock);
310-
return err;
268+
return otto_emdio_write_cmd(bus, PHY_CTRL_TYPE_C22, &cmd_data);
311269
}
312270

313271
static int otto_emdio_9300_read_c45(struct mii_bus *bus, int phy_id, int dev_addr, int regnum)
@@ -377,6 +335,21 @@ static int otto_emdio_9300_write_c45(struct mii_bus *bus, int port,
377335
return otto_emdio_write_cmd(bus, PHY_CTRL_TYPE_C45, &cmd_data);
378336
}
379337

338+
static int otto_emdio_write_c22(struct mii_bus *bus, int phy_id, int regnum, u16 value)
339+
{
340+
struct otto_emdio_priv *priv = otto_emdio_bus_to_priv(bus);
341+
int ret, port;
342+
343+
port = otto_emdio_phy_to_port(bus, phy_id);
344+
if (port < 0)
345+
return port;
346+
347+
scoped_guard(mutex, &priv->lock)
348+
ret = priv->info->write_c22(bus, port, regnum, value);
349+
350+
return ret;
351+
}
352+
380353
static int otto_emdio_write_c45(struct mii_bus *bus, int phy_id,
381354
int dev_addr, int regnum, u16 value)
382355
{
@@ -470,7 +443,7 @@ static int otto_emdio_probe_one(struct device *dev, struct otto_emdio_priv *priv
470443
bus->write_c45 = otto_emdio_write_c45;
471444
} else {
472445
bus->read = priv->info->read_c22;
473-
bus->write = priv->info->write_c22;
446+
bus->write = otto_emdio_write_c22;
474447
}
475448
bus->parent = dev;
476449
chan = bus->priv;

0 commit comments

Comments
 (0)