Skip to content

Commit 1eb5944

Browse files
ffainellidavem330
authored andcommitted
net: dsa: Provide a slave MII bus if needed
Mimic what net/dsa/dsa.c does and provide a slave MII bus by default which will be created if the driver implements a phy_read method. Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Vivien Didelot <vivien.didelot@savoirfairelinux.com> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 6e830d8 commit 1eb5944

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

net/dsa/dsa2.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,18 @@ static int dsa_ds_apply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
312312
if (err < 0)
313313
return err;
314314

315+
if (!ds->slave_mii_bus && ds->drv->phy_read) {
316+
ds->slave_mii_bus = devm_mdiobus_alloc(ds->dev);
317+
if (!ds->slave_mii_bus)
318+
return -ENOMEM;
319+
320+
dsa_slave_mii_bus_init(ds);
321+
322+
err = mdiobus_register(ds->slave_mii_bus);
323+
if (err < 0)
324+
return err;
325+
}
326+
315327
for (index = 0; index < DSA_MAX_PORTS; index++) {
316328
port = ds->ports[index].dn;
317329
if (!port)
@@ -361,6 +373,9 @@ static void dsa_ds_unapply(struct dsa_switch_tree *dst, struct dsa_switch *ds)
361373

362374
dsa_user_port_unapply(port, index, ds);
363375
}
376+
377+
if (ds->slave_mii_bus && ds->drv->phy_read)
378+
mdiobus_unregister(ds->slave_mii_bus);
364379
}
365380

366381
static int dsa_dst_apply(struct dsa_switch_tree *dst)

0 commit comments

Comments
 (0)